david.m...@gmail.com unread, Jan 25, 2026, 4:08:33 PM (8 days ago) Jan 25
Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Window Maker Development
This patch is fixing some issues in how right and center aligned wtextfields are handled. -text selection with mouse was not working properly especially setting and identifying the cursor position -middle button paste was only working for left aligned text --- WINGs/wtextfield.c | 90 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 26 deletions(-) diff --git a/WINGs/wtextfield.c b/WINGs/wtextfield.c index 4752330b..6a4d9ef2 100644 --- a/WINGs/wtextfield.c +++ b/WINGs/wtextfield.c @@ -853,8 +853,8 @@ static void paintTextField(TextField * tPtr) count = tPtr->viewPosition; } - rx = tPtr->offsetWidth + 1 + WMWidthOfString(tPtr->font, text, count) - - WMWidthOfString(tPtr->font, text, tPtr->viewPosition); + rx = tx + WMWidthOfString(tPtr->font, &(text[tPtr->viewPosition]), + count - tPtr->viewPosition); WMDrawImageString(screen, drawbuffer, color, screen->gray, tPtr->font, rx, ty, &(text[count]), count2); @@ -1405,7 +1405,25 @@ static void handleTextFieldActionEvents(XEvent * event, void *data) tPtr->viewPosition); } - tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x); + if (tPtr->flags.alignment == WARight) { + int textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen); + if (textWidth < tPtr->usableWidth) { + tPtr->cursorPosition = pointToCursorPosition(tPtr, + event->xmotion.x - tPtr->usableWidth + textWidth); + } else { + tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x); + } + } else if (tPtr->flags.alignment == WACenter) { + int textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen); + if (textWidth < tPtr->usableWidth) { + tPtr->cursorPosition = pointToCursorPosition(tPtr, + event->xmotion.x - (tPtr->usableWidth - textWidth) / 2); + } else { + tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x); + } + } else { + tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x); + } /* Do not allow text selection in secure textfields */ if (tPtr->flags.secure) { @@ -1438,17 +1456,35 @@ static void handleTextFieldActionEvents(XEvent * event, void *data) if (tPtr->flags.enabled && !tPtr->flags.focused) { WMSetFocusToWidget(tPtr); } + if (textWidth < tPtr->usableWidth) { + tPtr->cursorPosition = pointToCursorPosition(tPtr, + event->xbutton.x - tPtr->usableWidth + + textWidth); + } else + tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x); + if (tPtr->flags.focused) { tPtr->selection.position = tPtr->cursorPosition; tPtr->selection.count = 0; } + paintTextField(tPtr); + break; + + case WACenter: + textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen); + if (tPtr->flags.enabled && !tPtr->flags.focused) { + WMSetFocusToWidget(tPtr); + } if (textWidth < tPtr->usableWidth) { tPtr->cursorPosition = pointToCursorPosition(tPtr, - event->xbutton.x - tPtr->usableWidth - + textWidth); - } else + event->xbutton.x - (tPtr->usableWidth - textWidth) / 2); + } else { tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x); - + } + if (tPtr->flags.focused) { + tPtr->selection.position = tPtr->cursorPosition; + tPtr->selection.count = 0; + } paintTextField(tPtr); break; @@ -1462,29 +1498,31 @@ static void handleTextFieldActionEvents(XEvent * event, void *data) tPtr->selection.count = 0; paintTextField(tPtr); } - if (event->xbutton.button == Button2 && tPtr->flags.enabled) { - char *text; - int n; - - if (!WMRequestSelection(tPtr->view, XA_PRIMARY, XA_STRING, - event->xbutton.time, pasteText, NULL)) { - text = XFetchBuffer(tPtr->view->screen->display, &n, 0); - - if (text) { - text[n] = 0; - WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition); - XFree(text); - NOTIFY(tPtr, didChange, WMTextDidChangeNotification, - (void *)WMInsertTextEvent); - } - } else { - tPtr->flags.waitingSelection = 1; - } - } break; default: break; } + + if (event->xbutton.button == Button2 && tPtr->flags.enabled) { + char *text; + int n; + + if (!WMRequestSelection(tPtr->view, XA_PRIMARY, XA_STRING, + event->xbutton.time, pasteText, NULL)) { + text = XFetchBuffer(tPtr->view->screen->display, &n, 0); + + if (text) { + text[n] = 0; + WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition); + XFree(text); + NOTIFY(tPtr, didChange, WMTextDidChangeNotification, + (void *)WMInsertTextEvent); + } + } else { + tPtr->flags.waitingSelection = 1; + } + } + break; case ButtonRelease: -- 2.43.0
0002-WINGs-fix-right-and-center-aligned-wtextfield.patch