aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/RootTheme.cc208
-rw-r--r--src/RootTheme.hh24
-rw-r--r--src/Screen.cc18
-rw-r--r--src/ScreenResources.cc29
4 files changed, 235 insertions, 44 deletions
diff --git a/src/RootTheme.cc b/src/RootTheme.cc
index 9d73477..dea61cf 100644
--- a/src/RootTheme.cc
+++ b/src/RootTheme.cc
@@ -23,38 +23,216 @@
23 23
24#include "RootTheme.hh" 24#include "RootTheme.hh"
25 25
26#include "FbRootWindow.hh"
26#include "FbCommands.hh" 27#include "FbCommands.hh"
28
27#include "FbTk/App.hh" 29#include "FbTk/App.hh"
30#include "FbTk/Font.hh"
31#include "FbTk/ImageControl.hh"
32#include "FbTk/Resource.hh"
33#include "FbTk/FileUtil.hh"
34#include "FbTk/StringUtil.hh"
35#include "FbTk/TextureRender.hh"
36
37
38#include <X11/Xatom.h>
39
40using std::string;
41
42class BackgroundItem: public FbTk::ThemeItem<FbTk::Texture> {
43public:
44 BackgroundItem(FbTk::Theme &tm, const std::string &name, const std::string &altname):
45 FbTk::ThemeItem<FbTk::Texture>(tm, name, altname) {
46
47 }
48
49 void load(const std::string *o_name = 0, const std::string *o_altname = 0) {
50 const string &m_name = (o_name == 0) ? name() : *o_name;
51 const string &m_altname = (o_altname == 0) ? altName() : *o_altname;
52
53 // create subnames
54 string color_name(FbTk::ThemeManager::instance().
55 resourceValue(m_name + ".color", m_altname + ".Color"));
56 string colorto_name(FbTk::ThemeManager::instance().
57 resourceValue(m_name + ".colorTo", m_altname + ".ColorTo"));
58 string pixmap_name(FbTk::ThemeManager::instance().
59 resourceValue(m_name + ".pixmap", m_altname + ".Pixmap"));
60
61
62 // set default value if we failed to load colors
63 if (!(*this)->color().setFromString(color_name.c_str(),
64 theme().screenNum()))
65 (*this)->color().setFromString("darkgray", theme().screenNum());
66
67 if (!(*this)->colorTo().setFromString(colorto_name.c_str(),
68 theme().screenNum()))
69 (*this)->colorTo().setFromString("white", theme().screenNum());
70
71
72 if (((*this)->type() & FbTk::Texture::SOLID) != 0 && ((*this)->type() & FbTk::Texture::FLAT) == 0)
73 (*this)->calcHiLoColors(theme().screenNum());
74
75 // remove whitespace and set filename
76 FbTk::StringUtil::removeFirstWhitespace(pixmap_name);
77 FbTk::StringUtil::removeTrailingWhitespace(pixmap_name);
78 m_filename = pixmap_name;
79
80 // we dont load any pixmap, using external command to set background pixmap
81 (*this)->pixmap() = 0;
82 }
83
84 void setFromString(const char *str) {
85 m_options = str; // save option string
86 FbTk::ThemeItem<FbTk::Texture>::setFromString(str);
87 }
88 const std::string &filename() const { return m_filename; }
89 const std::string &options() const { return m_options; }
90private:
91 std::string m_filename, m_options;
92};
93
94
95RootTheme::RootTheme(const std::string &root_command,
96 FbTk::ImageControl &image_control):
97 FbTk::Theme(image_control.screenNumber()),
98 m_background(new BackgroundItem(*this, "background", "Background")),
99 m_opgc(RootWindow(FbTk::App::instance()->display(), image_control.screenNumber())),
100 m_root_command(root_command),
101 m_image_ctrl(image_control),
102 m_lock(false),
103 m_background_loaded(true) {
28 104
29RootTheme::RootTheme(int screen_num, std::string &screen_root_command):
30 FbTk::Theme(screen_num),
31 m_root_command(*this, "rootCommand", "RootCommand"),
32 m_screen_root_command(screen_root_command),
33 m_opgc(RootWindow(FbTk::App::instance()->display(), screen_num)),
34 m_lock(false) {
35
36 Display *disp = FbTk::App::instance()->display(); 105 Display *disp = FbTk::App::instance()->display();
37 m_opgc.setForeground(WhitePixel(disp, screen_num)^BlackPixel(disp, screen_num)); 106 m_opgc.setForeground(WhitePixel(disp, screenNum())^BlackPixel(disp, screenNum()));
38 m_opgc.setFunction(GXxor); 107 m_opgc.setFunction(GXxor);
39 m_opgc.setSubwindowMode(IncludeInferiors); 108 m_opgc.setSubwindowMode(IncludeInferiors);
40 m_opgc.setLineAttributes(1, LineSolid, CapNotLast, JoinMiter); 109 m_opgc.setLineAttributes(1, LineSolid, CapNotLast, JoinMiter);
41} 110}
42 111
43RootTheme::~RootTheme() { 112RootTheme::~RootTheme() {
113 delete m_background;
114}
44 115
116bool RootTheme::fallback(FbTk::ThemeItem_base &item) {
117 // if background theme item was not found in the
118 // style then mark background as not loaded so
119 // we can deal with it in reconfigureTheme()
120 if (item.name() == "background") {
121 // mark no background loaded
122 m_background_loaded = false;
123 return true;
124 }
125 return false;
45} 126}
46 127
47void RootTheme::reconfigTheme() { 128void RootTheme::reconfigTheme() {
48 if (m_lock) 129 if (m_lock)
49 return; 130 return;
50 131 // if user specified background in the config then use it
51 // override resource root command? 132 // instead of style background
52 if (m_screen_root_command == "") { 133 if (!m_root_command.empty()) {
53 // do root command 134 FbCommands::ExecuteCmd cmd(m_root_command, screenNum());
54 FbCommands::ExecuteCmd cmd(*m_root_command, screenNum());
55 cmd.execute(); 135 cmd.execute();
136 return;
137 }
138
139 //
140 // Else parse background from style
141 //
142
143 // root window helper
144 FbRootWindow rootwin(screenNum());
145
146 // if the background theme item was not loaded
147 // then generate an image with a text that
148 // notifies the user about it
149
150 if (!m_background_loaded) {
151 FbTk::FbPixmap root(FbTk::FbPixmap::getRootPixmap(screenNum()));
152 // if there is no root background pixmap
153 // then we need to create one
154 if (root.drawable() == None) {
155 root.create(rootwin.window(),
156 rootwin.width(), rootwin.height(),
157 rootwin.depth());
158
159 FbTk::FbPixmap::setRootPixmap(screenNum(), root.drawable());
160 }
161
162 // setup root window property
163 Atom atom_root = XInternAtom(rootwin.display(), "_XROOTPMAP_ID", false);
164 Pixmap pm = root.drawable();
165 rootwin.changeProperty(atom_root, XA_PIXMAP, 32, PropModeReplace, (unsigned char *)&pm, 1);
166 rootwin.setBackgroundPixmap(root.drawable());
167
168
169 FbTk::GContext gc(root);
170
171 // fill background color
172 gc.setForeground(FbTk::Color("black", screenNum()));
173 root.fillRectangle(gc.gc(),
174 0, 0,
175 root.width(), root.height());
176 // text color
177 gc.setForeground(FbTk::Color("white", screenNum()));
178 // render text
179 const char errormsg[] =
180 "There is no background option specified in this style. Please consult the manual or read the FAQ.";
181 FbTk::Font font;
182 font.drawText(root, screenNum(), gc.gc(),
183 errormsg, strlen(errormsg),
184 2, font.height() + 2); // added some extra pixels for better visibility
185
186
187 // reset background mark
188 m_background_loaded = true;
189 root.release(); // we dont want to destroy this pixmap
56 } else { 190 } else {
57 FbCommands::ExecuteCmd cmd(m_screen_root_command, screenNum()); 191 // handle background option in style
58 cmd.execute(); 192 std::string filename = m_background->filename();
193 FbTk::StringUtil::removeTrailingWhitespace(filename);
194 FbTk::StringUtil::removeFirstWhitespace(filename);
195 // if background argument is a file then
196 // parse image options and call image setting
197 // command specified in the resources
198 if (FbTk::FileUtil::isRegularFile(filename.c_str())) {
199 // parse options
200 std::string options;
201 if (strstr(m_background->options().c_str(), "tiled") != 0)
202 options += "-t ";
203 if (strstr(m_background->options().c_str(), "centered") != 0)
204 options += "-c ";
205
206 // compose wallpaper application "fbsetbg" with argumetns
207 std::string commandargs = "fbsetbg " + options + " " + filename;
208
209 // call command with options
210 FbCommands::ExecuteCmd exec(commandargs, screenNum());
211 exec.execute();
212
213 } else {
214 // render normal texture
215
216 // we override the image control renderImage since
217 // since we do not want to cache this pixmap
218 XColor *colors;
219 int num_colors;
220 m_image_ctrl.getXColorTable(&colors, &num_colors);
221 FbTk::TextureRender image(m_image_ctrl, rootwin.width(), rootwin.height(),
222 colors, num_colors);
223 Pixmap pixmap = image.render(*(*m_background));
224 // setup root window property
225 Atom atom_root = XInternAtom(rootwin.display(), "_XROOTPMAP_ID", false);
226 rootwin.changeProperty(atom_root, XA_PIXMAP, 32, PropModeReplace, (unsigned char *)&pixmap, 1);
227 rootwin.setBackgroundPixmap(pixmap);
228
229 }
230
59 } 231 }
232
233 // clear root window
234 rootwin.clear();
235
236
237
60} 238}
diff --git a/src/RootTheme.hh b/src/RootTheme.hh
index dce9d31..c1ac060 100644
--- a/src/RootTheme.hh
+++ b/src/RootTheme.hh
@@ -26,21 +26,30 @@
26 26
27#include "FbTk/Theme.hh" 27#include "FbTk/Theme.hh"
28#include "FbTk/GContext.hh" 28#include "FbTk/GContext.hh"
29#include "FbTk/Texture.hh"
29 30
30#include <X11/Xlib.h> 31#include <X11/Xlib.h>
31 32
32#include <string> 33#include <string>
33 34
35class BackgroundItem;
36
37namespace FbTk {
38class ResourceManager;
39class ImageControl;
40}
34 41
35/// Contains border color, border size, bevel width and opGC for objects like geometry window in BScreen 42/// Contains border color, border size, bevel width and opGC for objects like geometry window in BScreen
36class RootTheme: public FbTk::Theme { 43class RootTheme: public FbTk::Theme {
37public: 44public:
38 /// constructor 45 /// constructor
39 /// @param screen_num the screen number 46 /// @param resmanager resource manager for finding specific resources
40 /// @param screen_root_command the string to be executed override theme rootCommand 47 /// @param image_control for rendering background texture
41 RootTheme(int screen_num, std::string &screen_root_command); 48 RootTheme(const std::string &root_command,
49 FbTk::ImageControl &image_control);
42 ~RootTheme(); 50 ~RootTheme();
43 51
52 bool fallback(FbTk::ThemeItem_base &item);
44 void reconfigTheme(); 53 void reconfigTheme();
45 54
46 GC opGC() const { return m_opgc.gc(); } 55 GC opGC() const { return m_opgc.gc(); }
@@ -55,10 +64,13 @@ public:
55 //!! TODO we should need this later 64 //!! TODO we should need this later
56 void lock(bool value) { m_lock = value; } 65 void lock(bool value) { m_lock = value; }
57private: 66private:
58 FbTk::ThemeItem<std::string> m_root_command; 67 BackgroundItem *m_background;///< background image/texture
59 std::string &m_screen_root_command; ///< string to execute and override theme rootCommand
60 FbTk::GContext m_opgc; 68 FbTk::GContext m_opgc;
61 bool m_lock; 69 const std::string &m_root_command;
70 FbTk::ImageControl &m_image_ctrl; ///< image control for rendering background texture
71 bool m_lock; ///< reconfigure lock
72 bool m_background_loaded; ///< whether or not the background is present in the style file
73
62}; 74};
63 75
64#endif // ROOTTHEME_HH 76#endif // ROOTTHEME_HH
diff --git a/src/Screen.cc b/src/Screen.cc
index c7fe1d3..b18dcb8 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -229,9 +229,6 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
229 // after fbwinframe have resized them 229 // after fbwinframe have resized them
230 m_winbutton_theme(new WinButtonTheme(scrn, *m_windowtheme)), 230 m_winbutton_theme(new WinButtonTheme(scrn, *m_windowtheme)),
231 m_menutheme(new MenuTheme(scrn)), 231 m_menutheme(new MenuTheme(scrn)),
232 m_root_theme(new
233 RootTheme(scrn,
234 *resource.rootcommand)),
235 m_root_window(scrn), 232 m_root_window(scrn),
236 m_geom_window(m_root_window, 233 m_geom_window(m_root_window,
237 0, 0, 10, 10, 234 0, 0, 10, 10,
@@ -249,8 +246,7 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
249 m_shutdown(false) { 246 m_shutdown(false) {
250 247
251 248
252 Fluxbox *fluxbox = Fluxbox::instance(); 249 Display *disp = m_root_window.display();
253 Display *disp = fluxbox->display();
254 250
255 initXinerama(); 251 initXinerama();
256 252
@@ -261,7 +257,7 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
261 SubstructureRedirectMask | KeyPressMask | KeyReleaseMask | 257 SubstructureRedirectMask | KeyPressMask | KeyReleaseMask |
262 ButtonPressMask | ButtonReleaseMask| SubstructureNotifyMask); 258 ButtonPressMask | ButtonReleaseMask| SubstructureNotifyMask);
263 259
264 fluxbox->sync(false); 260 FbTk::App::instance()->sync(false);
265 261
266 XSetErrorHandler((XErrorHandler) old); 262 XSetErrorHandler((XErrorHandler) old);
267 263
@@ -286,14 +282,18 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
286 rootWindow().setCursor(XCreateFontCursor(disp, XC_left_ptr)); 282 rootWindow().setCursor(XCreateFontCursor(disp, XC_left_ptr));
287 283
288 // load this screens resources 284 // load this screens resources
285 Fluxbox *fluxbox = Fluxbox::instance();
289 fluxbox->load_rc(*this); 286 fluxbox->load_rc(*this);
290 287
291 // setup image cache engine 288 // setup image cache engine
292 m_image_control.reset(new FbTk::ImageControl(scrn, true, fluxbox->colorsPerChannel(), 289 m_image_control.reset(new FbTk::ImageControl(scrn, true,
290 fluxbox->colorsPerChannel(),
293 fluxbox->getCacheLife(), fluxbox->getCacheMax())); 291 fluxbox->getCacheLife(), fluxbox->getCacheMax()));
294 imageControl().installRootColormap(); 292 imageControl().installRootColormap();
295 root_colormap_installed = true; 293 root_colormap_installed = true;
296 294
295 m_root_theme.reset(new RootTheme(*resource.rootcommand, imageControl()));
296
297 m_windowtheme->setFocusedAlpha(*resource.focused_alpha); 297 m_windowtheme->setFocusedAlpha(*resource.focused_alpha);
298 m_windowtheme->setUnfocusedAlpha(*resource.unfocused_alpha); 298 m_windowtheme->setUnfocusedAlpha(*resource.unfocused_alpha);
299 m_menutheme->setAlpha(*resource.menu_alpha); 299 m_menutheme->setAlpha(*resource.menu_alpha);
@@ -778,12 +778,12 @@ void BScreen::reconfigure() {
778 for_each(m_workspaces_list.begin(), 778 for_each(m_workspaces_list.begin(),
779 m_workspaces_list.end(), 779 m_workspaces_list.end(),
780 mem_fun(&Workspace::reconfigure)); 780 mem_fun(&Workspace::reconfigure));
781 781
782 // reconfigure Icons 782 // reconfigure Icons
783 for_each(m_icon_list.begin(), 783 for_each(m_icon_list.begin(),
784 m_icon_list.end(), 784 m_icon_list.end(),
785 mem_fun(&FluxboxWindow::reconfigure)); 785 mem_fun(&FluxboxWindow::reconfigure));
786 786
787 imageControl().cleanCache(); 787 imageControl().cleanCache();
788 // notify objects that the screen is reconfigured 788 // notify objects that the screen is reconfigured
789 m_reconfigure_sig.notify(); 789 m_reconfigure_sig.notify();
diff --git a/src/ScreenResources.cc b/src/ScreenResources.cc
index d541ae7..7d97cd8 100644
--- a/src/ScreenResources.cc
+++ b/src/ScreenResources.cc
@@ -44,7 +44,7 @@ void FbTk::Resource<BScreen::PlacementPolicy>::setFromString(const char *str) {
44} 44}
45 45
46template <> 46template <>
47string FbTk::Resource<BScreen::PlacementPolicy>::getString() { 47string FbTk::Resource<BScreen::PlacementPolicy>::getString() const {
48 switch (*(*this)) { 48 switch (*(*this)) {
49 case BScreen::ROWSMARTPLACEMENT: 49 case BScreen::ROWSMARTPLACEMENT:
50 return "RowSmartPlacement"; 50 return "RowSmartPlacement";
@@ -71,7 +71,7 @@ void FbTk::Resource<BScreen::RowDirection>::setFromString(const char *str) {
71} 71}
72 72
73template <> 73template <>
74string FbTk::Resource<BScreen::RowDirection>::getString() { 74string FbTk::Resource<BScreen::RowDirection>::getString() const {
75 switch (*(*this)) { 75 switch (*(*this)) {
76 case BScreen::LEFTRIGHT: 76 case BScreen::LEFTRIGHT:
77 return "LeftToRight"; 77 return "LeftToRight";
@@ -95,7 +95,7 @@ void FbTk::Resource<BScreen::ColumnDirection>::setFromString(const char *str) {
95} 95}
96 96
97template <> 97template <>
98string FbTk::Resource<BScreen::ColumnDirection>::getString() { 98string FbTk::Resource<BScreen::ColumnDirection>::getString() const {
99 switch (*(*this)) { 99 switch (*(*this)) {
100 case BScreen::TOPBOTTOM: 100 case BScreen::TOPBOTTOM:
101 return "TopToBottom"; 101 return "TopToBottom";
@@ -107,7 +107,7 @@ string FbTk::Resource<BScreen::ColumnDirection>::getString() {
107} 107}
108 108
109template <> 109template <>
110string FbTk::Resource<FbTk::MenuTheme::MenuMode>::getString() { 110string FbTk::Resource<FbTk::MenuTheme::MenuMode>::getString() const {
111 switch (*(*this)) { 111 switch (*(*this)) {
112 case FbTk::MenuTheme::DELAY_OPEN: 112 case FbTk::MenuTheme::DELAY_OPEN:
113 return string("Delay"); 113 return string("Delay");
@@ -127,14 +127,14 @@ void FbTk::Resource<FbTk::MenuTheme::MenuMode>::setFromString(const char *str) {
127 setDefaultValue(); 127 setDefaultValue();
128} 128}
129 129
130template<> 130
131std::string FbTk::Resource<BScreen::ResizeModel>::getString() { 131std::string FbTk::Resource<BScreen::ResizeModel>::getString() const {
132 switch (m_value) { 132 switch (m_value) {
133 case BScreen::QUADRANTRESIZE: 133 case BScreen::QUADRANTRESIZE:
134 return std::string("Quadrant"); 134 return std::string("Quadrant");
135 case BScreen::BOTTOMRESIZE: 135 case BScreen::BOTTOMRESIZE:
136 return std::string("Bottom"); 136 return std::string("Bottom");
137 }; 137 }
138 138
139 return std::string("Default"); 139 return std::string("Default");
140} 140}
@@ -151,7 +151,7 @@ setFromString(char const *strval) {
151} 151}
152 152
153template<> 153template<>
154std::string FbTk::Resource<BScreen::FocusModel>::getString() { 154std::string FbTk::Resource<BScreen::FocusModel>::getString() const {
155 switch (m_value) { 155 switch (m_value) {
156 case BScreen::MOUSEFOCUS: 156 case BScreen::MOUSEFOCUS:
157 return string("MouseFocus"); 157 return string("MouseFocus");
@@ -174,7 +174,8 @@ setFromString(char const *strval) {
174} 174}
175 175
176template<> 176template<>
177std::string FbTk::Resource<BScreen::TabFocusModel>::getString() { 177
178std::string FbTk::Resource<BScreen::TabFocusModel>::getString() const {
178 switch (m_value) { 179 switch (m_value) {
179 case BScreen::MOUSETABFOCUS: 180 case BScreen::MOUSETABFOCUS:
180 return string("SloppyTabFocus"); 181 return string("SloppyTabFocus");
@@ -197,7 +198,7 @@ setFromString(char const *strval) {
197} 198}
198 199
199template<> 200template<>
200std::string FbTk::Resource<BScreen::FollowModel>::getString() { 201std::string FbTk::Resource<BScreen::FollowModel>::getString() const {
201 switch (m_value) { 202 switch (m_value) {
202 case BScreen::FOLLOW_ACTIVE_WINDOW: 203 case BScreen::FOLLOW_ACTIVE_WINDOW:
203 return std::string("Follow"); 204 return std::string("Follow");
@@ -205,7 +206,7 @@ std::string FbTk::Resource<BScreen::FollowModel>::getString() {
205 case BScreen::FETCH_ACTIVE_WINDOW: 206 case BScreen::FETCH_ACTIVE_WINDOW:
206 return std::string("Current"); 207 return std::string("Current");
207 break; 208 break;
208 }; 209 }
209 210
210 return std::string("Ignore"); 211 return std::string("Ignore");
211} 212}
@@ -224,7 +225,7 @@ setFromString(char const *strval) {
224} 225}
225 226
226template<> 227template<>
227std::string FbTk::Resource<FbTk::GContext::LineStyle>::getString() { 228std::string FbTk::Resource<FbTk::GContext::LineStyle>::getString() const {
228 switch(m_value) { 229 switch(m_value) {
229 case FbTk::GContext::LINESOLID: 230 case FbTk::GContext::LINESOLID:
230 return "LineSolid"; 231 return "LineSolid";
@@ -254,7 +255,7 @@ void FbTk::Resource<FbTk::GContext::LineStyle>
254} 255}
255 256
256template<> 257template<>
257std::string FbTk::Resource<FbTk::GContext::JoinStyle>::getString() { 258std::string FbTk::Resource<FbTk::GContext::JoinStyle>::getString() const {
258 switch(m_value) { 259 switch(m_value) {
259 case FbTk::GContext::JOINMITER: 260 case FbTk::GContext::JOINMITER:
260 return "JoinMiter"; 261 return "JoinMiter";
@@ -284,7 +285,7 @@ void FbTk::Resource<FbTk::GContext::JoinStyle>
284} 285}
285 286
286template<> 287template<>
287std::string FbTk::Resource<FbTk::GContext::CapStyle>::getString() { 288std::string FbTk::Resource<FbTk::GContext::CapStyle>::getString() const {
288 switch(m_value) { 289 switch(m_value) {
289 case FbTk::GContext::CAPNOTLAST: 290 case FbTk::GContext::CAPNOTLAST:
290 return "CapNotLast"; 291 return "CapNotLast";