[Goodies-commits] r3350 - xfce4-notes-plugin/trunk/panel-plugin

Mike Massonnet mmassonnet at xfce.org
Thu Oct 11 00:02:04 CEST 2007


Author: mmassonnet
Date: 2007-10-10 22:02:04 +0000 (Wed, 10 Oct 2007)
New Revision: 3350

Modified:
   xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
   xfce4-notes-plugin/trunk/panel-plugin/notes.c
   xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
   xfce4-notes-plugin/trunk/panel-plugin/xfce4-popup-notes.c
   xfce4-notes-plugin/trunk/panel-plugin/xfce4-popup-notes.h
Log:
* panel-plugin/Makefile.am: Add compilation for xfce4-popup-notes.
* panel-plugin/panel-plugin.c, panel-plugin/xfce4-popup-notes.c: Add two new
  functions notes_plugin_message_received() and notes_plugin_set_selection().
* panel-plugin/panel-plugin.c(notes_plugin_new),
  panel-plugin/panel-plugin.c(notes_plugin_menu_popup): Changed the "event"
  signal with a "clicked" signal for btn_panel.


Modified: xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/Makefile.am	2007-10-10 22:01:50 UTC (rev 3349)
+++ xfce4-notes-plugin/trunk/panel-plugin/Makefile.am	2007-10-10 22:02:04 UTC (rev 3350)
@@ -1,18 +1,18 @@
-#bin_PROGRAMS = xfce4-popup-notes
-#
-#xfce4_popup_notes_SOURCES =										\
-#	xfce4-popup-notes.c											\
-#	xfce4-popup-notes.h
-#
-#xfce4_popup_notes_CFLAGS =										\
-#	$(LIBX11_CFLAGS)											\
-#	$(GTK_CFLAGS)
-#
-#xfce4_popup_notes_LDADD =										\
-#	$(LIBX11_LDFLAGS)											\
-#	$(LIBX11_LIBS)												\
-#	$(GTK_LIBS)
+bin_PROGRAMS = xfce4-popup-notes
 
+xfce4_popup_notes_SOURCES =										\
+	xfce4-popup-notes.c											\
+	xfce4-popup-notes.h
+
+xfce4_popup_notes_CFLAGS =										\
+	$(LIBX11_CFLAGS)											\
+	$(GTK_CFLAGS)
+
+xfce4_popup_notes_LDADD =										\
+	$(LIBX11_LDFLAGS)											\
+	$(LIBX11_LIBS)												\
+	$(GTK_LIBS)
+
 plugindir = $(libexecdir)/xfce4/panel-plugins
 plugin_PROGRAMS = xfce4-notes-plugin
 

Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c	2007-10-10 22:01:50 UTC (rev 3349)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c	2007-10-10 22:02:04 UTC (rev 3350)
@@ -563,7 +563,7 @@
     notes_window_new (notes_plugin);
 }
 
-void
+static void
 notes_window_menu_new (NotesWindow *notes_window)
 {
   /* Menu */
@@ -637,7 +637,7 @@
   gtk_widget_show_all (notes_window->menu);
 }
 
-void
+static void
 notes_window_menu_options_new (NotesWindow *notes_window)
 {
   DBG ("Create menu options (%p)", notes_window);

Modified: xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c	2007-10-10 22:01:50 UTC (rev 3349)
+++ xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c	2007-10-10 22:02:04 UTC (rev 3350)
@@ -25,6 +25,7 @@
 #endif
 
 #include "notes.h"
+#include "xfce4-popup-notes.h"
 
 #define PLUGIN_NAME "xfce4-notes-plugin"
 
@@ -46,8 +47,8 @@
                                                          int size);
 static void             notes_plugin_menu_new           (NotesPlugin *notes_plugin);
 
-static gboolean         notes_plugin_menu_popup         (NotesPlugin *notes_plugin,
-                                                         GdkEvent *event);
+static void             notes_plugin_menu_popup         (NotesPlugin *notes_plugin);
+
 static void             notes_plugin_menu_position      (GtkMenu *menu,
                                                          gint *x0,
                                                          gint *y0,
@@ -55,8 +56,13 @@
                                                          gpointer user_data);
 static void             notes_plugin_menu_destroy       (NotesPlugin *notes_plugin);
 
