]> icculus.org git repositories - mikachu/openbox.git/blob - src/Window.h
adding --add-missing to automake call
[mikachu/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   bool place_window;         // place the window ourselves when mapped
82
83   enum FocusMode { F_NoInput = 0, F_Passive,
84                    F_LocallyActive, F_GloballyActive };
85   FocusMode focus_mode;
86
87   enum ResizeZones {
88     ZoneTop     = 1 << 0,
89     ZoneBottom  = 1 << 1,
90     ZoneLeft    = 1 << 2,
91     ZoneRight   = 1 << 3
92   };
93   unsigned int resize_zone;     // bitmask of ResizeZones values
94
95   struct _flags {
96     Bool moving,             // is moving?
97       resizing,              // is resizing?
98       shaded,                // is shaded?
99       visible,               // is visible?
100       iconic,                // is iconified?
101       transient,             // is a transient window?
102       focused,               // has focus?
103       stuck,                 // is omnipresent
104       modal,                 // is modal? (must be dismissed to continue)
105       send_focus_message,    // should we send focus messages to our client?
106       shaped,                // does the frame use the shape extension?
107       managed;               // under openbox's control?
108                              // maximize is special, the number corresponds
109                              // with a mouse button
110                              // if 0, not maximized
111     unsigned int maximized;  // 1 = HorizVert, 2 = Vertical, 3 = Horizontal
112   } flags;
113
114   struct _client {
115     OpenboxWindow *transient_for,   // which window are we a transient for?
116       *transient;                   // which window is our transient?
117
118     Window window,                  // the client's window
119       window_group;                 // the client's window group
120
121     char *title, *icon_title;
122     size_t title_len;               // strlen(title)
123
124     int x, y,
125       old_bw;                       // client's borderwidth
126
127     unsigned int width, height,
128       title_text_w,                 // width as rendered in the current font
129       min_width, min_height,        // can not be resized smaller
130       max_width, max_height,        // can not be resized larger
131       width_inc, height_inc,        // increment step
132       min_aspect_x, min_aspect_y,   // minimum aspect ratio
133       max_aspect_x, max_aspect_y,   // maximum aspect ratio
134       base_width, base_height,
135       win_gravity;
136
137     unsigned long initial_state, normal_hint_flags, wm_hint_flags;
138
139     MwmHints *mwm_hint;
140     OpenboxHints *openbox_hint;
141   } client;
142
143   struct _functions {
144     Bool resize, move, iconify, maximize, close;
145   } functions;
146
147   /*
148    * client window = the application's window
149    * frame window = the window drawn around the outside of the client window
150    *                by the window manager which contains items like the
151    *                titlebar and close button
152    * title = the titlebar drawn above the client window, it displays the
153    *         window's name and any buttons for interacting with the window,
154    *         such as iconify, maximize, and close
155    * label = the window in the titlebar where the title is drawn
156    * buttons = maximize, iconify, close
157    * handle = the bar drawn at the bottom of the window, which contains the
158    *          left and right grips used for resizing the window
159    * grips = the smaller reactangles in the handle, one of each side of it.
160    *         When clicked and dragged, these resize the window interactively
161    * border = the line drawn around the outside edge of the frame window,
162    *          between the title, the bordered client window, and the handle.
163    *          Also drawn between the grips and the handle
164    */
165
166   /*
167    * what decorations do we have?
168    * this is based on the type of the client window as well as user input
169    * the menu is not really decor, but it goes hand in hand with the decor
170    */
171   struct _decorations {
172     Bool titlebar, handle, border, iconify, maximize, close, menu;
173   } decorations;
174
175   struct _frame {
176     // u -> unfocused, f -> has focus
177     unsigned long ulabel_pixel, flabel_pixel, utitle_pixel,
178       ftitle_pixel, uhandle_pixel, fhandle_pixel, ubutton_pixel,
179       fbutton_pixel, pbutton_pixel, uborder_pixel, fborder_pixel,
180       ugrip_pixel, fgrip_pixel;
181     Pixmap ulabel, flabel, utitle, ftitle, uhandle, fhandle,
182       ubutton, fbutton, pbutton, ugrip, fgrip;
183
184     Window window,       // the frame
185       plate,             // holds the client
186       title,
187       label,
188       handle,
189       close_button, iconify_button, maximize_button,
190       right_grip, left_grip;
191
192
193     unsigned int resize_w, resize_h;
194     int resize_x, resize_y,    // size and location of box drawn while resizing
195       move_x, move_y;          // location of box drawn while moving
196
197     int x, y,
198       grab_x, grab_y,          // where was the window when it was grabbed?
199       y_border, y_handle;      // where within frame is the border and handle
200
201     unsigned int width, height, title_h, label_w, label_h, handle_h,
202       button_w, button_h, grip_w, grip_h, mwm_border_w, border_h, border_w,
203       bevel_w;
204   } frame;
205
206 protected:
207   Bool getState();
208   Window createToplevelWindow(int x, int y, unsigned int width,
209                               unsigned int height, unsigned int borderwidth);
210   Window createChildWindow(Window parent, Cursor = None);
211
212   void getWMName();
213   void getWMIconName();
214   void getWMNormalHints();
215   void getWMProtocols();
216   void getWMHints();
217   void getMWMHints();
218   void getOpenboxHints();
219   void setNetWMAttributes();
220   void associateClientWindow();
221   void decorate();
222   void decorateLabel();
223   void positionButtons();
224   void positionWindows();
225   void createCloseButton();
226   void createIconifyButton();
227   void createMaximizeButton();
228   void redrawLabel();
229   void redrawAllButtons();
230   void redrawCloseButton(Bool);
231   void redrawIconifyButton(Bool);
232   void redrawMaximizeButton(Bool);
233   void restoreGravity();
234   void setGravityOffsets();
235   void setState(unsigned long);
236   void upsize();
237   void downsize();
238   void right_fixsize(int *gx = 0, int *gy = 0);
239   void left_fixsize(int *gx = 0, int *gy = 0);
240   void doMove(int x, int y);
241
242
243 public:
244   OpenboxWindow(Openbox &b, Window w, BScreen *s = (BScreen *) 0);
245   virtual ~OpenboxWindow();
246
247   inline Bool isTransient() const { return flags.transient; }
248   inline Bool isFocused() const { return flags.focused; }
249   inline Bool isVisible() const { return flags.visible; }
250   inline Bool isIconic() const { return flags.iconic; }
251   inline Bool isShaded() const { return flags.shaded; }
252   inline Bool isMaximized() const { return flags.maximized; }
253   inline Bool isMaximizedFull() const { return flags.maximized == 1; }
254   inline Bool isStuck() const { return flags.stuck; }
255   inline Bool isIconifiable() const { return functions.iconify; }
256   inline Bool isMaximizable() const { return functions.maximize; }
257   inline Bool isResizable() const { return functions.resize; }
258   inline Bool isClosable() const { return functions.close; }
259
260   inline Bool hasTitlebar() const { return decorations.titlebar; }
261   inline Bool hasTransient() const
262   { return ((client.transient) ? True : False); }
263
264   inline OpenboxWindow *getTransient() { return client.transient; }
265   inline OpenboxWindow *getTransientFor() { return client.transient_for; }
266
267   inline BScreen *getScreen() { return screen; }
268
269   inline const Window &getFrameWindow() const { return frame.window; }
270   inline const Window &getClientWindow() const { return client.window; }
271
272   inline Windowmenu * getWindowmenu() { return windowmenu; }
273
274   inline char **getTitle() { return &client.title; }
275   inline char **getIconTitle() { return &client.icon_title; }
276   //inline const int &getXFrame() const { return frame.x; }
277   //inline const int &getYFrame() const { return frame.y; }
278   //inline const int &getXClient() const { return client.x; }
279   //inline const int &getYClient() const { return client.y; }
280   inline const int &getWorkspaceNumber() const { return workspace_number; }
281   inline const int &getWindowNumber() const { return window_number; }
282
283   //inline const unsigned int &getWidth() const { return frame.width; }
284   //inline const unsigned int &getHeight() const {
285   //  if (!flags.shaded)
286   //    return frame.height;
287   //  else
288   //    return frame.title_h;
289   //}
290   //inline const unsigned int &getClientHeight() const
291   //{ return client.height; }
292   //inline const unsigned int &getClientWidth() const
293   //{ return client.width; }
294   inline const unsigned int &getTitleHeight() const
295   { return frame.title_h; }
296
297   //inline const Point origin() const {
298   //  return Point(frame.x, frame.y);
299   //}
300   //inline const Point clientOrigin() const {
301   //  return Point(client.x, client.y);
302   //}
303   //inline const Size size() const {
304   //  return Size(frame.width, flags.shaded ? frame.title_h : frame.height);
305   //}
306   //inline const Size clientSize() const {
307   //  return Size(client.width, client.height);
308   //}
309   inline const Rect area() const {
310     return Rect(frame.x, frame.y, frame.width,
311                 flags.shaded ? frame.title_h : frame.height);
312   }
313   inline const Rect clientArea() const {
314     return Rect(client.x, client.y, client.width, client.height);
315   }
316   
317   inline void setWindowNumber(int n) { window_number = n; }
318   
319   bool validateClient();
320   bool setInputFocus();
321
322   void setFocusFlag(Bool);
323   void iconify();
324   void deiconify(bool reassoc = true, bool raise = true, bool initial = false);
325   void close();
326   void withdraw();
327   void maximize(unsigned int button);
328   void shade();
329   void stick();
330   void unstick();
331   void reconfigure();
332   void installColormap(Bool);
333   void restore();
334   void configure(int dx, int dy, unsigned int dw, unsigned int dh);
335   void setWorkspace(int n);
336   void changeOpenboxHints(OpenboxHints *);
337   void restoreAttributes();
338
339   void startMove(int x, int y);
340   void endMove();
341   
342   void buttonPressEvent(XButtonEvent *);
343   void buttonReleaseEvent(XButtonEvent *);
344   void motionNotifyEvent(XMotionEvent *);
345   void destroyNotifyEvent(XDestroyWindowEvent *);
346   void mapRequestEvent(XMapRequestEvent *);
347   void mapNotifyEvent(XMapEvent *);
348   void unmapNotifyEvent(XUnmapEvent *);
349   void propertyNotifyEvent(Atom);
350   void exposeEvent(XExposeEvent *);
351   void configureRequestEvent(XConfigureRequestEvent *);
352
353 #ifdef    SHAPE
354   void shapeEvent(XShapeEvent *);
355 #endif // SHAPE
356
357   virtual void timeout();
358 };
359
360
361 #endif // __Window_hh