Binding transparency to the mouse wheel in Openbox

The Gentoo wiki suggests using transset-df to adjust window transparency on the fly under xcompmgr.

I couldn’t find transset-df in the Ubuntu repositories, so this was actually done in Arch first. The package is in AUR and is marked safe, so Arch users can rig this up in a jiffy. When I get a chance, I’ll compile transset-df and make sure it works in Ubuntu (I don’t see why it wouldn’t).

Unfortunately, the Gentoo wiki only describes using xbindkeys; for Openbox, it’s all about the rc.xml file. You should have one in your ~/.config/openbox/ folder. If you don’t, copy it from the default location at /etc/xdg/openbox/ with this command:

cp /etc/xdg/openbox/rc.xml ~/.config/openbox/

Don’t just wildly copy *.xml from that location; you’ll overwrite the menu.xml file as well, and that could make your system menus real weird real fast.

Editing rc.xml is a little daunting at first, unless you’re used to XML. What you’re looking for in this example is the section marked context name="Titlebar". You can add this code just about anywhere, but it might take a little editing to make it work.

Insert this code, or copy and paste it. Remember that WordPress won’t allow proper XML tags, so replace the curly brackets with the appropriate greater-than and less-than symbols.

{mousebind button="C-Up" action="Click"}
{action name="Execute"}
{execute}
transset-df -p --inc 0.2
{/execute}
{/action}
{/mousebind}

That makes CTRL+mousewheel-up on the titlebar of a window increase the opacity of the window. Now for the opposite.

{mousebind button="C-Down" action="Click"}
{action name="Execute"}
{execute}
transset-df -p --min 0.2 --dec 0.2
{/execute}
{/action}
{/mousebind}

(By the way, those are double-dashes in front of min, inc and dec. WordPress doesn’t do those well either. If you just want to cut and paste my rc.xml, it’s in the Ubuntu-nl pastebin here. You might get a little weird behavior afterward, but don’t fret.)

That last section makes CTRL+mousewheel-down on the titlebar decrease the opacity, or make it more transparent. Save the file and restart Openbox (just from the right-click menu is enough. You don’t have to stop X altogether).

I strongly recommend making sure you use the --min flag on the decrease command. I lost a window somewhere before I started using the flag, and I’m still looking for it. 😉

Remember that it will only work when the mouse cursor is hovering over the window’s titlebar. If you want it to work on another part of the window decoration, move (or copy) those tags to the appropriate area in rc.xml. If you want to use a different key command (like CTRL+ALT+SHIFT or something), make sure you change the C-Up and C-Down parts to C-A-S-Up and C-A-S-Down, or whatever.

Have fun!

5 thoughts on “Binding transparency to the mouse wheel in Openbox

  1. ofek

    The keybindings worked perfectly and mimicked the beryl plugin with almost no memory footprint. Great idea and usage off transset-df.

    Reply
  2. Pingback: Hello world! « Urukrama’s Weblog

  3. Pingback: An Openbox Guide « Urukrama’s Weblog

  4. Pingback: Setting Window Transparency from the Keyboard « console matt

Leave a comment