+static gboolean         notes_plugin_message_received   (GtkWidget *widget,
+                                                         GdkEventClient *ev,
+                                                         gpointer data);
+static gboolean         notes_plugin_set_selection      (NotesPlugin *notes_plugin);
 
 
+
 static void
 notes_plugin_register (XfcePanelPlugin *panel_plugin)
 {
@@ -100,11 +106,12 @@
                             G_CALLBACK (notes_plugin_free),
                             notes_plugin);
   g_signal_connect_swapped (notes_plugin->btn_panel,
-                            "event",
+                            "clicked",
                             G_CALLBACK (notes_plugin_menu_popup),
                             notes_plugin);
 
   xfce_panel_plugin_add_action_widget (panel_plugin, notes_plugin->btn_panel);
+  notes_plugin_set_selection (notes_plugin);
   gtk_widget_show_all (notes_plugin->btn_panel);
 
   return notes_plugin;
@@ -236,28 +243,20 @@
   gtk_widget_show_all (notes_plugin->menu);
 }
 
-static gboolean
-notes_plugin_menu_popup (NotesPlugin *notes_plugin,
-                         GdkEvent *event)
+static void
+notes_plugin_menu_popup (NotesPlugin *notes_plugin)
 {
-  /**
-   * If GDK_CONTROL_MASK is set the panel displays its context menu
-   * therefore we prefer to *not* popup our menu.
-   */
-  if (event->type == GDK_BUTTON_PRESS &&
-      event->button.button == 1 && !(event->button.state & GDK_CONTROL_MASK))
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (notes_plugin->btn_panel)))
     {
-      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notes_plugin->btn_panel), TRUE);
       notes_plugin_menu_new (notes_plugin);
       gtk_menu_popup (GTK_MENU (notes_plugin->menu),
                       NULL,
                       NULL,
                       (GtkMenuPositionFunc) notes_plugin_menu_position,
-                      notes_plugin,
-                      event->button.button,
-                      event->button.time);
+                      notes_plugin->panel_plugin,
+                      0,
+                      gtk_get_current_event_time ());
     }
-  return FALSE;
 }
 
 static void
