r2136 - trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src

mickey at sita.openmoko.org mickey at sita.openmoko.org
Sun Jun 3 14:55:50 CEST 2007


Author: mickey
Date: 2007-06-03 14:55:50 +0200 (Sun, 03 Jun 2007)
New Revision: 2136

Modified:
   trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/buttonactions.c
Log:
openmoko-panel-mainmenu: kill topmost window on short press of power button


Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/buttonactions.c
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/buttonactions.c	2007-06-03 06:21:35 UTC (rev 2135)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/buttonactions.c	2007-06-03 12:55:50 UTC (rev 2136)
@@ -22,6 +22,10 @@
 #include <gtk/gtkmenu.h>
 #include <gtk/gtkmenuitem.h>
 
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
 #include <fcntl.h>
 #include <string.h>
 #include <errno.h>
@@ -41,9 +45,9 @@
     #define POWER_BUTTON_EVENT_PATH "/dev/input/event2"
     #define POWER_BUTTON_KEYCODE 116
 #else
-    #define AUX_BUTTON_EVENT_PATH "/dev/input/event4"
+    #define AUX_BUTTON_EVENT_PATH "/dev/input/event1"
     #define AUX_BUTTON_KEYCODE 0x25
-    #define POWER_BUTTON_EVENT_PATH "/dev/input/event3"
+    #define POWER_BUTTON_EVENT_PATH "/dev/input/event0"
     #define POWER_BUTTON_KEYCODE 0x25
 #endif
 
@@ -56,6 +60,46 @@
 GtkWidget* aux_menu = 0;
 GtkWidget* power_menu = 0;
 
+/* Borrowed from libwnck */
+static Window
+        get_window_property (Window  xwindow,
+                             Atom    atom)
+{
+    Atom type;
+    int format;
+    gulong nitems;
+    gulong bytes_after;
+    Window *w;
+    int err, result;
+    Window retval;
+
+    gdk_error_trap_push ();
+
+    type = None;
+    result = XGetWindowProperty (gdk_display,
+                                 xwindow,
+                                 atom,
+                                 0, G_MAXLONG,
+                                 False, XA_WINDOW, &type, &format, &nitems,
+                                 &bytes_after, (unsigned char **) &w);
+    err = gdk_error_trap_pop ();
+
+    if (err != Success ||
+        result != Success)
+        return None;
+
+    if (type != XA_WINDOW)
+    {
+        XFree (w);
+        return None;
+    }
+
+    retval = *w;
+    XFree (w);
+
+    return retval;
+}
+
 gboolean panel_mainmenu_install_watcher()
 {
     int auxfd = open( AUX_BUTTON_EVENT_PATH, O_RDONLY );
@@ -214,7 +258,7 @@
 {
     //FIXME talk to neod
     //FIXME notify user
-    system( "/bin/sh poweroff");
+    system( "/sbin/poweroff");
 }
 
 gboolean panel_mainmenu_power_timeout( guint timeout )
@@ -223,7 +267,33 @@
     power_timer = -1;
     if ( timeout < 1 )
     {
-        // close current application
+        Window xwindow = get_window_property( gdk_x11_get_default_root_xwindow(), gdk_x11_get_xatom_by_name("_NET_ACTIVE_WINDOW") );
+        g_debug( "active Window = %d", (int) xwindow );
+
+        Display* display = XOpenDisplay( NULL );
+
+        //xwindow = gdk_x11_drawable_get_xid (window);
+
+        XEvent xev;
+        xev.xclient.type = ClientMessage;
+        xev.xclient.serial = 0;
+        xev.xclient.send_event = True;
+        xev.xclient.display = display;
+        xev.xclient.window = xwindow;
+        xev.xclient.message_type = gdk_x11_get_xatom_by_name( "_NET_CLOSE_WINDOW" );
+        xev.xclient.format = 32;
+        xev.xclient.data.l[0] = 0;
+        xev.xclient.data.l[1] = 0;
+        xev.xclient.data.l[2] = 0;
+        xev.xclient.data.l[3] = 0;
+        xev.xclient.data.l[4] = 0;
+
+        //TODO: add timeout checking for response
+
+        XSendEvent (display, gdk_x11_get_default_root_xwindow (), False,
+                    SubstructureRedirectMask | SubstructureNotifyMask, &xev);
+        XCloseDisplay( display );
+
     }
     else
     {





More information about the commitlog mailing list