]> icculus.org git repositories - mikachu/openbox.git/blob - src/Window.hh
make all parents/transients that are related have the same sticky state.
[mikachu/openbox.git] / 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 private:
112   Blackbox *blackbox;
113   BScreen *screen;
114   XAtom *xatom;
115   BTimer *timer;
116   BlackboxAttributes blackbox_attrib;
117
118   Time lastButtonPressTime;  // used for double clicks, when were we clicked
119   Windowmenu *windowmenu;
120
121   unsigned int window_number;
122   unsigned long current_state;
123
124   enum FocusMode { F_NoInput = 0, F_Passive,
125                    F_LocallyActive, F_GloballyActive };
126   FocusMode focus_mode;
127
128   struct _flags {
129     bool moving,             // is moving?
130       resizing,              // is resizing?
131       shaded,                // is shaded?
132       visible,               // is visible?
133       iconic,                // is iconified?
134       focused,               // has focus?
135       stuck,                 // is omnipresent
136       modal,                 // is modal? (must be dismissed to continue)
137       send_focus_message,    // should we send focus messages to our client?
138       shaped;                // does the frame use the shape extension?
139     unsigned int maximized;  // maximize is special, the number corresponds
140                              // with a mouse button
141                              // if 0, not maximized
142                              // 1 = HorizVert, 2 = Vertical, 3 = Horizontal
143   } flags;
144
145   struct _client {
146     Window window,                  // the client's window
147       window_group;
148     BlackboxWindow *transient_for;  // which window are we a transient for?
149     BlackboxWindowList transientList; // which windows are our transients?
150
151     std::string title, icon_title;
152
153     Rect rect;
154
155     int old_bw;                       // client's borderwidth
156
157     unsigned int
158       min_width, min_height,        // can not be resized smaller
159       max_width, max_height,        // can not be resized larger
160       width_inc, height_inc,        // increment step
161       min_aspect_x, min_aspect_y,   // minimum aspect ratio
162       max_aspect_x, max_aspect_y,   // maximum aspect ratio
163       base_width, base_height,
164       win_gravity;
165
166     unsigned long initial_state, normal_hint_flags, wm_hint_flags;
167   } client;
168
169   FunctionFlags functions;
170   /*
171    * what decorations do we have?
172    * this is based on the type of the client window as well as user input
173    * the menu is not really decor, but it goes hand in hand with the decor
174    */
175   DecorationFlags decorations;
176
177   /*
178    * client window = the application's window
179    * frame window = the window drawn around the outside of the client window
180    *                by the window manager which contains items like the
181    *                titlebar and close button
182    * title = the titlebar drawn above the client window, it displays the
183    *         window's name and any buttons for interacting with the window,
184    *         such as iconify, maximize, and close
185    * label = the window in the titlebar where the title is drawn
186    * buttons = maximize, iconify, close
187    * handle = the bar drawn at the bottom of the window, which contains the
188    *          left and right grips used for resizing the window
189    * grips = the smaller reactangles in the handle, one of each side of it.
190    *         When clicked and dragged, these resize the window interactively
191    * border = the line drawn around the outside edge of the frame window,
192    *          between the title, the bordered client window, and the handle.
193    *          Also drawn between the grips and the handle
194    */
195
196   struct _frame {
197     // u -> unfocused, f -> has focus
198     unsigned long ulabel_pixel, flabel_pixel, utitle_pixel,
199       ftitle_pixel, uhandle_pixel, fhandle_pixel, ubutton_pixel,
200       fbutton_pixel, pbutton_pixel, uborder_pixel, fborder_pixel,
201       ugrip_pixel, fgrip_pixel;
202     Pixmap ulabel, flabel, utitle, ftitle, uhandle, fhandle,
203       ubutton, fbutton, pbutton, ugrip, fgrip;
204
205     Window window,       // the frame
206       plate,             // holds the client
207       title,
208       label,
209       handle,
210       close_button, iconify_button, maximize_button,
211       right_grip, left_grip;
212
213     /*
214      * size and location of the box drawn while the window dimensions or
215      * location is being changed, ie. resized or moved
216      */
217     Rect changing;
218
219     Rect rect;                  // frame geometry
220     Strut margin;               // margins between the frame and client
221
222     int grab_x, grab_y;         // where was the window when it was grabbed?
223
224     unsigned int inside_w, inside_h, // window w/h without border_w
225       title_h, label_w, label_h, handle_h,
226       button_w, grip_w, mwm_border_w, border_w,
227       bevel_w;
228   } frame;
229
230   BlackboxWindow(const BlackboxWindow&);
231   BlackboxWindow& operator=(const BlackboxWindow&);
232
233   bool getState(void);
234   Window createToplevelWindow();
235   Window createChildWindow(Window parent, Cursor = None);
236
237   void getWMName(void);
238   void getWMIconName(void);
239   void getWMNormalHints(void);
240   void getWMProtocols(void);
241   void getWMHints(void);
242   void getMWMHints(void);
243   bool getBlackboxHints(void);
244   void getTransientInfo(void);
245   void setNetWMAttributes(void);
246   void associateClientWindow(void);
247   void decorate(void);
248   void decorateLabel(void);
249   void positionButtons(bool redecorate_label = False);
250   void positionWindows(void);
251   void createHandle(void);
252   void destroyHandle(void);
253   void createTitlebar(void);
254   void destroyTitlebar(void);
255   void createCloseButton(void);
256   void destroyCloseButton(void);
257   void createIconifyButton(void);
258   void destroyIconifyButton(void);
259   void createMaximizeButton(void);
260   void destroyMaximizeButton(void);
261   void redrawLabel(void);
262   void redrawAllButtons(void);
263   void redrawCloseButton(bool pressed);
264   void redrawIconifyButton(bool pressed);
265   void redrawMaximizeButton(bool pressed);
266   void restoreGravity(void);
267   void setGravityOffsets(void);
268   void setState(unsigned long new_state);
269   void upsize(void);
270
271   enum Corner { TopLeft, TopRight };
272   void constrain(Corner anchor, int *pw = 0, int *ph = 0);
273
274 public:
275   BlackboxWindow(Blackbox *b, Window w, BScreen *s);
276   virtual ~BlackboxWindow(void);
277
278   inline bool isTransient(void) const { return client.transient_for != 0; }
279   inline bool isFocused(void) const { return flags.focused; }
280   inline bool isVisible(void) const { return flags.visible; }
281   inline bool isIconic(void) const { return flags.iconic; }
282   inline bool isShaded(void) const { return flags.shaded; }
283   inline bool isMaximized(void) const { return flags.maximized; }
284   inline bool isStuck(void) const { return flags.stuck; }
285   inline bool isIconifiable(void) const { return functions & Func_Iconify; }
286   inline bool isMaximizable(void) const { return functions & Func_Maximize; }
287   inline bool isResizable(void) const { return functions & Func_Resize; }
288   inline bool isClosable(void) const { return functions & Func_Close; }
289
290   inline bool hasTitlebar(void) const { return decorations & Decor_Titlebar; }
291
292   inline const BlackboxWindowList &getTransients(void) const
293   { return client.transientList; }
294   BlackboxWindow *getTransientFor(void) const;
295
296   inline BScreen *getScreen(void) const { return screen; }
297
298   inline Window getFrameWindow(void) const { return frame.window; }
299   inline Window getClientWindow(void) const { return client.window; }
300   inline Window getGroupWindow(void) const { return client.window_group; }
301
302   inline Windowmenu * getWindowmenu(void) const { return windowmenu; }
303
304   inline const char *getTitle(void) const
305   { return client.title.c_str(); }
306   inline const char *getIconTitle(void) const
307   { return client.icon_title.c_str(); }
308
309   inline unsigned int getWorkspaceNumber(void) const
310   { return blackbox_attrib.workspace; }
311   inline unsigned int getWindowNumber(void) const { return window_number; }
312
313   inline const Rect &frameRect(void) const { return frame.rect; }
314   inline const Rect &clientRect(void) const { return client.rect; }
315
316   inline unsigned int getTitleHeight(void) const
317   { return frame.title_h; }
318
319   inline void setWindowNumber(int n) { window_number = n; }
320
321   bool validateClient(void) const;
322   bool setInputFocus(void);
323
324   void setFocusFlag(bool focus);
325   void iconify(void);
326   void deiconify(bool reassoc = True, bool raise = True);
327   void show(void);
328   void close(void);
329   void withdraw(void);
330   void maximize(unsigned int button);
331   void remaximize(void);
332   void shade(void);
333   void stick(void);
334   void reconfigure(void);
335   void updateFocusModel(void);
336   void installColormap(bool install);
337   void restore(bool remap);
338   void configure(int dx, int dy, unsigned int dw, unsigned int dh);
339   void setWorkspace(unsigned int n);
340   void changeBlackboxHints(BlackboxHints *net);
341   void restoreAttributes(void);
342
343   void buttonPressEvent(XButtonEvent *be);
344   void buttonReleaseEvent(XButtonEvent *re);
345   void motionNotifyEvent(XMotionEvent *me);
346   void destroyNotifyEvent(XDestroyWindowEvent */*unused*/);
347   void mapRequestEvent(XMapRequestEvent *mre);
348   void unmapNotifyEvent(XUnmapEvent */*unused*/);
349   void reparentNotifyEvent(XReparentEvent */*unused*/);
350   void propertyNotifyEvent(Atom atom);
351   void exposeEvent(XExposeEvent *ee);
352   void configureRequestEvent(XConfigureRequestEvent *cr);
353
354 #ifdef    SHAPE
355   void configureShape(void);
356   void shapeEvent(XShapeEvent * /*unused*/);
357 #endif // SHAPE
358
359   virtual void timeout(void);
360 };
361
362
363 #endif // __Window_hh