~ubuntu-branches/ubuntu/precise/fluxbox/precise

« back to all changes in this revision

Viewing changes to src/Window.hh

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2008-07-01 10:38:14 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701103814-khx2b6il152x9p93
Tags: 1.0.0+deb1-8
* x-dev has been removed from build-depends (out-of-date package).
* Standards-Version bumped to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Window.hh for Fluxbox Window Manager
2
 
// Copyright (c) 2001 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
3
 
//
4
 
// Window.hh for Blackbox - an X11 Window manager
5
 
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net)
6
 
//
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:
13
 
//
14
 
// The above copyright notice and this permission notice shall be included in
15
 
// all copies or substantial portions of the Software.
16
 
//
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.
24
 
 
25
 
// $Id: Window.hh 4099 2005-09-07 16:46:17Z simonb $
26
 
 
27
 
#ifndef  WINDOW_HH
28
 
#define  WINDOW_HH
29
 
 
30
 
#include "FbTk/Timer.hh"
31
 
#include "FbTk/Subject.hh"
32
 
#include "FbTk/EventHandler.hh"
33
 
#include "FbTk/XLayerItem.hh"
34
 
#include "FbWinFrame.hh"
35
 
 
36
 
#include <X11/Xlib.h>
37
 
#include <X11/Xutil.h>
38
 
 
39
 
#include <vector>
40
 
#include <string>
41
 
#include <memory>
42
 
#include <map>
43
 
 
44
 
class WinClient;
45
 
class FbWinFrameTheme;
46
 
class BScreen;
47
 
class FbWinFrame;
48
 
 
49
 
namespace FbTk {
50
 
class TextButton;
51
 
class MenuTheme;
52
 
class ImageControl;
53
 
class XLayer;
54
 
class Menu;
55
 
}
56
 
 
57
 
/// Creates the window frame and handles any window event for it
58
 
class FluxboxWindow: public FbTk::EventHandler {
59
 
public:
60
 
    /// Represents certain "preset" sets of decorations.
61
 
    enum Decoration {
62
 
        DECOR_NONE=0, ///< no decor at all
63
 
        DECOR_NORMAL, ///< normal normal
64
 
        DECOR_TINY,   ///< tiny decoration
65
 
        DECOR_TOOL    ///< decor tool
66
 
    };
67
 
 
68
 
    /// Motif wm Hints
69
 
    enum {
70
 
        MwmHintsFunctions   = (1l << 0), ///< use motif wm functions
71
 
        MwmHintsDecorations     = (1l << 1) ///< use motif wm decorations
72
 
    };
73
 
 
74
 
    /// Motif wm functions
75
 
    enum MwmFunc{
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
82
 
    };
83
 
 
84
 
    /// Motif wm decorations
85
 
    enum MwmDecor {
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
93
 
    };
94
 
 
95
 
    /// attributes for BlackboxHints
96
 
    enum Attrib {
97
 
        ATTRIB_SHADED = 0x01,
98
 
        ATTRIB_MAXHORIZ = 0x02,
99
 
        ATTRIB_MAXVERT = 0x04,
100
 
        ATTRIB_OMNIPRESENT = 0x08,
101
 
        ATTRIB_WORKSPACE = 0x10,
102
 
        ATTRIB_STACK = 0x20,
103
 
        ATTRIB_DECORATION = 0x40,
104
 
        ATTRIB_HIDDEN = 0x80,
105
 
    };
106
 
 
107
 
    /**
108
 
     * Types of maximization
109
 
     */
110
 
    enum MaximizeMode {
111
 
        MAX_NONE = 0, ///< normal state
112
 
        MAX_HORZ = 1, ///< maximize horizontal
113
 
        MAX_VERT = 2, ///< maximize vertical
114
 
        MAX_FULL = 3  ///< maximize full
115
 
    };
116
 
    /**
117
 
       This enumeration represents individual decoration
118
 
       attributes, they can be OR-d together to get a mask.
119
 
       Useful for saving.
120
 
    */
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),
131
 
        DECORM_TAB      = (1<<9),
132
 
        DECORM_ENABLED  = (1<<10),
133
 
        DECORM_LAST     = (1<<11) // useful for getting "All"
134
 
    };
135
 
 
136
 
    enum ResizeCorner {
137
 
        LEFTTOP,
138
 
        LEFTBOTTOM,
139
 
        RIGHTBOTTOM,
140
 
        RIGHTTOP
141
 
    };
