shell: Expose panel launching with DBus-activation
Turn Control Center in a DBus-activable service and export a 'launch-panel' GAction which accepts a tuple containing the id of the desired panel and its parameters as a GVariant array. The snippet below show how the custom shortcuts section of the keyboard panel can be invoked by a external programs through DBus: GVariantBuilder *flags = g_variant_builder_new (G_VARIANT_TYPE_VARDICT); GVariantBuilder *params = g_variant_builder_new (G_VARIANT_TYPE ("av")); g_variant_builder_add (params, "v", g_variant_builder_end (flags)); g_variant_builder_add (params, "v", g_variant_new_string ("shortcuts")); g_variant_builder_add (params, "v", g_variant_new_string ("custom")); GVariant *v = g_variant_new ("(s@av)", "keyboard", g_variant_builder_end (params)); GApplication *gnomecc = g_application_new (id, G_APPLICATION_IS_LAUNCHER); if (!g_application_register (gnomecc, NULL, &error)) g_error ("Failed to register launcher for %s: %s", id, error->message); g_action_group_activate_action (G_ACTION_GROUP (gnomecc), "launch-panel", v); https://bugzilla.gnome.org/show_bug.cgi?id=696054
This commit is contained in:
parent
31a8a99440
commit
ab0576f1f0
3 changed files with 42 additions and 1 deletions
|
@ -86,6 +86,13 @@ endif
|
|||
|
||||
AM_CPPFLAGS = -DGNOMELOCALEDIR="\"$(datadir)/locale\""
|
||||
|
||||
# Dbus service file
|
||||
servicefiledir = $(datadir)/dbus-1/services
|
||||
servicefile_in_files = org.gnome.ControlCenter.service.in
|
||||
servicefile_DATA = $(servicefile_in_files:.service.in=.service)
|
||||
$(servicefile_DATA): $(servicefile_in_files) Makefile
|
||||
$(AM_V_GEN) sed -e 's|[@]bindir[@]|$(bindir)|' $< > $@
|
||||
|
||||
sysdir = $(datadir)/applications
|
||||
sys_in_files = gnome-control-center.desktop.in
|
||||
sys_DATA = $(sys_in_files:.desktop.in=.desktop)
|
||||
|
@ -99,10 +106,11 @@ completions/gnome-control-center: completions/gnome-control-center.in list-panel
|
|||
|
||||
EXTRA_DIST = \
|
||||
gnome-control-center.desktop.in.in \
|
||||
$(servicefile_in_files) \
|
||||
$(completion_in_files) \
|
||||
list-panel.sh
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES) $(completion_DATA)
|
||||
CLEANFILES = $(BUILT_SOURCES) $(completion_DATA) $(servicefile_DATA)
|
||||
DISTCLEANFILES = gnome-control-center.desktop gnome-control-center.desktop.in
|
||||
|
||||
noinst_PROGRAMS = test-hostname
|
||||
|
|
|
@ -95,6 +95,27 @@ help_activated (GSimpleAction *action,
|
|||
GDK_CURRENT_TIME, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
launch_panel_activated (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer user_data)
|
||||
{
|
||||
CcApplication *self = CC_APPLICATION (user_data);
|
||||
GError *error = NULL;
|
||||
gchar *panel_id;
|
||||
GVariant *parameters;
|
||||
|
||||
g_variant_get (parameter, "(&s@av)", &panel_id, ¶meters);
|
||||
g_debug ("gnome-control-center: 'launch-panel' activated for panel '%s' with %"G_GSIZE_FORMAT" arguments",
|
||||
panel_id, g_variant_n_children (parameters));
|
||||
if (!cc_shell_set_active_panel_from_id (CC_SHELL (self->priv->window), panel_id, parameters, &error))
|
||||
{
|
||||
g_warning ("Failed to activate the '%s' panel: %s", panel_id, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
g_variant_unref (parameters);
|
||||
}
|
||||
|
||||
static int
|
||||
cc_application_command_line (GApplication *application,
|
||||
GApplicationCommandLine *command_line)
|
||||
|
@ -280,6 +301,15 @@ cc_application_startup (GApplication *application)
|
|||
g_signal_connect (action, "activate", G_CALLBACK (cc_application_quit), self);
|
||||
g_object_unref (action);
|
||||
|
||||
/* Launch panel by id. The parameter is a (panel_id, array_of_panel_parameters)
|
||||
* tuple. The GVariant-containing array usually is just the same array of
|
||||
* strings that would be generated by passing panel-specific arguments on
|
||||
* the command line. */
|
||||
action = g_simple_action_new ("launch-panel", G_VARIANT_TYPE ("(sav)"));
|
||||
g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action));
|
||||
g_signal_connect (action, "activate", G_CALLBACK (launch_panel_activated), self);
|
||||
g_object_unref (action);
|
||||
|
||||
menu = g_menu_new ();
|
||||
|
||||
section = g_menu_new ();
|
||||
|
|
3
shell/org.gnome.ControlCenter.service.in
Normal file
3
shell/org.gnome.ControlCenter.service.in
Normal file
|
@ -0,0 +1,3 @@
|
|||
[D-BUS Service]
|
||||
Name=org.gnome.ControlCenter
|
||||
Exec=@bindir@/gnome-control-center
|
Loading…
Add table
Add a link
Reference in a new issue