After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 773405 - PATCH: gsd-power-manager: Show kbd-brigthness osd on UPower.KbdBacklight.BrightnessChanged signal
PATCH: gsd-power-manager: Show kbd-brigthness osd on UPower.KbdBacklight.Brig...
Status: RESOLVED FIXED
Product: gnome-settings-daemon
Classification: Core
Component: power
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gnome-settings-daemon-maint
gnome-settings-daemon-maint
: 672380 (view as bug list)
Depends on: 773403
Blocks:
 
 
Reported: 2016-10-24 07:45 UTC by Hans de Goede
Modified: 2017-05-25 13:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH 5/5] gsd-power-manager: Show kbd-brigthness osd on UPower.KbdBacklight.BrightnessChanged signal (2.97 KB, patch)
2016-10-24 07:45 UTC, Hans de Goede
none Details | Review
[PATCH 6/7] power: Add org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal (8.54 KB, patch)
2017-01-29 18:18 UTC, Hans de Goede
none Details | Review
[PATCH 7/7] media-keys: Show kbd-brigthness osd on org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal (2.37 KB, patch)
2017-01-29 18:19 UTC, Hans de Goede
none Details | Review
[PATCH 2/3] power: Add org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal (8.17 KB, patch)
2017-02-09 17:56 UTC, Hans de Goede
none Details | Review
[PATCH 3/3] media-keys: Show kbd-brigthness osd on org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal (2.50 KB, patch)
2017-02-09 17:57 UTC, Hans de Goede
none Details | Review
[PATCH 2/3] power: Add org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal (8.17 KB, patch)
2017-03-16 10:02 UTC, Hans de Goede
committed Details | Review
[PATCH 3/3] media-keys: Show kbd-brigthness osd on org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal (2.62 KB, patch)
2017-03-16 10:03 UTC, Hans de Goede
committed Details | Review

Description Hans de Goede 2016-10-24 07:45:28 UTC
Created attachment 338322 [details] [review]
[PATCH 5/5] gsd-power-manager: Show kbd-brigthness osd on UPower.KbdBacklight.BrightnessChanged signal

If we receive a org.freedesktop.UPower.KbdBacklight.BrightnessChanged signal and the brightness is different then what we last set, show the kbd-brigthness osd.

