Make icon size configurable
authormartyj19 <martyj19@comcast.net>
Fri, 10 Jul 2009 14:29:11 +0000 (14:29 +0000)
committermartyj19 <martyj19@comcast.net>
Fri, 10 Jul 2009 14:29:11 +0000 (14:29 +0000)
Enable xkb plugin to build by default and clean up somewhat

21 files changed:
configure.ac
data/ui/panel-pref.glade
src/configurator.c
src/icon-grid.c
src/icon-grid.h
src/misc.c
src/misc.h
src/panel.c
src/panel.h
src/plugins/dirmenu.c
src/plugins/kbled/kbled.c
src/plugins/launchbar.c
src/plugins/menu.c
src/plugins/pager.c
src/plugins/tray.c
src/plugins/volume/volume.c
src/plugins/volumealsa/volumealsa.c
src/plugins/wincmd.c
src/plugins/xkb/xkb-plugin.c
src/plugins/xkb/xkb.c
src/plugins/xkb/xkb.h

index 26c2cc1..0271961 100644 (file)
@@ -203,7 +203,7 @@ dnl    done
     plugin_deskno=deskno
     plugin_batt=batt
     plugin_kbled=kbled
-    plugin_xkb=
+    plugin_xkb=xkb
     plugin_thermal=thermal
 
     AC_MSG_RESULT(all)
@@ -363,7 +363,7 @@ echo Building dynamic plugins:
         AC_MSG_RESULT([    netstat - Monitor networking status (Linux Only)])
     fi
     if test x"$plugin_volume" != x; then
-        AC_MSG_RESULT([    volume - Display and adjust volume of sound card])
+        AC_MSG_RESULT([    volume - Display and adjust volume of sound card for OSS])
     fi
     if test x"$plugin_volumealsa" != x; then
         AC_MSG_RESULT([    volumealsa - Display and adjust volume of sound card for ALSA])
index 544168f..cf0ecd7 100644 (file)
                         <child>
                           <object class="GtkTable" id="table2">
                             <property name="visible">True</property>
-                            <property name="n_rows">2</property>
+                            <property name="n_rows">3</property>
                             <property name="n_columns">3</property>
                             <property name="row_spacing">2</property>
                             <child>
                                 <property name="y_options"></property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkLabel" id="label11">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">&lt;b&gt;Icon&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </object>
+                              <packing>
+                                <property name="top_attach">2</property>
+                                <property name="bottom_attach">3</property>
+                                <property name="y_options"></property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkSpinButton" id="icon_size">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="invisible_char">&#x2022;</property>
+                                <property name="adjustment">adjustment5</property>
+                                <property name="climb_rate">1</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                                <property name="top_attach">2</property>
+                                <property name="bottom_attach">3</property>
+                                <property name="x_options"></property>
+                                <property name="y_options">GTK_SHRINK</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="label14">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">pixels</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">2</property>
+                                <property name="right_attach">3</property>
+                                <property name="top_attach">2</property>
+                                <property name="bottom_attach">3</property>
+                              </packing>
+                            </child>
                           </object>
                         </child>
                       </object>
     <property name="upper">32767</property>
     <property name="step_increment">1</property>
   </object>
+  <object class="GtkAdjustment" id="adjustment5">
+    <property name="upper">32767</property>
+    <property name="step_increment">1</property>
+  </object>
 </interface>
index bc51404..fdab0f5 100644 (file)
@@ -363,6 +363,13 @@ set_height_when_minimized( GtkSpinButton* spin,  Panel* p  )
 }
 
 static void
+set_icon_size( GtkSpinButton* spin,  Panel* p  )
+{
+    p->icon_size = (int)gtk_spin_button_get_value(spin);
+    panel_set_panel_configuration_changed(p);
+}
+
+static void
 on_sel_plugin_changed( GtkTreeSelection* tree_sel, GtkWidget* label )
 {
     GtkTreeIter it;
@@ -867,7 +874,11 @@ void panel_configure( Panel* p, int sel_page )
 
     w = (GtkWidget*)gtk_builder_get_object( builder, "height_unit" );
     update_opt_menu( w, HEIGHT_PIXEL - 1);
-    //g_signal_connect( w, "changed", G_CALLBACK(set_height_type), NULL);
+
+    w = (GtkWidget*)gtk_builder_get_object( builder, "icon_size" );
+    gtk_spin_button_set_range( (GtkSpinButton*)w, PANEL_HEIGHT_MIN, PANEL_HEIGHT_MAX );
+    gtk_spin_button_set_value( (GtkSpinButton*)w, p->icon_size );
+    g_signal_connect( w, "value_changed", G_CALLBACK(set_icon_size), p );
 
     /* properties */
 
@@ -1043,7 +1054,8 @@ panel_global_config_save( Panel* p, FILE *fp)
     lxpanel_put_bool(fp, "usefontcolor", p->usefontcolor);
     lxpanel_put_line(fp, "fontcolor=#%06x", gcolor2rgb24(&p->gfontcolor));
     lxpanel_put_bool(fp, "background", p->background );
-    lxpanel_put_str(fp, "backgroundfile", p->background_file );
+    lxpanel_put_str(fp, "backgroundfile", p->background_file);
+    lxpanel_put_int(fp, "iconsize", p->icon_size);
     lxpanel_put_line(fp, "}\n");
 }
 
