From 6fdc02fae21517f7a773b15529d6591804fe3d25 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 20 Dec 2023 10:24:26 +0000 Subject: [PATCH] Updated key handling for x11 adaptor Fixed build error with latest key handling Fixed keyboard modifiers to work consistently with other profiles Change-Id: Ic21876922beed25847a89e1332e36d6aced3aafc --- dali/internal/window-system/x11/window-base-x.h | 4 +- .../internal/window-system/x11/window-system-x.cpp | 63 +++++++++++++++++++--- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/dali/internal/window-system/x11/window-base-x.h b/dali/internal/window-system/x11/window-base-x.h index 867b7ad..cec66a3 100644 --- a/dali/internal/window-system/x11/window-base-x.h +++ b/dali/internal/window-system/x11/window-base-x.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_WINDOW_SYSTEM_X11_WINDOW_BASE_X_H /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,7 +100,7 @@ public: /** * Create the dali key event from the X11 event */ - static Integration::KeyEvent CreateKeyEvent(WindowSystemX::X11KeyEvent* keyEvent, Integration::KeyEvent::State state); + Integration::KeyEvent CreateKeyEvent(WindowSystemX::X11KeyEvent* keyEvent, Integration::KeyEvent::State state); /** * @brief Called when a key down is received. diff --git a/dali/internal/window-system/x11/window-system-x.cpp b/dali/internal/window-system/x11/window-system-x.cpp index 0f5f66c..3309edb 100644 --- a/dali/internal/window-system/x11/window-system-x.cpp +++ b/dali/internal/window-system/x11/window-system-x.cpp @@ -383,7 +383,7 @@ void LeaveNotifyEventHandler(const XEvent* xevent) HandlePointerMove(xevent->xcrossing.x, xevent->xcrossing.y, xevent->xcrossing.time, xevent->xcrossing.subwindow ? xevent->xcrossing.subwindow : xevent->xcrossing.window); } -void ConvertKeyEvent(const XEvent* xEvent, WindowSystemX::X11KeyEvent& keyEvent) +void ConvertKeyEvent(const XEvent* xEvent, WindowSystemX::X11KeyEvent& keyEvent, bool down) { const XKeyEvent* xKeyEvent = &(xEvent->xkey); @@ -402,10 +402,59 @@ void ConvertKeyEvent(const XEvent* xEvent, WindowSystemX::X11KeyEvent& keyEvent) keyEvent.keyname = keyname; } - keyEvent.timestamp = xKeyEvent->time; - keyEvent.modifiers = xKeyEvent->state; // @todo add own modifier list - keyEvent.window = xKeyEvent->window; - keyEvent.event = xEvent; + static int modifiers = 0; + switch(keySymbol) + { + case XK_Shift_L: + { + modifiers &= 0xFE; + modifiers |= down ? 0x01 : 0; + break; + } + case XK_Shift_R: + { + modifiers &= 0xFD; + modifiers |= down ? 0x02 : 0; + break; + } + case XK_Control_L: + { + modifiers &= 0xFB; + modifiers |= down ? 0x04 : 0; + break; + } + case XK_Control_R: + { + modifiers &= 0xF7; + modifiers |= down ? 0x08 : 0; + break; + } + case XK_Alt_L: + { + modifiers &= 0xEF; + modifiers |= down ? 0x10 : 0; + break; + } + case XK_Alt_R: + { + modifiers &= 0xDF; + modifiers |= down ? 0x20 : 0; + break; + } + case XK_ISO_Level3_Shift: + { + modifiers &= 0xDF; + modifiers |= down ? 0x20 : 0; + break; + } // Alt Graphics + } + int shiftModifier = (modifiers & 0x03) != 0; + int controlModifier = (modifiers & 0x0C) != 0; + int altModifier = (modifiers & 0x30) != 0; + keyEvent.timestamp = xKeyEvent->time; + keyEvent.modifiers = shiftModifier | controlModifier << 1 | altModifier << 2; + keyEvent.window = xKeyEvent->window; + keyEvent.event = xEvent; KeySym keySymbol2; XComposeStatus composeStatus; @@ -432,14 +481,14 @@ void ConvertKeyEvent(const XEvent* xEvent, WindowSystemX::X11KeyEvent& keyEvent) void KeyPressEventHandler(const XEvent* xevent) { WindowSystemX::X11KeyEvent x11KeyEvent; - ConvertKeyEvent(xevent, x11KeyEvent); + ConvertKeyEvent(xevent, x11KeyEvent, true); GetImplementation().TriggerEventHandler(WindowSystemBase::Event::KEY_DOWN, x11KeyEvent); } void KeyReleaseEventHandler(const XEvent* xevent) { WindowSystemX::X11KeyEvent x11KeyEvent; - ConvertKeyEvent(xevent, x11KeyEvent); + ConvertKeyEvent(xevent, x11KeyEvent, false); GetImplementation().TriggerEventHandler(WindowSystemBase::Event::KEY_UP, x11KeyEvent); } -- 2.7.4