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