index 8177a3b..bd17588 100644 (file)
@@ -201,8 +201,8 @@ static void icon_grid_demand_resize(IconGrid * ig)
  * The icon grid manages the contents of the container.
  * The orientation, geometry of the elements, and spacing can be varied.  All elements are the same size. */
 IconGrid * icon_grid_new(
-    Panel * panel, GtkWidget * container, GtkOrientation orientation,
-    gint child_width, gint child_height, gint spacing, gint border, gint target_dimension)
+    Panel * panel, GtkWidget * container,
+    GtkOrientation orientation, gint child_width, gint child_height, gint spacing, gint border, gint target_dimension)
 {
     /* Create a structure representing the icon grid and collect the parameters. */
     IconGrid * ig = g_new0(IconGrid, 1);
@@ -330,10 +330,15 @@ extern void icon_grid_reorder_child(IconGrid * ig, GtkWidget * child, gint posit
     }
 }
 
-/* Change the orientation of an icon grid. */
-void icon_grid_set_orientation(IconGrid * ig, GtkOrientation orientation, gint target_dimension)
+/* Change the geometry of an icon grid. */
+void icon_grid_set_geometry(IconGrid * ig,
+    GtkOrientation orientation, gint child_width, gint child_height, gint spacing, gint border, gint target_dimension)
 {
     ig->orientation = orientation;
+    ig->child_width = child_width;
+    ig->child_height = child_height;
+    ig->spacing = spacing;
+    ig->border = border;
     ig->target_dimension = target_dimension;
     icon_grid_demand_resize(ig);
 }
index 4aef4c2..eacb636 100644 (file)
@@ -53,11 +53,12 @@ typedef struct _icon_grid {
 } IconGrid;
 
 extern IconGrid * icon_grid_new(
-    Panel * panel, GtkWidget * container, GtkOrientation orientation,
-    gint child_width, gint child_height, gint spacing, gint border, gint target_dimension);
+    Panel * panel, GtkWidget * container,
+    GtkOrientation orientation, gint child_width, gint child_height, gint spacing, gint border, gint target_dimension);
                                                /* Create an icon grid */
-extern void icon_grid_set_orientation(IconGrid * ig, GtkOrientation orientation, gint target_dimension);
-                                               /* Change the orientation of an icon grid */
+extern void icon_grid_set_geometry(IconGrid * ig,
+    GtkOrientation orientation, gint child_width, gint child_height, gint spacing, gint border, gint target_dimension);
+                                               /* Change the geometry of an icon grid */
 extern void icon_grid_add(IconGrid * ig, GtkWidget * child, gboolean visible);
                                                /* Add a child to the icon grid */
 extern void icon_grid_remove(IconGrid * ig, GtkWidget * child);
index 8d24695..cc2914e 100644 (file)
@@ -919,7 +919,7 @@ static void on_theme_changed(GtkIconTheme * theme, GtkWidget * img)
     _gtk_image_set_from_file_scaled(img, data->fname, data->dw, data->dh, data->keep_ratio);
 }
 
-void fb_button_set_from_file(GtkWidget * btn, const char * img_file)
+void fb_button_set_from_file(GtkWidget * btn, const char * img_file, gint width, gint height, gboolean keep_ratio)
 {
     /* Locate the image within the button. */
     GtkWidget * child = gtk_bin_get_child(GTK_BIN(btn));
@@ -938,6 +938,9 @@ void fb_button_set_from_file(GtkWidget * btn, const char * img_file)
         ImgData * data = (ImgData *) g_object_get_qdata(G_OBJECT(img), img_data_id);
         g_free(data->fname);
         data->fname = g_strdup(img_file);
+        data->dw = width;
+        data->dh = height;
+        data->keep_ratio = keep_ratio;
         _gtk_image_set_from_file_scaled(img, data->fname, data->dw, data->dh, data->keep_ratio);
     }
 }
index 2f95aa4..c4f9bd3 100644 (file)
@@ -128,7 +128,7 @@ extern GtkMenu* lxpanel_get_panel_menu( Panel* panel, Plugin* plugin, gboolean u
 
 extern GdkPixbuf* lxpanel_load_icon( const char* name, int width, int height, gboolean use_fallback );
 
-void fb_button_set_from_file(GtkWidget* btn, const char* img_file);
+void fb_button_set_from_file(GtkWidget* btn, const char* img_file, gint width, gint height, gboolean keep_ratio);
 
 gboolean lxpanel_launch_app(const char* exec, GList* files, gboolean in_terminal);
 
index f2d8017..a101714 100644 (file)
@@ -80,6 +80,7 @@ static Panel* panel_allocate(void)
     p->usefontcolor = 0;
     p->fontcolor = 0x00000000;
     p->spacing = 0;
+    p->icon_size = PANEL_ICON_SIZE;
     return p;
 }
 
@@ -824,6 +825,17 @@ void panel_establish_autohide(Panel *p)
     }
 }
 
+/* Set an image from a file with scaling to the panel icon size. */
+void panel_image_set_from_file(Panel * p, GtkWidget * image, char * file)
+{
+    GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file_at_scale(file, p->icon_size, p->icon_size, TRUE, NULL);
+    if (pixbuf != NULL)
+    {
+        gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
+        g_object_unref(pixbuf);
+    }
+}
+
 static void
 panel_start_gui(Panel *p)
 {
@@ -1119,6 +1131,8 @@ panel_parse_global(Panel *p, char **fp)
                     p->background = str2num(bool_pair, s.t[1], 0);
                 } else if( !g_ascii_strcasecmp(s.t[0], "BackgroundFile") ) {
                     p->background_file = g_strdup( s.t[1] );
+                } else if (!g_ascii_strcasecmp(s.t[0], "IconSize")) {
+                    p->icon_size = atoi(s.t[1]);
                 } else {
                     ERR( "lxpanel: %s - unknown var in Global section\n", s.t[0]);
                 }
