[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: KAction and global shortcuts.
From:       "Kelvie Wong" <kelvie () ieee ! org>
Date:       2007-12-07 5:58:32
Message-ID: 94ccbe710712062158t4b662ec3l9ea5f221d08514d1 () mail ! gmail ! com
[Download RAW message or body]

On Dec 5, 2007 12:30 PM, Andreas Hartmetz <ahartmetz@gmail.com> wrote:
> Am Mittwoch 05 Dezember 2007 20:57:42 schrieb Kelvie Wong:
>
> > On Dec 5, 2007 11:35 AM, Andreas Hartmetz <ahartmetz@gmail.com> wrote:
> > > Am Mittwoch 05 Dezember 2007 03:06:21 schrieb Kelvie Wong:
> > > > OK, it's probably not the global shortcuts that are broken -- it's
> > > > probably how I'm implementing them.
> > > >
> > > >
> > > > The normal KDE shortcuts (like Alt-F2 for the search/run and
> > > > Ctrl+Alt+L for lock screen) work.  It's probably something in my code.
> > > >
> > > > The signal from KAction doesn't seem to be emitted to my module.
> > > >
> > > > On Dec 3, 2007 4:19 PM, Kelvie Wong <kelvie@ieee.org> wrote:
> > > > > On Dec 2, 2007 7:02 PM, Hamish Rodda <rodda@kde.org> wrote:
> > > > > > On Mon, 3 Dec 2007 11:18:07 am Kelvie Wong wrote:
> > > > > > > I'm currently trying to help port KMilo's generic mm-keys module
> > > > > > > to work with KDE4.
> > > > > > >
> > > > > > > I've gotten the entire thing to build, replaced all the DCOP
> > > > > > > calls with DBus, and updated it to work with the new plugin
> > > > > > > factory (it loads and builds), and added some other minor fixes.
> > > > > > >
> > > > > > > The final hurdle (that I can see), is hooking the global shortcut
> > > > > > > keys to work with the new KAction.  I don't know why it doesn't
> > > > > > > work (I haven't confirmed if Qt::Key_VolumeUp ==
> > > > > > > XF86AudioRaiseVolume, though) --
> > > > > > >
> > > > > > > Here's the relevant code:
> > > > > > >
> > > > > > > struct ShortcutInfo
> > > > > > > {
> > > > > > >       const char* name;
> > > > > > >       Qt::Key symbol;
> > > > > > >       const char *slot;
> > > > > > > };
> > > > > > >
> > > > > > >       static const ShortcutInfo shortcuts[] = {
> > > > > > >               { "FastVolumeUp", Qt::Key_VolumeUp,
> > > > > > > SLOT(fastVolumeUp()) }, { "FastVolumeDown", Qt::Key_VolumeDown,
> > > > > > > SLOT(fastVolumeDown()) }, { "SlowVolumeUp",
> > > > > > > Qt::CTRL+Qt::Key_VolumeUp, SLOT(slowVolumeUp()) }, {
> > > > > > > "SlowVolumeDown", Qt::CTRL+Qt::Key_VolumeDown,
> > > > > > > SLOT(slowVolumeDown()) }, { "Mute", Qt::Key_VolumeMute,
> > > > > > > SLOT(mute()) }
> > > > > > >       };
> > > > > > >
> > > > > > >       ShortcutInfo si;
> > > > > > >       int len = (int)sizeof(shortcuts)/sizeof(ShortcutInfo);
> > > > > > >       for (int i = 0; i < len; i++) {
> > > > > > >               si = shortcuts[i];
> > > > > > >               KAction *act = new KAction(si.name, this);
> > > > > > >               act->setGlobalShortcut(KShortcut(si.symbol),
> > > > > > >
> > > > > > >                                  KAction::ActiveShortcut |
> > > > > > > KAction::DefaultShortcut); connect(act, SIGNAL(triggered(bool)),
> > > > > > > si.slot); }
> > > > > > >
> > > > > > > I can confirm that it does connect; the slot doesn't get called
> > > > > > > though.
> > > > > > >
> > > > > > > I can also confirm that the globalshortcut does get set, as in
> > > > > > > kglobalshortcutsrc:
> > > > > > > [KDE Global Shortcuts]
> > > > > > > kded\x01FastVolumeDown=Volume Down
> > > > > > > kded\x01FastVolumeUp=Volume Up
> > > > > > > kded\x01Mute=Volume Mute
> > > > > > > kded\x01SlowVolumeDown=Ctrl+Volume Down
> > > > > > > kded\x01SlowVolumeUp=Ctrl+Volume Up
> > > > > > >
> > > > > > > Anyone more familiar with KAction than I want to give me a hint?
> > > > > > > :)
> > >
> > > Interesting. If your code is a kded module it will have a more complex
> > > DBus "path" than your usual application.
> > > Also, applications use their KGlobal::mainComponent().componentName() for
> > > a unique name to register their shortcuts. From the config file it looks
> > > like the main component name ("kded") is not good enough here.
> > > Honestly, I have forgotten quite some details about DBus in the meantime.
> > > I suspect that either the complicated DBus path or the insufficient
> > > component name are giving you problems. The DBus browser from the Qt
> > > examples is a handy tool to see the DBus functions offered by some
> > > module.
> > > If your code is not a kded module I have no idea what is going wrong.
> > >
> > > >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to
> > > >> unsubscribe <<
> >
> > The code I'm writing is in a module.. inside a kded module (the
> > generic module inside KMilo).
> >
> > Do I have to look at the dbus functions for kglobalaccel?  Or should I
> > make a dbus interface for my KMilo module?
> >
> > Also, where's the dbus call being made? In the backtrace I can see
> > that the invokeAction signal is somehow passed through DBus; I'll take
> > a look at it when I get home tonight.
> >
> > I talked a bit about this in #kde4-devel with aseigo, and he suspected
> > it was something in KHotkeys; but gdb and grep tell me that khotkeys
> > is not included anywhere, so I'm not too sure about that.  Something
> > about the X events assuming there's a window before processing global
> > shortcuts, and kded modules not having a window.
>
> Ok, short description of how global shortcuts work:
> -Applications register their actions' shortcuts with kdedglobalshortcuts using
> the component name and action names.
> -kdedglobalshortcuts grabs the keys for the shortcuts and emits a signal
> containing the main component name and action name when the keys are pressed.
> -Applications listen to these signals and trigger the actions when they see
> their main component name and an existing action.
>
> The main classes involved are KGlobalAccel on the application side and
> KdedGlobalAccel on the kded side. KHotkeys is not usually involved.
> Aaron just seems to have missed the changes.
>
> Hope this helps. If not, feel free to ask more questions.
>
>
> >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
>

Alright, after a long evening with GDB, I've found my own problem --
it wasn't resolving the keycode correctly unless my xmodmap script ran
to map the media button keysyms first in kkeyserver.  I called xmodmap
before startkde4 and it detected it fine.  I did not realize that you
needed the keycode/keysym matched before the global shortcuts were
loaded (was it like this in KDE3?).

This broke because when the keysym is turned into a keycode, it asks
the current X display for it -- and before xmodmap maps them, the
keycode does not exist yet.

That's one thing down, and I hope I can get my kmilo patch done before
this weekend, as there are other issues with it :P

Either way, I've learned a _lot_ about how the whole kglobalaccel
system works now.

Thanks for the help.
-- 
Kelvie Wong
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic