11

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.

7

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

5

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)
  • Dear @Glutanimate, after -l also switches to windows on other workspaces. – Kadir Aug 30 '14 at 3:58
  • @Kadir That's strange. It doesn't on my system. If you have some time, would you be willing to post the output of wmctrl -xl to a site like pastebin.com and link it here? – Glutanimate Aug 30 '14 at 4:11
  • Dear @Glutanimate, here it is: pastebin.com/iJBAZ5a7 – Kadir Aug 30 '14 at 4:22
  • @Kadir Thanks! Looks like Unity/Compiz isn't exposing the workspace information properly so wmctrl has trouble picking it up (that's why you only see zeroes in the second column, those should be the workspace numbers). No idea if that's a bug or if it was designed that way. I didn't notice this because I was using LXDE. I'll add a note to the answer. – Glutanimate Aug 30 '14 at 5:05
4

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

  • I want to preserve Alt-`'s property, which is switching between an application's windows in the current viewport. I need another shortcut like Ctrl-Alt-`, which will switch between an application's windows in all of the viewports. – Kadir Aug 28 '14 at 12:46
  • 1
    @Kadir Unfortunately, the dconf property won't allow both config to coexist. It's one behaviour or the other. – Sylvain Pineau Aug 28 '14 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.