Home | History | Annotate | Download | only in evdev
      1 // Copyright 2013 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.
      4 
      5 #ifndef UI_EVENTS_OZONE_EVDEV_EVENT_MODIFIERS_H_
      6 #define UI_EVENTS_OZONE_EVDEV_EVENT_MODIFIERS_H_
      7 
      8 #include "ui/events/events_export.h"
      9 #include "ui/events/ozone/event_converter_ozone.h"
     10 
     11 namespace ui {
     12 
     13 enum {
     14   EVDEV_MODIFIER_NONE,
     15   EVDEV_MODIFIER_CAPS_LOCK,
     16   EVDEV_MODIFIER_SHIFT,
     17   EVDEV_MODIFIER_CONTROL,
     18   EVDEV_MODIFIER_ALT,
     19   EVDEV_MODIFIER_LEFT_MOUSE_BUTTON,
     20   EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON,
     21   EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON,
     22   EVDEV_MODIFIER_COMMAND,
     23   EVDEV_MODIFIER_ALTGR,
     24   EVDEV_NUM_MODIFIERS
     25 };
     26 
     27 // Modifier key state for Evdev.
     28 //
     29 // Chrome relies on the underlying OS to interpret modifier keys such as Shift,
     30 // Ctrl, and Alt. The Linux input subsystem does not assign any special meaning
     31 // to these keys, so this work must happen at a higher layer (normally X11 or
     32 // the console driver). When using evdev directly, we must do it ourselves.
     33 //
     34 // The modifier state is shared between all input devices connected to the
     35 // system. This is to support actions such as Shift-Clicking that use multiple
     36 // devices.
     37 //
     38 // Normally a modifier is set if any of the keys or buttons assigned to it are
     39 // currently pressed. However some keys toggle a persistent "lock" for the
     40 // modifier instead, such as CapsLock. If a modifier is "locked" then its state
     41 // is inverted until it is unlocked.
     42 class EVENTS_EXPORT EventModifiersEvdev {
     43  public:
     44   EventModifiersEvdev();
     45   ~EventModifiersEvdev();
     46 
     47   // Record key press or release for regular modifier key (shift, alt, etc).
     48   void UpdateModifier(unsigned int modifier, bool down);
     49 
     50   // Record key press or release for locking modifier key (caps lock).
     51   void UpdateModifierLock(unsigned int modifier, bool down);
     52 
     53   // Return current flags to use for incoming events.
     54   int GetModifierFlags();
     55 
     56  private:
     57   // Count of keys pressed for each modifier.
     58   int modifiers_down_[EVDEV_NUM_MODIFIERS];
     59 
     60   // Mask of modifier flags currently "locked".
     61   int modifier_flags_locked_;
     62 
     63   // Mask of modifier flags currently active (nonzero keys pressed xor locked).
     64   int modifier_flags_;
     65 
     66   // Update modifier_flags_ from modifiers_down_ and modifier_flags_locked_.
     67   void UpdateFlags(unsigned int modifier);
     68 
     69   DISALLOW_COPY_AND_ASSIGN(EventModifiersEvdev);
     70 };
     71 
     72 }  // namspace ui
     73 
     74 #endif  // UI_EVENTS_OZONE_EVDEV_EVENT_MODIFIERS_H_
     75