From c52a84a1704a2963b3d454a43617d8911778fb72 Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Tue, 5 Aug 2008 23:40:18 -0700 Subject: make wallpapers do The Right Thing (tm) --- ChangeLog | 3 +++ src/RootTheme.cc | 74 +++++++++++++++++++++++++--------------------------- src/RootTheme.hh | 2 +- util/fbsetbg | 39 +++++++++++++++++++++------ util/startfluxbox.in | 24 +---------------- 5 files changed, 72 insertions(+), 70 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5020fc..8a6a8f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ (Format: Year/Month/Day) Changes for 1.1 +*08/08/06: + * Automatically restore the previous background on startup (Mark) + RootTheme.cc/hh util/fbsetbg startfluxbox.in *08/08/05: * Fixed Focus key command (Mark) CurrentWindowCmd.cc/hh FocusableList.cc/hh diff --git a/src/RootTheme.cc b/src/RootTheme.cc index 617c3d5..c09957f 100644 --- a/src/RootTheme.cc +++ b/src/RootTheme.cc @@ -150,7 +150,8 @@ RootTheme::RootTheme(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_image_ctrl(image_control) { + m_image_ctrl(image_control), + m_first(true) { Display *disp = FbTk::App::instance()->display(); m_opgc.setForeground(WhitePixel(disp, screenNum())^BlackPixel(disp, screenNum())); @@ -183,10 +184,6 @@ void RootTheme::reconfigTheme() { if (!m_background->changed()) return; - // style doesn't wish to change the background - if (strstr(m_background->options().c_str(), "none") != 0) - return; - // // Else parse background from style // @@ -197,37 +194,35 @@ void RootTheme::reconfigTheme() { 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())) { + std::string cmd = realProgramName("fbsetbg") + (m_first ? " -z " : " -Z "); + + // style doesn't wish to change the background + if (strstr(m_background->options().c_str(), "none") != 0) { + if (!m_first) + return; + } else if (FbTk::FileUtil::isRegularFile(filename.c_str())) { // parse options - std::string options = "-F "; 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 = realProgramName("fbsetbg") + " " + options + - filename; - - // call command with options - FbCommands::ExecuteCmd exec(commandargs, screenNum()); - exec.execute(); - + cmd += "-t "; + else if (strstr(m_background->options().c_str(), "centered") != 0) + cmd += "-c "; + else if (strstr(m_background->options().c_str(), "aspect") != 0) + cmd += "-a "; + else + cmd += "-f "; + + cmd += filename; } else if (FbTk::FileUtil::isDirectory(filename.c_str()) && - strstr(m_background->options().c_str(), "random") != 0) { - std::string commandargs = realProgramName("fbsetbg") + " -R " + - filename; - FbCommands::ExecuteCmd exec(commandargs, screenNum()); - exec.execute(); + strstr(m_background->options().c_str(), "random") != 0) { + cmd += "-r " + filename; } else { // render normal texture with fbsetroot - + cmd += "-b "; // Make sure the color strings are valid, // so we dont pass any `commands` that can be executed @@ -240,23 +235,26 @@ void RootTheme::reconfigTheme() { std::string options; if (color_valid) - options += "-foreground '" + m_background->colorString() + "' "; + cmd += "-foreground '" + m_background->colorString() + "' "; if (color_to_valid) - options += "-background '" + m_background->colorToString() + "' "; + cmd += "-background '" + m_background->colorToString() + "' "; if (strstr(m_background->options().c_str(), "mod") != 0) - options += "-mod " + m_background->modX() + " " + m_background->modY(); + cmd += "-mod " + m_background->modX() + " " + m_background->modY(); else if ((*m_background)->type() & FbTk::Texture::SOLID && color_valid) - options += "-solid '" + m_background->colorString() + "' "; - + cmd += "-solid '" + m_background->colorString() + "' "; else if ((*m_background)->type() & FbTk::Texture::GRADIENT) { - options += "-gradient '" + m_background->options() + "'"; + // remove whitespace from the options, since fbsetroot doesn't care + // and dealing with sh and fbsetbg is impossible if we don't + std::string options = m_background->options(); + options = FbTk::StringUtil::replaceString(options, " ", ""); + options = FbTk::StringUtil::replaceString(options, "\t", ""); + cmd += "-gradient " + options; } - - std::string commandargs = realProgramName("fbsetroot") + " " + options; - - FbCommands::ExecuteCmd exec(commandargs, screenNum()); - exec.execute(); } + // call command with options + FbCommands::ExecuteCmd exec(cmd, screenNum()); + m_first = false; + exec.execute(); } diff --git a/src/RootTheme.hh b/src/RootTheme.hh index 5ae5165..09c752c 100644 --- a/src/RootTheme.hh +++ b/src/RootTheme.hh @@ -64,7 +64,7 @@ private: BackgroundItem *m_background;///< background image/texture FbTk::GContext m_opgc; FbTk::ImageControl &m_image_ctrl; ///< image control for rendering background texture - + bool m_first; }; #endif // ROOTTHEME_HH diff --git a/util/fbsetbg b/util/fbsetbg index 0f38d4c..a12d427 100644 --- a/util/fbsetbg +++ b/util/fbsetbg @@ -155,14 +155,14 @@ remembercommand() { grep -vs "|${DISPLAY}$" ${lastwallpaper} > ${lastwallpaper}.tmp mv -f ${lastwallpaper}.tmp ${lastwallpaper} if [ "$option" = fbsetroot ]; then - echo $option"|$wallpaper|"$DISPLAY >> $lastwallpaper + echo $option"|$wallpaper|$style|"$DISPLAY >> $lastwallpaper return fi # Make dir/../../path/file.jpg work case $wallpaper in # no spaces allowed between the varname and '|' - /*) echo $option $option2"|$wallpaper|"$DISPLAY >> $lastwallpaper ;; - *) echo $option $option2"|$PWD/$wallpaper|"$DISPLAY >> $lastwallpaper ;; + /*) echo $option $option2"|$wallpaper|$style|"$DISPLAY >> $lastwallpaper ;; + *) echo $option $option2"|$PWD/$wallpaper|$style|"$DISPLAY >> $lastwallpaper ;; esac } @@ -252,13 +252,11 @@ while [ $# -gt 0 ]; do -b) option=fbsetroot shift wallpaper=$* - use_fbsetroot break ;; -B) option=fbsetroot shift wallpaper=$* remember=false - use_fbsetroot break ;; -r) option2=$option option=random @@ -285,15 +283,36 @@ while [ $# -gt 0 ]; do message "No previous wallpaper recorded for display ${DISPLAY}" exit 1 fi - if [ "$option" = "fbsetroot" ]; then - use_fbsetroot - fi else message "No previous wallpaper recorded for display ${DISPLAY}" exit 1 fi remember=false break ;; + -z) + if [ -r "$lastwallpaper" ]; then + option=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f1` + option2=`echo $option|cut -d' ' -f2` + option=`echo $option|cut -d' ' -f1` + style=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f3` + wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2` + if [ -z "$wallpaper" ]; then + option=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f1` + option2=`echo $option|cut -d' ' -f2` + option=`echo $option|cut -d' ' -f1` + style=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f3` + wallpaper=`grep "|${DISPLAY}.0$" $lastwallpaper|cut -d'|' -f2` + fi + fi + if [ "$style" != "style" -a -n "$wallpaper" ]; then + remember=false + break + fi + style="style" + shift ;; + -Z) + style="style" + shift ;; -p) display_tips ; exit 0 ;; -h) display_help ; exit 0 ;; --) @@ -323,6 +342,10 @@ while [ $# -gt 0 ]; do esac done +if [ "$option" = "fbsetroot" ]; then + use_fbsetroot +fi + # Find the default wallpapersetter if [ "$setterfromcommandline" != true ]; then if [ -r "$lastwallpaper" ]; then diff --git a/util/startfluxbox.in b/util/startfluxbox.in index 64c48e3..3c083f3 100755 --- a/util/startfluxbox.in +++ b/util/startfluxbox.in @@ -39,30 +39,8 @@ else # # Lines starting with a '#' are ignored. -# This sets a black background - -@pkgprefix@fbsetroot@pkgsuffix@ -solid black - -# You can set your favourite wallpaper here. You will also need to uncomment the -# line in $HOME/.@pkgprefix@fluxbox@pkgsuffix@/overlay or else your style will override it. -# -# @pkgprefix@fbsetbg@pkgsuffix@ -f $HOME/.@pkgprefix@fluxbox@pkgsuffix@/backgrounds/wallpaper.png - -# Other examples. Check man xset for details. -# -# Turn off beeps: -# xset -b -# -# Increase the keyboard repeat-rate: -# xset r rate 195 35 -# -# Your own fonts-dir: -# xset +fp "$HOME/.fonts" -# # Change your keymap: -# xmodmap "$HOME/.Xmodmap" - - +xmodmap "$HOME/.Xmodmap" # Applications you want to run with fluxbox. # MAKE SURE THAT APPS THAT KEEP RUNNING HAVE AN ''&'' AT THE END. -- cgit v0.11.2