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
;
81 bool place_window
; // place the window ourselves when mapped
83 enum FocusMode
{ F_NoInput
= 0, F_Passive
,
84 F_LocallyActive
, F_GloballyActive
};
93 unsigned int resize_zone
; // bitmask of ResizeZones values
96 Bool moving
, // is moving?
97 resizing
, // is resizing?
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
115 OpenboxWindow
*transient_for
, // which window are we a transient for?
116 *transient
; // which window is our transient?
118 Window window
, // the client's window
119 window_group
; // the client's window group
121 char *title
, *icon_title
;
122 size_t title_len
; // strlen(title)
125 old_bw
; // client's borderwidth
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
,
137 unsigned long initial_state
, normal_hint_flags
, wm_hint_flags
;
140 OpenboxHints
*openbox_hint
;
144 Bool resize
, move
, iconify
, maximize
, close
;
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
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
171 struct _decorations
{
172 Bool titlebar
, handle
, border
, iconify
, maximize
, close
, menu
;
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
;
184 Window window
, // the frame
185 plate
, // holds the client
189 close_button
, iconify_button
, maximize_button
,
190 right_grip
, left_grip
;
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
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
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
,
208 Window
createToplevelWindow(int x
, int y
, unsigned int width
,
209 unsigned int height
, unsigned int borderwidth
);
210 Window
createChildWindow(Window parent
, Cursor
= None
);
213 void getWMIconName();
214 void getWMNormalHints();
215 void getWMProtocols();
218 void getOpenboxHints();
219 void setNetWMAttributes();
220 void associateClientWindow();
222 void decorateLabel();
223 void positionButtons();
224 void positionWindows();
225 void createCloseButton();
226 void createIconifyButton();
227 void createMaximizeButton();
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);
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
);
244 OpenboxWindow(Openbox
&b
, Window w
, BScreen
*s
= (BScreen
*) 0);
245 virtual ~OpenboxWindow();
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
; }
260 inline Bool
hasTitlebar() const { return decorations
.titlebar
; }
261 inline Bool
hasTransient() const
262 { return ((client
.transient
) ? True
: False
); }
264 inline OpenboxWindow
*getTransient() { return client
.transient
; }
265 inline OpenboxWindow
*getTransientFor() { return client
.transient_for
; }
267 inline BScreen
*getScreen() { return screen
; }
269 inline const Window
&getFrameWindow() const { return frame
.window
; }
270 inline const Window
&getClientWindow() const { return client
.window
; }
272 inline Windowmenu
* getWindowmenu() { return windowmenu
; }
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
; }
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;
288 // return frame.title_h;
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
; }
297 //inline const Point origin() const {
298 // return Point(frame.x, frame.y);
300 //inline const Point clientOrigin() const {
301 // return Point(client.x, client.y);
303 //inline const Size size() const {
304 // return Size(frame.width, flags.shaded ? frame.title_h : frame.height);
306 //inline const Size clientSize() const {
307 // return Size(client.width, client.height);
309 inline const Rect
area() const {
310 return Rect(frame
.x
, frame
.y
, frame
.width
,
311 flags
.shaded
? frame
.title_h
: frame
.height
);
313 inline const Rect
clientArea() const {
314 return Rect(client
.x
, client
.y
, client
.width
, client
.height
);
317 inline void setWindowNumber(int n
) { window_number
= n
; }
319 bool validateClient();
320 bool setInputFocus();
322 void setFocusFlag(Bool
);
324 void deiconify(bool reassoc
= true, bool raise
= true, bool initial
= false);
327 void maximize(unsigned int button
);
332 void installColormap(Bool
);
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();
339 void startMove(int x
, int y
);
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
*);
354 void shapeEvent(XShapeEvent
*);
357 virtual void timeout();
361 #endif // __Window_hh