Key combination to switch between an application's windows in all of viewports

Alt-` is used to switch between an application's windows in the current viewport in Unity.

Is there another key combination to switch between an application's windows in all of viewports?

I do not want to change default behaviour of Alt-`, which is switching between an application's windows in the current viewport.

I am using Ubuntu 14.04 and Unity.


Solution 1:

Inspired by Pineau's answer, I found a dirty trick to get it done: keep Alt+` for switching between application windows in one viewport, and (for example) Alt+1 to switch between application windows on all viewports.

Minor cosmetic downside is that the responsiveness is a little less accurate, since the settings need a fraction of a second to change. In Practice however, you will hardly notice.

  1. install xdotool:

    sudo apt-get install xdotool
    
  2. Copy the following scipt into an empty file and save it as switch.sh

    #!/bin/bash
    
    dconf write /org/compiz/profiles/unity/plugins/unityshell/alt-tab-bias-viewport false
    sleep 0.2
    xdotool keydown alt key 0x60
    dconf write /org/compiz/profiles/unity/plugins/unityshell/alt-tab-bias-viewport true
    sleep 1
    
  3. set a key combination to run the script: System Preferences > Keyboard > Shortcuts > Custom Shortcuts. I choose Alt+1, since it is close to the other one.

    Now you can use either Alt+1 to switch between all windows of (for example) gedit:

    enter image description here

    or Alt+` to switch between gedit windows of only the currect workspace:

    enter image description here

note:

  1. In the script, the key above the Tab is set to key 0x60. This might be different on other lauyouts. In case it won't work, run in a terminal xev, then press Return, then the key above tab. In the output, look for a string like (keysym 0x60, grave). The keysym value is the value you need in the (script-) line:

    xdotool keydown alt key 0x60
    
  2. The values of sleep 0.2 and sleep 1 make the script work fine on my system, but they might be subject to optimization for faster systems (reduce).

More options

Similarly, you can set a key combination to switch between all application windows on all viewports the script would then be:

#!/bin/bash

dconf write /org/compiz/profiles/unity/plugins/unityshell/alt-tab-bias-viewport false
sleep 0.2
xdotool keydown alt key 0xff09
dconf write /org/compiz/profiles/unity/plugins/unityshell/alt-tab-bias-viewport true
sleep 1

If you set for example Alt+Q for this, you have nice set of all options:

Alt+` Switch between current application's windows on current viewport

Alt+1 Switch between current application's windows on all viewports

Alt+Tab Switch between all application windows on current viewport

Alt+Q Switch between all application windows on all viewports

enter image description here

Alt+Tab : Switch between all application windows on current viewport

enter image description here

Alt+Q: Switch between all application windows on all viewports

Solution 2:

Generic solution using wmctrl


Overview

The following script should be compatible with all EWMH-compliant window managers (e.g. xfwm4, openbox, kwin, compiz...). It uses wmctrl and xprop, which can be installed with:

sudo apt-get install x11-utils wmctrl

Installation

Copy and save the following passage as simple-window-switcher:

#!/bin/bash

# based on a script by Robert Steiniger
# (http://lars.st0ne.at/blog/switch%20between%20windows%20within%20the%20same%20application)

Usage="
  Title:        simple-window-switcher 0.1
  Description:  switch between all windows of active application
  Author:       Copyright Glutanimate 2014 (https://github.com/Glutanimate)
  License:      GNU GPLv3
  Usage:        $(basename "$0") [-g|-l|-h]
                -g: global window switching (across all workspaces)
                -l: local window switching (current workspace)
                -h: display this help message

                If no argument is provided window switching will be set to global.
"

while getopts "lgh" OPTIONS; do
  case $OPTIONS in
    l ) Fields="3-4"
        ;;
    g ) Fields="4"
        ;;
    h ) echo "$Usage"
        exit 0
        ;;
   \? ) echo "$Usage"
        exit 1
        ;;
  esac
done

ActiveWinID="$(xprop -root | sed -n 's/_NET_ACTIVE_WINDOW(WINDOW): window id # 0x//p')"
# fields 3-4: <desktop number> <window class>
ActiveWinClass="$(wmctrl -xl | grep "$ActiveWinID" | cut -d" " -f${Fields})"
WindowList="$(wmctrl -xl | grep "$ActiveWinClass" | cut -d" " -f1)"
NextWindow="$(echo "$WindowList" | grep -A1 "$ActiveWinID" | sed -n 2p)"

if [[ -z "$NextWindow" ]]; then
  NextWindow="$(echo $WindowList | head -n 1)"
fi

wmctrl -i -a "$NextWindow"

Mark the script as executable and save it anywhere you please (preferably in your PATH, e.g. /usr/local/bin or ~/bin).

Usage

Use they keyboard shortcuts menu of your window manager to assign simple-window-switcher to a hotkey of your choice. You can use the following parameters to control how the script behaves:

  • -g: global window switching (across all workspaces)
  • -l: local window switching (current workspace); might not work with Unity/Compiz (see comment section for further information)

Solution 3:

Open a Terminal and type the following command:

dconf write /org/compiz/profiles/unity/plugins/unityshell/alt-tab-bias-viewport false

Alternatively you can install the Unity Tweak Tool:

sudo apt-get install unity-tweak-tool
unity-tweak-tool

Then enable the Switch between windows on all workspaces option in the Switcher Tab:

enter image description here