Commit 417c16fb authored by Andrey Butirsky's avatar Andrey Butirsky Committed by Ben Cooksley
Browse files

fix keyboard layout OSD on X

OSD for alternative shortcut has been removed in 9021b3cb,
because that approach don't work well with new layout applet.

New approach intends to make OSD behavior almost identical on X11/
Wayland - OSD should only pop up on keyboard shortcut and not on the
applet click/mouse wheeling.

Also, it implements OSD for the Main shortcut.

BUG: 408928
parent cad50cb7
Pipeline #111105 failed with stage
in 3 minutes and 3 seconds
......@@ -139,8 +139,9 @@ void KeyboardDaemon::registerListeners()
}
connect(xEventNotifier, &XInputEventNotifier::newPointerDevice, this, &KeyboardDaemon::configureMouse);
connect(xEventNotifier, &XInputEventNotifier::newKeyboardDevice, this, &KeyboardDaemon::configureKeyboard);
connect(xEventNotifier, &XEventNotifier::layoutMapChanged, this, &KeyboardDaemon::layoutMapChanged);
connect(xEventNotifier, &XEventNotifier::layoutChanged, this, &KeyboardDaemon::layoutChangedSlot);
connect(xEventNotifier, &XEventNotifier::layoutChangedByXKBShortcut, this, &KeyboardDaemon::layoutChangedByXKBShortcut);
connect(xEventNotifier, &XEventNotifier::layoutMapChanged, this, &KeyboardDaemon::layoutMapChanged);
xEventNotifier->start();
}
......@@ -151,6 +152,7 @@ void KeyboardDaemon::unregisterListeners()
disconnect(xEventNotifier, &XInputEventNotifier::newPointerDevice, this, &KeyboardDaemon::configureMouse);
disconnect(xEventNotifier, &XInputEventNotifier::newKeyboardDevice, this, &KeyboardDaemon::configureKeyboard);
disconnect(xEventNotifier, &XEventNotifier::layoutChanged, this, &KeyboardDaemon::layoutChangedSlot);
disconnect(xEventNotifier, &XEventNotifier::layoutChangedByXKBShortcut, this, &KeyboardDaemon::layoutChangedByXKBShortcut);
disconnect(xEventNotifier, &XEventNotifier::layoutMapChanged, this, &KeyboardDaemon::layoutMapChanged);
}
}
......@@ -162,6 +164,16 @@ void KeyboardDaemon::layoutChangedSlot()
Q_EMIT layoutChanged(getLayout());
}
void layoutChangedByXKBShortcut()
{
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"),
QStringLiteral("/org/kde/osdService"),
QStringLiteral("org.kde.osdService"),
QStringLiteral("kbdLayoutChanged"));
msg << QStringLiteral("layout switch");
QDBusConnection::sessionBus().asyncCall(msg);
}
void KeyboardDaemon::layoutMapChanged()
{
keyboardConfig->load();
......
......@@ -39,6 +39,7 @@ private Q_SLOTS:
void configureKeyboard();
void configureMouse();
void layoutChangedSlot();
void layoutChangedByXKBShortcut();
void layoutMapChanged();
bool setLayout(QAction *action);
......
......@@ -16,6 +16,11 @@
#include <X11/Xlib.h>
#include <X11/extensions/XKBrules.h>
// FIXME
#define XK_XKB_KEYS
#include <X11/keysymdef.h>
#include <xcb/xcb_keysyms.h>
#include <fixx11h.h>
// more information about the limit https://bugs.freedesktop.org/show_bug.cgi?id=19501
......@@ -304,8 +309,17 @@ bool XEventNotifier::isXkbEvent(xcb_generic_event_t *event)
return (event->response_type & ~0x80) == xkbOpcode + XkbEventCode;
}
bool XEventNotifier::processOtherEvents(xcb_generic_event_t * /*event*/)
bool XEventNotifier::processOtherEvents(xcb_generic_event_t *event)
{
if ( (event->response_type & ~0x80) == XCB_KEY_PRESS ) {
xcb_key_symbols_t *symbols = xcb_key_symbols_alloc(QX11Info::connection());
const xcb_keysym_t keySymX = xcb_key_press_lookup_keysym(symbols, reinterpret_cast<xcb_key_press_event_t *>(event), 0);
if (keySymX == XK_ISO_Next_Group) {
emit layoutChangedByXKBShortcut();
}
}
return true;
}
......@@ -360,6 +374,20 @@ int XEventNotifier::registerForXkbEvents(Display *display)
qCWarning(KCM_KEYBOARD) << "Couldn't select desired XKB events";
return false;
}
xcb_void_cookie_t cookie = xcb_grab_key_checked(QX11Info::connection(),
true,
QX11Info::appRootWindow(),
XCB_MOD_MASK_ANY,
XCB_GRAB_ANY,
XCB_GRAB_MODE_ASYNC,
XCB_GRAB_MODE_ASYNC);
QScopedPointer<xcb_generic_error_t, QScopedPointerPodDeleter> error(xcb_request_check(QX11Info::connection(), cookie));
if (!error.isNull()) {
qCWarning(KCM_KEYBOARD) << "Couldn't grab keys";
return false;
}
return true;
}
......
......@@ -43,6 +43,7 @@ class XEventNotifier : public QObject, public QAbstractNativeEventFilter
Q_SIGNALS:
void layoutChanged();
void layoutMapChanged();
void layoutChangedByXKBShortcut();
public:
XEventNotifier();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment