Skip to content

Context menus with just a touchscreen

Sunday, 29 June 2008  |  mkruisselbrink

An issue I encountered while running plasma on my Neo1973 is the lack of a right mouse button (the screen can't really distinguish between ends of the stylus/which finger I use). A situation where this lack of an RMB is most clear is when you want to use some functionality that is only available in a context-menu. I've implemented one way this is sometimes handled on other devices: if you hold your 'left' button for more than a certain delay (without moving more than a certain distance), the widget will receive a context menu event instead of the original left mouse button down and up events. I've implemented this by installing an event filter on the application object that intercepts all mouse events and when it detects a left mouse press, this event is saved and not immediately passed to the program. Instead a timer is started. If the left mouse button is released or the mouse is moved far enough before the timer fires, the original event will be send, so the application will just think a normal click or drag happened, however if the timer fires before the button is released or the mouse is moved, both the press and release events will be eaten by the event filter and instead a QContextMenuEvent is sent.

Currently I've written this code inside the plasma application, but once I've moved it to be part of KApplication all KDE applications should be a lot more usable with just a left mouse button. When I do this I probably should also make the delay and distance parameters configurable.

(If you're wondering why my previous plasma screenshots didn't have a background image but these screenshots do, it is because I hadn't installed the 'qt4-plugin-imageformat-jpeg' package and thus jpeg loading didn't work; one of the disadvantages of a system where qt4 is split in 163 different packages, it is a lot of work to ensure everything I need on my phone is also actually installed)

(for anyone interested in the actual code (which is currently very ugly) I'm working on this code in a branch of kdelibs/kdebase at branches/work/soc-plasma-sff)