[Xfce4-commits] <xfce4-panel:master> Add support for pluggable dialogs.

Nick Schermer noreply at xfce.org
Sun Jan 29 12:14:01 CET 2012


Updating branch refs/heads/master
         to 95fdcccae23bf0ebd5b46cdc8d830f357006c4ab (commit)
       from 988e604d205c6f76df998ebf16aa9d598a44a3bc (commit)

commit 95fdcccae23bf0ebd5b46cdc8d830f357006c4ab
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Jan 29 12:12:23 2012 +0100

    Add support for pluggable dialogs.

 panel-preferences.desktop.in         |    3 +
 panel/main.c                         |    6 +-
 panel/panel-dbus-client.c            |    8 ++-
 panel/panel-dbus-client.h            |    1 +
 panel/panel-dbus-service-infos.xml   |    3 +-
 panel/panel-dbus-service.c           |    6 +-
 panel/panel-preferences-dialog.c     |  113 +++++++++++++++++++++++++++++-----
 panel/panel-preferences-dialog.glade |    2 +-
 panel/panel-preferences-dialog.h     |    3 +-
 9 files changed, 119 insertions(+), 26 deletions(-)

diff --git a/panel-preferences.desktop.in b/panel-preferences.desktop.in
index 999075e..2cd477d 100644
--- a/panel-preferences.desktop.in
+++ b/panel-preferences.desktop.in
@@ -7,5 +7,8 @@ Categories=XFCE;GTK;Settings;DesktopSettings;X-XFCE-SettingsDialog;X-XFCE-Person
 OnlyShowIn=XFCE;
 Terminal=false
 StartupNotify=true
+X-XfcePluggable=true
+X-XfceHelpComponent=xfce4-panel
+X-XfceHelpPage=preferences
 _Name=Panel
 _Comment=Customize the panel
diff --git a/panel/main.c b/panel/main.c
index 44ebf3c..3747d8a 100644
--- a/panel/main.c
+++ b/panel/main.c
@@ -61,6 +61,7 @@ static gboolean   opt_version = FALSE;
 static gboolean   opt_disable_wm_check = FALSE;
 static gchar     *opt_plugin_event = NULL;
 static gchar    **opt_arguments = NULL;
+static gchar     *opt_socket_id = NULL;
 
 
 
@@ -84,6 +85,7 @@ static GOptionEntry option_entries[] =
   { "disable-wm-check", 'd', 0, G_OPTION_ARG_NONE, &opt_disable_wm_check, N_("Do not wait for a window manager on startup"), NULL },
   { "version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, N_("Print version information and exit"), NULL },
   { "plugin-event", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_plugin_event, NULL, NULL },
+  { "socket-id", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_socket_id, NULL, NULL },
   { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &opt_arguments, NULL, NULL },
   { NULL }
 };
@@ -264,7 +266,7 @@ main (gint argc, gchar **argv)
   else if (opt_preferences >= 0)
     {
       /* send a signal to the running instance to show the preferences dialog */
-      succeed = panel_dbus_client_display_preferences_dialog (opt_preferences, &error);
+      succeed = panel_dbus_client_display_preferences_dialog (opt_preferences, opt_socket_id, &error);
       goto dbus_return;
     }
   else if (opt_add_items >= 0)
@@ -333,7 +335,7 @@ main (gint argc, gchar **argv)
 
   /* open dialog if we started from launch_panel */
   if (opt_preferences >= 0)
-    panel_preferences_dialog_show_from_id (opt_preferences);
+    panel_preferences_dialog_show_from_id (opt_preferences, opt_socket_id);
 
   gtk_main ();
 
diff --git a/panel/panel-dbus-client.c b/panel/panel-dbus-client.c
index 47add8b..be259ec 100644
--- a/panel/panel-dbus-client.c
+++ b/panel/panel-dbus-client.c
@@ -70,8 +70,9 @@ panel_dbus_client_get_proxy (GError **error)
 
 
 gboolean
