From ed386e9d7a51375f09063302a3b1e73103ea86c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Tue, 8 Mar 2016 15:15:13 +0100 Subject: add "Desktop mode" switch for Lomiri --- src/service.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 1d3115f..30226c9 100644 --- a/src/service.c +++ b/src/service.c @@ -76,6 +76,8 @@ static const char * const menu_names[N_PROFILES] = "desktop_lockscreen" }; +static const char * const usage_mode_schema_name = "com.lomiri.Shell"; + struct ProfileMenuInfo { /* the root level -- the header is the only child of this */ @@ -96,6 +98,7 @@ struct _IndicatorSessionServicePrivate IndicatorSessionActions * backend_actions; GSettings * indicator_settings; GSettings * keybinding_settings; + GSettings * usage_mode_settings; GSimpleActionGroup * actions; guint actions_export_id; struct ProfileMenuInfo menus[N_PROFILES]; @@ -149,6 +152,11 @@ rebuild_settings_section_soon (IndicatorSessionService * self) { rebuild_soon (self, SECTION_SETTINGS); } +static inline void +rebuild_admin_section_soon (IndicatorSessionService * self) +{ + rebuild_soon (self, SECTION_ADMIN); +} /*** **** @@ -334,6 +342,33 @@ get_current_real_name (IndicatorSessionService * self) return ""; } +static gboolean +usage_mode_to_action_state(GValue *value, + GVariant *variant, + gpointer unused) +{ + const gchar* usage_mode = g_variant_get_string(variant, NULL); + GVariant* ret_var = g_variant_new_boolean(g_strcmp0(usage_mode, "Windowed") == 0 ? TRUE : FALSE); + g_value_set_variant(value, ret_var); + return TRUE; +} + +static GVariant* +action_state_to_usage_mode(const GValue *value, + const GVariantType * unused_expected_type, + gpointer unused) +{ + GVariant* var = g_value_get_variant(value); + GVariant* ret = g_variant_new_string(g_variant_get_boolean(var) == TRUE ? "Windowed" : "Staged"); + return ret; +} + +static void +on_usage_mode_setting_changed (gpointer gself) +{ + rebuild_admin_section_soon((IndicatorSessionService*)(gself)); +} + static GMenuModel * create_admin_section (void) { @@ -346,6 +381,16 @@ create_admin_section (void) g_menu_append (menu, distro_help_label, "indicator.distro_help"); g_free (desktop_help_label); g_free (distro_help_label); + + if (ayatana_common_utils_is_lomiri()) + { + GMenuItem * menu_item = NULL; + menu_item = g_menu_item_new(_("Desktop mode"), "indicator.usage-mode"); + g_menu_item_set_attribute(menu_item, "x-ayatana-type", "s", "org.ayatana.indicator.switch"); + g_menu_append_item(menu, menu_item); + g_object_unref(menu_item); + } + g_menu_append (menu, _("Report a Bug…"), "indicator.bug"); return G_MENU_MODEL (menu); } @@ -954,13 +999,29 @@ init_gactions (IndicatorSessionService * self) g_action_map_add_action (G_ACTION_MAP (p->actions), G_ACTION(a)); p->guest_switcher_action = a; - /* add switch-to-user action... parameter is the uesrname */ + /* add switch-to-user action... parameter is the username */ v = create_user_switcher_state (self); a = g_simple_action_new_stateful ("switch-to-user", G_VARIANT_TYPE_STRING, v); g_signal_connect (a, "activate", G_CALLBACK(on_user_activated), self); g_action_map_add_action (G_ACTION_MAP (p->actions), G_ACTION(a)); p->user_switcher_action = a; + /* add usage-mode action */ + a = g_simple_action_new_stateful("usage-mode", + NULL, + g_variant_new_boolean(FALSE)); + g_settings_bind_with_mapping(p->usage_mode_settings, "usage-mode", + a, "state", + G_SETTINGS_BIND_DEFAULT, + usage_mode_to_action_state, + action_state_to_usage_mode, + NULL, + NULL); + + g_action_map_add_action(G_ACTION_MAP(p->actions), G_ACTION(a)); + g_signal_connect_swapped(p->usage_mode_settings, "changed::usage-mode", + G_CALLBACK(on_usage_mode_setting_changed), self); + /* add the header action */ a = g_simple_action_new_stateful ("_header", NULL, action_state_for_header (self)); @@ -1183,9 +1244,18 @@ indicator_session_service_init (IndicatorSessionService * self) { p->keybinding_settings = g_settings_new ("org.gnome.settings-daemon.plugins.media-keys"); } - else if (ayatana_common_utils_is_gnome() || ayatana_common_utils_is_unity()) + else if (ayatana_common_utils_is_gnome()) + { + p->keybinding_settings = g_settings_new ("org.gnome.settings-daemon.plugins.media-keys"); + } + else if (ayatana_common_utils_is_unity()) + { + p->keybinding_settings = g_settings_new ("org.gnome.settings-daemon.plugins.media-keys"); + } + else if (ayatana_common_utils_is_lomiri()) { p->keybinding_settings = g_settings_new ("org.gnome.settings-daemon.plugins.media-keys"); + p->usage_mode_settings = g_settings_new(usage_mode_schema_name); } self->priv = p; @@ -1356,6 +1426,7 @@ my_dispose (GObject * o) g_clear_object (&p->backend_actions); g_clear_object (&p->indicator_settings); g_clear_object (&p->keybinding_settings); + g_clear_object (&p->usage_mode_settings); g_clear_object (&p->actions); for (i=0; i Date: Tue, 8 Mar 2016 15:26:24 +0100 Subject: plug a memleak --- src/service.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 30226c9..3fca33b 100644 --- a/src/service.c +++ b/src/service.c @@ -105,6 +105,7 @@ struct _IndicatorSessionServicePrivate GSimpleAction * header_action; GSimpleAction * user_switcher_action; GSimpleAction * guest_switcher_action; + GSimpleAction * usage_mode_action; GHashTable * users; GHashTable * reported_users; guint rebuild_id; @@ -1021,6 +1022,7 @@ init_gactions (IndicatorSessionService * self) g_action_map_add_action(G_ACTION_MAP(p->actions), G_ACTION(a)); g_signal_connect_swapped(p->usage_mode_settings, "changed::usage-mode", G_CALLBACK(on_usage_mode_setting_changed), self); + p->usage_mode_action = a; /* add the header action */ a = g_simple_action_new_stateful ("_header", NULL, @@ -1435,6 +1437,7 @@ my_dispose (GObject * o) g_clear_object (&p->header_action); g_clear_object (&p->user_switcher_action); g_clear_object (&p->guest_switcher_action); + g_clear_object (&p->usage_mode_action); g_clear_object (&p->conn); g_clear_pointer (&p->default_icon_serialized, g_variant_unref); -- cgit v1.2.3 From 9b7b8400b7824f19ef1c877f059473a373670e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Tue, 8 Mar 2016 23:12:26 +0100 Subject: use ellipsis and convergence friendly "about" caption --- src/service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 3fca33b..f6f6251 100644 --- a/src/service.c +++ b/src/service.c @@ -375,9 +375,9 @@ create_admin_section (void) { GMenu * menu; gchar * desktop_help_label = g_strdup_printf(_("%s Desktop Help"), get_desktop_name()); - gchar * distro_help_label = g_strdup_printf(_("%s Help"), get_distro_name()); + gchar * distro_help_label = g_strdup_printf(_("%s Help…"), get_distro_name()); menu = g_menu_new (); - g_menu_append (menu, _("About This Computer"), "indicator.about"); + g_menu_append (menu, _("About This Device…"), "indicator.about"); g_menu_append (menu, desktop_help_label, "indicator.desktop_help"); g_menu_append (menu, distro_help_label, "indicator.distro_help"); g_free (desktop_help_label); -- cgit v1.2.3 From 31d06b6a5456e6a60e0e6bc21cafbff36f1f4c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Tue, 15 Mar 2016 14:39:58 +0100 Subject: change the About string only for u8 would be confusing for u7/desktop and need a string freeze exception at this point --- src/service.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index f6f6251..206079a 100644 --- a/src/service.c +++ b/src/service.c @@ -377,7 +377,13 @@ create_admin_section (void) gchar * desktop_help_label = g_strdup_printf(_("%s Desktop Help"), get_desktop_name()); gchar * distro_help_label = g_strdup_printf(_("%s Help…"), get_distro_name()); menu = g_menu_new (); - g_menu_append (menu, _("About This Device…"), "indicator.about"); + + if (ayatana_common_utils_is_lomiri()) { + g_menu_append (menu, _("About This Device…"), "indicator.about"); + } else { + g_menu_append (menu, _("About This Computer"), "indicator.about"); + } + g_menu_append (menu, desktop_help_label, "indicator.desktop_help"); g_menu_append (menu, distro_help_label, "indicator.distro_help"); g_free (desktop_help_label); -- cgit v1.2.3 From df4c24eb24ae2b58b772b51e08b7d7f338f25140 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Mar 2016 15:33:29 +0100 Subject: Only use Lomiri schema if it's installed to avoid hard dependency --- src/service.c | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 206079a..dbe9698 100644 --- a/src/service.c +++ b/src/service.c @@ -371,9 +371,10 @@ on_usage_mode_setting_changed (gpointer gself) } static GMenuModel * -create_admin_section (void) +create_admin_section (IndicatorSessionService * self) { GMenu * menu; + priv_t * p = self->priv; gchar * desktop_help_label = g_strdup_printf(_("%s Desktop Help"), get_desktop_name()); gchar * distro_help_label = g_strdup_printf(_("%s Help…"), get_distro_name()); menu = g_menu_new (); @@ -389,7 +390,7 @@ create_admin_section (void) g_free (desktop_help_label); g_free (distro_help_label); - if (ayatana_common_utils_is_lomiri()) + if (p->usage_mode_action && ayatana_common_utils_is_lomiri()) { GMenuItem * menu_item = NULL; menu_item = g_menu_item_new(_("Desktop mode"), "indicator.usage-mode"); @@ -799,7 +800,7 @@ create_menu (IndicatorSessionService * self, int profile) if (profile == PROFILE_DESKTOP) { - sections[n++] = create_admin_section (); + sections[n++] = create_admin_section (self); sections[n++] = create_settings_section (self); sections[n++] = create_switch_section (self, profile); sections[n++] = create_logout_section (self); @@ -1014,21 +1015,24 @@ init_gactions (IndicatorSessionService * self) p->user_switcher_action = a; /* add usage-mode action */ - a = g_simple_action_new_stateful("usage-mode", + if (p->usage_mode_settings) + { + a = g_simple_action_new_stateful("usage-mode", + NULL, + g_variant_new_boolean(FALSE)); + g_settings_bind_with_mapping(p->usage_mode_settings, "usage-mode", + a, "state", + G_SETTINGS_BIND_DEFAULT, + usage_mode_to_action_state, + action_state_to_usage_mode, NULL, - g_variant_new_boolean(FALSE)); - g_settings_bind_with_mapping(p->usage_mode_settings, "usage-mode", - a, "state", - G_SETTINGS_BIND_DEFAULT, - usage_mode_to_action_state, - action_state_to_usage_mode, - NULL, - NULL); - - g_action_map_add_action(G_ACTION_MAP(p->actions), G_ACTION(a)); - g_signal_connect_swapped(p->usage_mode_settings, "changed::usage-mode", - G_CALLBACK(on_usage_mode_setting_changed), self); - p->usage_mode_action = a; + NULL); + + g_action_map_add_action(G_ACTION_MAP(p->actions), G_ACTION(a)); + g_signal_connect_swapped(p->usage_mode_settings, "changed::usage-mode", + G_CALLBACK(on_usage_mode_setting_changed), self); + p->usage_mode_action = a; + } /* add the header action */ a = g_simple_action_new_stateful ("_header", NULL, @@ -1071,7 +1075,7 @@ rebuild_now (IndicatorSessionService * self, int sections) if (sections & SECTION_ADMIN) { - rebuild_section (desktop->submenu, 0, create_admin_section()); + rebuild_section (desktop->submenu, 0, create_admin_section(self)); } if (sections & SECTION_SETTINGS) @@ -1240,6 +1244,7 @@ indicator_session_service_init (IndicatorSessionService * self) priv_t * p; gpointer gp; GIcon * icon; + GSettingsSchema * usage_mode_schema; /* init our priv pointer */ p = indicator_session_service_get_instance_private (self); @@ -1263,7 +1268,16 @@ indicator_session_service_init (IndicatorSessionService * self) else if (ayatana_common_utils_is_lomiri()) { p->keybinding_settings = g_settings_new ("org.gnome.settings-daemon.plugins.media-keys"); - p->usage_mode_settings = g_settings_new(usage_mode_schema_name); + + /* Only use unity8 schema if it's installed; this avoids a hard dependency + on unity8-schemas */ + usage_mode_schema = g_settings_schema_source_lookup (g_settings_schema_source_get_default (), + usage_mode_schema_name, TRUE); + if (usage_mode_schema) + { + p->usage_mode_settings = g_settings_new (usage_mode_schema_name); + g_settings_schema_unref (usage_mode_schema); + } } self->priv = p; -- cgit v1.2.3