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
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
-
1There's only one desktop in compiz. But
wmctrl
can switch viewport within the desktop anyway. See my answer below.– LenikJan 7, 2011 at 8:53
- First download this helper script for controlling compiz from the command line. Save it as
compiz-send.py
in your home folder. - 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. 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.Open up Startup Applications, System -> Preferences -> Startup Applications.
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.Log out and log back in and verify that it works.
-
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
– LenikJan 7, 2011 at 6:16 -
@谢继雷 Change the
sleep 5
part of the script to a higher number likesleep 10
to make sure compiz is already running when the script is run. You are using compiz right?– IsaiahJan 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.– LenikJan 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..– LenikJan 7, 2011 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 ;)
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..