[Xfce4-commits] [apps/xfce4-screensaver] 01/01: Drop show-flags setting from our embedded xkb to simplify the codebase and do less drawing
noreply at xfce.org
noreply at xfce.org
Sun Nov 11 22:19:02 CET 2018
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 fd98c90f11dd784dcd66abf9284ac0a647b6d3db
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Sun Nov 11 16:18:55 2018 -0500
Drop show-flags setting from our embedded xkb to simplify the codebase and do less drawing
---
src/xfcekbd-config-private.h | 6 --
src/xfcekbd-indicator-config.c | 115 -------------------------
src/xfcekbd-indicator-config.h | 6 --
src/xfcekbd-indicator.c | 187 +++++++----------------------------------
4 files changed, 32 insertions(+), 282 deletions(-)
diff --git a/src/xfcekbd-config-private.h b/src/xfcekbd-config-private.h
index fc1cd02..1ced19c 100644
--- a/src/xfcekbd-config-private.h
+++ b/src/xfcekbd-config-private.h
@@ -52,12 +52,6 @@
#define DEFAULT_KEY_KBD_LOAD_EXTRA_ITEMS FALSE
/**
- * KBD/Indicator: Show flags instead of language code
- */
-#define KEY_KBD_INDICATOR_SHOW_FLAGS "/kbd/indicator/show-flags"
-#define DEFAULT_KEY_KBD_INDICATOR_SHOW_FLAGS FALSE
-
-/**
* KBD/Indicator: Secondary groups
*/
#define KEY_KBD_INDICATOR_SECONDARIES "/kbd/indicator/secondary"
diff --git a/src/xfcekbd-indicator-config.c b/src/xfcekbd-indicator-config.c
index 331aa8f..0c37f6e 100644
--- a/src/xfcekbd-indicator-config.c
+++ b/src/xfcekbd-indicator-config.c
@@ -40,126 +40,16 @@
* static applet config functions
*/
-static gchar *
-xfcekbd_indicator_config_get_images_file (XfcekbdIndicatorConfig *ind_config,
- XfcekbdKeyboardConfig *kbd_config,
- int group) {
- char *image_file = NULL;
- GtkIconInfo *icon_info = NULL;
-
- if (!ind_config->show_flags)
- return NULL;
-
- if ((kbd_config->layouts_variants != NULL) &&
- (g_strv_length (kbd_config->layouts_variants) > group)) {
- char *full_layout_name =
- kbd_config->layouts_variants[group];
-
- if (full_layout_name != NULL) {
- char *l, *v;
- xfcekbd_keyboard_config_split_items (full_layout_name,
- &l, &v);
- if (l != NULL) {
- /* probably there is something in theme? */
- icon_info = gtk_icon_theme_lookup_icon
- (ind_config->icon_theme, l, 48, 0);
-
- /* Unbelievable but happens */
- if (icon_info != NULL &&
- gtk_icon_info_get_filename (icon_info) == NULL) {
- g_object_unref (icon_info);
- icon_info = NULL;
- }
- }
- }
- }
- /* fallback to the default value */
- if (icon_info == NULL) {
- icon_info = gtk_icon_theme_lookup_icon
- (ind_config->icon_theme, "stock_dialog-error", 48, 0);
- }
- if (icon_info != NULL) {
- image_file =
- g_strdup (gtk_icon_info_get_filename (icon_info));
- g_object_unref (icon_info);
- }
-
- return image_file;
-}
-
-void
-xfcekbd_indicator_config_load_image_filenames (XfcekbdIndicatorConfig *
- ind_config,
- XfcekbdKeyboardConfig *
- kbd_config) {
- int i;
- ind_config->image_filenames = NULL;
-
- if (!ind_config->show_flags)
- return;
-
- for (i = xkl_engine_get_max_num_groups (ind_config->engine);
- --i >= 0;) {
- gchar *image_file =
- xfcekbd_indicator_config_get_images_file (ind_config,
- kbd_config,
- i);
- ind_config->image_filenames =
- g_slist_prepend (ind_config->image_filenames,
- image_file);
- }
-}
-
-void
-xfcekbd_indicator_config_free_image_filenames (XfcekbdIndicatorConfig *ind_config) {
- while (ind_config->image_filenames) {
- if (ind_config->image_filenames->data)
- g_free (ind_config->image_filenames->data);
- ind_config->image_filenames =
- g_slist_delete_link (ind_config->image_filenames,
- ind_config->image_filenames);
- }
-}
-
void
xfcekbd_indicator_config_init (XfcekbdIndicatorConfig *ind_config,
XklEngine *engine) {
- gchar *sp;
-
memset (ind_config, 0, sizeof (*ind_config));
ind_config->channel = xfconf_channel_get (SETTINGS_XFCONF_CHANNEL);
ind_config->engine = engine;
-
- ind_config->icon_theme = gtk_icon_theme_get_default ();
-
- gtk_icon_theme_append_search_path (ind_config->icon_theme, sp =
- g_build_filename (g_get_home_dir
- (),
- ".icons/flags",
- NULL));
- g_free (sp);
-
- gtk_icon_theme_append_search_path (ind_config->icon_theme,
- sp =
- g_build_filename (DATADIR,
- "pixmaps/flags",
- NULL));
- g_free (sp);
-
- gtk_icon_theme_append_search_path (ind_config->icon_theme,
- sp =
- g_build_filename (DATADIR,
- "icons/flags",
- NULL));
- g_free (sp);
}
void
xfcekbd_indicator_config_term (XfcekbdIndicatorConfig *ind_config) {
- ind_config->icon_theme = NULL;
-
- xfcekbd_indicator_config_free_image_filenames (ind_config);
-
g_object_unref (ind_config->channel);
ind_config->channel = NULL;
}
@@ -170,11 +60,6 @@ xfcekbd_indicator_config_load_from_xfconf (XfcekbdIndicatorConfig * ind_config)
xfconf_channel_get_int (ind_config->channel,
KEY_KBD_INDICATOR_SECONDARIES,
DEFAULT_KEY_KBD_INDICATOR_SECONDARIES);
-
- ind_config->show_flags =
- xfconf_channel_get_bool (ind_config->channel,
- KEY_KBD_INDICATOR_SHOW_FLAGS,
- DEFAULT_KEY_KBD_INDICATOR_SHOW_FLAGS);
}
void
diff --git a/src/xfcekbd-indicator-config.h b/src/xfcekbd-indicator-config.h
index f126ca6..3c960c0 100644
--- a/src/xfcekbd-indicator-config.h
+++ b/src/xfcekbd-indicator-config.h
@@ -32,11 +32,9 @@
typedef struct _XfcekbdIndicatorConfig XfcekbdIndicatorConfig;
struct _XfcekbdIndicatorConfig {
int secondary_groups_mask;
- gboolean show_flags;
/* private, transient */
XfconfChannel *channel;
- GSList *image_filenames;
GtkIconTheme *icon_theme;
int config_listener_id;
XklEngine *engine;
@@ -53,10 +51,6 @@ void xfcekbd_indicator_config_term (XfcekbdIndicatorConfig
void xfcekbd_indicator_config_load_from_xfconf (XfcekbdIndicatorConfig *applet_config);
-void xfcekbd_indicator_config_load_image_filenames (XfcekbdIndicatorConfig *applet_config,
- XfcekbdKeyboardConfig *kbd_config);
-void xfcekbd_indicator_config_free_image_filenames (XfcekbdIndicatorConfig *applet_config);
-
/* Should be updated on Indicator/Xfconf configuration change */
void xfcekbd_indicator_config_activate (XfcekbdIndicatorConfig *applet_config);
diff --git a/src/xfcekbd-indicator.c b/src/xfcekbd-indicator.c
index 992e66e..b999230 100644
--- a/src/xfcekbd-indicator.c
+++ b/src/xfcekbd-indicator.c
@@ -79,85 +79,6 @@ static void xfcekbd_indicator_fill (XfcekbdIndi
static void xfcekbd_indicator_set_tooltips (XfcekbdIndicator *gki,
const char *str);
-static void
-xfcekbd_indicator_load_images () {
- int i;
- GSList *image_filename;
-
- globals.images = NULL;
- xfcekbd_indicator_config_load_image_filenames (&globals.ind_cfg,
- &globals.kbd_cfg);
-
- if (!globals.ind_cfg.show_flags)
- return;
-
- image_filename = globals.ind_cfg.image_filenames;
-
- for (i = xkl_engine_get_max_num_groups (globals.engine);
- --i >= 0; image_filename = image_filename->next) {
- GdkPixbuf *image = NULL;
- char *image_file = (char *) image_filename->data;
-
- if (image_file != NULL) {
- GError *gerror = NULL;
- image =
- gdk_pixbuf_new_from_file (image_file, &gerror);
- if (image == NULL) {
- GtkWidget *dialog =
- gtk_message_dialog_new (NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("There was an error loading an image: %s"),
- gerror->
- message);
- g_signal_connect (G_OBJECT (dialog),
- "response",
- G_CALLBACK
- (gtk_widget_destroy),
- NULL);
-
- gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-
- gtk_widget_show (dialog);
- g_error_free (gerror);
- }
- xkl_debug (150,
- "Image %d[%s] loaded -> %p[%dx%d]\n",
- i, image_file, image,
- gdk_pixbuf_get_width (image),
- gdk_pixbuf_get_height (image));
- }
- /* We append the image anyway - even if it is NULL! */
- globals.images = g_slist_append (globals.images, image);
- }
-}
-
-static void
-xfcekbd_indicator_free_images () {
- GdkPixbuf *pi;
- GSList *img_node;
-
- xfcekbd_indicator_config_free_image_filenames (&globals.ind_cfg);
-
- while ((img_node = globals.images) != NULL) {
- pi = GDK_PIXBUF (img_node->data);
- /* It can be NULL - some images may be missing */
- if (pi != NULL) {
- g_object_unref (pi);
- }
- globals.images =
- g_slist_remove_link (globals.images, img_node);
- g_slist_free_1 (img_node);
- }
-}
-
-static void
-xfcekbd_indicator_update_images (void) {
- xfcekbd_indicator_free_images ();
- xfcekbd_indicator_load_images ();
-}
-
void
xfcekbd_indicator_set_tooltips (XfcekbdIndicator *gki,
const char *str) {
@@ -237,32 +158,6 @@ xfcekbd_indicator_button_pressed (GtkWidget *widget,
return FALSE;
}
-static void
-draw_flag (GtkWidget *flag,
- cairo_t *cr,
- GdkPixbuf *image) {
- /* Image width and height */
- int iw = gdk_pixbuf_get_width (image);
- int ih = gdk_pixbuf_get_height (image);
- GtkAllocation allocation;
- double xwiratio, ywiratio, wiratio;
-
- gtk_widget_get_allocation (flag, &allocation);
-
- /* widget-to-image scales, X and Y */
- xwiratio = 1.0 * allocation.width / iw;
- ywiratio = 1.0 * allocation.height / ih;
- wiratio = xwiratio < ywiratio ? xwiratio : ywiratio;
-
- /* transform cairo context */
- cairo_translate (cr, allocation.width / 2.0, allocation.height / 2.0);
- cairo_scale (cr, wiratio, wiratio);
- cairo_translate (cr, - iw / 2.0, - ih / 2.0);
-
- gdk_cairo_set_source_pixbuf (cr, image, 0, 0);
- cairo_paint (cr);
-}
-
static gchar *
xfcekbd_indicator_extract_layout_name (int group,
XklEngine *engine,
@@ -344,60 +239,45 @@ xfcekbd_indicator_create_label_title (int group,
static GtkWidget *
xfcekbd_indicator_prepare_drawing (XfcekbdIndicator *gki,
int group) {
- gpointer pimage;
- GdkPixbuf *image;
GtkWidget *ebox;
- pimage = g_slist_nth_data (globals.images, group);
+ char *lbl_title = NULL;
+ char *layout_name = NULL;
+ GtkWidget *label;
+ static GHashTable *ln2cnt_map = NULL;
+
ebox = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
- if (globals.ind_cfg.show_flags) {
- GtkWidget *flag;
- if (pimage == NULL)
- return NULL;
- image = GDK_PIXBUF (pimage);
- flag = gtk_drawing_area_new ();
- gtk_widget_add_events (GTK_WIDGET (flag),
- GDK_BUTTON_PRESS_MASK);
- g_signal_connect (G_OBJECT (flag), "draw",
- G_CALLBACK (draw_flag), image);
- gtk_container_add (GTK_CONTAINER (ebox), flag);
- } else {
- char *lbl_title = NULL;
- char *layout_name = NULL;
- GtkWidget *label;
- static GHashTable *ln2cnt_map = NULL;
-
- layout_name =
- xfcekbd_indicator_extract_layout_name (group,
- globals.engine,
- &globals.kbd_cfg,
- globals.short_group_names,
- globals.full_group_names);
-
- lbl_title =
- xfcekbd_indicator_create_label_title (group,
- &ln2cnt_map,
- layout_name);
-
- label = gtk_label_new (lbl_title);
- gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- gtk_widget_set_margin_start (label, 2);
- gtk_widget_set_margin_end (label, 2);
- gtk_widget_set_margin_top (label, 2);
- gtk_widget_set_margin_bottom (label, 2);
- g_free (lbl_title);
- gtk_label_set_angle (GTK_LABEL (label), gki->priv->angle);
-
- if (group + 1 == xkl_engine_get_num_groups (globals.engine)) {
- g_hash_table_destroy (ln2cnt_map);
- ln2cnt_map = NULL;
- }
- gtk_container_add (GTK_CONTAINER (ebox), label);
+ layout_name =
+ xfcekbd_indicator_extract_layout_name (group,
+ globals.engine,
+ &globals.kbd_cfg,
+ globals.short_group_names,
+ globals.full_group_names);
+
+ lbl_title =
+ xfcekbd_indicator_create_label_title (group,
+ &ln2cnt_map,
+ layout_name);
+
+ label = gtk_label_new (lbl_title);
+ gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_widget_set_margin_start (label, 2);
+ gtk_widget_set_margin_end (label, 2);
+ gtk_widget_set_margin_top (label, 2);
+ gtk_widget_set_margin_bottom (label, 2);
+ g_free (lbl_title);
+ gtk_label_set_angle (GTK_LABEL (label), gki->priv->angle);
+
+ if (group + 1 == xkl_engine_get_num_groups (globals.engine)) {
+ g_hash_table_destroy (ln2cnt_map);
+ ln2cnt_map = NULL;
}
+ gtk_container_add (GTK_CONTAINER (ebox), label);
+
g_signal_connect (G_OBJECT (ebox),
"button_press_event",
G_CALLBACK (xfcekbd_indicator_button_pressed), gki);
@@ -464,7 +344,6 @@ xfcekbd_indicator_ind_cfg_changed (XfconfChannel *channel,
gpointer user_data) {
xkl_debug (100, "Applet configuration changed in Xfconf - reiniting...\n");
xfcekbd_indicator_config_load_from_xfconf (&globals.ind_cfg);
- xfcekbd_indicator_update_images ();
xfcekbd_indicator_config_activate (&globals.ind_cfg);
ForAllIndicators () {
@@ -506,7 +385,6 @@ xfcekbd_indicator_kbd_cfg_callback (XfcekbdIndicator *gki) {
xkl_debug (100, "XKB configuration changed on X Server - reiniting...\n");
xfcekbd_keyboard_config_load_from_x_current (&globals.kbd_cfg, xklrec);
- xfcekbd_indicator_update_images ();
g_strfreev (globals.full_group_names);
globals.full_group_names = NULL;
@@ -779,7 +657,6 @@ xfcekbd_indicator_global_init (void) {
xfcekbd_keyboard_config_load_from_x_current (&globals.kbd_cfg, xklrec);
xfcekbd_indicator_config_load_from_xfconf (&globals.ind_cfg);
- xfcekbd_indicator_update_images ();
xfcekbd_indicator_config_activate (&globals.ind_cfg);
xfcekbd_indicator_load_group_names ((const gchar **) xklrec->layouts,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list