142
 
 
143
 
    typedef struct _blackbox_hints {
144
 
        unsigned long flags, attrib, workspace, stack;
145
 
        long decoration;
146
 
    } BlackboxHints;
147
 
 
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;
153
 
 
154
 
    typedef std::list<WinClient *> ClientList;
155
 
 
156
 
    /// create a window from a client
157
 
    FluxboxWindow(WinClient &client,
158
 
                  FbWinFrameTheme &tm,
159
 
                  FbTk::XLayer &layer);
160
 
 
161
 
    virtual ~FluxboxWindow();
162
 
 
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);
174
 
    void nextClient();
175
 
    void prevClient();
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);
182
 
 
183
 
    bool setInputFocus();
184
 
    void raiseAndFocus() { raise(); setInputFocus(); }
185
 
    void setFocusFlag(bool flag);
186
 
    // map this window
187
 
    void show();
188
 
    // unmap this window
189
 
    void hide() { hide(true); }
190
 
    void hide(bool interrupt_moving);
191
 
    void iconify();
192
 
    void deiconify(bool reassoc = true, bool do_raise = true);
193
 
    /// close current client
194
 
    void close();
195
 
    /// kill current client
196
 
    void kill();
197
 
    /// set the window in withdrawn state
198
 
    void withdraw(bool interrupt_moving);
199
 
    /// set fullscreen
200
 
    void setFullscreen(bool flag);
201
 
    /// toggle maximize
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
208
 
    void maximizeFull();
209
 
    /// toggles shade
210
 
    void shade();
211
 
    /// shades window
212
 
    void shadeOn();
213
 
    /// unshades window
214
 
    void shadeOff();
215
 
    /// toggles sticky
216
 
    void stick();
217
 
    void raise();
218
 
    void lower();
219
 
    void tempRaise();
220
 
    void raiseLayer();
221
 
    void lowerLayer();
222
 
    void moveToLayer(int layernum);
223
 
    void setFocusHidden(bool value);
224
 
    void setIconHidden(bool value);
225
 
    void reconfigure();
226
 
 
227
 
 
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
245
 
    void popupMenu();
246
 
 
247
 
    void pauseMoving();
248
 
    void resumeMoving();
249
 
    /**
250
 
       @name event handlers
251
 
    */
252
 
    //@{
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);
266
 
    //@}
267
 
 
268
 
    void setDecoration(Decoration decoration, bool apply = true);
269
 
    void applyDecorations(bool initial = false);
270
 
    void toggleDecoration();
271
 
 
272
 
    unsigned int decorationMask() const;
273
 
    void setDecorationMask(unsigned int mask);
274
 
 
275
 
    /**
276
 
       @name accessors
277
 
    */
278
 
    //@{
279
 
    
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; }
288
 
 
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; }
314
 
 
315
 
    inline const BScreen &screen() const { return m_screen; }
316
 
    inline BScreen &screen() { return m_screen; }
317
 
 
318
 
    inline const FbTk::XLayerItem &layerItem() const { return m_layeritem; }
319
 
    inline FbTk::XLayerItem &layerItem() { return m_layeritem; }
320
 
 
321
 
    Window clientWindow() const;
322
 
 
323
 
    FbTk::FbWindow &fbWindow();
324
 
    const FbTk::FbWindow &fbWindow() const;
325
 
 
326
 
    FbTk::Menu &menu(); 
327
 
    const FbTk::Menu &menu() const;
328
 
 
329
 
    const FbTk::FbWindow &parent() const { return m_parent; }
330
 
    FbTk::FbWindow &parent() { return m_parent; }
331
 
 
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(); }
338
 
 
339
 
    unsigned int workspaceNumber() const { return m_workspace_number; }
340
 
 
341
 
    int layerNum() const { return m_layernum; }
342
 
    void setLayerNum(int layernum);
343
 
 
344
 
 
345
 
    unsigned int titlebarHeight() const;
346
 
 
347
 
    int initialState() const;
348
 
 
349
 
    inline FbWinFrame &frame() { return m_frame; }
350
 
    inline const FbWinFrame &frame() const { return m_frame; }
351
 
 
352
 
    /**
353
 
       @name signals
354
 
       @{
355
 
    */
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
369
 
 
370
 
    void reconfigTheme();
371
 
 
372
 
    const timeval &lastFocusTime() const { return m_last_focus_time;}
