]> Dogcows Code - chaz/openbox/blob - src/Window.h
added ClickMouse window placement policy
[chaz/openbox] / src / Window.h
1 // Window.h for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 #ifndef __Window_hh
24 #define __Window_hh
25
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #ifdef SHAPE
29 # include <X11/extensions/shape.h>
30 #endif // SHAPE
31
32 #include "BaseDisplay.h"
33 #include "Timer.h"
34 #include "Windowmenu.h"
35 #include "Geometry.h"
36
37 // forward declaration
38 class OpenboxWindow;
39
40 #define MwmHintsFunctions (1l << 0)
41 #define MwmHintsDecorations (1l << 1)
42
43 #define MwmFuncAll (1l << 0)
44 #define MwmFuncResize (1l << 1)
45 #define MwmFuncMove (1l << 2)
46 #define MwmFuncIconify (1l << 3)
47 #define MwmFuncMaximize (1l << 4)
48 #define MwmFuncClose (1l << 5)
49
50 #define MwmDecorAll (1l << 0)
51 #define MwmDecorBorder (1l << 1)
52 #define MwmDecorHandle (1l << 2)
53 #define MwmDecorTitle (1l << 3)
54 #define MwmDecorMenu (1l << 4)
55 #define MwmDecorIconify (1l << 5)
56 #define MwmDecorMaximize (1l << 6)
57
58 // this structure only contains 3 elements... the Motif 2.0 structure contains
59 // 5... we only need the first 3... so that is all we will define
60 typedef struct MwmHints {
61 unsigned long flags, functions, decorations;
62 } MwmHints;
63
64 #define PropMwmHintsElements 3
65
66
67 class OpenboxWindow : public TimeoutHandler {
68 private:
69 BImageControl *image_ctrl;
70 Openbox &openbox;
71 BScreen *screen;
72 Display *display;
73 BTimer *timer;
74 OpenboxAttributes openbox_attrib;
75
76 Time lastButtonPressTime; // used for double clicks, when were we clicked
77 Windowmenu *windowmenu;
78
79 int window_number, workspace_number;
80 unsigned long current_state;
81
82 enum FocusMode { F_NoInput = 0, F_Passive,
83 F_LocallyActive, F_GloballyActive };
84 FocusMode focus_mode;
85
86 enum ResizeZones {
87 ZoneTop = 1 << 0,
88 ZoneBottom = 1 << 1,
89 ZoneLeft = 1 << 2,
90 ZoneRight = 1 << 3
91 };
92 unsigned int resize_zone; // bitmask of ResizeZones values
93
94 struct _flags {
95 Bool moving, // is moving?
96 resizing, // is resizing?
97 shaded, // is shaded?
98 visible, // is visible?
99 iconic, // is iconified?
100 transient, // is a transient window?
101 focused, // has focus?
102 stuck, // is omnipresent
103 modal, // is modal? (must be dismissed to continue)
104 send_focus_message, // should we send focus messages to our client?
105 shaped, // does the frame use the shape extension?
106 managed; // under openbox's control?
107 // maximize is special, the number corresponds
108 // with a mouse button
109 // if 0, not maximized
110 unsigned int maximized; // 1 = HorizVert, 2 = Vertical, 3 = Horizontal
111 } flags;
112
113 struct _client {
114 OpenboxWindow *transient_for, // which window are we a transient for?
115 *transient; // which window is our transient?
116
117 Window window, // the client's window
118 window_group; // the client's window group
119
120 char *title, *icon_title;
121 size_t title_len; // strlen(title)
122
123 int x, y,
124 old_bw; // client's borderwidth
125
126 unsigned int width, height,
127 title_text_w, // width as rendered in the current font
128 min_width, min_height, // can not be resized smaller
129 max_width, max_height, // can not be resized larger
130 width_inc, height_inc, // increment step
131 min_aspect_x, min_aspect_y, // minimum aspect ratio
132 max_aspect_x, max_aspect_y, // maximum aspect ratio
133 base_width, base_height,
134 win_gravity;
135
136 unsigned long initial_state, normal_hint_flags, wm_hint_flags;
137
138 MwmHints *mwm_hint;
139 OpenboxHints *openbox_hint;
140 } client;
141
142 struct _functions {
143 Bool resize, move, iconify, maximize, close;
144 } functions;
145
146 /*
147 * client window = the application's window
148 * frame window = the window drawn around the outside of the client window
149 * by the window manager which contains items like the
150 * titlebar and close button
151 * title = the titlebar drawn above the client window, it displays the
152 * window's name and any buttons for interacting with the window,
153 * such as iconify, maximize, and close
154 * label = the window in the titlebar where the title is drawn
155 * buttons = maximize, iconify, close
156 * handle = the bar drawn at the bottom of the window, which contains the
157 * left and right grips used for resizing the window
158 * grips = the smaller reactangles in the handle, one of each side of it.
159 * When clicked and dragged, these resize the window interactively
160 * border = the line drawn around the outside edge of the frame window,
161 * between the title, the bordered client window, and the handle.
162 * Also drawn between the grips and the handle
163 */
164
165 /*
166 * what decorations do we have?
167 * this is based on the type of the client window as well as user input
168 * the menu is not really decor, but it goes hand in hand with the decor
169 */
170 struct _decorations {
171 Bool titlebar, handle, border, iconify, maximize, close, menu;
172 } decorations;
173
174 struct _frame {
175 // u -> unfocused, f -> has focus
176 unsigned long ulabel_pixel, flabel_pixel, utitle_pixel,
177 ftitle_pixel, uhandle_pixel, fhandle_pixel, ubutton_pixel,
178 fbutton_pixel, pbutton_pixel, uborder_pixel, fborder_pixel,
179 ugrip_pixel, fgrip_pixel;
180 Pixmap ulabel, flabel, utitle, ftitle, uhandle, fhandle,
181 ubutton, fbutton, pbutton, ugrip, fgrip;
182
183 Window window, // the frame
184 plate, // holds the client
185 title,
186 label,
187 handle,
188 close_button, iconify_button, maximize_button,
189 right_grip, left_grip;
190
191
192 unsigned int resize_w, resize_h;
193 int resize_x, resize_y, // size and location of box drawn while resizing
194 move_x, move_y; // location of box drawn while moving
195
196 int x, y,
197 grab_x, grab_y, // where was the window when it was grabbed?
198 y_border, y_handle; // where within frame is the border and handle
199
200 unsigned int width, height, title_h, label_w, label_h, handle_h,
201 button_w, button_h, grip_w, grip_h, mwm_border_w, border_h, border_w,
202 bevel_w;
203 } frame;
204
205 protected:
206 Bool getState();
207 Window createToplevelWindow(int x, int y, unsigned int width,
208 unsigned int height, unsigned int borderwidth);
209 Window createChildWindow(Window parent, Cursor = None);
210
211 void getWMName();
212 void getWMIconName();
213 void getWMNormalHints();
214 void getWMProtocols();
215 void getWMHints();
216 void getMWMHints();
217 void getOpenboxHints();
218 void setNetWMAttributes();
219 void associateClientWindow();
220 void decorate();
221 void decorateLabel();
222 void positionButtons(Bool redecorate_label = False);
223 void positionWindows();
224 void createCloseButton();
225 void createIconifyButton();
226 void createMaximizeButton();
227 void redrawLabel();
228 void redrawAllButtons();
229 void redrawCloseButton(Bool);
230 void redrawIconifyButton(Bool);
231 void redrawMaximizeButton(Bool);
232 void restoreGravity();
233 void setGravityOffsets();
234 void setState(unsigned long);
235 void upsize();
236 void downsize();
237 void right_fixsize(int *gx = 0, int *gy = 0);
238 void left_fixsize(int *gx = 0, int *gy = 0);
239 void doMove(int x, int y);
240
241
242 public:
243 OpenboxWindow(Openbox &b, Window w, BScreen *s = (BScreen *) 0);
244 virtual ~OpenboxWindow();
245
246 inline Bool isTransient() const { return flags.transient; }
247 inline Bool isFocused() const { return flags.focused; }
248 inline Bool isVisible() const { return flags.visible; }
249 inline Bool isIconic() const { return flags.iconic; }
250 inline Bool isShaded() const { return flags.shaded; }
251 inline Bool isMaximized() const { return flags.maximized; }
252 inline Bool isMaximizedFull() const { return flags.maximized == 1; }
253 inline Bool isStuck() const { return flags.stuck; }
254 inline Bool isIconifiable() const { return functions.iconify; }
255 inline Bool isMaximizable() const { return functions.maximize; }
256 inline Bool isResizable() const { return functions.resize; }
257 inline Bool isClosable() const { return functions.close; }
258
259 inline Bool hasTitlebar() const { return decorations.titlebar; }
260 inline Bool hasTransient() const
261 { return ((client.transient) ? True : False); }
262
263 inline OpenboxWindow *getTransient() { return client.transient; }
264 inline OpenboxWindow *getTransientFor() { return client.transient_for; }
265
266 inline BScreen *getScreen() { return screen; }
267
268 inline const Window &getFrameWindow() const { return frame.window; }
269 inline const Window &getClientWindow() const { return client.window; }
270
271 inline Windowmenu * getWindowmenu() { return windowmenu; }
272
273 inline char **getTitle() { return &client.title; }
274 inline char **getIconTitle() { return &client.icon_title; }
275 //inline const int &getXFrame() const { return frame.x; }
276 //inline const int &getYFrame() const { return frame.y; }
277 //inline const int &getXClient() const { return client.x; }
278 //inline const int &getYClient() const { return client.y; }
279 inline const int &getWorkspaceNumber() const { return workspace_number; }
280 inline const int &getWindowNumber() const { return window_number; }
281
282 //inline const unsigned int &getWidth() const { return frame.width; }
283 //inline const unsigned int &getHeight() const {
284 // if (!flags.shaded)
285 // return frame.height;
286 // else
287 // return frame.title_h;
288 //}
289 //inline const unsigned int &getClientHeight() const
290 //{ return client.height; }
291 //inline const unsigned int &getClientWidth() const
292 //{ return client.width; }
293 inline const unsigned int &getTitleHeight() const
294 { return frame.title_h; }
295
296 //inline const Point origin() const {
297 // return Point(frame.x, frame.y);
298 //}
299 //inline const Point clientOrigin() const {
300 // return Point(client.x, client.y);
301 //}
302 //inline const Size size() const {
303 // return Size(frame.width, flags.shaded ? frame.title_h : frame.height);
304 //}
305 //inline const Size clientSize() const {
306 // return Size(client.width, client.height);
307 //}
308 inline const Rect area() const {
309 return Rect(frame.x, frame.y, frame.width,
310 flags.shaded ? frame.title_h : frame.height);
311 }
312 inline const Rect clientArea() const {
313 return Rect(client.x, client.y, client.width, client.height);
314 }
315
316 inline void setWindowNumber(int n) { window_number = n; }
317
318 Bool validateClient();
319 Bool setInputFocus();
320
321 void setFocusFlag(Bool);
322 void iconify();
323 void deiconify(Bool reassoc = True, Bool raise = True);
324 void close();
325 void withdraw();
326 void maximize(unsigned int button);
327 void shade();
328 void stick();
329 void unstick();
330 void reconfigure();
331 void installColormap(Bool);
332 void restore();
333 void configure(int dx, int dy, unsigned int dw, unsigned int dh);
334 void setWorkspace(int n);
335 void changeOpenboxHints(OpenboxHints *);
336 void restoreAttributes();
337
338 void startMove(int x, int y);
339 void endMove();
340
341 void buttonPressEvent(XButtonEvent *);
342 void buttonReleaseEvent(XButtonEvent *);
343 void motionNotifyEvent(XMotionEvent *);
344 void destroyNotifyEvent(XDestroyWindowEvent *);
345 void mapRequestEvent(XMapRequestEvent *);
346 void mapNotifyEvent(XMapEvent *);
347 void unmapNotifyEvent(XUnmapEvent *);
348 void propertyNotifyEvent(Atom);
349 void exposeEvent(XExposeEvent *);
350 void configureRequestEvent(XConfigureRequestEvent *);
351
352 #ifdef SHAPE
353 void shapeEvent(XShapeEvent *);
354 #endif // SHAPE
355
356 virtual void timeout();
357 };
358
359
360 #endif // __Window_hh
This page took 0.054847 seconds and 4 git commands to generate.