index 7ec0bdc..7704b77 100644 (file)
@@ -94,6 +94,7 @@ typedef struct _Panel {
     guint visible : 1;
     int height_when_hidden;
     guint hide_timeout;
+    int icon_size;                     /* Icon size */
 
     int desknum;
     int curdesk;
@@ -218,6 +219,7 @@ extern void panel_determine_background_pixmap(Panel * p, GtkWidget * widget, Gdk
 extern void panel_draw_label_integer(Panel * p, GtkWidget * label, int value, gboolean bold);
 extern void panel_draw_label_text(Panel * p, GtkWidget * label, char * text, gboolean bold);
 extern void panel_establish_autohide(Panel *p);
+extern void panel_image_set_from_file(Panel * p, GtkWidget * image, char * file);
 extern void panel_set_wm_strut(Panel *p);
 extern void panel_set_dock_type(Panel *p);
 extern void panel_set_panel_configuration_changed(Panel *p);
index f514a28..096e31c 100644 (file)
@@ -326,7 +326,7 @@ dirmenu_constructor(Plugin *p, char **fp)
     /* Create button.
      * It is not known why, but the button text will not draw if it is edited from empty to non-empty
      * unless this strategy of initializing it with a non-empty value first is followed. */
-    p->pwid = dm->button = fb_button_new_from_file_with_label(fname, PANEL_ICON_SIZE, PANEL_ICON_SIZE,
+    p->pwid = dm->button = fb_button_new_from_file_with_label(fname, p->panel->icon_size, p->panel->icon_size,
         PANEL_ICON_HIGHLIGHT, TRUE, p->panel, "Temp");
     dirmenu_apply_config_to_children(dm->button, dm);
     gtk_container_set_border_width( GTK_CONTAINER(dm->button), 0 );
@@ -393,6 +393,10 @@ static void dirmenu_configure( Plugin *p, GtkWindow* parent )
 /* Callback when panel configuration changes. */
 static void dirmenu_panel_configuration_changed(Plugin * p)
 {
+    dirmenu* dm = (dirmenu*)p->priv;
+    fb_button_set_from_file(p->pwid,
+        ((dm->image != NULL) ? dm->image : "file-manager"),
+        p->panel->icon_size, p->panel->icon_size, TRUE);
     dirmenu_apply_config(p);
 }
 
index 35ae81d..2f95837 100644 (file)
@@ -51,6 +51,7 @@ static int xkb_error_base = 0;
 
 /* Private context for keyboard LED plugin. */
 typedef struct {
+    Plugin * plugin;                           /* Back pointer to plugin */
     IconGrid * icon_grid;                      /* Icon grid manager */
     GtkWidget *indicator_image[3];             /* Image for each indicator */
     int current_state;                         /* Current LED state, bit encoded */
@@ -74,7 +75,7 @@ static void kbled_update_image(KeyboardLEDPlugin * kl, int i, int state)
         PACKAGE_DATA_DIR "/lxpanel/images",
         ((state) ? on_icons[i] : off_icons[i]),
         NULL);
-    gtk_image_set_from_file(GTK_IMAGE(kl->indicator_image[i]), file);
+    panel_image_set_from_file(kl->plugin->panel, GTK_IMAGE(kl->indicator_image[i]), file);
     g_free(file);
 }
 
@@ -115,6 +116,7 @@ static int kbled_constructor(Plugin * p, char ** fp)
 {
     /* Allocate and initialize plugin context and set into Plugin private data pointer. */
     KeyboardLEDPlugin * kl = g_new0(KeyboardLEDPlugin, 1);
+    kl->plugin = p;
     kl->visible[0] = FALSE;
     kl->visible[1] = TRUE;
     kl->visible[2] = TRUE;
@@ -159,7 +161,7 @@ static int kbled_constructor(Plugin * p, char ** fp)
     /* Allocate an icon grid manager to manage the container.
      * Then allocate three images for the three indications, but make them visible only when the configuration requests. */
     GtkOrientation bo = (p->panel->orientation == ORIENT_HORIZ) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
-    kl->icon_grid = icon_grid_new(p->panel, p->pwid, bo, PANEL_ICON_SIZE, PANEL_ICON_SIZE, 0, 0, p->panel->height); 
+    kl->icon_grid = icon_grid_new(p->panel, p->pwid, bo, p->panel->icon_size, p->panel->icon_size, 0, 0, p->panel->height); 
     int i;
     for (i = 0; i < 3; i++)
     {
@@ -247,7 +249,12 @@ static void kbled_panel_configuration_changed(Plugin * p)
     /* Set orientation into the icon grid. */
     KeyboardLEDPlugin * kl = (KeyboardLEDPlugin *) p->priv;
     GtkOrientation bo = (p->panel->orientation == ORIENT_HORIZ) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
-    icon_grid_set_orientation(kl->icon_grid, bo, p->panel->height);
+    icon_grid_set_geometry(kl->icon_grid, bo, p->panel->icon_size, p->panel->icon_size, 0, 0, p->panel->height);
+
+    /* Do a full redraw. */
+    int current_state = kl->current_state;
+    kl->current_state = ~ kl->current_state;
+    kbled_update_display(p, current_state);
 }
 
 /* Plugin descriptor. */
index 714d689..5f47896 100644 (file)
@@ -207,7 +207,8 @@ static void launchbutton_build_bootstrap(Plugin * p)
         lb->bootstrap_button = g_new0(LaunchButton, 1);
         lb->bootstrap_button->plugin = p;
         lb->bootstrap_button->widget = gtk_button_new();
-        gtk_button_set_image(GTK_BUTTON(lb->bootstrap_button->widget), gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
+        gtk_button_set_image(GTK_BUTTON(lb->bootstrap_button->widget),
+            gtk_image_new_from_pixbuf(lxpanel_load_icon(GTK_STOCK_ADD, p->panel->icon_size, p->panel->icon_size, FALSE)));
         g_signal_connect(lb->bootstrap_button->widget, "button-press-event", G_CALLBACK(launchbutton_press_event), lb->bootstrap_button);
 
         /* Add the bootstrap button to the icon grid.  By policy it is empty at this point. */
@@ -273,7 +274,7 @@ static void launchbutton_build_gui(Plugin * p, LaunchButton * btn)
     }
 
     /* Create a button with the specified icon. */
-    GtkWidget * button = fb_button_new_from_file(btn->image, PANEL_ICON_SIZE, PANEL_ICON_SIZE, PANEL_ICON_HIGHLIGHT, TRUE);
+    GtkWidget * button = fb_button_new_from_file(btn->image, p->panel->icon_size, p->panel->icon_size, PANEL_ICON_HIGHLIGHT, TRUE);
     btn->widget = button;
     GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
     if (btn->tooltip != NULL)
@@ -387,7 +388,7 @@ static int launchbar_constructor(Plugin * p, char ** fp)
 
     /* Allocate an icon grid manager to manage the container. */
     GtkOrientation bo = (p->panel->orientation == ORIENT_HORIZ) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
-    lb->icon_grid = icon_grid_new(p->panel, p->pwid, bo, PANEL_ICON_SIZE, PANEL_ICON_SIZE, 3, 0, p->panel->height);
+    lb->icon_grid = icon_grid_new(p->panel, p->pwid, bo, p->panel->icon_size, p->panel->icon_size, 3, 0, p->panel->height);
 
     /* Read parameters from the configuration file. */
     if (fp != NULL)
@@ -804,7 +805,20 @@ static void launchbar_panel_configuration_changed(Plugin * p)
     /* Set orientation into the icon grid. */
     LaunchbarPlugin * lb = (LaunchbarPlugin *) p->priv;
     GtkOrientation bo = (p->panel->orientation == ORIENT_HORIZ) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
-    icon_grid_set_orientation(lb->icon_grid, bo, p->panel->height);
+    icon_grid_set_geometry(lb->icon_grid, bo, p->panel->icon_size, p->panel->icon_size, 3, 0, p->panel->height);
+
+    /* Reset all the images to resize them. */
+    GSList * l;
+    for (l = lb->buttons; l != NULL; l = l->next)
+    {
+        LaunchButton * btn = (LaunchButton *) l->data;
+        fb_button_set_from_file(btn->widget, btn->image, p->panel->icon_size, p->panel->icon_size, TRUE);
+    }
+
+    /* Reset the bootstrap button. */
+    if (lb->bootstrap_button != NULL)
+        gtk_button_set_image(GTK_BUTTON(lb->bootstrap_button->widget),
+            gtk_image_new_from_pixbuf(lxpanel_load_icon(GTK_STOCK_ADD, p->panel->icon_size, p->panel->icon_size, FALSE)));
 }
 
 /* Plugin descriptor. */
index 146ce21..e72aa78 100644 (file)
@@ -576,7 +576,6 @@ gboolean show_system_menu( gpointer system_menu )
 static GtkWidget *
 make_button(Plugin *p, gchar *fname, gchar *name, GdkColor* tint, GtkWidget *menu)
 {
-    int w = -1, h = PANEL_ICON_SIZE;
     char* title = NULL;
     menup *m;
 
@@ -601,14 +600,14 @@ make_button(Plugin *p, gchar *fname, gchar *name, GdkColor* tint, GtkWidget *men
         else
             title = name;
 
-        m->img = fb_button_new_from_file_with_label(fname, w, h, gcolor2rgb24(tint), TRUE, p->panel, title);
+        m->img = fb_button_new_from_file_with_label(fname, -1, p->panel->icon_size, gcolor2rgb24(tint), TRUE, p->panel, title);
 
         if( title != name )
             g_free( title );
     }
     else
     {
-        m->img = fb_button_new_from_file(fname, w, h, gcolor2rgb24(tint), TRUE);
+        m->img = fb_button_new_from_file(fname, -1, p->panel->icon_size, gcolor2rgb24(tint), TRUE);
     }
 
     gtk_widget_show(m->img);
@@ -977,7 +976,7 @@ static void apply_config(Plugin* p)
 {
     menup* m = (menup*)p->priv;
     if( m->fname )
-        fb_button_set_from_file( m->img, m->fname );
+        fb_button_set_from_file( m->img, m->fname, -1, p->panel->icon_size, TRUE );
 }
 
 static void menu_config( Plugin *p, GtkWindow* parent )
@@ -993,6 +992,12 @@ static void menu_config( Plugin *p, GtkWindow* parent )
     gtk_window_present( GTK_WINDOW(dlg) );
 }
 
+/* Callback when panel configuration changes. */
+static void menu_panel_configuration_changed(Plugin * p)
+{
+    apply_config(p);
+}
+
 PluginClass menu_plugin_class = {
 
     PLUGINCLASS_VERSIONING,
@@ -1005,6 +1010,7 @@ PluginClass menu_plugin_class = {
     constructor : menu_constructor,
     destructor  : menu_destructor,
     config : menu_config,
-    save : save_config
+    save : save_config,
+    panel_configuration_changed : menu_panel_configuration_changed
 };
 
index 6be88df..66b9b0b 100644 (file)
@@ -783,7 +783,11 @@ static void pager_panel_configuration_changed(Plugin * p)
     /* Reset the icon grid orientation. */
     PagerPlugin * pg = (PagerPlugin *) p->priv;
     GtkOrientation bo = (p->panel->orientation == ORIENT_HORIZ) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
-    icon_grid_set_orientation(pg->icon_grid, bo, p->panel->height); 
+    icon_grid_set_geometry(pg->icon_grid, bo,
+        (PANEL_HEIGHT_DEFAULT - BORDER_WIDTH * 2) * pg->aspect_ratio,
+        PANEL_HEIGHT_DEFAULT - BORDER_WIDTH * 2,
+        1, BORDER_WIDTH,
+        p->panel->height); 
 }
 
 /* Plugin descriptor. */
index f489e9e..a3a3fc3 100644 (file)
@@ -688,7 +688,7 @@ static int tray_constructor(Plugin * p, char ** fp)
 
     /* Create an icon grid to manage the container. */
     GtkOrientation bo = (p->panel->orientation == ORIENT_HORIZ) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
-    tr->icon_grid = icon_grid_new(p->panel, p->pwid, bo, PANEL_ICON_SIZE, PANEL_ICON_SIZE, 3, 0, p->panel->height);
+    tr->icon_grid = icon_grid_new(p->panel, p->pwid, bo, p->panel->icon_size, p->panel->icon_size, 3, 0, p->panel->height);
     return 1;
 }
 
@@ -727,7 +727,7 @@ static void tray_panel_configuration_changed(Plugin * p)
     /* Set orientation into the icon grid. */
     TrayPlugin * tr = (TrayPlugin *) p->priv;
     GtkOrientation bo = (p->panel->orientation == ORIENT_HORIZ) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
-    icon_grid_set_orientation(tr->icon_grid, bo, p->panel->height);
+    icon_grid_set_geometry(tr->icon_grid, bo, p->panel->icon_size, p->panel->icon_size, 3, 0, p->panel->height);
 }
 
 /* Plugin descriptor. */
