diff options
Diffstat (limited to 'src/RootTheme.cc')
-rw-r--r-- | src/RootTheme.cc | 235 |
1 files changed, 145 insertions, 90 deletions
diff --git a/src/RootTheme.cc b/src/RootTheme.cc index 6847fc2..eeb95f9 100644 --- a/src/RootTheme.cc +++ b/src/RootTheme.cc | |||
@@ -48,7 +48,8 @@ using std::string; | |||
48 | class BackgroundItem: public FbTk::ThemeItem<FbTk::Texture> { | 48 | class BackgroundItem: public FbTk::ThemeItem<FbTk::Texture> { |
49 | public: | 49 | public: |
50 | BackgroundItem(FbTk::Theme &tm, const std::string &name, const std::string &altname): | 50 | BackgroundItem(FbTk::Theme &tm, const std::string &name, const std::string &altname): |
51 | FbTk::ThemeItem<FbTk::Texture>(tm, name, altname) { | 51 | FbTk::ThemeItem<FbTk::Texture>(tm, name, altname), |
52 | m_changed(false), m_loaded(false) { | ||
52 | 53 | ||
53 | } | 54 | } |
54 | 55 | ||
@@ -56,6 +57,9 @@ public: | |||
56 | const string &m_name = (o_name == 0) ? name() : *o_name; | 57 | const string &m_name = (o_name == 0) ? name() : *o_name; |
57 | const string &m_altname = (o_altname == 0) ? altName() : *o_altname; | 58 | const string &m_altname = (o_altname == 0) ? altName() : *o_altname; |
58 | 59 | ||
60 | // if we got this far, then the background was loaded | ||
61 | m_loaded = true; | ||
62 | |||
59 | // create subnames | 63 | // create subnames |
60 | string color_name(FbTk::ThemeManager::instance(). | 64 | string color_name(FbTk::ThemeManager::instance(). |
61 | resourceValue(m_name + ".color", m_altname + ".Color")); | 65 | resourceValue(m_name + ".color", m_altname + ".Color")); |
@@ -63,9 +67,59 @@ public: | |||
63 | resourceValue(m_name + ".colorTo", m_altname + ".ColorTo")); | 67 | resourceValue(m_name + ".colorTo", m_altname + ".ColorTo")); |
64 | string pixmap_name(FbTk::ThemeManager::instance(). | 68 | string pixmap_name(FbTk::ThemeManager::instance(). |
65 | resourceValue(m_name + ".pixmap", m_altname + ".Pixmap")); | 69 | resourceValue(m_name + ".pixmap", m_altname + ".Pixmap")); |
70 | string mod_x(FbTk::ThemeManager::instance(). | ||
71 | resourceValue(m_name + ".modX", m_altname + ".ModX")); | ||
72 | string mod_y(FbTk::ThemeManager::instance(). | ||
73 | resourceValue(m_name + ".modY", m_altname + ".ModY")); | ||
74 | |||
75 | // validate mod_x and mod_y | ||
76 | if (mod_x.length() > 2) | ||
77 | mod_x.erase(2,mod_x.length()); // shouldn't be longer than 2 digits | ||
78 | if (mod_y.length() > 2) | ||
79 | mod_y.erase(2,mod_y.length()); // ditto | ||
80 | // should be integers | ||
81 | if (!mod_x.length() || mod_x[0] < '0' || mod_x[0] > '9' || | ||
82 | (mod_x.length() == 2 && (mod_x[1] < '0' || mod_x[1] > '9'))) | ||
83 | mod_x = "1"; | ||
84 | if (!mod_y.length() || mod_y[0] < '0' || mod_y[0] > '9' || | ||
85 | (mod_y.length() == 2 && (mod_y[1] < '0' || mod_y[1] > '9'))) | ||
86 | mod_y = "1"; | ||
87 | |||
88 | // check if any of our values have changed | ||
89 | if (mod_x != m_mod_x) { | ||
90 | m_changed = true; | ||
91 | m_mod_x = mod_x; | ||
92 | } | ||
93 | if (mod_y != m_mod_y) { | ||
94 | m_changed = true; | ||
95 | m_mod_y = mod_y; | ||
96 | } | ||
97 | // these aren't quite right, but I don't care | ||
98 | if (color_name != m_color) { | ||
99 | m_changed = true; | ||
100 | m_color = color_name; | ||
101 | } | ||
102 | if (colorto_name != m_color_to) { | ||
103 | m_changed = true; | ||
104 | m_color_to = colorto_name; | ||
105 | } | ||
106 | |||
107 | // remove whitespace from filename | ||
108 | FbTk::StringUtil::removeFirstWhitespace(pixmap_name); | ||
109 | FbTk::StringUtil::removeTrailingWhitespace(pixmap_name); | ||
110 | |||
111 | if (mod_x != m_mod_x || mod_y != m_mod_y || pixmap_name != m_filename || | ||
112 | color_name != m_color || colorto_name != m_color_to) { | ||
113 | m_changed = true; | ||
114 | m_mod_x = mod_x; | ||
115 | m_mod_y = mod_y; | ||
116 | m_filename = pixmap_name; | ||
117 | |||
118 | // these aren't quite right because of defaults set below | ||
119 | m_color = color_name; | ||
120 | m_color_to = colorto_name; | ||
121 | } | ||
66 | 122 | ||
67 | m_color = color_name; | ||
68 | m_color_to = colorto_name; | ||
69 | // set default value if we failed to load colors | 123 | // set default value if we failed to load colors |
70 | if (!(*this)->color().setFromString(color_name.c_str(), | 124 | if (!(*this)->color().setFromString(color_name.c_str(), |
71 | theme().screenNum())) | 125 | theme().screenNum())) |
@@ -79,11 +133,6 @@ public: | |||
79 | if (((*this)->type() & FbTk::Texture::SOLID) != 0 && ((*this)->type() & FbTk::Texture::FLAT) == 0) | 133 | if (((*this)->type() & FbTk::Texture::SOLID) != 0 && ((*this)->type() & FbTk::Texture::FLAT) == 0) |
80 | (*this)->calcHiLoColors(theme().screenNum()); | 134 | (*this)->calcHiLoColors(theme().screenNum()); |
81 | 135 | ||
82 | // remove whitespace and set filename | ||
83 | FbTk::StringUtil::removeFirstWhitespace(pixmap_name); | ||
84 | FbTk::StringUtil::removeTrailingWhitespace(pixmap_name); | ||
85 | m_filename = pixmap_name; | ||
86 | |||
87 | // we dont load any pixmap, using external command to set background pixmap | 136 | // we dont load any pixmap, using external command to set background pixmap |
88 | (*this)->pixmap() = 0; | 137 | (*this)->pixmap() = 0; |
89 | } | 138 | } |
@@ -96,9 +145,17 @@ public: | |||
96 | const std::string &options() const { return m_options; } | 145 | const std::string &options() const { return m_options; } |
97 | const std::string &colorString() const { return m_color; } | 146 | const std::string &colorString() const { return m_color; } |
98 | const std::string &colorToString() const { return m_color_to; } | 147 | const std::string &colorToString() const { return m_color_to; } |
148 | const std::string &modX() const { return m_mod_x; } | ||
149 | const std::string &modY() const { return m_mod_y; } | ||
150 | bool changed() const { return m_changed; } | ||
151 | bool loaded() const { return m_loaded; } | ||
152 | void setApplied() { m_changed = false; } | ||
153 | void unsetLoaded() { m_loaded = false; } | ||
99 | private: | 154 | private: |
100 | std::string m_filename, m_options; | 155 | std::string m_filename, m_options; |
101 | std::string m_color, m_color_to; | 156 | std::string m_color, m_color_to; |
157 | std::string m_mod_x, m_mod_y; | ||
158 | bool m_changed, m_loaded; | ||
102 | }; | 159 | }; |
103 | 160 | ||
104 | 161 | ||
@@ -108,9 +165,7 @@ RootTheme::RootTheme(const std::string &root_command, | |||
108 | m_background(new BackgroundItem(*this, "background", "Background")), | 165 | m_background(new BackgroundItem(*this, "background", "Background")), |
109 | m_opgc(RootWindow(FbTk::App::instance()->display(), image_control.screenNumber())), | 166 | m_opgc(RootWindow(FbTk::App::instance()->display(), image_control.screenNumber())), |
110 | m_root_command(root_command), | 167 | m_root_command(root_command), |
111 | m_image_ctrl(image_control), | 168 | m_image_ctrl(image_control) { |
112 | m_already_set(false), | ||
113 | m_background_loaded(true) { | ||
114 | 169 | ||
115 | Display *disp = FbTk::App::instance()->display(); | 170 | Display *disp = FbTk::App::instance()->display(); |
116 | m_opgc.setForeground(WhitePixel(disp, screenNum())^BlackPixel(disp, screenNum())); | 171 | m_opgc.setForeground(WhitePixel(disp, screenNum())^BlackPixel(disp, screenNum())); |
@@ -129,7 +184,7 @@ bool RootTheme::fallback(FbTk::ThemeItem_base &item) { | |||
129 | // we can deal with it in reconfigureTheme() | 184 | // we can deal with it in reconfigureTheme() |
130 | if (item.name() == "background") { | 185 | if (item.name() == "background") { |
131 | // mark no background loaded | 186 | // mark no background loaded |
132 | m_background_loaded = false; | 187 | m_background->unsetLoaded(); |
133 | return true; | 188 | return true; |
134 | } | 189 | } |
135 | return false; | 190 | return false; |
@@ -138,10 +193,19 @@ bool RootTheme::fallback(FbTk::ThemeItem_base &item) { | |||
138 | void RootTheme::reconfigTheme() { | 193 | void RootTheme::reconfigTheme() { |
139 | _FB_USES_NLS; | 194 | _FB_USES_NLS; |
140 | 195 | ||
141 | if (m_already_set) | 196 | if (!m_background->loaded()) { |
197 | cerr<<"Fluxbox: "<< | ||
198 | _FB_CONSOLETEXT(Common, BackgroundWarning, | ||
199 | "There is no background option specified in this style." | ||
200 | " Please consult the manual or read the FAQ.", | ||
201 | "Background missing warning")<<endl; | ||
202 | return; | ||
203 | } | ||
204 | |||
205 | if (!m_background->changed()) | ||
142 | return; | 206 | return; |
143 | else | 207 | |
144 | m_already_set = true; | 208 | m_background->setApplied(); |
145 | 209 | ||
146 | // if user specified background in the config then use it | 210 | // if user specified background in the config then use it |
147 | // instead of style background | 211 | // instead of style background |
@@ -151,6 +215,11 @@ void RootTheme::reconfigTheme() { | |||
151 | return; | 215 | return; |
152 | } | 216 | } |
153 | 217 | ||
218 | // style doesn't wish to change the background | ||
219 | if (strstr(m_background->options().c_str(), "none") != 0) | ||
220 | return; | ||
221 | |||
222 | |||
154 | // | 223 | // |
155 | // Else parse background from style | 224 | // Else parse background from style |
156 | // | 225 | // |
@@ -158,84 +227,70 @@ void RootTheme::reconfigTheme() { | |||
158 | // root window helper | 227 | // root window helper |
159 | FbRootWindow rootwin(screenNum()); | 228 | FbRootWindow rootwin(screenNum()); |
160 | 229 | ||
161 | // if the background theme item was not loaded | 230 | // handle background option in style |
162 | 231 | std::string filename = m_background->filename(); | |
163 | if (!m_background_loaded) { | 232 | FbTk::StringUtil::removeTrailingWhitespace(filename); |
164 | cerr<<"Fluxbox: "<< | 233 | FbTk::StringUtil::removeFirstWhitespace(filename); |
165 | _FB_CONSOLETEXT(Common, BackgroundWarning, | 234 | // if background argument is a file then |
166 | "There is no background option specified in this style." | 235 | // parse image options and call image setting |
167 | " Please consult the manual or read the FAQ.", | 236 | // command specified in the resources |
168 | "Background missing warning")<<endl; | 237 | filename = FbTk::StringUtil::expandFilename(filename); |
169 | } else { | 238 | if (FbTk::FileUtil::isRegularFile(filename.c_str())) { |
170 | // handle background option in style | 239 | // parse options |
171 | std::string filename = m_background->filename(); | 240 | std::string options; |
172 | FbTk::StringUtil::removeTrailingWhitespace(filename); | 241 | if (strstr(m_background->options().c_str(), "tiled") != 0) |
173 | FbTk::StringUtil::removeFirstWhitespace(filename); | 242 | options += "-t "; |
174 | // if background argument is a file then | 243 | if (strstr(m_background->options().c_str(), "centered") != 0) |
175 | // parse image options and call image setting | 244 | options += "-c "; |
176 | // command specified in the resources | 245 | if (strstr(m_background->options().c_str(), "aspect") != 0) |
177 | filename = FbTk::StringUtil::expandFilename(filename); | 246 | options += "-a "; |
178 | if (FbTk::FileUtil::isRegularFile(filename.c_str())) { | ||
179 | // parse options | ||
180 | std::string options; | ||
181 | if (strstr(m_background->options().c_str(), "tiled") != 0) | ||
182 | options += "-t "; | ||
183 | if (strstr(m_background->options().c_str(), "centered") != 0) | ||
184 | options += "-c "; | ||
185 | if (strstr(m_background->options().c_str(), "aspect") != 0) | ||
186 | options += "-a "; | ||
187 | 247 | ||
188 | // compose wallpaper application "fbsetbg" with argumetns | 248 | // compose wallpaper application "fbsetbg" with argumetns |
189 | std::string commandargs = "fbsetbg " + options + " " + filename; | 249 | std::string commandargs = "fbsetbg " + options + " " + filename; |
190 | 250 | ||
191 | // call command with options | 251 | // call command with options |
192 | FbCommands::ExecuteCmd exec(commandargs, screenNum()); | 252 | FbCommands::ExecuteCmd exec(commandargs, screenNum()); |
193 | exec.execute(); | 253 | exec.execute(); |
194 | 254 | ||
195 | } else if (FbTk::FileUtil::isDirectory(filename.c_str()) && | 255 | } else if (FbTk::FileUtil::isDirectory(filename.c_str()) && |
196 | strstr(m_background->options().c_str(), "random") != 0) { | 256 | strstr(m_background->options().c_str(), "random") != 0) { |
197 | std::string commandargs = "fbsetbg -r " + filename; | 257 | std::string commandargs = "fbsetbg -r " + filename; |
198 | FbCommands::ExecuteCmd exec(commandargs, screenNum()); | 258 | FbCommands::ExecuteCmd exec(commandargs, screenNum()); |
199 | exec.execute(); | 259 | exec.execute(); |
200 | } else { | 260 | } else { |
201 | // render normal texture with fbsetroot | 261 | // render normal texture with fbsetroot |
202 | 262 | ||
203 | 263 | ||
204 | // Make sure the color strings are valid, | 264 | // Make sure the color strings are valid, |
205 | // so we dont pass any `commands` that can be executed | 265 | // so we dont pass any `commands` that can be executed |
206 | bool color_valid = | 266 | bool color_valid = |
207 | FbTk::Color::validColorString(m_background->colorString().c_str(), | 267 | FbTk::Color::validColorString(m_background->colorString().c_str(), |
208 | screenNum()); | 268 | screenNum()); |
209 | bool color_to_valid = | 269 | bool color_to_valid = |
210 | FbTk::Color::validColorString(m_background->colorToString().c_str(), | 270 | FbTk::Color::validColorString(m_background->colorToString().c_str(), |
211 | screenNum()); | 271 | screenNum()); |
212 | 272 | ||
213 | std::string options; | 273 | std::string options; |
214 | if (color_valid) | 274 | if (color_valid) |
215 | options += "-foreground '" + m_background->colorString() + "' "; | 275 | options += "-foreground '" + m_background->colorString() + "' "; |
216 | if (color_to_valid) | 276 | if (color_to_valid) |
217 | options += "-background '" + m_background->colorToString() + "' "; | 277 | options += "-background '" + m_background->colorToString() + "' "; |
218 | 278 | ||
219 | if ((*m_background)->type() & FbTk::Texture::SOLID && color_valid) | 279 | if (strstr(m_background->options().c_str(), "mod") != 0) |
220 | options += "-solid '" + m_background->colorString() + "' "; | 280 | options += "-mod " + m_background->modX() + " " + m_background->modY(); |
221 | 281 | else if ((*m_background)->type() & FbTk::Texture::SOLID && color_valid) | |
222 | if ((*m_background)->type() & FbTk::Texture::GRADIENT) { | 282 | options += "-solid '" + m_background->colorString() + "' "; |
223 | 283 | ||
224 | if (color_valid) | 284 | else if ((*m_background)->type() & FbTk::Texture::GRADIENT) { |
225 | options += "-from '" + m_background->colorString() + "' "; | 285 | options += "-gradient '" + m_background->options() + "'"; |
226 | if (color_to_valid) | ||
227 | options += "-to '" + m_background->colorToString() + "' "; | ||
228 | |||
229 | options += "-gradient '" + m_background->options() + "'"; | ||
230 | } | ||
231 | |||
232 | std::string commandargs = "fbsetroot " + options; | ||
233 | |||
234 | FbCommands::ExecuteCmd exec(commandargs, screenNum()); | ||
235 | exec.execute(); | ||
236 | } | 286 | } |
237 | 287 | ||
238 | rootwin.clear(); | 288 | std::string commandargs = "fbsetroot " + options; |
289 | |||
290 | FbCommands::ExecuteCmd exec(commandargs, screenNum()); | ||
291 | exec.execute(); | ||
239 | } | 292 | } |
240 | 293 | ||
294 | rootwin.clear(); | ||
295 | |||
241 | } | 296 | } |