Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Unified Diff: remoting/host/input_injector_x11.cc

Issue 2844533002: When receiving a key event on Linux, set host lock state to match client's (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/input_injector_x11.cc
diff --git a/remoting/host/input_injector_x11.cc b/remoting/host/input_injector_x11.cc
index 2e4bdc6880e74f2795edbed05a7ab8e5cf8d0fe5..df871ca6cc711f5cde7cc6a2571dbabd8da11977 100644
--- a/remoting/host/input_injector_x11.cc
+++ b/remoting/host/input_injector_x11.cc
@@ -10,6 +10,7 @@
#include <X11/extensions/XTest.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
+#include <X11/keysym.h>
#undef Status // Xlib.h #defines this, which breaks protobuf headers.
#include <set>
@@ -121,6 +122,9 @@ class InputInjectorX11 : public InputInjector {
// Enables or disables keyboard auto-repeat globally.
void SetAutoRepeatEnabled(bool enabled);
+ // Sets the keyboard lock states to those provided.
+ void SetLockStates(uint32_t states);
+
void InjectScrollWheelClicks(int button, int count);
// Compensates for global button mappings and resets the XTest device
// mapping.
@@ -276,6 +280,10 @@ void InputInjectorX11::Core::InjectKeyEvent(const KeyEvent& event) {
XTestFakeKeyEvent(display_, keycode, False, CurrentTime);
}
+ if (event.has_lock_states()) {
+ SetLockStates(event.lock_states());
+ }
+
if (pressed_keys_.empty()) {
// Disable auto-repeat, if necessary, to avoid triggering auto-repeat
// if network congestion delays the key-up event from the client.
@@ -347,6 +355,20 @@ void InputInjectorX11::Core::SetAutoRepeatEnabled(bool mode) {
XChangeKeyboardControl(display_, KBAutoRepeatMode, &control);
}
+void InputInjectorX11::Core::SetLockStates(uint32_t states) {
+ unsigned int caps_lock_mask = XkbKeysymToModifiers(display_, XK_Caps_Lock);
+ unsigned int num_lock_mask = XkbKeysymToModifiers(display_, XK_Num_Lock);
+ unsigned int lock_values = 0;
+ if (states & protocol::KeyEvent::LOCK_STATES_CAPSLOCK) {
+ lock_values |= caps_lock_mask;
+ }
+ if (states & protocol::KeyEvent::LOCK_STATES_NUMLOCK) {
+ lock_values |= num_lock_mask;
+ }
+ XkbLockModifiers(display_, XkbUseCoreKbd, caps_lock_mask | num_lock_mask,
+ lock_values);
rkjnsn 2017/04/25 19:25:03 We could check the existing states first instead o
Jamie 2017/04/25 20:15:57 I think this is fine. The documentation suggests t
+}
+
void InputInjectorX11::Core::InjectScrollWheelClicks(int button, int count) {
if (button < 0) {
LOG(WARNING) << "Ignoring unmapped scroll wheel button";
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698