Tuesday 18 August 2009

How to make Conky play nicely with KDE 4.3

Up till recently, I stuck fervently to Gnome DE, since it was the default on Ubuntu 8.10. After I upgraded to Ubuntu 9.04, I decided to give Kubuntu a whirl (the current version of Kubuntu is KDE 4.2), but I could barely get it to run for an hour without a total system freeze, so I ditched that idea!

When KDE 4.3 came out, I was willing to give it another try, especially as a number of folks on the August Screenie Thread at the Ubuntu Forums said that it was much faster and better all around than 4.2...Well, they didn't let me down! However, this is not an I LOVE KDE thread...

Since I depend heavily on Conky to keep my system running, I needed KDE and Conky to play nicely together or I wouldn't be able to use it full-time. Since I already used a startup script to run Conky, I just let that run in KDE and, uh, got this:
From My Little Desktop Photos

After a bit of investigation (thank you, Internet), I discovered that the reason was twofold: first, Conky uses pseudo-transparency instead of ACTUAL transparency; second, KDE doesn't draw wallpaper to the root window, only to the plasma desktop. To clarify these points:
1) Pseudo-transparency in Conky means that it peeks at the root desktop and draws it as the background of the Conky window.
2) KDE draws wallpapers to the plasma desktop only, which is the lowest window on top of the root window. Instead, the root window is empty, which shows up in Conky as black. Yuck. Well, unless you really like black.

Anyway, after much tinkering, I have gotten my desktop to look like this:
From My Little Desktop Photos

Yay!

To get your Conky and KDE to cooperate, rather than pugilate (is that a word?):

Use feh to draw the current background to the root window.

Feh is a lightweight image viewer, but that's really irrelevant, since it does what we need it to here! To install it (if you haven't already), use:
sudo apt-get install feh

I will assume for the moment that you are already using a startup script to launch your Conky from the startup programs menu...Mine initially looked like this:
#!/bin/bash
sleep 15
conky &

I wanted to run feh just once before Conky started up, so that the root window was already drawn before Conky tried to peek at it, so I modified my conky_start.sh to be:
#! /bin/bash
feh --bg-scale `grep 'wallpaper=' ~/.kde/share/config/plasma-desktop-appletsrc | tail --bytes=+11`
sleep 15
conky -&

A couple of notes...The "--bg-scale" option assumes that you use "scale" to draw your wallpaper (as opposed to center, tile, etc.). If you do use another method, you can also use --bg-tile --bg-center, etc. instead. The feh looks at the plasma-desktop-appletsrc file to see what wallpaper is currently being used, and draws that to the background.

And as with all tweaks, there are a couple of pitfalls. First, because we're running feh just once before Conky starts, if you change backgrounds during your session, it won't change in Conky, a la this:
From My Little Desktop Photos

I would recommend doing a
killall conky
~/scripts/conky_start.sh

and restarting the plasma-desktop to redraw your Conky (I just log out and back in).

Another pitfall is that if you use the stock KDE wallpapers, this method may not work. That's because the "wallpaper=" field in plasma-desktop-appletsrc in this case points to a directory, not a file, and somehow KDE figures out which of several resolutions to use. Feh can't figure that out, so it draws nothing, and you're back to the black background. The workaround is to find the wallpaper you want, copy it into, say ~/Pictures/Wallpapers/ and select it from there with the Desktop Settings dialog.

Ensure that your Conky window doesn't overlap any plasmoids.

Regardless of whether you use own_window_hints below (see my previous post), plasmoids will always draw still lower. So if your Conky window overlaps, you'll get something like this:
From My Little Desktop Photos

(Keep in mind that I use Compiz to make my Conky semi-transparent, as in another previous post...)

Enjoy KDE!!!


Well, that's pretty self-explanatory...!

12 comments:

  1. Heya Londonali1010,

    Welcome to the wonderful world of KDE4 + Conky!
    I do have 2 notes for your blog...

    a. I like to use an ${execi 6000 feh --bg-scale "`grep 'wallpaper=' ~/.kde/share/config/plasma-desktop-appletsrc | head -n1 | tail --bytes=+11`"} in the start of my .conkyrc (just under TEXT) so that every so often the background changes to match what the plasma settigs have.

    b. notice I have an extra 'head' shatement in there... that's because if you look at the file (~/.kde/share/config/plasma-desktop-appletsrc) you will find a history of sorts of wallpapers you have used... the head command only grabs the 1st one, which is the one currently in use.

    ReplyDelete
  2. Hey Crinos, great to see you here!

    I purposely didn't add the feh line to my Conky because I didn't want to run except when Conky starts up. Especially because if I change the background, the plasma-desktop-appletsrc doesn't seem to change until I reboot anyway, so there's no point in running it more often.

    Also...Maybe we have a slightly different version of the file because I only have one instance of "wallpaper="...The one above it is "userswallpapers=" so wouldn't get found...

    ReplyDelete
  3. Well heck...

    The version of KDE I've got installed doesn't store multiple "wallpaper=" lines either... wonder when that changed.

    Oh well, that's what I get for using beta...

    BTW: The plasma-desktop-appletsrc does update without a reboot, it just takes a VERY long time. (read as an hour or two) I'm not sure why the long delay, or where th info is stored temporarily. (It would have to be, wouldn't it?)

    ReplyDelete
  4. OK, it's been a long time and plasma-desktop-appletsrc still has not updated... I'm starting to thing you are correct on this one too.

    ReplyDelete
  5. Aha! it finally updated!

    whew... took long enough. (~4 hours!)
    that's absurd.

    ReplyDelete
  6. Hm...That's weird. I wonder why it doesn't update? It may just be that it's like a "session save" document that helps KDE boot up, but then only does a backup every several hours unless you logout...?

    ReplyDelete
  7. thanks! for th info ;)

    ReplyDelete
  8. Hi, I followed your tutorial but the black background is below the conky all the times. You have any suggestion for solve this?

    (Sorry for my English)

    ReplyDelete
  9. Well, after some intents I found that the only solution to draw the background below the Conky is to run the Feh line command on terminal. I try to make an .sh file with this script and put this on the autostart folder but there are something wrong, because does not work.

    Suggestions?

    PD. When I run on terminal "sudo nautilus" the Conky crashed.

    ReplyDelete
  10. hello.

    This is how you change background and make conky change as well:

    1 - change background.
    2 - change folder view to desktop view
    3 - terminal:
    feh --bg-scale `grep 'wallpaper=' ~/.kde/share/config/plasma-desktop-appletsrc | tail --bytes=+11`
    4 - change back to folder view

    all set :)

    ReplyDelete
  11. Hi,

    I've found that setting 'own_window_argb_visual' to enabled solves the problem and has none of the pitfalls you mention (got it from: http://conky.sourceforge.net/config_settings.html).
    Don't know if this works with every system.

    Using Ubuntu 10.04 + KDE

    Cheers!

    ReplyDelete
  12. Another way to make conky change when you change the wallpaper is to install inotify-tools and add the following to your $HOME/.kde/Autostart/

    #!/bin/bash
    while [ TRUE ]; do inotifywait .kde/share/config/plasma-desktop-appletsrc; feh --bg-scale `grep 'wallpaper=' ~/.kde/share/config/plasma-desktop-appletsrc | tail --bytes=+11`; done

    The script is waiting for changes to the plasma-desktop-appletrc file; once it detects a change, the feh command is executed and updates conky background. This is not that bad (anymore) since the appletrc file is updated within a few seconds after the wallpaper changes.

    This can be achieved even more efficiently by checking whether the change in the appletrc file is the wallpaper, in which case it should execute the feh command.

    ReplyDelete