Krita Source Code Documentation
Loading...
Searching...
No Matches
KisGrabKeyboardFocusRecoveryWorkaround Class Reference

Background: For some reason, when using a combination of 'grabKeyboard' and 'releaseKeyboard' (e.g. the screen color sampling facility), the active window loses focus, or at least that is indicated by the change on the windows decorations (title bar, frame, etc.). Actually, the window seems to remain activated/focused regardless of the change on the window decorations. This is probably some bug on Qt/Plasma/X11 (a small and simple standalone test app gives the same results). More...

#include <KisGrabKeyboardFocusRecoveryWorkaround.h>

Classes

class  Private
 

Public Member Functions

void recoverFocus ()
 

Static Public Member Functions

static KisGrabKeyboardFocusRecoveryWorkaroundinstance ()
 

Private Member Functions

 KisGrabKeyboardFocusRecoveryWorkaround ()
 

Private Attributes

QScopedPointer< Privatem_d
 

Detailed Description

Background: For some reason, when using a combination of 'grabKeyboard' and 'releaseKeyboard' (e.g. the screen color sampling facility), the active window loses focus, or at least that is indicated by the change on the windows decorations (title bar, frame, etc.). Actually, the window seems to remain activated/focused regardless of the change on the window decorations. This is probably some bug on Qt/Plasma/X11 (a small and simple standalone test app gives the same results).

Workaround: This class uses a dummy top-level widget that is shown and closed immediately. This activates the dummy widget and then the previous window is reactivated, effectively restoring the focused look.

Usage: Use 'KisGrabKeyboardFocusRecoveryWorkaround::instance()->recoverFocus() when using a 'grabKeyboard'/'releaseKeyboard' if the top window seems to lose focus. Put that line right before 'releaseKeyboard' to prevent window decorations flickering.

Definition at line 34 of file KisGrabKeyboardFocusRecoveryWorkaround.h.

Constructor & Destructor Documentation

◆ KisGrabKeyboardFocusRecoveryWorkaround()

KisGrabKeyboardFocusRecoveryWorkaround::KisGrabKeyboardFocusRecoveryWorkaround ( )
private

Member Function Documentation

◆ instance()

KisGrabKeyboardFocusRecoveryWorkaround * KisGrabKeyboardFocusRecoveryWorkaround::instance ( )
static

Definition at line 32 of file KisGrabKeyboardFocusRecoveryWorkaround.cpp.

33{
34 static KisGrabKeyboardFocusRecoveryWorkaround *instance_ {nullptr};
35 if (!instance_) {
37 }
38 return instance_;
39}
Background: For some reason, when using a combination of 'grabKeyboard' and 'releaseKeyboard' (e....

References KisGrabKeyboardFocusRecoveryWorkaround().

◆ recoverFocus()

void KisGrabKeyboardFocusRecoveryWorkaround::recoverFocus ( )

Definition at line 41 of file KisGrabKeyboardFocusRecoveryWorkaround.cpp.

42{
43#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
44 // Get the top-most window
45 QWidget *activeWindow = qApp->activeWindow();
46 QWidget *mainWindow = activeWindow;
47 // It may be that the active window is some dialog (e.g. the color
48 // selector). If the dummy widget is set as a child of that one, it may
49 // interfere somehow with the task bar (a new entry may appear on some
50 // window managers). So we get the parent window and use that as parent of
51 // the dummy widget.
52 while (mainWindow->parentWidget()) {
53 mainWindow = mainWindow->parentWidget();
54 }
55 // The window flags have to be set as Qt::Dialog so that the workaround
56 // works as expected
57 m_d->dummyFocusRecoveryWidget->setParent(mainWindow, Qt::Dialog);
58 // Perform the following a couple of times to ensure good results. Doing it
59 // only once may fail sometimes for some unknown reason
60 for (int i = 0; i < 2; ++i) {
61 m_d->dummyFocusRecoveryWidget->show();
62 m_d->dummyFocusRecoveryWidget->close();
63 // Ensure that the previously activated window is again active. If the
64 // active window was a dialog (e.g. the color selector), then the parent
65 // window of the dummy widget will be the main window, so the main
66 // window may be active at this point
67 activeWindow->activateWindow();
68 }
69#endif
70}

References m_d.

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisGrabKeyboardFocusRecoveryWorkaround::m_d
private

Definition at line 43 of file KisGrabKeyboardFocusRecoveryWorkaround.h.


The documentation for this class was generated from the following files: