This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Assign plasmoid global shortcut to action

Tags: plasmoid, shortcut plasmoid, shortcut plasmoid, shortcut
(comma "," separated)
User avatar
simgunz
Registered Member
Posts
56
Karma
0
OS
Hi all,
I see that each plasmoid has a shortcut configuration page where it is possible to assign a global shortcut. I want to use this shortcut to let my plasmoid do something.
By default this shortcut should just bring the focus on the widget, even though none of the plasmoids I've tested do this.
Lancelot instead uses this shortcut to show the menu. I've tried to search in the code of lancelot, but I haven't find where it set this global shortcut. (Lancelot also provide a specific global shortcuts configuration page, but it's not want I need).

I've done this in my plasmoid (in the constructor):

Code: Select all
    //Setup the action
    m_toggleAction = new KAction("ToggleAction", this);
    //Add action to the plasmoid action collection
    addAction("ToggleAction", m_toggleAction);
    m_toggleAction->setGlobalShortcut(globalShortcut());
    connect(m_toggleAction, SIGNAL(triggered(bool)), this, SLOT(toggle()));


but nothing happens when I trigger the shortcut. Do anyone know what I'm missing?
User avatar
simgunz
Registered Member
Posts
56
Karma
0
OS
Actually the default behaviour of the global shortcut of bringing the focus to the plasmoid, can be see in action on the plasmoids on the panel; in fact when the global shortcut is triggered the plasmoid shows the extender. So also in the case of lancelot this is just the default behaviour, and no specific code has been written.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Please see http://api.kde.org/4.x-api/kdelibs-apid ... tml#l01556

In your constructor, it is not necessary for you to setup an action to handle the global shortcut assigned to your applet - this is done for you by Plasma::Applet. All you need to do is connect to the activate() signal which your applet will be sent.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
simgunz
Registered Member
Posts
56
Karma
0
OS
Perfect one-line-solution.

Actually in the Plasma Applet API in the documentation of the activate() signal, it's explicitly written that it's emitted when the global shortcut is activated. But I've completely missed that line.

Thanks.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]