@@ -267,27 +266,28 @@
                             gboolean *push_in,
                             gpointer user_data)
 {
-  NotesPlugin          *notes_plugin;
+  XfcePanelPlugin      *panel_plugin = user_data;
+  GtkWidget            *btn_panel;
   GtkRequisition        requisition;
   GtkOrientation        orientation;
 
-  notes_plugin = (NotesPlugin *)user_data;
   g_return_if_fail (GTK_IS_MENU (menu));
-  g_return_if_fail (NULL != notes_plugin);
+  btn_panel = gtk_menu_get_attach_widget (menu);
+  g_return_if_fail (GTK_IS_WIDGET (btn_panel));
 
-  orientation = xfce_panel_plugin_get_orientation (notes_plugin->panel_plugin);
+  orientation = xfce_panel_plugin_get_orientation (panel_plugin);
   gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
-  gdk_window_get_origin (notes_plugin->btn_panel->window, x, y);
+  gdk_window_get_origin (btn_panel->window, x, y);
 
   switch (orientation)
     {
     case GTK_ORIENTATION_HORIZONTAL:
-      if (*y + notes_plugin->btn_panel->allocation.height + requisition.height > gdk_screen_height ())
+      if (*y + btn_panel->allocation.height + requisition.height > gdk_screen_height ())
         /* Show menu above */
         *y -= requisition.height;
       else
         /* Show menu below */
-        *y += notes_plugin->btn_panel->allocation.height;
+        *y += btn_panel->allocation.height;
 
       if (*x + requisition.width > gdk_screen_width ())
         /* Adjust horizontal position */
@@ -295,12 +295,12 @@
       break;
 
     case GTK_ORIENTATION_VERTICAL:
-      if (*x + notes_plugin->btn_panel->allocation.width + requisition.width > gdk_screen_width ())
+      if (*x + btn_panel->allocation.width + requisition.width > gdk_screen_width ())
         /* Show menu on the right */
         *x -= requisition.width;
       else
         /* Show menu on the left */
-        *x += notes_plugin->btn_panel->allocation.width;
+        *x += btn_panel->allocation.width;
 
       if (*y + requisition.height > gdk_screen_height ())
         /* Adjust vertical position */
@@ -324,3 +324,68 @@
 
 XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (notes_plugin_register);
 
+
+
+/* Handle user messages from xfce4-popup-notes command */
+
+static gboolean
+notes_plugin_message_received (GtkWidget *widget,
+                               GdkEventClient *ev,
+                               gpointer user_data)
+{
+  NotesPlugin        *notes_plugin = user_data;
+
+  DBG ("Message received");
+  if (G_LIKELY (ev->data_format == 8 && *(ev->data.b) != '\0'))
+    {
+      if (!g_ascii_strcasecmp (XFCE_NOTES_MESSAGE, ev->data.b))
+        {
+          DBG ("`%s'", ev->data.b);
+          xfce_panel_plugin_set_panel_hidden (notes_plugin->panel_plugin,
+                                              FALSE);
+          while (gtk_events_pending ())
+	    gtk_main_iteration ();
+          gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notes_plugin->btn_panel),
+                                        TRUE);
+          return TRUE;
+        }
+    }
+
+  return FALSE;
+}
+
+static gboolean
+notes_plugin_set_selection (NotesPlugin *notes_plugin)
+{
+  GdkScreen          *gscreen;
+  gchar              *selection_name;
+  Atom                selection_atom;
+  GtkWidget          *win;
+  Window              id;
+
+  win = gtk_invisible_new ();
+  gtk_widget_realize (win);
+  id = GDK_WINDOW_XID (GTK_WIDGET (win)->window);
+
+  gscreen = gtk_widget_get_screen (win);
+  selection_name = g_strdup_printf (XFCE_NOTES_SELECTION"%d",
+                                    gdk_screen_get_number (gscreen));
+  selection_atom = XInternAtom (GDK_DISPLAY (), selection_name, FALSE);
+
+  if (XGetSelectionOwner (GDK_DISPLAY (), selection_atom))
+    {
+      gtk_widget_destroy (win);
+      return FALSE;
+    }
+
+  XSelectInput (GDK_DISPLAY (), id, PropertyChangeMask);
+  XSetSelectionOwner (GDK_DISPLAY (), selection_atom, id, GDK_CURRENT_TIME);
+
+  g_signal_connect (win,
+                    "client-event",
+                    G_CALLBACK (notes_plugin_message_received),
+                    notes_plugin);
+
+  return TRUE;
+}
+

Modified: xfce4-notes-plugin/trunk/panel-plugin/xfce4-popup-notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/xfce4-popup-notes.c	2007-10-10 22:01:50 UTC (rev 3349)
+++ xfce4-notes-plugin/trunk/panel-plugin/xfce4-popup-notes.c	2007-10-10 22:02:04 UTC (rev 3350)
@@ -20,74 +20,64 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-#include <gtk/gtk.h>
-#include <glib.h>
-#include <gdk/gdkx.h>
-#include <X11/Xlib.h>
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
 
 #include "xfce4-popup-notes.h"
 
 
 
 static gboolean
