several fixes for background option in styles

This commit is contained in:
markt 2007-01-14 19:00:18 +00:00
parent 16743aad06
commit 6ed9f38b7a
14 changed files with 199 additions and 103 deletions

View file

@ -1,5 +1,14 @@
(Format: Year/Month/Day)
Changes for 1.0rc3:
*07/01/14:
* Several changes for background style option: (Mark)
- now support `background: mod' to coincide with fbsetroot -mod --
In addition to `background.color' and `background.colorTo', this option
must also set `background.modX' and `background.modY' to integers
- added `background: none' for styles that do not include a background
- fixed bug with style backgrounds not getting set when changing styles
- updated default styles to be valid wrt background options
RootTheme.cc/hh Screen.cc FbTk/Theme.hh
*07/01/13:
* Only change focus order when user specifically focuses a window (Mark)
Screen.cc Window.cc FocusControl.cc/hh

View file

@ -104,7 +104,11 @@ bevelWidth: 2
borderWidth: 1
handleWidth: 5
!rootCommand: fbsetroot -mod 4 4 -bg rgb:10/18/20 -fg rgb:30/38/40
background: mod
background.modX: 4
background.modY: 4
background.color: rgb:10/18/20
background.colorTo: rgb:30/38/40
*Font: -*-lucidatypewriter-medium-r-*-*-*-100-*-*-*-*-*-*
!*Font: vera-7

View file

@ -172,3 +172,6 @@ borderWidth: 1
bevelWidth: 0
handleWidth: 3
frameWidth: 0
! need this here, even though there is no background in the style
background: none

View file

@ -192,3 +192,6 @@ toolbar.iconbar.empty.colorTo: #cfcfcf
toolbar.iconbar.borderWidth: 1
toolbar.iconbar.borderColor: #dbdbdb
! need this here, even though there is no background in the style
background: none

View file

@ -131,4 +131,8 @@ bevelWidth: 2
borderWidth: 2
handleWidth: 3
!rootCommand: fbsetroot -mod 5 5 -fg rgb:62/70/85 -bg rgb:52/60/75
background: mod
background.modX: 5
background.modY: 5
background.color: rgb:52/60/75
background.colorTo: rgb:62/70/85

View file

@ -107,7 +107,11 @@ borderWidth: 1
bevelWidth: 2
handleWidth: 4
rootCommand: fbsetroot -mod 4 4 -fg rgb:54/6/6 -bg grey20
background: mod
background.modX: 4
background.modY: 4
background.color: grey20
background.colorTo: rgb:54/6/6
! for the bbtools
menuFont: lucidasans-10

View file

@ -99,4 +99,8 @@ handleWidth: 5
*font: -b&h-lucida-medium-r-normal-*-*-100-*-*-p-*-iso8859-*
*textColor: black
rootCommand: fbsetroot -mod 16 8 -bg rgb:0/8/8 -fg rgb:0/9/9
background: mod
background.modX: 16
background.modY: 8
background.color: rgb:0/8/8
background.colorTo: rgb:0/9/9

View file

@ -107,7 +107,11 @@ borderWidth: 1
bevelWidth: 2
handleWidth: 4
rootCommand: fbsetroot -mod 4 4 -fg rgb:6/6/5c -bg grey20
background: mod
background.modX: 4
background.modY: 4
background.color: grey20
background.colorTo: rgb:6/6/5c
! for the bbtools
menuFont: lucidasans-10

View file

@ -104,6 +104,10 @@ bevelWidth: 1
borderWidth: 1
handleWidth: 3
rootCommand: fbsetroot -mod 2 2 -fg rgb:48/50/68 -bg rgb:50/58/70
background: mod
background.modX: 2
background.modY: 2
background.color: rgb:50/58/70
background.colorTo: rgb:48/50/68
*Font: lucidasans-10

View file

@ -348,15 +348,23 @@ Everything you need to make your menu look pretty.
BACKGROUND
------------
Rarely are you going to want to use this option. There is a command that is
similar that is used in the init file. It is bad style to use this in your
style, as it forces the user to use your background. So note that it is good
practice to leave this blank or out of the style altogether.
Every style must specify the background option. If you don't want your style to
change the user's background, then use `background: none'. The options
`centered', `aspect', `tiled', and `fullscreen' require the `background.pixmap'
resource to contain a valid file name. The `random' option requires
`background.pixmap' to contain a valid directory name. For these options,
fluxbox(1) will call fbsetbg(1) to set the background. The options `gradient',
`solid', and `mod' all require `background.color' to be set. `gradient' and
`mod' both require `background.colorTo'. `mod' requires `background.modX' and
`background.modY' to be set as well. These options will be passed to
fbsetroot(1) to set the background.
background: centered|aspect|tiled|fullscreen|random|solid|gradient <texture>
background.pixmap: <file (or directory for random)>
background: centered|aspect|tiled|fullscreen|random|solid|gradient <texture>|mod|none
background.pixmap: <file or directory>
background.color: <color>
background.colorTo: <color>
background.modX: <integer>
background.modY: <integer>
SLIT
----

