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
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

A way to have per desktop or random wallpapers in Openbox

#!/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 nitrogen, 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 

Offline

Help fund CrunchBang, donate to the project!

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

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

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

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

Offline

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

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

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

Offline

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

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

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?

Offline

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

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

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)

Offline

#6 2015-04-12 21:10:19

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

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

Offline

#7 2015-04-12 23:51:03

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 13,970

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

Offline

#8 2015-05-07 22:36:40

userx-bw
#! Die Hard
From: stuck in an unknown reality
Registered: 2013-11-19
Posts: 735

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

Last edited by userx-bw (2015-05-07 22:44:18)


"How can you learn how to fix it, if you don't break it first? ops
"the only way to get away with murder is - by killing time" swp 1997  monkey
"A computer is only as smart as the person using it"
"Just plug it in and see if it blows up, if not then take it apart and figure out how it works."

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.
Server: acrobat

Debian Logo