You are not logged in.

#1 2015-11-16 22:57:40

damo
....moderator....
Registered: 2015-08-20
Posts: 4,386

Set backgrounds for each workspace and/or monitor in Openbox

This neat little script automatically sets the background for each workspace that you switch to. There is a slight lag while it does it, but it is way better than the polling method in the python script posted on the #! forums A way to have per desktop or random wallpapers in Openbox.

I've just found the code I've been looking for for years - how to monitor xprop desktop changes via a background process!

xprop -root -spy _NET_CURRENT_DESKTOP

Simples monkey

****************************************************

EDIT: Beware an xprop memory leak

As noted by @xaos52:

xaos52 wrote:

unresolved 'memory leak' bug against running xprop -spy for extended periods if time.

****************************************************

You need to have `feh` installed.

I know it isn't technically a daemon, but I've called it `wallpapersd` cos I think it sounds cool cool
[EDIT: updated script here: Post #6

#!/bin/bash
#
# Script to enable different wallpapers on each workspace and monitor.
# Written by damo <damo@bunsenlabs.org> November 2015
#
# When first run, the script writes a configuration file template. The user can
# then edit this and add the image filepaths.
#
# To run while logged in, add "wallpapersd &" to your autostart
#
# REQUIRES: 'feh'
###############################################################################

WALLS_FILE="$HOME/.config/wallpapers.cfg"
FEH_CMD="feh --bg-fill" # edit this, or wallpapers.cfg, to use a different feh command

TXT=$(echo -e "# Add filepaths to the images to be set as backgrounds on each workspace."
    echo -e "# You can have an image set for each monitor."
    echo -e "#\n# Commands should be in the form:\n#"
    echo -e "#  $FEH_CMD 'path/to/image1(monitor 1)' 'path/to/image2(monitor 2)' etc\n#"
    echo -e "############################################################################"
    )

if ! hash feh;then
    echo "feh is required to set the backgrounds. Install the feh package then re-run the script"
    exit 1
fi

if [[ ! -f $WALLS_FILE ]];then
    echo -e "$TXT\n" > "$WALLS_FILE"
    NUM_DESKTOPS=$(xprop -root _NET_NUMBER_OF_DESKTOPS | tail -c -2)
    for (( i=0; i < $NUM_DESKTOPS; i++ ));do
        echo "[DESKTOP_$i] $FEH_CMD " >> "$WALLS_FILE"
    done
    xdg-open "$WALLS_FILE"  # open cfg file for editing. Script must be restarted afterwards.
    exit
else
    xprop -root -spy _NET_CURRENT_DESKTOP | (   # <-- this is the watching process
    while read -r;do
        CURR_DESKTOP=${REPLY:${#REPLY}-1:1}
        while read DTOP CMD;do
            VAL="[DESKTOP_$CURR_DESKTOP]"
            if [[ "$DTOP" = "$VAL" ]];then
                eval $CMD
            fi
        done < "$WALLS_FILE"
    done
    )
fi

Credit to @garolou on the Mint forum for the idea here

-------------------------------

See `man feh` for possible background settings

You may find that a single widescreen image across 2 monitors needs the `--no-xinerama` parameter

Last edited by damo (2015-12-09 14:19:05)


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#2 2015-11-17 04:34:17

dolly
Miss Mixunderstand
From: /lab1
Registered: 2015-10-03
Posts: 343

Re: Set backgrounds for each workspace and/or monitor in Openbox

Very nice. Thanks! smile


Keep BunsenLabs #!yish please.

Offline

#3 2015-11-17 13:33:17

unklar
Member
Registered: 2015-10-31
Posts: 735

Re: Set backgrounds for each workspace and/or monitor in Openbox

Excellent! Many thanks.

Offline

#4 2015-11-21 08:39:47

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 4,677
Website

Re: Set backgrounds for each workspace and/or monitor in Openbox

Very nice discovery with that xprop line!!

A couple of the niggles you might expect...

Could that line setting TXT be simplified?

TXT= "# Add filepaths to the images to be set as backgrounds on each workspace.
# You can have an image set for each monitor.
#
# Commands should be in the form:
#
#  $FEH_CMD 'path/to/image1(monitor 1)' 'path/to/image2(monitor 2)' etc
#
############################################################################"

A tiny bicker, but you're parsing the output of xprop in two different ways for the same result. In fact they might both be simplified a bit:

NUM_DESKTOPS=$(xprop -root _NET_NUMBER_OF_DESKTOPS)
NUM_DESKTOPS=${NUM_DESKTOPS:(-1)}

CURR_DESKTOP=${REPLY(-1)}

But anyway, thank you for a great simple solution which I'll probably use myself soon. smile

(I wonder if it could be modified to use nitrogen instead of feh?)


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

#5 2015-11-21 11:59:40

damo
....moderator....
Registered: 2015-08-20
Posts: 4,386

Re: Set backgrounds for each workspace and/or monitor in Openbox

^ Thanks for the code comments.

I used `feh` because you can pass the image paths directly to it - one per monitor. `nitrogen` needs to read the config from a file, so it requires one cfg file per workspace and some extra work.

`feh` is so much easier wink


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#6 2015-11-21 19:42:30

damo
....moderator....
Registered: 2015-08-20
Posts: 4,386

Re: Set backgrounds for each workspace and/or monitor in Openbox

Made some edits as per @johnraff's suggestions.

Added usage/help options and command switch to edit config file. The config template now has the bg section from `man feh` for reference.

#!/bin/bash
#
# Script to enable different wallpapers on each workspace and monitor with Openbox
# Written by damo <damo@bunsenlabs.org> November 2015
#
# When first run, the script writes a configuration file template. The user can
# then edit this and add the image filepaths.
#
# To run while logged in, add "wallpapersd &" to your autostart
#
# REQUIRES: 'feh'
###############################################################################

WALLS_FILE="$HOME/.config/wallpapers.cfg"
FEH_CMD="feh --bg-fill" # edit this, or wallpapers.cfg, to use a different feh command

TXT="# Add filepaths to the images to be set as backgrounds on each workspace.
# You can have an image set for each monitor.
# Commands should be in the form:
#  $FEH_CMD 'path/to/image1(monitor 1)' 'path/to/image2(monitor 2)' etc
#
# From man feh:
# For the --bg-center and --bg-max options, you can use the --geometry option to
# specify an offset from one side of the screen instead of centering the image.
# Positive values will offset from the left/top side, negative values from the
# bottom/right.  +0 and -0 are both valid and distinct values.
#
# Note that all options except --bg-tile support Xinerama.  For instance,
# if you have multiple screens connected and use e.g.  --bg-center, feh will
# center or appropriately offset the image on each screen.  You may even specify 
# more than one file, in that case, the first file is set on screen 0, the second
# on screen 1, and so on.
#
# Use --no-xinerama to treat the whole X display as one screen when setting wallpapers.
#     --bg-center
#         Center the file on the background.  If it is too small, it will be
#         surrounded by a black border
#     --bg-fill
#         Like --bg-scale, but preserves aspect ratio by zooming the image until
#         it fits.  Either a horizontal or a vertical part of the image will be cut off
#     --bg-max
#         Like --bg-fill, but scale the image to the maximum size that fits the
#         screen with black borders on one side.
#     --bg-scale
#         Fit the file into the background without repeating it, cutting off stuff
#         or using borders.  But the aspect ratio is not preserved either
#     --bg-tile
#         Tile (repeat) the image in case it is too small for the screen
#
###########################################################################"

USAGE="USAGE:

  wallpapersd &   Runs the 'daemon' to set per-workspace backgrounds.
                  First run will open wallpapers.cfg, which has instructions and feh settings.
  
  --config        Open wallpapers.cfg for editing
  
  -h,--help       This help
"

if ! hash feh;then
    echo "feh is required to set the backgrounds. Install the feh package then re-run the script"
    exit 1
fi

case "$1" in
    -h|--help ) echo -e "\n$USAGE"
                exit
                ;;
    --config  ) if [[ -f $WALLS_FILE ]] &>/dev/null;then
                    echo -e "\n  Open wallpapers.cfg for editing?\n  (wallpapersd needs to be restarted afterwards) y|N"
                    read -srn1 RET
                    case $RET in
                        n|N ) exit;;
                        y|Y ) xdg-open "$WALLS_FILE" &  # open cfg file for editing
                              killall wallpapersd
                              exit
                              ;;
                        *   ) exit
                              ;;
                    esac
                else
                    echo -e "  No ~/.config/wallpapers.cfg found\n  Run wallpapersd first? Y|n?"
                    read -srn1 ANS
                    case $ANS in
                        n|N ) exit
                              ;;
                        *   ) wallpapersd 2>/dev/null & # run app to generate cfg template
                              xdg-open "$WALLS_FILE" &  # open cfg file for editing
                              ;;
                    esac
                fi
                ;;
