Skip to content

Add workaround for alt key on selection tools

There is an issue when pressing alt on the canvas, when using a tool. Usually it gives the focus to the menu bar to be able to use accelerator keys. This seems to happen only if you are not pressing another key or if you are not moving the cursor (maybe that is interpreted by qt as if the user probably don't want to use accelerator keys). So, to reiterate, it only happens if the cursor is still and there is no other key pressed (also if you use the global menu on kde it doesn't happen). When alt is pressed the first time, a key pressed event is sent, but a key release event is not sent when the key is released. The second time the key is pressed, no key pressed event is sent, but a key release event is sent when the key is released. Is as if the intermediate key release and press events were sent to the menu bar instead (at least that's my intuition).

The effect may not be an issue in certain tools, because of their use of modifiers, but in the selection tools it is very noticeable and cumbersome.

I tried filtering the events of the app, but I couldn't make it work. The same events that were not sent before weren't sent to the event filter. So I made a little helper class that tracks the state of the modifiers over time using a timer and qApp->queryKeyboardModifiers(). I can't say I like this solution, but it was the only thing I was capable of implementing that seems to work.

There is still another issue: if the alt key is pressed, then the focus seems captures by the menu bar, and the other modifiers seem to not work, util the mouse is moved and the key pressed... So instead of tracking the alt modifier only, I made it track every modifier, which turned out also to be less messy code-wise than tracking a single modifier.

I saw that the freehand tool kind of workaround the issue somehow, but I don't know if the same approach could be used here. Or maybe this should be solved as part of the "canvas focus" issue.

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.
Edited by Deif Lou

Merge request reports