Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/PopoverWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,40 @@ 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 screen_reader_action = new SimpleAction.stateful (
"screen-reader",
null,
applications_settings.get_boolean ("screen-reader-enabled")
);

screen_reader_action.activate.connect (() => {
applications_settings.set_boolean ("screen-reader-enabled", !applications_settings.get_boolean ("screen-reader-enabled"));
});

applications_settings.changed["screen-reader-enabled"].connect (() => {
screen_reader_action.set_state (applications_settings.get_boolean ("screen-reader-enabled"));
});

var screen_keyboard_action = new SimpleAction.stateful (
"screen-keyboard",
null,
applications_settings.get_boolean ("screen-keyboard-enabled")
);

screen_keyboard_action.activate.connect (() => {
applications_settings.set_boolean ("screen-keyboard-enabled", !applications_settings.get_boolean ("screen-keyboard-enabled"));
});

applications_settings.changed["screen-keyboard-enabled"].connect (() => {
screen_keyboard_action.set_state (applications_settings.get_boolean ("screen-keyboard-enabled"));
});

var action_group = new SimpleActionGroup ();
action_group.add_action (screen_reader_action);
action_group.add_action (screen_keyboard_action);

insert_action_group ("quick-settings", action_group);

var glib_settings = new Settings ("io.elementary.desktop.quick-settings");

Expand Down
29 changes: 21 additions & 8 deletions src/Widgets/DarkModeToggle.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,34 @@ public class QuickSettings.DarkModeToggle: SettingsToggle {
}

construct {
action_name = "quick-settings.dark-mode";
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);
});
}
}
64 changes: 38 additions & 26 deletions src/Widgets/PreventSleepToggle.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
icon: new ThemedIcon ("system-suspend-symbolic"),
Expand All @@ -15,34 +17,44 @@ public class QuickSettings.PreventSleepToggle: SettingsToggle {
}

construct {
action_name = "quick-settings.inhibit";
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 = new ThemedIcon ("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 = new ThemedIcon ("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 = new ThemedIcon ("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 = new ThemedIcon ("system-suspend-symbolic");

suspend_cookie = 0;
idle_cookie = 0;
}
}
}
32 changes: 25 additions & 7 deletions src/Widgets/RotationToggle.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,36 @@ public class QuickSettings.RotationToggle: SettingsToggle {
}

construct {
action_name = "quick-settings.rotation-lock";
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");

bind_property ("active", this, "icon", SYNC_CREATE, (binding, srcval, ref targetval) => {
if ((bool) srcval) {
targetval = new ThemedIcon ("quick-settings-rotation-locked-symbolic");
var rotation_lock_action = new SimpleAction.stateful (
"rotation-lock",
null,
settings.get_boolean ("orientation-lock")
);

rotation_lock_action.activate.connect (() => {
settings.set_boolean ("orientation-lock", !settings.get_boolean ("orientation-lock"));
});

settings.changed["orientation-lock"].connect (() => {
rotation_lock_action.set_state (settings.get_boolean ("orientation-lock"));
});

rotation_lock_action.change_state.connect ((value) => {
if (value.get_boolean ()) {
icon = new ThemedIcon ("quick-settings-rotation-locked-symbolic");
} else {
targetval = new ThemedIcon ("quick-settings-rotation-allowed-symbolic");
icon = new ThemedIcon ("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);
});
}
}
5 changes: 2 additions & 3 deletions src/Widgets/SettingsToggle.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

public class QuickSettings.SettingsToggle : Gtk.FlowBoxChild {
public bool active { get; set; }
public string action_name { get; set; }
public Icon icon { get; construct set; }
public string label { get; construct; }
public string settings_uri { get; set; default = "settings://"; }
Expand Down Expand Up @@ -42,8 +42,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", image, "gicon");

middle_click_gesture = new Gtk.GestureMultiPress (button) {
Expand Down