Liupold / pidswallow

A swallower script using process hierarchy.
Apache License 2.0
43 stars 0 forks source link
bspwm de gnome herbstluftwm i3wm kde openbox plasma plasma5 process pstree swallowing terminal toggle window wm wms xdo xdotoo xdotool

A stupid simple swallower 😉.

(Based on Process hierarchy)

Super easy to config. Uses xdo WM/DE independent.

PKGBUILD-STATUS SHELLCHECK-STATUS license

Features

pidswallow (pid swallow WM/DE independent)
Hides terminal window automatically, so that you don't have to

pidswallow [OPTION ...]

OPTIONS:
        -h  --help              Show this message
        -s  --swallow <CWID>    Hides parent window of the given child window id.
        -v  --vomit <CWID>      Unhides parent window of the given child window id.
        -t  --toggle <CWID>     toggle between swallow and vomit. (default)
        -g  --glue              treat if parent and child window are same. (recommended)
        -l  --loop              listen and hide / unhide window on launch / remove.
        -V  --verbose           Shows useful information.

bugs/issues: https://github.com/liupold/pidswallow.
Benchmark #1: pidswallow -s 0x02A00003
  Time (mean ± σ):      28.0 ms ±   4.3 ms    [User: 13.8 ms, System: 18.0 ms]
  Range (min … max):    24.1 ms …  48.0 ms    74 runs

Demo

Demo

How it works

takes wid as as arg --> gets process tree --> check blacklist --> hide parent.

Dependencies

1) xdo 2) xprop (--loop and --glue). 3) xev (--glue). 4) xdotool (cross-workspace --glue, optional).

Installation

Using AUR

yay -S pidswallow

Autostart

1) Launch when WM/DE starts (Example: .xinitrc, i3-config, bspwrc)

pgrep -fl 'pidswallow -gl' || pidswallow -gl

2) Add the following to your bashrc, zshrc or shell init script. This step isn't strictly necessary, but it fixes problems with daemon-based terminals and also improves the performance of pidswallow. Note: You might want to skip this step if you use Alacritty (see Known Issues). Note: Your window manager has to focus new terminals as soon as they are spawned for this to work correctly.

[ -n "$DISPLAY" ]  && command -v xdo >/dev/null 2>&1 && xdo id > /tmp/term-wid-"$$"
trap "( rm -f /tmp/term-wid-"$$" )" EXIT HUP

3) Restart wm and terminals.

Additional Configuration

Environment variables can be exported to change the behavior of pidswallow.

The following ones accept lists of space separated process names.

The ones following are executed in a subshell (/bin/sh) and support the special strings $pwid and $cwid, holding the parent and child window IDs, respectively.

Tested on

(If you did please let me know, If it dosent work create a issue).

Known Issues

Tricks

Manual swallow (toggle)

1) Add pidswallow to your path. 2) run this and click on the child window (not the term) to swallow.

 xwininfo | awk '/Window id:/{print $4}' | pidswallow -gt

3) or pass the window-id via keyboard shortcut. (Eg: sxhkd toggle).

super + v
    xdo id | pidswallow -gt

Launch a program from term wihout being swallowed.

setsid -f <command>  # this will not swallow the terminal.

WM specific recommendations.

bspwm

Add each set of lines to your bspwmrc, right before running pidswallow.

export PIDSWALLOW_SWALLOW_COMMAND='bspc node $pwid --flag hidden=on'
export PIDSWALLOW_VOMIT_COMMAND='bspc node $pwid --flag hidden=off'

This way bspwm will remember window positions and won't lose track of swallowed windows.

export PIDSWALLOW_PREGLUE_HOOK='bspc query -N -n $pwid.floating >/dev/null && bspc node $cwid --state floating'

Check if parent window state is floating and apply the same to the child if that's the case. This example should work in most cases, but feel free to add more complex hooks to your setup. (e.g. to mimic more properties of the parent).