jkitching / soft-brightness-plus

Gnome-shell extension to manage your display brightness via an alpha overlay (instead of the backlight).
GNU General Public License v3.0
49 stars 10 forks source link

Screen brightness buttons do not work when only non-DDC monitor is available #6

Open Cm4nXD opened 1 year ago

Cm4nXD commented 1 year ago

Can you add an option to set configurable keybinds for changing the brightness value?

jkitching commented 1 year ago

I am not sure this fits within the scope of the extension... perhaps you could just configure the keys using gsettings or by running a custom command for a keyboard shortcut?

The first method is described here: https://discourse.gnome.org/t/screen-brightness-with-keyboard-shorcuts-osd/9005/3

gsettings set org.gnome.settings-daemon.plugins.media-keys screen-brightness-down "['<Super>F6']" 
gsettings set org.gnome.settings-daemon.plugins.media-keys screen-brightness-up "['<Super>F7']"

The second method is described here: https://www.reddit.com/r/gnome/comments/cpcldr/custom_keybinds_for_brightness/

Cm4nXD commented 1 year ago

I use this extension to implement brightness controls on my monitor since it cannot be controlled via DDC. So gnome will just spit the error that there is no usable backlight when using gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.StepDown

As for the brightness key binds, I do not wish to change the default ones, I simply want to be able to use the existing keys to control this extension's overlay.

jkitching commented 1 year ago

Let me try to summarize:

Is all of this accurate?

Cm4nXD commented 1 year ago

Yes

jkitching commented 1 year ago

Originally I wanted to come up with a way of solving this that would allow use of the existing XF86MonBrightness{Up,Down} keys without any extra configuration. But I'm at wit's end, and am starting to think it's just best to allow the user to bind a key like in the "Brightness control using ddcutil" extension. Here are the methods I tried for posterity's sake:

Main.wm.addKeybinding

The first method looks something like this:

let my_settings = ExtensionUtils.getSettings("org.gnome.shell.extensions.mycoolstuff");

Main.wm.addKeybinding("cool-hotkey", my_settings,
    Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
    Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW
    this._hotkeyActionMethod.bind(this));

Source: StackOverflow

The problem here is if we attempt to bind to XF86MonBrightness{Up,Down}, then Mutter seems to exibit some random behaviour as to which keybinding is actually used (the original one owned by gsd-power, and our own). There's also no way I can tell to find out of the call succeeded or not, or introspect which handler is currently assigned to a specific hotkey.

accelerator-activated signal

The second method connects to the accelerator-activated signal, and then grabs accelerators XF86MonBrightness{Up,Down}. Code looks something like this:

global.display.connect('accelerator-activated', handler);
const action = global.display.grab_accelerator(accelerator);
const name = Meta.external_binding_name_for_action(action);
Main.wm.allowKeybinding(name, Shell.ActionMode.ALL);

Source: StackExchange / superuser

But the grab_accelerator call fails if something else has already grabbed it. On the other hand, the accelerator handler is still called when XF86MonBrightness{Up,Down} keys are pressed (among others)... we just don't know what key was pressed. The handler is passed the action argument which is always set to 0.

Unsetting gsd-power keybindings

The above two methods actually work fine, assuming XF86MonBrightness{Up,Down} haven't been assigned to anything. So in theory we could (silently?) remove the two keybindings:

gsettings set org.gnome.settings-daemon.plugins.media-keys screen-brightness-down-static "['']"
gsettings set org.gnome.settings-daemon.plugins.media-keys screen-brightness-up-static "['']"

And maybe even attempt to re-add them when the extension is disabled. But that's a lot of bookkeeping, and perhaps not very nice to make such changes right under the user's nose. Not to mention, if XF86MonBrightness{Up,Down} happens to be assigned to anything else, we won't know, and our own keybinding will still not work correctly.

The other option is to ask the user politely to remove gsd-power's keybindings in our extension settings dialog. But that also seems prone to failure.

User-configurable keybindings

The final option is what @Cm4nXD was requesting in the first place... user-configurable keybindings in the extension settings dialog. The "Brightness control using ddcutil" does a good job of this:

add custom keybinding

Assigning to XF86MonBrightness{Up,Down} just "doesn't work" by virtue of the keys already being intercepted by gsd-power. So some instructions on unsetting the two keybindings (as shown above) may still be useful in the UI.