Skip to content

Commit

Permalink
MainView: use Gtk.Dropdown for power button behavior (#248)
Browse files Browse the repository at this point in the history
* MainView: use Gtk.Dropdown for power button behavior

* Remove valign

* revert layout changes

---------

Co-authored-by: Leo <lenemter@gmail.com>
Co-authored-by: Jeremy Wootten <jeremywootten@gmail.com>
  • Loading branch information
3 people authored Feb 13, 2024
1 parent c1dc35b commit e6becbe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 76 deletions.
1 change: 0 additions & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ src/Interfaces.vala
src/Widgets/BatteryBox.vala
src/Widgets/TimeoutComboBox.vala
src/Widgets/LidCloseActionComboBox.vala
src/Widgets/ActionComboBox.vala
src/Widgets/PowerModeButton.vala
39 changes: 32 additions & 7 deletions src/MainView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Power.MainView : Switchboard.SettingsPage {
private const string SETTINGS_DAEMON_NAME = "org.gnome.SettingsDaemon.Power";
private const string SETTINGS_DAEMON_PATH = "/org/gnome/SettingsDaemon/Power";

private Gtk.DropDown powerbutton_dropdown;
private Gtk.Scale scale;
private PowerSettings screen;

Expand Down Expand Up @@ -157,17 +158,25 @@ public class Power.MainView : Switchboard.SettingsPage {

var screen_timeout = new TimeoutComboBox (new GLib.Settings ("org.gnome.desktop.session"), "idle-delay");

var power_label = new Gtk.Label (_("Power button:")) {
halign = Gtk.Align.END,
xalign = 1
// FIXME: Virtual machines can only shutdown or do nothing. Tablets always suspend.
powerbutton_dropdown = new Gtk.DropDown.from_strings ({
_("Do nothing"),
_("Suspend"),
_("Ask to shutdown")
}) {
hexpand = true
};

var power_combobox = new ActionComboBox ("power-button-action");
var powerbutton_label = new Gtk.Label (_("Power Button Behavior")) {
halign = Gtk.Align.END,
xalign = 1,
mnemonic_widget = powerbutton_dropdown
};

main_grid.attach (screen_timeout_label, 0, 4);
main_grid.attach (screen_timeout, 1, 4);
main_grid.attach (power_label, 0, 5);
main_grid.attach (power_combobox, 1, 5);
main_grid.attach (powerbutton_label, 0, 5);
main_grid.attach (powerbutton_dropdown, 1, 5);

var sleep_timeout_label = new Gtk.Label (_("Suspend when inactive for:")) {
xalign = 1
Expand Down Expand Up @@ -303,10 +312,21 @@ public class Power.MainView : Switchboard.SettingsPage {

label_size.add_widget (sleep_timeout_label);
label_size.add_widget (screen_timeout_label);
label_size.add_widget (power_label);
label_size.add_widget (powerbutton_label);

// hide stack switcher if we only have ac line
stack_switcher.visible = stack.observe_children ().get_n_items () > 1;

update_powerbutton_dropdown ();
settings.changed["power-button-action"].connect (update_powerbutton_dropdown);

powerbutton_dropdown.notify["selected"].connect (() => {
int[] map = {0, 1, 3};
settings.set_enum (
"power-button-action",
map[powerbutton_dropdown.selected]
);
});
}

public static Polkit.Permission? get_permission () {
Expand Down Expand Up @@ -433,4 +453,9 @@ public class Power.MainView : Switchboard.SettingsPage {

return false;
}

private void update_powerbutton_dropdown () {
int[] map = {0, 1, 1, 2};
powerbutton_dropdown.selected = map [settings.get_enum ("power-button-action")];
}
}
2 changes: 1 addition & 1 deletion src/Plug.vala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace Power {
public override async Gee.TreeMap<string, string> search (string search) {
var search_results = new Gee.TreeMap<string, string> ((GLib.CompareDataFunc<string>)strcmp, (Gee.EqualDataFunc<string>)str_equal);
search_results.set ("%s%s".printf (display_name, _("Suspend button")), "");
search_results.set ("%s%s".printf (display_name, _("Power button")), "");
search_results.set ("%s%s".printf (display_name, _("Power Button Behavior")), "");
search_results.set ("%s%s".printf (display_name, _("Display inactive")), "");
search_results.set ("%s%s".printf (display_name, _("Dim display")), "");
search_results.set ("%s%s".printf (display_name, _("Lid close")), "");
Expand Down
66 changes: 0 additions & 66 deletions src/Widgets/ActionComboBox.vala

This file was deleted.

1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ plug_files = files(
'Widgets/BatteryBox.vala',
'Widgets/TimeoutComboBox.vala',
'Widgets/LidCloseActionComboBox.vala',
'Widgets/ActionComboBox.vala',
'Widgets/PowerModeButton.vala',
)

Expand Down

0 comments on commit e6becbe

Please sign in to comment.