diff --git a/README.md b/README.md index d48cd12..186ea9a 100644 --- a/README.md +++ b/README.md @@ -247,8 +247,8 @@ window that'll allow you to see all of the CSS classes + other information. To add toggle buttons to your control center you can set the "type" in any acton to "toggle". The toggle button supports different commands depending on the state of the button and -an "update_command" to update the state in case of changes from outside swaync. The update_command -is called every time the control center is opened/closed. +an "update-command" to update the state in case of changes from outside swaync. The update-command +is called every time the control center is opened. The active toggle button also gains the css-class ".toggle:checked" `config.json` example: @@ -262,7 +262,7 @@ The active toggle button also gains the css-class ".toggle:checked" "type": "toggle", "active": true, "command": "sh -c '[[ $SWAYNC_TOGGLE_STATE == true ]] && nmcli radio wifi on || nmcli radio wifi off'", - "update_command": "sh -c '[[ $(nmcli radio wifi) == \"enabled\" ]] && echo true || echo false'" + "update-command": "sh -c '[[ $(nmcli radio wifi) == \"enabled\" ]] && echo true || echo false'" } ] } diff --git a/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala b/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala index 6328343..9b79503 100644 --- a/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala +++ b/src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala @@ -45,7 +45,7 @@ namespace SwayNotificationCenter.Widgets { } public override void on_cc_visibility_change (bool value) { - if (!value) { + if (value) { foreach (var tb in toggle_buttons) { tb.on_update.begin (); } diff --git a/src/controlCenter/widgets/menubar/menubar.vala b/src/controlCenter/widgets/menubar/menubar.vala index 36a4ce9..9de7885 100644 --- a/src/controlCenter/widgets/menubar/menubar.vala +++ b/src/controlCenter/widgets/menubar/menubar.vala @@ -121,9 +121,18 @@ namespace SwayNotificationCenter.Widgets { }); foreach (var a in obj.actions) { - Gtk.Button b = new Gtk.Button.with_label (a.label); - b.clicked.connect (() => execute_command.begin (a.command)); - menu.pack_start (b, true, true, 0); + switch (a.type) { + case ButtonType.TOGGLE: + ToggleButton tb = new ToggleButton (a.label, a.command, a.update_command, a.active); + menu.pack_start (tb, true, true, 0); + toggle_buttons.append (tb); + break; + default: + Gtk.Button b = new Gtk.Button.with_label (a.label); + b.clicked.connect (() => execute_command.begin (a.command)); + menu.pack_start (b, true, true, 0); + break; + } } switch (obj.position) { @@ -221,6 +230,7 @@ namespace SwayNotificationCenter.Widgets { foreach (var obj in menu_objects) { obj.revealer ?.set_reveal_child (false); } + } else { foreach (var tb in toggle_buttons) { tb.on_update.begin (); }