[Xfce4-commits] <xfce4-embed-plugin:master> Added "focus" menu item.

David Schneider noreply at xfce.org
Sun Jan 1 21:44:32 CET 2012


Updating branch refs/heads/master
         to 9778a3d6f477b7dbf211b27cc9daee005a1f56a0 (commit)
       from 1ebb6b3a04af7ac92a1d2729bb39c07d5fc9055b (commit)

commit 9778a3d6f477b7dbf211b27cc9daee005a1f56a0
Author: David Schneider <dnschneid at gmail.com>
Date:   Fri Dec 30 16:02:34 2011 -0500

    Added "focus" menu item.

 TODO                 |    2 +-
 panel-plugin/embed.c |   26 ++++++++++++++++++++++++++
 panel-plugin/embed.h |    1 +
 panel-plugin/ewmh.c  |    6 ++++++
 panel-plugin/ewmh.h  |    1 +
 5 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/TODO b/TODO
index 33a9db0..7503d0c 100644
--- a/TODO
+++ b/TODO
@@ -9,5 +9,5 @@ Fake socket no longer necessary?
       to work.
     * Might be worth doing for simplicity, but not high priority
 Option to enable click-to-activate keyboard input
-Menu item to activate keyboard input
+Fix plugin destruction destroying window
 Label font
diff --git a/panel-plugin/embed.c b/panel-plugin/embed.c
index 27133a5..a6d07a4 100644
--- a/panel-plugin/embed.c
+++ b/panel-plugin/embed.c
@@ -225,6 +225,9 @@ embed_new (XfcePanelPlugin *plugin)
   embed->embed_menu = gtk_image_menu_item_new_with_mnemonic (_("_Embed"));
   gtk_widget_show (embed->embed_menu);
 
+  /* focus menu item, not shown by default */
+  embed->focus_menu = gtk_image_menu_item_new_with_mnemonic (_("_Focus"));
+
   return embed;
 }
 
@@ -270,6 +273,20 @@ embed_free (XfcePanelPlugin *plugin, EmbedPlugin *embed)
 
 
 
+/* Callback for the focus menu button. Activates focus on the plugin. */
+static void
+embed_focus_menu (GtkMenuItem *focus_menu, EmbedPlugin *embed)
+{
+  if (embed->plug_is_gtkplug) {
+    if (embed->socket)
+      xfce_panel_plugin_focus_widget (embed->plugin, embed->socket);
+  } else if (embed->plug) {
+    focus_window (embed->disp, embed->plug);
+  }
+}
+
+
+
 /* Callback when the orientation of the panel is changed. */
 static void
 embed_orientation_changed (XfcePanelPlugin *plugin,
@@ -545,6 +562,7 @@ embed_plug_added (GtkWidget *socket, EmbedPlugin *embed)
   /* Flip the menu items */
   gtk_widget_hide (embed->embed_menu);
   gtk_widget_show (embed->popout_menu);
+  gtk_widget_show (embed->focus_menu);
 
   /* Stop any searching that is going on */
   embed_stop_search (embed);
@@ -614,6 +632,7 @@ embed_plug_removed (GtkWidget *socket, EmbedPlugin *embed)
 
   /* Flip the menu items */
   gtk_widget_hide (embed->popout_menu);
+  gtk_widget_hide (embed->focus_menu);
   gtk_widget_show (embed->embed_menu);
 
   /* Assume the socket will be destroyed after this returns, so get rid of our
@@ -849,6 +868,13 @@ embed_construct (XfcePanelPlugin *plugin)
   g_signal_connect (G_OBJECT (embed->embed_menu), "activate",
                     G_CALLBACK (embed_embed_menu), embed);
 
+  /* Add the "focus" menu item */
+  xfce_panel_plugin_menu_insert_item (plugin,
+                                      GTK_MENU_ITEM (embed->focus_menu));
+  g_signal_connect (G_OBJECT (embed->focus_menu), "activate",
+                    G_CALLBACK (embed_focus_menu), embed);
+
+
   /* show the configure menu item and connect signal */
   xfce_panel_plugin_menu_show_configure (plugin);
   g_signal_connect (G_OBJECT (plugin), "configure-plugin",
diff --git a/panel-plugin/embed.h b/panel-plugin/embed.h
index d0e3918..3180b00 100644
--- a/panel-plugin/embed.h
+++ b/panel-plugin/embed.h
@@ -33,6 +33,7 @@ typedef struct
     GtkWidget       *socket;
     GtkWidget       *popout_menu;
     GtkWidget       *embed_menu;
+    GtkWidget       *focus_menu;
 
     /* panel data */
     GdkNativeWindow  plug;
diff --git a/panel-plugin/ewmh.c b/panel-plugin/ewmh.c
index e65e61a..f8dd093 100644
--- a/panel-plugin/ewmh.c
+++ b/panel-plugin/ewmh.c
@@ -269,3 +269,9 @@ void show_window (Display *disp, Window win)
     client_msg(disp, win, "_NET_WM_DESKTOP", *cur_desktop);
     g_free(cur_desktop);
 }
+
+void focus_window (Display *disp, Window win)
+{
+    XSetInputFocus (disp, win, RevertToNone, CurrentTime);
+    XFlush (disp);
+}
diff --git a/panel-plugin/ewmh.h b/panel-plugin/ewmh.h
index f91b1a2..2a59337 100644
--- a/panel-plugin/ewmh.h
+++ b/panel-plugin/ewmh.h
@@ -33,6 +33,7 @@ void reparent_window (Display *disp, Window win, Window parent,
 		      gint width, gint height);
 void resize_window (Display *disp, Window win, gint width, gint height);
 void show_window (Display *disp, Window win);
+void focus_window (Display *disp, Window win);
 
 G_END_DECLS
 


More information about the Xfce4-commits mailing list