This makes the kbd-brigthness osd properly show up on laptops with hardwired keyboard backlight brightness hotkeys (which don't emit input events).

Note this depends on the patches from bug 773402 and 773403, hence the [PATCH 5/5].
Comment 1 Bastien Nocera 2016-10-24 11:17:09 UTC
Review of attachment 338322 [details] [review]:

::: plugins/power/gsd-power-manager.c
@@ +1488,3 @@
         backlight_iface_emit_changed (manager, GSD_POWER_DBUS_INTERFACE_KEYBOARD, percentage);
+
+        /* Brightness changed by firmware handled hotkey, show osd. */

OSD. Should be a couple of lines below, or reverse the check to make it clearer:
if (manager->priv->shell_proxy != NULL) {...

I really don't link this, as it splits the OSD between the media-keys and the power plugin, depending on whether the firmware or g-s-d handles the key. We need a better way than this.
Comment 2 Hans de Goede 2016-10-24 13:13:44 UTC
Hi,

Thanks for all the reviews, I'll go over them and post new versions. May take a while though as I'm rather busy (in the middle of switching teams).

(In reply to Bastien Nocera from comment #1)
> Review of attachment 338322 [details] [review] [review]:
> 
> ::: plugins/power/gsd-power-manager.c
> @@ +1488,3 @@
>          backlight_iface_emit_changed (manager,
> GSD_POWER_DBUS_INTERFACE_KEYBOARD, percentage);
> +
> +        /* Brightness changed by firmware handled hotkey, show osd. */
> 
> OSD. Should be a couple of lines below, or reverse the check to make it
> clearer:
> if (manager->priv->shell_proxy != NULL) {...
> 
> I really don't link this, as it splits the OSD between the media-keys and
> the power plugin, depending on whether the firmware or g-s-d handles the
> key. We need a better way than this.

I already sort of expected this comment, but I decided to go with the KISS approach first. Since I did expect this I do have an alternative proposal:

Make the media-keys plugin watch the Brightness property on org.gnome.SettingsDaemon.Power.Keyboard for changes and update the OSD based on this, this would work both for hardwired hotkeys, as well as for any changes done by the media-keys plugin itself as those will emit a PropertiesChanged signal for Brightness too, so this would then replace the show_osd() in gsd-media-keys-manager.c: update_brightness_cb() (for keyboards).

This will need some careful handling of the initial PropertiesChanged signal the gsd-power-manager emits but I believe that can be dealt with.

Please let me know what you think of this approach. If you like it I will take a shot at implementing it.

Regards,

Hans
Comment 3 Hans de Goede 2016-10-24 16:56:32 UTC
(In reply to Hans de Goede from comment #2)
> I already sort of expected this comment, but I decided to go with the KISS
> approach first. Since I did expect this I do have an alternative proposal:
> 
> Make the media-keys plugin watch the Brightness property on
> org.gnome.SettingsDaemon.Power.Keyboard for changes and update the OSD based
> on this, this would work both for hardwired hotkeys, as well as for any
> changes done by the media-keys plugin itself as those will emit a
> PropertiesChanged signal for Brightness too, so this would then replace the
> show_osd() in gsd-media-keys-manager.c: update_brightness_cb() (for
> keyboards).

Hmm, I just realized that this will not work because this will also cause the osd to show when changing the brightness through the slider in gnome-control-panel. So I see 2 options:

1) Make org.gnome.SettingsDaemon.Power.Keyboard emit some new signal when the hardware autonomously changes the brightness, and make the media-keys plugin listen to this and show the osd
2) Move all keyboard backlight osd handling to gsd-power-manager.c

I'm personally leaning towards 1.

Regards,

Hans
Comment 4 Bastien Nocera 2016-10-25 15:04:47 UTC
1) would work best for me as well.
Comment 5 Hans de Goede 2017-01-29 18:18:32 UTC
Created attachment 344494 [details] [review]
[PATCH 6/7] power: Add org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal

Thanks for the reviews I'm attaching a new set of patches, addressing all review remarks.
Comment 6 Hans de Goede 2017-01-29 18:19:05 UTC
Created attachment 344495 [details] [review]
[PATCH 7/7] media-keys: Show kbd-brigthness osd on org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal
Comment 7 Bastien Nocera 2017-01-30 11:06:12 UTC
Review of attachment 344494 [details] [review]:

s/Therefor/Therefore/
s/osd/OSD/

::: plugins/power/gsd-power-manager.c
@@ +1497,3 @@
 
+        /* kbd_brightness_now != new_brightness, so the brightness was not
+         * changed by us, assume it was changed by a firmwware handle hotkey. */

I'm pretty sure this is racy.
Comment 8 Bastien Nocera 2017-01-30 11:11:20 UTC
Review of attachment 344495 [details] [review]:

s/osd/OSD/

::: plugins/media-keys/gsd-media-keys-manager.c
@@ +3122,3 @@
+        g_variant_get (parameters, "(is)", &brightness, &source);
+
+        if (g_strcmp0 (source, "hotkey") != 0)

You're leaking the source string here. Should be:
const char *source;
g_variant_get (parameters, "(i&s)", &brightness, &source);
which doesn't make a copy of the string.
Comment 9 Bastien Nocera 2017-01-30 11:25:32 UTC
(In reply to Bastien Nocera from comment #7)
> Review of attachment 344494 [details] [review] [review]:
> 
> s/Therefor/Therefore/
> s/osd/OSD/
> 
> ::: plugins/power/gsd-power-manager.c
> @@ +1497,3 @@
>  
> +        /* kbd_brightness_now != new_brightness, so the brightness was not
> +         * changed by us, assume it was changed by a firmwware handle
> hotkey. */
> 
> I'm pretty sure this is racy.

This isn't racy for now, but it would be racy if we made those calls asynchronous.

You'd also need to take "session_is_active" to avoid showing OSDs on inactive sessions.
Comment 10 Hans de Goede 2017-01-30 14:32:46 UTC
(In reply to Bastien Nocera from comment #8)
> Review of attachment 344495 [details] [review] [review]:
> 
> s/osd/OSD/
> 
> ::: plugins/media-keys/gsd-media-keys-manager.c
> @@ +3122,3 @@
> +        g_variant_get (parameters, "(is)", &brightness, &source);
> +
> +        if (g_strcmp0 (source, "hotkey") != 0)
> 
> You're leaking the source string here. Should be:
> const char *source;
> g_variant_get (parameters, "(i&s)", &brightness, &source);
> which doesn't make a copy of the string.

Ok, will fix.
Comment 11 Hans de Goede 2017-01-30 14:37:12 UTC
(In reply to Bastien Nocera from comment #9)
> (In reply to Bastien Nocera from comment #7)
> > Review of attachment 344494 [details] [review] [review] [review]:
> > 
> > s/Therefor/Therefore/
> > s/osd/OSD/
> > 
> > ::: plugins/power/gsd-power-manager.c
> > @@ +1497,3 @@
> >  
> > +        /* kbd_brightness_now != new_brightness, so the brightness was not
> > +         * changed by us, assume it was changed by a firmwware handle
> > hotkey. */
> > 
> > I'm pretty sure this is racy.
> 
> This isn't racy for now, but it would be racy if we made those calls
> asynchronous.

Ack, so lets not make them asynchronous, if we do there is really nothing we can do to avoid the race.

> You'd also need to take "session_is_active" to avoid showing OSDs on
> inactive sessions.

OK, will fix.
Comment 12 Bastien Nocera 2017-01-30 14:52:56 UTC
(In reply to Hans de Goede from comment #11)
> (In reply to Bastien Nocera from comment #9)
> > (In reply to Bastien Nocera from comment #7)
> > > Review of attachment 344494 [details] [review] [review] [review] [review]:
> > > 
> > > s/Therefor/Therefore/
> > > s/osd/OSD/
> > > 
> > > ::: plugins/power/gsd-power-manager.c
> > > @@ +1497,3 @@
> > >  
> > > +        /* kbd_brightness_now != new_brightness, so the brightness was not
> > > +         * changed by us, assume it was changed by a firmwware handle
> > > hotkey. */
> > > 
> > > I'm pretty sure this is racy.
> > 
> > This isn't racy for now, but it would be racy if we made those calls
> > asynchronous.
> 
> Ack, so lets not make them asynchronous, if we do there is really nothing we
> can do to avoid the race.

No, this is not an "if", this is a "when". We'll eventually make it asynchronous, so we need to build the framework to be able to handle that.
Comment 13 Hans de Goede 2017-02-09 17:56:18 UTC
Created attachment 345355 [details] [review]
[PATCH 2/3] power: Add org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal

Hi,

Here is a new version addressing the review comments and using the new upower BrightnessChangedWithSource signal to address to race concerns.

Regards,

Hans
Comment 14 Hans de Goede 2017-02-09 17:57:10 UTC
Created attachment 345357 [details] [review]
[PATCH 3/3] media-keys: Show kbd-brigthness osd on org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal
Comment 15 Hans de Goede 2017-03-16 10:02:46 UTC
Created attachment 348071 [details] [review]
[PATCH 2/3] power: Add org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal

Updated patch to match the upower changes as merged upstream.
Comment 16 Hans de Goede 2017-03-16 10:03:08 UTC
Created attachment 348072 [details] [review]
[PATCH 3/3] media-keys: Show kbd-brigthness osd on org.gnome.SettingsDaemon.Power.Keyboard.BrightnessChanged signal

Updated patch to match the upower changes as merged upstream.
Comment 17 Hans de Goede 2017-05-01 07:17:14 UTC
Ping? Anything blocking these from getting merged ? The upower and kernel patches are all in place so it would be nice to get this merged and the issues with keyboard brightness fixed.
Comment 18 Rui Matos 2017-05-24 15:31:20 UTC
*** Bug 672380 has been marked as a duplicate of this bug. ***
Comment 19 Rui Matos 2017-05-25 13:45:03 UTC
Review of attachment 348071 [details] [review]:

looks fine
Comment 20 Rui Matos 2017-05-25 13:46:02 UTC
Review of attachment 348072 [details] [review]:

lgtm