Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadAccess when try to register Meida keys in linux #6

Closed
mohsenti opened this issue Sep 7, 2017 · 6 comments
Closed

BadAccess when try to register Meida keys in linux #6

mohsenti opened this issue Sep 7, 2017 · 6 comments

Comments

@mohsenti
Copy link

mohsenti commented Sep 7, 2017

Hi,

I develop a simple audio player with Qt, now I have handle mediakeys like play/pause , next , previous and others but when try to register hotkeys a badaccess exception occur in code.
Is it a library bug ?

error message : QHotkey: Failed to register hotkey. Error: BadAccess (attempt to access private resource denied)

@Skycoder42
Copy link
Owner

I'm afraid it's not a bug, but a limitation. As stated in the README, not all keys will work for all platforms. And as it seems, this is true for media keys on linux.

This does not mean, it's impossible, but you can't use the Qt keycodes like Qt::Key_Play. This is because the algorithm that mapps thouse keys is not complete, as I wasn't able to find a solution that works for all keys.

As a solution, try find out the native keycode on linux, and try this one

QHotkey::NativeShortcut native;
native.key = /*native keycode for "play" here*/;
auto hKey = new QHotkey(native);

If this still triggers an error, it is impossible to register the keys.

@ArsenArsen
Copy link
Contributor

Other things utilizing these keys use GNOME's daemon. You could look at how GNOME handles it. By the way here are the X keysyms for media buttons:

XF86AudioPlay
XF86AudioPrev
XF86AudioNext
XF86AudioStop
XF86HomePage

@Skycoder42
Copy link
Owner

Closing, as it seems no further help is needed

@rodlie
Copy link

rodlie commented Apr 20, 2019

So, any solutions for this?

    // XF86MonBrightnessUp 0x1008FF02 233
    QHotkey::NativeShortcut native;
    native.key = 233;
    qDebug() << "KEY?" << native.isValid();
    auto hotkey = new QHotkey(native, true, this);
    qDebug() << "OK?" << hotkey->isRegistered();

I get false on both.

@Skycoder42
Copy link
Owner

You have to create a native shortcut as

QHotkey::NativeShortcut native (233);

Thats an artifact of NativeShortcut originally beeing a private class, thus the validity does not get updates when settings the key/modifier directly... I shall fix that in the next release.

After creating the native shortcut that way, at least the first line should return true. For the second one, there is once again no guarantee. If it works, it works. If not, it's not possible with the "normal" keygrabber API that is used by this library.

@rodlie
Copy link

rodlie commented Apr 21, 2019

Thanks, that did the trick.

I do however need a way to get the keycode automatically from XF86MonBrightnessUp somehow (will do some reading, suggestions welcome).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants