diff --git a/src/PopoverWidget.vala b/src/PopoverWidget.vala index 77bfa65..817afed 100644 --- a/src/PopoverWidget.vala +++ b/src/PopoverWidget.vala @@ -27,6 +27,7 @@ public class QuickSettings.PopoverWidget : Gtk.Box { var screen_reader = new SettingsToggle ( _("Screen Reader") ) { + action_name = "quick-settings.screen-reader-enabled", icon_name = "orca-symbolic", settings_uri = "settings://sound" }; @@ -34,6 +35,7 @@ public class QuickSettings.PopoverWidget : Gtk.Box { var onscreen_keyboard = new SettingsToggle ( _("Onscreen Keyboard") ) { + action_name = "quick-settings.screen-keyboard-enabled", icon_name = "input-keyboard-symbolic", settings_uri = "settings://input/keyboard/behavior" }; @@ -117,8 +119,12 @@ public class QuickSettings.PopoverWidget : Gtk.Box { }); var applications_settings = new Settings ("org.gnome.desktop.a11y.applications"); - applications_settings.bind ("screen-keyboard-enabled", onscreen_keyboard, "active", DEFAULT); - applications_settings.bind ("screen-reader-enabled", screen_reader, "active", DEFAULT); + + var action_group = new SimpleActionGroup (); + action_group.add_action (applications_settings.create_action ("screen-reader-enabled")); + action_group.add_action (applications_settings.create_action ("screen-keyboard-enabled")); + + insert_action_group ("quick-settings", action_group); var glib_settings = new Settings ("io.elementary.desktop.quick-settings"); diff --git a/src/Widgets/DarkModeToggle.vala b/src/Widgets/DarkModeToggle.vala index 68c311e..d977de1 100644 --- a/src/Widgets/DarkModeToggle.vala +++ b/src/Widgets/DarkModeToggle.vala @@ -11,22 +11,35 @@ public class QuickSettings.DarkModeToggle: SettingsToggle { } construct { + action_name = "quick-settings.dark-mode"; icon_name = "dark-mode-symbolic"; settings_uri = "settings://desktop/appearance"; var settings = new GLib.Settings ("io.elementary.settings-daemon.prefers-color-scheme"); - active = settings.get_enum ("color-scheme") == Granite.Settings.ColorScheme.DARK; - settings.changed["color-scheme"].connect (() => { - active = settings.get_enum ("color-scheme") == Granite.Settings.ColorScheme.DARK; - }); + var dark_mode_action = new SimpleAction.stateful ( + "dark-mode", + null, + new Variant.boolean (settings.get_enum ("color-scheme") == Granite.Settings.ColorScheme.DARK) + ); - notify["active"].connect (() => { - if (active) { - settings.set_enum ("color-scheme", Granite.Settings.ColorScheme.DARK); - } else { + dark_mode_action.activate.connect (() => { + if (settings.get_enum ("color-scheme") == Granite.Settings.ColorScheme.DARK) { settings.set_enum ("color-scheme", Granite.Settings.ColorScheme.NO_PREFERENCE); + } else { + settings.set_enum ("color-scheme", Granite.Settings.ColorScheme.DARK); } }); + + settings.changed["color-scheme"].connect (() => { + dark_mode_action.set_state ( + new Variant.boolean (settings.get_enum ("color-scheme") == Granite.Settings.ColorScheme.DARK) + ); + }); + + map.connect (() => { + var action_group = (SimpleActionGroup) get_action_group ("quick-settings"); + action_group.add_action (dark_mode_action); + }); } } diff --git a/src/Widgets/PreventSleepToggle.vala b/src/Widgets/PreventSleepToggle.vala index 2298e5e..a56b039 100644 --- a/src/Widgets/PreventSleepToggle.vala +++ b/src/Widgets/PreventSleepToggle.vala @@ -7,6 +7,8 @@ public class QuickSettings.PreventSleepToggle: SettingsToggle { private uint suspend_cookie = 0; private uint idle_cookie = 0; + private SimpleAction inhibit_action; + public PreventSleepToggle () { Object ( label: _("Prevent Sleep") @@ -14,35 +16,45 @@ public class QuickSettings.PreventSleepToggle: SettingsToggle { } construct { + action_name = "quick-settings.inhibit"; icon_name = "system-suspend-symbolic"; settings_uri = "settings://power"; - notify["active"].connect ((obj, pspec) => { - var _prevent_sleep_toggle = (SettingsToggle) obj; - unowned var application = (Gtk.Application) GLib.Application.get_default (); - - if (_prevent_sleep_toggle.active && suspend_cookie == 0 && idle_cookie == 0) { - suspend_cookie = application.inhibit ( - (Gtk.Window) get_toplevel (), - Gtk.ApplicationInhibitFlags.SUSPEND, - "Prevent session from suspending" - ); - idle_cookie = application.inhibit ( - (Gtk.Window) get_toplevel (), - Gtk.ApplicationInhibitFlags.IDLE, - "Prevent session from idle" - ); - - icon_name = "system-suspend-disabled-symbolic"; - } else if (!_prevent_sleep_toggle.active && suspend_cookie > 0 && idle_cookie > 0) { - application.uninhibit (suspend_cookie); - application.uninhibit (idle_cookie); - - icon_name = "system-suspend-symbolic"; - - suspend_cookie = 0; - idle_cookie = 0; - } + inhibit_action = new SimpleAction.stateful ("inhibit", null, new Variant.boolean (suspend_cookie > 0 && idle_cookie > 0)); + inhibit_action.activate.connect (toggle_inibit); + + map.connect (() => { + var action_group = (SimpleActionGroup) get_action_group ("quick-settings"); + action_group.add_action (inhibit_action); }); } + + private void toggle_inibit () { + unowned var application = (Gtk.Application) GLib.Application.get_default (); + + if (suspend_cookie == 0 && idle_cookie == 0) { + suspend_cookie = application.inhibit ( + (Gtk.Window) get_toplevel (), + Gtk.ApplicationInhibitFlags.SUSPEND, + "Prevent session from suspending" + ); + idle_cookie = application.inhibit ( + (Gtk.Window) get_toplevel (), + Gtk.ApplicationInhibitFlags.IDLE, + "Prevent session from idle" + ); + + inhibit_action.set_state (new Variant.boolean (true)); + icon_name = "system-suspend-disabled-symbolic"; + } else if (suspend_cookie > 0 && idle_cookie > 0) { + application.uninhibit (suspend_cookie); + application.uninhibit (idle_cookie); + + inhibit_action.set_state (new Variant.boolean (false)); + icon_name = "system-suspend-symbolic"; + + suspend_cookie = 0; + idle_cookie = 0; + } + } } diff --git a/src/Widgets/RotationToggle.vala b/src/Widgets/RotationToggle.vala index 8aa3133..e86d3b9 100644 --- a/src/Widgets/RotationToggle.vala +++ b/src/Widgets/RotationToggle.vala @@ -11,19 +11,24 @@ public class QuickSettings.RotationToggle: SettingsToggle { } construct { + action_name = "quick-settings.orientation-lock"; icon_name = "quick-settings-rotation-locked-symbolic"; settings_uri = "settings://display"; - var touchscreen_settings = new Settings ("org.gnome.settings-daemon.peripherals.touchscreen"); - touchscreen_settings.bind ("orientation-lock", this, "active", DEFAULT); + var settings = new Settings ("org.gnome.settings-daemon.peripherals.touchscreen"); + var rotation_lock_action = settings.create_action ("orientation-lock"); - bind_property ("active", this, "icon-name", SYNC_CREATE, (binding, srcval, ref targetval) => { - if ((bool) srcval) { - targetval = "quick-settings-rotation-locked-symbolic"; + rotation_lock_action.notify["state"].connect (() => { + if (rotation_lock_action.state.get_boolean ()) { + icon_name = "quick-settings-rotation-locked-symbolic"; } else { - targetval = "quick-settings-rotation-allowed-symbolic"; + icon_name = "quick-settings-rotation-allowed-symbolic"; } - return true; + }); + + map.connect (() => { + var action_group = (SimpleActionGroup) get_action_group ("quick-settings"); + action_group.add_action (rotation_lock_action); }); } } diff --git a/src/Widgets/SettingsToggle.vala b/src/Widgets/SettingsToggle.vala index 4a38e47..047995f 100644 --- a/src/Widgets/SettingsToggle.vala +++ b/src/Widgets/SettingsToggle.vala @@ -4,7 +4,7 @@ */ public class QuickSettings.SettingsToggle : Gtk.FlowBoxChild { - public bool active { get; set; } + public string action_name { get; set; } public string icon_name { get; set; } public string label { get; construct; } public string settings_uri { get; set; default = "settings://"; } @@ -41,8 +41,7 @@ public class QuickSettings.SettingsToggle : Gtk.FlowBoxChild { can_focus = false; child = box; - button.bind_property ("active", this, "active", SYNC_CREATE | BIDIRECTIONAL); - + bind_property ("action-name", button, "action-name"); bind_property ("icon-name", image, "icon-name"); middle_click_gesture = new Gtk.GestureMultiPress (button) {