[Sugar-devel] Alt-Tab in Sugar

Sascha Silbe sascha-ml-reply-to-2011-4 at silbe.org
Tue Oct 25 07:49:32 EDT 2011


Excerpts from Sebastian Silva's message of 2011-10-25 04:15:29 +0200:

> But Sugar will instead continue along the X-order so to say of the Frame.
> Could we change this default?
> Also, is there a setting for this in metacity or does Sugar have its own 
> Alt-Tab
> implementation?

I should really start writing my "Sugar Hacks" series. The window
managing tweaks are exactly what I've been planning for the first post.

Alt-Tab is handled by Sugar by default, with the behaviour you describe
(and since it needs to show the Frame, it's quite slow). Fortunately
Sugar waits for metacity to start up before installing the key handlers,
so you can tell metacity to handle Alt-Tab instead. Or rather you can
hack Sugar to not tell metacity to disable the keys:

diff --git i/bin/sugar-session w/bin/sugar-session
index 8ea195f..7db9610 100755
--- i/bin/sugar-session
+++ w/bin/sugar-session
@@ -177,9 +177,10 @@ def setup_window_manager():
     if subprocess.call('echo $DISPLAY; xsetroot -cursor_name left_ptr',
shell=True):
         logging.warning('Can not reset cursor')
 
-    if subprocess.call('metacity-message disable-keybindings',
-            shell=True):
-        logging.warning('Can not disable metacity keybindings')
+# local hack: We _do_ want metacity to handle Alt-Tab etc.
+#    if subprocess.call('metacity-message disable-keybindings',
+#            shell=True):
+#        logging.warning('Can not disable metacity keybindings')
 
 def bootstrap():
     setup_window_manager()


Since I'm hacking a lot on Sugar with testing on several branches and
having to cherry-pick this commit each time is a PITA, I've chosen a
slightly different, more quick&dirty-style approach myself. It works
because my configured metacity key bindings don't clash with Sugar.

This is what my .xsession looks like:

exec ~/sugar-jhbuild/sugar-jhbuild run dbus-launch --exit-with-session \
     --config-file="$HOME"/.sugar/default/dbus-session.conf bash -c '
  echo "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" > ~/.sugar/dbus-session-bus-address.sh
#  ~/sugar-jhbuild/source/datastore-fuse/datastore-fuse.py ~/datastore
  while true ; do
    ( sleep 5 ; metacity-message enable-keybindings ) &
    ( sleep 10 ; metacity-message enable-keybindings ) &
    ( sleep 20 ; metacity-message enable-keybindings ) &
    ( sleep 30 ; metacity-message enable-keybindings ) &
#  exec notion
    sugar --scaling 100
  done
#  fusermount -u ~/datastore
'

You can ignore the first few lines; their purpose is just to run
everything within sugar-jhbuild (so I can run Sugar natively rather than
having to use sugar-emulator) and to save the session bus address to
some place my profile scripts can read it (this enables me to use
copy-to-journal via ssh from another box).

The interesting pieces are the metacity-message invocations. You'll
notice two things:

1. It's the exact opposite (enable-keybindings) to what Sugar is doing
   (disable-keybindings).
2. Since we don't know exactly when Sugar is invoking metacity-message
   (and Sugar doesn't provide any hooks), we need to try it several
   times. The last line alone would suffice in theory, but then I (as a
   user) would always need to wait that long after restarting Sugar
   before I can use the window manager keys (restarting is much faster
   than first start on boot).


The while loop in .xsession is very useful when hacking on Sugar since
it will restart just Sugar and keep everything else (e.g. text editor
with Sugar sources) running.

As mentioned above my metacity key binding configuration is different
from the default so it doesn't clash with Sugar. In fact it derives from
my custom ion3 / notion key binding scheme, which is to use combinations
with the Win (for window manager ;) ) key (Grab key on XOs - there's
still an interaction problem with olpc-kbdshim that I need to fix).
Since notion has 2D navigation across frames (tiles), the cursor keys
are a natural fit for changing between them. Similarly, I'm using
<Win>+<Ctrl>+<Cursor Left/Right> to switch between windows in a frame.
Since metacity doesn't support tiling and Sugar runs everything
full-screen, I'm using <Win>+<Cursor Left/Right> to navigate the windows
in metacity:

gconftool-2 -s --type string /apps/metacity/global_keybindings/cycle_windows '<Mod4>Right'
gconftool-2 -s --type string /apps/metacity/global_keybindings/cycle_windows_backward '<Mod4>Left'

On XOs with their tiny screen the next key binding for temporarily
making "legacy" windows like xterm fullscreen (especially disabling
window decorations) is very useful:

gconftool-2 -s --type string /apps/metacity/window_keybindings/toggle_fullscreen '<Mod4>Return'

Fast access to xterm and screen locking:

gconftool-2 -s --type string /apps/metacity/global_keybindings/run_command_1 '<Mod4>t'
gconftool-2 -s --type string /apps/metacity/keybinding_commands/command_1 'xterm -maximized'
gconftool-2 -s --type string /apps/metacity/global_keybindings/run_command_2 '<Mod4>l'
gconftool-2 -s --type string /apps/metacity/keybinding_commands/command_2 'sh -c "sleep 1 ; xtrlock"'

HTH,
Sascha

-- 
http://sascha.silbe.org/
http://www.infra-silbe.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 665 bytes
Desc: not available
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20111025/f2c08d62/attachment.pgp>


More information about the Sugar-devel mailing list