index bf153e3..abaf94d 100644 (file)
@@ -78,22 +78,22 @@ static void update_icon (Plugin* p)
        theme = gtk_icon_theme_get_default();
        
        if (curr_volume <= 0) {
-               info = gtk_icon_theme_lookup_icon( theme, "stock_volume-mute", 24, 0 );
+               info = gtk_icon_theme_lookup_icon( theme, "stock_volume-mute", p->panel->icon_size, 0 );
        }
        else if (curr_volume > 0 && curr_volume <= 50) {
-               info = gtk_icon_theme_lookup_icon( theme, "stock_volume-min", 24, 0 );
+               info = gtk_icon_theme_lookup_icon( theme, "stock_volume-min", p->panel->icon_size, 0 );
        }
        else if (curr_volume > 50 && curr_volume <= 75) {
-               info = gtk_icon_theme_lookup_icon( theme, "stock_volume-med", 24, 0 );
+               info = gtk_icon_theme_lookup_icon( theme, "stock_volume-med", p->panel->icon_size, 0 );
        }
        else if (curr_volume > 75) {
-               info = gtk_icon_theme_lookup_icon( theme, "stock_volume-max", 24, 0 );
+               info = gtk_icon_theme_lookup_icon( theme, "stock_volume-max", p->panel->icon_size, 0 );
        }
 
        if (info ) {
                icon = gdk_pixbuf_new_from_file_at_size(
                                gtk_icon_info_get_filename( info ),
-                               24, 24, NULL );
+                               p->panel->icon_size, p->panel->icon_size, NULL );
                gtk_icon_info_free( info );
        }
        else {
@@ -164,7 +164,7 @@ static void on_mouse_scroll (GtkWidget* widget, GdkEventScroll* evt, Plugin* p)
        }
 }
 
