Skip to content

Commit

Permalink
Add env variable for toggle button
Browse files Browse the repository at this point in the history
  • Loading branch information
JannisPetschenka committed Oct 11, 2023
1 parent 7b8ae81 commit ceb2248
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
8 changes: 6 additions & 2 deletions man/swaync.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ config file to be able to detect config errors
type: string ++
default: "normal" ++
description: Type of the button ++
Toggle buttons receive the '.active' css class ++
Toggle buttons receive the '.active' css class and an env ++
variable "SWAYNC_TOGGLE_STATE" is set. See example usage in the ++
default config.json ++
enum: ["normal", "toggle"] ++
active: ++
type: bool ++
Expand Down Expand Up @@ -446,7 +448,9 @@ config file to be able to detect config errors
type: string ++
default: "normal" ++
description: Type of the button ++
Toggle buttons receive the '.active' css class ++
Toggle buttons receive the '.active' css class and an env ++
variable "SWAYNC_TOGGLE_STATE" is set. See example usage in the ++
default config.json ++
enum: ["normal", "toggle"] ++
active: ++
type: bool ++
Expand Down
10 changes: 10 additions & 0 deletions src/config.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
"mpris": {
"image-size": 96,
"image-radius": 12
},
"buttons-grid": {
"actions": [
{
"label": "直",
"type": "toggle",
"active": true,
"command": "sh -c '[[ $SWAYNC_TOGGLE_STATE == true ]] && nmcli radio wifi on || nmcli radio wifi off'"
}
]
}
}
}
2 changes: 1 addition & 1 deletion src/configSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
},
"type": {
"type": "string",
"description": "Type of the button; toggle buttons receive the .active css class",
"description": "Type of the button; toggle buttons receive the .active css class and an env variable 'SWAYNC_TOGGLE_STATE' is set. See example in the default config.json",
"default": "normal",
"enum": ["normal", "toggle"]
},
Expand Down
6 changes: 4 additions & 2 deletions src/controlCenter/widgets/shared/toggleButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace SwayNotificationCenter.Widgets {
this.toggled.connect (on_toggle);
}

private void on_toggle (Gtk.ToggleButton tb) {
BaseWidget.execute_command (command);
private async void on_toggle () {
string msg = "";
string[] env_additions = { "SWAYNC_TOGGLE_STATE="+this.active.to_string () };
yield Functions.execute_command (this.command, env_additions, out msg);
}
}
}

0 comments on commit ceb2248

Please sign in to comment.