Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions data/power.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,15 @@
<summary>Sets if the percentage of the primary battery is shown in the panel.</summary>
<description>Enable this to see the percentage of the battery directly in the panel without having to click onto the power-indicator.</description>
</key>
<key type="as" name="brightness-up">
<default>['XF86MonBrightnessUp']</default>
<summary>Global brightness up</summary>
<description>Increase monitor brightness on supported panels</description>
</key>
<key type="as" name="brightness-down">
<default>['XF86MonBrightnessDown']</default>
<summary>Global brightness down</summary>
<description>Decrease monitor brightness on supported panels</description>
</key>
</schema>
</schemalist>
40 changes: 38 additions & 2 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class Power.Indicator : Wingpanel.Indicator {

private Settings settings;

private bool open = false;

public Indicator (bool is_in_session) {
Object (
code_name : Wingpanel.Indicator.POWER,
Expand All @@ -48,6 +50,38 @@ public class Power.Indicator : Wingpanel.Indicator {
brightness_manager = Services.BrightnessManager.get_default ();

settings = new GLib.Settings ("io.elementary.panel.power");

var brightness_up = new Wingpanel.KeybindingHelper.SignalAction ();
brightness_up.activated.connect (global_brightness_up);

var brightness_down = new Wingpanel.KeybindingHelper.SignalAction ();
brightness_down.activated.connect (global_brightness_down);

var helper = Wingpanel.KeybindingHelper.get_default ();
helper.add_keybinding ("brightness-up", settings, brightness_up);
helper.add_keybinding ("brightness-down", settings, brightness_down);
}

private void global_brightness_up () {
brightness_manager.set_global_brightness (brightness_manager.get_global_brightness () + 0.1);
maybe_show_brightness_osd (brightness_manager.get_global_brightness ());
}

private void global_brightness_down () {
brightness_manager.set_global_brightness (brightness_manager.get_global_brightness () - 0.1);
maybe_show_brightness_osd (brightness_manager.get_global_brightness ());
}

private void maybe_show_brightness_osd (double value) {
if (open) {
return;
}

var parameters = new HashTable<string, Variant> (str_hash, str_equal);
parameters["icon"] = new Variant.string ("display-brightness-symbolic");
parameters["level"] = new Variant.double (value);

Wingpanel.KeybindingHelper.get_default ().show_osd (parameters);
}

public override Gtk.Widget get_display_widget () {
Expand Down Expand Up @@ -77,10 +111,12 @@ public class Power.Indicator : Wingpanel.Indicator {
return popover_widget;
}

public override void opened () { }
public override void opened () {
open = true;
}

public override void closed () {

open = false;
}

private void update_visibility () {
Expand Down
Loading