summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorBerke Viktor <berkeviktor@aol.com>2012-06-02 04:28:37 +0200
committerBerke Viktor <berkeviktor@aol.com>2012-06-02 04:28:37 +0200
commit2f6eccd87373fd19cdc35af32dfbe8565f10653c (patch)
treec5c7564d5da28b2341ea4c6e122f7dfba57a94ce /src
parente012c9e5a77ec2361dfe33ed393f7156570e650a (diff)
Restore XChat-WDK from tray when only one instance is allowed to run and X-Tray is used
Diffstat (limited to 'src')
-rw-r--r--src/common/xchat.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/common/xchat.c b/src/common/xchat.c
index 22c4eddb..0cfd422e 100644
--- a/src/common/xchat.c
+++ b/src/common/xchat.c
@@ -902,6 +902,39 @@ xchat_execv (char * const argv[])
 #endif
 }
 
+#ifdef WIN32
+static void
+xchat_restore_window (HWND xchat_window)
+{
+	/* ShowWindow (xchat_window, SW_RESTORE); another way, but works worse */
+	SendMessage (xchat_window, WM_SYSCOMMAND, SC_RESTORE, 0);
+	SetForegroundWindow (xchat_window);
+}
+
+BOOL CALLBACK
+enum_windows_impl (HWND current_window, LPARAM lParam)
+{
+	TCHAR buffer[10];
+	ZeroMemory (&buffer, sizeof (buffer));
+
+	if (!current_window)
+	{
+		return TRUE;
+	}
+
+	GetWindowText (current_window, buffer, 10);
+	if (stricmp (buffer, "xchat-wdk") == 0)		/* We've found it, stop */
+	{
+		xchat_restore_window (current_window);
+		return FALSE;
+	}
+	else										/* Keep searching */
+	{
+		return TRUE;
+	}
+}
+#endif
+
 int
 main (int argc, char *argv[])
 {
@@ -937,7 +970,20 @@ main (int argc, char *argv[])
 
 		if (error == ERROR_ALREADY_EXISTS || mutex == NULL)
 		{
-			return 1;
+			/* restoring the XChat window from the tray via the taskbar icon
+			 * only works correctly when X-Tray is used, but it's not a big deal
+			 * since you can only minimize XChat to tray via the taskbar if you
+			 * use X-Tray*/
+			if (xtray_mode ())
+			{
+				/* FindWindow() doesn't support wildcards so we check all the open windows */
+				EnumWindows (enum_windows_impl, NULL);
+				return 0;
+			}
+			else
+			{
+				return 1;
+			}
 		}
 	}
 #endif