[Goodies-commits] r3689 - in xfce4-places-plugin/trunk: . panel-plugin

Diego Ongaro ongardie at xfce.org
Mon Dec 10 06:49:30 CET 2007


Author: ongardie
Date: 2007-12-10 05:49:29 +0000 (Mon, 10 Dec 2007)
New Revision: 3689

Added:
   xfce4-places-plugin/trunk/panel-plugin/xfce4-popup-places.c
   xfce4-places-plugin/trunk/panel-plugin/xfce4-popup-places.h
Modified:
   xfce4-places-plugin/trunk/ChangeLog
   xfce4-places-plugin/trunk/panel-plugin/Makefile.am
   xfce4-places-plugin/trunk/panel-plugin/view.c
Log:
2007-12-09	Diego Ongaro <ongardie at gmail.com>

* xfce4-popup-places.{c,h}, view.c, Makefile.am:
Bug #3672: popup command (thanks to Mike for the patch)


Modified: xfce4-places-plugin/trunk/ChangeLog
===================================================================
--- xfce4-places-plugin/trunk/ChangeLog	2007-12-09 21:38:27 UTC (rev 3688)
+++ xfce4-places-plugin/trunk/ChangeLog	2007-12-10 05:49:29 UTC (rev 3689)
@@ -1,6 +1,8 @@
 2007-12-09	Diego Ongaro <ongardie at gmail.com>
 
 	* *: Improve compatibility with older versions of libs
+	* xfce4-popup-places.{c,h}, view.c, Makefile.am: Bug #3672:
+	popup command (thanks to Mike for the patch)
 
 2007-12-08	Diego Ongaro <ongardie at gmail.com>
 

Modified: xfce4-places-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/Makefile.am	2007-12-09 21:38:27 UTC (rev 3688)
+++ xfce4-places-plugin/trunk/panel-plugin/Makefile.am	2007-12-10 05:49:29 UTC (rev 3689)
@@ -1,3 +1,20 @@
+bin_PROGRAMS = xfce4-popup-places
+
+xfce4_popup_places_SOURCES =						\
+	xfce4-popup-places.c						\
+	xfce4-popup-places.h
+
+xfce4_popup_places_CFLAGS =						\
+	$(LIBX11_CFLAGS)						\
+	$(GTK_CFLAGS)
+
+xfce4_popup_places_LDADD =						\
+	$(LIBX11_LDFLAGS)						\
+	$(LIBX11_LIBS)							\
+	$(GTK_LIBS)
+
+
+
 plugindir = $(libexecdir)/xfce4/panel-plugins
 
 plugin_PROGRAMS =							\

Modified: xfce4-places-plugin/trunk/panel-plugin/view.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/view.c	2007-12-09 21:38:27 UTC (rev 3688)
+++ xfce4-places-plugin/trunk/panel-plugin/view.c	2007-12-10 05:49:29 UTC (rev 3689)
@@ -58,6 +58,7 @@
 #include "model_system.h"
 #include "model_volumes.h"
 #include "model_user.h"
+#include "xfce4-popup-places.h"
 
 struct _PlacesView
 {
@@ -928,6 +929,61 @@
     return dlg;
 }
 
+/********** Handle user message **********/
+static gboolean
+places_view_plugin_message_received (GtkWidget *widget,
+                                     GdkEventClient *ev,
+                                     gpointer user_data)
+{
+    PlacesView *view = user_data;
+
+    DBG ("Message received");
+    if (G_LIKELY (ev->data_format == 8 && *(ev->data.b) != '\0'
+                  && !g_ascii_strcasecmp (PLACES_MSG_MENU, ev->data.b))){
+        DBG ("`%s'", ev->data.b);
+        GdkEventButton ev_btn;
+        ev_btn.button = 1;
+        pview_open_menu (view);
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
+static gboolean
+places_view_plugin_set_selection (PlacesView *view)
+{
+    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_PLACES_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 (places_view_plugin_message_received),
+                      view);
+
+    return TRUE;
+}
+
 /********** Initialization & Finalization **********/
 PlacesView*
 places_view_init(XfcePanelPlugin *plugin)
@@ -1003,6 +1059,8 @@
 
     DBG("done");
 
+    places_view_plugin_set_selection (view);
+
     return view;
 }
 

Added: xfce4-places-plugin/trunk/panel-plugin/xfce4-popup-places.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/xfce4-popup-places.c	                        (rev 0)
+++ xfce4-places-plugin/trunk/panel-plugin/xfce4-popup-places.c	2007-12-10 05:49:29 UTC (rev 3689)
@@ -0,0 +1,85 @@
+/* $Id$
+ *
+ *  Places - panel plugin for Xfce Desktop Environment
+ *           popup command
+ *  Copyright (C) 2002-2006  Olivier Fourdan
+ *                2007       Mike Massonnet <mmassonnet at xfce.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+
+#include "xfce4-popup-places.h"
+
+
+
+static gboolean
+plugin_check_is_running (GtkWidget *widget,
+                         Window *xid)
+{
+    GdkScreen          *gscreen;
+    gchar              *selection_name;
+    Atom                selection_atom;
+
+    gscreen = gtk_widget_get_screen (widget);
+    selection_name = g_strdup_printf (XFCE_PLACES_SELECTION"%d",
+                                      gdk_screen_get_number (gscreen));
+    selection_atom = XInternAtom (GDK_DISPLAY (), selection_name, FALSE);
+
+    if ((*xid = XGetSelectionOwner (GDK_DISPLAY (), selection_atom)))
+        return TRUE;
+
+    return FALSE;
+}
+
+gint
+main (gint argc, gchar *argv[])
+{
+    GdkEventClient        gev;
+    GtkWidget            *win;
+    Window                id;
+    gchar                *message = NULL;
+
+    gtk_init (&argc, &argv);
+
+    message = g_strdup_printf (PLACES_MSG_MENU);
+    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;
+    g_snprintf (gev.data.b, sizeof (gev.data.b), message);
+
+    if (plugin_check_is_running (win, &id))
+        gdk_event_send_client_message ((GdkEvent *)&gev, (GdkNativeWindow)id);
+    else
+        g_warning ("Can't find the xfce4-places-plugin.\n");
+    gdk_flush ();
+
+    gtk_widget_destroy (win);
+
+    return FALSE;
+}
+

Added: xfce4-places-plugin/trunk/panel-plugin/xfce4-popup-places.h
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/xfce4-popup-places.h	                        (rev 0)
+++ xfce4-places-plugin/trunk/panel-plugin/xfce4-popup-places.h	2007-12-10 05:49:29 UTC (rev 3689)
@@ -0,0 +1,35 @@
+/* $Id$
+ *
+ *  Places - panel plugin for Xfce Desktop Environment
+ *           popup command
+ *  Copyright (C) 2002-2006  Olivier Fourdan
+ *                2007       Mike Massonnet <mmassonnet at gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __XFCE4_POPUP_PLACES_H__
+#define __XFCE4_POPUP_PLACES_H__
+
+#ifndef XFCE_PLACES_SELECTION
+#define XFCE_PLACES_SELECTION   "XFCE_PLACES_SELECTION"
+#endif
+
+#ifndef PLACES_MSG_MENU
+#define PLACES_MSG_MENU         "MENU"
+#endif
+
+#endif
+




More information about the Goodies-commits mailing list