Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have setup 3x3 workspace switcher, and I want to position in the center one by default. Is it possible?

share|improve this question

5 Answers 5

up vote 7 down vote accepted

Thanks to Marco, I have figured out a way using wmctrl.

Because compiz workspaces are actually viewport of a single desktop, so the solution is to move the current viewport to cover the center region of the desktop.

First, call wmctrl -d to get the information of current desktop:

read desktop_id _ast \
    DG_ geometry \
    VP_ viewport \
    WA_ wa_off wa_size \
    title \
    < <(LANG=C wmctrl -d | grep '*')

geom_w=${geometry%x*}
geom_h=${geometry#*x}

# The workarea size isn't accurate, because the top/bottom panel is excluded. 
viewport_w=${wa_size%x*}
viewport_h=${wa_size#*x}

rows=$((geom_w / viewport_w))
cols=$((geom_h / viewport_h))

# Fix the viewport size
viewport_w=$((geom_w / rows))
viewport_h=$((geom_h / cols))

Then, calculate the origin of the center viewport:

center_row=$((rows / 2))
center_col=$((cols / 2))

center_x=$((center_col * viewport_w))
center_y=$((center_row * viewport_h))

center_viewport=$center_x,$center_y

And move the viewport there:

wmctrl -o $center_viewport
share|improve this answer

Yes: install wmctrl Install wmctrl and create a file in ~/.config/autostart/wmctrl.desktop with the following:

[Desktop Entry]
Name=Desktop Switcher
Exec=/usr/bin/wmctrl -s 4
Type=Application
share|improve this answer
1  
There's only one desktop in compiz. But wmctrl can switch viewport within the desktop anyway. See my answer below. –  Xiè Jìléi Jan 7 '11 at 8:53
  1. First download this helper script alt text for controlling compiz from the command line. Save it as compiz-send.py in your home folder.
  2. Run the command python compiz-send.py vpswitch switch_to_5_key to make sure it works correctly. It should switch you to the center workspace.
  3. If it works, create a file called .switch_to_center_workspace.sh in your home folder and paste the following inside of it:

    #!/bin/bash
    sleep 5 && python /home/user/compiz-send.py vpswitch switch_to_5_key
    

    replacing user with your username.

  4. Open up Startup Applications, System -> Preferences -> Startup Applications.

  5. Click Add and in the Command: entry put /home/user/.switch_to_center_workspace.sh. Put whatever you want in the Name: and Comment: entries.

  6. Log out and log back in and verify that it works.

share|improve this answer
    
Unfortunately the script doesn't work dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method "activate" with signature "si" on interface "org.freedesktop.compiz" doesn't exist –  Xiè Jìléi Jan 7 '11 at 6:16
    
@谢继雷 Change the sleep 5 part of the script to a higher number like sleep 10 to make sure compiz is already running when the script is run. You are using compiz right? –  Alvin Row Jan 7 '11 at 6:20
    
I try to run the script in gnome-terminal, and get the exception. I'm using compiz 0.8.6. –  Xiè Jìléi Jan 7 '11 at 6:37
    
In the script, it's said the method signature "si" doesn't exist, so I guess the arguments (string, int) passed to activate() may not correct.. –  Xiè Jìléi Jan 7 '11 at 6:44

I was going to ask the similar question, but for 3 horizontal workspaces and I'm also running compiz, and the wmctrl -d output(per workspace) looks like this:

  • At Workspace 1: 0 * DG: 4098x768 VP: 0,0 WA: 0,24 1366x744 Workspace 1
  • At Workspace 2: 0 * DG: 4098x768 VP: 1366,0 WA: 0,24 1366x744 Workspace 1
  • At Workspace 3: 0 * DG: 4098x768 VP: 2732,0 WA: 0,24 1366x744 Workspace 1

Than I simply used wmctrl -o 1366,0 (VP values) to make the center as my default workspace at startup. Might not work for everyone, but just in case ;)

Thanks.

p.s. sorry for posting this as another answer, I'd rather add comment to one of existent answers, but not yet gained reputation :)

share|improve this answer
    
The command I'm using in "System -> Preferences -> Startup Applications": sh -c "sleep 2;/usr/bin/wmctrl -o 1366,0 –  wik Feb 20 '11 at 9:45
    
...you might need to adjust sleep value, e.g. try 10, 15, etc. –  wik Feb 21 '11 at 8:06
    
Thanks for this note - sorry I didn't read it before reading your answer :) –  sdaau Mar 27 '11 at 18:06

Just a brief note - I'm using Natty, and thanks to @谢继雷's answer, I noticed that the following is reported by moving the terminal in each of the four 'workspaces' in Unity:

$ wmctrl -d
# top left
0  * DG: 2048x1200  VP: 0,0  WA: 0,24 1024x576  Workspace 1
# bottom left
0  * DG: 2048x1200  VP: 0,600  WA: 0,24 1024x576  Workspace 1
# top right
0  * DG: 2048x1200  VP: 1024,0  WA: 0,24 1024x576  Workspace 1
# bottom right 
0  * DG: 2048x1200  VP: 1024,600  WA: 0,24 1024x576  Workspace 1

... i.e. they are not neither separate desktops, nor workspaces - simply the viewport changes!

So, to change between those four viewports, simply call the wmctrl -o command directly with the VP values listed above, i.e.:

wmctrl -o 0,0
wmctrl -o 0,600
wmctrl -o 1024,0
wmctrl -o 1024,600

EDIT: Ups, sorry, just saw this is the same as @wik's answer - merge/delete as appropriate..

share|improve this answer

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.