You are not logged in.

#1 2011-03-20 11:15:09

lashni
Member
Registered: 2010-07-16
Posts: 7

openbox: wallpaper per desktop

I don't know if this will scratch anyones itch but I wanted a different wallpaper for each virtual desktop in openbox. Feh seems to be the fastest at setting backgrounds. Timing different graphic filetypes revealed that bmp renders the fastest so I recommend using imagemagick convert on your png/jpg wallpapers. There will still be a noticeable lag when changing desktops but I find it pretty bearable. On a desktop with an nvidia card, I couldn't figure out how to avoid a flicker during the desktop wallpaper rendering but had no such problem with this notebook with an ati card.

The program looks for bmp files named 0-3 (or your maximum number of virtual desktops) in the wp directory.

Some xlib code was pinched from Neap (BSD). Requires python-xlib.

chdesk.py

#!/usr/bin/env python2

import os
import sys
from Xlib import display, X
import Xlib.protocol.event


bg = 'feh --bg-center'
wp = '~/dev/desktop/wallpapers/'


class Desktop():

    def __init__(self):
        self.display = display.Display()
        self.screen = self.display.screen()
        self.root = self.screen.root
        self.current = self.root.get_full_property(self.display.intern_atom('_NET_CURRENT_DESKTOP'), 0).value[0]
        self.total = self.root.get_full_property(self.display.get_atom('_NET_NUMBER_OF_DESKTOPS'), 0).value[0]

    def next_desktop(self, direction):
        highest = self.total - 1
        lowest = 0
        if direction == 'left':
            if self.current == lowest:
                return highest
            else:
                return self.current - 1
        if direction == 'right':
            if self.current == highest:
                return lowest
            else:
                return self.current + 1

    def change_desktop(self, num):
        win = self.root
        ctype = self.display.get_atom('_NET_CURRENT_DESKTOP')
        data = [num]
        self.send_event(win, ctype, data)
        os.system(bg + " " + wp + str(num) + ".bmp")
        self.display.flush()

    def send_event(self, win, ctype, data, mask=None):
        data = (data + [0] * (5 - len(data)))[:5]
        ev = Xlib.protocol.event.ClientMessage(window=win,
                client_type=ctype, data=(32, data))
        if not mask:
            mask = X.SubstructureRedirectMask | X.SubstructureNotifyMask
        self.root.send_event(ev, event_mask=mask)


if __name__ == "__main__":
    desk = Desktop()
    try:
        new = int(sys.argv[1])
        desk.change_desktop(new)
    except ValueError:
        new = desk.next_desktop(sys.argv[1])
        desk.change_desktop(new)

rc.xml

    <keybind key="W-Left">
      <action name="Execute">
        <command>/home/shudde/dev/desktop/chdesk.py left</command>
      </action>
    </keybind>
    <keybind key="W-Right">
      <action name="Execute">
        <command>/home/shudde/dev/desktop/chdesk.py right</command>
      </action>
    </keybind>

    <keybind key="W-F1">
      <action name="Execute">
        <command>/home/shudde/dev/desktop/chdesk.py 0</command>
      </action>
    </keybind>
    <keybind key="W-F2">
      <action name="Execute">
        <command>/home/shudde/dev/desktop/chdesk.py 1</command>
      </action>
    </keybind>
    <keybind key="W-F3">
      <action name="Execute">
        <command>/home/shudde/dev/desktop/chdesk.py 2</command>
      </action>
    </keybind>
    <keybind key="W-F4">
      <action name="Execute">
        <command>/home/shudde/dev/desktop/chdesk.py 3</command>
      </action>
    </keybind>

EDIT: Removed pygtk import and dependency note, was from a similar project.

Last edited by lashni (2011-03-20 11:21:31)

Offline

#2 2011-04-14 04:38:27

ki3rk3gaard
Member
From: Bushwick not Williamsburg
Registered: 2011-04-09
Posts: 8

Re: openbox: wallpaper per desktop

Kewl Beanz thanks I had thought of doing the same . Let me know about any other Openbox tweaks .


It belongs to the imperfection of everything human that man can only attain his desire by passing through its opposite.

Offline

#3 2011-04-14 12:26:11

lashni
Member
Registered: 2010-07-16
Posts: 7

Re: openbox: wallpaper per desktop

I would but I actually changed over to qtile now... the barrier to entry is a lot higher than openbox but I'm loving using a wm written in python with a nice API.

http://qtile.org

Offline

Board footer

Powered by FluxBB