]> Dogcows Code - chaz/openbox/blob - src/Window.hh
sync with bb. mostly cleanups in Window.cc
[chaz/openbox] / src / Window.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Window.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 __Window_hh
25 #define __Window_hh
26
27 extern "C" {
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
30 #ifdef SHAPE
31 # include <X11/extensions/shape.h>
32 #endif // SHAPE
33 }
34
35 #include <string>
36
37 #include "BaseDisplay.hh"
38 #include "Timer.hh"
39 #include "Util.hh"
40 #include "Windowmenu.hh"
41 #include "Workspace.hh"
42 #include "Screen.hh"
43
44 class XAtom;
45 class BInput;
46
47 #define MwmHintsFunctions (1l << 0)
48 #define MwmHintsDecorations (1l << 1)
49
50 #define MwmFuncAll (1l << 0)
51 #define MwmFuncResize (1l << 1)
52 #define MwmFuncMove (1l << 2)
53 #define MwmFuncIconify (1l << 3)
54 #define MwmFuncMaximize (1l << 4)
55 #define MwmFuncClose (1l << 5)
56
57 #define MwmDecorAll (1l << 0)
58 #define MwmDecorBorder (1l << 1)
59 #define MwmDecorHandle (1l << 2)
60 #define MwmDecorTitle (1l << 3)
61 #define MwmDecorMenu (1l << 4) // not used
62 #define MwmDecorIconify (1l << 5)
63 #define MwmDecorMaximize (1l << 6)
64
65 // this structure only contains 3 elements... the Motif 2.0 structure contains
66 // 5... we only need the first 3... so that is all we will define
67 typedef struct MwmHints {
68 unsigned long flags, functions, decorations;
69 } MwmHints;
70
71 #define PropMwmHintsElements 3
72
73 class BWindowGroup {
74 private:
75 Blackbox *blackbox;
76 Window group;
77 BlackboxWindowList windowList;
78
79 public:
80 BWindowGroup(Blackbox *b, Window _group);
81 ~BWindowGroup(void);
82
83 inline Window groupWindow(void) const { return group; }
84
85 inline bool empty(void) const { return windowList.empty(); }
86
87 void addWindow(BlackboxWindow *w) { windowList.push_back(w); }
88 void removeWindow(BlackboxWindow *w) { windowList.remove(w); }
89
90 /*
91 find a window on the specified screen. the focused window (if any) is
92 checked first, otherwise the first matching window found is returned.
93 transients are returned only if allow_transients is True.
94 */
95 BlackboxWindow *find(BScreen *screen, bool allow_transients = False) const;
96 };
97
98
99 class BlackboxWindow : public TimeoutHandler {
100 public:
101 enum Function { Func_Resize = (1l << 0),
102 Func_Move = (1l << 1),
103 Func_Iconify = (1l << 2),
104 Func_Maximize = (1l << 3),
105 Func_Close = (1l << 4) };
106 typedef unsigned char FunctionFlags;
107
108 enum Decoration { Decor_Titlebar = (1l << 0),
109 Decor_Handle = (1l << 1),
110 Decor_Border = (1l << 2),
111 Decor_Iconify = (1l << 3),
112 Decor_Maximize = (1l << 4),
113 Decor_Close = (1l << 5) };
114 typedef unsigned char DecorationFlags;
115
116 enum WindowType { Type_Desktop,
117 Type_Dock,
118 Type_Toolbar,
119 Type_Menu,
120 Type_Utility,
121 Type_Splash,
122 Type_Dialog,
123 Type_Normal };
124
125 enum Corner { TopLeft,
126 TopRight,
127 BottomLeft,
128 BottomRight };
129
130 private:
131 Blackbox *blackbox;
132 BScreen *screen;
133 XAtom *xatom;
134 BInput *input;
135 BTimer *timer;
136 BlackboxAttributes blackbox_attrib;
137
138 Time lastButtonPressTime; // used for double clicks, when were we clicked
139 Windowmenu *windowmenu;
140
141 unsigned int window_number;
142 unsigned long current_state;
143
144 enum FocusMode { F_NoInput = 0, F_Passive,
145 F_LocallyActive, F_GloballyActive };
146 FocusMode focus_mode;
147
148 struct _flags {
149 bool moving, // is moving?
150 resizing, // is resizing?
151 shaded, // is shaded?
152 visible, // is visible?
153 iconic, // is iconified?
154 focused, // has focus?
155 stuck, // is omnipresent?
156 modal, // is modal? (must be dismissed to continue)
157 skip_taskbar, // skipped by taskbars?
158 skip_pager, // skipped by pagers?
159 fullscreen, // a fullscreen window?
160 send_focus_message, // should we send focus messages to our client?
161 shaped; // does the frame use the shape extension?
162 unsigned int maximized; // maximize is special, the number corresponds
163 // with a mouse button
164 // if 0, not maximized
165 // 1 = HorizVert, 2 = Vertical, 3 = Horizontal
166 } flags;
167
168 struct _client {
169 Window window, // the client's window
170 window_group;
171 BlackboxWindow *transient_for; // which window are we a transient for?
172 BlackboxWindowList transientList; // which windows are our transients?
173
174 std::string title, icon_title;
175
176 Rect rect;
177 Strut strut;
178
179 int old_bw; // client's borderwidth
180
181 unsigned int
182 min_width, min_height, // can not be resized smaller
183 max_width, max_height, // can not be resized larger
184 width_inc, height_inc, // increment step
185 min_aspect_x, min_aspect_y, // minimum aspect ratio
186 max_aspect_x, max_aspect_y, // maximum aspect ratio
187 base_width, base_height,
188 win_gravity;
189
190 unsigned long initial_state, normal_hint_flags, wm_hint_flags;
191 } client;
192
193 FunctionFlags functions;
194 /*
195 * what decorations do we have?
196 * this is based on the type of the client window as well as user input
197 * the menu is not really decor, but it goes hand in hand with the decor
198 */
199 DecorationFlags decorations;
200 Corner resize_dir;
201 WindowType window_type;
202
203 /*
204 * client window = the application's window
205 * frame window = the window drawn around the outside of the client window
206 * by the window manager which contains items like the
207 * titlebar and close button
208 * title = the titlebar drawn above the client window, it displays the
209 * window's name and any buttons for interacting with the window,
210 * such as iconify, maximize, and close
211 * label = the window in the titlebar where the title is drawn
212 * buttons = maximize, iconify, close
213 * handle = the bar drawn at the bottom of the window, which contains the
214 * left and right grips used for resizing the window
215 * grips = the smaller reactangles in the handle, one of each side of it.
216 * When clicked and dragged, these resize the window interactively
217 * border = the line drawn around the outside edge of the frame window,
218 * between the title, the bordered client window, and the handle.
219 * Also drawn between the grips and the handle
220 */
221
222 struct _frame {
223 // u -> unfocused, f -> has focus
224 unsigned long ulabel_pixel, flabel_pixel, utitle_pixel,
225 ftitle_pixel, uhandle_pixel, fhandle_pixel, ubutton_pixel,
226 fbutton_pixel, pbutton_pixel, uborder_pixel, fborder_pixel,
227 ugrip_pixel, fgrip_pixel;
228 Pixmap ulabel, flabel, utitle, ftitle, uhandle, fhandle,
229 ubutton, fbutton, pbutton, ugrip, fgrip;
230
231 Window window, // the frame
232 plate, // holds the client
233 title,
234 label,
235 handle,
236 close_button, iconify_button, maximize_button,
237 right_grip, left_grip;
238
239 /*
240 * size and location of the box drawn while the window dimensions or
241 * location is being changed, ie. resized or moved
242 */
243 Rect changing;
244
245 Rect rect; // frame geometry
246 Strut margin; // margins between the frame and client
247
248 int grab_x, grab_y; // where was the window when it was grabbed?
249
250 unsigned int inside_w, inside_h, // window w/h without border_w
251 title_h, label_w, label_h, handle_h,
252 button_w, grip_w, mwm_border_w, border_w,
253 bevel_w;
254 } frame;
255
256 BlackboxWindow(const BlackboxWindow&);
257 BlackboxWindow& operator=(const BlackboxWindow&);
258
259 bool getState(void);
260 Window createToplevelWindow();
261 Window createChildWindow(Window parent, Cursor = None);
262
263 void getWindowType(void);
264 void updateStrut(void);
265 void getWMName(void);
266 void getWMIconName(void);
267 void getWMNormalHints(void);
268 void getWMProtocols(void);
269 void getWMHints(void);
270 void getNetWMHints(void);
271 void getMWMHints(void);
272 bool getBlackboxHints(void);
273 void getTransientInfo(void);
274 bool isKDESystrayWindow(void);
275 void setNetWMAttributes(void);
276 void associateClientWindow(void);
277 void decorate(void);
278 void decorateLabel(void);
279 void positionButtons(bool redecorate_label = False);
280 void positionWindows(void);
281 void createHandle(void);
282 void destroyHandle(void);
283 void createTitlebar(void);
284 void destroyTitlebar(void);
285 void createCloseButton(void);
286 void destroyCloseButton(void);
287 void createIconifyButton(void);
288 void destroyIconifyButton(void);
289 void createMaximizeButton(void);
290 void destroyMaximizeButton(void);
291 void redrawWindowFrame(void) const;
292 void redrawLabel(void) const;
293 void redrawAllButtons(void) const;
294 void redrawCloseButton(bool pressed) const;
295 void redrawIconifyButton(bool pressed) const;
296 void redrawMaximizeButton(bool pressed) const;
297 void applyGravity(Rect &r);
298 void restoreGravity(Rect &r);
299 void setAllowedActions(void);
300 void setState(unsigned long new_state);
301 void upsize(void);
302 void doMove(int x_root, int y_root);
303 void endMove(void);
304 void doResize(int x_root, int y_root);
305 void endResize(void);
306
307 void constrain(Corner anchor, int *pw = 0, int *ph = 0);
308
309 public:
310 BlackboxWindow(Blackbox *b, Window w, BScreen *s);
311 virtual ~BlackboxWindow(void);
312
313 inline bool isTransient(void) const { return client.transient_for != 0; }
314 inline bool isFocused(void) const { return flags.focused; }
315 inline bool isVisible(void) const { return flags.visible; }
316 inline bool isIconic(void) const { return flags.iconic; }
317 inline bool isShaded(void) const { return flags.shaded; }
318 inline bool isMaximized(void) const { return flags.maximized; }
319 inline bool isMaximizedHoriz(void) const { return flags.maximized == 3; }
320 inline bool isMaximizedVert(void) const { return flags.maximized == 2; }
321 inline bool isMaximizedFull(void) const { return flags.maximized == 1; }
322 inline bool isStuck(void) const { return flags.stuck; }
323 inline bool isModal(void) const { return flags.modal; }
324 inline bool isIconifiable(void) const { return functions & Func_Iconify; }
325 inline bool isMaximizable(void) const { return functions & Func_Maximize; }
326 inline bool isResizable(void) const { return functions & Func_Resize; }
327 inline bool isMovable(void) const { return functions & Func_Move; }
328 inline bool isClosable(void) const { return functions & Func_Close; }
329 inline bool isDesktop(void) const { return window_type == Type_Desktop; }
330
331 inline bool hasTitlebar(void) const { return decorations & Decor_Titlebar; }
332
333 inline const BlackboxWindowList &getTransients(void) const
334 { return client.transientList; }
335 BlackboxWindow *getTransientFor(void) const;
336
337 inline BScreen *getScreen(void) const { return screen; }
338
339 inline Window getFrameWindow(void) const { return frame.window; }
340 inline Window getClientWindow(void) const { return client.window; }
341 inline Window getGroupWindow(void) const { return client.window_group; }
342
343 inline Windowmenu * getWindowmenu(void) const { return windowmenu; }
344
345 inline const char *getTitle(void) const
346 { return client.title.c_str(); }
347 inline const char *getIconTitle(void) const
348 { return client.icon_title.c_str(); }
349
350 inline unsigned int getWorkspaceNumber(void) const
351 { return blackbox_attrib.workspace; }
352 inline unsigned int getWindowNumber(void) const { return window_number; }
353
354 inline const Rect &frameRect(void) const { return frame.rect; }
355 inline const Rect &clientRect(void) const { return client.rect; }
356
357 inline unsigned int getTitleHeight(void) const
358 { return frame.title_h; }
359
360 inline void setWindowNumber(int n) { window_number = n; }
361
362 bool validateClient(void) const;
363 bool setInputFocus(void);
364
365 // none of these are used by the window manager, they are here to persist
366 // them properly in the window's netwm state property.
367 inline bool skipTaskbar(void) const { return flags.skip_taskbar; }
368 inline void setSkipTaskbar(const bool s) { flags.skip_taskbar = s; }
369 inline bool skipPager(void) const { return flags.skip_pager; }
370 inline void setSkipPager(const bool s) { flags.skip_pager = s; }
371 inline bool isFullscreen(void) const { return flags.fullscreen; }
372 inline void setFullscreen(const bool f) { flags.fullscreen = f; }
373
374 inline void setModal(const bool m) { flags.modal = m; }
375
376 void beginMove(int x_root, int y_root);
377 void beginResize(int x_root, int y_root, Corner dir);
378 void setFocusFlag(bool focus);
379 void iconify(void);
380 void deiconify(bool reassoc = True, bool raise = True);
381 void show(void);
382 void showWindowMenu(int root_x, int root_y);
383 void close(void);
384 void withdraw(void);
385 void maximize(unsigned int button);
386 void remaximize(void);
387 void shade(void);
388 void stick(void);
389 void raise(void);
390 void lower(void);
391 void reconfigure(void);
392 void grabButtons(void);
393 void ungrabButtons(void);
394 void installColormap(bool install);
395 void restore(bool remap);
396 void configure(int dx, int dy, unsigned int dw, unsigned int dh);
397 void setWorkspace(unsigned int n);
398 void changeBlackboxHints(BlackboxHints *net);
399 void restoreAttributes(void);
400
401 void buttonPressEvent(const XButtonEvent *be);
402 void buttonReleaseEvent(const XButtonEvent *re);
403 void motionNotifyEvent(const XMotionEvent *me);
404 void destroyNotifyEvent(const XDestroyWindowEvent */*unused*/);
405 void mapRequestEvent(const XMapRequestEvent *mre);
406 void unmapNotifyEvent(const XUnmapEvent */*unused*/);
407 void reparentNotifyEvent(const XReparentEvent */*unused*/);
408 void propertyNotifyEvent(Atom atom);
409 void exposeEvent(const XExposeEvent *ee);
410 void configureRequestEvent(const XConfigureRequestEvent *cr);
411
412 #ifdef SHAPE
413 void configureShape(void);
414 void shapeEvent(XShapeEvent * /*unused*/);
415 #endif // SHAPE
416
417 virtual void timeout(void);
418 };
419
420
421 #endif // __Window_hh
This page took 0.060296 seconds and 5 git commands to generate.