1
// Window.hh for Fluxbox Window Manager
2
// Copyright (c) 2001 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
4
// Window.hh for Blackbox - an X11 Window manager
5
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net)
7
// Permission is hereby granted, free of charge, to any person obtaining a
8
// copy of this software and associated documentation files (the "Software"),
9
// to deal in the Software without restriction, including without limitation
10
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
// and/or sell copies of the Software, and to permit persons to whom the
12
// Software is furnished to do so, subject to the following conditions:
14
// The above copyright notice and this permission notice shall be included in
15
// all copies or substantial portions of the Software.
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
// DEALINGS IN THE SOFTWARE.
25
// $Id: Window.hh 4099 2005-09-07 16:46:17Z simonb $
30
#include "FbTk/Timer.hh"
31
#include "FbTk/Subject.hh"
32
#include "FbTk/EventHandler.hh"
33
#include "FbTk/XLayerItem.hh"
34
#include "FbWinFrame.hh"
37
#include <X11/Xutil.h>
45
class FbWinFrameTheme;
57
/// Creates the window frame and handles any window event for it
58
class FluxboxWindow: public FbTk::EventHandler {
60
/// Represents certain "preset" sets of decorations.
62
DECOR_NONE=0, ///< no decor at all
63
DECOR_NORMAL, ///< normal normal
64
DECOR_TINY, ///< tiny decoration
65
DECOR_TOOL ///< decor tool
70
MwmHintsFunctions = (1l << 0), ///< use motif wm functions
71
MwmHintsDecorations = (1l << 1) ///< use motif wm decorations
74
/// Motif wm functions
76
MwmFuncAll = (1l << 0), ///< all motif wm functions
77
MwmFuncResize = (1l << 1), ///< resize
78
MwmFuncMove = (1l << 2), ///< move
79
MwmFuncIconify = (1l << 3), ///< iconify
80
MwmFuncMaximize = (1l << 4), ///< maximize
81
MwmFuncClose = (1l << 5) ///< close
84
/// Motif wm decorations
86
MwmDecorAll = (1l << 0), /// all decorations
87
MwmDecorBorder = (1l << 1), /// border
88
MwmDecorHandle = (1l << 2), /// handle
89
MwmDecorTitle = (1l << 3), /// title
90
MwmDecorMenu = (1l << 4), /// menu
91
MwmDecorIconify = (1l << 5), /// iconify
92
MwmDecorMaximize = (1l << 6) /// maximize
95
/// attributes for BlackboxHints
98
ATTRIB_MAXHORIZ = 0x02,
99
ATTRIB_MAXVERT = 0x04,
100
ATTRIB_OMNIPRESENT = 0x08,
101
ATTRIB_WORKSPACE = 0x10,
103
ATTRIB_DECORATION = 0x40,
104
ATTRIB_HIDDEN = 0x80,
108
* Types of maximization
111
MAX_NONE = 0, ///< normal state
112
MAX_HORZ = 1, ///< maximize horizontal
113
MAX_VERT = 2, ///< maximize vertical
114
MAX_FULL = 3 ///< maximize full
117
This enumeration represents individual decoration
118
attributes, they can be OR-d together to get a mask.
121
enum DecorationMask {
122
DECORM_TITLEBAR = (1<<0),
123
DECORM_HANDLE = (1<<1),
124
DECORM_BORDER = (1<<2),
125
DECORM_ICONIFY = (1<<3),
126
DECORM_MAXIMIZE = (1<<4),
127
DECORM_CLOSE = (1<<5),
128
DECORM_MENU = (1<<6),
129
DECORM_STICKY = (1<<7),
130
DECORM_SHADE = (1<<8),
132
DECORM_ENABLED = (1<<10),
133
DECORM_LAST = (1<<11) // useful for getting "All"
143
typedef struct _blackbox_hints {
144
unsigned long flags, attrib, workspace, stack;
148
typedef struct _blackbox_attributes {
149
unsigned long flags, attrib, workspace, stack;
150
long premax_x, premax_y;
151
unsigned long premax_w, premax_h;
152
} BlackboxAttributes;
154
typedef std::list<WinClient *> ClientList;
156
/// create a window from a client
157
FluxboxWindow(WinClient &client,
159
FbTk::XLayer &layer);
161
virtual ~FluxboxWindow();
163
/// attach client to our client list and remove it from old window
164
void attachClient(WinClient &client, int x=-1, int y=-1);
165
/// detach client (remove it from list) and create a new window for it
166
bool detachClient(WinClient &client);
167
/// detach current working client if we have more than one
168
void detachCurrentClient();
169
/// remove client from client list
170
bool removeClient(WinClient &client);
171
/// set new current client and raise it
172
bool setCurrentClient(WinClient &client, bool setinput = true);
173
WinClient *findClient(Window win);
176
void moveClientLeft();
177
void moveClientRight();
178
void moveClientRightOf(WinClient &win, WinClient &dest);
179
void moveClientLeftOf(WinClient &win, WinClient &dest);
180
void moveClientTo(WinClient &win, int x, int y);
181
ClientList::iterator getClientInsertPosition(int x, int y);
183
bool setInputFocus();
184
void raiseAndFocus() { raise(); setInputFocus(); }
185
void setFocusFlag(bool flag);
189
void hide() { hide(true); }
190
void hide(bool interrupt_moving);
192
void deiconify(bool reassoc = true, bool do_raise = true);
193
/// close current client
195
/// kill current client
197
/// set the window in withdrawn state
198
void withdraw(bool interrupt_moving);
200
void setFullscreen(bool flag);
202
void maximize(int type = MAX_FULL);
203
/// maximizes the window horizontal
204
void maximizeHorizontal();
205
/// maximizes the window vertical
206
void maximizeVertical();
207
/// maximizes the window fully
222
void moveToLayer(int layernum);
223
void setFocusHidden(bool value);
224
void setIconHidden(bool value);
228
void installColormap(bool);
229
void restore(WinClient *client, bool remap);
230
void restore(bool remap);
231
/// move frame to x, y
232
void move(int x, int y, int gravity = ForgetGravity);
233
/// resize frame to width, height
234
void resize(unsigned int width, unsigned int height);
235
/// move and resize frame to pox x,y and size width, height
236
void moveResize(int x, int y, unsigned int width, unsigned int height, int gravity = ForgetGravity, bool send_event = false);
237
/// move to pos x,y and resize client window to size width, height
238
void moveResizeForClient(int x, int y, unsigned int width, unsigned int height, int gravity = ForgetGravity);
239
void setWorkspace(int n);
240
void changeBlackboxHints(const BlackboxHints &bh);
241
void updateFunctions();
242
void restoreAttributes();
243
void showMenu(int mx, int my);
244
// popup menu on last button press position
253
void handleEvent(XEvent &event);
254
void buttonPressEvent(XButtonEvent &be);
255
void buttonReleaseEvent(XButtonEvent &be);
256
void motionNotifyEvent(XMotionEvent &me);
257
void destroyNotifyEvent(XDestroyWindowEvent &dwe);
258
void mapRequestEvent(XMapRequestEvent &mre);
259
void mapNotifyEvent(XMapEvent &mapev);
260
void unmapNotifyEvent(XUnmapEvent &unmapev);
261
void exposeEvent(XExposeEvent &ee);
262
void configureRequestEvent(XConfigureRequestEvent &ce);
263
void propertyNotifyEvent(WinClient &client, Atom a);
264
void enterNotifyEvent(XCrossingEvent &ev);
265
void leaveNotifyEvent(XCrossingEvent &ev);
268
void setDecoration(Decoration decoration, bool apply = true);
269
void applyDecorations(bool initial = false);
270
void toggleDecoration();
272
unsigned int decorationMask() const;
273
void setDecorationMask(unsigned int mask);
280
// @return NormalState | IconicState | WithdrawnState
281
unsigned int getWmState() const { return m_current_state; }
282
// whether this window can be tabbed with other windows,
283
// and others tabbed with it
284
inline void setTabable(bool tabable) { functions.tabable = tabable; }
285
inline bool isTabable() { return functions.tabable; }
286
inline void setMovable(bool movable) { functions.move = movable; }
287
inline void setResizable(bool resizable) { functions.resize = resizable; }
289
inline bool isFocusHidden() const { return (m_blackbox_attrib.flags & ATTRIB_HIDDEN); }
290
inline bool isIconHidden() const { return m_icon_hidden; }
291
inline bool isManaged() const { return m_initialized; }
292
inline bool isInitialized() const { return m_initialized; }
293
inline bool isFocused() const { return focused; }
294
bool isVisible() const;
295
inline bool isIconic() const { return iconic; }
296
inline bool isShaded() const { return shaded; }
297
inline bool isFullscreen() const { return fullscreen; }
298
inline bool isMaximized() const { return maximized == MAX_FULL; }
299
inline bool isIconifiable() const { return functions.iconify; }
300
inline bool isMaximizable() const { return functions.maximize; }
301
inline bool isResizable() const { return functions.resize; }
302
inline bool isClosable() const { return functions.close; }
303
inline bool isStuck() const { return stuck; }
304
inline bool hasTitlebar() const { return decorations.titlebar; }
305
inline bool isMoving() const { return moving; }
306
inline bool isResizing() const { return resizing; }
307
bool isGroupable() const;
308
inline int numClients() const { return m_clientlist.size(); }
309
inline bool empty() const { return m_clientlist.empty(); }
310
inline ClientList &clientList() { return m_clientlist; }
311
inline const ClientList &clientList() const { return m_clientlist; }
312
inline WinClient &winClient() { return *m_client; }
313
inline const WinClient &winClient() const { return *m_client; }
315
inline const BScreen &screen() const { return m_screen; }
316
inline BScreen &screen() { return m_screen; }
318
inline const FbTk::XLayerItem &layerItem() const { return m_layeritem; }
319
inline FbTk::XLayerItem &layerItem() { return m_layeritem; }
321
Window clientWindow() const;
323
FbTk::FbWindow &fbWindow();
324
const FbTk::FbWindow &fbWindow() const;
327
const FbTk::Menu &menu() const;
329
const FbTk::FbWindow &parent() const { return m_parent; }
330
FbTk::FbWindow &parent() { return m_parent; }
332
const std::string &title() const;
333
const std::string &iconTitle() const;
334
inline int x() const { return frame().x(); }
335
inline int y() const { return frame().y(); }
336
inline unsigned int width() const { return frame().width(); }
337
inline unsigned int height() const { return frame().height(); }
339
unsigned int workspaceNumber() const { return m_workspace_number; }
341
int layerNum() const { return m_layernum; }
342
void setLayerNum(int layernum);
345
unsigned int titlebarHeight() const;
347
int initialState() const;
349
inline FbWinFrame &frame() { return m_frame; }
350
inline const FbWinFrame &frame() const { return m_frame; }
356
FbTk::Subject &stateSig() { return m_statesig; }
357
const FbTk::Subject &stateSig() const { return m_statesig; }
358
FbTk::Subject &layerSig() { return m_layersig; }
359
const FbTk::Subject &layerSig() const { return m_layersig; }
360
FbTk::Subject &hintSig() { return m_hintsig; }
361
const FbTk::Subject &hintSig() const { return m_hintsig; }
362
FbTk::Subject &workspaceSig() { return m_workspacesig; }
363
const FbTk::Subject &workspaceSig() const { return m_workspacesig; }
364
FbTk::Subject &dieSig() { return m_diesig; }
365
const FbTk::Subject &dieSig() const { return m_diesig; }
366
FbTk::Subject &focusSig() { return m_focussig; }
367
FbTk::Subject &titleSig() { return m_titlesig; }
368
/** @} */ // end group signals
370
void reconfigTheme();
372
const timeval &lastFocusTime() const { return m_last_focus_time;}
376
class WinSubject: public FbTk::Subject {
378
WinSubject(FluxboxWindow &w):m_win(w) { }
379
FluxboxWindow &win() { return m_win; }
380
const FluxboxWindow &win() const { return m_win; }
382
FluxboxWindow &m_win;
385
bool oplock; ///< Used to help stop transient loops occurring by locking a window during certain operations
388
static const int PropBlackboxAttributesElements = 8;
393
/// applies a shape mask to the window if it has one
395
void updateClientLeftWindow();
398
void startMoving(Window win);
399
void stopMoving(bool interrupted = false);
400
void startResizing(Window win, int x, int y);
401
void stopResizing(bool interrupted = false);
402
/// try to attach current attaching client to a window at pos x, y
403
void attachTo(int x, int y, bool interrupted = false);
406
/// gets title string from client window and updates frame's title
407
void updateTitleFromClient(WinClient &client);
408
/// gets icon name from client window
409
void updateIconNameFromClient(WinClient &client);
410
void updateMWMHintsFromClient(WinClient &client);
411
void updateBlackboxHintsFromClient(const WinClient &client);
412
void updateRememberStateFromClient(WinClient &client);
413
void saveBlackboxAttribs();
414
void associateClientWindow(bool use_attrs = false, int x = 0, int y = 0, unsigned int width = 1, unsigned int height = 1);
416
void restoreGravity();
417
void setGravityOffsets();
418
void setState(unsigned long stateval, bool setting_up);
420
// modifies left and top if snap is necessary
421
void doSnapping(int &left, int &top);
422
// user_w/h return the values that should be shown to the user
423
void fixsize(int *user_w = 0, int *user_h = 0);
424
void moveResizeClient(WinClient &client, int x, int y, unsigned int width, unsigned int height);
425
/// sends configurenotify to all clients
426
void sendConfigureNotify(bool send_to_netizens = true);
428
static void grabPointer(Window grab_window,
430
unsigned int event_mask,
431
int pointer_mode, int keyboard_mode,
435
static void ungrabPointer(Time time);
437
void associateClient(WinClient &client);
439
// state and hint signals
440
WinSubject m_hintsig, m_statesig, m_layersig, m_workspacesig, m_diesig, m_focussig, m_titlesig;
442
class ThemeListener: public FbTk::Observer {
444
ThemeListener(FluxboxWindow &win):m_win(win) { }
445
void update(FbTk::Subject *) {
446
m_win.reconfigTheme();
449
FluxboxWindow &m_win;
451
ThemeListener m_themelistener;
454
bool moving, resizing, shaded, iconic,
455
focused, stuck, m_initialized, fullscreen;
459
WinClient *m_attaching_tab;
461
BScreen &m_screen; /// screen on which this window exist
463
Display *display; /// display connection
464
BlackboxAttributes m_blackbox_attrib;
466
timeval m_last_focus_time;
468
int m_button_grab_x, m_button_grab_y; // handles last button press event for move
469
int m_last_resize_x, m_last_resize_y; // handles last button press event for resize
470
int m_last_move_x, m_last_move_y; // handles last pos for non opaque moving
471
unsigned int m_last_resize_h, m_last_resize_w; // handles height/width for resize "window"
473
unsigned int m_workspace_number;
474
unsigned long m_current_state; // NormalState | IconicState | Withdrawn
476
Decoration m_old_decoration;
477
unsigned int m_old_decoration_mask;
479
ClientList m_clientlist;
480
WinClient *m_client; ///< current client
481
typedef std::map<WinClient *, FbTk::TextButton *> Client2ButtonMap;
482
Client2ButtonMap m_labelbuttons;
484
// just temporary solution
485
friend class WinClient;
487
struct _decorations {
488
bool titlebar, handle, border, iconify,
489
maximize, close, menu, sticky, shade, tab, enabled;
492
bool m_toggled_decos;
495
bool resize, move, iconify, maximize, close, tabable;
498
bool m_shaped; ///< if the window is shaped with a mask
499
bool m_icon_hidden; ///< if the window is in the iconbar
500
int m_old_pos_x, m_old_pos_y; ///< old position so we can restore from maximized
501
unsigned int m_old_width, m_old_height; ///< old size so we can restore from maximized state
502
int m_last_button_x, ///< last known x position of the mouse button
503
m_last_button_y; ///< last known y position of the mouse button
506
FbTk::XLayerItem m_layeritem;
510
FbTk::FbWindow &m_parent; ///< window on which we draw move/resize rectangle (the "root window")
512
ResizeCorner m_resize_corner;
514
static int s_num_grabs; ///< number of XGrabPointer's