Quickly hide and call out the terminal

There are several drop-down terminal emulators, common ones include Yakuake, Guake, Tilda, etc., which has an obvious advantage. You can use the hotkey (mostly press F12 by default) to call out the window when you are using it. Hide the window.

If this is your first contact, you will probably be a little shocked inside, as if it is a breath of fresh air in the terminal world. In fact, the core here is to be able to recruit, to fight, and to return to camp after the battle. This is how our party directs the army. It is not a big problem to drink, paddle, and eat at ordinary times. When a big scene comes, we have to attack with a hammer at the speed of light.

Search for information on the Internet. This quick call-out interface is inspired by the QUAKE game. When playing the game, press the hotkey to pop up the configuration interface, so it is often also called quake-style, quake-mode, quake-like. I have never played quake, cs I should have played the game before, so I think that’s pretty much what it means.

I have said a lot off topic. Now using the alacrity terminal, how can I achieve similar functions in the labwc window environment, or in the Wayland compositor?

Here's how I went about it:

1. Quick hide

Most window managers can hide/minimize windows, such as Gnome's Super+H. Because I mostly used Gnome environment in the past, I also set the same setting under the labwc window manager (press Win on the keyboard key + h).

1<keybind key="W-h">
2     <action name="Iconify" />
3</keybind>

labwc -r After re-reading the configuration, the active window can be hidden at any time, and natural terminal software is no exception.

2. Quick call

Quickly exhaling is effectively equivalent to pulling it out. Anyway, it just pops up the interface for people to use. Maybe the pull-down method is more eye-catching and the style is slightly higher. As a pragmatist, I don't really care.

Quickly calling out the window manager is to refocus the foreground. In the wayland environment, I found a command line tool wlrctl, which implements the wlr-foreign-toplevel-management protocol, which is quite interesting.

  • Can call the soft keyboard for typing
1➜ ~ wlrctl keyboard type 'Hello, world!'
2➜ ~Hello, world!
  • Control cursor movement

For example, continuously control the cursor to move 50 pixels to the right and 70 pixels upward.

1➜ ~ wlrctl pointer move 50 -70
2➜ ~ wlrctl pointer move 50 -70
3➜ ~ wlrctl pointer move 50 -70
4➜ ~
  • Focus on Software

This is what we focus on this time. Let’s look at the labwc configuration:

1<keybind key="W-Return">
2<action>
3     <name>Execute</name>
4     <command>sh -c 'wlrctl window focus Alacritty || alacritty'</command>
5</action>
6</keybind>

The key point is this wlrctl window focus Alacritty || alacritty, which means that if Alcaritty is running, focus directly switches to the foreground (focus). If it is not running, start it directly.

In this way, regardless of whether Alacritty is running or not, you can call out the terminal through the Win + Return shortcut key.

Some readers may wonder why the first letter of Alacritty is capitalized for one moment and lowercase for another.

This depends on the wlrctl manual:

focus [matches...]

Instruct the compositor to focus matching windows.

A match is a colon separated attribute/value pair. e.g. To match a firefox window, a suitable match value is app_id:firefox. You may give any number of match specifiers, and a window must match all of them to be considered. If the app_id or title keys are specified more than once, a window may match any of the given values. Otherwise later key value pairs override previous ones. A match without a key is assumed to be an app_id, so just firefox works in the example above.

Currently supported attributes are: app_id, title, and state.

Because app_id is recognized as Alacritty when the terminal is running:

 1➜ ~ ps -ef |grep -i alacritty
 2mephisto 35359 1 0 11:32 ? 00:00:00 sh -c wlrctl window focus Alacritty || alacritty
 3mephisto 35361 35359 0 11:32 ? 00:00:50 alacritty
 4mephisto 58501 23717 0 15:20 pts/7 00:00:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir= .hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox -i alacritty
 5➜ ~ wlrctl window focus Alacritty
 6➜ ~ echo $?
 70
 8➜ ~ wlrctl window focus alacritty
 9➜ ~ echo $?
101
11➜ ~

Matching can only be achieved when the first letter is capitalized, and 0 is returned. If the real terminal program is not running, || returns false in front of it, and directly runs alacritty to start the terminal.

After such operations, you can quickly hide/call out the terminal (corresponding to win + h/win + return respectively), as shown in the following animation:

quake-like alacritty

The tool for recording screen and making gif is not very good, the picture is a bit blurry, please forgive me, but you can clearly see the continuous switching.

Some readers may be used to using one key to hide/call out, so they have to find a way to use an intermediate variable to save the state. Each key press triggers a reversal and a Boolean value switch.

Personally, I don't think it's necessary. win + h can hide any window. It's a convention and it's almost muscle memory.

win + return calling out is the default behavior of the window manager labwc.

Call out when you want to use it, hide it when not in use, shrink it to the status bar, and change the matching software. In theory, you can switch to any software freely. The terminal is a high-frequency software. I am very satisfied with this configuration 😄.

Lastmod: Tuesday, December 5, 2023

See Also:

Translations: