aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/BaseScreen.hh
blob: f8f5208a43fabaec16234e4af0db3ece2bccf8f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/** BaseScreen.hh file for the fluxbox compositor. */

// Copyright (c) 2011 Gediminas Liktaras (gliktaras at gmail dot com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.


#ifndef FBCOMPOSITOR_SCREEN_HH
#define FBCOMPOSITOR_SCREEN_HH

#include "BaseCompWindow.hh"
#include "Enumerations.hh"
#include "PluginManager.hh"

#include <X11/extensions/Xfixes.h>
#include <X11/Xlib.h>

#include <algorithm>
#include <iosfwd>
#include <list>
#include <vector>


namespace FbCompositor {

    class BaseScreen;
    class CompositorConfig;


    //--- SUPPORTING FUNCTIONS -------------------------------------------------

    /** << output stream operator for the BaseScreen class. */
    std::ostream &operator<<(std::ostream& out, const BaseScreen& s);


    //--- BASE CLASS FOR SCREENS -----------------------------------------------

    /**
     * Base class for screen managing classes.
     */
    class BaseScreen {
        //--- FRIEND OPERATORS -------------------------------------------------

        friend std::ostream &operator<<(std::ostream& out, const BaseScreen& s);

    public:
        //--- CONSTRUCTORS AND DESTRUCTORS -------------------------------------

        /** Constructor. */
        BaseScreen(int screen_number, PluginType plugin_type, const CompositorConfig &config);

        /** Destructor. */
        virtual ~BaseScreen();


        //--- OTHER INITIALIZATION ---------------------------------------------

        /** Initializes the screen's plugins. */
        virtual void initPlugins(const CompositorConfig &config);

        /** Initializes all of the windows on the screen. */
        virtual void initWindows();


        //--- ACCESSORS --------------------------------------------------------

        /** \returns the current connection to the X server. */
        Display *display();

        /** \returns the current connection to the X server (const version). */
        const Display *display() const;

        /** \returns the vector with the output heads on this screen. */
        const std::vector<XRectangle> &heads() const;

        /** \returns screen's root window. */
        BaseCompWindow &rootWindow();

        /** \returns screen's root window (const version). */
        const BaseCompWindow &rootWindow() const;


        /** \returns the active window XID. */
        Window activeWindow() const;

        /** \returns the XID of the current iconbar item. */
        Window currentIconbarItem() const;

        /** \returns the index of the current workspace. */
        int currentWorkspace() const;

        /** \returns screen's number. */
        int screenNumber() const;

        /** \returns the number of workspaces on this screen. */
        int workspaceCount() const;


        //--- WINDOW MANIPULATION ----------------------------------------------

        /** Circulates a window on this screen. */
        void circulateWindow(Window window, int place);

        /** Creates a new window on this screen. */
        void createWindow(Window window);

        /** Damages a window on this screen. */
        void damageWindow(Window window, const XRectangle &area);

        /** Destroys a window on this screen. */
        void destroyWindow(Window window);

        /** Maps a window on this screen. */
        void mapWindow(Window window);

        /** Updates window's configuration. */
        void reconfigureWindow(const XConfigureEvent &event);

        /** Reparents a window. */
        void reparentWindow(Window window, Window parent);

        /** Updates window's shape. */
        void updateShape(Window window);

        /** Unmaps a window on this screen. */
        void unmapWindow(Window window);

        /** Updates the value of some window's property. */
        void updateWindowProperty(Window window, Atom property, int state);


        /** Marks a particular window as ignored. */
        void ignoreWindow(Window window);

        /** Checks whether a given window is managed by the current screen. */
        bool isWindowManaged(Window window);


        //--- SCREEN MANIPULATION ----------------------------------------------

        /** Removes all accumulated damage from the screen. */
        void clearScreenDamage();

        /** Updates heads on the current screen. */
        void updateHeads(HeadMode head_mode);


        /** Notifies the screen of a background change. */
        virtual void setRootPixmapChanged();

        /** Notifies the screen of a root window change. */
        virtual void setRootWindowSizeChanged();


        //--- SCREEN RENDERING -------------------------------------------------

        /** Renders the screen's contents. */
        virtual void renderScreen() = 0;


    protected:
        //--- PROTECTED ACCESSORS ----------------------------------------------

        /** \returns the list of windows on the screen. */
        const std::list<BaseCompWindow*> &allWindows() const;

        /** \returns the damaged screen area. */
        XserverRegion damagedScreenArea();

        /** \returns the plugin manager. */
        const PluginManager &pluginManager() const;
        
        /** \returns the reconfigure rectangle. */
        XRectangle reconfigureRectangle() const;


        /** \returns the root window pixmap. */
        Pixmap rootWindowPixmap() const;

        /** \returns whether the root window pixmap was set by the WM. */
        bool wmSetRootWindowPixmap() const;


        //--- SPECIALIZED WINDOW MANIPULATION FUNCTIONS ------------------------

        /** Creates a window object from its XID. */
        virtual BaseCompWindow *createWindowObject(Window window) = 0;


    private:
        //--- CONSTRUCTORS -----------------------------------------------------

        /** Copy constructor. */
        BaseScreen(const BaseScreen&);


