π

Switching Windows and Desktops According to Window Names and Text Search

Show Sidebar

Update 2024-02-07: remark on Wayland below.

Here is a neat little PIM improvement which has a great impact on my personal way on how to deal with Virtual Desktops and windows on my GNU/Linux systems. After using it for a few months, I do find this method brilliant and therefore, I need to blog about it.

Working with many application windows on different Virtual Desktops comes with a burden. In most setups, you have to manually switch desktop before you can see the corresponding windows and switch to them. However, in my usual work I know exactly to what window I'm going to jump to, independent of my current Virtual Desktop.

Same as with using a (local) search engine to "teleport" to a specific web site, computer file or start an application, I introduced myself to a method to teleport to any open window on my computer.

In combination with the Firefox add-on "window-titler", I may switch to arbitrary windows by simply invoking a custom keyboard combination, enter a search term (if it's unique with few letters, it's really quick), press Enter and my focus is switched to the Virtual Desktop and the window of choice.

When I enter "evo" I may jump to my Evolution email client. When I enter "ema" I jump to my Emacs. Entering "rc" jumps to my Firefox window thich I named "[rc]" using the add-on from above. You get the idea.

An example popup window when searching for "Untitled". (click for a larger version)

I rarely switch desktops or apps otherwise, since I've got that method in place. Few small PIM tricks have had such a great impact on my daily computer usage than this one.

My Current Implementation

Update 2024-02-07: My implementation mentioned below is only working with X.org and not with Wayland. See discussions like that. If you know how to implement the workflow on Wayland-based machines, please do write a comment!

For the implementation, I found inspiration from that web page. My method requires the following tools:

As soon as you understood the principle, you can think of alternative implementation using different tools, of course.

In my xfce environment, I create a new keyboard shortcut. System Settings → "Keyboard" → "Shortcuts" → "Custom Shortcuts". Click the "+" and add the command:

 rofi -monitor -2 -show window -kb-accept-alt 'Return' \
      -kb-accept-entry 'Shift+Return' \
      -window-command "/home/vk/src/misc/vk-switch-to-windowid.sh {window}"	  

The name and location of the mentioned shell script may vary.

My personal preference for the keyboard shortcut is mapped via my QMK keyboard firmware to LAYER + SPACE for opening the rofi search window.

The vk-switch-to-windowid.sh script is:

#!/bin/bash

WINID="${1}"

## switch to the virtual desktop of the chosen window and show the window:
/usr/bin/wmctrl -i -a "${WINID}"

## xfce window manager has a bug where the focus is not correct with "focus
## follows mouse":
##   https://github.com/davatorium/rofi/discussions/1585
##   https://www.reddit.com/r/qtools/comments/siksac/using_rofi_show_window_with_focus_follows_mouse/
##   https://gitlab.xfce.org/xfce/xfwm4/-/issues/224
## This is a workaround to fix that by placing the mouse:
/usr/bin/xdotool mousemove -window "${WINID}" 100 -20

#end	  

You don't need the xdotool workaround if you're not affected by the xfce/xfwm4 issue mentioned.

If you want to switch to a different look and feel for rofi, you might want to invoke rofi-theme-selector. I personally use the theme named "arthur" at the moment.

Have fun improving your PIM workflows!


Related articles that link to this one:

Comment via email (persistent) or via Disqus (ephemeral) comments below: