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)
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:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
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.
29 #include <X11/Xutil.h>
31 # include <X11/extensions/shape.h>
37 #include "BaseDisplay.hh"
40 #include "Windowmenu.hh"
41 #include "Workspace.hh"
47 #define MwmHintsFunctions (1l << 0)
48 #define MwmHintsDecorations (1l << 1)
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)
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)
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;
71 #define PropMwmHintsElements 3
77 BlackboxWindowList windowList;
80 BWindowGroup(Blackbox *b, Window _group);
83 inline Window groupWindow(void) const { return group; }
85 inline bool empty(void) const { return windowList.empty(); }
87 void addWindow(BlackboxWindow *w) { windowList.push_back(w); }
88 void removeWindow(BlackboxWindow *w) { windowList.remove(w); }
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.
95 BlackboxWindow *find(BScreen *screen, bool allow_transients = False) const;
99 class BlackboxWindow : public TimeoutHandler {
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;
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;
116 enum WindowType { Type_Desktop,
125 enum Corner { TopLeft,
136 BlackboxAttributes blackbox_attrib;
138 Time lastButtonPressTime; // used for double clicks, when were we clicked
139 Windowmenu *windowmenu;
141 unsigned int window_number;
142 unsigned long current_state;
144 enum FocusMode { F_NoInput = 0, F_Passive,
145 F_LocallyActive, F_GloballyActive };
146 FocusMode focus_mode;
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
169 Window window, // the client's window
171 BlackboxWindow *transient_for; // which window are we a transient for?
172 BlackboxWindowList transientList; // which windows are our transients?
174 std::string title, icon_title;
179 int old_bw; // client's borderwidth
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,
190 unsigned long initial_state, normal_hint_flags, wm_hint_flags;
193 FunctionFlags functions;
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
199 DecorationFlags decorations;
201 WindowType window_type;
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
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;
231 Window window, // the frame
232 plate, // holds the client
236 close_button, iconify_button, maximize_button,
237 right_grip, left_grip;
240 * size and location of the box drawn while the window dimensions or
241 * location is being changed, ie. resized or moved
245 Rect rect; // frame geometry
246 Strut margin; // margins between the frame and client
248 int grab_x, grab_y; // where was the window when it was grabbed?
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,
256 BlackboxWindow(const BlackboxWindow&);
257 BlackboxWindow& operator=(const BlackboxWindow&);
260 Window createToplevelWindow();
261 Window createChildWindow(Window parent, Cursor = None);
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);
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 redrawLabel(void);
292 void redrawAllButtons(void);
293 void redrawCloseButton(bool pressed);
294 void redrawIconifyButton(bool pressed);
295 void redrawMaximizeButton(bool pressed);
296 void restoreGravity(void);
297 void setGravityOffsets(void);
298 void setAllowedActions(void);
299 void setState(unsigned long new_state);
301 void doMove(int x_root, int y_root);
303 void doResize(int x_root, int y_root);
304 void endResize(void);
306 void constrain(Corner anchor, int *pw = 0, int *ph = 0);
309 BlackboxWindow(Blackbox *b, Window w, BScreen *s);
310 virtual ~BlackboxWindow(void);
312 inline bool isTransient(void) const { return client.transient_for != 0; }
313 inline bool isFocused(void) const { return flags.focused; }
314 inline bool isVisible(void) const { return flags.visible; }
315 inline bool isIconic(void) const { return flags.iconic; }
316 inline bool isShaded(void) const { return flags.shaded; }
317 inline bool isMaximized(void) const { return flags.maximized; }
318 inline bool isMaximizedHoriz(void) const { return flags.maximized == 3; }
319 inline bool isMaximizedVert(void) const { return flags.maximized == 2; }
320 inline bool isMaximizedFull(void) const { return flags.maximized == 1; }
321 inline bool isStuck(void) const { return flags.stuck; }
322 inline bool isModal(void) const { return flags.modal; }
323 inline bool isIconifiable(void) const { return functions & Func_Iconify; }
324 inline bool isMaximizable(void) const { return functions & Func_Maximize; }
325 inline bool isResizable(void) const { return functions & Func_Resize; }
326 inline bool isMovable(void) const { return functions & Func_Move; }
327 inline bool isClosable(void) const { return functions & Func_Close; }
328 inline bool isDesktop(void) const { return window_type == Type_Desktop; }
330 inline bool hasTitlebar(void) const { return decorations & Decor_Titlebar; }
332 inline const BlackboxWindowList &getTransients(void) const
333 { return client.transientList; }
334 BlackboxWindow *getTransientFor(void) const;
336 inline BScreen *getScreen(void) const { return screen; }
338 inline Window getFrameWindow(void) const { return frame.window; }
339 inline Window getClientWindow(void) const { return client.window; }
340 inline Window getGroupWindow(void) const { return client.window_group; }
342 inline Windowmenu * getWindowmenu(void) const { return windowmenu; }
344 inline const char *getTitle(void) const
345 { return client.title.c_str(); }
346 inline const char *getIconTitle(void) const
347 { return client.icon_title.c_str(); }
349 inline unsigned int getWorkspaceNumber(void) const
350 { return blackbox_attrib.workspace; }
351 inline unsigned int getWindowNumber(void) const { return window_number; }
353 inline const Rect &frameRect(void) const { return frame.rect; }
354 inline const Rect &clientRect(void) const { return client.rect; }
356 inline unsigned int getTitleHeight(void) const
357 { return frame.title_h; }
359 inline void setWindowNumber(int n) { window_number = n; }
361 bool validateClient(void) const;
362 bool setInputFocus(void);
364 // none of these are used by the window manager, they are here to persist
365 // them properly in the window's netwm state property.
366 inline bool skipTaskbar(void) const { return flags.skip_taskbar; }
367 inline void setSkipTaskbar(const bool s) { flags.skip_taskbar = s; }
368 inline bool skipPager(void) const { return flags.skip_pager; }
369 inline void setSkipPager(const bool s) { flags.skip_pager = s; }
370 inline bool isFullscreen(void) const { return flags.fullscreen; }
371 inline void setFullscreen(const bool f) { flags.fullscreen = f; }
373 inline void setModal(const bool m) { flags.modal = m; }
375 void beginMove(int x_root, int y_root);
376 void beginResize(int x_root, int y_root, Corner dir);
377 void setFocusFlag(bool focus);
379 void deiconify(bool reassoc = True, bool raise = True);
381 void showWindowMenu(int root_x, int root_y);
384 void maximize(unsigned int button);
385 void remaximize(void);
390 void reconfigure(void);
391 void grabButtons(void);
392 void ungrabButtons(void);
393 void installColormap(bool install);
394 void restore(bool remap);
395 void configure(int dx, int dy, unsigned int dw, unsigned int dh);
396 void setWorkspace(unsigned int n);
397 void changeBlackboxHints(BlackboxHints *net);
398 void restoreAttributes(void);
400 void buttonPressEvent(const XButtonEvent *be);
401 void buttonReleaseEvent(const XButtonEvent *re);
402 void motionNotifyEvent(const XMotionEvent *me);
403 void destroyNotifyEvent(const XDestroyWindowEvent */*unused*/);
404 void mapRequestEvent(const XMapRequestEvent *mre);
405 void unmapNotifyEvent(const XUnmapEvent */*unused*/);
406 void reparentNotifyEvent(const XReparentEvent */*unused*/);
407 void propertyNotifyEvent(Atom atom);
408 void exposeEvent(const XExposeEvent *ee);
409 void configureRequestEvent(const XConfigureRequestEvent *cr);
412 void configureShape(void);
413 void shapeEvent(XShapeEvent * /*unused*/);
416 virtual void timeout(void);
420 #endif // __Window_hh