-static void on_button_press (GtkWidget* widget, GdkEventButton* evt, Plugin* p)
+static gboolean on_button_press (GtkWidget* widget, GdkEventButton* evt, Plugin* p)
 {
        volume_t *vol = (volume_t*) p->priv;
 
@@ -279,7 +279,7 @@ static int volume_constructor(Plugin *p, char **fp)
             
     g_signal_connect( vol->mainw, "scroll-event",
             G_CALLBACK(on_mouse_scroll), p );
-    gtk_widget_set_size_request( vol->mainw, 24, 24 );
+    gtk_widget_set_size_request( vol->mainw, p->panel->icon_size, p->panel->icon_size );
 
     /* obtain current volume */
     vol->dlg = create_volume_window();
index 942a671..d0e4e9c 100644 (file)
@@ -79,10 +79,7 @@ static void update_display(volume_t* vol)
     /* mute status */
     snd_mixer_selem_get_playback_switch(vol->master_element, 0, &vol->mute);
 
-    if (vol->mute==0)
-        gtk_image_set_from_file(GTK_IMAGE(vol->tray_icon), ICONS_MUTE);
-    else
-        gtk_image_set_from_file(GTK_IMAGE(vol->tray_icon), ICONS_VOLUME);
+    panel_image_set_from_file(vol->plugin->panel, vol->tray_icon, ((vol->mute) ? ICONS_VOLUME : ICONS_MUTE));
 
     g_signal_handler_block( vol->mute_check, vol->mute_handler );
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vol->mute_check), !vol->mute );
@@ -266,12 +263,12 @@ static void click_mute(GtkWidget *widget, volume_t *vol)
     int chn;
 
     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
-        gtk_image_set_from_file(GTK_IMAGE(vol->tray_icon), ICONS_MUTE);
+        panel_image_set_from_file(vol->plugin->panel, GTK_IMAGE(vol->tray_icon), ICONS_MUTE);
         for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++) {
             snd_mixer_selem_set_playback_switch(vol->master_element, chn, 0);
         }
     } else {
-        gtk_image_set_from_file(GTK_IMAGE(vol->tray_icon), ICONS_VOLUME);
+        panel_image_set_from_file(vol->plugin->panel, GTK_IMAGE(vol->tray_icon), ICONS_VOLUME);
         for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++) {
             snd_mixer_selem_set_playback_switch(vol->master_element, chn, 1);
         }
