]> Dogcows Code - chaz/openbox/blob - src/Window.h
Initial revision
[chaz/openbox] / 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
36 // forward declaration
37 class OpenboxWindow;
38
39 #define MwmHintsFunctions (1l << 0)
40 #define MwmHintsDecorations (1l << 1)
41
42 #define MwmFuncAll (1l << 0)
43 #define MwmFuncResize (1l << 1)
44 #define MwmFuncMove (1l << 2)
45 #define MwmFuncIconify (1l << 3)
46 #define MwmFuncMaximize (1l << 4)
47 #define MwmFuncClose (1l << 5)
48
49 #define MwmDecorAll (1l << 0)
50 #define MwmDecorBorder (1l << 1)
51 #define MwmDecorHandle (1l << 2)
52 #define MwmDecorTitle (1l << 3)
53 #define MwmDecorMenu (1l << 4)
54 #define MwmDecorIconify (1l << 5)
55 #define MwmDecorMaximize (1l << 6)
56
57 // this structure only contains 3 elements... the Motif 2.0 structure contains
58 // 5... we only need the first 3... so that is all we will define
59 typedef struct MwmHints {
60 unsigned long flags, functions, decorations;
61 } MwmHints;
62
63 #define PropMwmHintsElements 3
64
65
66 class OpenboxWindow : public TimeoutHandler {
67 private:
68 BImageControl *image_ctrl;
69 Openbox *openbox;
70 BScreen *screen;
71 Display *display;
72 BTimer *timer;
73 OpenboxAttributes openbox_attrib;
74
75 Time lastButtonPressTime; // used for double clicks, when were we clicked
76 Windowmenu *windowmenu;
77
78 int window_number, workspace_number;
79 unsigned long current_state;
80
81 enum FocusMode { F_NoInput = 0, F_Passive,
82 F_LocallyActive, F_GloballyActive };
83 FocusMode focus_mode;
84
85 enum ResizeZones {
86 ZoneTop = 1 << 0,
87 ZoneBottom = 1 << 1,
88 ZoneLeft = 1 << 2,
89 ZoneRight = 1 << 3
90 };
91 unsigned int resize_zone; // bitmask of ResizeZones values
92
93 struct _flags {
94 Bool moving, // is moving?
95 resizing, // is resizing?
96 shaded, // is shaded?
97 visible, // is visible?
98 iconic, // is iconified?
99 transient, // is a transient window?
100 focused, // has focus?
101 stuck, // is omnipresent
102 modal, // is modal? (must be dismissed to continue)
103 send_focus_message, // should we send focus messages to our client?
104 shaped, // does the frame use the shape extension?
105 managed; // under openbox's control?
106 // maximize is special, the number corresponds
107 // with a mouse button
108 // if 0, not maximized
109 unsigned int maximized; // 1 = HorizVert, 2 = Vertical, 3 = Horizontal
110 } flags;
111
112 struct _client {
113 OpenboxWindow *transient_for, // which window are we a transient for?
114 *transient; // which window is our transient?
115
116 Window window, // the client's window
117 window_group; // the client's window group
118
119 char *title, *icon_title;
120 size_t title_len; // strlen(title)
121
122 int x, y,
123 old_bw; // client's borderwidth
124
125 unsigned int width, height,
126 title_text_w, // width as rendered in the current font
127 min_width, min_height, // can not be resized smaller
128 max_width, max_height, // can not be resized larger
129 width_inc, height_inc, // increment step
130 min_aspect_x, min_aspect_y, // minimum aspect ratio
131 max_aspect_x, max_aspect_y, // maximum aspect ratio
132 base_width, base_height,
133 win_gravity;
134
135 unsigned long initial_state, normal_hint_flags, wm_hint_flags;
136
137 MwmHints *mwm_hint;
138 OpenboxHints *openbox_hint;
139 } client;
140
141 struct _functions {
142 Bool resize, move, iconify, maximize, close;
143 } functions;
144
145 /*
146 * client window = the application's window
147 * frame window = the window drawn around the outside of the client window
148 * by the window manager which contains items like the
149 * titlebar and close button
150 * title = the titlebar drawn above the client window, it displays the
151 * window's name and any buttons for interacting with the window,
152 * such as iconify, maximize, and close
153 * label = the window in the titlebar where the title is drawn
154 * buttons = maximize, iconify, close
155 * handle = the bar drawn at the bottom of the window, which contains the
156 * left and right grips used for resizing the window
157 * grips = the smaller reactangles in the handle, one of each side of it.
158 * When clicked and dragged, these resize the window interactively
159 * border = the line drawn around the outside edge of the frame window,
160 * between the title, the bordered client window, and the handle.
161 * Also drawn between the grips and the handle
162 */
163
164 /*
165 * what decorations do we have?
166 * this is based on the type of the client window as well as user input
167 * the menu is not really decor, but it goes hand in hand with the decor
168 */
169 struct _decorations {
170 Bool titlebar, handle, border, iconify, maximize, close, menu;
171 } decorations;
172
173 struct _frame {
174 // u -> unfocused, f -> has focus
175 unsigned long ulabel_pixel, flabel_pixel, utitle_pixel,
176 ftitle_pixel, uhandle_pixel, fhandle_pixel, ubutton_pixel,
177 fbutton_pixel, pbutton_pixel, uborder_pixel, fborder_pixel,
178 ugrip_pixel, fgrip_pixel;
179 Pixmap ulabel, flabel, utitle, ftitle, uhandle, fhandle,
180 ubutton, fbutton, pbutton, ugrip, fgrip;
181
182 Window window, // the frame
183 plate, // holds the client
184 title,
185 label,
186 handle,
187 close_button, iconify_button, maximize_button,
188 right_grip, left_grip;
189
190
191 unsigned int resize_w, resize_h;
192 int resize_x, resize_y, // size and location of box drawn while resizing
193 move_x, move_y; // location of box drawn while moving
194
195 int x, y,
196 grab_x, grab_y, // where was the window when it was grabbed?
197 y_border, y_handle; // where within frame is the border and handle
198
199 unsigned int width, height, title_h, label_w, label_h, handle_h,
200 button_w, button_h, grip_w, grip_h, mwm_border_w, border_h, border_w,
201 bevel_w, snap_w, snap_h;
202 } frame;
203
204 protected:
205 Bool getState(void);
206 Window createToplevelWindow(int x, int y, unsigned int width,
207 unsigned int height, unsigned int borderwidth);
208 Window createChildWindow(Window parent, Cursor = None);
209
210 void getWMName(void);
211 void getWMIconName(void);
212 void getWMNormalHints(void);
213 void getWMProtocols(void);
214 void getWMHints(void);
215 void getMWMHints(void);
216 void getOpenboxHints(void);
217 void setNetWMAttributes(void);
218 void associateClientWindow(void);
219 void decorate(void);
220 void decorateLabel(void);
221 void positionButtons(Bool redecorate_label = False);
222 void positionWindows(void);
223 void createCloseButton(void);
224 void createIconifyButton(void);
225 void createMaximizeButton(void);
226 void redrawLabel(void);
227 void redrawAllButtons(void);
228 void redrawCloseButton(Bool);
229 void redrawIconifyButton(Bool);
230 void redrawMaximizeButton(Bool);
231 void restoreGravity(void);
232 void setGravityOffsets(void);
233 void setState(unsigned long);
234 void upsize(void);
235 void downsize(void);
236 void right_fixsize(int *gx = 0, int *gy = 0);
237 void left_fixsize(int *gx = 0, int *gy = 0);
238
239
240 public:
241 OpenboxWindow(Openbox *b, Window w, BScreen *s = (BScreen *) 0);
242 virtual ~OpenboxWindow(void);
243
244 inline Bool isTransient(void) const { return flags.transient; }
245 inline Bool isFocused(void) const { return flags.focused; }
246 inline Bool isVisible(void) const { return flags.visible; }
247 inline Bool isIconic(void) const { return flags.iconic; }
248 inline Bool isShaded(void) const { return flags.shaded; }
249 inline Bool isMaximized(void) const { return flags.maximized; }
250 inline Bool isMaximizedFull(void) const { return flags.maximized == 1; }
251 inline Bool isStuck(void) const { return flags.stuck; }
252 inline Bool isIconifiable(void) const { return functions.iconify; }
253 inline Bool isMaximizable(void) const { return functions.maximize; }
254 inline Bool isResizable(void) const { return functions.resize; }
255 inline Bool isClosable(void) const { return functions.close; }
256
257 inline Bool hasTitlebar(void) const { return decorations.titlebar; }
258 inline Bool hasTransient(void) const
259 { return ((client.transient) ? True : False); }
260
261 inline OpenboxWindow *getTransient(void) { return client.transient; }
262 inline OpenboxWindow *getTransientFor(void) { return client.transient_for; }
263
264 inline BScreen *getScreen(void) { return screen; }
265
266 inline const Window &getFrameWindow(void) const { return frame.window; }
267 inline const Window &getClientWindow(void) const { return client.window; }
268
269 inline Windowmenu * getWindowmenu(void) { return windowmenu; }
270
271 inline char **getTitle(void) { return &client.title; }
272 inline char **getIconTitle(void) { return &client.icon_title; }
273 inline const int &getXFrame(void) const { return frame.x; }
274 inline const int &getYFrame(void) const { return frame.y; }
275 inline const int &getXClient(void) const { return client.x; }
276 inline const int &getYClient(void) const { return client.y; }
277 inline const int &getWorkspaceNumber(void) const { return workspace_number; }
278 inline const int &getWindowNumber(void) const { return window_number; }
279
280 inline const unsigned int &getWidth(void) const { return frame.width; }
281 inline const unsigned int &getHeight(void) const { return frame.height; }
282 inline const unsigned int &getClientHeight(void) const
283 { return client.height; }
284 inline const unsigned int &getClientWidth(void) const
285 { return client.width; }
286 inline const unsigned int &getTitleHeight(void) const
287 { return frame.title_h; }
288
289 inline void setWindowNumber(int n) { window_number = n; }
290
291 Bool validateClient(void);
292 Bool setInputFocus(void);
293
294 void setFocusFlag(Bool);
295 void iconify(void);
296 void deiconify(Bool reassoc = True, Bool raise = True);
297 void close(void);
298 void withdraw(void);
299 void maximize(unsigned int button);
300 void shade(void);
301 void stick(void);
302 void unstick(void);
303 void reconfigure(void);
304 void installColormap(Bool);
305 void restore(void);
306 void configure(int dx, int dy, unsigned int dw, unsigned int dh);
307 void setWorkspace(int n);
308 void changeOpenboxHints(OpenboxHints *);
309 void restoreAttributes(void);
310
311 void buttonPressEvent(XButtonEvent *);
312 void buttonReleaseEvent(XButtonEvent *);
313 void motionNotifyEvent(XMotionEvent *);
314 void destroyNotifyEvent(XDestroyWindowEvent *);
315 void mapRequestEvent(XMapRequestEvent *);
316 void mapNotifyEvent(XMapEvent *);
317 void unmapNotifyEvent(XUnmapEvent *);
318 void propertyNotifyEvent(Atom);
319 void exposeEvent(XExposeEvent *);
320 void configureRequestEvent(XConfigureRequestEvent *);
321
322 #ifdef SHAPE
323 void shapeEvent(XShapeEvent *);
324 #endif // SHAPE
325
326 virtual void timeout(void);
327 };
328
329
330 #endif // __Window_hh
This page took 0.050413 seconds and 4 git commands to generate.