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