@@ -392,7 +389,7 @@ volumealsa_constructor(Plugin *p, char **fp)
     vol->mainw = gtk_event_box_new();
 
     gtk_widget_add_events(vol->mainw, GDK_BUTTON_PRESS_MASK);
-    gtk_widget_set_size_request( vol->mainw, PANEL_ICON_SIZE, PANEL_ICON_SIZE );
+    gtk_widget_set_size_request( vol->mainw, p->panel->icon_size, p->panel->icon_size );
 
     g_signal_connect(G_OBJECT(vol->mainw), "button-press-event",
                          G_CALLBACK(tray_icon_press), vol);
@@ -415,6 +412,12 @@ volumealsa_constructor(Plugin *p, char **fp)
     RET(1);
 }
 
+/* Callback when panel configuration changes. */
+static void volumealsa_panel_configuration_changed(Plugin * p)
+{
+    /* Do a full redraw. */
+    update_display((volume_t *) p->priv);
+}
 
 PluginClass volumealsa_plugin_class = {
 
@@ -428,5 +431,6 @@ PluginClass volumealsa_plugin_class = {
     constructor : volumealsa_constructor,
     destructor  : volumealsa_destructor,
     config : NULL,
-    save : NULL
+    save : NULL,
+    panel_configuration_changed : volumealsa_panel_configuration_changed
 };
index 1251cff..fe7dc35 100644 (file)
@@ -53,6 +53,8 @@ static gboolean wincmd_button_clicked(GtkWidget * widget, GdkEventButton * event
 static int wincmd_constructor(Plugin * p, char ** fp);
 static void wincmd_destructor(Plugin * p);
 static void wincmd_save_configuration(Plugin * p, FILE * fp);
+static void wincmd_panel_configuration_changed(Plugin * p);
+
 
 /* Execute a window command. */
 static void wincmd_execute(WindowCommand command)
@@ -161,7 +163,7 @@ static int wincmd_constructor(Plugin * p, char ** fp)
         wc->image = g_strdup("window-manager");
 
     /* Allocate top level widget and set into Plugin widget pointer. */
-    p->pwid = fb_button_new_from_file(wc->image, PANEL_ICON_SIZE, PANEL_ICON_SIZE, PANEL_ICON_HIGHLIGHT, TRUE);
+    p->pwid = fb_button_new_from_file(wc->image, p->panel->icon_size, p->panel->icon_size, PANEL_ICON_HIGHLIGHT, TRUE);
     gtk_container_set_border_width(GTK_CONTAINER(p->pwid), 0);
     g_signal_connect(G_OBJECT(p->pwid), "button_press_event", G_CALLBACK(wincmd_button_clicked), (gpointer) p);
     gtk_widget_set_tooltip_text(p->pwid, _("Left click to iconify all windows.  Middle click to shade them."));
@@ -174,7 +176,7 @@ static int wincmd_constructor(Plugin * p, char ** fp)
 /* Plugin destructor. */
 static void wincmd_destructor(Plugin * p)
 {
-    WinCmdPlugin * wc = (WinCmdPlugin * ) p->priv;
+    WinCmdPlugin * wc = (WinCmdPlugin *) p->priv;
     g_free(wc->image);
     g_free(wc);
 }
@@ -188,6 +190,13 @@ static void wincmd_save_configuration(Plugin * p, FILE * fp)
     lxpanel_put_str(fp, "Button2", num2str(wincmd_pair, wc->button_2_command, NULL));
 }
 
+/* Callback when panel configuration changes. */
+static void wincmd_panel_configuration_changed(Plugin * p)
+{
+    WinCmdPlugin * wc = (WinCmdPlugin *) p->priv;
+    fb_button_set_from_file(p->pwid, wc->image, p->panel->icon_size, p->panel->icon_size, TRUE);
+}
+
 /* Plugin descriptor. */
 PluginClass wincmd_plugin_class = {
 
@@ -201,5 +210,6 @@ PluginClass wincmd_plugin_class = {
     constructor : wincmd_constructor,
     destructor  : wincmd_destructor,
     config : NULL,
-    save : wincmd_save_configuration
+    save : wincmd_save_configuration,
+    panel_configuration_changed : wincmd_panel_configuration_changed
 };
index 3fffd02..860f44c 100644 (file)
@@ -35,10 +35,10 @@ static void
 xkb_free(t_xkb *xkb);
 
 static void
-xkb_save_config(t_xkb *xkb, gchar *filename);
+xkb_configure(Plugin * p, GtkWindow * parent);
 
 static t_xkb_options_dlg*
-xkb_options_dlg_create();
+xkb_options_dlg_create(t_xkb * xkb);
 
 static void
 free_xkb_options_dlg(GtkDialog *dialog, gint arg1, gpointer user_data);
@@ -56,7 +56,7 @@ static void
 application_closed( FbEv* ev, Window win, gpointer data) ;
 
 static void 
-xkb_refresh_gui(t_xkb *data) ;
+xkb_refresh_gui(t_xkb * plugin);
 
 /* ------------------------------------------------------------------ *
  *                     Panel Plugin Interface                         *
@@ -80,11 +80,6 @@ xkb_set_size(Plugin *plugin,gint size,
 static void 
 xkb_free_data(Plugin *plugin,t_xkb *xkb);
 
-static void 
-xkb_save(Plugin *plugin, t_xkb *xkb);
-
-static void 
-xkb_configure(Plugin *plugin, t_xkb *xkb);
 
 static void 
 xkb_about(Plugin *plugin, t_xkb *xkb);
@@ -98,8 +93,11 @@ xkb_constructor (Plugin *plugin, char** fp)
 
   const char *initial_group;
 
-  xkb = g_new(t_xkb, 1);
+  xkb = g_new0(t_xkb, 1);
+  xkb->plugin = plugin;
+  plugin->priv = xkb;
 
+  xkb->size = plugin->panel->icon_size;
   xkb->display_type = IMAGE;
   xkb->enable_perapp = TRUE;
   xkb->default_group = 0;
@@ -128,14 +126,14 @@ xkb_constructor (Plugin *plugin, char** fp)
         }
     }
 
-  xkb->size = PANEL_ICON_SIZE;
 
   plugin->pwid = gtk_event_box_new();
   gtk_widget_add_events(plugin->pwid, GDK_BUTTON_PRESS_MASK);
   xkb->btn = gtk_button_new();
   gtk_container_add(GTK_CONTAINER(plugin->pwid), xkb->btn);
   gtk_button_set_relief(GTK_BUTTON(xkb->btn), GTK_RELIEF_NONE);
-  // gtk_container_add(GTK_CONTAINER(xkb->plugin->pwid), xkb->btn);
+  GTK_WIDGET_UNSET_FLAGS(xkb->btn, GTK_CAN_FOCUS);
+  GTK_WIDGET_UNSET_FLAGS(xkb->btn, GTK_CAN_DEFAULT);
 
   gtk_widget_show(xkb->btn);
   g_signal_connect(xkb->btn, "button-press-event", G_CALLBACK(change_group), xkb);
@@ -154,6 +152,7 @@ xkb_constructor (Plugin *plugin, char** fp)
   initial_group = initialize_xkb(xkb);
 
   xkb_refresh_gui(xkb);
+  set_new_locale(xkb);
 
   channel = g_io_channel_unix_new(get_connection_number());
   source_id = g_io_add_watch(channel, G_IO_IN | G_IO_PRI, 
@@ -166,10 +165,8 @@ xkb_constructor (Plugin *plugin, char** fp)
 //  win_close_hanler = g_signal_connect( G_OBJECT (fbev), 
 //      "destroy_window", G_CALLBACK(application_closed), xkb);
 
-  gtk_widget_show_all(plugin->pwid);
+  gtk_widget_show(plugin->pwid);
 
-  xkb->plugin = plugin;
-  plugin->priv = xkb;
   
   
     RET(1);
@@ -208,25 +205,14 @@ xkb_free_data(Plugin *plugin, t_xkb *xkb)
   xkb_free(xkb);
 }
 
-void xkb_save(Plugin *plugin, t_xkb *xkb)
-{
-  gchar *filename;
-//  filename = xfce_panel_plugin_save_location(plugin, TRUE);
-  if (filename)
-  {
-    xkb_save_config(xkb, filename);
-    g_free(filename);
-  }
-}
-
-void 
-xkb_configure(Plugin *plugin, t_xkb *xkb)
+/* Callback when the configuration dialog is to be shown. */
+static void xkb_configure(Plugin * p, GtkWindow * parent)
 {
-//  xfce_panel_plugin_block_menu(plugin)
-  dlg = xkb_options_dlg_create();
-  xkb_options_dlg_set_xkb(dlg, xkb);
-  gtk_dialog_run(GTK_DIALOG(dlg->dialog));
-  //xfce_panel_plugin_unblock_menu(plugin);
+    t_xkb * xkb = (t_xkb *) p->priv
+    dlg = xkb_options_dlg_create(xkb);
+    xkb_options_dlg_set_xkb(dlg, xkb);
+    gtk_widget_set_size_request(GTK_WIDGET(dlg->dialog), 400, -1);     /* Improve geometry */
+    gtk_dialog_run(GTK_DIALOG(dlg->dialog));
 }
 
 void 
@@ -257,29 +243,6 @@ xkb_about(Plugin *plugin, t_xkb *xkb)
 
 /* ----------------- xkb plugin stuff -----------------------*/
 
-static void
-xkb_save_config(t_xkb *xkb, gchar *filename)
-{
-/*
-  XfceRc* rcfile = xfce_rc_simple_open(filename, FALSE);
-  if (!rcfile) 
-  {
-    return;
-  }
-
-  xfce_rc_set_group(rcfile, NULL);
-
-  xfce_rc_write_int_entry(rcfile, "display_type", 
-      xkb->display_type);
-  xfce_rc_write_int_entry(rcfile, "per_app_layout", 
-      (xkb->enable_perapp) ? 1 : 0);
-  xfce_rc_write_int_entry(rcfile, "default_group", 
-      xkb->default_group);
-
-  xfce_rc_close(rcfile);
-*/
-}
-
 void 
 active_window_changed(FbEv *ev, gpointer data) 
 {
@@ -309,30 +272,18 @@ change_group(GtkWidget *widget,  GdkEventButton * event, gpointer data)
   do_change_group(1, xkb);
 }
 
-void 
-xkb_refresh_gui(t_xkb *data) 
+void xkb_refresh_gui(t_xkb * plugin) 
 {
-  t_xkb *plugin = (t_xkb *) data;
-
-  switch (plugin->display_type) 
-  {
-    case TEXT:
-      gtk_widget_hide(plugin->image);
-      gtk_widget_show(plugin->label);
-      break;
-    case IMAGE:
-      if (is_current_group_flag_available()) 
-      {
+    if ((plugin->display_type == TEXT) || ( ! is_current_group_flag_available())) 
+    {
+        gtk_widget_hide(plugin->image);
+        gtk_widget_show(plugin->label);
+    }
+    else
+    {
         gtk_widget_hide(plugin->label);
         gtk_widget_show(plugin->image);
-      }
-      break;
-    default: break;
-  }
-
-  /* Part of the image may remain visible after display type change */
-  gtk_widget_queue_draw_area(plugin->btn, 0, 0, 
-      plugin->size, plugin->size);
+    }
 }
 
 static void 
@@ -359,6 +310,7 @@ xkb_display_type_changed(GtkComboBox *cb, gpointer *data)
   t_xkb *xkb = (t_xkb *) data;
   xkb->display_type = gtk_combo_box_get_active(cb);
   xkb_refresh_gui(xkb);
+  set_new_locale(xkb);
 }
 
 static void 
@@ -368,6 +320,7 @@ xkb_enable_perapp_changed(GtkToggleButton *tb, gpointer *data)
   dlg->xkb->enable_perapp = gtk_toggle_button_get_active(tb);
   gtk_widget_set_sensitive(dlg->per_app_default_layout_menu, 
       dlg->xkb->enable_perapp);
+  set_new_locale(dlg->xkb);
 }
 
 static void 
