12

I have set up 3x3 workspace switcher, and I want my position to be on the central one by default. Is it possible?

5 Answers 5

7

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
6

Yes: install wmctrl

sudo apt-get 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
1
  • 1
    There's only one desktop in compiz. But wmctrl can switch viewport within the desktop anyway. See my answer below.
    – Lenik
    Jan 7, 2011 at 8:53
2
  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.

4
  • 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
    – Lenik
    Jan 7, 2011 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?
    – Isaiah
    Jan 7, 2011 at 6:20
  • I try to run the script in gnome-terminal, and get the exception. I'm using compiz 0.8.6.
    – Lenik
    Jan 7, 2011 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..
    – Lenik
    Jan 7, 2011 at 6:44
2

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 ;)

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

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..

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .