summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/common/cfgfiles.c1
-rw-r--r--src/common/xchat.c30
-rw-r--r--src/common/xchat.h1
-rw-r--r--src/fe-gtk/setup.c1
4 files changed, 31 insertions, 2 deletions
diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c
index 53e0865c..e5d0eaef 100644
--- a/src/common/cfgfiles.c
+++ b/src/common/cfgfiles.c
@@ -436,6 +436,7 @@ const struct prefs vars[] = {
 	{"gui_lagometer", P_OFFINT (lagometer), TYPE_INT},
 	{"gui_license", P_OFFSET (gui_license), TYPE_STR},
 	{"gui_mode_buttons", P_OFFINT (chanmodebuttons), TYPE_BOOL},
+	{"gui_one_instance", P_OFFINT (gui_one_instance), TYPE_BOOL},
 	{"gui_pane_left_size", P_OFFINT (gui_pane_left_size), TYPE_INT},
 	{"gui_pane_right_size", P_OFFINT (gui_pane_right_size), TYPE_INT},
 	{"gui_quit_dialog", P_OFFINT (gui_quit_dialog), TYPE_BOOL},
diff --git a/src/common/xchat.c b/src/common/xchat.c
index ba2f5d41..8dca6de8 100644
--- a/src/common/xchat.c
+++ b/src/common/xchat.c
@@ -26,7 +26,9 @@
 #define WANTSOCKET
 #include "inet.h"
 
-#ifndef WIN32
+#ifdef WIN32
+#include <windows.h>
+#else
 #include <sys/wait.h>
 #include <signal.h>
 #endif
@@ -903,7 +905,11 @@ int
 main (int argc, char *argv[])
 {
 	int ret;
-	
+
+#ifdef WIN32
+	HANDLE mutex;
+#endif
+
 	srand (time (0));	/* CL: do this only once! */
 
 #ifdef SOCKS
@@ -920,6 +926,21 @@ main (int argc, char *argv[])
 
 	load_config ();
 
+#ifdef WIN32
+	if (prefs.gui_one_instance)
+	{
+		DWORD error;
+
+		mutex = CreateMutex (NULL, TRUE, "Local\xchat");
+		error = GetLastError ();
+
+		if (error == ERROR_ALREADY_EXISTS || mutex == NULL)
+		{
+			return 1;
+		}
+	}
+#endif
+
 #ifdef USE_LIBPROXY
 	libproxy_factory = px_proxy_factory_new();
 #endif
@@ -945,6 +966,11 @@ main (int argc, char *argv[])
 
 #ifdef WIN32
 	WSACleanup ();
+
+	if (prefs.gui_one_instance)
+	{
+		CloseHandle (mutex);
+	}
 #endif
 
 	return 0;
diff --git a/src/common/xchat.h b/src/common/xchat.h
index 6856d949..08177e20 100644
--- a/src/common/xchat.h
+++ b/src/common/xchat.h
@@ -186,6 +186,7 @@ struct xchatprefs
 	int gui_usermenu;
 	int gui_join_dialog;
 	int gui_quit_dialog;
+	int gui_one_instance;
 	int dialog_left;
 	int dialog_top;
 	int dialog_width;
diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c
index 66e8349e..8fbed277 100644
--- a/src/fe-gtk/setup.c
+++ b/src/fe-gtk/setup.c
@@ -403,6 +403,7 @@ static const setting advanced_settings[] =
 	{ST_TOGGLE,	N_("Display MODEs in raw form"), P_OFFINTNL(raw_modes), 0, 0, 0},
 	{ST_TOGGLE,	N_("Whois on notify"), P_OFFINTNL(whois_on_notifyonline), N_("Sends a /WHOIS when a user comes online in your notify list"), 0, 0},
 	{ST_TOGGLE,	N_("Hide join and part messages"), P_OFFINTNL(confmode), N_("Hide channel join/part messages by default"), 0, 0},
+	{ST_TOGGLE,	N_("Allow only one instance of XChat to run"), P_OFFINTNL(gui_one_instance), 0, 0, 0},
 	{ST_ENTRY,	N_("License Text:"), P_OFFSETNL(gui_license), 0, 0, sizeof prefs.gui_license},
 	{ST_HEADER,	N_("Auto Open DCC Windows"),0,0,0},
 	{ST_TOGGLE, N_("Send window"), P_OFFINTNL(autoopendccsendwindow), 0, 0, 0},