diff options
author | Gediminas Liktaras <gliktaras@gmail.com> | 2011-12-08 13:34:09 (GMT) |
---|---|---|
committer | Paul Tagliamonte <paultag@fluxbox.org> | 2011-12-10 16:13:19 (GMT) |
commit | cd339169d1961eb508ea89cee2609ec6d0fc0c15 (patch) | |
tree | 01acd158a03fb17a72e067ff0b36701da75e49dc /util/fbcompose/plugins/opengl/preview | |
parent | 85ac5c4b2c6a526992f483a6e91867dc2f82a19e (diff) | |
download | fluxbox_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/opengl/preview')
-rw-r--r-- | util/fbcompose/plugins/opengl/preview/Makefile.am | 38 | ||||
-rw-r--r-- | util/fbcompose/plugins/opengl/preview/PreviewPlugin.cc | 217 | ||||
-rw-r--r-- | util/fbcompose/plugins/opengl/preview/PreviewPlugin.hh | 144 |
3 files changed, 399 insertions, 0 deletions
diff --git a/util/fbcompose/plugins/opengl/preview/Makefile.am b/util/fbcompose/plugins/opengl/preview/Makefile.am new file mode 100644 index 0000000..e99103e --- /dev/null +++ b/util/fbcompose/plugins/opengl/preview/Makefile.am | |||
@@ -0,0 +1,38 @@ | |||
1 | ## Makefile.am 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 | FBCOMPOSE_PATH = @FBCOMPOSE_PATH@ | ||
24 | |||
25 | AM_CXXFLAGS = -Wall -Wextra -pedantic -fPIC | ||
26 | AM_LDFLAGS = -export-dynamic -shared -module -avoid-version | ||
27 | |||
28 | INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/FbTk -I$(top_srcdir)/util/fbcompose | ||
29 | |||
30 | |||
31 | plugindir = $(FBCOMPOSE_PATH)/plugins/opengl | ||
32 | plugin_LTLIBRARIES = preview.la | ||
33 | preview_la_LIBADD = $(top_builddir)/src/FbTk/libFbTk.a | ||
34 | preview_la_SOURCES = PreviewPlugin.hh PreviewPlugin.cc | ||
35 | |||
36 | |||
37 | $(top_builddir)/src/FbTk/libFbTk.a: | ||
38 | cd $(top_builddir)/src/FbTk && make | ||
diff --git a/util/fbcompose/plugins/opengl/preview/PreviewPlugin.cc b/util/fbcompose/plugins/opengl/preview/PreviewPlugin.cc new file mode 100644 index 0000000..97faf34 --- /dev/null +++ b/util/fbcompose/plugins/opengl/preview/PreviewPlugin.cc | |||
@@ -0,0 +1,217 @@ | |||
1 | /** PreviewPlugin.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 "PreviewPlugin.hh" | ||
25 | |||
26 | #include "BaseScreen.hh" | ||
27 | #include "Exceptions.hh" | ||
28 | #include "OpenGLScreen.hh" | ||
29 | #include "OpenGLWindow.hh" | ||
30 | #include "Utility.hh" | ||
31 | |||
32 | #include <algorithm> | ||
33 | #include <iostream> | ||
34 | |||
35 | using namespace FbCompositor; | ||
36 | |||
37 | |||
38 | //--- SHADER SOURCES ----------------------------------------------------------- | ||
39 | |||
40 | /** Plugin's fragment shader source. */ | ||
41 | const GLchar FRAGMENT_SHADER[] = "\ | ||
42 | void preview() { } \n\ | ||
43 | "; | ||
44 | |||
45 | /** Plugin's vertex shader source. */ | ||
46 | const GLchar VERTEX_SHADER[] = "\ | ||
47 | void preview() { } \n\ | ||
48 | "; | ||
49 | |||
50 | |||
51 | //--- CONSTANTS ---------------------------------------------------------------- | ||
52 | |||
53 | /** Maximum height of the preview window. */ | ||
54 | const int MAX_PREVIEW_HEIGHT = 150; | ||
55 | |||
56 | /** Maximum width of the preview window. */ | ||
57 | const int MAX_PREVIEW_WIDTH = 150; | ||
58 | |||
59 | /** Transparency of the preview window. */ | ||
60 | const unsigned int PREVIEW_ALPHA = 200; | ||
61 | |||
62 | /** Time in microseconds until the preview window is shown. */ | ||
63 | const int SLEEP_TIME = 500000; | ||
64 | |||
65 | |||
66 | //--- CONSTRUCTORS AND DESTRUCTORS --------------------------------------------- | ||
67 | |||
68 | // Constructor. | ||
69 | PreviewPlugin::PreviewPlugin(const BaseScreen &screen, const std::vector<FbTk::FbString> &args) : | ||
70 | OpenGLPlugin(screen, args) { | ||
71 | |||
72 | m_tick_tracker.setTickSize(SLEEP_TIME); | ||
73 | } | ||
74 | |||
75 | // Destructor. | ||
76 | PreviewPlugin::~PreviewPlugin() { } | ||
77 | |||
78 | |||
79 | //--- ACCESSORS ---------------------------------------------------------------- | ||
80 | |||
81 | // Returns the additional source code for the fragment shader. | ||
82 | const char *PreviewPlugin::fragmentShader() const { | ||
83 | return FRAGMENT_SHADER; | ||
84 | } | ||
85 | |||
86 | // Returns the additional source code for the vertex shader. | ||
87 | const char *PreviewPlugin::vertexShader() const { | ||
88 | return VERTEX_SHADER; | ||
89 | } | ||
90 | |||
91 | |||
92 | //--- WINDOW EVENT CALLBACKS --------------------------------------------------- | ||
93 | |||
94 | // Called, whenever a new window is created. | ||
95 | void PreviewPlugin::windowCreated(const BaseCompWindow &window) { | ||
96 | const OpenGLWindow &gl_window = dynamic_cast<const OpenGLWindow&>(window); | ||
97 | |||
98 | OpenGLRenderingJob job; | ||
99 | job.prim_pos_buffer = new OpenGLBuffer(openGLScreen(), GL_ARRAY_BUFFER); | ||
100 | job.main_tex_coord_buffer = openGLScreen().defaultTexCoordBuffer(); | ||
101 | job.shape_tex_coord_buffer = openGLScreen().defaultTexCoordBuffer(); | ||
102 | job.alpha = PREVIEW_ALPHA / 255.0f; | ||
103 | job.shader_init = new NullInitializer(); | ||
104 | job.shader_deinit = new NullDeinitializer(); | ||
105 | |||
106 | PreviewWindowData win_data = { gl_window, job }; | ||
107 | m_preview_data.insert(std::make_pair(gl_window.window(), win_data)); | ||
108 | } | ||
109 | |||
110 | /** Called, whenever a window is destroyed. */ | ||
111 | void PreviewPlugin::windowDestroyed(const BaseCompWindow &window) { | ||
112 | std::map<Window, PreviewWindowData>::iterator it = m_preview_data.find(window.window()); | ||
113 | if (it != m_preview_data.end()) { | ||
114 | m_preview_data.erase(it); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | |||
119 | //--- RENDERING ACTIONS -------------------------------------------------------- | ||
120 | |||
121 | /** Extra rendering actions and jobs. */ | ||
122 | const std::vector<OpenGLRenderingJob> &PreviewPlugin::extraRenderingActions() { | ||
123 | m_extra_jobs.clear(); | ||
124 | |||
125 | std::map<Window, PreviewWindowData>::iterator it = m_preview_data.find(screen().currentIconbarItem()); | ||
126 | if (it != m_preview_data.end()) { | ||
127 | PreviewWindowData &cur_preview = it->second; | ||
128 | |||
129 | if (!m_tick_tracker.isRunning()) { | ||
130 | m_tick_tracker.start(); | ||
131 | } | ||
132 | |||
133 | if (cur_preview.window.partitionCount() > 0) { | ||
134 | updatePreviewWindow(cur_preview); | ||
135 | if (m_tick_tracker.totalElapsedTicks() > 0) { | ||
136 | m_extra_jobs.push_back(cur_preview.job); | ||
137 | } | ||
138 | } | ||
139 | } else { | ||
140 | m_tick_tracker.stop(); | ||
141 | } | ||
142 | |||
143 | return m_extra_jobs; | ||
144 | } | ||
145 | |||
146 | |||
147 | //--- INTERNAL FUNCTIONS ------------------------------------------------------- | ||
148 | |||
149 | // Update the preview window. | ||
150 | // TODO: Place the preview window on the edge of the toolbar. | ||
151 | // TODO: Left/Right toolbar orientations. | ||
152 | // TODO: Use all window texture partitions. | ||
153 | void PreviewPlugin::updatePreviewWindow(PreviewWindowData &win_preview) { | ||
154 | XRectangle thumb_dim; | ||
155 | |||
156 | // Find thumbnail's width and height. | ||
157 | int full_thumb_width = std::min<int>(win_preview.window.realWidth(), openGLScreen().maxTextureSize()); | ||
158 | int full_thumb_height = std::min<int>(win_preview.window.realHeight(), openGLScreen().maxTextureSize()); | ||
159 | |||
160 | double scale_factor = 1.0; | ||
161 | scale_factor = std::max(scale_factor, full_thumb_width / double(MAX_PREVIEW_WIDTH)); | ||
162 | scale_factor = std::max(scale_factor, full_thumb_height / double(MAX_PREVIEW_HEIGHT)); | ||
163 | |||
164 | thumb_dim.width = static_cast<int>(full_thumb_width / scale_factor); | ||
165 | thumb_dim.height = static_cast<int>(full_thumb_height / scale_factor); | ||
166 | |||
167 | // Find thumbnail's X and Y coordinates. | ||
168 | int mouse_pos_x, mouse_pos_y; | ||
169 | mousePointerLocation(screen(), mouse_pos_x, mouse_pos_y); | ||
170 | |||
171 | if (screen().heads().size() > 0) { | ||
172 | XRectangle cur_head = screen().heads()[0]; | ||
173 | |||
174 | // First find which head the mouse pointer is on, | ||
175 | for (size_t i = 1; i < screen().heads().size(); i++) { | ||
176 | XRectangle head = screen().heads()[i]; | ||
177 | if ((mouse_pos_x >= head.x) && (mouse_pos_y >= head.y) | ||
178 | && (mouse_pos_x < (head.x + head.width)) | ||
179 | && (mouse_pos_y < (head.y + head.height))) { | ||
180 | cur_head = head; | ||
181 | break; | ||
182 | } | ||
183 | } | ||
184 | |||
185 | // then position the thumbnail there. | ||
186 | thumb_dim.x = mouse_pos_x - thumb_dim.width / 2; | ||
187 | |||
188 | int mid_head = cur_head.y + (cur_head.height / 2); | ||
189 | if (mouse_pos_y < mid_head) { | ||
190 | thumb_dim.y = mouse_pos_y + 10; | ||
191 | } else { | ||
192 | thumb_dim.y = mouse_pos_y - thumb_dim.height - 10; | ||
193 | } | ||
194 | } else { // But WHAT IF we have no heads? | ||
195 | thumb_dim.x = mouse_pos_x - (thumb_dim.width / 2); | ||
196 | thumb_dim.y = mouse_pos_y + 10; | ||
197 | } | ||
198 | |||
199 | // Update job struct variables. | ||
200 | win_preview.job.prim_pos_buffer->bufferPosRectangle(screen().rootWindow().width(), screen().rootWindow().height(), thumb_dim); | ||
201 | |||
202 | win_preview.job.main_texture = win_preview.window.contentTexturePartition(0); | ||
203 | win_preview.job.shape_texture = win_preview.window.shapeTexturePartition(0); | ||
204 | } | ||
205 | |||
206 | |||
207 | //--- PLUGIN MANAGER FUNCTIONS ------------------------------------------------- | ||
208 | |||
209 | // Creates a plugin object. | ||
210 | extern "C" BasePlugin *createPlugin(const BaseScreen &screen, const std::vector<FbTk::FbString> &args) { | ||
211 | return new PreviewPlugin(screen, args); | ||
212 | } | ||
213 | |||
214 | // Returns the type of the plugin. | ||
215 | extern "C" FbCompositor::PluginType pluginType() { | ||
216 | return Plugin_OpenGL; | ||
217 | } | ||
diff --git a/util/fbcompose/plugins/opengl/preview/PreviewPlugin.hh b/util/fbcompose/plugins/opengl/preview/PreviewPlugin.hh new file mode 100644 index 0000000..bd3d07c --- /dev/null +++ b/util/fbcompose/plugins/opengl/preview/PreviewPlugin.hh | |||
@@ -0,0 +1,144 @@ | |||
1 | /** PreviewPlugin.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_PLUGIN_OPENGL_PREVIEW_PREVIEWPLUGIN_HH | ||
25 | #define FBCOMPOSITOR_PLUGIN_OPENGL_PREVIEW_PREVIEWPLUGIN_HH | ||
26 | |||
27 | |||
28 | #include "Enumerations.hh" | ||
29 | #include "OpenGLPlugin.hh" | ||
30 | #include "OpenGLResources.hh" | ||
31 | #include "OpenGLShaders.hh" | ||
32 | #include "TickTracker.hh" | ||
33 | |||
34 | #include "FbTk/FbString.hh" | ||
35 | |||
36 | #include <GL/glew.h> | ||
37 | #include <GL/gl.h> | ||
38 | |||
39 | #include <X11/Xlib.h> | ||
40 | |||
41 | #include <map> | ||
42 | #include <vector> | ||
43 | |||
44 | |||
45 | namespace FbCompositor { | ||
46 | |||
47 | class BaseScreen; | ||
48 | class OpenGLScreen; | ||
49 | class OpenGLWindow; | ||
50 | |||
51 | |||
52 | /** | ||
53 | * Provides window preview feature for the iconbar. | ||
54 | */ | ||
55 | class PreviewPlugin : public OpenGLPlugin { | ||
56 | struct PreviewWindowData; | ||
57 | |||
58 | public : | ||
59 | //--- CONSTRUCTORS AND DESTRUCTORS ------------------------------------- | ||
60 | |||
61 | /** Constructor. */ | ||
62 | PreviewPlugin(const BaseScreen &screen, const std::vector<FbTk::FbString> &args); | ||
63 | |||
64 | /** Destructor. */ | ||
65 | ~PreviewPlugin(); | ||
66 | |||
67 | |||
68 | //--- ACCESSORS -------------------------------------------------------- | ||
69 | |||
70 | /** \returns the name of the plugin. */ | ||
71 | const char *pluginName() const; | ||
72 | |||
73 | |||
74 | /** \returns the additional source code for the fragment shader. */ | ||
75 | const char *fragmentShader() const; | ||
76 | |||
77 | /** \returns the additional source code for the vertex shader. */ | ||
78 | const char *vertexShader() const; | ||
79 | |||
80 | |||
81 | //--- WINDOW EVENT CALLBACKS ------------------------------------------- | ||
82 | |||
83 | /** Called, whenever a new window is created. */ | ||
84 | void windowCreated(const BaseCompWindow &window); | ||
85 | |||
86 | /** Called, whenever a window is destroyed. */ | ||
87 | void windowDestroyed(const BaseCompWindow &window); | ||
88 | |||
89 | |||
90 | //--- RENDERING ACTIONS ------------------------------------------------ | ||
91 | |||
92 | /** Extra rendering actions and jobs. */ | ||
93 | const std::vector<OpenGLRenderingJob> &extraRenderingActions(); | ||
94 | |||
95 | |||
96 | private : | ||
97 | //--- INTERNAL FUNCTIONS ----------------------------------------------- | ||
98 | |||
99 | /** Update the preview window. */ | ||
100 | void updatePreviewWindow(PreviewWindowData &win_preview); | ||
101 | |||
102 | |||
103 | //--- GENERAL RENDERING VARIABLES -------------------------------------- | ||
104 | |||
105 | /** Vector, containing the plugin's extra rendering jobs. */ | ||
106 | std::vector<OpenGLRenderingJob> m_extra_jobs; | ||
107 | |||
108 | |||
109 | /** Timer that signals when the preview window should appear. */ | ||
110 | TickTracker m_tick_tracker; | ||
111 | |||
112 | |||
113 | //--- PREVIEW WINDOW DATA ---------------------------------------------- | ||
114 | |||
115 | /** Holds data about the preview window. */ | ||
116 | struct PreviewWindowData { | ||
117 | const OpenGLWindow &window; ///< The corresponding window object. | ||
118 | OpenGLRenderingJob job; ///< Rendering job of this preview object. | ||
119 | }; | ||
120 | |||
121 | /** A list of potential preview windows. */ | ||
122 | std::map<Window, PreviewWindowData> m_preview_data; | ||
123 | }; | ||
124 | |||
125 | |||
126 | //--- INLINE FUNCTIONS ----------------------------------------------------- | ||
127 | |||
128 | // Returns the name of the plugin. | ||
129 | inline const char *PreviewPlugin::pluginName() const { | ||
130 | return "preview"; | ||
131 | } | ||
132 | } | ||
133 | |||
134 | |||
135 | //--- PLUGIN MANAGER FUNCTIONS ------------------------------------------------- | ||
136 | |||
137 | /** Creates a plugin object. */ | ||
138 | extern "C" FbCompositor::BasePlugin *createPlugin(const FbCompositor::BaseScreen &screen, const std::vector<FbTk::FbString> &args); | ||
139 | |||
140 | /** \returns the type of the plugin. */ | ||
141 | extern "C" FbCompositor::PluginType pluginType(); | ||
142 | |||
143 | |||
144 | #endif // FBCOMPOSITOR_PLUGIN_OPENGL_PREVIEW_PREVIEWPLUGIN_HH | ||