Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I start GUI program, it's window appears appears on currently active desktop (essentially, on random desktop).

How to make it to appear on the specified desktop? For example, at startup I want certain programs to be started and distributed to desktops.

I've already set up config file of openbox to force some programs to always start on specific desktop.

Ideally it should be like:

start_on_desktop 1 gnome-terminal --tab -e program1 --tab -e program2
start_on_desktop 2 gnome-terminal --tab -e program3 --tab -e program4
start_on_desktop 3 firefox

It should be able to start the same program on other desktop.

Also dislike when I start program while being on desktop X then switch to desktop Y and SUDDENLY a program which should be on X appears on Y. When I start lots of programs on and switch often between desktops they end up being in chaos and I need to collect them together and redistribute sanely.

Also I want the first initial gnome-terminal to be on desktop 3, but I also want subsequent gnome-terminals to be on the desktop where I pressed the keystroke (also configured in openbox) that launches gnome-terminal.

share|improve this question
    
What are you using to manage your virtual desktops? As for "at startup I want certain programs to be started and distributed to desktops", this ( bbs.archlinux.org/viewtopic.php?pid=419103 ) should work. –  Matthieu Cartier Jan 22 '11 at 17:54
    
@neurolysis: openbox takes care of the virtual desktops: openbox.org/wiki/Help:Configuration#Desktops –  akira Jan 22 '11 at 18:21
add comment

2 Answers

try devilspie:

Devil's Pie can be configured to detect windows as they are created, and match the window to a set of rules. If the window matches the rules, it can perform a series of actions on that window. For example, I can make all windows created by X-Chat appear on all workspaces, and the main Gkrellm1 window does not appear in the pager or task list.
share|improve this answer
    
I want start two the same applications with the same windows (e.g. two gnome-terminals) on different desktops. openbox itself can place windows matched by window and class name to a desktop. –  Vi. Jan 22 '11 at 23:43
    
First thought: modify the script to list windows before and after starting the command, then diff them, and if there's only one line different, grab the window id for that line. Or: modify the script to try matching the window name with the first word of the command line passed to start_on_desktop. –  Mikel Jan 23 '11 at 6:13
    
@Mikel: has your comment something to do with my answer? –  akira Jan 25 '11 at 14:48
    
@Vi. With gnome-terminal, at least, one can give devilspie something to grab onto with the gnome-terminal option --window-with-role. –  Darael Mar 3 '13 at 15:46
add comment

Here's a first pass at a script to do it using wmctrl.

Works for me with Metacity, and should work in Openbox because it's also EWMH compliant.

Relies on GNU sleep. If you don't have that, change tries to 10 and sleeptime to 1.

start_on_desktop

#!/bin/sh

if test $# -lt 2
then
    echo "Usage: start_on_desktop <desktop> <command> [<command args>...]" 1>&2
    exit 2
fi

desktop=$1
shift
"$@"&
pid=$!
tries=100
sleeptime=0.1
while test $tries -gt 0
do
    sleep $sleeptime
    windows=$(wmctrl -l -p)
    while read _id _desktop _pid _rest
    do
        _ppid=$(ps -o ppid= -p $_pid)
        if test "$_pid" = "$pid" -o "$_ppid" = "$pid"
        then
            id=$_id
            break 2
        fi
    done <<EOF
$windows
EOF
    tries=$((tries - 1))
done
if test -n "$id"
then
    wmctrl -i -r "$id" -t "$desktop"
    exit $?
else
    echo "Window not found" 1>&2
    exit 1
fi

And here's a script to find out the current desktop.

current_desktop

#!/bin/sh

desktops=$(wmctrl -d)
while read id stat rest
do
    if test "$stat" = "*"
    then
        echo $id
        exit 0
    fi
done <<EOF
$desktops
EOF
echo "Cannot determine current desktop" 1>&2
exit 1

You could use it like this to move any application that takes a long time to start back to the desktop where you started it:

start_on_desktop $(current_desktop) <firefox or eclipse or whatever>

I guess you would put your four start_on_desktop lines in .Xclients or .xsession.

share|improve this answer
    
wmctrl -l -p is often like 0x03000012 2 0 N/A 0.5.2 svn for programs I want to run using that script. –  Vi. Jan 23 '11 at 3:51
    
And, for example, GVim reports just invalid PID. –  Vi. Jan 23 '11 at 3:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.