User Tools

Site Tools


metacity-tabs

metacity tabs

This page describes how to set up keybindings, so you can switch to the nth window on the current desktop. It's been tested with the metacity window manager, but may work with lots of others. It uses wmctrl to communicate with the window manager. To switch to the next/previous window, you'll also need to install xdotool.

For example, you could map Super-1 (hold down the Super key and press the 1 key) to go to the first window on the current desktop/workspace.

First the script:

   #!/bin/bash
   
   # this script is designed to be activated by keyboard shortcuts.
   #
   # If you have wmctrl installed you can:
   #
   #         pass 1 to activate (bring to front and focus) the first window in the
   #         current workspace (or 2 for the 2nd, 3 for the 3rd, etc)
   #
   #
   # If you have wmctrl and xdotool installed you can:
   #
   #         pass +1 to activate the next window in the current workspace, or -1
   #         for the previous window
   
   current_workspace="$(wmctrl -d | sed -n 's/ *[*].*//p')"
   windows_in_current_workspace="$(wmctrl -l | sed -n "s/\(0x........\) *$current_workspace .*/\1/p")"
   
   if test "$1" = "-1"
   then
        current_window_id="$(printf '0x%08x' $(xdotool getactivewindow))"
        activate="$(echo "$windows_in_current_workspace" | grep -B 1 "$current_window_id" | head -n 1)"
   elif test "$1" = "+1"
   then
        current_window_id="$(printf '0x%08x' $(xdotool getactivewindow))"
        activate="$(echo "$windows_in_current_workspace" | grep -A 1 "$current_window_id" | tail -n 1)"
   else
        activate="$(echo "$windows_in_current_workspace" | head -n $1 |  tail -n 1)"
   fi
   
   wmctrl -i -a "$activate"

In the examples below, I've got that script called activate-nth-window. The first (and only) argument is which window you want. Pass 1 for the first window, 2 for the 2nd, etc.. Now you can set up keybindings. One way to achieve this is with xbindkeys. It should work with most window managers. You'll need to have ~/.xbindkeysrc with something like this in it:

  "activate-nth-window -1"
    mod4+j
  
  "activate-nth-window +1"
    mod4+l
  
  "activate-nth-window 1"
    mod4+1
  
  "activate-nth-window 2"
    mod4+2
  
  "activate-nth-window 3"
    mod4+3
  
  "activate-nth-window 4"
    mod4+4
  
  "activate-nth-window 5"
    mod4+5
  
  "activate-nth-window 6"
    mod4+6
  
  "activate-nth-window 7"
    mod4+7
  
  "activate-nth-window 8"
    mod4+8
  
  "activate-nth-window 9"
    mod4+9
  
  "activate-nth-window 10"
    mod4+0

Then just run xbindkeys and test it out!

metacity-tabs.txt · Last modified: 2016/08/31 14:10 (external edit)