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 11:26:06 -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 11:27:08 -0000 @@ -153,11 +153,11 @@ static Widget addTab(Widget folder, WindowInfo *window, const char *string); static int compareWindowNames(const void *windowA, const void *windowB); static int getTabPosition(Widget tab); static Widget manageToolBars(Widget toolBarsForm); static void hideTearOffs(Widget menuPane); -static void CloseDocumentWindow(Widget w, WindowInfo *window, XtPointer callData); +static void closeDocumentWindow(Widget w, WindowInfo *window, XtPointer callData); static void closeTabCB(Widget w, Widget mainWin, caddr_t callData); static void raiseTabCB(Widget w, XtPointer clientData, XtPointer callData); static Widget createTextArea(Widget parent, WindowInfo *window, int rows, int cols, int emTabDist, char *delimiters, int wrapMargin, int lineNumCols); @@ -987,11 +987,15 @@ ClearRedoList(window); XmTextSetString(window->statsLine, ""); /* resets scroll pos of stats line from long file names */ UpdateStatsLine(window); DetermineLanguageMode(window, True); - RefreshTabState(window); + + /* iconify if requested */ + XtVaSetValues(window->shell, XmNiconic, True); + + RefreshTabState(window); return; } /* Free syntax highlighting patterns, if any. w/o redisplaying */ FreeHighlightingData(window); @@ -2370,11 +2374,11 @@ static void closeCB(Widget w, WindowInfo *window, XtPointer callData) { window = WidgetToWindow(w); - CloseDocumentWindow(w, window, callData); + closeDocumentWindow(w, window, callData); } #ifndef NO_SESSION_RESTART static void saveYourselfCB(Widget w, Widget appShell, XtPointer callData) { @@ -2478,10 +2482,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 window state. -- Yooden */ int IsIconic(WindowInfo *window) { unsigned long *property = NULL; unsigned long nItems; @@ -2498,10 +2509,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. @@ -3723,11 +3735,11 @@ } return True; } -static void CloseDocumentWindow(Widget w, WindowInfo *window, XtPointer callData) +static void closeDocumentWindow(Widget w, WindowInfo *window, XtPointer callData) { int nDocuments = NDocuments(window); if (nDocuments == NWindows()) { /* this is only window, then exit */