2003-04-25 10:14:54 +00:00
|
|
|
// RootTheme.cc
|
2006-02-16 06:53:05 +00:00
|
|
|
// Copyright (c) 2003 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
|
2003-04-25 10:14:54 +00:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2004-11-19 11:37:27 +00:00
|
|
|
// $Id$
|
2003-04-25 10:14:54 +00:00
|
|
|
|
|
|
|
#include "RootTheme.hh"
|
|
|
|
|
2005-11-22 21:59:48 +00:00
|
|
|
#include "FbRootWindow.hh"
|
2003-04-25 10:14:54 +00:00
|
|
|
#include "FbCommands.hh"
|
2005-11-22 21:59:48 +00:00
|
|
|
|
2004-01-02 13:29:01 +00:00
|
|
|
#include "FbTk/App.hh"
|
2005-11-22 21:59:48 +00:00
|
|
|
#include "FbTk/Font.hh"
|
|
|
|
#include "FbTk/ImageControl.hh"
|
|
|
|
#include "FbTk/Resource.hh"
|
|
|
|
#include "FbTk/FileUtil.hh"
|
|
|
|
#include "FbTk/StringUtil.hh"
|
|
|
|
#include "FbTk/TextureRender.hh"
|
2006-02-12 08:02:39 +00:00
|
|
|
#include "FbTk/I18n.hh"
|
2005-11-22 21:59:48 +00:00
|
|
|
|
|
|
|
#include <X11/Xatom.h>
|
2006-02-12 08:02:39 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2005-11-22 21:59:48 +00:00
|
|
|
|
2006-02-12 08:02:39 +00:00
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
2005-11-22 21:59:48 +00:00
|
|
|
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) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void load(const std::string *o_name = 0, const std::string *o_altname = 0) {
|
|
|
|
const string &m_name = (o_name == 0) ? name() : *o_name;
|
|
|
|
const string &m_altname = (o_altname == 0) ? altName() : *o_altname;
|
|
|
|
|
|
|
|
// create subnames
|
|
|
|
string color_name(FbTk::ThemeManager::instance().
|
|
|
|
resourceValue(m_name + ".color", m_altname + ".Color"));
|
|
|
|
string colorto_name(FbTk::ThemeManager::instance().
|
|
|
|
resourceValue(m_name + ".colorTo", m_altname + ".ColorTo"));
|
|
|
|
string pixmap_name(FbTk::ThemeManager::instance().
|
|
|
|
resourceValue(m_name + ".pixmap", m_altname + ".Pixmap"));
|
|
|
|
|
2006-02-12 08:02:39 +00:00
|
|
|
m_color = color_name;
|
|
|
|
m_color_to = colorto_name;
|
2005-11-22 21:59:48 +00:00
|
|
|
// set default value if we failed to load colors
|
|
|
|
if (!(*this)->color().setFromString(color_name.c_str(),
|
|
|
|
theme().screenNum()))
|
|
|
|
(*this)->color().setFromString("darkgray", theme().screenNum());
|
|
|
|
|
|
|
|
if (!(*this)->colorTo().setFromString(colorto_name.c_str(),
|
|
|
|
theme().screenNum()))
|
|
|
|
(*this)->colorTo().setFromString("white", theme().screenNum());
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFromString(const char *str) {
|
|
|
|
m_options = str; // save option string
|
|
|
|
FbTk::ThemeItem<FbTk::Texture>::setFromString(str);
|
|
|
|
}
|
|
|
|
const std::string &filename() const { return m_filename; }
|
|
|
|
const std::string &options() const { return m_options; }
|
2006-02-12 08:02:39 +00:00
|
|
|
const std::string &colorString() const { return m_color; }
|
|
|
|
const std::string &colorToString() const { return m_color_to; }
|
2005-11-22 21:59:48 +00:00
|
|
|
private:
|
|
|
|
std::string m_filename, m_options;
|
2006-02-12 08:02:39 +00:00
|
|
|
std::string m_color, m_color_to;
|
2005-11-22 21:59:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
RootTheme::RootTheme(const std::string &root_command,
|
|
|
|
FbTk::ImageControl &image_control):
|
|
|
|
FbTk::Theme(image_control.screenNumber()),
|
|
|
|
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_lock(false),
|
|
|
|
m_background_loaded(true) {
|
2003-04-25 10:14:54 +00:00
|
|
|
|
|
|
|
Display *disp = FbTk::App::instance()->display();
|
2005-11-22 21:59:48 +00:00
|
|
|
m_opgc.setForeground(WhitePixel(disp, screenNum())^BlackPixel(disp, screenNum()));
|
2003-09-12 21:34:22 +00:00
|
|
|
m_opgc.setFunction(GXxor);
|
|
|
|
m_opgc.setSubwindowMode(IncludeInferiors);
|
2004-03-22 21:01:42 +00:00
|
|
|
m_opgc.setLineAttributes(1, LineSolid, CapNotLast, JoinMiter);
|
2003-04-25 10:14:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RootTheme::~RootTheme() {
|
2005-11-22 21:59:48 +00:00
|
|
|
delete m_background;
|
|
|
|
}
|
2003-09-12 21:34:22 +00:00
|
|
|
|
2005-11-22 21:59:48 +00:00
|
|
|
bool RootTheme::fallback(FbTk::ThemeItem_base &item) {
|
|
|
|
// if background theme item was not found in the
|
|
|
|
// style then mark background as not loaded so
|
|
|
|
// we can deal with it in reconfigureTheme()
|
|
|
|
if (item.name() == "background") {
|
|
|
|
// mark no background loaded
|
|
|
|
m_background_loaded = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2003-04-25 10:14:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RootTheme::reconfigTheme() {
|
2006-02-14 12:46:29 +00:00
|
|
|
_FB_USES_NLS;
|
|
|
|
|
2004-01-02 13:29:01 +00:00
|
|
|
if (m_lock)
|
|
|
|
return;
|
2006-02-12 08:02:39 +00:00
|
|
|
|
2005-11-22 21:59:48 +00:00
|
|
|
// if user specified background in the config then use it
|
|
|
|
// instead of style background
|
|
|
|
if (!m_root_command.empty()) {
|
|
|
|
FbCommands::ExecuteCmd cmd(m_root_command, screenNum());
|
2003-04-25 10:14:54 +00:00
|
|
|
cmd.execute();
|
2005-11-22 21:59:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-02-12 08:02:39 +00:00
|
|
|
|
2005-11-22 21:59:48 +00:00
|
|
|
//
|
|
|
|
// Else parse background from style
|
|
|
|
//
|
|
|
|
|
|
|
|
// root window helper
|
|
|
|
FbRootWindow rootwin(screenNum());
|
|
|
|
|
|
|
|
// if the background theme item was not loaded
|
|
|
|
|
|
|
|
if (!m_background_loaded) {
|
2006-04-02 13:16:35 +00:00
|
|
|
const char *warning_msg =
|
2006-02-12 08:02:39 +00:00
|
|
|
_FBTEXT(Common, BackgroundWarning,
|
|
|
|
"There is no background option specified in this style."
|
|
|
|
" Please consult the manual or read the FAQ.",
|
|
|
|
"Background missing warning");
|
2005-11-22 21:59:48 +00:00
|
|
|
|
2006-02-12 08:02:39 +00:00
|
|
|
cerr<<"Fluxbox: "<<warning_msg<<endl;
|
|
|
|
|
2003-04-25 10:14:54 +00:00
|
|
|
} else {
|
2005-11-22 21:59:48 +00:00
|
|
|
// 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
|
|
|
|
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 ";
|
2005-12-03 09:48:32 +00:00
|
|
|
if (strstr(m_background->options().c_str(), "random") != 0)
|
|
|
|
options += "-r ";
|
2005-12-03 18:15:55 +00:00
|
|
|
if (strstr(m_background->options().c_str(), "aspect") != 0)
|
2005-12-03 09:48:32 +00:00
|
|
|
options += "-a ";
|
|
|
|
|
2005-11-22 21:59:48 +00:00
|
|
|
// compose wallpaper application "fbsetbg" with argumetns
|
|
|
|
std::string commandargs = "fbsetbg " + options + " " + filename;
|
2006-02-12 08:02:39 +00:00
|
|
|
|
2005-11-22 21:59:48 +00:00
|
|
|
// call command with options
|
|
|
|
FbCommands::ExecuteCmd exec(commandargs, screenNum());
|
|
|
|
exec.execute();
|
|
|
|
|
|
|
|
} else {
|
2006-02-12 08:02:39 +00:00
|
|
|
// render normal texture with fbsetroot
|
2005-11-22 21:59:48 +00:00
|
|
|
|
|
|
|
|
2006-02-12 08:02:39 +00:00
|
|
|
// 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());
|
2005-11-22 21:59:48 +00:00
|
|
|
|
2006-02-12 08:02:39 +00:00
|
|
|
std::string options;
|
|
|
|
if (color_valid)
|
|
|
|
options += "-foreground '" + m_background->colorString() + "' ";
|
|
|
|
if (color_to_valid)
|
|
|
|
options += "-background '" + m_background->colorToString() + "' ";
|
2005-11-22 21:59:48 +00:00
|
|
|
|
2006-02-12 08:02:39 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
rootwin.clear();
|
|
|
|
}
|
2005-11-22 21:59:48 +00:00
|
|
|
|
2003-04-25 10:14:54 +00:00
|
|
|
}
|