SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-02-23 00:39:22

damo
#! Die Hard
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 653

A way to have per desktop or random wallpapers in Openbox

When I used Fluxbox it was dead easy to have different wallpapers on each desktop, using the changeworkspace entry in the configuration. It is easy enough to use keybindings to call eg feh/nautilus/fsetbg etc to change the background (loadsa threads on this out there), but I couldn't get it work with the mouse bindings as well. And having lots of identical <xml> entries seems a bit of an inelegant hack.

I tried using 'wmctrl', and got it working after a fashion with a bash script, but then tried 'xprop' :
'xprop -root _NET_CURRENT_DESKTOP'  outputs the necessary info to work with, and I've now "finished" a python script to give me the same functionality that Fluxbox did smile

Using 'feh' to load the images every time isn't so efficient I suppose, but I only notice the cpu load when quickly mousewheel scrolling through the desktops.

There are commandline switches to set per desktop or random wallpapers, and the time lag or time between changes.

USAGE at the beginning of the py file, which can be found at switchbg.py

NB There is minimal error trapping so use at your own risk! (And any pythonistas out there please be gentle with my noob code smile )

For a barebones script to set per desktop backgrounds, this is what I started with (but you will have to hard-code your specific details)....

#!/usr/bin/env python

#=========================================================================================
#   Written by damo, feb 2012
#   Use as you like :)
#=========================================================================================
#
#   Python script to set per-desktop background wallpaper for Openbox WM, without the need to
#   add shell commands to key and mouse bindings.
#
#   This code uses 'xprop' to get the current desktop, then 'feh' to set the wallpaper
#
#   You need to create a background image for each desktop, named '0.jpg','1.jpg' etc,
#   (although you could change the code to read eg 'png' etc)
#
#   See 'feh' man page for options, which can be entered as fields in the subprocess.call()
#==========================================================================================
#   USAGE   python switchbg.py [options]
#
#           [option 1] : [/path/to/wallpaper/directory/]
#           [option 2] : [secs] (0.25 works OK) - time to poll xprop, 
#
#   Set the initial wallpaper background in autostart, using nautilus, feh, fsetbg etc
#   then add this script eg...
#
#   (feh --bg-scale /path/to/wallpaper/directory/0.jpg) &
#   (sleep 2s && python /path/to/switchbg.py /path/to/wallpaper/directory/ 0.2) &
#
#=========================================================================================

import time,subprocess,sys

def xprop_pipe(wp,t):
    '''Params are path to wallpaper directory (from args, and passed to set_bg()),
        and time to wait between xprop calls;
        Run xprop subprocess in an endless loop. It gets the current desktop as a string from
        stdout. The desktop number (0,1,2,3...) is the last field (cardinal),
        which is extracted with 'tail';
        communicate() returns a tuple, so we want the first value and discard the '\n';
        If the cardinal has changed, call set_bg() to change the wallpaper'''
    
    dtop = 0 # set initial desktop number (flag)
    xp = 'xprop -root _NET_CURRENT_DESKTOP | tail -c -2'# set xprop shell command

    while True:
        proc = subprocess.Popen(xp,stdout=subprocess.PIPE,shell=True)# subprocess: pipe to stdout
        curr_dtop = proc.communicate()[0]  # output is tuple, so get first val (desktop number)
        curr_dtop = int(curr_dtop)         # current desktop cardinal = 0,1,2,3...
        if curr_dtop != dtop:              # if cardinal has changed....
            set_bg(wp,curr_dtop)           # ....call set_bg func
            dtop = curr_dtop               # set the flag to current desktop
            
        time.sleep(t)                      # wait for t secs (from args)

def set_bg(wpath,i):
    '''params are the path to wallpaper directory and current desktop number;
        Get file path for wallpaper directory (from args);
        Run 'feh' shell command to set wallpaper for current desktop'''
    #======= set image filetype here... ==========================================================
    bg = wpath + str(i) + ".jpg"
    #======= See feh man pages for options: each should be in its own comma-separated quoted field
    subprocess.call(['feh','--bg-scale',bg],)# sub.call can be passed a list of strings as 
                                             # commandline input - no need to escape spaces etc

if __name__ == '__main__':
    '''commandline arguments are filepath to wallpaper directory [1], and polling time (secs)[2]
        Pass these on'''
    wp = sys.argv[1]       # path to wallpaper directory 
    t = float(sys.argv[2]) #convert commandline string input to float(required by sleep() )
    xprop_pipe(wp,t)       #run xprop to get current desktop 

Artwork at deviantArt; Iceweasel Personas; GDM #! Themes;
SLiM #! Themes

Offline

Be excellent to each other!

#2 2012-03-03 20:46:42

SabreWolfy
#! Die Hard
Registered: 2009-03-09
Posts: 1,276

Re: A way to have per desktop or random wallpapers in Openbox

So this changes/applies the wallpaper every time you switch desktops?


Support #!Waldorf • Debian sid • Xubuntu • siduction • Peppermint • OpenBox • Xfce • LXDE •

Offline

#3 2012-03-04 21:51:49

damo
#! Die Hard
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 653

Re: A way to have per desktop or random wallpapers in Openbox

SabreWolfy wrote:

So this changes/applies the wallpaper every time you switch desktops?

Yes. I've put it in my autostart, and here's no need to edit keybindings


Artwork at deviantArt; Iceweasel Personas; GDM #! Themes;
SLiM #! Themes

Offline

#4 2012-03-05 14:16:25

SabreWolfy
#! Die Hard
Registered: 2009-03-09
Posts: 1,276

Re: A way to have per desktop or random wallpapers in Openbox

Looking at the number of times I switch between desktops, this would become quite an overhead smile Do you never run applications maximized? Transparent terminals?


Support #!Waldorf • Debian sid • Xubuntu • siduction • Peppermint • OpenBox • Xfce • LXDE •

Offline

#5 2012-03-05 15:08:23

damo
#! Die Hard
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 653

Re: A way to have per desktop or random wallpapers in Openbox

I've got Pentium(R) Dual-Core CPU @ 2.30GHz, and the "rest" usage is about 3%. Compositing adds another 6-8%, and the switchbg script uses <1% when it is just polling xprop. It zaps up pretty quickly if I'm doing lots of desktop switching, but I can toggle it on/off with a keybind if I'm doing something processor-intensive like a graphics render.

I like to use terminal transparency (guake dropdown terminal) and I don't find the overhead much to worry about,but YMMV

The point of the script is to emulate the Fluxbox feature I miss, and extensive searching hasn't come up with anything I like, to use in Openbox. No doubt there is a better way to do it, but I'm too noobish to have found it yet smile .

It's easy enough to give it a go on your system, and I wouldn't be offended if it ended up in the wastebin! (Feedback would be good though)


Artwork at deviantArt; Iceweasel Personas; GDM #! Themes;
SLiM #! Themes

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo