Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
4e6fd09c11 | |||
2595680e07 | |||
c02c844715 | |||
f5d9405e04 | |||
d9a0d938b8 |
@@ -370,6 +370,16 @@ config file to be able to detect config errors
|
||||
type: string ++
|
||||
default: "" ++
|
||||
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 button to reveal a dropdown with action-buttons ++
|
||||
buttons#<name>: ++
|
||||
@@ -395,6 +405,16 @@ config file to be able to detect config errors
|
||||
type: string ++
|
||||
default: "" ++
|
||||
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 buttons to be displayed in the menu-button-bar ++
|
||||
*buttons-grid*++
|
||||
@@ -415,6 +435,16 @@ config file to be able to detect config errors
|
||||
type: string ++
|
||||
default: "" ++
|
||||
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 grid of buttons that execute shell commands ++
|
||||
#START pulse-audio
|
||||
|
@@ -422,6 +422,17 @@
|
||||
"type": "string",
|
||||
"description": "Command to be executed on click",
|
||||
"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 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) {
|
||||
this.suffix = 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++) {
|
||||
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 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 () {
|
||||
label = label,
|
||||
command = command
|
||||
command = command,
|
||||
type = type,
|
||||
active = active
|
||||
};
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
protected void execute_command (string cmd) {
|
||||
public static void execute_command (string cmd) {
|
||||
pid_t pid;
|
||||
int status;
|
||||
if ((pid = fork ()) < 0) {
|
||||
|
@@ -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);
|
||||
@@ -26,14 +27,28 @@ namespace SwayNotificationCenter.Widgets {
|
||||
|
||||
// add action to container
|
||||
foreach (var act in actions) {
|
||||
Gtk.Button b = new Gtk.Button.with_label (act.label);
|
||||
|
||||
b.clicked.connect (() => execute_command (act.command));
|
||||
|
||||
container.insert (b, -1);
|
||||
if (act.type == ButtonType.TOGGLE) {
|
||||
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);
|
||||
b.clicked.connect (() => execute_command (act.command));
|
||||
container.insert (b, -1);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
string ? label;
|
||||
string ? command;
|
||||
BaseWidget.ButtonType ? type;
|
||||
string ? active;
|
||||
}
|
||||
|
||||
public class Menubar : BaseWidget {
|
||||
@@ -69,16 +71,19 @@ namespace SwayNotificationCenter.Widgets {
|
||||
|
||||
void add_menu (ref unowned ConfigObject ? obj) {
|
||||
switch (obj.type) {
|
||||
case MenuType.BUTTONS:
|
||||
case MenuType.BUTTONS :
|
||||
Gtk.Box container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
|
||||
if (obj.name != null) container.get_style_context ().add_class (obj.name);
|
||||
|
||||
foreach (Action a in obj.actions) {
|
||||
Gtk.Button b = new Gtk.Button.with_label (a.label);
|
||||
|
||||
b.clicked.connect (() => execute_command (a.command));
|
||||
|
||||
container.add (b);
|
||||
if (a.type == ButtonType.TOGGLE) {
|
||||
ToggleButton tb = new ToggleButton (a.label, a.command, a.active);
|
||||
container.add (tb);
|
||||
} else {
|
||||
Gtk.Button b = new Gtk.Button.with_label (a.label);
|
||||
b.clicked.connect (() => execute_command (a.command));
|
||||
container.add (b);
|
||||
}
|
||||
}
|
||||
switch (obj.position) {
|
||||
case Position.LEFT:
|
||||
|
@@ -19,8 +19,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixel-size">96</property>
|
||||
<property name="icon-name">audio-x-generic-symbolic</property>
|
||||
<property name="use-fallback">True</property>
|
||||
<property name="use-fallback">False</property>
|
||||
<property name="icon_size">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
|
@@ -272,18 +272,6 @@ namespace SwayNotificationCenter.Widgets.Mpris {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Get the app icon
|
||||
Icon ? icon = null;
|
||||
if (desktop_entry is DesktopAppInfo) {
|
||||
icon = desktop_entry.get_icon ();
|
||||
}
|
||||
if (icon != null) {
|
||||
album_art.set_from_gicon (icon, mpris_config.image_size);
|
||||
} else {
|
||||
// Default icon
|
||||
album_art.set_from_icon_name ("audio-x-generic-symbolic",
|
||||
mpris_config.image_size);
|
||||
}
|
||||
}
|
||||
|
||||
private void update_button_shuffle (HashTable<string, Variant> metadata) {
|
||||
|
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
|
||||
'controlCenter/widgets/baseWidget.vala',
|
||||
'controlCenter/widgets/factory.vala',
|
||||
'controlCenter/widgets/shared/toggleButton.vala',
|
||||
# Widget: Title
|
||||
'controlCenter/widgets/title/title.vala',
|
||||
# Widget: Dnd
|
||||
|
@@ -282,6 +282,11 @@
|
||||
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 {
|
||||
background: @noti-bg-hover;
|
||||
}
|
||||
|
Reference in New Issue
Block a user