Cleanup bspwm support scripts
This commit is contained in:
parent
11155e2fe6
commit
91c7ebd467
3 changed files with 33 additions and 94 deletions
|
@ -117,7 +117,6 @@ bspc rule -a 'thunderbird' desktop='messenger' locked='true'
|
|||
|
||||
"$HOME/.config/polybar/launch.sh" &
|
||||
|
||||
#"$HOME/.config/bspwm/swallow.py" &
|
||||
"$HOME/.config/bspwm/focus-voip.py" &
|
||||
|
||||
feh --bg-fill "$XDG_PICTURES_DIR/wallpaper/active_wallpaper"
|
||||
|
|
33
.config/bspwm/focus-voip.py
Executable file
33
.config/bspwm/focus-voip.py
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import subprocess
|
||||
from functools import partial
|
||||
|
||||
|
||||
cmd_run = partial(subprocess.Popen, text=True, shell=True)
|
||||
|
||||
def cmd_output(cmd):
|
||||
try:
|
||||
out = subprocess.check_output(cmd, text=True, shell=True).strip()
|
||||
except Exception:
|
||||
out = ''
|
||||
return out
|
||||
|
||||
def execute(cmd):
|
||||
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||
universal_newlines=True, text=True, shell=True)
|
||||
for stdout_line in iter(popen.stdout.readline, ''):
|
||||
yield stdout_line
|
||||
popen.stdout.close()
|
||||
return_code = popen.wait()
|
||||
if return_code:
|
||||
raise subprocess.CalledProcessError(return_code, cmd)
|
||||
|
||||
if __name__ == '__main__':
|
||||
for event in execute('bspc subscribe node'):
|
||||
event = event.split()
|
||||
if event[0] == 'node_remove' or event[0] == 'node_transfer':
|
||||
if cmd_output('bspc query -D --names -d ' + event[2]) == 'side-view':
|
||||
if cmd_output('bspc query -N -d side-view') == '':
|
||||
cmd_run('bspc desktop voip -f')
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import subprocess
|
||||
from functools import partial
|
||||
|
||||
|
||||
cmd_run = partial(subprocess.Popen, text=True, shell=True)
|
||||
|
||||
|
||||
def cmd_output(cmd):
|
||||
try:
|
||||
out = subprocess.check_output(cmd, text=True, shell=True).strip()
|
||||
except Exception:
|
||||
out = ''
|
||||
return out
|
||||
|
||||
|
||||
def execute(cmd):
|
||||
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||
universal_newlines=True, text=True, shell=True)
|
||||
for stdout_line in iter(popen.stdout.readline, ""):
|
||||
yield stdout_line
|
||||
popen.stdout.close()
|
||||
return_code = popen.wait()
|
||||
if return_code:
|
||||
raise subprocess.CalledProcessError(return_code, cmd)
|
||||
|
||||
|
||||
def is_fullscreen(wid):
|
||||
return cmd_output(f'bspc query -N -n {wid}.fullscreen').strip()
|
||||
|
||||
|
||||
def is_floating(wid):
|
||||
return cmd_output(f'bspc query -N -n {wid}.floating').strip()
|
||||
|
||||
|
||||
def get_class(wid):
|
||||
out = cmd_output(f'xprop -id {wid} | grep WM_CLASS')
|
||||
if out:
|
||||
out = out.split(' = ')[1].split(', ')
|
||||
return (out[0].strip('"'), out[1].strip('"'))
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def get_pid(wid):
|
||||
out = cmd_output(f'xprop -id {wid} | grep WM_PID')
|
||||
if out:
|
||||
return out.split(' = ')[1]
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def is_child(pid, child_pid):
|
||||
tree = cmd_output(f'pstree -T -p {pid}')
|
||||
for line in tree.split('\n'):
|
||||
if child_pid in line:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def swallow():
|
||||
swallowed = {}
|
||||
for event in execute('bspc subscribe node'):
|
||||
event = event.split()
|
||||
if event[0] == 'node_add':
|
||||
new_wid = event[-1]
|
||||
last_wid = cmd_output('bspc query -N -d -n last.window')
|
||||
if(get_class(last_wid)[0] != 'Alacritty'):
|
||||
continue
|
||||
if any([is_floating(new_wid), is_floating(last_wid),
|
||||
is_fullscreen(new_wid), is_fullscreen(last_wid)]):
|
||||
continue
|
||||
new_pid = get_pid(new_wid)
|
||||
last_pid = get_pid(last_wid)
|
||||
if not all([new_pid, last_pid]):
|
||||
continue
|
||||
if is_child(last_pid, new_pid):
|
||||
cmd_run(f'bspc node --swap {last_wid} --follow')
|
||||
cmd_run(f'bspc node {new_wid} --flag private=on')
|
||||
cmd_run(f'bspc node {last_wid} --flag hidden=on')
|
||||
cmd_run(f'bspc node {last_wid} --flag private=on')
|
||||
swallowed[new_wid] = last_wid
|
||||
if event[0] == 'node_remove':
|
||||
removed_wid = event[-1]
|
||||
if removed_wid in swallowed.keys():
|
||||
swallowed_id = swallowed[removed_wid]
|
||||
cmd_run(f'bspc node {swallowed_id} --flag hidden=off')
|
||||
cmd_run(f'bspc node --focus {swallowed_id}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
swallow()
|
Loading…
Reference in a new issue