Index: source/server.c =================================================================== RCS file: /cvsroot/nedit/nedit/source/server.c,v retrieving revision 1.28 diff -c -r1.28 server.c *** source/server.c 14 Apr 2004 09:44:00 -0000 1.28 --- source/server.c 3 Jun 2004 10:47:36 -0000 *************** *** 76,81 **** --- 76,83 ---- static void cleanUpServerCommunication(void); static void processServerCommandString(char *string); static void getFileClosedProperty(WindowInfo *window); + static int isLocatedOnDesktop(WindowInfo *window, long currentDesktop); + static WindowInfo *findWindowOnDesktop(int tabbed, long currentDesktop); static Atom ServerRequestAtom = 0; static Atom ServerExistsAtom = 0; *************** *** 283,288 **** --- 285,335 ---- deleteProperty(&atom); } + static int isLocatedOnDesktop(WindowInfo *window, long currentDesktop) + { + long windowDesktop; + if (currentDesktop == -1) + return True; /* No desktop information available */ + + windowDesktop = QueryDesktop(TheDisplay, window->shell); + /* Sticky windows have desktop 0xFFFFFFFF by convention */ + if (windowDesktop == currentDesktop || windowDesktop == 0xFFFFFFFFL) + return True; /* Desktop matches, or window is sticky */ + + return False; + } + + static WindowInfo *findWindowOnDesktop(int tabbed, long currentDesktop) + { + WindowInfo *window; + + if (currentDesktop == -1) /* No desktop information available */ + return WindowList; + + if (tabbed == 0 || (tabbed == -1 && GetPrefOpenInTab() == 0)) { + /* A new window is requested, unless we find an untitled unmodified + document on the current desktop */ + for (window=WindowList; window!=NULL; window=window->next) { + if (window->filenameSet || window->fileChanged || + window->macroCmdData != NULL) + continue; + /* No check for top document here! */ + if (isLocatedOnDesktop(window, currentDesktop)) + return window; + } + } + else { + /* Find a window on the current desktop to hold the new document */ + for (window=WindowList; window!=NULL; window=window->next) { + /* Avoid unnecessary property access (server round-trip) */ + if (!IsTopDocument(window)) + continue; + if (isLocatedOnDesktop(window, currentDesktop)) + return window; + } + } + return NULL; /* No window found on current desktop -> create new window */ + } static void processServerCommandString(char *string) { *************** *** 292,306 **** int lineNum, createFlag, readFlag, iconicFlag, lastIconic = 0, tabbed; int fileLen, doLen, lmLen, geomLen, charsRead, itemsRead; WindowInfo *window, *lastFile = NULL; /* If the command string is empty, put up an empty, Untitled window (or just pop one up if it already exists) */ if (string[0] == '\0') { for (window=WindowList; window!=NULL; window=window->next) ! if (!window->filenameSet && !window->fileChanged) break; if (window == NULL) { ! EditNewFile(WindowList, NULL, False, NULL, NULL); CheckCloseDim(); } else { --- 339,357 ---- int lineNum, createFlag, readFlag, iconicFlag, lastIconic = 0, tabbed; int fileLen, doLen, lmLen, geomLen, charsRead, itemsRead; WindowInfo *window, *lastFile = NULL; + long currentDesktop = QueryCurrentDesktop(TheDisplay, + RootWindow(TheDisplay, DefaultScreen(TheDisplay))); /* If the command string is empty, put up an empty, Untitled window (or just pop one up if it already exists) */ if (string[0] == '\0') { for (window=WindowList; window!=NULL; window=window->next) ! if (!window->filenameSet && !window->fileChanged && ! isLocatedOnDesktop(window, currentDesktop)) break; if (window == NULL) { ! EditNewFile(findWindowOnDesktop(tabbed, currentDesktop), NULL, ! False, NULL, NULL); CheckCloseDim(); } else { *************** *** 357,369 **** */ if (fileLen <= 0) { for (window=WindowList; window!=NULL; window=window->next) ! if (!window->filenameSet && !window->fileChanged) break; if (*doCommand == '\0') { if (window == NULL) { ! EditNewFile(tabbed? WindowList : NULL, NULL, iconicFlag, ! lmLen==0?NULL:langMode, NULL); } else { if (iconicFlag) RaiseDocument(window); --- 408,421 ---- */ if (fileLen <= 0) { for (window=WindowList; window!=NULL; window=window->next) ! if (!window->filenameSet && !window->fileChanged && ! isLocatedOnDesktop(window, currentDesktop)) break; if (*doCommand == '\0') { if (window == NULL) { ! EditNewFile(findWindowOnDesktop(tabbed, currentDesktop), ! NULL, iconicFlag, lmLen==0?NULL:langMode, NULL); } else { if (iconicFlag) RaiseDocument(window); *************** *** 411,417 **** last file opened will be raised to restore those deferred items. The current file may also be raised if there're macros to execute on. */ ! window = EditExistingFile(WindowList, filename, pathname, editFlags, geometry, iconicFlag, lmLen == 0 ? NULL : langMode, tabbed == -1? GetPrefOpenInTab() : tabbed, True); --- 463,469 ---- last file opened will be raised to restore those deferred items. The current file may also be raised if there're macros to execute on. */ ! window = EditExistingFile(findWindowOnDesktop(tabbed, currentDesktop), filename, pathname, editFlags, geometry, iconicFlag, lmLen == 0 ? NULL : langMode, tabbed == -1? GetPrefOpenInTab() : tabbed, True); Index: util/misc.c =================================================================== RCS file: /cvsroot/nedit/nedit/util/misc.c,v retrieving revision 1.63 diff -c -r1.63 misc.c *** util/misc.c 3 May 2004 08:53:14 -0000 1.63 --- util/misc.c 3 Jun 2004 10:47:36 -0000 *************** *** 150,155 **** --- 150,156 ---- Cardinal *nArgs); static void pageUpAP(Widget w, XEvent *event, String *args, Cardinal *nArgs); + static long queryDesktop(Display *display, Window window, Atom deskTopAtom); /* ** Set up closeCB to be called when the user selects close from the *************** *** 2197,2199 **** --- 2198,2263 ---- } #endif } + + static long queryDesktop(Display *display, Window window, Atom deskTopAtom) + { + long deskTopNumber = 0; + Atom actualType; + int actualFormat; + unsigned long nItems, bytesAfter; + unsigned char *prop; + + if (XGetWindowProperty(display, window, deskTopAtom, 0, 1, + False, AnyPropertyType, &actualType, &actualFormat, &nItems, + &bytesAfter, &prop) != Success) { + return -1; /* Property not found */ + } + + if (actualType == None) { + return -1; /* Property does not exist */ + } + + if (actualFormat != 32 || nItems != 1) { + XFree((char*)prop); + return -1; /* Wrong format */ + } + + deskTopNumber = *(long*)prop; + XFree((char*)prop); + return deskTopNumber; + } + + /* + ** Returns the current desktop number, or -1 if no desktop information + ** is available. + */ + long QueryCurrentDesktop(Display *display, Window rootWindow) + { + static Atom currentDesktopAtom = -1; + + if (currentDesktopAtom == -1) + currentDesktopAtom = XInternAtom(display, "_NET_CURRENT_DESKTOP", True); + + if (currentDesktopAtom != None) { + return queryDesktop(display, rootWindow, currentDesktopAtom); + } + return -1; /* No desktop information */ + } + + /* + ** Returns the number of the desktop the given shell window is currently on, + ** or -1 if no desktop information is available (or if the window is sticky, + ** ie., it is on all desktops). + */ + long QueryDesktop(Display *display, Widget shell) + { + static Atom wmDesktopAtom = -1; + + if (wmDesktopAtom == -1) + wmDesktopAtom = XInternAtom(display, "_NET_WM_DESKTOP", True); + + if (wmDesktopAtom != None) { + return queryDesktop(display, XtWindow(shell), wmDesktopAtom); + } + return -1; /* No desktop information */ + } Index: util/misc.h =================================================================== RCS file: /cvsroot/nedit/nedit/util/misc.h,v retrieving revision 1.22 diff -c -r1.22 misc.h *** util/misc.h 29 Jan 2004 10:53:36 -0000 1.22 --- util/misc.h 3 Jun 2004 10:47:36 -0000 *************** *** 95,99 **** --- 95,101 ---- void AddMouseWheelSupport(Widget w); void RadioButtonChangeState(Widget widget, Boolean state, Boolean notify); void CloseAllPopupsFor(Widget shell); + long QueryCurrentDesktop(Display *display, Window rootWindow); + long QueryDesktop(Display *display, Widget shell); #endif /* NEDIT_MISC_H_INCLUDED */