[Xfce4-commits] [apps/xfce4-screensaver] 04/06: cleanup kbd indicator logic
noreply at xfce.org
noreply at xfce.org
Tue Jun 18 01:33:27 CEST 2019
This is an automated email from the git hooks/post-receive script.
b l u e s a b r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository apps/xfce4-screensaver.
commit ee49e733a1329f3be3e6455be1686ad665f1bfe5
Author: Alexander Butenko <a.butenka at gmail.com>
Date: Sun Jun 16 18:39:42 2019 -0400
cleanup kbd indicator logic
Signed-off-by: Sean Davis <smd.seandavis at gmail.com>
---
src/xfcekbd-config-private.h | 71 ----------
src/xfcekbd-desktop-config.c | 244 ----------------------------------
src/xfcekbd-desktop-config.h | 73 ----------
src/xfcekbd-indicator-config.c | 88 ------------
src/xfcekbd-indicator-config.h | 62 ---------
src/xfcekbd-indicator-marshal.list | 1 -
src/xfcekbd-indicator.c | 265 +++++--------------------------------
src/xfcekbd-keyboard-config.c | 218 ------------------------------
src/xfcekbd-keyboard-config.h | 64 ---------
9 files changed, 34 insertions(+), 1052 deletions(-)
diff --git a/src/xfcekbd-config-private.h b/src/xfcekbd-config-private.h
deleted file mode 100644
index df0fd62..0000000
--- a/src/xfcekbd-config-private.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2006 Sergey V. Udaltsov <svu at gnome.org>
- * Copyright (C) 2018 Sean Davis <bluesabre at xfce.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; see the file COPYING.LGPL. If not,
- * write to the Free Software Foundation, Inc., 51 Franklin St,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef SRC_XFCEKBD_CONFIG_PRIVATE_H_
-#define SRC_XFCEKBD_CONFIG_PRIVATE_H_
-
-#include "xfcekbd-desktop-config.h"
-#include "xfcekbd-keyboard-config.h"
-
-#define SETTINGS_XFCONF_CHANNEL "xfce4-screensaver"
-
-/**
- * KBD/General: Default group, assigned on window creation
- */
-#define KEY_KBD_DEFAULT_GROUP "/xkb/default-group"
-#define DEFAULT_KEY_KBD_DEFAULT_GROUP -1
-
-/**
- * KBD/General: Keep and manage separate group per window
- */
-#define KEY_KBD_GROUP_PER_WINDOW "/xkb/group-per-window"
-#define DEFAULT_KEY_KBD_GROUP_PER_WINDOW TRUE
-
-/**
- * KBD/General: Save/restore indicators together with layout groups
- */
-#define KEY_KBD_HANDLE_INDICATORS "/xkb/handle-indicators"
-#define DEFAULT_KEY_KBD_HANDLE_INDICATORS FALSE
-
-/**
- * KBD/General: Load extra configuration items
- * Load exotic, rarely used layouts and options
- */
-#define KEY_KBD_LOAD_EXTRA_ITEMS "/xkb/load-extra-items"
-#define DEFAULT_KEY_KBD_LOAD_EXTRA_ITEMS FALSE
-
-/**
- * KBD/Indicator: Secondary groups
- */
-#define KEY_KBD_SECONDARY_GROUPS "/xkb/secondary-groups"
-#define DEFAULT_KEY_KBD_SECONDARY_GROUPS 0
-
-/**
- * General config functions (private)
- */
-extern void xfcekbd_keyboard_config_model_set (XfcekbdKeyboardConfig *kbd_config,
- const gchar *model_name);
-
-extern void xfcekbd_keyboard_config_options_set (XfcekbdKeyboardConfig *kbd_config,
- gint idx,
- const gchar *group_name,
- const gchar *option_name);
-
-#endif /* SRC_XFCEKBD_CONFIG_PRIVATE_H_ */
diff --git a/src/xfcekbd-desktop-config.c b/src/xfcekbd-desktop-config.c
deleted file mode 100644
index 88322aa..0000000
--- a/src/xfcekbd-desktop-config.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright (C) 2006 Sergey V. Udaltsov <svu at gnome.org>
- * Copyright (C) 2018 Sean Davis <bluesabre at xfce.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; see the file COPYING.LGPL. If not,
- * write to the Free Software Foundation, Inc., 51 Franklin St,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <X11/keysym.h>
-
-#include <gio/gio.h>
-
-#include <libxfce4util/libxfce4util.h>
-#include <xfconf/xfconf.h>
-
-#include "gs-debug.h"
-#include "xfcekbd-desktop-config.h"
-#include "xfcekbd-config-private.h"
-
-/*
- * static common functions
- */
-
-static gboolean
-xfcekbd_desktop_config_get_lv_descriptions (XfcekbdDesktopConfig *config,
- XklConfigRegistry *registry,
- const gchar **layout_ids,
- const gchar **variant_ids,
- gchar ***short_layout_descriptions,
- gchar ***long_layout_descriptions,
- gchar ***short_variant_descriptions,
- gchar ***long_variant_descriptions) {
- const gchar **pl, **pv;
- guint total_layouts;
- gchar **sld, **lld, **svd, **lvd;
- XklConfigItem *item = xkl_config_item_new ();
-
- if (!(xkl_engine_get_features (config->engine) & XKLF_MULTIPLE_LAYOUTS_SUPPORTED))
- return FALSE;
-
- pl = layout_ids;
- pv = variant_ids;
- total_layouts = g_strv_length ((char **) layout_ids);
- sld = *short_layout_descriptions = g_new0 (gchar *, total_layouts + 1);
- lld = *long_layout_descriptions = g_new0 (gchar *, total_layouts + 1);
- svd = *short_variant_descriptions = g_new0 (gchar *, total_layouts + 1);
- lvd = *long_variant_descriptions = g_new0 (gchar *, total_layouts + 1);
-
- while (pl != NULL && *pl != NULL) {
- xkl_debug (100, "ids: [%s][%s]\n", *pl, pv == NULL ? NULL : *pv);
-
- g_snprintf (item->name, sizeof item->name, "%s", *pl);
- if (xkl_config_registry_find_layout (registry, item)) {
- *sld = g_strdup (item->short_description);
- *lld = g_strdup (item->description);
- } else {
- *sld = g_strdup ("");
- *lld = g_strdup ("");
- }
-
- if (pv != NULL && *pv != NULL) {
- g_snprintf (item->name, sizeof item->name, "%s", *pv);
- if (xkl_config_registry_find_variant (registry, *pl, item)) {
- *svd = g_strdup (item->short_description);
- *lvd = g_strdup (item->description);
- } else {
- *svd = g_strdup ("");
- *lvd = g_strdup ("");
- }
- } else {
- *svd = g_strdup ("");
- *lvd = g_strdup ("");
- }
-
- xkl_debug (100, "description: [%s][%s][%s][%s]\n", *sld, *lld, *svd, *lvd);
- sld++;
- lld++;
- svd++;
- lvd++;
-
- pl++;
-
- if (pv != NULL && *pv != NULL)
- pv++;
- }
-
- g_object_unref (item);
- return TRUE;
-}
-
-/*
- * extern XfcekbdDesktopConfig config functions
- */
-void
-xfcekbd_desktop_config_init (XfcekbdDesktopConfig *config,
- XklEngine *engine) {
- memset (config, 0, sizeof (*config));
- config->channel = xfconf_channel_get (SETTINGS_XFCONF_CHANNEL);
- config->engine = engine;
-}
-
-void
-xfcekbd_desktop_config_term (XfcekbdDesktopConfig *config) {
- g_object_unref (config->channel);
- config->channel = NULL;
-}
-
-void
-xfcekbd_desktop_config_load_from_xfconf (XfcekbdDesktopConfig *config) {
- config->group_per_app =
- xfconf_channel_get_bool(config->channel,
- KEY_KBD_GROUP_PER_WINDOW,
- DEFAULT_KEY_KBD_GROUP_PER_WINDOW);
- gs_debug("group_per_app: %d\n", config->group_per_app);
-
- config->handle_indicators =
- xfconf_channel_get_bool(config->channel,
- KEY_KBD_HANDLE_INDICATORS,
- DEFAULT_KEY_KBD_HANDLE_INDICATORS);
- gs_debug("handle_indicators: %d\n", config->handle_indicators);
-
- config->load_extra_items =
- xfconf_channel_get_bool(config->channel,
- KEY_KBD_LOAD_EXTRA_ITEMS,
- DEFAULT_KEY_KBD_LOAD_EXTRA_ITEMS);
- gs_debug("load_extra_items: %d\n", config->load_extra_items);
-
- config->default_group =
- xfconf_channel_get_int(config->channel,
- KEY_KBD_DEFAULT_GROUP,
- DEFAULT_KEY_KBD_DEFAULT_GROUP);
-
- if (config->default_group < -1
- || config->default_group >=
- xkl_engine_get_max_num_groups (config->engine)) {
- config->default_group = -1;
- }
- gs_debug("default_group: %d\n", config->default_group);
-}
-
-gboolean
-xfcekbd_desktop_config_activate (XfcekbdDesktopConfig *config) {
- gboolean rv = TRUE;
-
- xkl_engine_set_group_per_toplevel_window (config->engine,
- config->group_per_app);
- xkl_engine_set_indicators_handling (config->engine,
- config->handle_indicators);
- xkl_engine_set_default_group (config->engine,
- config->default_group);
-
- return rv;
-}
-
-void
-xfcekbd_desktop_config_lock_next_group (XfcekbdDesktopConfig *config) {
- int group = xkl_engine_get_next_group (config->engine);
- xkl_engine_lock_group (config->engine, group);
-}
-
-/**
- * xfcekbd_desktop_config_start_listen:
- * @func: (scope notified): a function to call when settings are changed
- */
-void
-xfcekbd_desktop_config_start_listen (XfcekbdDesktopConfig *config,
- GCallback func,
- gpointer user_data) {
- config->config_listener_id =
- g_signal_connect (config->channel, "property-changed", func,
- user_data);
-}
-
-void
-xfcekbd_desktop_config_stop_listen (XfcekbdDesktopConfig *config) {
- g_signal_handler_disconnect (config->channel,
- config->config_listener_id);
- config->config_listener_id = 0;
-}
-
-gboolean
-xfcekbd_desktop_config_load_group_descriptions (XfcekbdDesktopConfig *config,
- XklConfigRegistry *registry,
- const gchar **layout_ids,
- const gchar **variant_ids,
- gchar ***short_group_names,
- gchar ***full_group_names) {
- gchar **sld, **lld, **svd, **lvd;
- gchar **psld, **plld, **plvd;
- gchar **psgn, **pfgn, **psvd;
- gint total_descriptions;
-
- if (!xfcekbd_desktop_config_get_lv_descriptions (config,
- registry,
- layout_ids,
- variant_ids,
- &sld,
- &lld,
- &svd,
- &lvd)) {
- return False;
- }
-
- total_descriptions = g_strv_length (sld);
-
- *short_group_names = psgn = g_new0 (gchar *, total_descriptions + 1);
- *full_group_names = pfgn = g_new0 (gchar *, total_descriptions + 1);
-
- plld = lld;
- psld = sld;
- plvd = lvd;
- psvd = svd;
- while (plld != NULL && *plld != NULL) {
- gchar *sd = (*psvd[0] == '\0') ? *psld : *psvd;
- psld++, psvd++;
- *psgn++ = g_strdup (sd);
- *pfgn++ = g_strdup (xfcekbd_keyboard_config_format_full_layout
- (*plld++, *plvd++));
- }
- g_strfreev (sld);
- g_strfreev (lld);
- g_strfreev (svd);
- g_strfreev (lvd);
-
- return True;
-}
diff --git a/src/xfcekbd-desktop-config.h b/src/xfcekbd-desktop-config.h
deleted file mode 100644
index 7910c4a..0000000
--- a/src/xfcekbd-desktop-config.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2006 Sergey V. Udaltsov <svu at gnome.org>
- * Copyright (C) 2018 Sean Davis <bluesabre at xfce.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; see the file COPYING.LGPL. If not,
- * write to the Free Software Foundation, Inc., 51 Franklin St,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef SRC_XFCEKBD_DESKTOP_CONFIG_H_
-#define SRC_XFCEKBD_DESKTOP_CONFIG_H_
-
-#include <X11/Xlib.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <libxklavier/xklavier.h>
-
-#include <xfconf/xfconf.h>
-
-/*
- * General configuration
- */
-typedef struct _XfcekbdDesktopConfig XfcekbdDesktopConfig;
-struct _XfcekbdDesktopConfig {
- gint default_group;
- gboolean group_per_app;
- gboolean handle_indicators;
- gboolean load_extra_items;
-
- /* private, transient */
- XfconfChannel *channel;
- int config_listener_id;
- XklEngine *engine;
-};
-
-/*
- * XfcekbdDesktopConfig functions
- */
-extern void xfcekbd_desktop_config_init (XfcekbdDesktopConfig *config,
- XklEngine *engine);
-extern void xfcekbd_desktop_config_term (XfcekbdDesktopConfig *config);
-
-extern void xfcekbd_desktop_config_load_from_xfconf (XfcekbdDesktopConfig *config);
-
-extern gboolean xfcekbd_desktop_config_activate (XfcekbdDesktopConfig *config);
-
-extern gboolean xfcekbd_desktop_config_load_group_descriptions (XfcekbdDesktopConfig *config,
- XklConfigRegistry *registry,
- const gchar **layout_ids,
- const gchar **variant_ids,
- gchar ***short_group_names,
- gchar ***full_group_names);
-
-extern void xfcekbd_desktop_config_lock_next_group (XfcekbdDesktopConfig *config);
-
-extern void xfcekbd_desktop_config_start_listen (XfcekbdDesktopConfig *config,
- GCallback func,
- gpointer user_data);
-
-extern void xfcekbd_desktop_config_stop_listen (XfcekbdDesktopConfig *config);
-
-#endif /* SRC_XFCEKBD_DESKTOP_CONFIG_H_ */
diff --git a/src/xfcekbd-indicator-config.c b/src/xfcekbd-indicator-config.c
deleted file mode 100644
index d795a6b..0000000
--- a/src/xfcekbd-indicator-config.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2006 Sergey V. Udaltsov <svu at gnome.org>
- * Copyright (C) 2018 Sean Davis <bluesabre at xfce.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; see the file COPYING.LGPL. If not,
- * write to the Free Software Foundation, Inc., 51 Franklin St,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <X11/keysym.h>
-
-#include <libxfce4util/libxfce4util.h>
-#include <xfconf/xfconf.h>
-
-#include "xfcekbd-keyboard-config.h"
-#include "xfcekbd-indicator-config.h"
-#include "xfcekbd-config-private.h"
-
-/*
- * static applet config functions
- */
-
-void
-xfcekbd_indicator_config_init (XfcekbdIndicatorConfig *ind_config,
- XklEngine *engine) {
- memset (ind_config, 0, sizeof (*ind_config));
- ind_config->channel = xfconf_channel_get (SETTINGS_XFCONF_CHANNEL);
- ind_config->engine = engine;
-}
-
-void
-xfcekbd_indicator_config_term (XfcekbdIndicatorConfig *ind_config) {
- g_object_unref (ind_config->channel);
- ind_config->channel = NULL;
-}
-
-void
-xfcekbd_indicator_config_load_from_xfconf (XfcekbdIndicatorConfig * ind_config) {
- ind_config->secondary_groups_mask =
- xfconf_channel_get_int (ind_config->channel,
- KEY_KBD_SECONDARY_GROUPS,
- DEFAULT_KEY_KBD_SECONDARY_GROUPS);
-}
-
-void
-xfcekbd_indicator_config_activate (XfcekbdIndicatorConfig * ind_config) {
- xkl_engine_set_secondary_groups_mask (ind_config->engine,
- ind_config->secondary_groups_mask);
-}
-
-/**
- * xfcekbd_indicator_config_start_listen:
- * @func: (scope notified): a function to call when settings are changed
- */
-void
-xfcekbd_indicator_config_start_listen (XfcekbdIndicatorConfig *ind_config,
- GCallback func,
- gpointer user_data) {
- ind_config->config_listener_id =
- g_signal_connect (ind_config->channel,
- "property-changed",
- func,
- user_data);
-}
-
-void
-xfcekbd_indicator_config_stop_listen (XfcekbdIndicatorConfig *ind_config) {
- g_signal_handler_disconnect (ind_config->channel,
- ind_config->config_listener_id);
- ind_config->config_listener_id = 0;
-}
diff --git a/src/xfcekbd-indicator-config.h b/src/xfcekbd-indicator-config.h
deleted file mode 100644
index e139e67..0000000
--- a/src/xfcekbd-indicator-config.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2006 Sergey V. Udaltsov <svu at gnome.org>
- * Copyright (C) 2018 Sean Davis <bluesabre at xfce.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; see the file COPYING.LGPL. If not,
- * write to the Free Software Foundation, Inc., 51 Franklin St,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef SRC_XFCEKBD_INDICATOR_CONFIG_H_
-#define SRC_XFCEKBD_INDICATOR_CONFIG_H_
-
-#include <gtk/gtk.h>
-#include <xfconf/xfconf.h>
-
-#include "xfcekbd-keyboard-config.h"
-
-/*
- * Indicator configuration
- */
-typedef struct _XfcekbdIndicatorConfig XfcekbdIndicatorConfig;
-struct _XfcekbdIndicatorConfig {
- int secondary_groups_mask;
-
- /* private, transient */
- XfconfChannel *channel;
- int config_listener_id;
- XklEngine *engine;
-};
-
-/*
- * XfcekbdIndicatorConfig functions -
- * some of them require XfcekbdKeyboardConfig as well -
- * for loading approptiate images
- */
-void xfcekbd_indicator_config_init (XfcekbdIndicatorConfig *ind_config,
- XklEngine *engine);
-void xfcekbd_indicator_config_term (XfcekbdIndicatorConfig *ind_config);
-
-void xfcekbd_indicator_config_load_from_xfconf (XfcekbdIndicatorConfig *ind_config);
-
-/* Should be updated on Indicator/Xfconf configuration change */
-void xfcekbd_indicator_config_activate (XfcekbdIndicatorConfig *ind_config);
-
-void xfcekbd_indicator_config_start_listen (XfcekbdIndicatorConfig *ind_config,
- GCallback func,
- gpointer user_data);
-
-void xfcekbd_indicator_config_stop_listen (XfcekbdIndicatorConfig *ind_config);
-
-#endif /* SRC_XFCEKBD_INDICATOR_CONFIG_H_ */
diff --git a/src/xfcekbd-indicator-marshal.list b/src/xfcekbd-indicator-marshal.list
deleted file mode 100644
index 5b76282..0000000
--- a/src/xfcekbd-indicator-marshal.list
+++ /dev/null
@@ -1 +0,0 @@
-VOID:VOID
diff --git a/src/xfcekbd-indicator.c b/src/xfcekbd-indicator.c
index 8413b22..482c5ff 100644
--- a/src/xfcekbd-indicator.c
+++ b/src/xfcekbd-indicator.c
@@ -29,22 +29,11 @@
#include <libxfce4util/libxfce4util.h>
#include "gs-debug.h"
-#include "xfcekbd-desktop-config.h"
#include "xfcekbd-indicator.h"
-#include "xfcekbd-indicator-config.h"
-#include "xfcekbd-indicator-marshal.h"
typedef struct _gki_globals {
XklEngine *engine;
- XklConfigRegistry *registry;
-
- XfcekbdDesktopConfig cfg;
- XfcekbdIndicatorConfig ind_cfg;
- XfcekbdKeyboardConfig kbd_cfg;
-
const gchar *tooltips_format;
- gchar **full_group_names;
- gchar **short_group_names;
GSList *widget_instances;
gboolean redraw_queued;
@@ -128,6 +117,8 @@ xfcekbd_indicator_fill (XfcekbdIndicator * gki) {
static gboolean xfcekbd_indicator_key_pressed (GtkWidget *widget,
GdkEventKey *event,
XfcekbdIndicator *gki) {
+ int group;
+
switch (event->keyval) {
case GDK_KEY_KP_Enter:
case GDK_KEY_ISO_Enter:
@@ -135,7 +126,9 @@ static gboolean xfcekbd_indicator_key_pressed (GtkWidget *widget,
case GDK_KEY_Return:
case GDK_KEY_space:
case GDK_KEY_KP_Space:
- xfcekbd_desktop_config_lock_next_group(&globals.cfg);
+ gs_debug("Switching language");
+ group = xkl_engine_get_next_group (globals.engine);
+ xkl_engine_lock_group (globals.engine, group);
globals.redraw_queued = TRUE;
return TRUE;
default:
@@ -150,8 +143,9 @@ xfcekbd_indicator_button_pressed (GtkWidget *widget,
GdkEventButton *event,
XfcekbdIndicator *gki) {
if (event->button == 1 && event->type == GDK_BUTTON_PRESS) {
- gs_debug("Mouse button pressed on applet\n");
- xfcekbd_desktop_config_lock_next_group (&globals.cfg);
+ gs_debug("Switching language");
+ int group = xkl_engine_get_next_group (globals.engine);
+ xkl_engine_lock_group (globals.engine, group);
globals.redraw_queued = TRUE;
return TRUE;
}
@@ -159,46 +153,17 @@ xfcekbd_indicator_button_pressed (GtkWidget *widget,
}
static gchar *
-xfcekbd_indicator_extract_layout_name (int group,
- XklEngine *engine,
- XfcekbdKeyboardConfig *kbd_cfg,
- gchar **short_group_names,
- gchar **full_group_names) {
- char *layout_name = NULL;
- if (group < g_strv_length (short_group_names)) {
- if (xkl_engine_get_features (engine) & XKLF_MULTIPLE_LAYOUTS_SUPPORTED) {
- char *full_layout_name = kbd_cfg->layouts_variants[group];
- char *variant_name;
- if (!xfcekbd_keyboard_config_split_items (full_layout_name,
- &layout_name,
- &variant_name)) {
- /* just in case */
- layout_name = full_layout_name;
- }
+xfcekbd_indicator_extract_layout_name (int groupId) {
+ const gchar** layouts;
- /* make it freeable */
- layout_name = g_strdup (layout_name);
+ layouts = xkl_engine_get_groups_names (globals.engine);
- if (short_group_names != NULL) {
- char *short_group_name = short_group_names[group];
- if (short_group_name != NULL && *short_group_name != '\0') {
- /* drop the long name */
- g_free (layout_name);
- layout_name =
- g_strdup (short_group_name);
- }
- }
- } else {
- layout_name = g_strdup (full_group_names[group]);
- }
- }
-
- if (layout_name == NULL)
- layout_name = g_strdup ("");
-
- return layout_name;
+ if (strlen (layouts[groupId]) < 2)
+ return g_strdup ("");
+ return g_strndup (layouts[groupId], 2);
}
+
static gchar *
xfcekbd_indicator_create_label_title (int group,
GHashTable **ln2cnt_map,
@@ -238,7 +203,7 @@ xfcekbd_indicator_create_label_title (int group,
static GtkWidget *
xfcekbd_indicator_prepare_drawing (XfcekbdIndicator *gki,
- int group) {
+ int groupId) {
GtkWidget *ebox;
char *lbl_title = NULL;
@@ -249,17 +214,10 @@ xfcekbd_indicator_prepare_drawing (XfcekbdIndicator *gki,
ebox = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
- layout_name =
- xfcekbd_indicator_extract_layout_name (group,
- globals.engine,
- &globals.kbd_cfg,
- globals.short_group_names,
- globals.full_group_names);
+ layout_name = xfcekbd_indicator_extract_layout_name (groupId);
+ gs_debug ("setting lang to %s", layout_name);
- lbl_title =
- xfcekbd_indicator_create_label_title (group,
- &ln2cnt_map,
- layout_name);
+ lbl_title = xfcekbd_indicator_create_label_title (groupId, &ln2cnt_map, layout_name);
label = gtk_label_new (lbl_title);
gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
@@ -271,7 +229,7 @@ xfcekbd_indicator_prepare_drawing (XfcekbdIndicator *gki,
g_free (lbl_title);
gtk_label_set_angle (GTK_LABEL (label), gki->priv->angle);
- if (group + 1 == xkl_engine_get_num_groups (globals.engine)) {
+ if (groupId + 1 == xkl_engine_get_num_groups (globals.engine)) {
g_hash_table_destroy (ln2cnt_map);
ln2cnt_map = NULL;
}
@@ -294,15 +252,17 @@ xfcekbd_indicator_prepare_drawing (XfcekbdIndicator *gki,
static void
xfcekbd_indicator_update_tooltips (XfcekbdIndicator *gki) {
XklState *state = xkl_engine_get_current_state (globals.engine);
- gchar *buf;
+ const gchar** layouts = xkl_engine_get_groups_names (globals.engine);
+ gchar *buf;
+
if (state == NULL ||
state->group < 0 ||
- state->group >= g_strv_length (globals.full_group_names)) {
+ state->group >= g_strv_length ((gchar **)layouts)) {
return;
}
- buf = g_strdup_printf (globals.tooltips_format, globals.full_group_names[state->group]);
-
+ buf = g_strdup_printf (globals.tooltips_format, layouts[state->group]);
+ gs_debug ("setting lang to %s", layouts[state->group]);
xfcekbd_indicator_set_tooltips (gki, buf);
g_free (buf);
}
@@ -313,97 +273,6 @@ xfcekbd_indicator_parent_set (GtkWidget *gki,
xfcekbd_indicator_update_tooltips (XFCEKBD_INDICATOR (gki));
}
-
-static void
-xfcekbd_indicator_reinit_ui (XfcekbdIndicator *gki) {
- xfcekbd_indicator_cleanup (gki);
- xfcekbd_indicator_fill (gki);
-
- xfcekbd_indicator_set_current_page (gki);
-
- g_signal_emit_by_name (gki, "reinit-ui");
-}
-
-/* Should be called once for all widgets */
-static void
-xfcekbd_indicator_cfg_changed (XfconfChannel *channel,
- gchar *key,
- gpointer user_data) {
- gs_debug( "General configuration changed in Xfconf - reiniting...\n");
- xfcekbd_desktop_config_load_from_xfconf (&globals.cfg);
- xfcekbd_desktop_config_activate (&globals.cfg);
- ForAllIndicators () {
- xfcekbd_indicator_reinit_ui (gki);
- } NextIndicator ();
-}
-
-/* Should be called once for all widgets */
-static void
-xfcekbd_indicator_ind_cfg_changed (XfconfChannel *channel,
- gchar *key,
- gpointer user_data) {
- gs_debug( "Applet configuration changed in Xfconf - reiniting...\n");
- xfcekbd_indicator_config_load_from_xfconf (&globals.ind_cfg);
- xfcekbd_indicator_config_activate (&globals.ind_cfg);
-
- ForAllIndicators () {
- xfcekbd_indicator_reinit_ui (gki);
- } NextIndicator ();
-}
-
-static void
-xfcekbd_indicator_load_group_names (const gchar **layout_ids,
- const gchar **variant_ids) {
- if (!xfcekbd_desktop_config_load_group_descriptions (&globals.cfg,
- globals.registry,
- layout_ids,
- variant_ids,
- &globals.short_group_names,
- &globals.full_group_names)) {
- /* We just populate no short names (remain NULL) -
- * full names are going to be used anyway */
- gint i, total_groups = xkl_engine_get_num_groups (globals.engine);
- globals.full_group_names = g_new0 (gchar *, total_groups + 1);
-
- if (xkl_engine_get_features (globals.engine) & XKLF_MULTIPLE_LAYOUTS_SUPPORTED) {
- gchar **lst = globals.kbd_cfg.layouts_variants;
- for (i = 0; *lst; lst++, i++) {
- globals.full_group_names[i] = g_strdup ((char *) *lst);
- }
- } else {
- for (i = total_groups; --i >= 0;) {
- globals.full_group_names[i] = g_strdup_printf ("Group %d", i);
- }
- }
- }
-}
-
-/* Should be called once for all widgets */
-static void
-xfcekbd_indicator_kbd_cfg_callback (XfcekbdIndicator *gki) {
- XklConfigRec *xklrec = xkl_config_rec_new ();
- gs_debug( "XKB configuration changed on X Server - reiniting...\n");
-
- xfcekbd_keyboard_config_load_from_x_current (&globals.kbd_cfg, xklrec);
-
- g_strfreev (globals.full_group_names);
- globals.full_group_names = NULL;
-
- if (globals.short_group_names != NULL) {
- g_strfreev (globals.short_group_names);
- globals.short_group_names = NULL;
- }
-
- xfcekbd_indicator_load_group_names ((const gchar **) xklrec->layouts,
- (const gchar **)
- xklrec->variants);
-
- ForAllIndicators () {
- xfcekbd_indicator_reinit_ui (gki);
- } NextIndicator ();
- g_object_unref (G_OBJECT (xklrec));
-}
-
/* Should be called once for all applets */
static void
xfcekbd_indicator_state_callback (XklEngine *engine,
@@ -414,21 +283,18 @@ xfcekbd_indicator_state_callback (XklEngine *engine,
if (changeType == GROUP_CHANGED) {
ForAllIndicators () {
- xfcekbd_indicator_set_current_page_for_group
- (gki, group);
+ xfcekbd_indicator_set_current_page_for_group (gki, group);
}
NextIndicator ();
}
}
-
void
xfcekbd_indicator_set_current_page (XfcekbdIndicator *gki) {
XklState *cur_state;
cur_state = xkl_engine_get_current_state (globals.engine);
if (cur_state->group >= 0)
- xfcekbd_indicator_set_current_page_for_group (gki,
- cur_state->group);
+ xfcekbd_indicator_set_current_page_for_group (gki, cur_state->group);
}
void
@@ -554,17 +420,14 @@ static void xfcekbd_indicator_init(XfcekbdIndicator *gki) {
static void
xfcekbd_indicator_finalize (GObject *obj) {
XfcekbdIndicator *gki = XFCEKBD_INDICATOR (obj);
- gs_debug(
- "Starting the xfce-kbd-indicator widget shutdown process for %p\n",
- gki);
+ gs_debug("Starting the xfce-kbd-indicator widget shutdown process for %p", gki);
/* remove BEFORE all termination work is finished */
globals.widget_instances = g_slist_remove (globals.widget_instances, gki);
xfcekbd_indicator_cleanup (gki);
- gs_debug(
- "The instance of xfce-kbd-indicator successfully finalized\n");
+ gs_debug("The instance of xfce-kbd-indicator successfully finalized");
g_free (gki->priv);
@@ -579,15 +442,6 @@ xfcekbd_indicator_global_term (void) {
gs_debug( "*** Last XfcekbdIndicator instance ***\n");
xfcekbd_indicator_stop_listen ();
- xfcekbd_desktop_config_stop_listen (&globals.cfg);
- xfcekbd_indicator_config_stop_listen (&globals.ind_cfg);
-
- xfcekbd_indicator_config_term (&globals.ind_cfg);
- xfcekbd_keyboard_config_term (&globals.kbd_cfg);
- xfcekbd_desktop_config_term (&globals.cfg);
-
- g_object_unref (G_OBJECT (globals.registry));
- globals.registry = NULL;
g_object_unref (G_OBJECT (globals.engine));
globals.engine = NULL;
gs_debug( "*** Terminated globals *** \n");
@@ -598,82 +452,31 @@ xfcekbd_indicator_class_init (XfcekbdIndicatorClass *klass) {
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- gs_debug( "*** First XfcekbdIndicator instance *** \n");
+ gs_debug( "*** First XfcekbdIndicator instance ***");
memset (&globals, 0, sizeof (globals));
/* Initing some global vars */
globals.tooltips_format = "%s";
-
globals.redraw_queued = FALSE;
/* Initing vtable */
object_class->finalize = xfcekbd_indicator_finalize;
-
widget_class->scroll_event = xfcekbd_indicator_scroll;
widget_class->parent_set = xfcekbd_indicator_parent_set;
-
- /* Signals */
- g_signal_new ("reinit-ui",
- XFCEKBD_TYPE_INDICATOR,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (XfcekbdIndicatorClass, reinit_ui),
- NULL, NULL, xfcekbd_indicator_VOID__VOID,
- G_TYPE_NONE, 0);
}
static void
xfcekbd_indicator_global_init (void) {
- XklConfigRec *xklrec = xkl_config_rec_new ();
-
globals.engine = xkl_engine_get_instance(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()));
-
if (globals.engine == NULL) {
gs_debug("Libxklavier initialization error");
return;
}
-
- g_signal_connect (globals.engine,
- "X-state-changed",
- G_CALLBACK (xfcekbd_indicator_state_callback),
- NULL);
- g_signal_connect (globals.engine,
- "X-config-changed",
- G_CALLBACK (xfcekbd_indicator_kbd_cfg_callback),
- NULL);
-
- xfcekbd_desktop_config_init (&globals.cfg, globals.engine);
- xfcekbd_keyboard_config_init (&globals.kbd_cfg, globals.engine);
- xfcekbd_indicator_config_init (&globals.ind_cfg, globals.engine);
-
- xfcekbd_desktop_config_start_listen (&globals.cfg,
- (GCallback)
- xfcekbd_indicator_cfg_changed,
- NULL);
- xfcekbd_indicator_config_start_listen (&globals.ind_cfg,
- (GCallback)
- xfcekbd_indicator_ind_cfg_changed,
- NULL);
-
- xfcekbd_desktop_config_load_from_xfconf (&globals.cfg);
- xfcekbd_desktop_config_activate (&globals.cfg);
-
- globals.registry = xkl_config_registry_get_instance (globals.engine);
- xkl_config_registry_load (globals.registry, globals.cfg.load_extra_items);
-
- xfcekbd_keyboard_config_load_from_x_current (&globals.kbd_cfg, xklrec);
-
- xfcekbd_indicator_config_load_from_xfconf (&globals.ind_cfg);
- xfcekbd_indicator_config_activate (&globals.ind_cfg);
-
- xfcekbd_indicator_load_group_names ((const gchar **) xklrec->layouts,
- (const gchar **)
- xklrec->variants);
- g_object_unref (G_OBJECT (xklrec));
-
+ g_signal_connect (globals.engine, "X-state-changed",
+ G_CALLBACK (xfcekbd_indicator_state_callback), NULL);
xfcekbd_indicator_start_listen ();
-
- gs_debug( "*** Inited globals *** \n");
+ gs_debug( "*** Inited globals ***");
}
GtkWidget *
diff --git a/src/xfcekbd-keyboard-config.c b/src/xfcekbd-keyboard-config.c
deleted file mode 100644
index 3275096..0000000
--- a/src/xfcekbd-keyboard-config.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * Copyright (C) 2006 Sergey V. Udaltsov <svu at gnome.org>
- * Copyright (C) 2018 Sean Davis <bluesabre at xfce.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; see the file COPYING.LGPL. If not,
- * write to the Free Software Foundation, Inc., 51 Franklin St,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <X11/keysym.h>
-
-#include <libxfce4util/libxfce4util.h>
-
-#include "gs-debug.h"
-#include "xfcekbd-config-private.h"
-#include "xfcekbd-keyboard-config.h"
-
-/*
- * XfcekbdKeyboardConfig
- */
-
-/*
- * extern common functions
- */
-static const gchar *
-xfcekbd_keyboard_config_merge_items (const gchar *parent,
- const gchar *child) {
- static gchar buffer[XKL_MAX_CI_NAME_LENGTH * 2 - 1];
- *buffer = '\0';
- if (parent != NULL) {
- if (strlen (parent) >= XKL_MAX_CI_NAME_LENGTH)
- return NULL;
- strcat (buffer, parent);
- }
- if (child != NULL && *child != 0) {
- if (strlen (child) >= XKL_MAX_CI_NAME_LENGTH)
- return NULL;
- strcat (buffer, "\t");
- strcat (buffer, child);
- }
- return buffer;
-}
-
-gboolean
-xfcekbd_keyboard_config_split_items (const gchar *merged,
- gchar **parent,
- gchar **child) {
- static gchar pbuffer[XKL_MAX_CI_NAME_LENGTH];
- static gchar cbuffer[XKL_MAX_CI_NAME_LENGTH];
- int plen, clen;
- const gchar *pos;
- *parent = *child = NULL;
-
- if (merged == NULL)
- return FALSE;
-
- pos = strchr (merged, '\t');
- if (pos == NULL) {
- plen = strlen (merged);
- clen = 0;
- } else {
- plen = pos - merged;
- clen = strlen (pos + 1);
- if (clen >= XKL_MAX_CI_NAME_LENGTH)
- return FALSE;
- strcpy (*child = cbuffer, pos + 1);
- }
- if (plen >= XKL_MAX_CI_NAME_LENGTH)
- return FALSE;
- memcpy (*parent = pbuffer, merged, plen);
- pbuffer[plen] = '\0';
- return TRUE;
-}
-
-/*
- * static XfcekbdKeyboardConfig functions
- */
-static void
-xfcekbd_keyboard_config_copy_from_xkl_config (XfcekbdKeyboardConfig *kbd_config,
- XklConfigRec *pdata) {
- char **p;
- int i;
-
- xfcekbd_keyboard_config_model_set (kbd_config, pdata->model);
- gs_debug("Loaded Kbd model: [%s]\n", pdata->model);
-
- /* Layouts */
- g_strfreev (kbd_config->layouts_variants);
- kbd_config->layouts_variants = NULL;
- if (pdata->layouts != NULL) {
- char **p1;
- p = pdata->layouts;
- p1 = pdata->variants;
- kbd_config->layouts_variants = g_new0 (gchar *, g_strv_length (pdata->layouts) + 1);
- i = 0;
- while (*p != NULL) {
- const gchar *full_layout = xfcekbd_keyboard_config_merge_items (*p, *p1);
- gs_debug("Loaded Kbd layout (with variant): [%s]\n", full_layout);
- kbd_config->layouts_variants[i++] = g_strdup (full_layout);
- p++;
- p1++;
- }
- }
-
- /* Options */
- g_strfreev (kbd_config->options);
- kbd_config->options = NULL;
-
- if (pdata->options != NULL) {
- p = pdata->options;
- kbd_config->options = g_new0 (gchar *, g_strv_length (pdata->options) + 1);
- i = 0;
- while (*p != NULL) {
- char *option = *p;
- char *delim = (option != NULL) ? strchr (option, ':') : NULL;
- int len;
- if ((delim != NULL) && ((len = (delim - option)) < XKL_MAX_CI_NAME_LENGTH)) {
- char group[XKL_MAX_CI_NAME_LENGTH];
- strncpy (group, option, len);
- group[len] = 0;
- gs_debug("Loaded Kbd option: [%s][%s]\n", group, option);
- xfcekbd_keyboard_config_options_set (kbd_config, i++, group, option);
- }
- p++;
- }
- }
-}
-
-/*
- * extern XfcekbdKeyboardConfig config functions
- */
-void
-xfcekbd_keyboard_config_init (XfcekbdKeyboardConfig *kbd_config,
- XklEngine *engine) {
- memset (kbd_config, 0, sizeof (*kbd_config));
- kbd_config->engine = engine;
-}
-
-void
-xfcekbd_keyboard_config_term (XfcekbdKeyboardConfig *kbd_config) {
- xfcekbd_keyboard_config_model_set (kbd_config, NULL);
-
- g_strfreev (kbd_config->layouts_variants);
- kbd_config->layouts_variants = NULL;
- g_strfreev (kbd_config->options);
- kbd_config->options = NULL;
-}
-
-void
-xfcekbd_keyboard_config_load_from_x_current (XfcekbdKeyboardConfig *kbd_config,
- XklConfigRec *data) {
- gboolean own_data = data == NULL;
- gs_debug("Copying config from X(current)\n");
- if (own_data)
- data = xkl_config_rec_new ();
- if (xkl_config_rec_get_from_server (data, kbd_config->engine))
- xfcekbd_keyboard_config_copy_from_xkl_config (kbd_config,
- data);
- else
- gs_debug("Could not load keyboard config from server: [%s]\n", xkl_get_last_error ());
- if (own_data)
- g_object_unref (G_OBJECT (data));
-}
-
-void
-xfcekbd_keyboard_config_model_set (XfcekbdKeyboardConfig *kbd_config,
- const gchar *model_name) {
- if (kbd_config->model != NULL)
- g_free (kbd_config->model);
- kbd_config->model =
- (model_name == NULL
- || model_name[0] == '\0') ? NULL : g_strdup (model_name);
-}
-
-void
-xfcekbd_keyboard_config_options_set (XfcekbdKeyboardConfig *kbd_config,
- gint idx,
- const gchar *group_name,
- const gchar *option_name) {
- const gchar *merged;
- if (group_name == NULL || option_name == NULL)
- return;
- merged =
- xfcekbd_keyboard_config_merge_items (group_name, option_name);
- if (merged == NULL)
- return;
- kbd_config->options[idx] = g_strdup (merged);
-}
-
-const gchar *
-xfcekbd_keyboard_config_format_full_layout (const gchar *layout_descr,
- const gchar *variant_descr) {
- static gchar full_descr[XKL_MAX_CI_DESC_LENGTH * 2];
- if (variant_descr == NULL || variant_descr[0] == 0)
- g_snprintf (full_descr, sizeof (full_descr), "%s",
- layout_descr);
- else
- g_snprintf (full_descr, sizeof (full_descr), "%s %s",
- layout_descr, variant_descr);
- return full_descr;
-}
diff --git a/src/xfcekbd-keyboard-config.h b/src/xfcekbd-keyboard-config.h
deleted file mode 100644
index ca58666..0000000
--- a/src/xfcekbd-keyboard-config.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2006 Sergey V. Udaltsov <svu at gnome.org>
- * Copyright (C) 2018 Sean Davis <bluesabre at xfce.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; see the file COPYING.LGPL. If not,
- * write to the Free Software Foundation, Inc., 51 Franklin St,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef SRC_XFCEKBD_KEYBOARD_CONFIG_H_
-#define SRC_XFCEKBD_KEYBOARD_CONFIG_H_
-
-#include <X11/Xlib.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <libxklavier/xklavier.h>
-
-extern const gchar XFCEKBD_KEYBOARD_CONFIG_KEY_MODEL[];
-extern const gchar XFCEKBD_KEYBOARD_CONFIG_KEY_LAYOUTS[];
-extern const gchar XFCEKBD_KEYBOARD_CONFIG_KEY_OPTIONS[];
-
-/*
- * Keyboard Configuration
- */
-typedef struct _XfcekbdKeyboardConfig XfcekbdKeyboardConfig;
-struct _XfcekbdKeyboardConfig {
- gchar *model;
- gchar **layouts_variants;
- gchar **options;
-
- /* private, transient */
- int config_listener_id;
- XklEngine *engine;
-};
-
-/*
- * XfcekbdKeyboardConfig functions
- */
-extern void xfcekbd_keyboard_config_init (XfcekbdKeyboardConfig *kbd_config,
- XklEngine *engine);
-extern void xfcekbd_keyboard_config_term (XfcekbdKeyboardConfig *kbd_config);
-
-extern void xfcekbd_keyboard_config_load_from_x_current (XfcekbdKeyboardConfig *kbd_config,
- XklConfigRec *data);
-
-extern gboolean xfcekbd_keyboard_config_split_items (const gchar *merged,
- gchar **parent,
- gchar **child);
-
-extern const gchar * xfcekbd_keyboard_config_format_full_layout (const gchar *layout_descr,
- const gchar *variant_descr);
-
-#endif /* SRC_XFCEKBD_KEYBOARD_CONFIG_H_ */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list