# HG changeset patch # User Sadrul Habib Chowdhury # Date 1173423877 0 # Node ID 8afc77eb6c1f5e9373a707d601a0a830ddd75e2d # Parent 567097a973c6aeaa00a02671de9ee263bed0e7a2 Fork\! diff -r 567097a973c6 -r 8afc77eb6c1f console/plugins/gntclipboard.c --- a/console/plugins/gntclipboard.c Fri Mar 09 01:44:18 2007 +0000 +++ b/console/plugins/gntclipboard.c Fri Mar 09 07:04:37 2007 +0000 @@ -30,6 +30,9 @@ #include #endif +#include +#include + #include #include @@ -39,11 +42,11 @@ #include -static gboolean stop = FALSE; +static pid_t child = 0; static gulong sig_handle; -static gpointer * +static void set_clip(gchar *string) { #ifdef HAVE_X11 @@ -54,16 +57,16 @@ Display *dpy = XOpenDisplay(NULL); if (!dpy) - return NULL; + return; ids = getenv("WINDOWID"); if (ids == NULL) - return NULL; + return; w = atoi(ids); XSetSelectionOwner(dpy, XA_PRIMARY, w, CurrentTime); XFlush(dpy); XSelectInput(dpy, w, StructureNotifyMask); - while (!stop) { - XNextEvent(dpy, &e); + while (TRUE) { + XNextEvent(dpy, &e); /* this blocks. */ req = &e.xselectionrequest; if (e.type == SelectionRequest) { XChangeProperty(dpy, @@ -83,33 +86,38 @@ XSendEvent(dpy, req->requestor, 0, 0, &respond); XFlush (dpy); } else if (e.type == SelectionClear) { - return NULL; + return; } } #endif - return NULL; + return; } static void clipboard_changed(GntWM *wm, gchar *string) { #ifdef HAVE_X11 - static GThread *thread = NULL; - if (thread) { - stop = TRUE; - thread = g_thread_join(thread); + if (child) { + kill(child, SIGTERM); } - g_thread_create((GThreadFunc)set_clip, string, TRUE, NULL); + if ((child = fork() == 0)) { + set_clip(string); + _exit(0); + } #endif } static gboolean plugin_load(GaimPlugin *plugin) { - if (!XOpenDisplay(NULL)) + if (!XOpenDisplay(NULL)) { gaim_debug_warning("gntclipboard", "Couldn't find X display\n"); - if (!getenv("WINDOWID")) + return FALSE; + } + if (!getenv("WINDOWID")) { gaim_debug_warning("gntclipboard", "Couldn't find window\n"); + return FALSE; + } sig_handle = g_signal_connect(G_OBJECT(gnt_get_clipboard()), "clipboard_changed", G_CALLBACK(clipboard_changed), NULL); return TRUE; } @@ -117,6 +125,10 @@ static gboolean plugin_unload(GaimPlugin *plugin) { + if (child) { + kill(child, SIGTERM); + child = 0; + } g_signal_handler_disconnect(G_OBJECT(gnt_get_clipboard()), sig_handle); return TRUE; } @@ -151,7 +163,6 @@ static void init_plugin(GaimPlugin *plugin) { - g_thread_init(NULL); } GAIM_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info)