[Xfce4-commits] <xfce4-xkb-plugin:master> Cleanup.

Igor Slepchin noreply at xfce.org
Wed Aug 22 23:24:08 CEST 2012


Updating branch refs/heads/master
         to 16f933d1e3d83093dc67f35dec9011b33d501f8f (commit)
       from ffbcc2b8473cd1b2896b11c4b1c6f2e226ec1cd8 (commit)

commit 16f933d1e3d83093dc67f35dec9011b33d501f8f
Author: Igor Slepchin <igor.slepchin at gmail.com>
Date:   Sat Jul 21 04:02:29 2012 -0400

    Cleanup.
    
    Get rid of t_xkb_settings struct; keep its only member (group_policy)
    in t_xkb struct directly instead.
    
    Declare xkb_plugin_popup_menu() as static.
    
    Get rid of a few superfluous UI refreshes.

 panel-plugin/xfce4-xkb-plugin.c    |   22 ++++--------
 panel-plugin/xfce4-xkb-plugin.h    |    2 +-
 panel-plugin/xkb-callbacks.c       |    5 ++-
 panel-plugin/xkb-callbacks.h       |    3 --
 panel-plugin/xkb-config.c          |   64 ++++++++++++++++++------------------
 panel-plugin/xkb-config.h          |    9 +----
 panel-plugin/xkb-settings-dialog.c |   16 ++-------
 7 files changed, 50 insertions(+), 71 deletions(-)

diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c
index 1cf96ae..d72713b 100644
--- a/panel-plugin/xfce4-xkb-plugin.c
+++ b/panel-plugin/xfce4-xkb-plugin.c
@@ -75,7 +75,7 @@ static gboolean     xkb_load_config                     (t_xkb *xkb,
 
 static void         xkb_load_default                    (t_xkb *xkb);
 
-static void         xkb_initialize_menu                 (t_xkb *xkb);
+static void         xkb_initialize_popup_menu           (t_xkb *xkb);
 
 
 /* ================================================================== *
@@ -145,7 +145,7 @@ xkb_state_changed (gint current_group, gboolean config_changed,
 
     if (config_changed)
     {
-        xkb_initialize_menu (xkb);
+        xkb_initialize_popup_menu (xkb);
     }
 }
 
@@ -165,7 +165,6 @@ xkb_new (XfcePanelPlugin *plugin)
     WnckScreen *wnck_screen;
 
     xkb = panel_slice_new0 (t_xkb);
-    xkb->settings = g_new0 (t_xkb_settings, 1);
     xkb->plugin = plugin;
 
     filename = xfce_panel_plugin_save_location (plugin, TRUE);
@@ -202,11 +201,11 @@ xkb_new (XfcePanelPlugin *plugin)
             G_CALLBACK (xkb_plugin_layout_image_exposed), xkb);
     gtk_widget_show (GTK_WIDGET (xkb->layout_image));
 
-    if (xkb_config_initialize (xkb->settings, xkb_state_changed, xkb))
+    if (xkb_config_initialize (xkb->group_policy, xkb_state_changed, xkb))
     {
         xkb_refresh_gui (xkb);
 
-        xkb_initialize_menu (xkb);
+        xkb_initialize_popup_menu (xkb);
     }
 
     wnck_screen = wnck_screen_get_default ();
@@ -225,8 +224,6 @@ xkb_free (t_xkb *xkb)
 {
     xkb_config_finalize ();
 
-    g_free (xkb->settings);
-
     gtk_widget_destroy (xkb->layout_image);
     gtk_widget_destroy (xkb->btn);
     gtk_widget_destroy (xkb->popup);
@@ -240,8 +237,6 @@ xfce_xkb_save_config (XfcePanelPlugin *plugin, t_xkb *xkb)
     gchar* filename;
     XfceRc* rcfile;
 
-    xkb_config_update_settings (xkb->settings);
-    xkb_initialize_menu (xkb);
 
     filename = xfce_panel_plugin_save_location (plugin, TRUE);
     if (!filename)
@@ -259,7 +254,7 @@ xfce_xkb_save_config (XfcePanelPlugin *plugin, t_xkb *xkb)
 
     xfce_rc_write_int_entry (rcfile, "display_type", xkb->display_type);
     xfce_rc_write_int_entry (rcfile, "display_textsize", xkb->display_textsize);
-    xfce_rc_write_int_entry (rcfile, "group_policy", xkb->settings->group_policy);
+    xfce_rc_write_int_entry (rcfile, "group_policy", xkb->group_policy);
 
     xfce_rc_close (rcfile);
     g_free (filename);
@@ -275,7 +270,7 @@ xkb_load_config (t_xkb *xkb, const gchar *filename)
 
         xkb->display_type = xfce_rc_read_int_entry (rcfile, "display_type", DISPLAY_TYPE_IMAGE);
         xkb->display_textsize = xfce_rc_read_int_entry (rcfile, "display_textsize", DISPLAY_TEXTSIZE_SMALL);
-        xkb->settings->group_policy = xfce_rc_read_int_entry (rcfile, "group_policy", GROUP_POLICY_PER_APPLICATION);
+        xkb->group_policy = xfce_rc_read_int_entry (rcfile, "group_policy", GROUP_POLICY_PER_APPLICATION);
 
         xfce_rc_close (rcfile);
 
@@ -290,7 +285,7 @@ xkb_load_default (t_xkb *xkb)
 {
     xkb->display_type = DISPLAY_TYPE_IMAGE;
     xkb->display_textsize = DISPLAY_TEXTSIZE_SMALL;
-    xkb->settings->group_policy = GROUP_POLICY_PER_APPLICATION;
+    xkb->group_policy = GROUP_POLICY_PER_APPLICATION;
 }
 
 static gboolean
@@ -319,7 +314,7 @@ xkb_calculate_sizes (t_xkb *xkb, GtkOrientation orientation, gint panel_size)
 }
 
 static void
-xkb_initialize_menu (t_xkb *xkb)
+xkb_initialize_popup_menu (t_xkb *xkb)
 {
     gint i, group_count;
     RsvgHandle *handle;
@@ -377,7 +372,6 @@ xkb_initialize_menu (t_xkb *xkb)
 
         gtk_menu_shell_append (GTK_MENU_SHELL (xkb->popup), menu_item);
     }
-
 }
 
 void
diff --git a/panel-plugin/xfce4-xkb-plugin.h b/panel-plugin/xfce4-xkb-plugin.h
index 4cd9a4a..68f6c8a 100644
--- a/panel-plugin/xfce4-xkb-plugin.h
+++ b/panel-plugin/xfce4-xkb-plugin.h
@@ -61,7 +61,7 @@ typedef struct
 
     t_display_type display_type;  /* display layout as image ot text */
     t_display_textsize display_textsize; /* text size for text layout */
-    t_xkb_settings *settings;     /* per-app setting and default group */
+    t_group_policy group_policy;     /* per-app/window/global policy */
 
     gint button_state;            /* gtk state of the button */
 
diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c
index d12e086..e300989 100644
--- a/panel-plugin/xkb-callbacks.c
+++ b/panel-plugin/xkb-callbacks.c
@@ -27,6 +27,9 @@
 #include "xkb-cairo.h"
 #include "xkb-util.h"
 
+static void xkb_plugin_popup_menu (GtkButton *btn,
+                                   gpointer data);
+
 void
 xkb_plugin_active_window_changed (WnckScreen *screen,
                                   WnckWindow *previously_active_window,
@@ -177,7 +180,7 @@ xkb_plugin_button_scrolled (GtkWidget *btn,
     return FALSE;
 }
 
-void
+static void
 xkb_plugin_popup_menu (GtkButton *btn,
                        gpointer data)
 {
diff --git a/panel-plugin/xkb-callbacks.h b/panel-plugin/xkb-callbacks.h
index 3cb5edf..a06c22f 100644
--- a/panel-plugin/xkb-callbacks.h
+++ b/panel-plugin/xkb-callbacks.h
@@ -60,9 +60,6 @@ void            xkb_plugin_window_closed        (WnckScreen *screen,
                                  WnckWindow *window,
                                  t_xkb *xkb);
 
-void            xkb_plugin_popup_menu           (GtkButton *btn,
-                                 gpointer data);
-
 void            xkb_plugin_button_clicked       (GtkButton *btn,
                                  gpointer data);
 
diff --git a/panel-plugin/xkb-config.c b/panel-plugin/xkb-config.c
index 8c43b7d..b0fdb84 100644
--- a/panel-plugin/xkb-config.c
+++ b/panel-plugin/xkb-config.c
@@ -45,7 +45,7 @@ typedef struct
 
     gchar               **group_names;
     gchar               **variants;
-    t_xkb_settings       *settings;
+    t_group_policy        group_policy;
     GHashTable           *variant_index_by_group;
 
 
@@ -63,7 +63,7 @@ typedef struct
 
 static t_xkb_config *config;
 
-static void         xkb_config_state_changed            (XklEngine *engine,
+static void         xkb_config_xkl_state_changed        (XklEngine *engine,
                                                          XklEngineStateChange change,
                                                          gint group,
                                                          gboolean restore,
@@ -77,20 +77,19 @@ static GdkFilterReturn
                                                          GdkEvent * event);
 
 static void         xkb_config_free                     ();
+static void         xkb_config_update_from_xkl          ();
 static void         xkb_config_initialize_xkb_options   (const XklConfigRec *config_rec);
 
 /* ---------------------- implementation ------------------------- */
 
 gboolean
-xkb_config_initialize (t_xkb_settings *settings,
+xkb_config_initialize (t_group_policy group_policy,
                XkbCallback callback,
                gpointer callback_data)
 {
-    g_assert (settings != NULL);
-
     config = g_new0 (t_xkb_config, 1);
 
-    config->settings = settings;
+    config->group_policy = group_policy;
 
     config->callback = callback;
     config->callback_data = callback_data;
@@ -102,7 +101,7 @@ xkb_config_initialize (t_xkb_settings *settings,
         return FALSE;
     }
 
-    xkb_config_update_settings (settings);
+    xkb_config_update_from_xkl ();
 
     xkl_engine_set_group_per_toplevel_window (config->engine, FALSE);
 
@@ -110,7 +109,7 @@ xkb_config_initialize (t_xkb_settings *settings,
 
     g_signal_connect (config->engine,
             "X-state-changed",
-            G_CALLBACK (xkb_config_state_changed),
+            G_CALLBACK (xkb_config_xkl_state_changed),
             NULL);
     g_signal_connect (config->engine,
             "X-config-changed",
@@ -258,25 +257,26 @@ xkb_config_prev_group (void)
     return TRUE;
 }
 
-gboolean
-xkb_config_update_settings (t_xkb_settings *settings)
+void
+xkb_config_set_group_policy (t_group_policy group_policy)
+{
+    config->group_policy = group_policy;
+}
+
+static void
+xkb_config_update_from_xkl (void)
 {
     XklConfigRec *config_rec;
 
-    g_assert (config != NULL);
-    g_assert (settings != NULL);
 
-    config->settings = settings;
+    g_assert (config != NULL);
 
     config_rec = xkl_config_rec_new ();
     xkl_config_rec_get_from_server (config_rec, config->engine);
 
     xkb_config_initialize_xkb_options (config_rec);
 
-    xkl_config_rec_reset (config_rec);
     g_object_unref (config_rec);
-
-    return TRUE;
 }
 
 void
@@ -292,7 +292,7 @@ xkb_config_window_changed (guint new_window_id, guint application_id)
     id = 0;
     hashtable = NULL;
 
-    switch (config->settings->group_policy)
+    switch (config->group_policy)
     {
         case GROUP_POLICY_GLOBAL:
             return;
@@ -316,12 +316,12 @@ xkb_config_window_changed (guint new_window_id, guint application_id)
     {
         group = GPOINTER_TO_INT (value);
     }
-
-    g_hash_table_insert (
-            hashtable,
-            GINT_TO_POINTER (id),
-            GINT_TO_POINTER (group)
-    );
+    else
+    {
+        g_hash_table_insert (hashtable,
+                             GINT_TO_POINTER (id),
+                             GINT_TO_POINTER (group));
+    }
 
     xkb_config_set_group (group);
 }
@@ -331,7 +331,7 @@ xkb_config_application_closed (guint application_id)
 {
     g_assert (config != NULL);
 
-    switch (config->settings->group_policy)
+    switch (config->group_policy)
     {
         case GROUP_POLICY_GLOBAL:
         case GROUP_POLICY_PER_WINDOW:
@@ -352,7 +352,7 @@ xkb_config_window_closed (guint window_id)
 {
     g_assert (config != NULL);
 
-    switch (config->settings->group_policy)
+    switch (config->group_policy)
     {
         case GROUP_POLICY_GLOBAL:
         case GROUP_POLICY_PER_APPLICATION:
@@ -406,15 +406,15 @@ xkb_config_get_variant (gint group)
 }
 
 void
-xkb_config_state_changed (XklEngine *engine,
-                          XklEngineStateChange change,
-                          gint group,
-                          gboolean restore,
-                          gpointer user_data)
+xkb_config_xkl_state_changed (XklEngine *engine,
+                              XklEngineStateChange change,
+                              gint group,
+                              gboolean restore,
+                              gpointer user_data)
 {
     if (change == GROUP_CHANGED)
     {
-        switch (config->settings->group_policy)
+        switch (config->group_policy)
         {
             case GROUP_POLICY_GLOBAL:
                 break;
@@ -443,7 +443,7 @@ xkb_config_state_changed (XklEngine *engine,
 void
 xkb_config_xkl_config_changed (XklEngine *engine, gpointer user_data)
 {
-    xkb_config_update_settings (config->settings);
+    xkb_config_update_from_xkl ();
 
     if (config->callback != NULL)
         config->callback (xkb_config_get_current_group (), TRUE, config->callback_data);
diff --git a/panel-plugin/xkb-config.h b/panel-plugin/xkb-config.h
index 0b14a10..dbdb974 100644
--- a/panel-plugin/xkb-config.h
+++ b/panel-plugin/xkb-config.h
@@ -41,20 +41,15 @@ typedef enum
     GROUP_POLICY_PER_APPLICATION    = 2
 } t_group_policy;
 
-typedef struct
-{
-    t_group_policy      group_policy;
-} t_xkb_settings;
-
 typedef void        (*XkbCallback)                  (gint current_group,
                                                      gboolean groups_changed,
                                                      gpointer user_data);
 
-gboolean          xkb_config_initialize                   (t_xkb_settings *settings,
+gboolean          xkb_config_initialize                   (t_group_policy group_policy,
                                                            XkbCallback callback,
                                                            gpointer data);
 void              xkb_config_finalize                     (void);
-gboolean          xkb_config_update_settings              (t_xkb_settings *settings);
+void              xkb_config_set_group_policy             (t_group_policy group_policy);
 gint              xkb_config_get_group_count              (void);
 const gchar*      xkb_config_get_group_name               (gint group);
 const gchar*      xkb_config_get_variant                  (gint group);
diff --git a/panel-plugin/xkb-settings-dialog.c b/panel-plugin/xkb-settings-dialog.c
index 42b9d0c..afd0222 100644
--- a/panel-plugin/xkb-settings-dialog.c
+++ b/panel-plugin/xkb-settings-dialog.c
@@ -65,7 +65,6 @@ enum enumeration
     NUM
 };
 
-static void         xkb_settings_update_from_ui        (t_xkb *xkb);
 
 /**************************************************************/
 
@@ -74,8 +73,6 @@ on_settings_close (GtkDialog *dialog, gint response, t_xkb *xkb)
 {
     xfce_panel_plugin_unblock_menu (xkb->plugin);
 
-    xkb_settings_update_from_ui (xkb);
-
     xfce_xkb_save_config (xkb->plugin, xkb);
 
     gtk_widget_destroy (GTK_WIDGET (dialog));
@@ -98,7 +95,8 @@ on_display_textsize_changed (GtkComboBox *cb, t_xkb *xkb)
 static void
 on_group_policy_changed (GtkComboBox *cb, t_xkb *xkb)
 {
-    xkb->settings->group_policy = gtk_combo_box_get_active (cb);
+    xkb->group_policy = gtk_combo_box_get_active (cb);
+    xkb_config_set_group_policy (xkb->group_policy);
 }
 
 void
@@ -162,7 +160,7 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
 
     gtk_combo_box_set_active (GTK_COMBO_BOX (display_type_optmenu), xkb->display_type);
     gtk_combo_box_set_active (GTK_COMBO_BOX (display_textsize_optmenu), xkb->display_textsize);
-    gtk_combo_box_set_active (GTK_COMBO_BOX (group_policy_combo), xkb->settings->group_policy);
+    gtk_combo_box_set_active (GTK_COMBO_BOX (group_policy_combo), xkb->group_policy);
 
     g_signal_connect (display_type_optmenu, "changed", G_CALLBACK (on_display_type_changed), xkb);
     g_signal_connect (group_policy_combo, "changed", G_CALLBACK (on_group_policy_changed), xkb);
@@ -201,11 +199,3 @@ xfce_xkb_about (XfcePanelPlugin *plugin)
     gtk_dialog_run (GTK_DIALOG (about));
     gtk_widget_destroy (about);
 }
-
-static void
-xkb_settings_update_from_ui (t_xkb *xkb)
-{
-    xkb_config_update_settings (xkb->settings);
-    xkb_refresh_gui (xkb);
-}
-


More information about the Xfce4-commits mailing list