kranewm

An ICCCM & EWMH compliant X11 reparenting, dynamic window manager, written in C++
git clone git://git.deurzen.net/kranewm
Log | Files | Refs | LICENSE

input.hh (6609B)


      1 #ifndef __WINSYS_INPUT_H_GUARD__
      2 #define __WINSYS_INPUT_H_GUARD__
      3 
      4 #include "common.hh"
      5 #include "window.hh"
      6 #include "geometry.hh"
      7 
      8 #include <unordered_set>
      9 #include <optional>
     10 #include <numeric>
     11 
     12 namespace winsys
     13 {
     14 
     15     enum class Key
     16     {
     17         Any,
     18 		BackSpace,
     19 		Tab,
     20 		Clear,
     21 		Return,
     22 		Shift,
     23 		Control,
     24 		Alt,
     25 		Super,
     26 		Menu,
     27 		Pause,
     28 		CapsLock,
     29 		Escape,
     30 		Space,
     31         ExclamationMark,
     32         QuotationMark,
     33         QuestionMark,
     34         NumberSign,
     35         DollarSign,
     36         PercentSign,
     37         AtSign,
     38         Ampersand,
     39         Apostrophe,
     40         LeftParenthesis,
     41         RightParenthesis,
     42         LeftBracket,
     43         RightBracket,
     44         LeftBrace,
     45         RightBrace,
     46         Underscore,
     47         Grave,
     48         Bar,
     49         Tilde,
     50         QuoteLeft,
     51         Asterisk,
     52         Plus,
     53         Comma,
     54         Minus,
     55         Period,
     56         Slash,
     57         BackSlash,
     58         Colon,
     59         SemiColon,
     60         Less,
     61         Equal,
     62         Greater,
     63 		PageUp,
     64 		PageDown,
     65 		End,
     66 		Home,
     67 		Left,
     68 		Up,
     69 		Right,
     70 		Down,
     71 		Select,
     72 		Print,
     73 		Execute,
     74 		PrintScreen,
     75 		Insert,
     76 		Delete,
     77 		Help,
     78 		Zero,
     79 		One,
     80 		Two,
     81 		Three,
     82 		Four,
     83 		Five,
     84 		Six,
     85 		Seven,
     86 		Eight,
     87 		Nine,
     88 		A,
     89 		B,
     90 		C,
     91 		D,
     92 		E,
     93 		F,
     94 		G,
     95 		H,
     96 		I,
     97 		J,
     98 		K,
     99 		L,
    100 		M,
    101 		N,
    102 		O,
    103 		P,
    104 		Q,
    105 		R,
    106 		S,
    107 		T,
    108 		U,
    109 		V,
    110 		W,
    111 		X,
    112 		Y,
    113 		Z,
    114 		NumPad0,
    115 		NumPad1,
    116 		NumPad2,
    117 		NumPad3,
    118 		NumPad4,
    119 		NumPad5,
    120 		NumPad6,
    121 		NumPad7,
    122 		NumPad8,
    123 		NumPad9,
    124 		Multiply,
    125 		Add,
    126 		Seperator,
    127 		Subtract,
    128 		Decimal,
    129 		Divide,
    130 		F1,
    131 		F2,
    132 		F3,
    133 		F4,
    134 		F5,
    135 		F6,
    136 		F7,
    137 		F8,
    138 		F9,
    139 		F10,
    140 		F11,
    141 		F12,
    142 		F13,
    143 		F14,
    144 		F15,
    145 		F16,
    146 		F17,
    147 		F18,
    148 		F19,
    149 		F20,
    150 		F21,
    151 		F22,
    152 		F23,
    153 		F24,
    154 		Numlock,
    155 		ScrollLock,
    156 		LeftShift,
    157 		RightShift,
    158 		LeftControl,
    159 		RightContol,
    160 		LeftAlt,
    161 		RightAlt,
    162 		LeftSuper,
    163 		RightSuper,
    164 		BrowserBack,
    165 		BrowserForward,
    166 		BrowserRefresh,
    167 		BrowserStop,
    168 		BrowserSearch,
    169 		BrowserFavorites,
    170 		BrowserHome,
    171 		VolumeMute,
    172 		VolumeDown,
    173 		VolumeUp,
    174 		MicMute,
    175 		NextTrack,
    176 		PreviousTrack,
    177 		StopMedia,
    178 		PlayPause,
    179 		BrightnessDown,
    180 		BrightnessUp,
    181 		KeyboardBrightnessDown,
    182 		KeyboardBrightnessUp,
    183 		LaunchMail,
    184 		SelectMedia,
    185 		LaunchAppA,
    186 		LaunchAppB,
    187 		LaunchAppC,
    188 		LaunchAppD,
    189 		LaunchAppE,
    190 		LaunchAppF,
    191 		LaunchApp0,
    192 		LaunchApp1,
    193 		LaunchApp2,
    194 		LaunchApp3,
    195 		LaunchApp4,
    196 		LaunchApp5,
    197 		LaunchApp6,
    198 		LaunchApp7,
    199 		LaunchApp8,
    200 		LaunchApp9
    201     };
    202 
    203     enum class Button
    204     {
    205         Left,
    206         Middle,
    207         Right,
    208         ScrollUp,
    209         ScrollDown,
    210         Backward,
    211         Forward
    212     };
    213 
    214     enum Modifier
    215     {
    216         Ctrl       = 1 << 0,
    217         Shift      = 1 << 1,
    218         Alt        = 1 << 2,
    219         AltGr      = 1 << 3,
    220         Super      = 1 << 4,
    221         NumLock    = 1 << 5,
    222         ScrollLock = 1 << 6,
    223 #ifndef DEBUG
    224         Main       = Super,
    225         Sec        = Alt
    226 #else
    227         Main       = Alt,
    228         Sec        = Super
    229 #endif
    230     };
    231 
    232     inline Modifier
    233     operator|(Modifier lhs, Modifier rhs)
    234     {
    235         return static_cast<Modifier>(
    236             static_cast<std::size_t>(lhs)
    237                 | static_cast<std::size_t>(rhs)
    238         );
    239     }
    240 
    241     struct KeyInput final
    242     {
    243         Key key;
    244         std::unordered_set<Modifier> modifiers;
    245     };
    246 
    247     struct KeyCapture final
    248     {
    249         KeyInput input;
    250         std::optional<Window> window;
    251     };
    252 
    253     struct MouseInput final
    254     {
    255         enum class MouseInputTarget
    256         {
    257             Global,
    258             Root,
    259             Client
    260         };
    261 
    262         MouseInputTarget target;
    263         Button button;
    264         std::unordered_set<Modifier> modifiers;
    265     };
    266 
    267     struct MouseCapture final
    268     {
    269         enum class MouseCaptureKind
    270         {
    271             Press,
    272             Release,
    273             Motion
    274         };
    275 
    276         MouseCaptureKind kind;
    277         MouseInput input;
    278         std::optional<Window> window;
    279         Pos root_rpos;
    280     };
    281 
    282     enum Grip
    283     {
    284         Left   = 1 << 0,
    285         Right  = 1 << 1,
    286         Top    = 1 << 2,
    287         Bottom = 1 << 3,
    288     };
    289 
    290     inline Grip
    291     operator|(Grip lhs, Grip rhs)
    292     {
    293         return static_cast<Grip>(
    294             static_cast<std::size_t>(lhs)
    295                 | static_cast<std::size_t>(rhs)
    296         );
    297     }
    298 
    299     inline Grip&
    300     operator|=(Grip& lhs, Grip rhs)
    301     {
    302         lhs = static_cast<Grip>(
    303             static_cast<std::size_t>(lhs)
    304                 | static_cast<std::size_t>(rhs)
    305         );
    306 
    307         return lhs;
    308     }
    309 
    310     inline Grip
    311     operator&(Grip lhs, Grip rhs)
    312     {
    313         return static_cast<Grip>(
    314             static_cast<std::size_t>(lhs)
    315                 & static_cast<std::size_t>(rhs)
    316         );
    317     }
    318 
    319     inline Grip&
    320     operator&=(Grip& lhs, Grip rhs)
    321     {
    322         lhs = static_cast<Grip>(
    323             static_cast<std::size_t>(lhs)
    324                 & static_cast<std::size_t>(rhs)
    325         );
    326 
    327         return lhs;
    328     }
    329 
    330     inline bool
    331     operator==(KeyInput const& lhs, KeyInput const& rhs)
    332     {
    333         return lhs.key == rhs.key
    334             && lhs.modifiers == rhs.modifiers;
    335     }
    336 
    337     inline bool
    338     operator==(MouseInput const& lhs, MouseInput const& rhs)
    339     {
    340         return lhs.target == rhs.target
    341             && lhs.button == rhs.button
    342             && lhs.modifiers == rhs.modifiers;
    343     }
    344 
    345 }
    346 
    347 namespace std
    348 {
    349     template <>
    350     struct hash<winsys::KeyInput>
    351     {
    352         std::size_t
    353         operator()(winsys::KeyInput const& input) const
    354         {
    355             std::size_t key_hash = std::hash<winsys::Key>()(input.key);
    356             std::size_t modifiers_hash = std::hash<std::size_t>()(
    357                 std::accumulate(
    358                     input.modifiers.begin(),
    359                     input.modifiers.end(),
    360                     static_cast<winsys::Modifier>(0),
    361                     std::bit_or<winsys::Modifier>()
    362                 )
    363             );
    364 
    365             return key_hash ^ modifiers_hash;
    366         }
    367     };
    368 }
    369 
    370 namespace std
    371 {
    372     template <>
    373     struct hash<winsys::MouseInput>
    374     {
    375         std::size_t
    376         operator()(winsys::MouseInput const& input) const
    377         {
    378             std::size_t target_hash = std::hash<winsys::MouseInput::MouseInputTarget>()(input.target);
    379             std::size_t button_hash = std::hash<winsys::Button>()(input.button);
    380             std::size_t modifiers_hash = std::hash<std::size_t>()(
    381                 std::accumulate(
    382                     input.modifiers.begin(),
    383                     input.modifiers.end(),
    384                     static_cast<winsys::Modifier>(0),
    385                     std::bit_or<winsys::Modifier>()
    386                 )
    387             );
    388 
    389             return target_hash ^ button_hash ^ modifiers_hash;
    390         }
    391     };
    392 }
    393 
    394 #endif//__WINSYS_INPUT_H_GUARD__