]> Dogcows Code - chaz/openbox/blobdiff - openbox/client.c
fix timers so that they work when theres lots of repeating timers in the queue..
[chaz/openbox] / openbox / client.c
index 517482c7aa3a7c939485a6f40229ddd1df986e7b..c90c39bf7cceefa6cc658e38c828a0dd0d203189 100644 (file)
 #  include <unistd.h>
 #endif
 
+#ifdef HAVE_SIGNAL_H
+#  include <signal.h> /* for kill() */
+#endif
+
 #include <glib.h>
 #include <X11/Xutil.h>
 
@@ -598,6 +602,12 @@ void client_manage(Window window)
     /* update the list hints */
     client_set_list();
 
+    /* watch for when the application stops responding.  only do this for
+       normal windows, i.e. windows which have titlebars and close buttons 
+       and things like that */
+    if (self->ping && client_normal(self))
+        ping_start(self, client_ping_event);
+
     /* free the ObAppSettings shallow copy */
     g_free(settings);
 
@@ -679,6 +689,10 @@ void client_unmanage(ObClient *self)
     /* remove the window from our save set */
     XChangeSaveSet(ob_display, self->window, SetModeDelete);
 
+    /* stop pinging the window */
+    if (self->ping && client_normal(self))
+        ping_stop(self);
+
     /* update the focus lists */
     focus_order_remove(self);
     if (client_focused(self)) {
@@ -1951,7 +1965,10 @@ void client_update_title(ObClient *self)
 
     if (self->not_responding) {
         data = visible;
-        visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
+        if (self->close_tried_term)
+            visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
+        else
+            visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
         g_free(data);
     }
 
@@ -1980,7 +1997,10 @@ void client_update_title(ObClient *self)
 
     if (self->not_responding) {
         data = visible;
-        visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
+        if (self->close_tried_term)
+            visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
+        else
+            visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
         g_free(data);
     }
 
@@ -2244,6 +2264,7 @@ static void client_get_session_ids(ObClient *self)
 
     if (got) {
         gchar localhost[128];
+        guint32 pid;
 
         gethostname(localhost, 127);
         localhost[127] = '\0';
@@ -2251,6 +2272,11 @@ static void client_get_session_ids(ObClient *self)
             self->client_machine = s;
         else
             g_free(s);
+
+        /* see if it has the PID set too (the PID requires that the
+           WM_CLIENT_MACHINE be set) */
+        if (PROP_GET32(self->window, net_wm_pid, cardinal, &pid))
+            self->pid = pid;
     }
 }
 
@@ -3184,6 +3210,12 @@ static void client_ping_event(ObClient *self, gboolean dead)
 {
     self->not_responding = dead;
     client_update_title(self);
+
+    if (!dead) {
+        /* try kill it nicely the first time again, if it started responding
+           at some point */
+        self->close_tried_term = FALSE;
+    }
 }
 
 void client_close(ObClient *self)
@@ -3193,23 +3225,39 @@ void client_close(ObClient *self)
     /* in the case that the client provides no means to requesting that it
        close, we just kill it */
     if (!self->delete_window)
+        /* don't use client_kill(), we should only kill based on PID in
+           response to a lack of PING replies */
+        XKillClient(ob_display, self->window);
+    else if (self->not_responding)
         client_kill(self);
-
-    if (self->not_responding)
-        client_kill(self);
-    else {
+    else
+        /* request the client to close with WM_DELETE_WINDOW */
         PROP_MSG_TO(self->window, self->window, wm_protocols,
                     prop_atoms.wm_delete_window, event_curtime, 0, 0, 0,
                     NoEventMask);
-
-        if (self->ping)
-            ping_start(self, client_ping_event);
-    }
 }
 
 void client_kill(ObClient *self)
 {
-    XKillClient(ob_display, self->window);
+    if (!self->client_machine && self->pid) {
+        /* running on the local host */
+        if (!self->close_tried_term) {
+            ob_debug("killing window 0x%x with pid %lu, with SIGTERM\n",
+                     self->window, self->pid);
+            kill(self->pid, SIGTERM);
+            self->close_tried_term = TRUE;
+
+            /* show that we're trying to kill it */
+            client_update_title(self);
+        }
+        else {
+            ob_debug("killing window 0x%x with pid %lu, with SIGKILL\n",
+                     self->window, self->pid);
+            kill(self->pid, SIGKILL); /* kill -9 */
+        }
+    }
+    else
+        XKillClient(ob_display, self->window);
 }
 
 void client_hilite(ObClient *self, gboolean hilite)
This page took 0.023788 seconds and 4 git commands to generate.