373
 
 
374
 
    //@}
375
 
 
376
 
    class WinSubject: public FbTk::Subject {
377
 
    public:
378
 
        WinSubject(FluxboxWindow &w):m_win(w) { }
379
 
        FluxboxWindow &win() { return m_win; }
380
 
        const FluxboxWindow &win() const { return m_win; }
381
 
    private:
382
 
        FluxboxWindow &m_win;
383
 
    };
384
 
 
385
 
    bool oplock; ///< Used to help stop transient loops occurring by locking a window during certain operations
386
 
 
387
 
private:
388
 
    static const int PropBlackboxAttributesElements = 8;
389
 
 
390
 
    void setupWindow();
391
 
 
392
 
    void init();
393
 
    /// applies a shape mask to the window if it has one
394
 
    void shape();
395
 
    void updateClientLeftWindow();
396
 
    void grabButtons();
397
 
 
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);
404
 
 
405
 
    bool getState();
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);
415
 
 
416
 
    void restoreGravity();
417
 
    void setGravityOffsets();
418
 
    void setState(unsigned long stateval, bool setting_up);
419
 
 
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);
427
 
 
428
 
    static void grabPointer(Window grab_window,
429
 
                     Bool owner_events,
430
 
                     unsigned int event_mask,
431
 
                     int pointer_mode, int keyboard_mode,
432
 
                     Window confine_to,
433
 
                     Cursor cursor,
434
 
                     Time time);
435
 
    static void ungrabPointer(Time time);
436
 
 
437
 
    void associateClient(WinClient &client);
438
 
 
439
 
    // state and hint signals
440
 
    WinSubject m_hintsig, m_statesig, m_layersig, m_workspacesig, m_diesig, m_focussig, m_titlesig;
441
 
 
442
 
    class ThemeListener: public FbTk::Observer {
443
 
    public:
444
 
        ThemeListener(FluxboxWindow &win):m_win(win) { }
445
 
        void update(FbTk::Subject *) {
446
 
            m_win.reconfigTheme();
447
 
        }
448
 
    private:
449
 
        FluxboxWindow &m_win;
450
 
    };
451
 
    ThemeListener m_themelistener;
452
 
 
453
 
    // Window states
454
 
    bool moving, resizing, shaded, iconic,
455
 
        focused, stuck, m_initialized, fullscreen;
456
 
 
457
 
    int maximized;
458
 
 
459
 
    WinClient *m_attaching_tab;
460
 
 
461
 
    BScreen &m_screen; /// screen on which this window exist
462
 
    FbTk::Timer m_timer;
463
 
    Display *display; /// display connection
464
 
    BlackboxAttributes m_blackbox_attrib;
465
 
 
466
 
    timeval m_last_focus_time;
467
 
 
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"
472
 
 
473
 
    unsigned int m_workspace_number;
474
 
    unsigned long m_current_state; // NormalState | IconicState | Withdrawn
475
 
 
476
 
    Decoration m_old_decoration;
477
 
    unsigned int m_old_decoration_mask;
478
 
 
479
 
    ClientList m_clientlist;
480
 
    WinClient *m_client; ///< current client
481
 
    typedef std::map<WinClient *, FbTk::TextButton *> Client2ButtonMap;
482
 
    Client2ButtonMap m_labelbuttons;
483
 
 
484
 
    // just temporary solution
485
 
    friend class WinClient;
486
 
 
487
 
    struct _decorations {
488
 
        bool titlebar, handle, border, iconify,
489
 
            maximize, close, menu, sticky, shade, tab, enabled;
490
 
    } decorations;
491
 
 
492
 
    bool m_toggled_decos;
493
 
 
494
 
    struct _functions {
495
 
        bool resize, move, iconify, maximize, close, tabable;
496
 
    } functions;
497
 
 
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
504
 
    FbWinFrame m_frame;
505
 
 
506
 
    FbTk::XLayerItem m_layeritem;
507
 
    int m_layernum;
508
 
    int m_old_layernum;
509
 
 
510
 
    FbTk::FbWindow &m_parent; ///< window on which we draw move/resize rectangle  (the "root window")
511
 
 
512
 
    ResizeCorner m_resize_corner;
513
 
 
514
 
    static int s_num_grabs; ///< number of XGrabPointer's
515
 
};
516
 
 
517
 
 
518
 
#endif // WINDOW_HH