From fa10a27e7ca3e0955dee527afc3f99069d1d327c Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Mon, 5 Dec 2011 13:24:44 +0000 Subject: [PATCH] Wait during a second before spawning a child keyboard again --- po/fr.po | 12 ++++++------ src/applets/keyboard.c | 44 +++++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/po/fr.po b/po/fr.po index 070ec7c..929aa35 100644 --- a/po/fr.po +++ b/po/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Panel 0.0.5\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-12-05 08:03-0500\n" +"POT-Creation-Date: 2011-12-05 08:17-0500\n" "PO-Revision-Date: 2010-04-22 12:45+0200\n" "Last-Translator: Pierre Pronchery \n" "Language-Team: French\n" @@ -84,23 +84,23 @@ msgstr "GPS actif" msgid "GSM is enabled" msgstr "GSM actif" -#: ../src/applets/keyboard.c:119 +#: ../src/applets/keyboard.c:121 msgid "Show keyboard" msgstr "Afficher le clavier" -#: ../src/applets/keyboard.c:278 ../src/applets/lock.c:114 ../src/run.c:108 +#: ../src/applets/keyboard.c:283 ../src/applets/lock.c:114 ../src/run.c:108 msgid "Command:" msgstr "Commande :" -#: ../src/applets/keyboard.c:289 +#: ../src/applets/keyboard.c:294 msgid "Width:" msgstr "Largeur :" -#: ../src/applets/keyboard.c:300 +#: ../src/applets/keyboard.c:305 msgid "Height:" msgstr "Hauteur :" -#: ../src/applets/keyboard.c:310 +#: ../src/applets/keyboard.c:315 msgid "Keep ratio" msgstr "Respecter les proportions" diff --git a/src/applets/keyboard.c b/src/applets/keyboard.c index 6c83e17..8170df6 100644 --- a/src/applets/keyboard.c +++ b/src/applets/keyboard.c @@ -37,6 +37,7 @@ /* types */ typedef struct _Keyboard { + guint source; GPid pid; /* settings */ @@ -108,6 +109,7 @@ static GtkWidget * _keyboard_init(PanelApplet * applet) if((keyboard = malloc(sizeof(*keyboard))) == NULL) return NULL; applet->priv = keyboard; + keyboard->source = 0; keyboard->pid = -1; keyboard->width = -1; keyboard->height = -1; @@ -125,7 +127,7 @@ static GtkWidget * _keyboard_init(PanelApplet * applet) applet->helper->icon_size); gtk_container_add(GTK_CONTAINER(ret), image); gtk_widget_show_all(ret); - g_idle_add(_init_idle, applet); + keyboard->source = g_idle_add(_init_idle, applet); return ret; } @@ -165,6 +167,7 @@ static gboolean _init_idle(gpointer data) Keyboard * keyboard = applet->priv; unsigned long xid; + keyboard->source = 0; if(keyboard->window != NULL) return FALSE; if(_keyboard_spawn(applet, &xid) != 0) @@ -193,8 +196,10 @@ static void _keyboard_destroy(PanelApplet * applet) { Keyboard * keyboard = applet->priv; + if(keyboard->source > 0) + g_source_remove(keyboard->source); if(keyboard->pid > 0) - g_spawn_close_pid(keyboard->pid); /* XXX may be dead already */ + g_spawn_close_pid(keyboard->pid); free(keyboard); } @@ -382,23 +387,36 @@ static int _keyboard_spawn(PanelApplet * applet, unsigned long * xid) /* callbacks */ /* keyboard_on_child */ +static gboolean _on_child_timeout(gpointer data); + static void _keyboard_on_child(GPid pid, gint status, gpointer data) +{ + PanelApplet * applet = data; + Keyboard * keyboard = applet->priv; + +#ifdef DEBUG + fprintf(stderr, "DEBUG: %s(%u) %u\n", __func__, pid, keyboard->pid); +#endif + if(keyboard->source != 0 || keyboard->pid != pid) + return; + if(WIFEXITED(status) || WIFSIGNALED(status)) + { + g_spawn_close_pid(keyboard->pid); + keyboard->source = g_timeout_add(1000, _on_child_timeout, + applet); + } +} + +static gboolean _on_child_timeout(gpointer data) { PanelApplet * applet = data; Keyboard * keyboard = applet->priv; unsigned long xid; -#ifdef DEBUG - fprintf(stderr, "DEBUG: %s(%u) %u\n", __func__, pid, keyboard->pid); -#endif - if(keyboard->pid != pid) - return; - if(WIFEXITED(status) || WIFSIGNALED(status)) - if(_keyboard_spawn(applet, &xid) == 0) - { - gtk_socket_add_id(GTK_SOCKET(keyboard->socket), xid); - gtk_widget_show(keyboard->socket); - } + keyboard->source = 0; + if(_keyboard_spawn(applet, &xid) == 0) + gtk_socket_add_id(GTK_SOCKET(keyboard->socket), xid); + return FALSE; }