-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add toggle button * Toggle button documentation * Fix issues * Add env variable for toggle button * Add state update command for toggle buttons * Fix Uncrustify * Update README
- Loading branch information
1 parent
69e92da
commit b7631c7
Showing
11 changed files
with
241 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace SwayNotificationCenter.Widgets { | ||
class ToggleButton : Gtk.ToggleButton { | ||
|
||
private string command; | ||
private string update_command; | ||
|
||
public ToggleButton (string label, string command, string update_command, bool active) { | ||
this.command = command; | ||
this.update_command = update_command; | ||
this.label = label; | ||
|
||
if (active) { | ||
this.active = true; | ||
} | ||
|
||
this.toggled.connect (on_toggle); | ||
} | ||
|
||
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); | ||
} | ||
|
||
public async void on_update () { | ||
if (update_command == "") return; | ||
string msg = ""; | ||
string[] env_additions = { "SWAYNC_TOGGLE_STATE=" + this.active.to_string () }; | ||
yield Functions.execute_command (this.update_command, env_additions, out msg); | ||
try { | ||
// remove trailing whitespaces | ||
Regex regex = new Regex ("\\s+$"); | ||
string res = regex.replace (msg, msg.length, 0, ""); | ||
if (res.up () == "TRUE") { | ||
this.active = true; | ||
} else { | ||
this.active = false; | ||
} | ||
} catch (RegexError e) { | ||
stderr.printf ("RegexError: %s\n", e.message); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.