        //--- PROPERTY UPDATE FUNCTIONS ----------------------------------------

        /** Update stored active window. */
        void updateActiveWindow();

        /** Update the current iconbar item. */
        void updateCurrentIconbarItem();

        /** Update the current workspace index. */
        void updateCurrentWorkspace();

        /** Update stored reconfigure rectangle. */
        void updateReconfigureRect();

        /** Update stored root window pixmap. */
        void updateRootWindowPixmap(Pixmap new_pixmap = None);

        /** Update the number of workspaces. */
        void updateWorkspaceCount();


        //--- SCREEN DAMAGE FUNCTIONS ------------------------------------------

        /** Damages the reconfigure rectangle on the screen. */
        void damageReconfigureRect();

        /** Damages the given rectangle on the screen. */
        void damageScreenArea(XRectangle area);

        /** Damages the area in the given window. */
        void damageWindowArea(BaseCompWindow *window, XRectangle area);

        /** Damages the area taken by the given window. */
        void damageWholeWindowArea(BaseCompWindow *window);


        //--- INTERNAL FUNCTIONS -----------------------------------------------

        /** \returns the first managed ancestor of a window. */
        std::list<BaseCompWindow*>::iterator getFirstManagedAncestorIterator(Window window);

        /** \returns the parent of a given window. */
        Window getParentWindow(Window window);

        /** \returns an iterator of m_windows that points to the given window. */
        std::list<BaseCompWindow*>::iterator getWindowIterator(Window window);
        
        /** \returns whether the given window is in the ignore list. */
        bool isWindowIgnored(Window window);

        /** Puts a window to a new location on the stack. */
        void restackWindow(std::list<BaseCompWindow*>::iterator &windowIt, Window above);


        //--- MAIN SCREEN DATA -------------------------------------------------

        /** Current connection to the X server. */
        Display *m_display;

        /** Heads of the current display. */
        std::vector<XRectangle> m_heads;

        /** Windows that should be ignored. */
        std::vector<Window> m_ignore_list;

        /** Plugin manager for this screen. */
        PluginManager m_plugin_manager;

        /** Screen's number. */
        int m_screen_number;

        /** Screen's root window. */
        BaseCompWindow m_root_window;

        /** Screen's windows. */
        std::list<BaseCompWindow*> m_windows;


        /** XID of the active window. */
        Window m_active_window_xid;

        /** XID of the current iconbar item. */
        Window m_current_iconbar_item;

        /** The index of the current workspace. */
        int m_current_workspace;

        /** The current reconfigure rectangle. */
        XRectangle m_reconfigure_rect;

        /** The total number of workspaces. */
        int m_workspace_count;


        /** A list of damaged rectangles on the screen. */
        std::vector<XRectangle> m_damaged_screen_rects;

        /** Damaged screen region. */
        XserverRegion m_screen_damage;


        /** Pixmap, containing the desktop background. */
        Pixmap m_root_window_pixmap;

        /** Whether the background pixmap is set by the window manager or this class. */
        bool m_wm_set_root_window_pixmap;
    };


    //--- INLINE FUNCTIONS -----------------------------------------------------

    // Returns the active window XID.
    inline Window BaseScreen::activeWindow() const {
        return m_active_window_xid;
    }

    // Returns all of screen's windows.
    inline const std::list<BaseCompWindow*> &BaseScreen::allWindows() const {
        return m_windows;
    }

    // Returns the XID of the current iconbar item.
    inline Window BaseScreen::currentIconbarItem() const {
        return m_current_iconbar_item;
    }

    // Returns the index of the current workspace.
    inline int BaseScreen::currentWorkspace() const {
        return m_current_workspace;
    }

    // Returns the current connection to the X server.
    inline Display *BaseScreen::display() {
        return m_display;
    }

    // Returns the current connection to the X server (const version).
    inline const Display *BaseScreen::display() const {
        return m_display;
    }

    // Returns the vector with the output heads on this screen.
    inline const std::vector<XRectangle> &BaseScreen::heads() const {
        return m_heads;
    }

    // Returns the plugin manager.
    inline const PluginManager &BaseScreen::pluginManager() const {
        return m_plugin_manager;
    }

    // Returns the reconfigure rectangle.
    inline XRectangle BaseScreen::reconfigureRectangle() const {
        return m_reconfigure_rect;
    }

    // Returns screen's root window.
    inline BaseCompWindow &BaseScreen::rootWindow() {
        return m_root_window;
    }

    // Returns screen's root window (const version).
    inline const BaseCompWindow &BaseScreen::rootWindow() const {
        return m_root_window;
    }

    // Returns the root window pixmap.
    inline Pixmap BaseScreen::rootWindowPixmap() const {
        return m_root_window_pixmap;
    }

    // Returns the screen's number.
    inline int BaseScreen::screenNumber() const {
        return m_screen_number;
    }

    // Returns whether the root window pixmap was set by the WM.
    inline bool BaseScreen::wmSetRootWindowPixmap() const {
        return m_wm_set_root_window_pixmap;
    }

    // Returns the number of workspaces on this screen.
    inline int BaseScreen::workspaceCount() const {
        return m_workspace_count;
    }
}


#endif  // FBCOMPOSITOR_SCREEN_HH