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

mickey at sita.openmoko.org mickey at sita.openmoko.org
Mon Apr 9 14:06:27 CEST 2007


Author: mickey
Date: 2007-04-09 14:06:26 +0200 (Mon, 09 Apr 2007)
New Revision: 1713

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/mokodesktop.h
   trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/stylusmenu.c
Log:
openmoko-panel-mainmenu: show popup menu, if power button is held for more than 1 second


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-04-08 16:59:10 UTC (rev 1712)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/buttonactions.c	2007-04-09 12:06:26 UTC (rev 1713)
@@ -18,10 +18,15 @@
  */
 #include "buttonactions.h"
 
+#include <gtk/gtklabel.h>
+#include <gtk/gtkmenu.h>
+#include <gtk/gtkmenuitem.h>
+
 #include <fcntl.h>
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <linux/input.h>
@@ -35,16 +40,19 @@
 #else
     #define AUX_BUTTON_EVENT_PATH "/dev/input/event0"
     #define AUX_BUTTON_KEYCODE 0x25
-    #define POWER_BUTTON_EVENT_PATH "/dev/input/event2"
+    #define POWER_BUTTON_EVENT_PATH "/dev/input/event1"
     #define POWER_BUTTON_KEYCODE 0x25
 #endif
 
 GPollFD aux_fd;
 GPollFD power_fd;
 
-GTimer* aux_timer;
-GTimer* power_timer;
+GTimer* aux_timer = 0;
+GTimer* power_timer = 0;
 
+GtkWidget* aux_menu = 0;
+GtkWidget* power_menu = 0;
+
 gboolean panel_mainmenu_install_watcher()
 {
     int auxfd = open( AUX_BUTTON_EVENT_PATH, O_RDONLY );
@@ -150,9 +158,66 @@
 }
 
 
+
+void panel_mainmenu_popup_positioning_cb( GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer user_data )
+{
+    gint menu_width;
+    gint menu_height;
+    gtk_widget_get_size_request( GTK_WIDGET(menu), &menu_width, &menu_height );
+    gint screen_width = gdk_screen_width();
+    gint screen_height = gdk_screen_height();
+
+    if ( GTK_WIDGET(menu) == aux_menu )
+    {
+        *x = 0;
+        *y = 0;
+    }
+    else if ( GTK_WIDGET(menu) == power_menu )
+    {
+        *x = screen_width - menu_width;
+        *y = screen_height - menu_height;
+    }
+    else
+        g_assert( FALSE ); // fail here if called for unknown menu
+}
+
+void panel_mainmenu_popup_selected_lock( GtkMenuItem* menu, gpointer user_data )
+{
+    system( "apm -s");
+}
+
+void panel_mainmenu_popup_selected_poweroff( GtkMenuItem* menu, gpointer user_data )
+{
+    system( "/bin/sh poweroff");
+}
+
 gboolean panel_mainmenu_power_timeout( guint timeout )
 {
     g_debug( "power pressed for %d", timeout );
+    if ( timeout < 1 )
+    {
+        // close current application
+    }
+    else
+    {
+        // show popup menu requesting for actions
+        if ( !aux_menu )
+        {
+            aux_menu = gtk_menu_new();
+            GtkWidget* lock = gtk_menu_item_new_with_label( "Lock" );
+            g_signal_connect( G_OBJECT(lock), "activate", G_CALLBACK(panel_mainmenu_popup_selected_lock), NULL );
+            gtk_menu_shell_append( GTK_MENU_SHELL(aux_menu), lock );
+            GtkWidget* flightmode = gtk_menu_item_new_with_label( "Flight Mode" );
+            gtk_menu_shell_append( GTK_MENU_SHELL(aux_menu), flightmode );
+            GtkWidget* profilelist = gtk_menu_item_new_with_label( "<Profile List>" );
+            gtk_menu_shell_append( GTK_MENU_SHELL(aux_menu), profilelist );
+            GtkWidget* poweroff = gtk_menu_item_new_with_label( "Power Off" );
+            g_signal_connect( G_OBJECT(poweroff), "activate", G_CALLBACK(panel_mainmenu_popup_selected_poweroff), NULL );
+            gtk_menu_shell_append( GTK_MENU_SHELL(aux_menu), poweroff );
+            gtk_widget_show_all( GTK_WIDGET(aux_menu) );
+        }
+        gtk_menu_popup( GTK_MENU(aux_menu), NULL, NULL, panel_mainmenu_popup_positioning_cb, 0, 0, GDK_CURRENT_TIME );
+    }
     return FALSE;
 }
 

Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/mokodesktop.h
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/mokodesktop.h	2007-04-08 16:59:10 UTC (rev 1712)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/mokodesktop.h	2007-04-09 12:06:26 UTC (rev 1713)
@@ -5,7 +5,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <fcntl.h> 
+#include <fcntl.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -15,10 +15,10 @@
 
 #include <libmb/mb.h>
 
-#define VFOLDERDIR 		"/usr/share/matchbox"
-#define DD_DIR 		 	"/usr/share/applications/" 
+#define VFOLDERDIR 		"/usr/local/share/matchbox"
+#define DD_DIR 		 	"/usr/local/share/applications/"
 
