Skip to content

Commit

Permalink
move battery label setting to Budgie Desktop Settings (#389)
Browse files Browse the repository at this point in the history
* move battery label setting to Budgie Desktop Settings

* changes

* Move battery percentage label to right of icon because that's like...normal

---------

Co-authored-by: Joshua Strobl <me@joshuastrobl.com>
  • Loading branch information
justchen1369 and JoshStrobl authored Aug 5, 2023
1 parent 8e79813 commit 991aa30
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/panel/applets/status/PowerIndicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public class BatteryIcon : Gtk.Box {
this.percent_label = new Gtk.Label("");
this.percent_label.get_style_context().add_class("percent-label");

this.percent_label.valign = Gtk.Align.CENTER;
this.percent_label.margin_end = 4;
pack_start(this.percent_label, false, false, 0);
this.percent_label.no_show_all = true;

this.image = new Gtk.Image();
this.image.valign = Gtk.Align.CENTER;
this.image.pixel_size = 0;
pack_start(this.image, false, false, 0);

this.percent_label.valign = Gtk.Align.CENTER;
this.percent_label.margin_end = 4;
pack_start(this.percent_label, false, false, 0);
this.percent_label.no_show_all = true;

this.update_ui(battery);

battery.notify.connect(this.on_battery_change);
Expand Down Expand Up @@ -258,8 +258,6 @@ public class PowerIndicator : Gtk.Bin {
private HashTable<string,BatteryIcon?> devices;

public bool label_visible { set ; get ; default = false; }
private Gtk.CheckButton check_percent;
private Settings battery_settings;

public PowerIndicator() {
devices = new HashTable<string,BatteryIcon?>(str_hash, str_equal);
Expand All @@ -274,19 +272,6 @@ public class PowerIndicator : Gtk.Bin {
box.border_width = 6;
popover.add(box);

/* Instaniate label_visible */
battery_settings = new Settings("org.gnome.desktop.interface");
battery_settings.bind("show-battery-percentage", this, "label-visible", SettingsBindFlags.GET);
notify["label-visible"].connect_after(this.update_labels);

check_percent = new Gtk.CheckButton.with_label(_("Show battery percentage"));
check_percent.get_child().set_property("margin", 4);
box.pack_start(check_percent, false, false, 0);
battery_settings.bind("show-battery-percentage", check_percent, "active", SettingsBindFlags.DEFAULT);

var sep = new Gtk.Separator(Gtk.Orientation.HORIZONTAL);
box.pack_start(sep, false, false, 1);

var button = new Gtk.Button.with_label(_("Power settings"));
button.get_style_context().add_class(Gtk.STYLE_CLASS_FLAT);
button.clicked.connect(open_power_settings);
Expand Down Expand Up @@ -346,7 +331,9 @@ public class PowerIndicator : Gtk.Bin {
widget.set_orientation(orient);
}

private void update_labels() {
public void update_labels(bool visible) {
this.label_visible = visible;

unowned BatteryIcon? icon = null;
var iter = HashTableIter<string,BatteryIcon?>(this.devices);
while (iter.next(null, out icon)) {
Expand Down
19 changes: 19 additions & 0 deletions src/panel/applets/status/StatusApplet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,29 @@ public class StatusPlugin : Budgie.Plugin, Peas.ExtensionBase {
}
}

private const string GNOME_SETTINGS_SCHEMA = "org.gnome.desktop.interface";

[GtkTemplate (ui="/com/solus-project/status/settings.ui")]
public class StatusSettings : Gtk.Grid {
Settings? settings = null;
Settings? gnome_settings = null;

[GtkChild]
private unowned Gtk.SpinButton? spinbutton_spacing;

[GtkChild]
private unowned Gtk.Switch? switch_show_battery_percentage;

public StatusSettings(Settings? settings) {
this.settings = settings;
this.gnome_settings = new Settings(GNOME_SETTINGS_SCHEMA);

settings.bind("spacing", spinbutton_spacing, "value", SettingsBindFlags.DEFAULT);
gnome_settings.bind("show-battery-percentage", switch_show_battery_percentage, "active", SettingsBindFlags.DEFAULT);
}
}


public class StatusApplet : Budgie.Applet {
public string uuid { public set; public get; }
protected Gtk.Box widget;
Expand All @@ -35,6 +45,7 @@ public class StatusApplet : Budgie.Applet {
protected PowerIndicator power;
protected Gtk.EventBox? wrap;
private Settings? settings;
private Settings? gnome_settings;
private Budgie.PopoverManager? manager = null;

/**
Expand Down Expand Up @@ -74,6 +85,14 @@ public class StatusApplet : Budgie.Applet {
show_all();

power = new PowerIndicator();

gnome_settings = new Settings(GNOME_SETTINGS_SCHEMA);

power.update_labels(gnome_settings.get_boolean("show-battery-percentage"));
gnome_settings.changed["show-battery-percentage"].connect((key) => {
power.update_labels(gnome_settings.get_boolean("show-battery-percentage"));
});

widget.pack_start(power, false, false, 0);
/* Power shows itself - we dont control that */

Expand Down
25 changes: 25 additions & 0 deletions src/panel/applets/status/settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="row_spacing">4</property>
<property name="column_spacing">4</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
Expand Down Expand Up @@ -38,5 +40,28 @@
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Show battery percentage</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="switch_show_battery_percentage">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</template>
</interface>

0 comments on commit 991aa30

Please sign in to comment.