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