-#define PIXMAP_PATH 	"/usr/share/pixmaps"
+#define PIXMAP_PATH 	"/usr/local/share/pixmaps"
 
 #ifdef DEBUG
 #define DBG(txt, args... ) fprintf(stderr, "DT-DEBUG: " txt , ##args )
@@ -27,7 +27,7 @@
 #endif
 
 
-enum {	   
+enum {
   ITEM_TYPE_UNKNOWN = 0,
   ITEM_TYPE_ROOT,
 
@@ -39,15 +39,15 @@
   ITEM_TYPE_FOLDER,  /* Same as 'official' Directory */
   ITEM_TYPE_LINK,    /* URL  */
 
-  ITEM_TYPE_FSDEVICE, 
-  ITEM_TYPE_MIMETYPE, 
-  ITEM_TYPE_DIRECTORY, 
-  ITEM_TYPE_SERVICE, 
+  ITEM_TYPE_FSDEVICE,
+  ITEM_TYPE_MIMETYPE,
+  ITEM_TYPE_DIRECTORY,
+  ITEM_TYPE_SERVICE,
   ITEM_TYPE_SERVICETYPE ,
 
   ITEM_TYPE_TASK_FOLDER, 		/* Not official */
   ITEM_TYPE_PREVIOUS,
-  ITEM_TYPE_CNT, 
+  ITEM_TYPE_CNT,
 };
 
 typedef void (*MokoDesktopCB)( void *data1, void *data2 ) ;
@@ -65,10 +65,10 @@
 
   MokoDesktopCB activate_cb;
 
-  struct _mokodesktop_item *item_next_sibling; 
-  struct _mokodesktop_item *item_prev_sibling; 
-  struct _mokodesktop_item *item_child; 
-  struct _mokodesktop_item *item_parent; 
+  struct _mokodesktop_item *item_next_sibling;
+  struct _mokodesktop_item *item_prev_sibling;
+  struct _mokodesktop_item *item_child;
+  struct _mokodesktop_item *item_parent;
 
 } MokoDesktopItem;
 

Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/stylusmenu.c
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/stylusmenu.c	2007-04-08 16:59:10 UTC (rev 1712)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-mainmenu/src/stylusmenu.c	2007-04-09 12:06:26 UTC (rev 1713)
@@ -21,24 +21,25 @@
 //#include "callbacks.h"
 
 static GtkImageMenuItem *moko_build_new_menu_item (const char *icon_name, const char *icon_path);
+static void moko_stylus_menu_activate_item(GtkWidget* widget, const char* name);
 
 void
 moko_stylus_menu_build (GtkMenu *menu, MokoDesktopItem *item)
 {
   //GtkMenu *sub_menu;
   GtkImageMenuItem *menu_item;
-    
+
   MokoDesktopItem *item_new;
 g_debug ("menu build-------------------------V");
   mokodesktop_items_enumerate_siblings(item->item_child, item_new)
-  { 
-     
+  {
+
      if (access (item_new->icon_name, 0) == 0)
      {
          g_debug ("item patch %s", item_new->icon_name);
          menu_item = moko_build_new_menu_item (item_new->name, item_new->icon_name);
      }
-     else 
+     else
      {
        char path[512];
        snprintf (path, 512, "%s/%s", PIXMAP_PATH, item_new->icon_name);
@@ -66,7 +67,7 @@
         {
           menu_item = moko_build_new_menu_item (tmp_item->name, tmp_item->icon_name);
         }
-        else 
+        else
         {
           char path[512];
           snprintf (path, 512, "%s/%s", PIXMAP_PATH, tmp_item->icon_name);
@@ -79,9 +80,9 @@
 	     //moko_fill_model(self->list_store, path, item_new->name, item_new);
            }
          }
-         
+
 		 if (tmp_item->type == ITEM_TYPE_DOTDESKTOP_ITEM ||tmp_item->type == ITEM_TYPE_APP )
-          // g_signal_connect (menu_item, "activate" ,G_CALLBACK(moko_stylus_menu_activate_item), tmp_item->data);
+            g_signal_connect (menu_item, "activate" ,G_CALLBACK(moko_stylus_menu_activate_item), tmp_item->data);
          gtk_menu_shell_append( GTK_MENU_SHELL(sub_menu), GTK_WIDGET(menu_item) );
          gtk_widget_show (GTK_WIDGET(menu_item));
       }
@@ -106,15 +107,20 @@
     item = gtk_image_menu_item_new_with_label (name);
     gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(item), image);
     gtk_widget_show (GTK_WIDGET(item));
-    
+
     return GTK_IMAGE_MENU_ITEM(item);
 }
 
+static void moko_stylus_menu_activate_item(GtkWidget* widget, const char* name)
+{
+    g_debug( "item activated: %s", name );
+}
+
 void
 moko_menu_position_cb (GtkMenu *menu, int *x, int *y, gboolean *push_in, GtkWidget *data)
 {
     GtkAllocation* allocation = &GTK_WIDGET(data)->allocation;
-    
+
     *x = allocation->x;
     *y = allocation->y + allocation->height;
 





More information about the commitlog mailing list