src/Input.hh (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
// -*- mode: C++; indent-tabs-mode: nil; -*- // Input.hh for Blackbox - an X11 Window manager // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org> // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. #ifndef __Input_hh #define __Input_hh extern "C" { #include <X11/Xlib.h> #include <X11/Xutil.h> } #include <list> class Blackbox; class BlackboxWindow; class BInput { public: enum MouseEvent { InvalidEvent = -1, IconifyButtonClick, MaximizeButtonClick, CloseButtonClick, WindowFramePress, WindowTitlePress, WindowTitleDoublePress, WindowClientPress, RootWindowPress, WindowDrag, WindowTitleDrag, WindowHandleDrag, WindowLeftGripDrag, WindowRightGripDrag, NUM_MOUSEEVENTS }; enum Action { NoAction = 0, Raise, Lower, Shade, Unshade, Stick, Unstick, Focus, Iconify, Close, ShowWindowMenu, NextWorkspace, PrevWorkspace, BeginMove, BeginResizeUL, BeginResizeUR, BeginResizeLL, BeginResizeLR, BeginResizeRelative, // picks a corner based on the mouse cursor's position ToggleMaximizeVert, ToggleMaximizeHoriz, ToggleMaximize, ToggleShade, ToggleStick, NUM_ACTIONS }; struct KeyBinding { unsigned int button; unsigned int state; // for keyboard events, this is applied to the focused window. // for mouse events, this is applied to the window that was clicked on. Action action; KeyBinding(unsigned int button, unsigned int state, Action action) { assert(button > 0); assert(action >= 0 && action < NUM_ACTIONS); this->button = button; this->state = state; this->action = action; } }; struct MouseBinding : public KeyBinding { MouseEvent event; MouseBinding(unsigned int button, unsigned int state, MouseEvent event, Action action) : KeyBinding(button, state, action) { assert(event >= 0 && event < NUM_MOUSEEVENTS); this->event = event; } }; typedef std::list<MouseBinding> MouseBindingList; typedef std::list<KeyBinding> KeyBindingList; private: Blackbox *_blackbox; Display *_display; MouseBindingList _mousebind; KeyBindingList _keybind; void doAction(BlackboxWindow *window, Action action) const; public: BInput(Blackbox *b); virtual ~BInput(); void add(unsigned int button, unsigned int state, MouseEvent event, Action action); void remove(unsigned int button, unsigned int state, MouseEvent event, Action action); void add(unsigned int button, unsigned int state, Action action); void remove(unsigned int button, unsigned int state, Action action); // execute a keyboard binding // returns false if the specified binding doesnt exist bool doAction(BlackboxWindow *window, unsigned int keycode, unsigned int state) const; // execute a mouse binding // returns false if the specified binding doesnt exist bool doAction(BlackboxWindow *window, unsigned int keycode, unsigned int state, MouseEvent eventtype) const; // determine if a keyboard binding exists bool hasAction(unsigned int keycode, unsigned int state) const; // determine if a mouse binding exists bool hasAction(unsigned int button, unsigned int state, MouseEvent eventtype) const; const MouseBindingList &getMouseBindings(void) { return _mousebind; } const KeyBindingList &getKeyBindings(void) { return _keybind; } }; #endif // __Input_hh |