I was initially using Yakuake, a drop-down terminal emulator based on KDE. One of the features I particularly enjoyed was the ability to press F12 to quickly show or hide the terminal. This was a convenient feature as it allowed me to quickly access the terminal, run a command, and then hide it again, all without needing to switch windows or use the mouse. However, for reasons of my own, I decided to switch to Kitty terminal. After switching to Kitty, I found that I missed the F12 show/hide feature from Yakuake. As a KDE user, I was used to this feature and found it inconvenient to use Kitty without it. So, I decided to implement a tool to do that.
This is a C program that finds, lists, and toggles visibility of windows based on their class name. It also has the ability to start a new process if a window of the specified class is not found.
It works on both X11 and Wayland (KDE Plasma / KWin):
- On X11 it walks the window tree with Xlib and maps/unmaps the window directly.
- On Wayland (detected via
WAYLAND_DISPLAY) native windows are invisible to X11, so it instead runs a small script inside the compositor over KWin's DBus scripting interface. The script matches windows byresourceClass/resourceName, toggles theirminimizedstate (hide if any is shown, otherwise show and activate), and reports the match count back so the tool knows whether to launch the process. If the KWin interface is unavailable it falls back to the X11 path.
Because the toggled window is an ordinary window (just minimized/restored), it keeps normal keyboard focus — unlike layer-shell drop-downs, which on KWin can leak key events to background windows.
- Find Window: The program can find a window by its class name in the X11 window system.
- List Windows: The program can list all windows along with their class names.
- Toggle Window: The program can toggle the visibility of a window (hide if it's visible, show if it's hidden).
- Start Process: If a window of the specified class is not found, the program can start a new process.
The program is run from the command line with the following syntax:
windowToggler <window_class> [<path_to_process> [process_args...]]
<window_class>: The class name of the window to find and toggle. Use "list" to list all windows.<path_to_process>: (Optional) The path to the process to start if a window of the specified class is not found.process_args: (Optional) Any arguments to pass to the process being started.
To toggle a window with the class name "kitty" and start Kitty if it's not already running, you would use:
./windowToggler kitty kitty --single-instance --detach
To toggle a Slack and start if it's not already running, you would use:
./windowToggler Slack slack
Steps to Create a Custom Global Shortcut Using Krunner Open System Settings:
- Access System Settings from the application launcher or by searching for it.
Navigate to Shortcuts:
- Go to "Shortcuts" in the System Settings window. Create a Custom Shortcut:
- Select "Custom Shortcuts" from the left sidebar.
- Click the "+" button at the bottom and choose "Global Shortcut" -> "Command/URL". Configure the Shortcut:
- In the "Trigger" tab, set your desired hotkey by clicking on "None" and pressing the key combination you want to use.
- In the "Action" tab, set the Command/URL to the following:
-
~/path/to/windowToggler kitty kitty --single-instance --detach
- X11 development package —
libx11-devon Debian-based systems. - D-Bus development package (for the Wayland/KWin path) —
libdbus-1-devon Debian-based systems.
make # builds ./windowToggler
make install # installs to $PREFIX/bin (PREFIX defaults to ~/.local)
Or directly with gcc:
gcc -O2 -o windowToggler main.c $(pkg-config --cflags --libs x11 dbus-1)
Intended for Unix-like systems. Tested on X11 and on KDE Plasma 6 (KWin) Wayland. The Wayland path is KWin-specific; other Wayland compositors (Hyprland, Sway, GNOME) are not supported and fall back to the X11 path.