From c47a47f86e7d5f73aa11f58bf9ad91386f038629 Mon Sep 17 00:00:00 2001 From: giskard Date: Mon, 13 May 2024 16:24:29 +0800 Subject: [PATCH 1/4] Tweak buttonsGrid to centered it, add options buttonsGrid is using flowbox as the container, with default halign set to FILL, for which users have to tweak the button size to make it really fill the space or it will not be centered. this add options to make the buttonGrid centered properly --- src/configSchema.json | 10 ++++++++++ .../widgets/buttonsGrid/buttonsGrid.vala | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/configSchema.json b/src/configSchema.json index 64210075..595bd599 100644 --- a/src/configSchema.json +++ b/src/configSchema.json @@ -418,6 +418,16 @@ "description": "A widget to add a grid of buttons that execute shell commands", "additionalProperties": false, "properties": { + "column-min": { + "type": "integer", + "description": "minimum number of buttons per line", + "default": 4 + }, + "column-max": { + "type": "integer", + "description": "maximum number of buttons per line", + "default": 7 + }, "actions": { "type": "array", "description": "A list of actions containing a label and a command", diff --git a/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala b/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala index 9b795036..0e7f65fa 100644 --- a/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala +++ b/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala @@ -15,14 +15,25 @@ namespace SwayNotificationCenter.Widgets { public ButtonsGrid (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { base (suffix, swaync_daemon, noti_daemon); + int column_min = 4; + int column_max = 7; + Json.Object ? config = get_config (this); if (config != null) { Json.Array a = get_prop_array (config, "actions"); if (a != null) actions = parse_actions (a); + + int? col_min = get_prop (config, "column-min"); + if (col_min != null) column_min = col_min; + int? col_max = get_prop (config, "column-max"); + if (col_max != null) column_max = col_max; } Gtk.FlowBox container = new Gtk.FlowBox (); container.set_selection_mode (Gtk.SelectionMode.NONE); + container.set_halign(Gtk.Align.CENTER); + container.set_min_children_per_line(column_min); + container.set_max_children_per_line(column_max); pack_start (container, true, true, 0); // add action to container From 061d836b602a807de63161c9afa73fe11f750c54 Mon Sep 17 00:00:00 2001 From: giskard Date: Mon, 13 May 2024 16:44:25 +0800 Subject: [PATCH 2/4] buttonsGrid: add center switch for compatibility set options only when it's present --- src/configSchema.json | 9 ++++++-- .../widgets/buttonsGrid/buttonsGrid.vala | 23 ++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/configSchema.json b/src/configSchema.json index 595bd599..bf7f11c8 100644 --- a/src/configSchema.json +++ b/src/configSchema.json @@ -418,15 +418,20 @@ "description": "A widget to add a grid of buttons that execute shell commands", "additionalProperties": false, "properties": { + "center": { + "type": "boolean", + "description": "set buttons-grid halign to center", + "default": false + }, "column-min": { "type": "integer", "description": "minimum number of buttons per line", - "default": 4 + "default": 0 }, "column-max": { "type": "integer", "description": "maximum number of buttons per line", - "default": 7 + "default": 0 }, "actions": { "type": "array", diff --git a/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala b/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala index 0e7f65fa..e2d96865 100644 --- a/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala +++ b/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala @@ -15,27 +15,28 @@ namespace SwayNotificationCenter.Widgets { public ButtonsGrid (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { base (suffix, swaync_daemon, noti_daemon); - int column_min = 4; - int column_max = 7; + Gtk.FlowBox container = new Gtk.FlowBox (); + container.set_selection_mode (Gtk.SelectionMode.NONE); + pack_start (container, true, true, 0); Json.Object ? config = get_config (this); if (config != null) { Json.Array a = get_prop_array (config, "actions"); if (a != null) actions = parse_actions (a); + bool? center = get_prop (config, "center"); + if (center != null && center) + container.set_halign(Gtk.Align.CENTER); + int? col_min = get_prop (config, "column-min"); - if (col_min != null) column_min = col_min; + if (col_min != null && col_min > 0) + container.set_min_children_per_line(col_min); + int? col_max = get_prop (config, "column-max"); - if (col_max != null) column_max = col_max; + if (col_max != null && col_max > 0) + container.set_max_children_per_line(col_max); } - Gtk.FlowBox container = new Gtk.FlowBox (); - container.set_selection_mode (Gtk.SelectionMode.NONE); - container.set_halign(Gtk.Align.CENTER); - container.set_min_children_per_line(column_min); - container.set_max_children_per_line(column_max); - pack_start (container, true, true, 0); - // add action to container foreach (var act in actions) { switch (act.type) { From dd79944dda50b7818b1dd41003ec980fb3e0d59c Mon Sep 17 00:00:00 2001 From: giskard Date: Mon, 13 May 2024 16:46:49 +0800 Subject: [PATCH 3/4] man: sync config options for buttonGrid --- man/swaync.5.scd | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/man/swaync.5.scd b/man/swaync.5.scd index ada6f9b7..8932a390 100644 --- a/man/swaync.5.scd +++ b/man/swaync.5.scd @@ -135,7 +135,7 @@ config file to be able to detect config errors type: bool ++ default: true ++ description: Display notification timestamps relative to now e.g. \"26 minutes ago\". ++ - If false, a local iso8601-formatted absolute timestamp is displayed. + If false, a local iso8601-formatted absolute timestamp is displayed. *control-center-height* ++ type: integer ++ @@ -442,6 +442,21 @@ config file to be able to detect config errors type: object ++ css class: widget-buttons (access buttons with >flowbox>flowboxchild>button) ++ properties: ++ + center: ++ + type: bool ++ + optional: true ++ + default: false ++ + description: set buttons-grid halign to center ++ + column-min: ++ + type: integer ++ + optional: true ++ + default: 0 ++ + description: minimum number of buttons per line ++ + column-max: ++ + type: integer ++ + optional: true ++ + default: 0 ++ + description: maximum number of buttons per line ++ actions: ++ type: array ++ Default values: [] ++ From 101fda0da40767d630fea6dead611ed653ab1580 Mon Sep 17 00:00:00 2001 From: giskard Date: Fri, 12 Jul 2024 23:31:15 +0800 Subject: [PATCH 4/4] fmt: reformat buttonsGrid --- .../widgets/buttonsGrid/buttonsGrid.vala | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala b/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala index e2d96865..f997fbd2 100644 --- a/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala +++ b/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala @@ -22,25 +22,30 @@ namespace SwayNotificationCenter.Widgets { Json.Object ? config = get_config (this); if (config != null) { Json.Array a = get_prop_array (config, "actions"); - if (a != null) actions = parse_actions (a); + if (a != null) { + actions = parse_actions (a); + } - bool? center = get_prop (config, "center"); - if (center != null && center) - container.set_halign(Gtk.Align.CENTER); + bool ? center = get_prop (config, "center"); + if (center != null && center) { + container.set_halign (Gtk.Align.CENTER); + } - int? col_min = get_prop (config, "column-min"); - if (col_min != null && col_min > 0) - container.set_min_children_per_line(col_min); + int ? col_min = get_prop (config, "column-min"); + if (col_min != null && col_min > 0) { + container.set_min_children_per_line (col_min); + } - int? col_max = get_prop (config, "column-max"); - if (col_max != null && col_max > 0) - container.set_max_children_per_line(col_max); + int ? col_max = get_prop (config, "column-max"); + if (col_max != null && col_max > 0) { + container.set_max_children_per_line (col_max); + } } // add action to container foreach (var act in actions) { switch (act.type) { - case ButtonType.TOGGLE: + case ButtonType.TOGGLE : ToggleButton tb = new ToggleButton (act.label, act.command, act.update_command, act.active); container.insert (tb, -1); toggle_buttons.append (tb);