summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Gjengset <jon@thesquareplanet.com>2013-09-06 10:49:30 +0100
committerJon Gjengset <jon@thesquareplanet.com>2013-09-06 10:54:15 +0100
commite62ede1cf0e863e0e9173d15f46a01bd6536fa11 (patch)
tree9711c363f77bdd41924d582c2e75cad492fcc350
parentClean up Makefile (diff)
downloadmktrayicon-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
-rw-r--r--README.md14
-rw-r--r--mktrayicon.c23
2 files changed, 23 insertions, 14 deletions
diff --git a/README.md b/README.md
index e290bd5..94a0caf 100644
--- a/README.md
+++ b/README.md
@@ -80,13 +80,25 @@ without blocking the GUI thread, as GTK seems to not like that. They've
deprecated most of the threading stuff, and only left this
`g_main_context_invoke` mess, which doesn't even seem to work all of the time.
-So, every now and again, the program will just die completely with the message:
+So, every now and again, the program will just die completely with one of the
+following messages:
```
+Xlib: sequence lost (0x100c1 > 0xc3) in reply type 0x1c!
+[xcb] Unknown request in queue while dequeuing
+[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
+[xcb] Aborting, sorry about that.
+
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
mktrayicon: xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
+
+Xlib: sequence lost (0x100c1 > 0xc3) in reply type 0x1c!
+[xcb] Unknown request in queue while dequeuing
+[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
+[xcb] Aborting, sorry about that.
+mktrayicon: xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
```
If someone has a genious way to fix this, patches are welcome.
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;
}
bgstack15