4

I am not happy with the current state of switching between application windows.

Imagine I have tree terminal windows with these titles:

  1. local
  2. root@localhost
  3. user@remotehost

Switching between these three terminals with ALT+TAB is no fun.

I am a fast ten fingers touch typer.

I search a way of switching directly to a window. I don't want to burden my eyes with looking at a list and choosing one entry.

Example: If I want to switch to the terminal with the title user@remotehost, I just want to type some magic key and then "user" and not more. Like all those nice auto complete inputs we see today.

I want to keep the default window manger which comes with ubuntu.

I know that there are some very special window manager which could do this. But I want to use the default window manager and maybe some extension plugin.

8
  • Does your question only concern windows of one application, or "cross" applications? (Would be easyer) – Jacob Vlijm Aug 12 '15 at 17:34
  • 1
    @JacobVlijm my concern is crossing windows of several applications. I want to switch the same way between gimp, inkscape or thunderbird. – guettli Aug 12 '15 at 18:08
  • 1
    If I understand well, you want to switch windows by typing (part of) the window name, am I correct? – Jacob Vlijm Aug 12 '15 at 18:09
  • @JacobVlijm yes, I want to type the title of the windoe to get to the window I want. – guettli Aug 12 '15 at 18:39
  • I assume by “the default window manager” you mean Unity? – Chriki Aug 12 '15 at 19:42
2

Given the recent demise of Unity desktop, another option for non-Unity desktops (such as the new default Gnome*) is to use the app launcher Kupfer, which has a plugin Window list, that allows to switch between windows by typing their name. I just tested with two terminal windows opened in different folders and it worked as expected by the OP.

enter image description here

Given that Kupfer has many more feature than just this, if you plan to use it only for switching between windows, I recommend turning off all the other unwanted plugins, so that Window list results end up on top and are usable directly.

*note - Gnome has some limited functionality for switching to opened window by typing. In the activities overview (opened by e.g. the Super key) you can type e.g. Terminal to switch to already opened terminal. However as of version 3.18 (which is used as default on my 16.04 LTS box) you can't differentiate between different windows of the same app. EDIT: You can even switch to particular windows by typing, but it's not as convenient as in Unity, because it also shows all other results above the window list, so you have to move down with arrows a lot.

0
5

In Unity since 14.04 you can hit Super+W (window spread) and then type-to-search for a window by it's name or name of the program.

4
  • OK. Just one thing: window spread has existed much earlier than that. I've used it in 13.04. – Sergiy Kolodyazhnyy Aug 12 '15 at 22:39
  • Great! I had this question on my mind for a long time. I just never asked. This was a mistake. Thank you! – guettli Aug 13 '15 at 5:15
  • +1 Nice one! I didn't know it worked by typing as well :) – Jacob Vlijm Aug 13 '15 at 5:23
  • @Serg Yes but the type-to-search function was added in 14.04 – jena Aug 21 '15 at 19:05
3

If you are not using Unity...

If you are using Unity, definitely use jan's answer. This one could be an alternative for other window managers.


The script below should do pretty much exactly as you describe:

  • Press a key combination
  • Type one or more characters of the window name
  • Press Return

    enter image description here

    and the corresponding window appears:

    enter image description here

The script

#!/usr/bin/env python3
import subprocess
import socket

machine_name = socket.gethostname()

get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")

w_list = get("wmctrl -l").splitlines()
w_data = [(w.split()[0], w[w.find(machine_name)+len(machine_name)+1:])for w in w_list]     
windows = [it[1] for it in w_data if "_NET_WM_WINDOW_TYPE_NORMAL" in get("xprop -id "+it[0])]
l = "'"+("' '").join(windows)+"'"
cmd = "zenity --list --title='Window chooser' --column='Type one or more characters' "+l
try:
    window = get(cmd).split("|")[-1].strip()
    w_id = [item[0] for item in w_data if window in item[1]][0]
    subprocess.Popen(["wmctrl", "-ia", w_id])
except:
    pass

How to use

  • The script needs wmctrlto be installed:

    sudo apt-get install wmctrl
    

Then:

  • Copy the script into an empty file, save it as window_switcher.py
  • Test- run it by the command:

    python3 /path/to/window_switcher.py
    
  • If all works fine, add it to a shortcut key: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    python3 /path/to/window_switcher.py
    
1
  • 1
    Great script, simple and great. An improvement would be to find the desired window to focus using regular expression – Diogo Sep 22 '17 at 0:32
1

create a shortkey with wmctrl and bind it to a keyboard shortcut

eg wmctrl -a 'Chromium' to switch to a window that has a name chromium in it

  • If you know the full name of the window, you can use

wmctrl -Fa 'Terminal - 12'

  • to list window names

wmctrl -l

2
  • How can this help OP to switch between multiple windows of the same application? Note the example OP provided. – jena Dec 11 '19 at 11:14
  • you can set a hot key to run these commands. Takes a bit of effort to set everything up but I think it gives you the most flexibility since you can set any buttons to activate any specific window. – Nic Wanavit Dec 11 '19 at 16:38
0

The utility "rofi" allows to display a list of open windows, which can be narrowed down by typing parts of the name of the application and/or window title.

rofi can be installed with the command sudo apt install rofi.

Launch rofi in "window" mode with the command

rofi -show window

Bind this command to a hotkey.

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.