Michael Leupold has been working on a class for kdelibs that can report on keyboard modifier (and mouse button) states, the same thing that the keyboard status widget does internally. The class should appear in KDE 4.3, and this is quite nice since it gives us a platform-neutral way to do things like show when the caps lock is on in dialogs with passwords without reimplementing the code to do that over and over.
When Michael told me he was working on this in response to my last blog on the keyboard state widget I sat back and thought, "Why the heck am I dragging myself over the coals and modifying the 986 line of code literal-port-from-kicker thing in kdreview?! I should write a small DataEngine around Michael's class and then do the widget in JavaScript: it's just a collection of buttons, after all!"
So today while the P-man was off at a friend's place I scurried off to a coffee shop and sat down to work on the DataEngine part. Other than half an hour or so spent on some phone calls from friends and answering Plasma bug days questions, I was able to just sit and hack on it while sipping cappuccinos for two hours. The end result is a complete DataEngine plus Services in 198 lines of C++ that is (thanks to plamaengineexplorer) fully tested and working flawlessly.
Now any Plasma component in any language can easily interact with keyboard and mouse button states. You can even latch and lock modifier keys ...
... which means I'm now ready to play with some JavaScript. Using the service architecture I expect a dozen lines of code or so for the buttons to lock/unlock/latch/unlatch the corresponding keys and another dozen or three lines at most to create the buttons, hook them up to the engine and get the layout orientation right (e.g. vertical for Vertical constrained containments). When done this will be the first JavaScript plasmoid to ship by default in kdebase. I can't wait to see what limitations and bugs I run into in the process. ;)
I think I'll also take the opportunity to write a Techbase article on writing Plasmoids in JavaScript as I go, documenting what I do step by step.
With Michael's code, the whole thing should be less than 650 lines code, which is a 35% savings over the old keyboard kicker applet and done in a way that any KDE app or Plasmoid can take advantage of.
Huzzah.
Saturday, April 25, 2009
Subscribe to:
Post Comments (Atom)

9 comments:
This reminds me something I found useful in Windows 2000 (and XP ?).
When Windows starts and you keep the shift key down, the programs configured to be automatically launched at start are ignored. This is cool when you want to quickly launch a session or when you have a buggy app in autostart (or the famous "reboot-shortcut-in-autostart" joke)
Even if this is an hidden feature, it could be interesting to have it in KDE :-)
I don't know if this new project enables this, but I do have a request for KDE 4.3:
Make it so that keyboard shortcuts can combine mouse + keyboard combinations. For example, the desktop zoom feature on Compiz can be configured to use META+Mouse Wheel to zoom in & out. Also, the Mouse Mark effect would be vastly simpler to use if it could be activated using a key combo + mouse button event.
Does this new data engine make that type of feature easy to implement?
You never mentioned the name of Michael's class or where to find it. Inquiry minds want to know.
@DanaKil: decent idea; would belong in ksmserver and with this new class it would be trivial to implement
@Chuckula: no, that's something else entirely unfortunately :)
@Parker: oops.. :) KModifierKeyInfo is the name of the class and it will be in kdereview tomorrow ..
On KDE 4.2 there's no way to add a javascript plasmoid, right? I just want to add a simple iGoogle gadget to my Desktop, and can't find the way to do it.
"Get new applets" in Plasma has an option to use a local "web component", but I have no idea what format that should be in. The file picker wants a zip file.
The only way I could find was with the mini-web-browser, by opening a local HTML file with the javascript in it.
@Pablo: "On KDE 4.2 there's no way to add a javascript plasmoid, right? I just want to add a simple iGoogle gadget to my Desktop, and can't find the way to do it."
yes, javascript plasmoids are supported; however iGoogle gadgets don't work out of the box as they have their own packaging system. a PackageStructure for them would solve that.
what we do support right now in 4.2 (that is relevant to your comment) is javascript plasmoids, html/css/js plasmoids and Google Gadgets.
if you can accesss an html url for the iGoogle gadget, however, you could load it up in the web plasmoid? :)
Yes, that's what I've been doing. But the web plasmoid has a fixed size, and it's too big. I tried to do it with this http://www.kde-look.org/content/show.php/Scripted+HTML?content=102052 applet, but it does not work on KDE 4.2.
I thought that iGoogle gadgets were just a few lines of javascript. Could you post a link to an example javascript plasmoid that can actually be installed with plasmapkg? Maybe I can edit the gadget to make it comply.
(I´m talking about a quite a useful gadget: the Labs Task. http://www.google.com/ig/modules/tasks.xml )
Is nice to see this post here. I passed the last week patching kosd to react on brightness, numlock and capslock keys. I really miss this class when I working on this task. I expect to integrate KModifierKeyInfo in my code, but I don't know if I will have time to this.
I have some questions and I want to raise one point about my experience extending kosd.
- I saw a similar code in kbstateapplet and in kxkb, they will use the new class ?
- This class shouldn't be related with kclengine some how ?
- I think this class will solve the problem with *lock keys but brightness keys
will continue to be a problem for a while if it depends of QT.
http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id=191318
http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id=195723
http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id=230168
http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id=245021
Ok, I'll found an answer to my own question. I post it here in case anyone finds it useful.
http://chani.ccdevnet.org/plasma/lfnw/kde2.odp
Post a Comment