@@ -375,12 +328,13 @@ xkb_def_lang_changed(GtkComboBox *cb, gpointer *data)
 {
   t_xkb *xkb = (t_xkb *) data;
   xkb->default_group = gtk_combo_box_get_active(cb);
+  set_new_locale(xkb);
 }
 
 /* ----------------- xkb options dialog -----------------------*/
 
 static t_xkb_options_dlg*
-xkb_options_dlg_create()
+xkb_options_dlg_create(t_xkb * xkb)
 {
   int x;
   GtkWidget *vbox, *hbox, *display_type_frame,
@@ -396,6 +350,8 @@ xkb_options_dlg_create()
       GTK_RESPONSE_OK,
       NULL
   );
+  panel_apply_icon(GTK_WINDOW(dlg->dialog));
+
  
   vbox = gtk_vbox_new(FALSE, 2);
   gtk_widget_show(vbox);
@@ -476,6 +432,9 @@ free_xkb_options_dlg(GtkDialog *dialog, gint arg1, gpointer user_data)
   DBG("destroy options dialog\n");
   gtk_widget_hide(dlg->dialog);
   gtk_widget_destroy(dlg->dialog);
+
+  panel_config_save(dlg->xkb->plugin->panel);
+  set_new_locale(dlg->xkb);
   
   g_free(dlg);
   dlg = NULL;
