Notice: Undefined index: aiosp_use_tags_as_keywords in /home/ellina/blog.prashanthellina.com/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php on line 885

Drawing on your Desktop

This is related to the previous post and is meant in part to demonstrate how great Linux is for doing “weird” stuff :) . This is what we are
trying to do.

desktop circle graphics

The circles in the background have been drawn by the python script below. To get the script running you should have python and pygame installed. If you are on Ubuntu do this to install both otherwise you can get the binaries for your distribution/OS.

sudo apt-get install python pygame

The code:

import pygame
import sys
import random
import time

pygame.init()

window = pygame.display.set_mode((1280, 1024))
screen = pygame.display.get_surface()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit(0)

    x = random.choice(range(640))
    y = random.choice(range(480))
    radius = random.choice(range(100))
    col_r = random.choice(range(255))
    col_g = random.choice(range(255))
    col_b = random.choice(range(255))

    time.sleep(.01)
    rect = pygame.draw.circle(screen, (col_r, col_g, col_b), (x,y), radius)
    pygame.display.update(rect)

download code

Running the code:

This will set the environment variable “SDL_WINDOWID” so that the script will know what the root window is.

export SDL_WINDOWID=`xwininfo -root|grep "id:"|sed 's/^.*id: //'|sed 's/ (.*$//'`

We have to tell the window manager to stop drawing on the desktop. I use gnome where the “nautilus” process does the drawing. Let us ask it to stop drawing.

gconftool-2 --type bool --set /apps/nautilus/preferences/show_desktop false

Now run the script:

python desktop_circles.py

No Trackbacks

5 Comments

  1. cool stuff man!

    Posted July 28, 2009 at 5:33 am | Permalink
  2. Jamie Schirf

    Hi. Very interesting code.

    I tried it out myself. It works, but it seems that once I stop it (like with control C), X loses the ability to make any new windows. In fact, attempting to call xcalc, it fails with:

    X Error of failed request: BadMatch (invalid parameter attributes)
    Major opcode of failed request: 1 (X_CreateWindow)
    Serial number of failed request: 41
    Current serial number in output stream: 44

    I thought that maybe something wasn’t getting released, so I inserted the following code in before the loop, to catch and respond to the interrupt:

    def handle_sigint(signum, frame):
    “”"I want to ensure resources are released before bailing.”"”
    print(“SIGINT received.”);
    pygame.display.quit()
    pygame.quit()
    sys.exit(0)
    # Set handler to catch Interupts
    signal.signal(signal.SIGINT, handle_sigint)

    Unfortunately, it didn’t seem to change anything. Do you have any ideas why that might be?

    Oh yes, I’m running this under Debian/FluxBox, if that makes any difference.

    Posted August 16, 2009 at 4:13 am | Permalink
  3. :( . Sorry I have tried this only under GNOME in Ubuntu. Does the problem subside after restarting X?

    Posted August 18, 2009 at 7:37 pm | Permalink
  4. Jamie Schirf

    Yes, once I restart X the problem goes away. I also tried this under GNOME just now with the same result. I don’t have an Ubuntu install handy to try it on though at the moment. This has me really curious now.

    Posted August 19, 2009 at 4:57 am | Permalink
  5. "; DROP DATABASE; --

    I tried this a while ago and had the same problem. Everything works as long as it’s running, but as soon as the script ends, X goes havoc.

    I tried a few things but I too couldnt find a solution.

    Running awesome3 on Arch Linux.

    Just in case anyone reads this. Jamie, you are not alone :)

    Posted October 23, 2009 at 12:19 am | Permalink