From 07af37a87917571f421c4eb2d53cf37376829e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 13 Feb 2024 11:35:59 -0800 Subject: [PATCH 1/3] MainView: justify layout, space between sections --- src/MainView.vala | 159 ++++++++++++++---------- src/Widgets/LidCloseActionComboBox.vala | 5 +- src/Widgets/TimeoutComboBox.vala | 4 +- 3 files changed, 92 insertions(+), 76 deletions(-) diff --git a/src/MainView.vala b/src/MainView.vala index 8d1e379d..759f84f7 100644 --- a/src/MainView.vala +++ b/src/MainView.vala @@ -72,23 +72,24 @@ public class Power.MainView : Switchboard.SettingsPage { warning ("Failed to get settings daemon for brightness setting"); } - var main_grid = new Gtk.Grid () { - column_spacing = 12, - row_spacing = 12 - }; + var box = new Gtk.Box (VERTICAL, 24); - if (backlight_detect ()) { - var brightness_label = new Gtk.Label (_("Display brightness:")) { - halign = Gtk.Align.END, - xalign = 1 + if (power_manager.has_battery ()) { + var battery_box = new BatteryBox () { + margin_bottom = 12 }; - var als_label = new Gtk.Label (_("Automatically adjust brightness:")) { - xalign = 1 - }; + box.append (battery_box); + } + if (backlight_detect ()) { var als_switch = new Gtk.Switch () { - halign = Gtk.Align.START + halign = END + }; + + var als_label = new Gtk.Label (_("Automatically Adjust Brightness")) { + mnemonic_widget = als_switch, + xalign = 0 }; settings.bind ("ambient-enabled", als_switch, "active", SettingsBindFlags.DEFAULT); @@ -118,45 +119,82 @@ public class Power.MainView : Switchboard.SettingsPage { scale.value_changed.connect (on_scale_value_changed); ((DBusProxy)screen).g_properties_changed.connect (on_screen_properties_changed); - main_grid.attach (brightness_label, 0, 1); - main_grid.attach (scale, 1, 1); - main_grid.attach (als_label, 0, 2); - main_grid.attach (als_switch, 1, 2); + var brightness_label = new Gtk.Label (_("Display Brightness")) { + mnemonic_widget = scale, + xalign = 0 + }; + + var brightness_grid = new Gtk.Grid () { + column_spacing = 12, + row_spacing = 12 + }; + brightness_grid.attach (brightness_label, 0, 0); + brightness_grid.attach (scale, 1, 0); + brightness_grid.attach (als_label, 0, 1); + brightness_grid.attach (als_switch, 1, 1); + + box.append (brightness_grid); label_size.add_widget (brightness_label); label_size.add_widget (als_label); } if (power_manager.has_lid ()) { - var lid_closed_label = new Gtk.Label (_("When lid is closed:")) { - halign = Gtk.Align.END, - xalign = 1 + var infobar_label = new Gtk.Label (_("Some changes will not take effect until you restart this computer")); + + var infobar = new Gtk.InfoBar () { + message_type = WARNING, + revealed = false + }; + infobar.add_child (infobar_label); + infobar.add_css_class (Granite.STYLE_CLASS_FRAME); + + var lid_closed_label = new Gtk.Label (_("Lid Close Behavior")) { + xalign = 0 }; - var lid_closed_box = new LidCloseActionComboBox (false); + var lid_closed_box = new LidCloseActionComboBox (false) { + hexpand = true + }; - var lid_dock_label = new Gtk.Label (_("When lid is closed with external monitor:")) { - halign = Gtk.Align.END, - xalign = 1 + var lid_dock_label = new Gtk.Label (_("Lid Close With External Display")) { + xalign = 0 }; - var lid_dock_box = new LidCloseActionComboBox (true); + var lid_dock_box = new LidCloseActionComboBox (true) { + hexpand = true + }; label_size.add_widget (lid_closed_label); label_size.add_widget (lid_dock_label); - main_grid.attach (lid_closed_label, 0, 6); - main_grid.attach (lid_closed_box, 1, 6); - main_grid.attach (lid_dock_label, 0, 7); - main_grid.attach (lid_dock_box, 1, 7); + var lid_close_grid = new Gtk.Grid () { + row_spacing = 12, + column_spacing = 12 + }; + lid_close_grid.attach (lid_closed_label, 0, 0); + lid_close_grid.attach (lid_closed_box, 1, 0); + lid_close_grid.attach (lid_dock_label, 0, 1); + lid_close_grid.attach (lid_dock_box, 1, 1); + lid_close_grid.attach (infobar, 0, 2, 2); + + box.append (lid_close_grid); + + var helper = LogindHelper.get_logind_helper (); + if (helper != null) { + helper.changed.connect (() => { + infobar.revealed = true; + }); + } } - var screen_timeout_label = new Gtk.Label (_("Turn off display when inactive for:")) { - halign = Gtk.Align.END, - xalign = 1 + var screen_timeout_label = new Gtk.Label (_("Automatic Display Off")) { + xalign = 0 }; - var screen_timeout = new TimeoutComboBox (new GLib.Settings ("org.gnome.desktop.session"), "idle-delay"); + var screen_timeout = new TimeoutComboBox (new GLib.Settings ("org.gnome.desktop.session"), "idle-delay") { + hexpand = true + }; // FIXME: Virtual machines can only shutdown or do nothing. Tablets always suspend. powerbutton_dropdown = new Gtk.DropDown.from_strings ({ @@ -168,24 +206,28 @@ public class Power.MainView : Switchboard.SettingsPage { }; var powerbutton_label = new Gtk.Label (_("Power Button Behavior")) { - halign = Gtk.Align.END, - xalign = 1, - mnemonic_widget = powerbutton_dropdown + mnemonic_widget = powerbutton_dropdown, + xalign = 0 }; + var main_grid = new Gtk.Grid () { + column_spacing = 12, + row_spacing = 12 + }; main_grid.attach (screen_timeout_label, 0, 4); main_grid.attach (screen_timeout, 1, 4); 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 + var sleep_timeout_label = new Gtk.Label (_("Suspend When Inactive For")) { + xalign = 0 }; var sleep_timeout = new TimeoutComboBox (settings, "sleep-inactive-ac-timeout") { enum_property = "sleep-inactive-ac-type", enum_never_value = PowerActionType.NOTHING, - enum_normal_value = PowerActionType.SUSPEND + enum_normal_value = PowerActionType.SUSPEND, + hexpand = true }; var ac_grid = new Gtk.Grid () { @@ -217,15 +259,16 @@ public class Power.MainView : Switchboard.SettingsPage { } if (power_manager.has_battery ()) { - var battery_timeout_label = new Gtk.Label (_("Suspend when inactive for:")) { - xalign = 1 + var battery_timeout_label = new Gtk.Label (_("Suspend When Inactive For")) { + xalign = 0 }; label_size.add_widget (battery_timeout_label); var battery_timeout = new TimeoutComboBox (settings, "sleep-inactive-battery-timeout") { enum_property = "sleep-inactive-battery-type", enum_never_value = PowerActionType.NOTHING, - enum_normal_value = PowerActionType.SUSPEND + enum_normal_value = PowerActionType.SUSPEND, + hexpand = true }; var battery_grid = new Gtk.Grid () { @@ -248,12 +291,16 @@ public class Power.MainView : Switchboard.SettingsPage { settings.bind ("power-saver-profile-on-low-battery", auto_low_power_switch, "active", DEFAULT); var auto_low_power_label = new Granite.HeaderLabel (_("Automatically Save Power")) { + hexpand = true, mnemonic_widget = auto_low_power_switch, secondary_text = _("Power Saver mode will be used when battery is low") }; - battery_grid.attach (auto_low_power_label, 0, 3); - battery_grid.attach (auto_low_power_switch, 1, 3); + var auto_low_power_box = new Gtk.Box (HORIZONTAL, 12); + auto_low_power_box.append (auto_low_power_label); + auto_low_power_box.append (auto_low_power_switch); + + battery_grid.attach (auto_low_power_box, 0, 3, 2); stack.add_titled (battery_grid, "battery", _("On Battery")); @@ -280,32 +327,6 @@ public class Power.MainView : Switchboard.SettingsPage { main_grid.attach (stack, 0, 9, 2); - var infobar_label = new Gtk.Label (_("Some changes will not take effect until you restart this computer")); - - var infobar = new Gtk.InfoBar () { - message_type = Gtk.MessageType.WARNING, - revealed = false - }; - infobar.add_child (infobar_label); - infobar.add_css_class (Granite.STYLE_CLASS_FRAME); - - var helper = LogindHelper.get_logind_helper (); - if (helper != null) { - helper.changed.connect (() => { - infobar.revealed = true; - }); - } - - var box = new Gtk.Box (VERTICAL, 12); - box.append (infobar); - if (power_manager.has_battery ()) { - var battery_box = new BatteryBox () { - margin_bottom = 12 - }; - - box.append (battery_box); - } - box.append (main_grid); child = box; diff --git a/src/Widgets/LidCloseActionComboBox.vala b/src/Widgets/LidCloseActionComboBox.vala index 04559daf..7c3745cb 100644 --- a/src/Widgets/LidCloseActionComboBox.vala +++ b/src/Widgets/LidCloseActionComboBox.vala @@ -35,10 +35,7 @@ class Power.LidCloseActionComboBox : Gtk.Widget { } construct { - combobox = new Gtk.ComboBoxText () { - hexpand = true - }; - + combobox = new Gtk.ComboBoxText (); combobox.set_parent (this); var helper = LogindHelper.get_logind_helper (); diff --git a/src/Widgets/TimeoutComboBox.vala b/src/Widgets/TimeoutComboBox.vala index 7283d95e..e647f780 100644 --- a/src/Widgets/TimeoutComboBox.vala +++ b/src/Widgets/TimeoutComboBox.vala @@ -93,9 +93,7 @@ class Power.TimeoutComboBox : Gtk.Widget { construct { key_type = schema.get_value (key).get_type (); - combobox = new Gtk.ComboBoxText () { - hexpand = true - }; + combobox = new Gtk.ComboBoxText (); combobox.append_text (_("Never")); combobox.append_text (_("5 min")); combobox.append_text (_("10 min")); From 954a1408ce294ff2afae5578b3a2644de982406c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 13 Feb 2024 11:48:35 -0800 Subject: [PATCH 2/3] Update search strings --- src/Plug.vala | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Plug.vala b/src/Plug.vala index d1a328fb..c65dae9f 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -69,18 +69,16 @@ namespace Power { // 'search' returns results like ("Keyboard → Behavior → Duration", "keyboardbehavior") public override async Gee.TreeMap search (string search) { var search_results = new Gee.TreeMap ((GLib.CompareDataFunc)strcmp, (Gee.EqualDataFunc)str_equal); - search_results.set ("%s → %s".printf (display_name, _("Suspend 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")), ""); - search_results.set ("%s → %s".printf (display_name, _("Display brightness")), ""); - search_results.set ("%s → %s".printf (display_name, _("Automatic brightness adjustment")), ""); + search_results.set ("%s → %s".printf (display_name, _("Automatically Adjust Brightness")), ""); search_results.set ("%s → %s".printf (display_name, _("Automatically Save Power")), ""); - search_results.set ("%s → %s".printf (display_name, _("Inactive display off")), ""); - search_results.set ("%s → %s".printf (display_name, _("Docked lid close")), ""); - search_results.set ("%s → %s".printf (display_name, _("Sleep inactivity timeout")), ""); - search_results.set ("%s → %s".printf (display_name, _("Suspend inactive")), ""); + search_results.set ("%s → %s".printf (display_name, _("Automatic Display Off")), ""); + search_results.set ("%s → %s".printf (display_name, _("Battery Level")), ""); + search_results.set ("%s → %s".printf (display_name, _("Dim Display")), ""); + search_results.set ("%s → %s".printf (display_name, _("Display Brightness")), ""); + search_results.set ("%s → %s".printf (display_name, _("Lid Close Behavior")), ""); + search_results.set ("%s → %s".printf (display_name, _("Lid Close With External Display")), ""); + search_results.set ("%s → %s".printf (display_name, _("Power Button Behavior")), ""); + search_results.set ("%s → %s".printf (display_name, _("Suspend When Inactive For")), ""); return search_results; } } From 48dfe5544f211d2fbe639696da35b9db5c3b8df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 13 Feb 2024 11:58:04 -0800 Subject: [PATCH 3/3] Add idle dim switch --- src/MainView.vala | 15 +++++++++++++++ src/Plug.vala | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/MainView.vala b/src/MainView.vala index 759f84f7..c4244463 100644 --- a/src/MainView.vala +++ b/src/MainView.vala @@ -188,6 +188,17 @@ public class Power.MainView : Switchboard.SettingsPage { } } + var idle_dim_switch = new Gtk.Switch () { + halign = END + }; + + var idle_dim_label = new Gtk.Label (_("Automatically Dim Display")) { + mnemonic_widget = idle_dim_switch, + xalign = 0 + }; + + label_size.add_widget (idle_dim_label); + var screen_timeout_label = new Gtk.Label (_("Automatic Display Off")) { xalign = 0 }; @@ -214,6 +225,8 @@ public class Power.MainView : Switchboard.SettingsPage { column_spacing = 12, row_spacing = 12 }; + main_grid.attach (idle_dim_label, 0, 3); + main_grid.attach (idle_dim_switch, 1, 3); main_grid.attach (screen_timeout_label, 0, 4); main_grid.attach (screen_timeout, 1, 4); main_grid.attach (powerbutton_label, 0, 5); @@ -341,6 +354,8 @@ public class Power.MainView : Switchboard.SettingsPage { update_powerbutton_dropdown (); settings.changed["power-button-action"].connect (update_powerbutton_dropdown); + settings.bind ("idle-dim", idle_dim_switch, "active", DEFAULT); + powerbutton_dropdown.notify["selected"].connect (() => { int[] map = {0, 1, 3}; settings.set_enum ( diff --git a/src/Plug.vala b/src/Plug.vala index c65dae9f..daadf407 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -70,10 +70,10 @@ namespace Power { public override async Gee.TreeMap search (string search) { var search_results = new Gee.TreeMap ((GLib.CompareDataFunc)strcmp, (Gee.EqualDataFunc)str_equal); search_results.set ("%s → %s".printf (display_name, _("Automatically Adjust Brightness")), ""); + search_results.set ("%s → %s".printf (display_name, _("Automatically Dim Display")), ""); search_results.set ("%s → %s".printf (display_name, _("Automatically Save Power")), ""); search_results.set ("%s → %s".printf (display_name, _("Automatic Display Off")), ""); search_results.set ("%s → %s".printf (display_name, _("Battery Level")), ""); - search_results.set ("%s → %s".printf (display_name, _("Dim Display")), ""); search_results.set ("%s → %s".printf (display_name, _("Display Brightness")), ""); search_results.set ("%s → %s".printf (display_name, _("Lid Close Behavior")), ""); search_results.set ("%s → %s".printf (display_name, _("Lid Close With External Display")), "");