Ubuntu Window Management with Multiple Monitors, Window Effects and Default File Associations

Multiple Monitors Window Management in Ubuntu

Moving your applications from one monitor to the next with hotkeys

I’ve been using multiple monitors for a while now, Starting with a 17″ CRT with a 19″ CRT and moving up to two 19″ LCD, then 3, then temporarily one wide screen and back to 2. Something I always loved having as a utility in ultramon that I couldn’t find in Ubuntu (Gnome) or any window manager for that matter, was the ability to move applications from monitor to monitor. I had assumed the search futile until I was searching about some questions I had concerning Compiz-fusion with dual monitors and I came about this thread on Ubuntu forums which brightened up my day. A fellow named gfixler posted a bash script that utilizes command line applications to move the windows.

For you multi-monitor users seeking salvation from removing your hand from the keyboard to move your application from one monitor to another, here’s the skinny on getting it setup using compiz-fusion, aka Advanced Desktop Effects, to set my keybinds.

1. Open a terminal and setup your prerequisites with apt-get:

sudo apt-get install wmctrl xprop xwininfo

If you get errors about x11-utils, just ignore them, this package will handle your needs.

2. Next, lets put the script somewhere you can call it, say “~/scripts

mkdir ~/scripts && cd ~/scripts && touch movewin.sh && chmod +x movewin.sh && gedit movewin.sh

2. Paste the following code, find the first function “getNumberOfMonitors” and configure it to the number of monitors you have (default 2).

#!/bin/bash
# swap_monitor.sh (original version)
# Moves the active window to the other screen of a dual-screen Xinerama setup.
#
# movewin.sh (modified version)
# allows movement of windows left and right between multiple monitors
#
# Requires: wmctrl, xprop, xwininfo
#
# Original Author: Raphael Wimmer
# raphman@gmx.de
#
# Modified by: Gary Fixler
# gfixler+bash@gmail.com
 
function getNumberOfMonitors
{
    # simply must be hardcoded
    # e.g. MatroxTripleHead2Go can service 3 screens,
    # but appears as only one monitor to the computer
 
    # change to your number of monitors
    echo 2
}
 
function getMonitorWidth
{
    numberOfMonitors=$(getNumberOfMonitors)
    monitorLine=$(xwininfo -root | grep "Width")
    monitorWidth=$((${monitorLine:8}/$numberOfMonitors ))
    echo $monitorWidth
}
 
function getActiveWindowID
{
    activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
    activeWinID="${activeWinLine:40}"
    echo $activeWinID
}
 
function getActiveWindowHorizontalPosition
{
    activeWinID=$(getActiveWindowID)
    xPosLine=$(xwininfo -id $activeWinID | grep "Absolute upper-left X")
    xPos=${xPosLine:25}
    echo $xPos
}
 
function getActiveWindowWidth
{
    activeWinID=$(getActiveWindowID)
    xWidthLine=$(xwininfo -id $activeWinID | grep "Width")
    xWidth=${xWidthLine:8}
    echo $xWidth
}
 
function getActiveWindowCurrentMonitor
{
    numberOfMonitors=$(getNumberOfMonitors)
    monitorWidth=$(getMonitorWidth)
    activeWinID=$(getActiveWindowID)
    xPos=$(getActiveWindowHorizontalPosition)
    i="0"
    while [ $xPos -gt $monitorWidth ]
    do
        xPos=$[$xPos-$monitorWidth]
        i=$[$i+1]
    done
    echo $i
}
 
function getActiveWindowPositionOneMonitorToTheLeft
{
    monitorWidth=$(getMonitorWidth)
    currentMonitor=$(getActiveWindowCurrentMonitor)
    activeWinID=$(getActiveWindowID)
    xPos=$(getActiveWindowHorizontalPosition)
    xPos=$[$xPos-$monitorWidth]
    echo $xPos
}
 
function getActiveWindowPositionOneMonitorToTheRight
{
    monitorWidth=$(getMonitorWidth)
    numberOfMonitors=$(getNumberOfMonitors)
    currentMonitor=$(getActiveWindowCurrentMonitor)
    activeWinID=$(getActiveWindowID)
    xPos=$(getActiveWindowHorizontalPosition)
    xPos=$[$xPos+$monitorWidth]
    echo $xPos
}
 
