Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
ff9e03e9de | |||
f5d9405e04 | |||
d9a0d938b8 |
@@ -370,6 +370,16 @@ config file to be able to detect config errors
|
|||||||
type: string ++
|
type: string ++
|
||||||
default: "" ++
|
default: "" ++
|
||||||
description: "Command to be executed on click" ++
|
description: "Command to be executed on click" ++
|
||||||
|
type: ++
|
||||||
|
type: string ++
|
||||||
|
default: "normal" ++
|
||||||
|
description: Type of the button. ++
|
||||||
|
Toggle buttons receive the '.active' css class ++
|
||||||
|
enum: ["normal", "toggle"] ++
|
||||||
|
active: ++
|
||||||
|
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 actions containing a label and a command ++
|
||||||
description: A button to reveal a dropdown with action-buttons ++
|
description: A button to reveal a dropdown with action-buttons ++
|
||||||
buttons#<name>: ++
|
buttons#<name>: ++
|
||||||
@@ -395,6 +405,16 @@ config file to be able to detect config errors
|
|||||||
type: string ++
|
type: string ++
|
||||||
default: "" ++
|
default: "" ++
|
||||||
description: "Command to be executed on click" ++
|
description: "Command to be executed on click" ++
|
||||||
|
type: ++
|
||||||
|
type: string ++
|
||||||
|
default: "normal" ++
|
||||||
|
description: Type of the button ++
|
||||||
|
Toggle buttons receive the '.active' css class ++
|
||||||
|
enum: ["normal", "toggle"] ++
|
||||||
|
active: ++
|
||||||
|
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 actions containing a label and a command ++
|
||||||
description: A list of buttons to be displayed in the menu-button-bar ++
|
description: A list of buttons to be displayed in the menu-button-bar ++
|
||||||
*buttons-grid*++
|
*buttons-grid*++
|
||||||
@@ -415,6 +435,16 @@ config file to be able to detect config errors
|
|||||||
type: string ++
|
type: string ++
|
||||||
default: "" ++
|
default: "" ++
|
||||||
description: "Command to be executed on click" ++
|
description: "Command to be executed on click" ++
|
||||||
|
type: ++
|
||||||
|
type: string ++
|
||||||
|
default: "normal" ++
|
||||||
|
description: Type of the button ++
|
||||||
|
Toggle buttons receive the '.active' css class ++
|
||||||
|
enum: ["normal", "toggle"] ++
|
||||||
|
active: ++
|
||||||
|
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 actions containing a label and a command ++
|
||||||
description: A grid of buttons that execute shell commands ++
|
description: A grid of buttons that execute shell commands ++
|
||||||
#START pulse-audio
|
#START pulse-audio
|
||||||
|
@@ -422,6 +422,17 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Command to be executed on click",
|
"description": "Command to be executed on click",
|
||||||
"default": ""
|
"default": ""
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Type of the button; toggle buttons receive the .active css class",
|
||||||
|
"default": "normal",
|
||||||
|
"enum": ["normal", "toggle"]
|
||||||
|
},
|
||||||
|
"active": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Command to run to test if button should be active",
|
||||||
|
"default": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,16 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
public unowned SwayncDaemon swaync_daemon;
|
public unowned SwayncDaemon swaync_daemon;
|
||||||
public unowned NotiDaemon noti_daemon;
|
public unowned NotiDaemon noti_daemon;
|
||||||
|
|
||||||
|
public enum ButtonType {
|
||||||
|
TOGGLE,
|
||||||
|
NORMAL;
|
||||||
|
|
||||||
|
public static ButtonType parse (string value) {
|
||||||
|
if (value == "toggle") return ButtonType.TOGGLE;
|
||||||
|
return ButtonType.NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected BaseWidget (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
|
protected BaseWidget (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
|
||||||
this.suffix = suffix;
|
this.suffix = suffix;
|
||||||
this.key = widget_name + (suffix.length > 0 ? "#%s".printf (suffix) : "");
|
this.key = widget_name + (suffix.length > 0 ? "#%s".printf (suffix) : "");
|
||||||
@@ -93,15 +103,20 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
for (int i = 0; i < actions.get_length (); i++) {
|
for (int i = 0; i < actions.get_length (); i++) {
|
||||||
string label = actions.get_object_element (i).get_string_member_with_default ("label", "label");
|
string label = actions.get_object_element (i).get_string_member_with_default ("label", "label");
|
||||||
string command = actions.get_object_element (i).get_string_member_with_default ("command", "");
|
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);
|
||||||
|
string active = actions.get_object_element (i).get_string_member_with_default ("active", "");
|
||||||
res[i] = Action () {
|
res[i] = Action () {
|
||||||
label = label,
|
label = label,
|
||||||
command = command
|
command = command,
|
||||||
|
type = type,
|
||||||
|
active = active
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void execute_command (string cmd) {
|
public static void execute_command (string cmd) {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status;
|
int status;
|
||||||
if ((pid = fork ()) < 0) {
|
if ((pid = fork ()) < 0) {
|
||||||
|
@@ -10,6 +10,7 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Action[] actions;
|
Action[] actions;
|
||||||
|
ToggleButton[] toggle_buttons;
|
||||||
|
|
||||||
public ButtonsGrid (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
|
public ButtonsGrid (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
|
||||||
base (suffix, swaync_daemon, noti_daemon);
|
base (suffix, swaync_daemon, noti_daemon);
|
||||||
@@ -26,14 +27,28 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
|
|
||||||
// add action to container
|
// add action to container
|
||||||
foreach (var act in actions) {
|
foreach (var act in actions) {
|
||||||
Gtk.Button b = new Gtk.Button.with_label (act.label);
|
if (act.type == ButtonType.TOGGLE) {
|
||||||
|
ToggleButton toggle_button = new ToggleButton (act.label, act.command, act.active);
|
||||||
b.clicked.connect (() => execute_command (act.command));
|
toggle_buttons += toggle_button;
|
||||||
|
Gtk.ToggleButton tb = toggle_button;
|
||||||
container.insert (b, -1);
|
container.insert (tb, -1);
|
||||||
|
} else {
|
||||||
|
Gtk.Button b = new Gtk.Button.with_label (act.label);
|
||||||
|
b.clicked.connect (() => execute_command (act.command));
|
||||||
|
container.insert (b, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
show_all ();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,8 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
public struct Action {
|
public struct Action {
|
||||||
string ? label;
|
string ? label;
|
||||||
string ? command;
|
string ? command;
|
||||||
|
BaseWidget.ButtonType ? type;
|
||||||
|
string ? active;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Menubar : BaseWidget {
|
public class Menubar : BaseWidget {
|
||||||
@@ -69,16 +71,19 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
|
|
||||||
void add_menu (ref unowned ConfigObject ? obj) {
|
void add_menu (ref unowned ConfigObject ? obj) {
|
||||||
switch (obj.type) {
|
switch (obj.type) {
|
||||||
case MenuType.BUTTONS:
|
case MenuType.BUTTONS :
|
||||||
Gtk.Box container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
|
Gtk.Box container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
|
||||||
if (obj.name != null) container.get_style_context ().add_class (obj.name);
|
if (obj.name != null) container.get_style_context ().add_class (obj.name);
|
||||||
|
|
||||||
foreach (Action a in obj.actions) {
|
foreach (Action a in obj.actions) {
|
||||||
Gtk.Button b = new Gtk.Button.with_label (a.label);
|
if (a.type == ButtonType.TOGGLE) {
|
||||||
|
ToggleButton tb = new ToggleButton (a.label, a.command, a.active);
|
||||||
b.clicked.connect (() => execute_command (a.command));
|
container.add (tb);
|
||||||
|
} else {
|
||||||
container.add (b);
|
Gtk.Button b = new Gtk.Button.with_label (a.label);
|
||||||
|
b.clicked.connect (() => execute_command (a.command));
|
||||||
|
container.add (b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch (obj.position) {
|
switch (obj.position) {
|
||||||
case Position.LEFT:
|
case Position.LEFT:
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<object class="GtkImage" id="album_art">
|
<object class="GtkImage" id="album_art">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
<property name="pixel-size">96</property>
|
<property name="pixel-size">48</property>
|
||||||
<property name="icon-name">audio-x-generic-symbolic</property>
|
<property name="icon-name">audio-x-generic-symbolic</property>
|
||||||
<property name="use-fallback">True</property>
|
<property name="use-fallback">True</property>
|
||||||
<property name="icon_size">0</property>
|
<property name="icon_size">0</property>
|
||||||
|
56
src/controlCenter/widgets/shared/toggleButton.vala
Normal file
56
src/controlCenter/widgets/shared/toggleButton.vala
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
namespace SwayNotificationCenter.Widgets {
|
||||||
|
class ToggleButton : Gtk.ToggleButton {
|
||||||
|
|
||||||
|
private bool _active;
|
||||||
|
private string command;
|
||||||
|
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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -26,6 +26,7 @@ widget_sources = [
|
|||||||
# Helpers
|
# Helpers
|
||||||
'controlCenter/widgets/baseWidget.vala',
|
'controlCenter/widgets/baseWidget.vala',
|
||||||
'controlCenter/widgets/factory.vala',
|
'controlCenter/widgets/factory.vala',
|
||||||
|
'controlCenter/widgets/shared/toggleButton.vala',
|
||||||
# Widget: Title
|
# Widget: Title
|
||||||
'controlCenter/widgets/title/title.vala',
|
'controlCenter/widgets/title/title.vala',
|
||||||
# Widget: Dnd
|
# Widget: Dnd
|
||||||
|
@@ -282,6 +282,11 @@
|
|||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* style given to the active toggle button */
|
||||||
|
.widget-buttons-grid>flowbox>flowboxchild>.active {
|
||||||
|
background: @noti-bg-focus;
|
||||||
|
}
|
||||||
|
|
||||||
.widget-buttons-grid>flowbox>flowboxchild>button:hover {
|
.widget-buttons-grid>flowbox>flowboxchild>button:hover {
|
||||||
background: @noti-bg-hover;
|
background: @noti-bg-hover;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user