Skip to content

Instantly share code, notes, and snippets.

@fl42v
Last active June 21, 2024 09:49
Show Gist options
  • Select an option

  • Save fl42v/dd22afbf4345eced2964b69fe4a1b2c3 to your computer and use it in GitHub Desktop.

Select an option

Save fl42v/dd22afbf4345eced2964b69fe4a1b2c3 to your computer and use it in GitHub Desktop.
Wezterm + cosmic-comp "window swallowing"

What

Hide wezterm window while some (usually gui) app runs and show after that.

Reqs

  • Wezterm (well, duh)
  • A window manager that processes minimization requests (probably). Works in cosmic-comp ootb, doesn't work in qtile (can probably be done with some configuration, tho)

Wezterm config

  wezterm.on('user-var-changed', function(window, pane, name, value)
    -- to see the logs use wezterm blocking-start
    -- to set a var use 
    -- ` bash -c "printf '\\033]1337;SetUserVar=$(basename "name")=$(echo value | base64)\\007'; sleep 0.1" `
    wezterm.log_info('var', name, value)

    -- "window swallowing"
    if name == 'whide' then
      window:perform_action(
        wezterm.action.Hide,
        pane
      )
    elseif name == 'wshow' then
      wezterm.log_info("here")
      window:maximize()
      window:restore()
      -- some unsuccessful (as in they don't restore the window) attempts. May work in other wm-s/de-s, tho.
      --window:perform_action(
      --  -- wezterm.action.Show,
      --  wezterm.action.SetWindowLevel 'AlwaysOnTop',
      --  pane
      --)
    end
  end)

Shell aliases

In case of fish, I made the following functions:

  • setUserVar:
      function setUserVar
          bash -c "printf '\\033]1337;SetUserVar=$(basename $argv[1])=$(echo $argv[2] | base64)\\007'; sleep 0.1"
      end
  • swallow:
      function swallow
        setUserVar whide
        eval $argv
        # save the exit status to be returned later
        # since neither does setUserVar fail like ever,
        # nor we need its exit code
        set -l res $status
        setUserVar wshow
        return $res
      end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment