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)
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:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
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.
27 #include <X11/Xutil.h>
29 # include <X11/extensions/shape.h>
32 #include "BaseDisplay.h"
34 #include "Windowmenu.h"
37 // forward declaration
40 #define MwmHintsFunctions (1l << 0)
41 #define MwmHintsDecorations (1l << 1)
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)
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)
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
;
64 #define PropMwmHintsElements 3
67 class OpenboxWindow
: public TimeoutHandler
{
69 BImageControl
*image_ctrl
;
74 OpenboxAttributes openbox_attrib
;
76 Time lastButtonPressTime
; // used for double clicks, when were we clicked
77 Windowmenu
*windowmenu
;
79 int window_number
, workspace_number
;
80 unsigned long current_state
;
82 enum FocusMode
{ F_NoInput
= 0, F_Passive
,
83 F_LocallyActive
, F_GloballyActive
};
92 unsigned int resize_zone
; // bitmask of ResizeZones values
95 Bool moving
, // is moving?
96 resizing
, // is resizing?
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
114 OpenboxWindow
*transient_for
, // which window are we a transient for?
115 *transient
; // which window is our transient?
117 Window window
, // the client's window
118 window_group
; // the client's window group
120 char *title
, *icon_title
;
121 size_t title_len
; // strlen(title)
124 old_bw
; // client's borderwidth
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
,
136 unsigned long initial_state
, normal_hint_flags
, wm_hint_flags
;
139 OpenboxHints
*openbox_hint
;
143 Bool resize
, move
, iconify
, maximize
, close
;
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
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
170 struct _decorations
{
171 Bool titlebar
, handle
, border
, iconify
, maximize
, close
, menu
;
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
;
183 Window window
, // the frame
184 plate
, // holds the client
188 close_button
, iconify_button
, maximize_button
,
189 right_grip
, left_grip
;
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
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
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
,
207 Window
createToplevelWindow(int x
, int y
, unsigned int width
,
208 unsigned int height
, unsigned int borderwidth
);
209 Window
createChildWindow(Window parent
, Cursor
= None
);
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);
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);
237 void right_fixsize(int *gx
= 0, int *gy
= 0);
238 void left_fixsize(int *gx
= 0, int *gy
= 0);
242 OpenboxWindow(Openbox
&b
, Window w
, BScreen
*s
= (BScreen
*) 0);
243 virtual ~OpenboxWindow(void);
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
; }
258 inline Bool
hasTitlebar(void) const { return decorations
.titlebar
; }
259 inline Bool
hasTransient(void) const
260 { return ((client
.transient
) ? True
: False
); }
262 inline OpenboxWindow
*getTransient(void) { return client
.transient
; }
263 inline OpenboxWindow
*getTransientFor(void) { return client
.transient_for
; }
265 inline BScreen
*getScreen(void) { return screen
; }
267 inline const Window
&getFrameWindow(void) const { return frame
.window
; }
268 inline const Window
&getClientWindow(void) const { return client
.window
; }
270 inline Windowmenu
* getWindowmenu(void) { return windowmenu
; }
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
; }
281 //inline const unsigned int &getWidth(void) const { return frame.width; }
282 //inline const unsigned int &getHeight(void) const {
283 // if (!flags.shaded)
284 // return frame.height;
286 // return frame.title_h;
288 //inline const unsigned int &getClientHeight(void) const
289 //{ return client.height; }
290 //inline const unsigned int &getClientWidth(void) const
291 //{ return client.width; }
292 inline const unsigned int &getTitleHeight(void) const
293 { return frame
.title_h
; }
295 //inline const Point origin() const {
296 // return Point(frame.x, frame.y);
298 //inline const Point clientOrigin() const {
299 // return Point(client.x, client.y);
301 //inline const Size size() const {
302 // return Size(frame.width, flags.shaded ? frame.title_h : frame.height);
304 //inline const Size clientSize() const {
305 // return Size(client.width, client.height);
307 inline const Rect
area() const {
308 return Rect(frame
.x
, frame
.y
, frame
.width
,
309 flags
.shaded
? frame
.title_h
: frame
.height
);
311 inline const Rect
clientArea() const {
312 return Rect(client
.x
, client
.y
, client
.width
, client
.height
);
315 inline void setWindowNumber(int n
) { window_number
= n
; }
317 Bool
validateClient(void);
318 Bool
setInputFocus(void);
320 void setFocusFlag(Bool
);
322 void deiconify(Bool reassoc
= True
, Bool raise
= True
);
325 void maximize(unsigned int button
);
329 void reconfigure(void);
330 void installColormap(Bool
);
332 void configure(int dx
, int dy
, unsigned int dw
, unsigned int dh
);
333 void setWorkspace(int n
);
334 void changeOpenboxHints(OpenboxHints
*);
335 void restoreAttributes(void);
337 void buttonPressEvent(XButtonEvent
*);
338 void buttonReleaseEvent(XButtonEvent
*);
339 void motionNotifyEvent(XMotionEvent
*);
340 void destroyNotifyEvent(XDestroyWindowEvent
*);
341 void mapRequestEvent(XMapRequestEvent
*);
342 void mapNotifyEvent(XMapEvent
*);
343 void unmapNotifyEvent(XUnmapEvent
*);
344 void propertyNotifyEvent(Atom
);
345 void exposeEvent(XExposeEvent
*);
346 void configureRequestEvent(XConfigureRequestEvent
*);
349 void shapeEvent(XShapeEvent
*);
352 virtual void timeout(void);
356 #endif // __Window_hh