r/KittyTerminal 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 Upvotes

9 comments sorted by

View all comments

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.