-xfce4_check_is_running (GtkWidget *widget, Window *xid)
+notes_plugin_check_is_running (GtkWidget *widget,
+                               Window *xid)
 {
-    GdkScreen *gscreen;
-    gchar selection_name[32];
-    Atom selection_atom;
+  GdkScreen          *gscreen;
+  gchar              *selection_name;
+  Atom                selection_atom;
 
-    gscreen = gtk_widget_get_screen (widget);
-    g_snprintf (selection_name, 
-                sizeof (selection_name),
-                XFCE_NOTES_SELECTION"%d",
-                gdk_screen_get_number (gscreen));
-    selection_atom = XInternAtom (GDK_DISPLAY (), selection_name, FALSE);
+  gscreen = gtk_widget_get_screen (widget);
+  selection_name = g_strdup_printf (XFCE_NOTES_SELECTION"%d",
+                                    gdk_screen_get_number (gscreen));
+  selection_atom = XInternAtom (GDK_DISPLAY (), selection_name, FALSE);
 
-    if ((*xid = XGetSelectionOwner (GDK_DISPLAY (), selection_atom)))
-        return TRUE;
+  if ((*xid = XGetSelectionOwner (GDK_DISPLAY (), selection_atom)))
+    return TRUE;
 
-    return FALSE;
+  return FALSE;
 }
 
-int
-main (int argc, char *argv[])
+gint
+main (gint argc, gchar *argv[])
 {
-    GdkEventClient gev;
-    GtkWidget *win;
-    Window id;
+  GdkEventClient        gev;
+  GtkWidget            *win;
+  Window                id;
 
-    gtk_init (&argc, &argv);
+  gtk_init (&argc, &argv);
 
-    win = gtk_invisible_new ();
-    gtk_widget_realize (win);
+  win = gtk_invisible_new ();
+  gtk_widget_realize (win);
 
-    gev.type = GDK_CLIENT_EVENT;
-    gev.window = win->window;
-    gev.send_event = TRUE;
-    gev.message_type = gdk_atom_intern ("STRING", FALSE);
-    gev.data_format = 8;
-    strcpy (gev.data.b, XFCE_NOTES_MESSAGE);
+  gev.type              = GDK_CLIENT_EVENT;
+  gev.window            = win->window;
+  gev.send_event        = TRUE;
+  gev.message_type      = gdk_atom_intern ("STRING", FALSE);
+  gev.data_format       = 8;
+  g_snprintf (gev.data.b, sizeof (gev.data.b), XFCE_NOTES_MESSAGE);
 
-    if (xfce4_check_is_running (win, &id))
-      {
-        gdk_event_send_client_message ((GdkEvent *)&gev, (GdkNativeWindow)id);
-      }
-    else
-      {
-        g_warning ("Can't find the xfce4-panel notes to popup.\n");
-      }
-    gdk_flush ();
+  if (notes_plugin_check_is_running (win, &id))
+    gdk_event_send_client_message ((GdkEvent *)&gev, (GdkNativeWindow)id);
+  else
+    g_warning ("Can't find the xfce4-notes-plugin.\n");
+  gdk_flush ();
 
-    gtk_widget_destroy (win);
+  gtk_widget_destroy (win);
 
-    return FALSE;
+  return FALSE;
 }
 

Modified: xfce4-notes-plugin/trunk/panel-plugin/xfce4-popup-notes.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/xfce4-popup-notes.h	2007-10-10 22:01:50 UTC (rev 3349)
+++ xfce4-notes-plugin/trunk/panel-plugin/xfce4-popup-notes.h	2007-10-10 22:02:04 UTC (rev 3350)
@@ -20,21 +20,16 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-
 #ifndef __XFCE4_POPUP_NOTES_H__
 #define __XFCE4_POPUP_NOTES_H__
 
 #ifndef XFCE_NOTES_MESSAGE
-#define XFCE_NOTES_MESSAGE    "xfce4-notes-popup"
-#endif /* XFCE_NOTES_MESSAGE */
+#define XFCE_NOTES_MESSAGE    "xfce4-popup-notes"
+#endif
 
 #ifndef XFCE_NOTES_SELECTION
-#define XFCE_NOTES_SELECTION  "XFCE_NOTES_SEL"
-#endif /* XFCE_NOTES_SELECTION */
+#define XFCE_NOTES_SELECTION  "XFCE_NOTES_SELECTION"
+#endif
 
-#endif /* __XFCE4_POPUP_NOTES_H__ */
+#endif
 




More information about the Goodies-commits mailing list