Index: source/server.c =================================================================== RCS file: /cvsroot/nedit/nedit/source/server.c,v retrieving revision 1.30 diff -U5 -r1.30 server.c --- source/server.c 23 Jun 2004 13:25:56 -0000 1.30 +++ source/server.c 15 Jul 2004 10:35:42 -0000 @@ -302,38 +302,51 @@ return False; } static WindowInfo *findWindowOnDesktop(int tabbed, long currentDesktop) { - WindowInfo *window; + WindowInfo *window; - if (currentDesktop == -1) /* No desktop information available */ - return WindowList; + 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 */ + 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! */ /* Why not? */ + + /* Return window if it is either on the current desktop or + iconized. */ + if (isLocatedOnDesktop(window, currentDesktop) + || IsIconic(window)) + { + 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) + || IsIconic(window)) + { + return window; + } + } + } + return NULL; /* No window found on current desktop -> create new window */ } static void processServerCommandString(char *string) { char *fullname, filename[MAXPATHLEN], pathname[MAXPATHLEN]; Index: source/window.c =================================================================== RCS file: /cvsroot/nedit/nedit/source/window.c,v retrieving revision 1.160 diff -U5 -r1.160 window.c --- source/window.c 13 Jun 2004 01:08:47 -0000 1.160 +++ source/window.c 15 Jul 2004 10:36:43 -0000 @@ -2478,10 +2478,17 @@ /* ** Returns true if window is iconic (as determined by the WM_STATE property ** on the shell window. I think this is the most reliable way to tell, ** but if someone has a better idea please send me a note). +** +** Note: The Motif FAQ (#264) claims that this breaks ICCCM guidelines, +** but I don't see how. The only problem I see could be WithdrawnState, +** which might or might remove the WM_STATE property entirely. But that +** just makes it a bit fuzzy, not breaking anything. +** The FAQ recommends to watch out for MapNotify/UnmapNotify events for +** determining windoe state. -- Yooden */ int IsIconic(WindowInfo *window) { unsigned long *property = NULL; unsigned long nItems; @@ -2498,10 +2505,11 @@ &nItems, &leftover, (unsigned char **)&property) != Success || nItems != 1 || property == NULL) return FALSE; result = *property == IconicState; XtFree((char *)property); + return result; } /* ** Add a window to the the window list.