esac

if [[ ! -f $WALLS_FILE ]];then
    echo -e "$TXT\n" > "$WALLS_FILE"
    NUM_DESKTOPS=$(xprop -root _NET_NUMBER_OF_DESKTOPS)
    NUM_DESKTOPS=${NUM_DESKTOPS:(-1)}
    for (( i=0; i < $NUM_DESKTOPS; i++ ));do
        echo "[DESKTOP_$i] $FEH_CMD " >> "$WALLS_FILE"
    done
    xdg-open "$WALLS_FILE"  # open cfg file for editing. Script must be restarted afterwards.
    exit
else
    xprop -root -spy _NET_CURRENT_DESKTOP | (   # <-- this is the watching process
        while read -r;do
            CURR_DESKTOP=${REPLY:(-1)}
            while read DTOP CMD;do
                VAL="[DESKTOP_$CURR_DESKTOP]"
                if [[ "$DTOP" = "$VAL" ]];then
                    eval $CMD
                fi
            done < "$WALLS_FILE"
        done
        )
fi

Now to investigate a nitrogen option.....


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#7 2015-11-22 03:28:54

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 4,677
Website

Re: Set backgrounds for each workspace and/or monitor in Openbox

damo wrote:

`feh` is so much easier wink

Really. feh is quite powerful for scripting things with images. Should we consider replacing nitrogen with feh for drawing the default wallpaper in BL?


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

