From 365556b676b5d86a25af052bd2a20aaf429f18b0 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 2 Jan 2002 17:45:40 +0000 Subject: [PATCH] misc selection and textfield fixes --- WINGs/ChangeLog | 6 +++++ WINGs/findfile.c | 67 ++++++++++++++++++++++++++++++++++++------------------ WINGs/selection.c | 57 +++++++++++++++++++++++++--------------------- WINGs/wtextfield.c | 41 +++++++++++++++++---------------- configure.ac | 4 ++-- configure.in | 4 ++-- po/Makefile.am | 7 +++--- util/wmsetup.c | 4 ++-- 8 files changed, 113 insertions(+), 77 deletions(-) diff --git a/WINGs/ChangeLog b/WINGs/ChangeLog index be1da80e..50435a5d 100644 --- a/WINGs/ChangeLog +++ b/WINGs/ChangeLog @@ -1,3 +1,9 @@ +Changes since wmaker 0.80.0: +............................ + +- fixed a bug in wfindfile() (rewrote wfindfile() with better logic). + + Changes since wmaker 0.70.0: ............................ diff --git a/WINGs/findfile.c b/WINGs/findfile.c index 6c2e4b51..7be10aef 100644 --- a/WINGs/findfile.c +++ b/WINGs/findfile.c @@ -160,6 +160,27 @@ wexpandpath(char *path) } +/* return address of next char != tok or end of string whichever comes first */ +static char* +skipchar(char *string, char tok) +{ + while(*string!=0 && *string==tok) + string++; + + return string; +} + + +/* return address of next char == tok or end of string whichever comes first */ +static char* +nextchar(char *string, char tok) +{ + while(*string!=0 && *string!=tok) + string++; + + return string; +} + /* *---------------------------------------------------------------------- @@ -180,15 +201,14 @@ char* wfindfile(char *paths, char *file) { char *path; - char *tmp; - int done; + char *tmp, *tmp2; int len, flen; char *fullpath; if (!file) return NULL; - if (*file=='/' || *file=='~' || *file=='$' || !paths) { + if (*file=='/' || *file=='~' || *file=='$' || !paths || *paths==0) { if (access(file, F_OK)<0) { fullpath = wexpandpath(file); if (!fullpath) @@ -207,26 +227,29 @@ wfindfile(char *paths, char *file) flen = strlen(file); tmp = paths; - done = 0; - while (!done) { - len = strcspn(tmp, ":"); - if (len==0) done=1; - path = wmalloc(len+flen+2); - path = memcpy(path, tmp, len); - path[len]=0; - strcat(path, "/"); - strcat(path, file); - fullpath = wexpandpath(path); - wfree(path); - if (fullpath) { - if (access(fullpath, F_OK)==0) { - return fullpath; - } - wfree(fullpath); - } - tmp=&(tmp[len+1]); - if (*tmp==0) break; + while (*tmp) { + tmp = skipchar(tmp, ':'); + if (*tmp==0) + break; + tmp2 = nextchar(tmp, ':'); + len = tmp2 - tmp; + path = wmalloc(len+flen+2); + path = memcpy(path, tmp, len); + path[len]=0; + if (path[len-1] != '/') + strcat(path, "/"); + strcat(path, file); + fullpath = wexpandpath(path); + wfree(path); + if (fullpath) { + if (access(fullpath, F_OK)==0) { + return fullpath; + } + wfree(fullpath); + } + tmp = tmp2; } + return NULL; } diff --git a/WINGs/selection.c b/WINGs/selection.c index 4ac0fcde..f094f2c4 100644 --- a/WINGs/selection.c +++ b/WINGs/selection.c @@ -38,9 +38,14 @@ typedef struct SelectionCallback { } SelectionCallback; -WMArray *selCallbacks = NULL; -WMArray *selHandlers = NULL; +static WMArray *selCallbacks = NULL; + +static WMArray *selHandlers = NULL; + +static Bool gotXError = False; + + void @@ -53,8 +58,9 @@ WMDeleteSelectionHandler(WMView *view, Atom selection, Time timestamp) if (!selHandlers) return; - - + + //printf("deleting selection handler for %d\n", win); + WM_ITERATE_ARRAY(selHandlers, handler, iter) { if (handler->view == view && (handler->selection == selection || selection == None) @@ -64,7 +70,8 @@ WMDeleteSelectionHandler(WMView *view, Atom selection, Time timestamp) handler->flags.delete_pending = 1; return; } - WMRemoveFromArray(selHandlers, handler); + //puts("found & removed"); + WMRemoveFromArray(selHandlers, handler); break; } } @@ -103,20 +110,20 @@ WMDeleteSelectionCallback(WMView *view, Atom selection, Time timestamp) } - -static Bool gotError = 0; -/* static int -errorHandler(XErrorEvent *error) +handleXError(Display *dpy, XErrorEvent *ev) { - return 0; + gotXError = True; + + return 1; } -*/ + static Bool writeSelection(Display *dpy, Window requestor, Atom property, Atom type, WMData *data) { + static void *oldHandler; int format, bpi; format = WMGetDataFormat(data); @@ -127,23 +134,18 @@ writeSelection(Display *dpy, Window requestor, Atom property, Atom type, /* printf("write to %x: %s\n", requestor, XGetAtomName(dpy, property)); */ - gotError = False; + oldHandler = XSetErrorHandler(handleXError); -#ifndef __sgi - if (!XChangeProperty(dpy, requestor, property, type, format, - PropModeReplace, WMDataBytes(data), - WMGetDataLength(data)/bpi)) - return False; -#else - /* in sgi seems this seems to return void */ - XChangeProperty(dpy, requestor, property, type, format, - PropModeReplace, WMDataBytes(data), - WMGetDataLength(data)/bpi); -#endif + gotXError = False; + + XChangeProperty(dpy, requestor, property, type, format, PropModeReplace, + WMDataBytes(data), WMGetDataLength(data)/bpi); XFlush(dpy); - return !gotError; + XSetErrorHandler(oldHandler); + + return !gotXError; } @@ -341,6 +343,7 @@ handleNotifyEvent(XEvent *event) void W_HandleSelectionEvent(XEvent *event) { + //printf("%d received %d\n", event->xany.window, event->type); if (event->type == SelectionNotify) { handleNotifyEvent(event); } else { @@ -359,9 +362,11 @@ WMCreateSelectionHandler(WMView *view, Atom selection, Time timestamp, Display *dpy = W_VIEW_SCREEN(view)->display; XSetSelectionOwner(dpy, selection, W_VIEW_DRAWABLE(view), timestamp); - if (XGetSelectionOwner(dpy, selection) != W_VIEW_DRAWABLE(view)) - return False; + if (XGetSelectionOwner(dpy, selection) != W_VIEW_DRAWABLE(view)) { + return False; + } + //printf("created selection handler for %d\n", W_VIEW_DRAWABLE(view)); handler = malloc(sizeof(SelectionHandler)); if (handler == NULL) return False; diff --git a/WINGs/wtextfield.c b/WINGs/wtextfield.c index a997e3dd..b071c080 100644 --- a/WINGs/wtextfield.c +++ b/WINGs/wtextfield.c @@ -285,6 +285,7 @@ lostHandler(WMView *view, Atom selection, void *cdata) { TextField *tPtr = (WMTextField*)view->self; + //WMDeleteSelectionHandler(view, XA_PRIMARY, CurrentTime); tPtr->flags.ownsSelection = 0; tPtr->selection.count = 0; paintTextField(tPtr); @@ -1447,16 +1448,6 @@ handleTextFieldActionEvents(XEvent *event, void *data) tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position; - if (tPtr->selection.count != 0) { - if (!tPtr->flags.ownsSelection) { - WMCreateSelectionHandler(tPtr->view, - XA_PRIMARY, - event->xbutton.time, - &selectionHandler, NULL); - tPtr->flags.ownsSelection = 1; - } - } - paintCursor(tPtr); paintTextField(tPtr); @@ -1482,7 +1473,8 @@ handleTextFieldActionEvents(XEvent *event, void *data) textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen); if (tPtr->flags.enabled && !tPtr->flags.focused) { WMSetFocusToWidget(tPtr); - } else if (tPtr->flags.focused) { + } + if (tPtr->flags.focused) { tPtr->selection.position = tPtr->cursorPosition; tPtr->selection.count = 0; } @@ -1499,11 +1491,8 @@ handleTextFieldActionEvents(XEvent *event, void *data) case WALeft: if (tPtr->flags.enabled && !tPtr->flags.focused) { WMSetFocusToWidget(tPtr); - tPtr->cursorPosition = pointToCursorPosition(tPtr, - event->xbutton.x); - paintTextField(tPtr); - } else if (tPtr->flags.focused - && event->xbutton.button == Button1) { + } + if (tPtr->flags.focused && event->xbutton.button == Button1) { tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x); tPtr->selection.position = tPtr->cursorPosition; @@ -1574,10 +1563,20 @@ handleTextFieldActionEvents(XEvent *event, void *data) event->xbutton.time, &selectionHandler, NULL); tPtr->flags.ownsSelection = 1; - } - - WMPostNotificationName("_lostOwnership", NULL, tPtr); - } + //puts("lost ownership"); + WMPostNotificationName("_lostOwnership", NULL, tPtr); + } + } else if (!tPtr->flags.secure && tPtr->selection.count!=0 && + !tPtr->flags.ownsSelection) { + WMCreateSelectionHandler(tPtr->view, + XA_PRIMARY, + event->xbutton.time, + &selectionHandler, NULL); + tPtr->flags.ownsSelection = 1; + //puts("lost ownership"); + WMPostNotificationName("_lostOwnership", NULL, tPtr); + } + lastButtonReleasedEvent = event->xbutton.time; break; @@ -1602,3 +1601,5 @@ destroyTextField(TextField *tPtr) wfree(tPtr); } + + diff --git a/configure.ac b/configure.ac index bbe3dc9f..3018aa4d 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ AC_INIT(src/WindowMaker.h) -AM_INIT_AUTOMAKE(WindowMaker, 0.80.0) +AM_INIT_AUTOMAKE(WindowMaker, 0.80.1) AM_PROG_LIBTOOL @@ -244,7 +244,7 @@ dnl ================== dnl List of supported locales dnl ------------------------- -supported_locales="bg cs da de el es et fi fr gl hr hu it ja ko nl no pl pt ro ru sk sv tr zh_CN zh_TW.Big5" +supported_locales="bg cs da de el es et fi fr gl hr hu it ja ko ms nl no pl pt ro ru sk sv tr zh_CN zh_TW.Big5" supported_wprefs_locales="bg cs de es et fi fr hr hu it ja ko pt ru sk zh_CN zh_TW.Big5" supported_wings_locales="cs de sk" diff --git a/configure.in b/configure.in index bbe3dc9f..3018aa4d 100644 --- a/configure.in +++ b/configure.in @@ -15,7 +15,7 @@ AC_INIT(src/WindowMaker.h) -AM_INIT_AUTOMAKE(WindowMaker, 0.80.0) +AM_INIT_AUTOMAKE(WindowMaker, 0.80.1) AM_PROG_LIBTOOL @@ -244,7 +244,7 @@ dnl ================== dnl List of supported locales dnl ------------------------- -supported_locales="bg cs da de el es et fi fr gl hr hu it ja ko nl no pl pt ro ru sk sv tr zh_CN zh_TW.Big5" +supported_locales="bg cs da de el es et fi fr gl hr hu it ja ko ms nl no pl pt ro ru sk sv tr zh_CN zh_TW.Big5" supported_wprefs_locales="bg cs de es et fi fr hr hu it ja ko pt ru sk zh_CN zh_TW.Big5" supported_wings_locales="cs de sk" diff --git a/po/Makefile.am b/po/Makefile.am index e938ffcc..c27daa7d 100644 --- a/po/Makefile.am +++ b/po/Makefile.am @@ -4,9 +4,10 @@ CATALOGS = @MOFILES@ CLEANFILES = $(CATALOGS) WindowMaker.pot -EXTRA_DIST = cs.po de.po es.po et.po fr.po gl.po ja.po ko.po nl.po pt.po \ - sv.po it.po no.po ru.po tr.po fi.po hr.po el.po pl.po ro.po zh_TW.Big5.po\ - zh_CN.po sk.po da.po bg.po hu.po ms.po +# keep this sorted +EXTRA_DIST = bg.po cs.po da.po de.po el.po es.po et.po fi.po fr.po gl.po \ + hr.po hu.po it.po ja.po ko.po ms.po nl.po no.po pl.po pt.po ro.po \ + ru.po sk.po sv.po tr.po zh_CN.po zh_TW.Big5.po POTFILES = \ $(top_builddir)/src/appicon.c \ diff --git a/util/wmsetup.c b/util/wmsetup.c index 1b701362..c8e68d07 100644 --- a/util/wmsetup.c +++ b/util/wmsetup.c @@ -290,7 +290,7 @@ Bool copyAllFiles(char *gsdir) FILE *f; char path[2048]; char file[256]; - char target[256]; + char target[2048]; /* copy misc data files */ @@ -298,7 +298,7 @@ Bool copyAllFiles(char *gsdir) f = fopen(path, "r"); while (!feof(f)) { - if (!fgets(path, 255, f)) { + if (!fgets(file, 255, f)) { break; } sprintf(path, "%s/%s", DATADIR, file); -- 2.11.4.GIT