Browse Source

Add support for pluggable dialogs.

tags/xfce4-panel-4.10.0
Nick Schermer 9 years ago
parent
commit
95fdcccae2
9 changed files with 119 additions and 26 deletions
  1. +3
    -0
      panel-preferences.desktop.in
  2. +4
    -2
      panel/main.c
  3. +5
    -3
      panel/panel-dbus-client.c
  4. +1
    -0
      panel/panel-dbus-client.h
  5. +2
    -1
      panel/panel-dbus-service-infos.xml
  6. +4
    -2
      panel/panel-dbus-service.c
  7. +97
    -16
      panel/panel-preferences-dialog.c
  8. +1
    -1
      panel/panel-preferences-dialog.glade
  9. +2
    -1
      panel/panel-preferences-dialog.h

+ 3
- 0
panel-preferences.desktop.in View File

@@ -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

+ 4
- 2
panel/main.c View File

@@ -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 ();



+ 5
- 3
panel/panel-dbus-client.c View File

@@ -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));



+ 1
- 0
panel/panel-dbus-client.h View File

@@ -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,


+ 2
- 1
panel/panel-dbus-service-infos.xml View File

@@ -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>

<!--


+ 4
- 2
panel/panel-dbus-service.c View File

@@ -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;
}


+ 97
- 16
panel/panel-preferences-dialog.c View File

@@ -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));
}



+ 1
- 1
panel/panel-preferences-dialog.glade View File

@@ -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>


+ 2
- 1
panel/panel-preferences-dialog.h View File

@@ -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);



Loading…
Cancel
Save