Position at central workspace on login

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

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