toggleButton: change "active" field to be a command
This commit is contained in:
@@ -377,9 +377,9 @@ config file to be able to detect config errors
|
||||
Toggle buttons receive the '.active' css class ++
|
||||
enum: ["normal", "toggle"] ++
|
||||
active: ++
|
||||
type: bool ++
|
||||
default: false ++
|
||||
description: Wether the toggle button is active as default or not ++
|
||||
type: string ++
|
||||
default: "" ++
|
||||
description: Command to run to test if button should be active (return code 0) or not ++
|
||||
description: A list of actions containing a label and a command ++
|
||||
description: A button to reveal a dropdown with action-buttons ++
|
||||
buttons#<name>: ++
|
||||
@@ -412,9 +412,9 @@ config file to be able to detect config errors
|
||||
Toggle buttons receive the '.active' css class ++
|
||||
enum: ["normal", "toggle"] ++
|
||||
active: ++
|
||||
type: bool ++
|
||||
default: false ++
|
||||
description: Wether the toggle button is active as default or not ++
|
||||
type: string ++
|
||||
default: "" ++
|
||||
description: Command to run to test if button should be active (return code 0) or not ++
|
||||
description: A list of actions containing a label and a command ++
|
||||
description: A list of buttons to be displayed in the menu-button-bar ++
|
||||
*buttons-grid*++
|
||||
@@ -442,9 +442,9 @@ config file to be able to detect config errors
|
||||
Toggle buttons receive the '.active' css class ++
|
||||
enum: ["normal", "toggle"] ++
|
||||
active: ++
|
||||
type: bool ++
|
||||
default: false ++
|
||||
description: Wether the toggle button is active as default or not ++
|
||||
type: string ++
|
||||
default: "" ++
|
||||
description: Command to run to test if button should be active (return code 0) or not ++
|
||||
description: A list of actions containing a label and a command ++
|
||||
description: A grid of buttons that execute shell commands ++
|
||||
#START pulse-audio
|
||||
|
@@ -430,9 +430,9 @@
|
||||
"enum": ["normal", "toggle"]
|
||||
},
|
||||
"active": {
|
||||
"type": "bool",
|
||||
"description": "Wether the toggle button is active as default or not",
|
||||
"default": false
|
||||
"type": "string",
|
||||
"description": "Command to run to test if button should be active",
|
||||
"default": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -105,7 +105,7 @@ namespace SwayNotificationCenter.Widgets {
|
||||
string command = actions.get_object_element (i).get_string_member_with_default ("command", "");
|
||||
string t = actions.get_object_element (i).get_string_member_with_default ("type", "normal");
|
||||
ButtonType type = ButtonType.parse (t);
|
||||
bool active = actions.get_object_element (i).get_boolean_member_with_default ("active", false);
|
||||
string active = actions.get_object_element (i).get_string_member_with_default ("active", "");
|
||||
res[i] = Action () {
|
||||
label = label,
|
||||
command = command,
|
||||
|
@@ -10,6 +10,7 @@ namespace SwayNotificationCenter.Widgets {
|
||||
}
|
||||
|
||||
Action[] actions;
|
||||
ToggleButton[] toggle_buttons;
|
||||
|
||||
public ButtonsGrid (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
|
||||
base (suffix, swaync_daemon, noti_daemon);
|
||||
@@ -27,7 +28,9 @@ namespace SwayNotificationCenter.Widgets {
|
||||
// add action to container
|
||||
foreach (var act in actions) {
|
||||
if (act.type == ButtonType.TOGGLE) {
|
||||
Gtk.ToggleButton tb = new ToggleButton (act.label, act.command, act.active);
|
||||
ToggleButton toggle_button = new ToggleButton (act.label, act.command, act.active);
|
||||
toggle_buttons += toggle_button;
|
||||
Gtk.ToggleButton tb = toggle_button;
|
||||
container.insert (tb, -1);
|
||||
} else {
|
||||
Gtk.Button b = new Gtk.Button.with_label (act.label);
|
||||
@@ -38,5 +41,14 @@ namespace SwayNotificationCenter.Widgets {
|
||||
|
||||
show_all ();
|
||||
}
|
||||
|
||||
public override void on_cc_visibility_change (bool val) {
|
||||
debug("buttonsGrid:on_cc_visibility_change %i", (int)val);
|
||||
if (val) {
|
||||
foreach (var tb in toggle_buttons) {
|
||||
tb.compute_state();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ namespace SwayNotificationCenter.Widgets {
|
||||
string ? label;
|
||||
string ? command;
|
||||
BaseWidget.ButtonType ? type;
|
||||
bool ? active;
|
||||
string ? active;
|
||||
}
|
||||
|
||||
public class Menubar : BaseWidget {
|
||||
|
@@ -1,25 +1,56 @@
|
||||
namespace SwayNotificationCenter.Widgets {
|
||||
class ToggleButton : Gtk.ToggleButton {
|
||||
|
||||
private bool _active;
|
||||
private string command;
|
||||
public ToggleButton (string label, string command, bool active) {
|
||||
private string active_test;
|
||||
public ToggleButton (string label, string command, string active) {
|
||||
this.command = command;
|
||||
this.active_test = active;
|
||||
this.label = label;
|
||||
this._active = false;
|
||||
|
||||
if (active) {
|
||||
this.get_style_context ().add_class ("active");
|
||||
this.active = true;
|
||||
}
|
||||
debug("ToggleButton created with test: %s", active);
|
||||
|
||||
this.toggled.connect (on_toggle);
|
||||
}
|
||||
|
||||
public void compute_state() {
|
||||
debug("compute_state");
|
||||
this.set_active(this.check_should_be_active());
|
||||
}
|
||||
|
||||
private void set_active(bool active) {
|
||||
debug("set_active: %i", (int)active);
|
||||
if (active) {
|
||||
this.get_style_context ().add_class ("active");
|
||||
this._active = true;
|
||||
} else {
|
||||
this.get_style_context ().remove_class ("active");
|
||||
this._active = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void on_toggle (Gtk.ToggleButton tb) {
|
||||
debug("on_toggle");
|
||||
this.set_active(!this._active);
|
||||
BaseWidget.execute_command (command);
|
||||
if (tb.active)
|
||||
tb.get_style_context ().add_class ("active");
|
||||
else
|
||||
tb.get_style_context ().remove_class ("active");
|
||||
}
|
||||
|
||||
private bool check_should_be_active () {
|
||||
string stdout;
|
||||
string stderr;
|
||||
int end_status;
|
||||
Process.spawn_sync (
|
||||
"/",
|
||||
this.active_test.split (" "),
|
||||
Environ.get(),
|
||||
SpawnFlags.SEARCH_PATH,
|
||||
null,
|
||||
out stdout,
|
||||
out stderr,
|
||||
out end_status);
|
||||
return end_status == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user