From 1136552de368b60958210d3270d41090ddea1a58 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 7 Sep 2022 05:46:02 +0200 Subject: src/service.c: Create separate header profiles --- src/service.c | 55 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/src/service.c b/src/service.c index fec90d85..ce4c0a80 100644 --- a/src/service.c +++ b/src/service.c @@ -1,5 +1,5 @@ /* - * Copyright 2021 Robert Tari + * Copyright 2021-2022 Robert Tari * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published @@ -60,6 +60,7 @@ struct ProfileMenuInfo GMenu *pMenu; GMenu *pSubmenu; guint nExportId; + GSimpleAction *pHeaderAction; }; struct _IndicatorKeyboardServicePrivate @@ -71,7 +72,6 @@ struct _IndicatorKeyboardServicePrivate gboolean bMenusBuilt; struct ProfileMenuInfo lMenus[N_PROFILES]; GSimpleActionGroup *pActionGroup; - GSimpleAction *pHeaderAction; GSimpleAction *pSettingsAction; GSimpleAction *pLayoutAction; GMenu *pLayoutSection; @@ -82,7 +82,7 @@ typedef IndicatorKeyboardServicePrivate priv_t; G_DEFINE_TYPE_WITH_PRIVATE(IndicatorKeyboardService, indicator_keyboard_service, G_TYPE_OBJECT) -static GVariant* createHeaderState(IndicatorKeyboardService *self) +static GVariant* createHeaderState(IndicatorKeyboardService *self, int nProfile) { GVariantBuilder cBuilder; g_variant_builder_init(&cBuilder, G_VARIANT_TYPE("a{sv}")); @@ -124,7 +124,7 @@ static GVariant* createHeaderState(IndicatorKeyboardService *self) return g_variant_builder_end(&cBuilder); } -static GMenuModel* createDesktopLayoutSection(IndicatorKeyboardService *self, int nProfile) +static GMenuModel* createLayoutSection(IndicatorKeyboardService *self) { self->pPrivate->pLayoutSection = g_menu_new(); @@ -160,7 +160,7 @@ static GMenuModel* createDesktopLayoutSection(IndicatorKeyboardService *self, in return G_MENU_MODEL(self->pPrivate->pLayoutSection); } -static GMenuModel* createDesktopSettingsSection(IndicatorKeyboardService *self) +static GMenuModel* createSettingsSection(IndicatorKeyboardService *self) { GMenu * pMenu = g_menu_new(); g_menu_append(pMenu, _("Keyboard Settings…"), "indicator.settings"); @@ -178,11 +178,14 @@ static void rebuildSection(GMenu *pMenu, int nPos, GMenuModel *pModel) static void rebuildNow(IndicatorKeyboardService *self, guint nSections) { struct ProfileMenuInfo *pInfoDesktop = &self->pPrivate->lMenus[PROFILE_DESKTOP]; + struct ProfileMenuInfo *pInfoPhone = &self->pPrivate->lMenus[PROFILE_PHONE]; struct ProfileMenuInfo *pInfoGreeter = &self->pPrivate->lMenus[PROFILE_GREETER]; if (nSections & SECTION_HEADER) { - g_simple_action_set_state(self->pPrivate->pHeaderAction, createHeaderState(self)); + g_simple_action_set_state(pInfoDesktop->pHeaderAction, createHeaderState(self, PROFILE_DESKTOP)); + g_simple_action_set_state(pInfoPhone->pHeaderAction, createHeaderState(self, PROFILE_PHONE)); + g_simple_action_set_state(pInfoGreeter->pHeaderAction, createHeaderState(self, PROFILE_GREETER)); } if (!self->pPrivate->bMenusBuilt) @@ -192,13 +195,15 @@ static void rebuildNow(IndicatorKeyboardService *self, guint nSections) if (nSections & SECTION_LAYOUTS) { - rebuildSection(pInfoDesktop->pSubmenu, 0, createDesktopLayoutSection(self, PROFILE_DESKTOP)); - rebuildSection(pInfoGreeter->pSubmenu, 0, createDesktopLayoutSection(self, PROFILE_GREETER)); + rebuildSection(pInfoDesktop->pSubmenu, 0, createLayoutSection(self)); + rebuildSection(pInfoPhone->pSubmenu, 0, createLayoutSection(self)); + rebuildSection(pInfoGreeter->pSubmenu, 0, createLayoutSection(self)); } if (nSections & SECTION_SETTINGS) { - rebuildSection(pInfoDesktop->pSubmenu, 1, createDesktopSettingsSection(self)); + rebuildSection(pInfoDesktop->pSubmenu, 1, createSettingsSection(self)); + rebuildSection(pInfoPhone->pSubmenu, 1, createSettingsSection(self)); } } @@ -216,17 +221,17 @@ static void createMenu(IndicatorKeyboardService *self, int nProfile) // Build the sections if (nProfile == PROFILE_PHONE) { - lSections[nSection++] = createDesktopLayoutSection(self, nProfile); - lSections[nSection++] = createDesktopSettingsSection(self); + lSections[nSection++] = createLayoutSection(self); + lSections[nSection++] = createSettingsSection(self); } else if (nProfile == PROFILE_DESKTOP) { - lSections[nSection++] = createDesktopLayoutSection(self, nProfile); - lSections[nSection++] = createDesktopSettingsSection(self); + lSections[nSection++] = createLayoutSection(self); + lSections[nSection++] = createSettingsSection(self); } else if (nProfile == PROFILE_GREETER) { - lSections[nSection++] = createDesktopLayoutSection(self, nProfile); + lSections[nSection++] = createLayoutSection(self); } // Add sections to the submenu @@ -239,7 +244,9 @@ static void createMenu(IndicatorKeyboardService *self, int nProfile) } // Add submenu to the header - pItem = g_menu_item_new(NULL, "indicator._header"); + gchar *sName = g_strdup_printf ("indicator._header-%s", m_lMenuNames[nProfile]); + pItem = g_menu_item_new(NULL, sName); + g_free (sName); g_menu_item_set_attribute(pItem, "x-ayatana-type", "s", "org.ayatana.indicator.root"); g_menu_item_set_submenu(pItem, G_MENU_MODEL(pSubmenu)); g_object_unref(pSubmenu); @@ -289,9 +296,14 @@ static void initActions(IndicatorKeyboardService *self) GSimpleAction *pAction; self->pPrivate->pActionGroup = g_simple_action_group_new(); - pAction = g_simple_action_new_stateful("_header", NULL, createHeaderState(self)); - g_action_map_add_action(G_ACTION_MAP(self->pPrivate->pActionGroup), G_ACTION(pAction)); - self->pPrivate->pHeaderAction = pAction; + for (int nProfile = 0; nProfile < N_PROFILES; ++nProfile) + { + gchar *sName = g_strdup_printf ("_header-%s", m_lMenuNames[nProfile]); + pAction = g_simple_action_new_stateful(sName, NULL, createHeaderState(self, nProfile)); + g_free (sName); + g_action_map_add_action(G_ACTION_MAP(self->pPrivate->pActionGroup), G_ACTION(pAction)); + self->pPrivate->lMenus[nProfile].pHeaderAction = pAction; + } pAction = g_simple_action_new("layout", G_VARIANT_TYPE_BYTE); g_action_map_add_action(G_ACTION_MAP(self->pPrivate->pActionGroup), G_ACTION(pAction)); @@ -405,7 +417,12 @@ static void onDispose(GObject *pObject) g_clear_object (&self->pPrivate->pSettingsAction); g_clear_object (&self->pPrivate->pLayoutAction); - g_clear_object (&self->pPrivate->pHeaderAction); + + for (int nProfile = 0; nProfile < N_PROFILES; ++nProfile) + { + g_clear_object (&self->pPrivate->lMenus[nProfile].pHeaderAction); + } + g_clear_object (&self->pPrivate->pActionGroup); g_clear_object (&self->pPrivate->pConnection); -- cgit v1.2.3 From c5d48625870952d8478e86c82d8b6803b65320ce Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 7 Sep 2022 06:19:14 +0200 Subject: Add GSettings options for indicator icon fixes https://github.com/AyatanaIndicators/ayatana-indicator-keyboard/issues/42 --- data/CMakeLists.txt | 8 +++++ data/org.ayatana.indicator.keyboard.gschema.xml.in | 19 ++++++++++++ src/service.c | 36 ++++++++++++++++++++-- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 data/org.ayatana.indicator.keyboard.gschema.xml.in diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 39bd0458..35bbfd54 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -53,3 +53,11 @@ install(FILES org.ayatana.indicator.keyboard.AccountsService.policy DESTINATION # 50-org.ayatana.indicator.keyboard.AccountsService.pkla install(FILES 50-org.ayatana.indicator.keyboard.AccountsService.pkla DESTINATION "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/polkit-1/localauthority/10-vendor.d") + +# org.ayatana.indicator.keyboard.gschema.xml + +find_package (Intltool REQUIRED) +set (ENV{LC_ALL} "C") +intltool_merge_translations ("${CMAKE_CURRENT_SOURCE_DIR}/org.ayatana.indicator.keyboard.gschema.xml.in" "${CMAKE_CURRENT_BINARY_DIR}/org.ayatana.indicator.keyboard.gschema.xml" ALL UTF8 STYLE "xml" NO_TRANSLATIONS) +find_package (GSettings REQUIRED) +add_schema ("org.ayatana.indicator.keyboard.gschema.xml") diff --git a/data/org.ayatana.indicator.keyboard.gschema.xml.in b/data/org.ayatana.indicator.keyboard.gschema.xml.in new file mode 100644 index 00000000..e80a89e9 --- /dev/null +++ b/data/org.ayatana.indicator.keyboard.gschema.xml.in @@ -0,0 +1,19 @@ + + + + true + <_summary>Show the language icon in desktop mode. + <_description>If enabled, the indicator shows the current layout icon. Otherwise, it displays a generic keyboard icon. + + + false + <_summary>Show the language icon in phone mode. + <_description>If enabled, the indicator shows the current layout icon. Otherwise, it displays a generic keyboard icon. + + + false + <_summary>Show the language icon in the greeter. + <_description>If enabled, the indicator shows the current layout icon. Otherwise, it displays a generic keyboard icon. + + + diff --git a/src/service.c b/src/service.c index ce4c0a80..3dabf5c9 100644 --- a/src/service.c +++ b/src/service.c @@ -76,6 +76,7 @@ struct _IndicatorKeyboardServicePrivate GSimpleAction *pLayoutAction; GMenu *pLayoutSection; Keyboard *pKeyboard; + GSettings *pSettings; }; typedef IndicatorKeyboardServicePrivate priv_t; @@ -90,8 +91,26 @@ static GVariant* createHeaderState(IndicatorKeyboardService *self, int nProfile) g_variant_builder_add(&cBuilder, "{sv}", "tooltip", g_variant_new_string(_("Keyboard layout switcher and settings"))); g_variant_builder_add(&cBuilder, "{sv}", "visible", g_variant_new_boolean(TRUE)); + gchar *sKey = NULL; + + if (nProfile == PROFILE_DESKTOP) + { + sKey = "language-icon-desktop"; + } + else if (nProfile == PROFILE_PHONE) + { + sKey = "language-icon-phone"; + } + else if (nProfile == PROFILE_GREETER) + { + sKey = "language-icon-greeter"; + } + + gboolean bLayout = g_settings_get_boolean (self->pPrivate->pSettings, sKey); GIcon *pIcon = NULL; - if (ayatana_common_utils_is_lomiri()) { + + if (bLayout == FALSE) + { pIcon = g_themed_icon_new_with_default_fallbacks(ICON_DEFAULT); } else @@ -395,6 +414,12 @@ static void onDispose(GObject *pObject) { IndicatorKeyboardService *self = INDICATOR_KEYBOARD_SERVICE(pObject); + if (self->pPrivate->pSettings != NULL) + { + g_signal_handlers_disconnect_by_data (self->pPrivate->pSettings, self); + g_clear_object (&self->pPrivate->pSettings); + } + if (self->pPrivate->pKeyboard != NULL) { g_object_unref(G_OBJECT(self->pPrivate->pKeyboard)); @@ -435,6 +460,12 @@ static void onDispose(GObject *pObject) G_OBJECT_CLASS(indicator_keyboard_service_parent_class)->dispose(pObject); } +static void onSettingsChanged(GSettings *pSettings, gchar *sKey, gpointer pData) +{ + IndicatorKeyboardService *self = INDICATOR_KEYBOARD_SERVICE(pData); + rebuildNow(self, SECTION_HEADER); +} + static void indicator_keyboard_service_init(IndicatorKeyboardService *self) { gchar *sLib = "libayatana-keyboard-x11.so.0"; @@ -464,9 +495,10 @@ static void indicator_keyboard_service_init(IndicatorKeyboardService *self) m_fnKeyboardGetNumLayouts = dlsym(m_pLibHandle, "keyboard_GetNumLayouts"); m_fnKeyboardGetLayout = dlsym(m_pLibHandle, "keyboard_GetLayout"); m_fnKeyboardSetLayout = dlsym(m_pLibHandle, "keyboard_SetLayout"); - self->pPrivate = indicator_keyboard_service_get_instance_private(self); self->pPrivate->pCancellable = g_cancellable_new(); + self->pPrivate->pSettings = g_settings_new ("org.ayatana.indicator.keyboard"); + g_signal_connect(self->pPrivate->pSettings, "changed", G_CALLBACK(onSettingsChanged), self); self->pPrivate->pKeyboard = m_fnKeyboardNew(); g_signal_connect(self->pPrivate->pKeyboard, KEYBOARD_LAYOUT_CHANGED, G_CALLBACK(onLayoutChanged), self); g_signal_connect(self->pPrivate->pKeyboard, KEYBOARD_CONFIG_CHANGED, G_CALLBACK(onConfigChanged), self); -- cgit v1.2.3 From 5ad5e033821a09386c3fd55d8f71bc2f929f36ae Mon Sep 17 00:00:00 2001 From: Moo Date: Wed, 7 Sep 2022 08:27:04 +0000 Subject: Translated using Weblate (Lithuanian) Currently translated at 100.0% (4 of 4 strings) Translation: Ayatana Indicators/Keyboard Applet Translate-URL: https://hosted.weblate.org/projects/ayatana-indicators/keyboard-applet/lt/ --- po/lt.po | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/po/lt.po b/po/lt.po index c5836f05..4a3647ca 100644 --- a/po/lt.po +++ b/po/lt.po @@ -8,17 +8,18 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-09-05 13:18+0200\n" -"PO-Revision-Date: 2021-01-30 15:41+0000\n" +"PO-Revision-Date: 2022-09-08 09:17+0000\n" "Last-Translator: Moo \n" -"Language-Team: Lithuanian \n" +"Language-Team: Lithuanian \n" "Language: lt\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n" -"%100<10 || n%100>=20) ? 1 : 2);\n" -"X-Generator: Weblate 4.5-dev\n" +"Plural-Forms: nplurals=3; plural=(n % 10 == 1 && (n % 100 < 11 || n % 100 > " +"19)) ? 0 : ((n % 10 >= 2 && n % 10 <= 9 && (n % 100 < 11 || n % 100 > 19)) ? " +"1 : 2);\n" +"X-Generator: Weblate 4.14.1-dev\n" #: ../src/service.c:89 msgid "Keyboard" @@ -26,13 +27,12 @@ msgstr "Klaviatūra" #: ../src/service.c:90 msgid "Keyboard layout switcher and settings" -msgstr "" +msgstr "Klaviatūros nustatymai ir išdėstymo perjungiklis" #: ../src/service.c:109 msgid "Current keyboard layout" msgstr "Dabartinis klaviatūros išdėstymas" #: ../src/service.c:166 -#, fuzzy msgid "Keyboard Settings…" -msgstr "Klaviatūros nustatymai..." +msgstr "Klaviatūros nustatymai…" -- cgit v1.2.3