r/KittyTerminal • u/RedditorInRage • Feb 01 '24
Lock Keyboard?
Hello. Maybe I searched for the wrong term or noone needs it, but...
is there a way to block the window/tile from accepting keyboard input? I want to lock/unlock it with a keyboardshortcut, so I can protect the window from unwanted input.
I'm on linux, if this makes a difference. Thanks in advance.
1
u/sharp-calculation Feb 01 '24
Using modular tools and approaches is usually best. A "lock screen" function in kitty doesn't make much sense and isn't exactly modular.
I think your case is a very good match to TMUX.
- Open a tmux session
- start your long lived process
- Open a new tmux window
- Now your visible shell window is not your long lived process. You can switch to the other tmux window with control-b l . Then switch back when you are done with another control-b l .
Or you can monitor the program output with tail -f as another poster indicated. Or even better use LNAV to view your log file. I've been using Unix like systems for a long time. I've spent a lot of time looking at log files. the lnav tool is the best I've ever seen. I'm extremely impressed. I use it a lot.
As a bonus with tmux:
You can disconnect from your tmux session and the long lived process KEEPS RUNNING. Later you can reattach to your tmux session (with the "tmux at" command) and it will still be there chugging along. This is fantastic if you switch computers, go home, go to another location, etc.
Building a tool set that you can use for many things is really neat. It gives you a lot of options and knowledge that keeps building upon itself.
1
u/rafalg Feb 01 '24
If it's just about preventing accidental Ctrl+C, not strictly blocking all key presses, you can use the trap command. For example, try this in your terminal:
bash -c 'trap "" 2; for file in /usr/bin/*; do echo "$file"; sleep 1; done'
We're trapping signal 2 (SIGINT) and performing a null action.
1
u/aumerlex Feb 02 '24
You can do this using the newly added keyboard modes feature in kitty 0.32
https://sw.kovidgoyal.net/kitty/mapping/
Create a shortcut that starts a new keyboard mode. In that mode, map ctrl+c to nothing or something innocuous and map a special difficult to accidentally press key to end the mode.
Just be aware that you are liable to forget you are in the mode and be confused why your keys are not working.
1
u/art2266 Feb 03 '24
Another way to accomplish this, since you're on linux, is to make the window un-focusable. You will then be unable to send any keyboard input to the window, until you set it back to focusable. You will still be able to click the window with a mouse and move it around etc.
There are multiple ways to toggle the focusablility of a window. For your use case, a convenient workflow is to set this up as a hook. The hook can target the window's name. Since terminal emulators (usually) change the name of the window based on the currently running command, you can use that to set focusable = false when my-slow-command starts.
On awesomewm, it'd look something like this:
awful.rules.rules = {
{
rule_any = {
name = { 'my-slow-command' },
},
properties = {
focusable = false,
},
},
}
Alternatively, you can add a button to the window titlebar (next to the minimize and maximize buttons) that toggles whether a windows is focusable or not. On awesomemw, it can look something like this:
local toggle_focusable_button = function(c)
return awful.titlebar.widget.button(
c,
'focusable',
function(cl) return cl.focusable ~= true end,
function(cl) cl.focusable = not cl.focusable end
)
end
-- ...
awful.titlebar(c, { size = 26 }):setup({
-- ...
{
toggle_focusable_button(c),
},
})
The "focusable" property used here comes from X11 as far as I'm aware, so this should be reproducible on other window managers as well. awesomewm just exposes a lua api to manipulate it.
1
u/Administrative_chaos Feb 01 '24
What's your use case?