Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add settings to center buttons-grid #426

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion man/swaync.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++
Expand Down Expand Up @@ -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: [] ++
Expand Down
15 changes: 15 additions & 0 deletions src/configSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,21 @@
"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": 0
},
"column-max": {
"type": "integer",
"description": "maximum number of buttons per line",
"default": 0
},
"actions": {
"type": "array",
"description": "A list of actions containing a label and a command",
Expand Down
29 changes: 23 additions & 6 deletions src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,37 @@ namespace SwayNotificationCenter.Widgets {
public ButtonsGrid (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
base (suffix, swaync_daemon, noti_daemon);

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);
}
if (a != null) {
actions = parse_actions (a);
}

Gtk.FlowBox container = new Gtk.FlowBox ();
container.set_selection_mode (Gtk.SelectionMode.NONE);
pack_start (container, true, true, 0);
bool ? center = get_prop<bool> (config, "center");
if (center != null && center) {
container.set_halign (Gtk.Align.CENTER);
}

int ? col_min = get_prop<int> (config, "column-min");
if (col_min != null && col_min > 0) {
container.set_min_children_per_line (col_min);
}

int ? col_max = get_prop<int> (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);
Expand Down