1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
7 #include <linux/input.h>
9 #include "ui/events/event.h"
15 static const int kEventFlagFromModifiers
[] = {
16 EF_NONE
, // EVDEV_MODIFIER_NONE,
17 EF_CAPS_LOCK_DOWN
, // EVDEV_MODIFIER_CAPS_LOCK
18 EF_SHIFT_DOWN
, // EVDEV_MODIFIER_SHIFT
19 EF_CONTROL_DOWN
, // EVDEV_MODIFIER_CONTROL
20 EF_ALT_DOWN
, // EVDEV_MODIFIER_ALT
21 EF_LEFT_MOUSE_BUTTON
, // EVDEV_MODIFIER_LEFT_MOUSE_BUTTON
22 EF_MIDDLE_MOUSE_BUTTON
, // EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON
23 EF_RIGHT_MOUSE_BUTTON
, // EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON
24 EF_BACK_MOUSE_BUTTON
, // EVDEV_MODIFIER_BACK_MOUSE_BUTTON
25 EF_FORWARD_MOUSE_BUTTON
, // EVDEV_MODIFIER_FORWARD_MOUSE_BUTTON
26 EF_COMMAND_DOWN
, // EVDEV_MODIFIER_COMMAND
27 EF_ALTGR_DOWN
, // EVDEV_MODIFIER_ALTGR
28 EF_MOD3_DOWN
, // EVDEV_MODIFIER_MOD3
33 EventModifiersEvdev::EventModifiersEvdev() {
34 memset(modifiers_down_
, 0, sizeof(modifiers_down_
));
36 EventModifiersEvdev::~EventModifiersEvdev() {}
38 void EventModifiersEvdev::UpdateModifier(unsigned int modifier
, bool down
) {
39 DCHECK_LT(modifier
, EVDEV_NUM_MODIFIERS
);
42 modifiers_down_
[modifier
]++;
44 // Ignore spurious modifier "up" events. This might happen if the
45 // button is down during startup.
46 if (modifiers_down_
[modifier
])
47 modifiers_down_
[modifier
]--;
50 UpdateFlags(modifier
);
53 void EventModifiersEvdev::UpdateModifierLock(unsigned int modifier
, bool down
) {
54 DCHECK_LT(modifier
, EVDEV_NUM_MODIFIERS
);
57 modifier_flags_locked_
^= kEventFlagFromModifiers
[modifier
];
59 UpdateFlags(modifier
);
62 void EventModifiersEvdev::SetModifierLock(unsigned int modifier
, bool locked
) {
63 DCHECK_LT(modifier
, EVDEV_NUM_MODIFIERS
);
66 modifier_flags_locked_
|= kEventFlagFromModifiers
[modifier
];
68 modifier_flags_locked_
&= ~kEventFlagFromModifiers
[modifier
];
70 UpdateFlags(modifier
);
73 void EventModifiersEvdev::UpdateFlags(unsigned int modifier
) {
74 int mask
= kEventFlagFromModifiers
[modifier
];
75 bool down
= modifiers_down_
[modifier
];
76 bool locked
= (modifier_flags_locked_
& mask
);
78 modifier_flags_
|= mask
;
80 modifier_flags_
&= ~mask
;
83 int EventModifiersEvdev::GetModifierFlags() { return modifier_flags_
; }
86 int EventModifiersEvdev::GetEventFlagFromModifier(unsigned int modifier
) {
87 return kEventFlagFromModifiers
[modifier
];