]> Dogcows Code - chaz/openbox/blob - src/Input.hh
add capability to stick a window from input, and make close buttons work.
[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 Stick,
68 Unstick,
69 Focus,
70 Iconify,
71 Close,
72 ShowWindowMenu,
73
74 BeginMove,
75 BeginResizeUL,
76 BeginResizeUR,
77 BeginResizeLL,
78 BeginResizeLR,
79 BeginResizeRelative, // picks a corner based on the mouse cursor's position
80
81 ToggleMaximizeVert,
82 ToggleMaximizeHoriz,
83 ToggleMaximize,
84 ToggleShade,
85 ToggleStick,
86
87 NUM_ACTIONS
88 };
89
90 struct KeyBinding {
91 unsigned int button;
92 unsigned int state;
93
94 // for keyboard events, this is applied to the focused window.
95 // for mouse events, this is applied to the window that was clicked on.
96 Action action;
97
98 KeyBinding(unsigned int button, unsigned int state, Action action) {
99 assert(button > 0);
100 assert(action >= 0 && action < NUM_ACTIONS);
101 this->button = button;
102 this->state = state;
103 this->action = action;
104 }
105 };
106
107 struct MouseBinding : public KeyBinding {
108 MouseEvent event;
109
110 MouseBinding(unsigned int button, unsigned int state, MouseEvent event,
111 Action action) : KeyBinding(button, state, action) {
112 assert(event >= 0 && event < NUM_MOUSEEVENTS);
113 this->event = event;
114 }
115 };
116
117 typedef std::list<MouseBinding> MouseBindingList;
118 typedef std::list<KeyBinding> KeyBindingList;
119
120 private:
121 Blackbox *_blackbox;
122 Display *_display;
123
124 MouseBindingList _mousebind;
125 KeyBindingList _keybind;
126
127 void doAction(BlackboxWindow *window, Action action) const;
128
129 public:
130 BInput(Blackbox *b);
131 virtual ~BInput();
132
133 void add(unsigned int button, unsigned int state, MouseEvent event,
134 Action action);
135 void remove(unsigned int button, unsigned int state, MouseEvent event,
136 Action action);
137 void add(unsigned int button, unsigned int state, Action action);
138 void remove(unsigned int button, unsigned int state, Action action);
139
140 // execute a keyboard binding
141 // returns false if the specified binding doesnt exist
142 bool doAction(BlackboxWindow *window, unsigned int keycode,
143 unsigned int state) const;
144 // execute a mouse binding
145 // returns false if the specified binding doesnt exist
146 bool doAction(BlackboxWindow *window, unsigned int keycode,
147 unsigned int state, MouseEvent eventtype) const;
148
149 // determine if a keyboard binding exists
150 bool hasAction(unsigned int keycode, unsigned int state) const;
151 // determine if a mouse binding exists
152 bool hasAction(unsigned int button, unsigned int state,
153 MouseEvent eventtype) const;
154
155 const MouseBindingList &getMouseBindings(void) { return _mousebind; }
156 const KeyBindingList &getKeyBindings(void) { return _keybind; }
157 };
158
159 #endif // __Input_hh
This page took 0.041062 seconds and 4 git commands to generate.