aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/BaseCompWindow.hh
diff options
context:
space:
mode:
authorGediminas Liktaras <gliktaras@gmail.com>2011-12-08 13:34:09 (GMT)
committerPaul Tagliamonte <paultag@fluxbox.org>2011-12-10 16:13:19 (GMT)
commitcd339169d1961eb508ea89cee2609ec6d0fc0c15 (patch)
tree01acd158a03fb17a72e067ff0b36701da75e49dc /util/fbcompose/BaseCompWindow.hh
parent85ac5c4b2c6a526992f483a6e91867dc2f82a19e (diff)
downloadfluxbox_paul-cd339169d1961eb508ea89cee2609ec6d0fc0c15.zip
fluxbox_paul-cd339169d1961eb508ea89cee2609ec6d0fc0c15.tar.bz2
fbcompose - A compositing addon for fluxbox window manager.
fbcompose(1) is an optional compositing addon for fluxbox window manager. It augments fluxbox with a number of graphical features. Most notably, fbcompose allows fluxbox to properly display applications that require compositing (docky, for example), adds support for true window transparency (as opposed to fluxbox's pseudo transparency) and provides a plugin framework to extend the compositor's functionality. As this is still a beta version of the compositor, the bugs are likely.
Diffstat (limited to 'util/fbcompose/BaseCompWindow.hh')
-rw-r--r--util/fbcompose/BaseCompWindow.hh409
1 files changed, 409 insertions, 0 deletions
diff --git a/util/fbcompose/BaseCompWindow.hh b/util/fbcompose/BaseCompWindow.hh
new file mode 100644
index 0000000..237b34f
--- /dev/null
+++ b/util/fbcompose/BaseCompWindow.hh
@@ -0,0 +1,409 @@
1/** BaseCompWindow.hh file for the fluxbox compositor. */
2
3// Copyright (c) 2011 Gediminas Liktaras (gliktaras at gmail dot com)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
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 THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21// THE SOFTWARE.
22
23
24#ifndef FBCOMPOSITOR_WINDOW_HH
25#define FBCOMPOSITOR_WINDOW_HH
26
27#include "Enumerations.hh"
28
29#include "FbTk/FbWindow.hh"
30
31#include <X11/Xlib.h>
32#include <X11/extensions/Xdamage.h>
33
34#include <iosfwd>
35#include <vector>
36
37
38namespace FbCompositor {
39
40 class BaseScreen;
41 class BaseCompWindow;
42
43
44 //--- SUPPORTING FUNCTIONS -------------------------------------------------
45
46 /** << output stream operator for the BaseCompWindow class. */
47 std::ostream &operator<<(std::ostream& out, const BaseCompWindow& window);
48
49
50 //--- BASE WINDOW CLASS ----------------------------------------------------
51
52 /**
53 * Base class for composited windows.
54 */
55 class BaseCompWindow : public FbTk::FbWindow {
56 //--- FRIEND OPERATORS -------------------------------------------------
57
58 friend std::ostream &operator<<(std::ostream& out, const BaseCompWindow& window);
59
60 public:
61 //--- CONSTRUCTORS AND DESTRUCTORS -------------------------------------
62
63 /** Constructor. */
64 BaseCompWindow(const BaseScreen &screen, Window window_xid, bool track_damage_deltas);
65
66 /** Destructor. */
67 virtual ~BaseCompWindow();
68
69
70 //--- ACCESSORS --------------------------------------------------------
71
72 /** \returns the window's opacity. */
73 int alpha() const;
74
75 /** \returns the window's contents as a pixmap. */
76 Pixmap contentPixmap() const;
77
78 /** \returns whether the window is damaged or not. */
79 bool isDamaged() const;
80
81 /** \returns whether the window is ignored or not. */
82 bool isIgnored() const;
83
84 /** \returns whether the screen is mapped or not. */
85 bool isMapped() const;
86
87 /** \returns the window's screen. */
88 const BaseScreen &screen() const;
89
90 /** \returns the type of the window. */
91 WindowType type() const;
92
93 /** \returns the window's visual. */
94 Visual *visual();
95
96 /** \returns the window's visual (const version). */
97 const Visual *visual() const;
98
99 /** \returns the window's class. */
100 int windowClass() const;
101
102
103 /** \returns the window's dimensions as an XRectangle (borders factored in). */
104 XRectangle dimensions() const;
105
106 /** \returns the window's height with borders factored in. */
107 unsigned int realHeight() const;
108
109 /** \returns the window's width with borders factored in. */
110 unsigned int realWidth() const;
111
112
113 //--- PROPERTY ACCESS --------------------------------------------------
114
115 /** \returns the value of the specified property. */
116 template<class T>
117 std::vector<T> propertyValue(Atom property_atom);
118
119 /** Convenience function for accessing properties with a single value. */
120 template<class T>
121 T singlePropertyValue(Atom property_atom, T default_value);
122
123 /** Convenience function that returns the first existing single atom value. */
124 template<class T>
125 T firstSinglePropertyValue(std::vector<Atom> property_atoms, T default_value);
126
127
128 //--- WINDOW MANIPULATION ----------------------------------------------
129
130 /** Add damage to a window. */
131 virtual void addDamage();
132
133 /** Mark the window as mapped. */
134 virtual void setMapped();
135
136 /** Mark the window as unmapped. */
137 virtual void setUnmapped();
138
139 /** Update the window's contents. */
140 virtual void updateContents();
141
142 /** Update window's geometry. */
143 virtual void updateGeometry();
144
145 /** Update window's property. */
146 virtual void updateProperty(Atom property, int state);
147
148
149 /** Set the clip shape as changed. */
150 void setClipShapeChanged();
151
152 /** Sets window's ignore flag. */
153 void setIgnored(bool ignore_status);
154
155
156 protected:
157 //--- PROTECTED ACCESSORS ----------------------------------------------
158
159 /** \returns whether the chip shape changed since the last update. */
160 int clipShapeChanged() const;
161
162 /** \returns the number of rectangles that make up the clip shape. */
163 int clipShapeRectCount() const;
164
165 /** \returns the rectangles that make up the clip shape. */
166 XRectangle *clipShapeRects() const;
167
168
169 /** \returns whether the window has been remapped since the last update. */
170 bool isRemapped() const;
171
172 /** \returns whether the window has been resized since the last update. */
173 bool isResized() const;
174
175
176 //--- PROTECTED WINDOW MANIPULATION ------------------------------------
177
178 /** Removes all damage from the window. */
179 void clearDamage();
180
181 /** Updates the window's content pixmap. */
182 void updateContentPixmap();
183
184 /** Update the window's clip shape. */
185 virtual void updateShape();
186
187
188 private:
189 //--- CONSTRUCTORS -----------------------------------------------------
190
191 /** Copy constructor. */
192 BaseCompWindow(const BaseCompWindow&);
193
194 /** Assignment operator. */
195 BaseCompWindow &operator=(const BaseCompWindow&);
196
197
198 //--- PROPERTY UPDATE FUNCTIONS ----------------------------------------
199
200 /** Updates window's alpha. */
201 void updateAlpha();
202
203 /** Updates the type of the window. */
204 void updateWindowType();
205
206
207 //--- CONVENIENCE FUNCTIONS --------------------------------------------
208
209 /** Returns the raw contents of a property. */
210 bool rawPropertyData(Atom property_atom, Atom property_type,
211 unsigned long *item_count_return, unsigned char **data_return);
212
213
214
215 //--- WINDOW ATTRIBUTES ------------------------------------------------
216
217 /** Window's screen. */
218 const BaseScreen &m_screen;
219
220
221 /** Window opacity. */
222 int m_alpha;
223
224 /** Window's class. */
225 int m_class;
226
227 /** Window's map state. */
228 bool m_is_mapped;
229
230 /** Window's type. */
231 WindowType m_type;
232
233 /** Window's visual. */
234 Visual *m_visual;
235
236
237 /** Window's content pixmap. */
238 Pixmap m_content_pixmap;
239
240 /** Window's damage object. */
241 Damage m_damage;
242
243 /** Shows whether the window is damaged. */
244 bool m_is_damaged;
245
246 /** Shows whether the window should be ignored by the renderers or not. */
247 bool m_is_ignored;
248
249 /** Shows whether the window has been remapped since the last update. */
250 bool m_is_remapped;
251
252 /** Shows whether the window has been resized since the last update. */
253 bool m_is_resized;
254
255
256 /** The number of rectangles of window's clip shape. */
257 int m_clip_shape_rect_count;
258
259 /** Rectangles, that make up the window's clip shape. */
260 XRectangle *m_clip_shape_rects;
261
262 /** Shows whether the clip shape changed since the last update. */
263 bool m_clip_shape_changed;
264 };
265
266
267 //--- INLINE FUNCTIONS -----------------------------------------------------
268
269 // Returns the window's opacity.
270 inline int BaseCompWindow::alpha() const {
271 return m_alpha;
272 }
273
274 // Returns whether the chip shape changed since the last update.
275 inline int BaseCompWindow::clipShapeChanged() const {
276 return m_clip_shape_changed;
277 }
278
279 // Returns the number of rectangles that make up the clip shape.
280 inline int BaseCompWindow::clipShapeRectCount() const {
281 return m_clip_shape_rect_count;
282 }
283
284 // Returns the rectangles that make up the clip shape.
285 inline XRectangle *BaseCompWindow::clipShapeRects() const {
286 return m_clip_shape_rects;
287 }
288
289 // Returns the window's contents as a pixmap.
290 inline Pixmap BaseCompWindow::contentPixmap() const {
291 return m_content_pixmap;
292 }
293
294 // Returns the window's dimensions as an XRectangle (borders factored in).
295 inline XRectangle BaseCompWindow::dimensions() const {
296 XRectangle dim = { x(), y(), realWidth(), realHeight() };
297 return dim;
298 }
299
300 // Returns whether the window is damaged or not.
301 inline bool BaseCompWindow::isDamaged() const {
302 return m_is_damaged;
303 }
304
305 // Returns whether the window is ignored or not.
306 inline bool BaseCompWindow::isIgnored() const {
307 return m_is_ignored;
308 }
309
310 // Returns whether the window is mapped or not.
311 inline bool BaseCompWindow::isMapped() const {
312 return m_is_mapped;
313 }
314
315 // Returns whether the window has been remapped since the last update.
316 inline bool BaseCompWindow::isRemapped() const {
317 return m_is_remapped;
318 }
319
320 // Returns whether the window has been resized since the last update.
321 inline bool BaseCompWindow::isResized() const {
322 return m_is_resized;
323 }
324
325 // Returns the window's screen.
326 inline const BaseScreen &BaseCompWindow::screen() const {
327 return m_screen;
328 }
329
330 // Sets the window's ignore flag.
331 inline void BaseCompWindow::setIgnored(bool ignore_status) {
332 m_is_ignored = ignore_status;
333 }
334
335 // Returns the window's height with borders factored in.
336 inline unsigned int BaseCompWindow::realHeight() const {
337 return height() + 2 * borderWidth();
338 }
339
340 // Returns the window's width with borders factored in.
341 inline unsigned int BaseCompWindow::realWidth() const {
342 return width() + 2 * borderWidth();
343 }
344
345 // Returns the type of the window.
346 inline WindowType BaseCompWindow::type() const {
347 return m_type;
348 }
349
350 // Returns the window's visual.
351 inline Visual *BaseCompWindow::visual() {
352 return m_visual;
353 }
354
355 // Returns the window's visual (const version).
356 inline const Visual *BaseCompWindow::visual() const {
357 return m_visual;
358 }
359
360 // Returns the window's class.
361 inline int BaseCompWindow::windowClass() const {
362 return m_class;
363 }
364
365
366 //--- PROPERTY ACCESS ----------------------------------------------------------
367
368 // Returns the value of the specified property.
369 template<class T>
370 std::vector<T> BaseCompWindow::propertyValue(Atom property_atom) {
371 if (property_atom) {
372 unsigned long item_count;
373 T *data;
374
375 if (rawPropertyData(property_atom, AnyPropertyType, &item_count, reinterpret_cast<unsigned char**>(&data))) {
376 std::vector<T> actualData(data, data + item_count);
377 XFree(data);
378 return actualData;
379 }
380 }
381
382 return std::vector<T>();
383 }
384
385 // Convenience function for accessing properties with a single value.
386 template<class T>
387 T BaseCompWindow::singlePropertyValue(Atom property_atom, T default_value) {
388 std::vector<T> values = propertyValue<T>(property_atom);
389 if (values.size() == 0) {
390 return default_value;
391 } else {
392 return values[0];
393 }
394 }
395
396 // Convenience function that returns the first existing single atom value.
397 template<class T>
398 T BaseCompWindow::firstSinglePropertyValue(std::vector<Atom> property_atoms, T default_value) {
399 for (size_t i = 0; i < property_atoms.size(); i++) {
400 std::vector<T> values = propertyValue<T>(property_atoms[i]);
401 if (values.size() != 0) {
402 return values[0];
403 }
404 }
405 return default_value;
406 }
407}
408
409#endif // FBCOMPOSITOR_WINDOW_HH