-panel_dbus_client_display_preferences_dialog (guint    active,
-                                              GError **error)
+panel_dbus_client_display_preferences_dialog (guint         active,
+                                              const gchar  *socket_id,
+                                              GError      **error)
 {
   gboolean    result;
   DBusGProxy *dbus_proxy;
@@ -83,7 +84,8 @@ panel_dbus_client_display_preferences_dialog (guint    active,
     return FALSE;
 
   result = _panel_dbus_client_display_preferences_dialog (dbus_proxy,
-                                                          active, error);
+                                                          active, socket_id,
+                                                          error);
 
   g_object_unref (G_OBJECT (dbus_proxy));
 
diff --git a/panel/panel-dbus-client.h b/panel/panel-dbus-client.h
index 3969404..c952706 100644
--- a/panel/panel-dbus-client.h
+++ b/panel/panel-dbus-client.h
@@ -23,6 +23,7 @@
 #include <gdk/gdk.h>
 
 gboolean  panel_dbus_client_display_preferences_dialog (guint         active,
+                                                        const gchar  *socket_id,
                                                         GError      **error);
 
 gboolean  panel_dbus_client_display_items_dialog       (guint         active,
diff --git a/panel/panel-dbus-service-infos.xml b/panel/panel-dbus-service-infos.xml
index 8c2d8b7..b171d8b 100644
--- a/panel/panel-dbus-service-infos.xml
+++ b/panel/panel-dbus-service-infos.xml
@@ -12,7 +12,7 @@
                 value="_panel_dbus_client"/>
 
     <!--
-      DisplayPreferencesDialog (active : UINT, socket-id : INT) : VOID
+      DisplayPreferencesDialog (active : UINT, socket-id : STRING) : VOID
 
       active    : The active panel number in the dialog, starting
                   at zero.
@@ -22,6 +22,7 @@
     -->
     <method name="DisplayPreferencesDialog">
       <arg name="active" direction="in" type="u" />
+      <arg name="socket_id" direction="in" type="s" />
     </method>
 
     <!--
diff --git a/panel/panel-dbus-service.c b/panel/panel-dbus-service.c
index 3947c43..800b5dc 100644
--- a/panel/panel-dbus-service.c
+++ b/panel/panel-dbus-service.c
@@ -44,6 +44,7 @@
 static void      panel_dbus_service_finalize                   (GObject            *object);
 static gboolean  panel_dbus_service_display_preferences_dialog (PanelDBusService   *service,
                                                                 guint               active,
+                                                                const gchar        *socket_id,
                                                                 GError            **error);
 static gboolean  panel_dbus_service_display_items_dialog       (PanelDBusService   *service,
                                                                 guint               active,
@@ -190,13 +191,14 @@ panel_dbus_service_finalize (GObject *object)
 static gboolean
 panel_dbus_service_display_preferences_dialog (PanelDBusService  *service,
                                                guint              active,
+                                               const gchar       *socket_id,
                                                GError           **error)
 {
   panel_return_val_if_fail (PANEL_IS_DBUS_SERVICE (service), FALSE);
   panel_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
   /* show the preferences dialog */
-  panel_preferences_dialog_show_from_id (active);
+  panel_preferences_dialog_show_from_id (active, socket_id);
 
   return TRUE;
 }
@@ -212,7 +214,7 @@ panel_dbus_service_display_items_dialog (PanelDBusService  *service,
   panel_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
   /* show the items dialog */
-  panel_preferences_dialog_show_from_id (active);
+  panel_item_dialog_show_from_id (active);
 
   return TRUE;
 }
diff --git a/panel/panel-preferences-dialog.c b/panel/panel-preferences-dialog.c
index 3a0119f..c55b056 100644
--- a/panel/panel-preferences-dialog.c
+++ b/panel/panel-preferences-dialog.c
@@ -20,6 +20,10 @@
 #include <config.h>
 #endif
 
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
 #include <exo/exo.h>
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4ui/libxfce4ui.h>
@@ -136,6 +140,9 @@ struct _PanelPreferencesDialog
 
   /* changed signal for the output selector */
   gulong            output_changed_handler_id;
+
+  /* plug in which the dialog is embedded */
+  GtkWidget        *socket_plug;
 };
 
 
@@ -283,6 +290,10 @@ panel_preferences_dialog_finalize (GObject *object)
   /* free bindings list */
   g_slist_free (dialog->bindings);
 
+  /* destroy possible pluggable dialog */
+  if (dialog->socket_plug != NULL)
+    gtk_widget_destroy (dialog->socket_plug);
+
   if (dialog->active != NULL)
     {
       if (dialog->items_changed_handler_id != 0)
@@ -1266,13 +1277,28 @@ panel_preferences_dialog_item_selection_changed (GtkTreeSelection       *selecti
 
 
 
-void
-panel_preferences_dialog_show (PanelWindow *active)
+static void
+panel_preferences_dialog_plug_deleted (GtkWidget *plug)
+{
+  g_signal_handlers_disconnect_by_func (G_OBJECT (plug),
+      G_CALLBACK (panel_preferences_dialog_plug_deleted), NULL);
+
+  g_object_unref (G_OBJECT (dialog_singleton));
+}
+
+
+
+static void
+panel_preferences_dialog_show_internal (PanelWindow     *active,
+                                        GdkNativeWindow  socket_window)
 {
   gint         panel_id = 0;
   GObject     *window, *combo;
   GdkScreen   *screen;
   GSList      *windows;
+  GtkWidget   *plug;
+  GObject     *plug_child;
+  GtkWidget   *content_area;
 
   panel_return_if_fail (active == NULL || PANEL_IS_WINDOW (active));
 
@@ -1295,17 +1321,6 @@ panel_preferences_dialog_show (PanelWindow *active)
         active = g_slist_nth_data (windows, 0);
     }
 
-  /* get the active screen */
-  if (G_LIKELY (active != NULL))
-    screen = gtk_widget_get_screen (GTK_WIDGET (active));
-  else
-    screen = gdk_screen_get_default ();
-
-  /* show the dialog on the same screen as the panel */
-  window = gtk_builder_get_object (GTK_BUILDER (dialog_singleton), "dialog");
-  panel_return_if_fail (GTK_IS_WIDGET (window));
-  gtk_window_set_screen (GTK_WINDOW (window), screen);
-
   /* select the active window in the dialog */
   combo = gtk_builder_get_object (GTK_BUILDER (dialog_singleton), "panel-combobox");
   panel_return_if_fail (GTK_IS_WIDGET (combo));
@@ -1313,20 +1328,86 @@ panel_preferences_dialog_show (PanelWindow *active)
   if (!panel_preferences_dialog_panel_combobox_rebuild (dialog_singleton, panel_id))
     gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
 
-  gtk_window_present (GTK_WINDOW (window));
+  window = gtk_builder_get_object (GTK_BUILDER (dialog_singleton), "dialog");
+  panel_return_if_fail (GTK_IS_WIDGET (window));
+  plug_child = gtk_builder_get_object (GTK_BUILDER (dialog_singleton), "plug-child");
+  panel_return_if_fail (GTK_IS_WIDGET (plug_child));
+
+  /* check if we need to remove the window from the plug */
+  if (dialog_singleton->socket_plug != NULL)
+    {
+      panel_return_if_fail (GTK_IS_PLUG (dialog_singleton->socket_plug));
+
+      /* move the vbox to the dialog */
+      content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
+      gtk_widget_reparent (GTK_WIDGET (plug_child), content_area);
+      gtk_widget_show (GTK_WIDGET (plug_child));
+
+      /* destroy the plug */
+      plug = dialog_singleton->socket_plug;
+      dialog_singleton->socket_plug = NULL;
+
+      g_signal_handlers_disconnect_by_func (G_OBJECT (plug),
+          G_CALLBACK (panel_preferences_dialog_plug_deleted), NULL);
+      gtk_widget_destroy (plug);
+    }
+
+  if (socket_window == 0)
+    {
+      /* show the dialog on the same screen as the panel */
+      if (G_LIKELY (active != NULL))
+        screen = gtk_widget_get_screen (GTK_WIDGET (active));
+      else
+        screen = gdk_screen_get_default ();
+      gtk_window_set_screen (GTK_WINDOW (window), screen);
+
+      gtk_window_present (GTK_WINDOW (window));
+    }
+  else
+    {
+      /* hide window */
+      gtk_widget_hide (GTK_WIDGET (window));
+
+      /* create a new plug */
+      plug = gtk_plug_new (socket_window);
+      g_signal_connect (G_OBJECT (plug), "delete-event",
+          G_CALLBACK (panel_preferences_dialog_plug_deleted), NULL);
+      dialog_singleton->socket_plug = plug;
+      gtk_widget_show (plug);
+
+      /* move the vbox in the plug */
+      gtk_widget_reparent (GTK_WIDGET (plug_child), plug);
+      gtk_widget_show (GTK_WIDGET (plug_child));
+    }
 }
 
 
 
 void
-panel_preferences_dialog_show_from_id (gint panel_id)
+panel_preferences_dialog_show (PanelWindow *active)
+{
+  panel_return_if_fail (active == NULL || PANEL_IS_WINDOW (active));
+  panel_preferences_dialog_show_internal (active, 0);
+}
+
+
+
+void
+panel_preferences_dialog_show_from_id (gint         panel_id,
+                                       const gchar *socket_id)
 {
   PanelApplication *application;
   PanelWindow      *window;
+  GdkNativeWindow   socket_window = 0;
+
+  /* x11 windows are ulong on 64 bit platforms
+   * or uint32 on other platforms */
+  if (socket_id != NULL)
+    socket_window = (GdkNativeWindow) strtoul (socket_id, NULL, 0);
 
   application = panel_application_get ();
   window = panel_application_get_window (application, panel_id);
-  panel_preferences_dialog_show (window);
+  panel_preferences_dialog_show_internal (window, socket_window);
   g_object_unref (G_OBJECT (application));
 }
 
diff --git a/panel/panel-preferences-dialog.glade b/panel/panel-preferences-dialog.glade
index 062cbed..79b3d47 100644
--- a/panel/panel-preferences-dialog.glade
+++ b/panel/panel-preferences-dialog.glade
@@ -118,7 +118,7 @@
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child>
-          <object class="GtkVBox" id="vbox1">
+          <object class="GtkVBox" id="plug-child">
             <property name="visible">True</property>
             <property name="border_width">6</property>
             <property name="orientation">vertical</property>
diff --git a/panel/panel-preferences-dialog.h b/panel/panel-preferences-dialog.h
index 89d73f3..792b445 100644
--- a/panel/panel-preferences-dialog.h
+++ b/panel/panel-preferences-dialog.h
@@ -39,7 +39,8 @@ GType      panel_preferences_dialog_get_type     (void) G_GNUC_CONST;
 
 void       panel_preferences_dialog_show         (PanelWindow *active);
 
-void       panel_preferences_dialog_show_from_id (gint         panel_id);
+void       panel_preferences_dialog_show_from_id (gint         panel_id,
+                                                  const gchar *socket_id);
 
 gboolean   panel_preferences_dialog_visible      (void);
 


More information about the Xfce4-commits mailing list