Wednesday, September 24, 2008

shortcuts design .. by blog! =)

When KDE people find a problem, they tend to latch onto it like a pitbull with a new chew toy and pound the thing into submission with pragmatic design. Michael's been blogging about global shortcuts, approaching it that oh-so-KDE-fashion. Gotta love it. Since he blogged about making global shortcuts work with apps like Plasma, I figured I'd reply in my blog.

Design-by-blog, the brave new future! Well, we've also talked at length about it on IRC and on mailing lists, too .. so we're not quite in danger of ending up designing KDE by SMS messages yet ;)

Anyways ... Michael suggests the idea of application contexts for shortcuts, and that would be absolutely perfect for Plasma. As software becomes more flexible, more user-maleable (which is different than configurable), I think more and more of our software will end up having to think of things in terms of "contexts".

Mike ran through how Plasma, in the simple case, works right now:

"So let's see what is needed for plasma to work correctly. If an applet is added to an containment register the global shortcut. If you have no id to use create one. QUuid is very helpful in that regard as demonstrated by khotkeys. Associate the id with your applet. Optionally write the current set shortcut to disk after calling setGlobalShortcut() with the id. The shortcut you want is probably not the shortcut you get if the user configured it with the global shortcuts kcm. A choice you currently ignore and change back to whatever you have stored in your configuration."


This isn't quite how it works right now, though. Here's what we do:

  • Each widget/applet has a unique ID

  • If a shortcut is associated with a widget, we load it from the appletsrc file

  • That shortcut gets registered, and right now we just force it (related to current shortcomings that contexts should fix for us)

  • If the user changes the configuration, the shortcut action is told about this by the shortcuts kded module

  • That shortcut gets written out to the appletsrc for usage in the future

  • The shortcut is unregistered (via forgetGlobalShortcut()) when the widget goes away, which can happen when the user removes the widget, swaps layouts or just quits plasma (all three behaviours are quite different)



This isn't perfect, but contexts should resolve our remaining issues nicely and Plasma could then play even nicer with the rest of the desktop session. The remaining question will be when to call forgetGlobalShortcut, and I think the answer is that with contexts in place we'd be able to limit that to widget removal or widget layout exportation.

And yes, this has got to be one my least interesting blog entries in a while. =) Now all of you who read this know what kind of fun and crazy life I lead on the mailing lists. ;)

2 comments:

illissius said...

I was initially going to post this at Jansen's blog, but after dicking with OpenID for too many minutes, decided here was simpler.

I still think the media player example needs to be addressed somehow (which I'm pretty sure is just a specific case of a more general problem). I'll leave my developer hat off for now and just describe my use case/problem and let you guys figure out how to solve it.

This is sort of a combination of several different small issues. I have both Amarok 1.4 and v2 installed, but use only 1.4. So I start typing 'amarok' in krunner. I have since figured out that the blurry icon is the 1.4 version while the crisp one is v2, but if I press enter too soon rather than clicking the icon, it still ends up starting v2. So then I quickly close it, because it's not the one I started. Then I start 1.4, and for several days I'm pissed and mystified that my global shortcuts stopped working.

Several days later I read Michael Janson's blog and find out what's causing this, and that I can open the global shortcuts kcm and unset all of amarok 2's shortcuts, and so I do this. This seems like a pretty bad workaround, though.

info said...

Hi Illissius

This should not happen. The daemon kdedglobalaccel will not grab shortcuts if the associated application is not running. So if amarok2 is not running the shortcuts should be available for amarok 1.4 .

Mike