#8 2015-11-22 06:37:39

nore
>2⁹
From: blueberry bush
Registered: 2015-09-29
Posts: 389

Re: Set backgrounds for each workspace and/or monitor in Openbox

johnraff wrote:

Should we consider replacing nitrogen with feh for drawing the default wallpaper in BL?

No objections, unless you put more weight on Linux newbie effect. Would "Change wallpaper" option in menu open  ~/.fehbg in text editor, then?
edit:Needs comments for bg-tile, bg-center, bg-max and bg-fill too.

Last edited by nore (2015-11-22 06:41:43)

Offline

#9 2015-11-22 06:49:58

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 4,677
Website

Re: Set backgrounds for each workspace and/or monitor in Openbox

^we'd have to write some scripts, but I think (without trying it) that you could do everything with feh that we are now doing with nitrogen. Like, feh also has options to show thumbnails of a directory full of images. I'm not sure if it can go recursive though...


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

#10 2015-11-22 12:37:18

nore
>2⁹
From: blueberry bush
Registered: 2015-09-29
Posts: 389

Re: Set backgrounds for each workspace and/or monitor in Openbox

Offline

#11 2015-11-22 13:28:13

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: Set backgrounds for each workspace and/or monitor in Openbox

+1 for replacing nitrogen with feh


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#12 2015-11-22 15:59:21

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,029

Re: Set backgrounds for each workspace and/or monitor in Openbox

I prefer feh as it is much more reliable on multi-monitor setups plus lends itself better to scripting. Setup some custom actions in your file manager and it is as good as any gui tool. Note: with some scripts for image browsing, the image viewer could be dumped as well.

Offline

#13 2015-11-23 10:43:27

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Set backgrounds for each workspace and/or monitor in Openbox

Nice script, damo, BUT:
seems like there is an unresolved 'memory leak' bug against running xprop -spy for extended periods if time.

My guess is that xprop is/was mostly used for debugging purposes. Hence no-one is really interested in fixing it. Not the Debian developers, nor upstream.

