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