View file

@ -68,11 +68,11 @@ public:
/// specialized
void setDefaultValue();
/// specialized
void setFromString(const char *strval);
virtual void setFromString(const char *strval);
/// specialized
// name and altname may be different to the primary ones (e.g. from fallback)
// if they are null, then the original name is used
void load(const std::string *name = 0, const std::string *altname = 0);
virtual void load(const std::string *name = 0, const std::string *altname = 0);
/**
@name access operators
*/

View file

@ -48,7 +48,8 @@ using std::string;
class BackgroundItem: public FbTk::ThemeItem<FbTk::Texture> {
public:
BackgroundItem(FbTk::Theme &tm, const std::string &name, const std::string &altname):
FbTk::ThemeItem<FbTk::Texture>(tm, name, altname) {
FbTk::ThemeItem<FbTk::Texture>(tm, name, altname),
m_changed(false), m_loaded(false) {
}
@ -56,6 +57,9 @@ public:
const string &m_name = (o_name == 0) ? name() : *o_name;
const string &m_altname = (o_altname == 0) ? altName() : *o_altname;
// if we got this far, then the background was loaded
m_loaded = true;
// create subnames
string color_name(FbTk::ThemeManager::instance().
resourceValue(m_name + ".color", m_altname + ".Color"));
@ -63,9 +67,59 @@ public:
resourceValue(m_name + ".colorTo", m_altname + ".ColorTo"));
string pixmap_name(FbTk::ThemeManager::instance().
resourceValue(m_name + ".pixmap", m_altname + ".Pixmap"));
string mod_x(FbTk::ThemeManager::instance().
resourceValue(m_name + ".modX", m_altname + ".ModX"));
string mod_y(FbTk::ThemeManager::instance().
resourceValue(m_name + ".modY", m_altname + ".ModY"));
// validate mod_x and mod_y
if (mod_x.length() > 2)
mod_x.erase(2,mod_x.length()); // shouldn't be longer than 2 digits
if (mod_y.length() > 2)
mod_y.erase(2,mod_y.length()); // ditto
// should be integers
if (!mod_x.length() || mod_x[0] < '0' || mod_x[0] > '9' ||
(mod_x.length() == 2 && (mod_x[1] < '0' || mod_x[1] > '9')))
mod_x = "1";
if (!mod_y.length() || mod_y[0] < '0' || mod_y[0] > '9' ||
(mod_y.length() == 2 && (mod_y[1] < '0' || mod_y[1] > '9')))
mod_y = "1";
// check if any of our values have changed
if (mod_x != m_mod_x) {
m_changed = true;
m_mod_x = mod_x;
}
if (mod_y != m_mod_y) {
m_changed = true;
m_mod_y = mod_y;
}
// these aren't quite right, but I don't care
if (color_name != m_color) {
m_changed = true;
m_color = color_name;
}
if (colorto_name != m_color_to) {
m_changed = true;
m_color_to = colorto_name;
}
// remove whitespace from filename
FbTk::StringUtil::removeFirstWhitespace(pixmap_name);
FbTk::StringUtil::removeTrailingWhitespace(pixmap_name);
if (mod_x != m_mod_x || mod_y != m_mod_y || pixmap_name != m_filename ||
color_name != m_color || colorto_name != m_color_to) {
m_changed = true;
m_mod_x = mod_x;
m_mod_y = mod_y;
m_filename = pixmap_name;
// these aren't quite right because of defaults set below
m_color = color_name;
m_color_to = colorto_name;
}
m_color = color_name;
m_color_to = colorto_name;
// set default value if we failed to load colors
if (!(*this)->color().setFromString(color_name.c_str(),
theme().screenNum()))
@ -79,11 +133,6 @@ public:
if (((*this)->type() & FbTk::Texture::SOLID) != 0 && ((*this)->type() & FbTk::Texture::FLAT) == 0)
(*this)->calcHiLoColors(theme().screenNum());
// remove whitespace and set filename
FbTk::StringUtil::removeFirstWhitespace(pixmap_name);
FbTk::StringUtil::removeTrailingWhitespace(pixmap_name);
m_filename = pixmap_name;
// we dont load any pixmap, using external command to set background pixmap
(*this)->pixmap() = 0;
}
@ -96,9 +145,17 @@ public:
const std::string &options() const { return m_options; }
const std::string &colorString() const { return m_color; }
const std::string &colorToString() const { return m_color_to; }
const std::string &modX() const { return m_mod_x; }
const std::string &modY() const { return m_mod_y; }
bool changed() const { return m_changed; }
bool loaded() const { return m_loaded; }
void setApplied() { m_changed = false; }
void unsetLoaded() { m_loaded = false; }
private:
std::string m_filename, m_options;
std::string m_color, m_color_to;
std::string m_mod_x, m_mod_y;
bool m_changed, m_loaded;
};
@ -108,9 +165,7 @@ RootTheme::RootTheme(const std::string &root_command,
m_background(new BackgroundItem(*this, "background", "Background")),
m_opgc(RootWindow(FbTk::App::instance()->display(), image_control.screenNumber())),
m_root_command(root_command),
m_image_ctrl(image_control),
m_already_set(false),
m_background_loaded(true) {
m_image_ctrl(image_control) {
Display *disp = FbTk::App::instance()->display();
m_opgc.setForeground(WhitePixel(disp, screenNum())^BlackPixel(disp, screenNum()));
@ -129,7 +184,7 @@ bool RootTheme::fallback(FbTk::ThemeItem_base &item) {
// we can deal with it in reconfigureTheme()
if (item.name() == "background") {
// mark no background loaded
m_background_loaded = false;
m_background->unsetLoaded();
return true;
}
return false;
@ -138,10 +193,19 @@ bool RootTheme::fallback(FbTk::ThemeItem_base &item) {
void RootTheme::reconfigTheme() {
_FB_USES_NLS;
if (m_already_set)
if (!m_background->loaded()) {
cerr<<"Fluxbox: "<<
_FB_CONSOLETEXT(Common, BackgroundWarning,
"There is no background option specified in this style."
" Please consult the manual or read the FAQ.",
"Background missing warning")<<endl;
return;
else
m_already_set = true;
}
if (!m_background->changed())
return;
m_background->setApplied();
// if user specified background in the config then use it
// instead of style background
@ -151,6 +215,11 @@ void RootTheme::reconfigTheme() {
return;
}
// style doesn't wish to change the background
if (strstr(m_background->options().c_str(), "none") != 0)
return;
//
// Else parse background from style
//
@ -158,84 +227,70 @@ void RootTheme::reconfigTheme() {
// root window helper
FbRootWindow rootwin(screenNum());
// if the background theme item was not loaded
if (!m_background_loaded) {
cerr<<"Fluxbox: "<<
_FB_CONSOLETEXT(Common, BackgroundWarning,
"There is no background option specified in this style."
" Please consult the manual or read the FAQ.",
"Background missing warning")<<endl;
} else {
// handle background option in style
std::string filename = m_background->filename();
FbTk::StringUtil::removeTrailingWhitespace(filename);
FbTk::StringUtil::removeFirstWhitespace(filename);
// if background argument is a file then
// parse image options and call image setting
// command specified in the resources
filename = FbTk::StringUtil::expandFilename(filename);
if (FbTk::FileUtil::isRegularFile(filename.c_str())) {
// parse options
std::string options;
if (strstr(m_background->options().c_str(), "tiled") != 0)
options += "-t ";
if (strstr(m_background->options().c_str(), "centered") != 0)
options += "-c ";
if (strstr(m_background->options().c_str(), "aspect") != 0)
options += "-a ";
// handle background option in style
std::string filename = m_background->filename();
FbTk::StringUtil::removeTrailingWhitespace(filename);
FbTk::StringUtil::removeFirstWhitespace(filename);
// if background argument is a file then
// parse image options and call image setting
// command specified in the resources
filename = FbTk::StringUtil::expandFilename(filename);
if (FbTk::FileUtil::isRegularFile(filename.c_str())) {
// parse options
std::string options;
if (strstr(m_background->options().c_str(), "tiled") != 0)
options += "-t ";
if (strstr(m_background->options().c_str(), "centered") != 0)
options += "-c ";
if (strstr(m_background->options().c_str(), "aspect") != 0)
options += "-a ";
// compose wallpaper application "fbsetbg" with argumetns
std::string commandargs = "fbsetbg " + options + " " + filename;
// compose wallpaper application "fbsetbg" with argumetns
std::string commandargs = "fbsetbg " + options + " " + filename;
// call command with options
FbCommands::ExecuteCmd exec(commandargs, screenNum());
exec.execute();
// call command with options
FbCommands::ExecuteCmd exec(commandargs, screenNum());
exec.execute();
} else if (FbTk::FileUtil::isDirectory(filename.c_str()) &&
strstr(m_background->options().c_str(), "random") != 0) {
std::string commandargs = "fbsetbg -r " + filename;
FbCommands::ExecuteCmd exec(commandargs, screenNum());
exec.execute();
} else {
// render normal texture with fbsetroot
} else if (FbTk::FileUtil::isDirectory(filename.c_str()) &&
strstr(m_background->options().c_str(), "random") != 0) {
std::string commandargs = "fbsetbg -r " + filename;
FbCommands::ExecuteCmd exec(commandargs, screenNum());
exec.execute();
} else {
// render normal texture with fbsetroot
// Make sure the color strings are valid,
// so we dont pass any `commands` that can be executed
bool color_valid =
FbTk::Color::validColorString(m_background->colorString().c_str(),
screenNum());
bool color_to_valid =
FbTk::Color::validColorString(m_background->colorToString().c_str(),
screenNum());
// Make sure the color strings are valid,
// so we dont pass any `commands` that can be executed
bool color_valid =
FbTk::Color::validColorString(m_background->colorString().c_str(),
screenNum());
bool color_to_valid =
FbTk::Color::validColorString(m_background->colorToString().c_str(),
screenNum());
std::string options;
if (color_valid)
options += "-foreground '" + m_background->colorString() + "' ";
if (color_to_valid)
options += "-background '" + m_background->colorToString() + "' ";
std::string options;
if (color_valid)
options += "-foreground '" + m_background->colorString() + "' ";
if (color_to_valid)
options += "-background '" + m_background->colorToString() + "' ";
if ((*m_background)->type() & FbTk::Texture::SOLID && color_valid)
options += "-solid '" + m_background->colorString() + "' ";
if (strstr(m_background->options().c_str(), "mod") != 0)
options += "-mod " + m_background->modX() + " " + m_background->modY();
else if ((*m_background)->type() & FbTk::Texture::SOLID && color_valid)
options += "-solid '" + m_background->colorString() + "' ";
if ((*m_background)->type() & FbTk::Texture::GRADIENT) {
if (color_valid)
options += "-from '" + m_background->colorString() + "' ";
if (color_to_valid)
options += "-to '" + m_background->colorToString() + "' ";
options += "-gradient '" + m_background->options() + "'";
}
std::string commandargs = "fbsetroot " + options;
FbCommands::ExecuteCmd exec(commandargs, screenNum());
exec.execute();
else if ((*m_background)->type() & FbTk::Texture::GRADIENT) {
options += "-gradient '" + m_background->options() + "'";
}
rootwin.clear();
std::string commandargs = "fbsetroot " + options;
FbCommands::ExecuteCmd exec(commandargs, screenNum());
exec.execute();
}
rootwin.clear();
}

View file

@ -51,8 +51,6 @@ public:
bool fallback(FbTk::ThemeItem_base &item);
void reconfigTheme();
// little hack to deal with reconfigures -- should be fixed
void setLoaded() { m_background_loaded = true; m_already_set = false; }
GC opGC() const { return m_opgc.gc(); }
@ -68,8 +66,6 @@ private:
FbTk::GContext m_opgc;
const std::string &m_root_command;
FbTk::ImageControl &m_image_ctrl; ///< image control for rendering background texture
bool m_already_set;
bool m_background_loaded; ///< whether or not the background is present in the style file
};

View file

@ -913,8 +913,6 @@ void BScreen::reconfigure() {
// notify objects that the screen is reconfigured
m_reconfigure_sig.notify();
m_root_theme->setLoaded();
// Reload style
FbTk::ThemeManager::instance().load(fluxbox->getStyleFilename(),
fluxbox->getStyleOverlayFilename(),