From 3153f7f3d4c716128c2a6c46c8bcd2734c8f2948 Mon Sep 17 00:00:00 2001 From: Vlad Marica Date: Wed, 18 Dec 2019 01:39:04 -0400 Subject: [PATCH] Add option for custom separator size (Bug #10481) --- plugins/separator/separator-dialog.glade | 80 +++++++++++++-- plugins/separator/separator.c | 120 +++++++++++++++++++++-- plugins/separator/separator.h | 1 + 3 files changed, 187 insertions(+), 14 deletions(-) diff --git a/plugins/separator/separator-dialog.glade b/plugins/separator/separator-dialog.glade index 6301a4fb..78c30108 100644 --- a/plugins/separator/separator-dialog.glade +++ b/plugins/separator/separator-dialog.glade @@ -3,6 +3,13 @@ + + 1 + 255 + 8 + 1 + 10 + True False @@ -13,6 +20,23 @@ False window-close-symbolic + + + + + + + + Default + + + Expand + + + Custom + + + @@ -113,7 +137,7 @@ False 12 - + True False _Style: @@ -152,18 +176,60 @@ - - _Expand + True + False + 18 + + + True + False + _Size: + True + size-type + + + False + True + 0 + + + + + True + False + size-type-model + + + + 0 + + + + + True + True + 1 + + + + + False + True + 2 + + + + True - False - True - True + end + custom-size False True - 1 + end + 3 diff --git a/plugins/separator/separator.c b/plugins/separator/separator.c index 7ece3b49..df229062 100644 --- a/plugins/separator/separator.c +++ b/plugins/separator/separator.c @@ -36,6 +36,8 @@ #define SEPARATOR_OFFSET (0.15) #define SEPARATOR_SIZE (8) +#define MIN_CUSTOM_SIZE (1) +#define MAX_CUSTOM_SIZE (255) #define DOTS_OFFSET (4) #define DOTS_SIZE (3) #define HANDLE_SIZE (4) @@ -75,6 +77,16 @@ enum _SeparatorPluginStyle SEPARATOR_PLUGIN_STYLE_DEFAULT = SEPARATOR_PLUGIN_STYLE_SEPARATOR }; +enum _SeparatorPluginSizeType { + SEPARATOR_PLUGIN_SIZE_TYPE_DEFAULT = 0, + SEPARATOR_PLUGIN_SIZE_TYPE_EXPAND, + SEPARATOR_PLUGIN_SIZE_TYPE_CUSTOM, + + /* defines */ + SEPARATOR_PLUGIN_SIZE_TYPE_MIN = SEPARATOR_PLUGIN_SIZE_TYPE_DEFAULT, + SEPARATOR_PLUGIN_SIZE_TYPE_MAX = SEPARATOR_PLUGIN_SIZE_TYPE_CUSTOM, +}; + struct _SeparatorPluginClass { /* parent class */ @@ -88,13 +100,21 @@ struct _SeparatorPlugin /* separator style */ SeparatorPluginStyle style; + + /* size type */ + SeparatorPluginSizeType size_type; + + /* separator size if the size_type is "custom */ + guint custom_size; }; enum { PROP_0, PROP_STYLE, - PROP_EXPAND + PROP_EXPAND, + PROP_SIZE_TYPE, + PROP_CUSTOM_SIZE, }; @@ -139,6 +159,24 @@ separator_plugin_class_init (SeparatorPluginClass *klass) NULL, NULL, FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, + PROP_SIZE_TYPE, + g_param_spec_uint ("size-type", + NULL, NULL, + SEPARATOR_PLUGIN_SIZE_TYPE_MIN, + SEPARATOR_PLUGIN_SIZE_TYPE_MAX, + SEPARATOR_PLUGIN_SIZE_TYPE_DEFAULT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, + PROP_CUSTOM_SIZE, + g_param_spec_uint ("custom-size", + NULL, NULL, + MIN_CUSTOM_SIZE, + MAX_CUSTOM_SIZE, + SEPARATOR_SIZE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } @@ -147,6 +185,8 @@ static void separator_plugin_init (SeparatorPlugin *plugin) { plugin->style = SEPARATOR_PLUGIN_STYLE_DEFAULT; + plugin->size_type = SEPARATOR_PLUGIN_SIZE_TYPE_DEFAULT; + plugin->custom_size = SEPARATOR_SIZE; } @@ -171,6 +211,14 @@ separator_plugin_get_property (GObject *object, g_value_set_boolean (value, expand); break; + case PROP_SIZE_TYPE: + g_value_set_uint (value, plugin->size_type); + break; + + case PROP_CUSTOM_SIZE: + g_value_set_uint (value, plugin->custom_size); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -204,6 +252,22 @@ separator_plugin_set_property (GObject *object, g_value_get_boolean (value)); break; + case PROP_SIZE_TYPE: + plugin->size_type = g_value_get_uint (value); + + xfce_panel_plugin_set_expand (XFCE_PANEL_PLUGIN (plugin), + plugin->size_type == SEPARATOR_PLUGIN_SIZE_TYPE_EXPAND); + + separator_plugin_size_changed (XFCE_PANEL_PLUGIN (plugin), + xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin))); + break; + + case PROP_CUSTOM_SIZE: + plugin->custom_size = g_value_get_uint(value); + separator_plugin_size_changed (XFCE_PANEL_PLUGIN (plugin), + xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin))); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -320,10 +384,14 @@ static void separator_plugin_construct (XfcePanelPlugin *panel_plugin) { SeparatorPlugin *plugin = XFCE_SEPARATOR_PLUGIN (panel_plugin); + GValue expand = G_VALUE_INIT; + GValue size_type = G_VALUE_INIT; const PanelProperty properties[] = { { "style", G_TYPE_UINT }, { "expand", G_TYPE_BOOLEAN }, + { "size-type", G_TYPE_UINT }, + { "custom-size", G_TYPE_UINT }, { NULL } }; @@ -336,6 +404,14 @@ separator_plugin_construct (XfcePanelPlugin *panel_plugin) xfce_panel_plugin_get_property_base (panel_plugin), properties, FALSE); + /* set the size type to 'expand' if the old expand flag is on */ + g_object_get_property( G_OBJECT(plugin), "expand", &expand); + if (g_value_get_boolean (&expand)) { + g_value_init (&size_type, G_TYPE_UINT); + g_value_set_uint (&size_type, SEPARATOR_PLUGIN_SIZE_TYPE_EXPAND); + g_object_set_property (G_OBJECT (plugin), "size-type", &size_type); + } + /* make sure the plugin is drawn */ gtk_widget_queue_draw (GTK_WIDGET (panel_plugin)); } @@ -346,19 +422,36 @@ static gboolean separator_plugin_size_changed (XfcePanelPlugin *panel_plugin, gint size) { + SeparatorPlugin *plugin = XFCE_SEPARATOR_PLUGIN (panel_plugin); + gint separator_width = SEPARATOR_SIZE; + + if (plugin->size_type == SEPARATOR_PLUGIN_SIZE_TYPE_CUSTOM) + separator_width = plugin->custom_size; + /* set the minimum separator size */ if (xfce_panel_plugin_get_orientation (panel_plugin) == GTK_ORIENTATION_HORIZONTAL) gtk_widget_set_size_request (GTK_WIDGET (panel_plugin), - SEPARATOR_SIZE, size); + separator_width, size); else gtk_widget_set_size_request (GTK_WIDGET (panel_plugin), - size, SEPARATOR_SIZE); + size, separator_width); return TRUE; } +static void +separator_plugin_configure_size_type_chooser_changed (GtkComboBox *size_type_combobox, + GtkWidget *custom_size_button) +{ + GValue size_type = G_VALUE_INIT; + g_object_get_property (G_OBJECT (size_type_combobox), "active", &size_type); + g_warn_if_fail (G_VALUE_HOLDS_INT (&size_type)); + + gtk_widget_set_visible (custom_size_button, + g_value_get_int (&size_type) == SEPARATOR_PLUGIN_SIZE_TYPE_CUSTOM); +} static void separator_plugin_configure_plugin (XfcePanelPlugin *panel_plugin) @@ -366,7 +459,7 @@ separator_plugin_configure_plugin (XfcePanelPlugin *panel_plugin) SeparatorPlugin *plugin = XFCE_SEPARATOR_PLUGIN (panel_plugin); GtkBuilder *builder; GObject *dialog; - GObject *style, *expand; + GObject *style, *size_type, *custom_size, *custom_size_button; panel_return_if_fail (XFCE_IS_SEPARATOR_PLUGIN (plugin)); @@ -381,11 +474,24 @@ separator_plugin_configure_plugin (XfcePanelPlugin *panel_plugin) G_OBJECT (style), "active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); - expand = gtk_builder_get_object (builder, "expand"); - g_object_bind_property (G_OBJECT (plugin), "expand", - G_OBJECT (expand), "active", + size_type = gtk_builder_get_object (builder, "size-type"); + g_object_bind_property (G_OBJECT (plugin), "size-type", + G_OBJECT (size_type), "active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); + custom_size = gtk_builder_get_object (builder, "custom-size"); + g_object_bind_property (G_OBJECT (plugin), "custom-size", + G_OBJECT (custom_size), "value", + G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); + + custom_size_button = gtk_builder_get_object (builder, "custom-size-button"); + gtk_widget_set_visible (GTK_WIDGET (custom_size_button), + plugin->size_type == SEPARATOR_PLUGIN_SIZE_TYPE_CUSTOM); + + /* listen for changes in the size type so the custom size input button can be shown/hidden */ + g_signal_connect (G_OBJECT (size_type), "changed", + G_CALLBACK(separator_plugin_configure_size_type_chooser_changed), custom_size_button); + gtk_widget_show (GTK_WIDGET (dialog)); } diff --git a/plugins/separator/separator.h b/plugins/separator/separator.h index 0b70b4e2..f241fb6f 100644 --- a/plugins/separator/separator.h +++ b/plugins/separator/separator.h @@ -27,6 +27,7 @@ G_BEGIN_DECLS typedef struct _SeparatorPluginClass SeparatorPluginClass; typedef struct _SeparatorPlugin SeparatorPlugin; typedef enum _SeparatorPluginStyle SeparatorPluginStyle; +typedef enum _SeparatorPluginSizeType SeparatorPluginSizeType; #define XFCE_TYPE_SEPARATOR_PLUGIN (separator_plugin_get_type ()) #define XFCE_SEPARATOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_SEPARATOR_PLUGIN, SeparatorPlugin)) -- 2.24.0.rc1