added first revision of the BestFit placement type.
[dana/openbox.git] / src / Window.h
1 // Window.h for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 #ifndef   __Window_hh
24 #define   __Window_hh
25
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #ifdef    SHAPE
29 #  include <X11/extensions/shape.h>
30 #endif // SHAPE
31
32 #include "BaseDisplay.h"
33 #include "Timer.h"
34 #include "Windowmenu.h"
35 #include "Geometry.h"
36
37 // forward declaration
38 class OpenboxWindow;
39
40 #define MwmHintsFunctions     (1l << 0)
41 #define MwmHintsDecorations   (1l << 1)
42
43 #define MwmFuncAll            (1l << 0)
44 #define MwmFuncResize         (1l << 1)
45 #define MwmFuncMove           (1l << 2)
46 #define MwmFuncIconify        (1l << 3)
47 #define MwmFuncMaximize       (1l << 4)
48 #define MwmFuncClose          (1l << 5)
49
50 #define MwmDecorAll           (1l << 0)
51 #define MwmDecorBorder        (1l << 1)
52 #define MwmDecorHandle        (1l << 2)
53 #define MwmDecorTitle         (1l << 3)
54 #define MwmDecorMenu          (1l << 4)
55 #define MwmDecorIconify       (1l << 5)
56 #define MwmDecorMaximize      (1l << 6)
57
58 // this structure only contains 3 elements... the Motif 2.0 structure contains
59 // 5... we only need the first 3... so that is all we will define
60 typedef struct MwmHints {
61   unsigned long flags, functions, decorations;
62 } MwmHints;
63
64 #define PropMwmHintsElements  3
65
66
67 class OpenboxWindow : public TimeoutHandler {
68 private:
69   BImageControl *image_ctrl;
70   Openbox *openbox;
71   BScreen *screen;
72   Display *display;
73   BTimer *timer;
74   OpenboxAttributes openbox_attrib;
75
76   Time lastButtonPressTime;  // used for double clicks, when were we clicked
77   Windowmenu *windowmenu;
78
79   int window_number, workspace_number;
80   unsigned long current_state;
81
82   enum FocusMode { F_NoInput = 0, F_Passive,
83                    F_LocallyActive, F_GloballyActive };
84   FocusMode focus_mode;
85
86   enum ResizeZones {
87     ZoneTop     = 1 << 0,
88     ZoneBottom  = 1 << 1,
89     ZoneLeft    = 1 << 2,
90     ZoneRight   = 1 << 3
91   };
92   unsigned int resize_zone;     // bitmask of ResizeZones values
93
94   struct _flags {
95     Bool moving,             // is moving?
96       resizing,              // is resizing?
97       shaded,                // is shaded?
98       visible,               // is visible?
99       iconic,                // is iconified?
100       transient,             // is a transient window?
101       focused,               // has focus?
102       stuck,                 // is omnipresent
103       modal,                 // is modal? (must be dismissed to continue)
104       send_focus_message,    // should we send focus messages to our client?
105       shaped,                // does the frame use the shape extension?
106       managed;               // under openbox's control?
107                              // maximize is special, the number corresponds
108                              // with a mouse button
109                              // if 0, not maximized
110     unsigned int maximized;  // 1 = HorizVert, 2 = Vertical, 3 = Horizontal
111   } flags;
112
113   struct _client {
114     OpenboxWindow *transient_for,  // which window are we a transient for?
115       *transient;                   // which window is our transient?
116
117     Window window,                  // the client's window
118       window_group;                 // the client's window group
119
120     char *title, *icon_title;
121     size_t title_len;               // strlen(title)
122
123     int x, y,
124       old_bw;                       // client's borderwidth
125
126     unsigned int width, height,
127       title_text_w,                 // width as rendered in the current font
128       min_width, min_height,        // can not be resized smaller
129       max_width, max_height,        // can not be resized larger
130       width_inc, height_inc,        // increment step
131       min_aspect_x, min_aspect_y,   // minimum aspect ratio
132       max_aspect_x, max_aspect_y,   // maximum aspect ratio
133       base_width, base_height,
134       win_gravity;
135
136     unsigned long initial_state, normal_hint_flags, wm_hint_flags;
137
138     MwmHints *mwm_hint;
139     OpenboxHints *openbox_hint;
140   } client;
141
142   struct _functions {
143     Bool resize, move, iconify, maximize, close;
144   } functions;
145
146   /*
147    * client window = the application's window
148    * frame window = the window drawn around the outside of the client window
149    *                by the window manager which contains items like the
150    *                titlebar and close button
151    * title = the titlebar drawn above the client window, it displays the
152    *         window's name and any buttons for interacting with the window,
153    *         such as iconify, maximize, and close
154    * label = the window in the titlebar where the title is drawn
155    * buttons = maximize, iconify, close
156    * handle = the bar drawn at the bottom of the window, which contains the
157    *          left and right grips used for resizing the window
158    * grips = the smaller reactangles in the handle, one of each side of it.
159    *         When clicked and dragged, these resize the window interactively
160    * border = the line drawn around the outside edge of the frame window,
161    *          between the title, the bordered client window, and the handle.
162    *          Also drawn between the grips and the handle
163    */
164
165   /*
166    * what decorations do we have?
167    * this is based on the type of the client window as well as user input
168    * the menu is not really decor, but it goes hand in hand with the decor
169    */
170   struct _decorations {
171     Bool titlebar, handle, border, iconify, maximize, close, menu;
172   } decorations;
173
174   struct _frame {
175     // u -> unfocused, f -> has focus
176     unsigned long ulabel_pixel, flabel_pixel, utitle_pixel,
177       ftitle_pixel, uhandle_pixel, fhandle_pixel, ubutton_pixel,
178       fbutton_pixel, pbutton_pixel, uborder_pixel, fborder_pixel,
179       ugrip_pixel, fgrip_pixel;
180     Pixmap ulabel, flabel, utitle, ftitle, uhandle, fhandle,
181       ubutton, fbutton, pbutton, ugrip, fgrip;
182
183     Window window,       // the frame
184       plate,             // holds the client
185       title,
186       label,
187       handle,
188       close_button, iconify_button, maximize_button,
189       right_grip, left_grip;
190
191
192     unsigned int resize_w, resize_h;
193     int resize_x, resize_y,    // size and location of box drawn while resizing
194       move_x, move_y;          // location of box drawn while moving
195
196     int x, y,
197       grab_x, grab_y,          // where was the window when it was grabbed?
198       y_border, y_handle;      // where within frame is the border and handle
199
200     unsigned int width, height, title_h, label_w, label_h, handle_h,
201       button_w, button_h, grip_w, grip_h, mwm_border_w, border_h, border_w,
202       bevel_w, snap_w, snap_h;
203   } frame;
204
205 protected:
206   Bool getState(void);
207   Window createToplevelWindow(int x, int y, unsigned int width,
208                               unsigned int height, unsigned int borderwidth);
209   Window createChildWindow(Window parent, Cursor = None);
210
211   void getWMName(void);
212   void getWMIconName(void);
213   void getWMNormalHints(void);
214   void getWMProtocols(void);
215   void getWMHints(void);
216   void getMWMHints(void);
217   void getOpenboxHints(void);
218   void setNetWMAttributes(void);
219   void associateClientWindow(void);
220   void decorate(void);
221   void decorateLabel(void);
222   void positionButtons(Bool redecorate_label = False);
223   void positionWindows(void);
224   void createCloseButton(void);
225   void createIconifyButton(void);
226   void createMaximizeButton(void);
227   void redrawLabel(void);
228   void redrawAllButtons(void);
229   void redrawCloseButton(Bool);
230   void redrawIconifyButton(Bool);
231   void redrawMaximizeButton(Bool);
232   void restoreGravity(void);
233   void setGravityOffsets(void);
234   void setState(unsigned long);
235   void upsize(void);
236   void downsize(void);
237   void right_fixsize(int *gx = 0, int *gy = 0);
238   void left_fixsize(int *gx = 0, int *gy = 0);
239
240
241 public:
242   OpenboxWindow(Openbox *b, Window w, BScreen *s = (BScreen *) 0);
243   virtual ~OpenboxWindow(void);
244
245   inline Bool isTransient(void) const { return flags.transient; }
246   inline Bool isFocused(void) const { return flags.focused; }
247   inline Bool isVisible(void) const { return flags.visible; }
248   inline Bool isIconic(void) const { return flags.iconic; }
249   inline Bool isShaded(void) const { return flags.shaded; }
250   inline Bool isMaximized(void) const { return flags.maximized; }
251   inline Bool isMaximizedFull(void) const { return flags.maximized == 1; }
252   inline Bool isStuck(void) const { return flags.stuck; }
253   inline Bool isIconifiable(void) const { return functions.iconify; }
254   inline Bool isMaximizable(void) const { return functions.maximize; }
255   inline Bool isResizable(void) const { return functions.resize; }
256   inline Bool isClosable(void) const { return functions.close; }
257
258   inline Bool hasTitlebar(void) const { return decorations.titlebar; }
259   inline Bool hasTransient(void) const
260   { return ((client.transient) ? True : False); }
261
262   inline OpenboxWindow *getTransient(void) { return client.transient; }
263   inline OpenboxWindow *getTransientFor(void) { return client.transient_for; }
264
265   inline BScreen *getScreen(void) { return screen; }
266
267   inline const Window &getFrameWindow(void) const { return frame.window; }
268   inline const Window &getClientWindow(void) const { return client.window; }
269
270   inline Windowmenu * getWindowmenu(void) { return windowmenu; }
271
272   inline char **getTitle(void) { return &client.title; }
273   inline char **getIconTitle(void) { return &client.icon_title; }
274   inline const int &getXFrame(void) const { return frame.x; }
275   inline const int &getYFrame(void) const { return frame.y; }
276   inline const int &getXClient(void) const { return client.x; }
277   inline const int &getYClient(void) const { return client.y; }
278   inline const int &getWorkspaceNumber(void) const { return workspace_number; }
279   inline const int &getWindowNumber(void) const { return window_number; }
280
281   inline const unsigned int &getWidth(void) const { return frame.width; }
282   inline const unsigned int &getHeight(void) const { return frame.height; }
283   inline const unsigned int &getClientHeight(void) const
284   { return client.height; }
285   inline const unsigned int &getClientWidth(void) const
286   { return client.width; }
287   inline const unsigned int &getTitleHeight(void) const
288   { return frame.title_h; }
289
290   inline const Point getOrigin() const {
291     return Point(frame.x, frame.y);
292   }
293   inline const Point getClientOrigin() const {
294     return Point(client.x, client.y);
295   }
296   inline const Size getSize() const {
297     return Size(frame.width, frame.height);
298   }
299   inline const Size getClientSize() const {
300     return Size(client.width, client.height);
301   }
302   inline const Rect getArea() const {
303     return Rect(frame.x, frame.y, frame.width, frame.height);
304   }
305   inline const Rect getClientArea() const {
306     return Rect(client.x, client.y, client.width, client.height);
307   }
308   
309   inline void setWindowNumber(int n) { window_number = n; }
310   
311   Bool validateClient(void);
312   Bool setInputFocus(void);
313
314   void setFocusFlag(Bool);
315   void iconify(void);
316   void deiconify(Bool reassoc = True, Bool raise = True);
317   void close(void);
318   void withdraw(void);
319   void maximize(unsigned int button);
320   void shade(void);
321   void stick(void);
322   void unstick(void);
323   void reconfigure(void);
324   void installColormap(Bool);
325   void restore(void);
326   void configure(int dx, int dy, unsigned int dw, unsigned int dh);
327   void setWorkspace(int n);
328   void changeOpenboxHints(OpenboxHints *);
329   void restoreAttributes(void);
330
331   void buttonPressEvent(XButtonEvent *);
332   void buttonReleaseEvent(XButtonEvent *);
333   void motionNotifyEvent(XMotionEvent *);
334   void destroyNotifyEvent(XDestroyWindowEvent *);
335   void mapRequestEvent(XMapRequestEvent *);
336   void mapNotifyEvent(XMapEvent *);
337   void unmapNotifyEvent(XUnmapEvent *);
338   void propertyNotifyEvent(Atom);
339   void exposeEvent(XExposeEvent *);
340   void configureRequestEvent(XConfigureRequestEvent *);
341
342 #ifdef    SHAPE
343   void shapeEvent(XShapeEvent *);
344 #endif // SHAPE
345
346   virtual void timeout(void);
347 };
348
349
350 #endif // __Window_hh