@@ -497,6 +456,23 @@ xkb_options_dlg_set_xkb(t_xkb_options_dlg *dlg, t_xkb *xkb)
   g_signal_connect(dlg->per_app_default_layout_menu, "changed", G_CALLBACK(xkb_def_lang_changed), xkb);
 }
 
+/* Callback when the configuration is to be saved. */
+static void xkb_save_configuration(Plugin * p, FILE * fp)
+{
+    t_xkb * xkb = (t_xkb *) p->priv;
+    lxpanel_put_int(fp, "DisplayType", xkb->display_type);
+    lxpanel_put_int(fp, "PerAppLayout", xkb->enable_perapp);
+    lxpanel_put_int(fp, "DefaultGroup", xkb->default_group);
+}
+
+/* Callback when panel configuration changes. */
+static void xkb_panel_configuration_changed(Plugin * p)
+{
+    /* Do a full redraw. */
+    t_xkb * xkb = (t_xkb *) p->priv;
+    xkb->size = p->panel->icon_size;
+    set_new_locale(xkb);
+}
 
 PluginClass xkb_plugin_class = {
 
@@ -507,8 +483,12 @@ PluginClass xkb_plugin_class = {
     version: "1.0",
     description : N_("Switch between available keyboard layouts"),
 
+    /* Due to static variable usage; when context migrated to t_xkb, can be removed. */
+    one_per_system : TRUE,
+
     constructor : xkb_constructor,
     destructor  : xkb_destructor,
-//    config : xkb_config,
-//    save : save_config,
+    config : xkb_configure,
+    save : xkb_save_configuration,
+    panel_configuration_changed : xkb_panel_configuration_changed
 };
index f335265..8c10db0 100644 (file)
@@ -347,13 +347,8 @@ set_new_locale(t_xkb *ctrl)
   GdkPixbuf *pixbuf = NULL, *tmp = NULL;
   gint pid;
 
-  /* Set the label   */
-  label_markup = xkb_get_label_markup (plugin); 
-  gtk_label_set_markup (GTK_LABEL (plugin->label), label_markup);
-  g_free(label_markup);
-  
   /* Set the image */
-  size = 0.9 * plugin->size;
+  size = plugin->size;
   group_name = get_current_group_name();
   filename = g_strdup_printf("%s/%s.png", FLAGSDIR, group_name);
   DBG ("Try to load image: %s", filename);
@@ -385,6 +380,15 @@ set_new_locale(t_xkb *ctrl)
     }
   }
 
+  /* Set the label */
+  if (plugin->display_type == TEXT)
+  {
+//    label_markup = xkb_get_label_markup (plugin);
+    panel_draw_label_text(plugin->plugin->panel, plugin->label, (char *) get_symbol_name_by_res_no (current_group_xkb_no), TRUE);
+//    gtk_label_set_markup (GTK_LABEL (plugin->label), label_markup);
+//    g_free(label_markup);
+  }
+  
   /* Part of the image may remain visible after image or display type change */
   gtk_widget_queue_draw_area(plugin->btn, 0, 0, plugin->size, plugin->size);
 
index 24787aa..89bd570 100644 (file)
 
 #include "dbg.h"
 
-#define ICONSIZETINY 24 
-#define ICONSIZESMALL 30
-#define ICONSIZEMEDIUM 45
-#define ICONSIZELARGE 60
+//#define ICONSIZETINY 24 
+//#define ICONSIZESMALL 30
+//#define ICONSIZEMEDIUM 45
+//#define ICONSIZELARGE 60
 
 typedef enum 
 {