Grab all possible keyboard modifiers for window commands

BUG: 424272
FIXED-IN: 5.19.4
This commit is contained in:
Vlad Zahorodnii 2020-07-16 14:01:08 +03:00 committed by Vlad Zahorodnii
parent 3609a029ea
commit 4921acf45a
2 changed files with 46 additions and 24 deletions

View file

@ -820,24 +820,45 @@ void X11Client::leaveNotifyEvent(xcb_leave_notify_event_t *e)
} }
} }
static uint16_t x11CommandAllModifier()
{
switch (options->commandAllModifier()) {
case Qt::MetaModifier:
return KKeyServer::modXMeta();
case Qt::AltModifier:
return KKeyServer::modXAlt();
default:
return 0;
}
}
#define XCapL KKeyServer::modXLock() #define XCapL KKeyServer::modXLock()
#define XNumL KKeyServer::modXNumLock() #define XNumL KKeyServer::modXNumLock()
#define XScrL KKeyServer::modXScrollLock() #define XScrL KKeyServer::modXScrollLock()
void X11Client::grabButton(Qt::KeyboardModifier modifier, uint8_t button) void X11Client::establishCommandWindowGrab(uint8_t button)
{ {
uint16_t x11Modifier; // Unfortunately there are a lot of possible modifier combinations that we need to take into
// account. We tackle that problem in a kind of smart way. First, we grab the button with all
// possible modifiers, then we ungrab the ones that are relevant only to commandAllx().
switch (modifier) { m_wrapper.grabButton(XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_MOD_MASK_ANY, button);
case Qt::MetaModifier:
x11Modifier = KKeyServer::modXMeta(); uint16_t x11Modifier = x11CommandAllModifier();
break;
case Qt::AltModifier: unsigned int mods[ 8 ] = {
x11Modifier = KKeyServer::modXAlt(); 0, XCapL, XNumL, XNumL | XCapL,
break; XScrL, XScrL | XCapL,
default: XScrL | XNumL, XScrL | XNumL | XCapL
x11Modifier = 0; };
break; for (int i = 0;
} i < 8;
++i)
m_wrapper.ungrabButton(x11Modifier | mods[ i ], button);
}
void X11Client::establishCommandAllGrab(uint8_t button)
{
uint16_t x11Modifier = x11CommandAllModifier();
unsigned int mods[ 8 ] = { unsigned int mods[ 8 ] = {
0, XCapL, XNumL, XNumL | XCapL, 0, XCapL, XNumL, XNumL | XCapL,
@ -872,17 +893,17 @@ void X11Client::updateMouseGrab()
if ((options->focusPolicyIsReasonable() && !isActive()) || if ((options->focusPolicyIsReasonable() && !isActive()) ||
(options->isClickRaise() && !isMostRecentlyRaised())) { (options->isClickRaise() && !isMostRecentlyRaised())) {
if (options->commandWindow1() != Options::MouseNothing) { if (options->commandWindow1() != Options::MouseNothing) {
grabButton(Qt::NoModifier, XCB_BUTTON_INDEX_1); establishCommandWindowGrab(XCB_BUTTON_INDEX_1);
} }
if (options->commandWindow2() != Options::MouseNothing) { if (options->commandWindow2() != Options::MouseNothing) {
grabButton(Qt::NoModifier, XCB_BUTTON_INDEX_2); establishCommandWindowGrab(XCB_BUTTON_INDEX_2);
} }
if (options->commandWindow3() != Options::MouseNothing) { if (options->commandWindow3() != Options::MouseNothing) {
grabButton(Qt::NoModifier, XCB_BUTTON_INDEX_3); establishCommandWindowGrab(XCB_BUTTON_INDEX_3);
} }
if (options->commandWindowWheel() != Options::MouseNothing) { if (options->commandWindowWheel() != Options::MouseNothing) {
grabButton(Qt::NoModifier, XCB_BUTTON_INDEX_4); establishCommandWindowGrab(XCB_BUTTON_INDEX_4);
grabButton(Qt::NoModifier, XCB_BUTTON_INDEX_5); establishCommandWindowGrab(XCB_BUTTON_INDEX_5);
} }
} }
@ -892,17 +913,17 @@ void X11Client::updateMouseGrab()
if (!workspace()->globalShortcutsDisabled()) { if (!workspace()->globalShortcutsDisabled()) {
if (options->commandAll1() != Options::MouseNothing) { if (options->commandAll1() != Options::MouseNothing) {
grabButton(options->commandAllModifier(), XCB_BUTTON_INDEX_1); establishCommandAllGrab(XCB_BUTTON_INDEX_1);
} }
if (options->commandAll2() != Options::MouseNothing) { if (options->commandAll2() != Options::MouseNothing) {
grabButton(options->commandAllModifier(), XCB_BUTTON_INDEX_2); establishCommandAllGrab(XCB_BUTTON_INDEX_2);
} }
if (options->commandAll3() != Options::MouseNothing) { if (options->commandAll3() != Options::MouseNothing) {
grabButton(options->commandAllModifier(), XCB_BUTTON_INDEX_3); establishCommandAllGrab(XCB_BUTTON_INDEX_3);
} }
if (options->commandAllWheel() != Options::MouseWheelNothing) { if (options->commandAllWheel() != Options::MouseWheelNothing) {
grabButton(options->commandAllModifier(), XCB_BUTTON_INDEX_4); establishCommandAllGrab(XCB_BUTTON_INDEX_4);
grabButton(options->commandAllModifier(), XCB_BUTTON_INDEX_5); establishCommandAllGrab(XCB_BUTTON_INDEX_5);
} }
} }
} }

View file

@ -416,7 +416,8 @@ private:
void sendSyncRequest(); void sendSyncRequest();
void leaveMoveResize() override; void leaveMoveResize() override;
void positionGeometryTip() override; void positionGeometryTip() override;
void grabButton(Qt::KeyboardModifier modifier, uint8_t button); void establishCommandWindowGrab(uint8_t button);
void establishCommandAllGrab(uint8_t button);
void resizeDecoration(); void resizeDecoration();
void createDecoration(const QRect &oldgeom) override; void createDecoration(const QRect &oldgeom) override;