EDIT:
It is not clear from the bug report whether it is just

xprop -spy

- spying on all variables - that causes problems.
Could be that monitoring just one value is OK.
We need a test monkey to try it out several days on end, changing desktop regularly. Volunteers?

Last edited by xaos52 (2015-11-23 12:43:29)

Offline

#14 2015-11-23 14:08:03

damo
....moderator....
Registered: 2015-08-20
Posts: 4,386

Re: Set backgrounds for each workspace and/or monitor in Openbox

xaos52 wrote:

...
We need a test monkey to try it out several days on end, changing desktop regularly. Volunteers?

Well, I am running it from autostart. How do I test for mem leaks - use `free -m`?

EDIT: quick DIY mem log test, getting `free -m` after several workspace switches (Don't know if this indicates anything useful!)
Output is "used"

[damo@debian ~]$ free -m | awk '/Mem/ {print $3}' >> tmp/memlog
[damo@debian ~]$ cat tmp/memlog 
No wallpapersd running
1244
1244
1243
1243
1244
1244
1243
1243
1244
1243

wallpapersd running
1245
1247
1247
1246
1247
1247
1246
1246
1246
1246
1246

Last edited by damo (2015-11-23 14:54:04)


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#15 2015-11-24 11:59:55

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: Set backgrounds for each workspace and/or monitor in Openbox

Use valgrind to check memory usage per process.
Install package valgrind
Let this command run for an hour

_ valgrind --tool=memcheck --leak-check=full -v xprop -root -spy

in a terminal. ( _ is my alias for /usr/bin/sudo )
Then Ctrl+C and check 'LEAK SUMMARY'.

My limited tests show memory leaks indeed, even when just monitoring current desktop.

Offline

#16 2015-11-25 07:17:21

Snap
Member
Registered: 2015-10-02
Posts: 465

Re: Set backgrounds for each workspace and/or monitor in Openbox

tknomanzr wrote:

I prefer feh as it is much more reliable on multi-monitor setups plus lends itself better to scripting. Setup some custom actions in your file manager and it is as good as any gui tool. Note: with some scripts for image browsing, the image viewer could be dumped as well.

It doesn't do svg or animated gifs without external help and some times it has troubles with certain image files compression formats (or I'm missing libraries I'm not aware of). If imagemagick or a similar tool is in the BL deafults then it could be fine doing the workarounds/scripts and removing Nitrogen and the image viewer altogether. That's why I still use mirage (I prefer it to viewnior). imv might be a nice replacement for feh, but it's not in the Debian Stable repos, so I guess it doesn't count here.

@Doc: Thanks for the memory leak check howto.

Last edited by Snap (2015-11-25 07:19:46)

Offline

#17 2015-12-20 14:26:43

JohnTheCuriousEye
Member
Registered: 2015-12-13
Posts: 12

Re: Set backgrounds for each workspace and/or monitor in Openbox

Is there any such package/program which would do the same but in Graphical Form ? Example would be Nitrogen but it only changes wallpaper which appears on both connected screens.

Any suggestions if any ?

Offline

#18 2015-12-20 14:32:54

damo
....moderator....
Registered: 2015-08-20
Posts: 4,386

Re: Set backgrounds for each workspace and/or monitor in Openbox

JohnTheCuriousEye wrote:

Is there any such package/program which would do the same but in Graphical Form ? Example would be Nitrogen but it only changes wallpaper which appears on both connected screens.

Any suggestions if any ?

Not for Openbox AFAIK, hence the need to script it.

Anyway - surely a text editor is a graphical app for the settings? tongue


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#19 2015-12-20 17:55:38

JohnTheCuriousEye
Member
Registered: 2015-12-13
Posts: 12

Re: Set backgrounds for each workspace and/or monitor in Openbox

damo wrote:
JohnTheCuriousEye wrote:

Is there any such package/program which would do the same but in Graphical Form ? Example would be Nitrogen but it only changes wallpaper which appears on both connected screens.

Any suggestions if any ?

Not for Openbox AFAIK, hence the need to script it.

Anyway - surely a text editor is a graphical app for the settings? tongue

I don't mind using the script posted here but I have heard there is some memory leaks in it ...
Anyway that is a bit strange for me because AFAIK if you install nitrogen on Ubuntu you can choose the specific screen and change its wallpaper to a different one but I suspect such script already exists and that's why it's working on Ubuntu.

Offline

#20 2015-12-20 18:25:50

damo
....moderator....
Registered: 2015-08-20
Posts: 4,386

Re: Set backgrounds for each workspace and/or monitor in Openbox

By "screen" do you mean "desktop/workspace" or "monitor"?

Nitrogen on BL can set the background for screen/monitor, but not workspace. Ubuntu doesn't use Openbox as a window manager BTW.

Ref memleak - if you regularly reboot, or manually recover the memory, it isn't much of a problem. If you leave your machine on for days it would be.


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#21 2015-12-20 19:50:51

JohnTheCuriousEye
Member
Registered: 2015-12-13
Posts: 12

Re: Set backgrounds for each workspace and/or monitor in Openbox

damo wrote:

By "screen" do you mean "desktop/workspace" or "monitor"?

Nitrogen on BL can set the background for screen/monitor, but not workspace. Ubuntu doesn't use Openbox as a window manager BTW.

Ref memleak - if you regularly reboot, or manually recover the memory, it isn't much of a problem. If you leave your machine on for days it would be.

I have two monitors on which I would find it very useful but since it has memory leak I will avoid using this script. Yes but you can install Nitrogen and use it anyway.

Offline

#22 2015-12-20 20:10:07

damo
....moderator....
Registered: 2015-08-20
Posts: 4,386

Re: Set backgrounds for each workspace and/or monitor in Openbox

JohnTheCuriousEye wrote:

....
I have two monitors on which I would find it very useful but since it has memory leak I will avoid using this script. Yes but you can install Nitrogen and use it anyway.

If you just want to set backgrounds for different monitors then what is the problem? Just use Nitrogen.

If you want to have a different background for different workspaces in Openbox then use a script like this one (or search Crunchbang forums for conky or keybind solutions)

The Openbox wiki has links to different methods.
( One of the methods is to my python script on the Crunchbang forums, but the links are broken. See A way to have per desktop or random wallpapers in Openbox. This works by polling the current desktop, so is a bit resource-hungry)


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#23 2017-11-16 15:57:05

tamer
New Member
Registered: 2017-11-16
Posts: 1

Re: Set backgrounds for each workspace and/or monitor in Openbox

i'm working with my laptop on tv over hdmi in extend screen mode LAPTOP (LVDS 1366x768 and TV 1920x1080). Everytime i start the laptop the wallpaper gets stretched to both screens.

my nitrogen/bg-saved.cfg looks like this:

[:0.0]
file=/home/dt/Pictures/wallpapers/ennedi.png
mode=5
bgcolor=#2e3436

[xin_0]
file=/home/dt/Pictures/wallpapers/ennedi.png
mode=0
bgcolor=#000000

[xin_1]
file=/home/dt/Pictures/wallpapers/ennedi.png
mode=0
bgcolor=#000000

When i start nitrogen --save over commandline some Gtk-CRITICAL and GLib GObject errors

am i missing sth?

My next try was  to change the order of calling the screenlayout in autostart before
nitrogen --restore. But things get worse - no wallpaper and i even cant set any wallpaper anymore ^^ After choosing wallpaper nitrogen disappears ...

UPDATE:Just restarted and i dont know why but it works now ..

## set Displays
/home/dt/.screenlayout/tv-hdmi.sh

## Set a wallpaper
nitrogen --restore 

Last edited by tamer (2017-11-16 16:26:48)

Offline

#24 2017-11-16 17:05:05

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,029

Re: Set backgrounds for each workspace and/or monitor in Openbox

Nitrogen has had issues with multiple desktops in the past. I typically use feh to set wallpapers on my three monitor desktop.

Offline

#25 2017-11-17 01:46:14

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 4,677
Website

Re: Set backgrounds for each workspace and/or monitor in Openbox

Also, the [:0.0] syntax is no longer used by nitrogen. I should delete that top section from bg-saved.cfg anyway.


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

Board footer

Powered by FluxBB