aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/Compositor.hh
blob: 459bfb0d4bedf9d103b9853c5b159d7792777011 (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
/** Compositor.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_COMPOSITOR_HH
#define FBCOMPOSITOR_COMPOSITOR_HH


#include "Enumerations.hh"
#include "Exceptions.hh"
#include "TickTracker.hh"

#include "FbTk/App.hh"

#include <X11/Xlib.h>

#include <vector>


namespace FbCompositor {

    class BaseScreen;
    class CompositorConfig;


    //--- TYPEDEFS -------------------------------------------------------------

    /** A pointer to an X query extension function. */
    typedef Bool (*QueryExtensionFunction)(Display*, int*, int*);

    /** A pointer to an X query version function. */
    typedef Status (*QueryVersionFunction)(Display*, int*, int*);


    //--- MAIN COMPOSITOR CLASS ------------------------------------------------

    /**
     * Main class for the compositor.
     *
     * Note that if the serverauto rendering mode is selected, ServerAutoApp is
     * used instead. This was done to take out the ad-hoc code out of this
     * class, since this class is too complex for serverauto rendering.
     */
    class Compositor : public FbTk::App {
    public:
        //--- CONSTRUCTORS AND DESTRUCTORS -------------------------------------

        /** Constructor. */
        Compositor(const CompositorConfig &configuration);

        /** Destructor. */
        ~Compositor();


        //--- EVENT LOOP -------------------------------------------------------

        /** Enters the event loop. */
        void eventLoop();


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

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

        /** Assignment operator. */
        Compositor &operator=(const Compositor&);


        //--- INITIALIZATION FUNCTIONS -----------------------------------------

        /** Acquire the ownership of compositing manager selections. */
        Window getCMSelectionOwnership(int screen_number);

        /** Initializes all relevant X's extensions. */
        void initAllExtensions();

        /** Initializes a particular X server extension. */
        void initExtension(const char *extension_name, QueryExtensionFunction extension_func,
                           QueryVersionFunction version_func, const int min_major_ver, const int min_minor_ver,
                           int &event_base, int &error_base);

        /** Initializes monitor heads on every screen. */
        void initHeads();


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

        /** \returns the exposed area in a XExposeEvent as an XRectangle. */
        XRectangle getExposedRect(const XExposeEvent &event);

        /** Locates the screen an event affects. Returns -1 on failure. */
        int screenOfEvent(const XEvent &event);


        //--- COMPOSITOR VARIABLES ---------------------------------------------

        /** A tick tracker that controls when the screen is redrawn. */
        TickTracker m_timer;

        /** Rendering mode in use. */
        RenderingMode m_rendering_mode;

        /** The array of available screens. */
        std::vector<BaseScreen*> m_screens;


        //--- EXTENSION BASE VARIABLES -----------------------------------------

        /** Event base of the X Composite extension. */
        int m_composite_event_base;

        /** Error base of the X Composite extension. */
        int m_composite_error_base;

        /** Event base of the X Damage extension. */
        int m_damage_event_base;

        /** Error base of the X Damage extension. */
        int m_damage_error_base;

        /** Event base of the GLX extension. */
        int m_glx_event_base;

        /** Error base of the GLX extension. */
        int m_glx_error_base;

        /** Event base of the X Fixes extension. */
        int m_fixes_event_base;

        /** Error base of the X Fixes extension. */
        int m_fixes_error_base;

        /** Event base of the X Render extension. */
        int m_render_event_base;

        /** Error base of the X Render extension. */
        int m_render_error_base;

        /** Event base of the X Shape extension. */
        int m_shape_event_base;

        /** Error base of the X Shape extension. */
        int m_shape_error_base;

        /** Event base of the Xinerama extension. */
        int m_xinerama_event_base;

        /** Error base of the Xinerama extension. */
        int m_xinerama_error_base;
    };


    //--- VARIOUS HANDLERS -----------------------------------------------------

    /** Custom signal handler. */
    void handleSignal(int signal);


    /** Custom X error handler (ignore). */
    int ignoreXError(Display *display, XErrorEvent *error);

    /** Custom X error handler (print, continue). */
    int printXError(Display *display, XErrorEvent *error);
}


#endif  // FBCOMPOSITOR_COMPOSITOR_HH