diff options
author | Jon Gjengset <jon@thesquareplanet.com> | 2013-09-06 10:49:30 +0100 |
---|---|---|
committer | Jon Gjengset <jon@thesquareplanet.com> | 2013-09-06 10:54:15 +0100 |
commit | e62ede1cf0e863e0e9173d15f46a01bd6536fa11 (patch) | |
tree | 9711c363f77bdd41924d582c2e75cad492fcc350 /mktrayicon.c | |
parent | Clean up Makefile (diff) | |
download | mktrayicon-e62ede1cf0e863e0e9173d15f46a01bd6536fa11.tar.gz mktrayicon-e62ede1cf0e863e0e9173d15f46a01bd6536fa11.tar.bz2 mktrayicon-e62ede1cf0e863e0e9173d15f46a01bd6536fa11.zip |
Try to fix X threading warning
Replace pthreads with GThread and g_main_context_invoke with
gdk_threads_add_idle as suggested here:
http://stackoverflow.com/a/18651036/472927
Problem still occurs, albeit now more rarely
Diffstat (limited to 'mktrayicon.c')
-rw-r--r-- | mktrayicon.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/mktrayicon.c b/mktrayicon.c index ec337e1..4b3e955 100644 --- a/mktrayicon.c +++ b/mktrayicon.c @@ -8,10 +8,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <pthread.h> #include <sys/stat.h> -GMainContext *mainc; GtkStatusIcon *icon; char *onclick = NULL; @@ -63,7 +61,7 @@ gboolean do_quit(gpointer data) return FALSE; } -void *watch_fifo(void *argv) +gpointer watch_fifo(gpointer argv) { char *buf = malloc(1024*sizeof(char)); char *param; @@ -77,7 +75,7 @@ void *watch_fifo(void *argv) while (1) { if (stat(fifo_path, &fifo_st) != 0) { perror("FIFO does not exist, exiting\n"); - g_main_context_invoke(mainc, do_quit, fifo); + gdk_threads_add_idle(do_quit, fifo); break; } @@ -85,7 +83,7 @@ void *watch_fifo(void *argv) if (fifo == NULL) { perror("FIFO went away, exiting\n"); - g_main_context_invoke(mainc, do_quit, fifo); + gdk_threads_add_idle(do_quit, fifo); break; } @@ -122,19 +120,19 @@ void *watch_fifo(void *argv) switch (*buf) { case 'q': - g_main_context_invoke(mainc, do_quit, param); + gdk_threads_add_idle(do_quit, param); break; case 't': /* tooltip */ - g_main_context_invoke(mainc, set_tooltip, param); + gdk_threads_add_idle(set_tooltip, param); break; case 'i': /* icon */ - g_main_context_invoke(mainc, set_icon, param); + gdk_threads_add_idle(set_icon, param); break; case 'h': /* hide */ - g_main_context_invoke(mainc, set_visible, (void *)0); + gdk_threads_add_idle(set_visible, (void *)0); break; case 's': /* show */ - g_main_context_invoke(mainc, set_visible, (void *)1); + gdk_threads_add_idle(set_visible, (void *)1); break; case 'c': /* click */ if (onclick != NULL) { @@ -180,7 +178,7 @@ int main(int argc, char **argv) { char *start_icon = "none"; FILE *fifo; - pthread_t reader; + GThread *reader; gtk_init(&argc, &argv); @@ -199,8 +197,7 @@ int main(int argc, char **argv) } icon = create_tray_icon(start_icon); - mainc = g_main_context_default(); - pthread_create(&reader, NULL, watch_fifo, argv[argc-1]); + reader = g_thread_new("watch_fifo", watch_fifo, argv[argc-1]); gtk_main(); return 0; } |