aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/plugins/xrender/fade/FadePlugin.cc
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/plugins/xrender/fade/FadePlugin.cc
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/plugins/xrender/fade/FadePlugin.cc')
-rw-r--r--util/fbcompose/plugins/xrender/fade/FadePlugin.cc265
1 files changed, 265 insertions, 0 deletions
diff --git a/util/fbcompose/plugins/xrender/fade/FadePlugin.cc b/util/fbcompose/plugins/xrender/fade/FadePlugin.cc
new file mode 100644
index 0000000..ac01189
--- /dev/null
+++ b/util/fbcompose/plugins/xrender/fade/FadePlugin.cc
@@ -0,0 +1,265 @@
1/** FadePlugin.cc 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#include "FadePlugin.hh"
25
26#include "BaseScreen.hh"
27#include "Utility.hh"
28#include "XRenderScreen.hh"
29#include "XRenderWindow.hh"
30
31#include <algorithm>
32#include <iostream>
33
34using namespace FbCompositor;
35
36
37//--- CONSTRUCTORS AND DESTRUCTORS ---------------------------------------------
38
39// Constructor.
40FadePlugin::FadePlugin(const BaseScreen &screen, const std::vector<FbTk::FbString> &args) :
41 XRenderPlugin(screen, args) {
42
43 m_fade_pict_format = XRenderFindStandardFormat(display(), PictStandardARGB32);
44}
45
46// Destructor.
47FadePlugin::~FadePlugin() { }
48
49
50//--- WINDOW EVENT CALLBACKS ---------------------------------------------------
51
52// Called, whenever a window becomes ignored.
53void FadePlugin::windowBecameIgnored(const BaseCompWindow &window) {
54 std::map<Window, PosFadeData>::iterator pos_it = m_positive_fades.find(window.window());
55 if (pos_it != m_positive_fades.end()) {
56 m_positive_fades.erase(pos_it);
57 }
58
59 std::vector<NegFadeData>::iterator neg_it = m_negative_fades.begin();
60 while (neg_it != m_negative_fades.end()) {
61 if (neg_it->window_id == window.window()) {
62 m_negative_fades.erase(neg_it);
63 break;
64 }
65 ++neg_it;
66 }
67}
68
69// Called, whenever a window is mapped.
70void FadePlugin::windowMapped(const BaseCompWindow &window) {
71 PosFadeData fade;
72
73 std::vector<NegFadeData>::iterator it = m_negative_fades.begin();
74 while (true) {
75 if (it == m_negative_fades.end()) {
76 fade.fade_alpha = 0;
77 fade.fade_picture = new XRenderPicture(xrenderScreen(), m_fade_pict_format, xrenderScreen().pictFilter());
78 break;
79 } else if (it->window_id == window.window()) {
80 fade.fade_alpha = it->fade_alpha;
81 fade.fade_picture = it->fade_picture;
82 m_negative_fades.erase(it);
83 break;
84 } else {
85 ++it;
86 }
87 }
88
89 fade.dimensions = window.dimensions();
90 fade.timer.setTickSize(250000 / 255);
91 fade.timer.start();
92
93 m_positive_fades.insert(std::make_pair(window.window(), fade));
94}
95
96// Called, whenever a window is unmapped.
97void FadePlugin::windowUnmapped(const BaseCompWindow &window) {
98 const XRenderWindow &xr_window = dynamic_cast<const XRenderWindow&>(window);
99 NegFadeData fade;
100
101 std::map<Window, PosFadeData>::iterator it = m_positive_fades.find(window.window());
102 if (it != m_positive_fades.end()) {
103 fade.fade_alpha = it->second.fade_alpha;
104 fade.fade_picture = it->second.fade_picture;
105 m_positive_fades.erase(it);
106 } else {
107 fade.fade_alpha = 255;
108 fade.fade_picture = new XRenderPicture(xrenderScreen(), m_fade_pict_format, xrenderScreen().pictFilter());
109 }
110
111 if (xr_window.contentPicture()->pictureHandle() != None) {
112 fade.dimensions = xr_window.dimensions();
113 fade.mask_picture = xr_window.maskPicture();
114 fade.window_id = xr_window.window();
115
116 fade.job.operation = PictOpOver;
117 fade.job.source_picture = xr_window.contentPicture();
118 fade.job.source_x = 0;
119 fade.job.source_y = 0;
120 fade.job.mask_x = 0;
121 fade.job.mask_y = 0;
122 fade.job.destination_x = xr_window.x();
123 fade.job.destination_y = xr_window.y();
124 fade.job.width = xr_window.realWidth();
125 fade.job.height = xr_window.realHeight();
126
127 fade.timer.setTickSize(250000 / 255);
128 fade.timer.start();
129
130 m_negative_fades.push_back(fade);
131 }
132}
133
134
135//--- RENDERING ACTIONS --------------------------------------------------------
136
137// Rectangles that the plugin wishes to damage.
138const std::vector<XRectangle> &FadePlugin::damagedAreas() {
139 m_damaged_areas.clear(); // TODO: Stop recreating vector's contents.
140
141 std::map<Window, PosFadeData>::iterator pos_it = m_positive_fades.begin();
142 while (pos_it != m_positive_fades.end()) {
143 m_damaged_areas.push_back(pos_it->second.dimensions);
144 ++pos_it;
145 }
146
147 std::vector<NegFadeData>::iterator neg_it = m_negative_fades.begin();
148 while (neg_it != m_negative_fades.end()) {
149 m_damaged_areas.push_back(neg_it->dimensions);
150 ++neg_it;
151 }
152
153 return m_damaged_areas;
154}
155
156
157// Window rendering job initialization.
158void FadePlugin::windowRenderingJobInit(const XRenderWindow &window, XRenderRenderingJob &job) {
159 std::map<Window, PosFadeData>::iterator it = m_positive_fades.find(window.window());
160 if (it != m_positive_fades.end()) {
161 PosFadeData &curFade = it->second;
162
163 int new_ticks;
164 try {
165 new_ticks = curFade.timer.newElapsedTicks();
166 } catch (const TimeException &e) {
167 new_ticks = 255;
168 }
169
170 if ((new_ticks > 0) || (curFade.fade_picture->pictureHandle() == None)) {
171 curFade.fade_alpha += new_ticks;
172 if (curFade.fade_alpha > 255) {
173 curFade.fade_alpha = 255;
174 }
175
176 createFadedMask(curFade.fade_alpha, window.maskPicture(), window.dimensions(), curFade.fade_picture);
177 }
178
179 if (curFade.fade_picture->pictureHandle() != None) {
180 job.mask_picture = curFade.fade_picture;
181 }
182 }
183}
184
185// Extra rendering actions and jobs.
186const std::vector<XRenderRenderingJob> &FadePlugin::extraRenderingActions() {
187 m_extra_jobs.clear(); // TODO: Stop recreating vector's contents.
188
189 for (size_t i = 0; i < m_negative_fades.size(); i++) {
190 int new_ticks;
191 try {
192 new_ticks = m_negative_fades[i].timer.newElapsedTicks();
193 } catch (const TimeException &e) {
194 new_ticks = 255;
195 }
196
197 if ((new_ticks > 0) || (m_negative_fades[i].fade_picture->pictureHandle() == None)) {
198 m_negative_fades[i].fade_alpha -= new_ticks;
199 if (m_negative_fades[i].fade_alpha < 0) {
200 m_negative_fades[i].fade_alpha = 0;
201 }
202
203 createFadedMask(m_negative_fades[i].fade_alpha, m_negative_fades[i].mask_picture,
204 m_negative_fades[i].dimensions, m_negative_fades[i].fade_picture);
205 }
206
207 if (m_negative_fades[i].fade_picture->pictureHandle() != None) {
208 m_negative_fades[i].job.mask_picture = m_negative_fades[i].fade_picture;
209 m_extra_jobs.push_back(m_negative_fades[i].job);
210 }
211 }
212
213 return m_extra_jobs;
214}
215
216// Called after the extra rendering jobs are executed.
217void FadePlugin::postExtraRenderingActions() {
218 std::map<Window, PosFadeData>::iterator pos_it = m_positive_fades.begin();
219 while (pos_it != m_positive_fades.end()) {
220 if (pos_it->second.fade_alpha >= 255) {
221 m_positive_fades.erase(pos_it++);
222 } else {
223 ++pos_it;
224 }
225 }
226
227 std::vector<NegFadeData>::iterator neg_it = m_negative_fades.begin();
228 while (neg_it != m_negative_fades.end()) {
229 if (neg_it->fade_alpha <= 0) {
230 neg_it = m_negative_fades.erase(neg_it);
231 } else {
232 ++neg_it;
233 }
234 }
235}
236
237
238//--- INTERNAL FUNCTIONS -------------------------------------------------------
239
240// Returns the faded mask picture for the given window fade.
241void FadePlugin::createFadedMask(int alpha, XRenderPicturePtr mask, XRectangle dimensions,
242 XRenderPicturePtr fade_picture_return) {
243 if (mask->pictureHandle() == None) {
244 return;
245 }
246
247 Pixmap fadePixmap = createSolidPixmap(screen(), dimensions.width, dimensions.height, alpha * 0x01010101);
248 fade_picture_return->setPixmap(fadePixmap, true);
249
250 XRenderComposite(display(), PictOpIn, mask->pictureHandle(), None, fade_picture_return->pictureHandle(),
251 0, 0, 0, 0, 0, 0, dimensions.width, dimensions.height);
252}
253
254
255//--- PLUGIN MANAGER FUNCTIONS -------------------------------------------------
256
257// Creates a plugin object.
258extern "C" BasePlugin *createPlugin(const BaseScreen &screen, const std::vector<FbTk::FbString> &args) {
259 return new FadePlugin(screen, args);
260}
261
262// Returns the type of the plugin.
263extern "C" FbCompositor::PluginType pluginType() {
264 return Plugin_XRender;
265}