function changeActiveWindowMonitor
{
    activeWinID=$(getActiveWindowID)
    if [ $1 -eq "0" ]
    then
        newXPos=$(getActiveWindowPositionOneMonitorToTheLeft)
        newXPos=$[$newXPos-5]
    else
        newXPos=$(getActiveWindowPositionOneMonitorToTheRight)
        newXPos=$[$newXPos-5]
    fi
 
    winState=$(xprop -id ${activeWinID} | grep "_NET_WM_STATE(ATOM)" )
 
    if [[ `echo ${winState} | grep "_NET_WM_STATE_MAXIMIZED_HORZ"` != "" ]]
        then
        maxH=1
        wmctrl -i -r ${activeWinID} -b remove,maximized_horz
    fi
 
    if [[ `echo ${winState} | grep "_NET_WM_STATE_MAXIMIZED_VERT"` != "" ]]
        then
        maxV=1
        wmctrl -i -r ${activeWinID} -b remove,maximized_vert
    fi
 
    if [[ `echo ${winState} | grep "_NET_WM_STATE_FULLSCREEN"` != "" ]]
        then
        fulls=1
        wmctrl -i -r ${activeWinID} -b remove,fullscreen
    fi
 
    # move window (finally)
    wmctrl -i -r ${activeWinID} -e 0,${newXPos},-1,-1,-1
 
    # restore maximization
    ((${maxV})) && wmctrl -i -r ${activeWinID} -b add,maximized_vert
    ((${maxH})) && wmctrl -i -r ${activeWinID} -b add,maximized_horz
    ((${fulls})) && wmctrl -i -r ${activeWinID} -b add,fullscreen
 
    # raise window (seems to be necessary sometimes)
    wmctrl -i -a ${activeWinID}
 
}
 
function moveActiveWindowOneMonitorToTheLeft
{
    changeActiveWindowMonitor 0
}
 
function moveActiveWindowOneMonitorToTheRight
{
    changeActiveWindowMonitor 1
}
 
"$1"
 
exit 0

3. Setup your hot keys with compiz-fusion. Go to System >> Preferences >> Advanced Desktop Effects. Inside “General Options“, click on the command tab (I apologize for my heinous blue links).

Compiz-fusion Hotkeys 1

2008-11-25-210327_900x435_scrot.png

Use

scripts/./movewin.sh moveActiveWindowOneMonitorToTheRight

and

scripts/./movewin.sh moveActiveWindowOneMonitorToTheLeft

respectively

Per Application Window Effects in Ubuntu

Bring character and tickle your soul with per application window effects

Another cool feature Compiz-fusion has is window animations. My friend James Lindsay recently reminded me about Window Effects… which when I first install Ubuntu on my laptop, I experimented my butt off… but being a laptop… I just used simple ones I’d turn off half the time anyway. He asked me why I don’t use them on my desktop and I didn’t have a good reason. Well, now I have 2 good reasons to keep using compiz.

2008-11-25-210749_900x591_scrot.png

I made my Thunderbird use the airplane effect so when I send emails, it flys away and for Geany, I used the magic lamp for open, close, maximize and minimize (different speeds). It’s a fun little effect that breaks up the stiffness of the desktop.

Default File Associations in Ubuntu

geany > gedit

I was tired of gedit popping up when geany’s just as lightweight but more affective. So found a command and altered it a bit to make my default editor geany.

1. Open the terminal and create\open the following file:

gedit ~/.local/share/applications/defaults.list

If it’s blank, add “[Default Applications]“. If it’s not, find “[Default Applications]“.

2. Then, back to the terminal, grep the default files associations and replace gedit with your editor of choice

grep gedit /usr/share/applications/defaults.list | sed s/gedit/geany/g

Copy (ctrl+shift+c) and paste the output into gedit, below the “[Default Applications]” header.

3. Restart nautilus to load the changes (will close all your file managers that are open and blink/freeze your desktop for a second)

pkill nautilus

Good luck, have fun and happy coding :)

Sup Party People? Ya like Nexuiz and Geany? Ballin’ like a ninja?

I’ve been quite involved in the open-source project Nexuiz recently. Most of my free time between work and school is focused on it. School’s been an interesting challenge. I’m taking two Psychology courses and a Physics class. They are both helping me get a deeper understanding of the game, the code and the community I run based around it. Nexuiz is an appealing game to people of all skills, the code base has gotten pretty strong and the effects are looking really nice. The recent addition of client-side quakec has spawned new features that simply were not possible prior to this change.

Like this new scoreboard
pics.nexuizninjaz.com

developed by blub, roughly based on a mockup I created
pics.nexuizninjaz.com

whose later HUD is being attempted by victim
pics.nexuizninjaz.com

I also began to theorize object relationships to be future projects I’d like to develop
pics.nexuizninjaz.com

I started working on my mapping skills (made this baby for my Technical Theatre class)
pics.nexuizninjaz.com

later releasing a classic Halo favorite remade and remixed collaborating with Michael “Tenshihan” Quinn and Florian “tapas” Schmidt
nexuizninjaz.com

started building some tools to run Nexuiz game servers
pics.nexuizninjaz.com

which are being provided by
pics.nexuizninjaz.com
whom have been very kind in helping us setup, upgrade and change locations. Big thanks to mkzelda who’s helped keep us on our feet in this respect.

gave a little love to the Nexuiz Tournament website, further extending that theme back into the game:
pics.nexuizninjaz.com
pics.nexuizninjaz.com

and now the ninjaz at our 1 year anniversary
nexuizninjaz.com
that we are celebrating with a mapping contest.

I’m still using and loving
ubuntu.com

with a text editor I’m loving more each day, geany
geany

I hope to have more tips and tricks for you all soon. I’ve been learning a lot on linux recently. I’ve been pretty focused as you can see but I’d be more than happy to answer any questions you may have. Feel free to contact me.