def auto_tab_cond(event, last_wid): if any((is_floating(event[-1]), is_fullscreen(event[-1]))): return False if last_wid == '': return False win_class = get_class(last_wid) curwin_class = get_class(event[-1]) if 'tabbed' in win_class and 'tabbed' not in curwin_class: # weird but children windows ids in a `tabbed` # skip a `0` in window ids so it is 0x... instead of 0x0... # therefore the replace sentence was_tabbed_child = any(wid.lower() in children_ids for wid in (event[-1], event[-1].replace('0x0', '0x'))) if not was_tabbed_child: return True else: return False
def tab_all(): all_wids = cmd_output( "bspc query -N -d -n '.window.!floating.!hidden'").split('\n') all_wids = [wid for wid in all_wids if 'tabbed' not in get_class(wid)] if all_wids: tabbed_wid = tab_current_win(all_wids[0]) if len(all_wids) > 1: for wid in all_wids[1:]: add_win_to_tabbed(wid, tabbed_wid)
def confirm_close_tabbed(cur_wid): rofi_cmd = ('echo -e "yes\nno" | rofi -selected-row 1 -width 20% -dmenu' f' -dpi 0 -theme {os.getenv("ROFI_THEME")} -lines 2 -p "Do you' ' want to close all tabbed windows?"') if 'tabbed' in get_class(cur_wid): if len(get_tabbed_children(cur_wid)) == 1: cmd_run(f'bspc node --{sys.argv[1]}') else: P = cmd_run(rofi_cmd, stdout=subprocess.PIPE) P.wait() answr = P.stdout.read().strip() if answr == 'yes': cmd_run(f'bspc node --{sys.argv[1]}') else: cmd_run(f'bspc node --{sys.argv[1]}')
def swallow_cond(new_wid, last_wid): ''' True if window should be swallowed False if not Modify it to your liking ''' print('swallow_cond') if desk_layout() == 'monocle': print(False) return False is_excluded = [ c for c in EXCLUDED_CLASSES if any(c in get_class(id) for id in (new_wid, last_wid)) ] if is_excluded: return False if any( (is_floating(new_wid), is_floating(last_wid), is_fullscreen(new_wid), is_fullscreen(last_wid), is_excluded)): return False return True
return False if last_wid == '': return False win_class = get_class(last_wid) curwin_class = get_class(event[-1]) if 'tabbed' in win_class and 'tabbed' not in curwin_class: # weird but children windows ids in a `tabbed` # skip a `0` in window ids so it is 0x... instead of 0x0... # therefore the replace sentence was_tabbed_child = any(wid.lower() in children_ids for wid in (event[-1], event[-1].replace('0x0', '0x'))) if not was_tabbed_child: return True else: return False if __name__ == '__main__': children_ids = [] for event in execute('bspc subscribe node_add node_focus'): event = event.split() if event[0] == 'node_add': last_wid = cmd_output('bspc query -N -d -n last.local.window') if auto_tab_cond(event, last_wid): add_win_to_tabbed(event[-1], last_wid) if event[0] == 'node_focus': node_id = event[-1] if 'tabbed' in get_class(node_id): children_ids = get_tabbed_children(node_id)
def tab_all(): all_wids = cmd_output( "bspc query -N -d -n '.window.!floating.!hidden'").split('\n') all_wids = [wid for wid in all_wids if 'tabbed' not in get_class(wid)] if all_wids: tabbed_wid = tab_current_win(all_wids[0]) if len(all_wids) > 1: for wid in all_wids[1:]: add_win_to_tabbed(wid, tabbed_wid) if __name__ == '__main__': cur_wid = cmd_output( "bspc query -N -d -n 'focused.window.!hidden.!floating'") if cur_wid: if sys.argv[1] == 'create': if 'tabbed' not in get_class(cur_wid): tab_current_win(cur_wid) elif sys.argv[1] == 'join': if 'tabbed' in get_class(sys.argv[2]): add_win_to_tabbed(cur_wid, sys.argv[2]) elif sys.argv[1] == 'remove': rm_win_from_tabbed(get_tabbed_children(cur_wid)[0]) elif sys.argv[1] == 'children': print(get_tabbed_children(cur_wid)) elif sys.argv[1] == 'all': tab_all()
def win_exists(win_class): 'Return True (and window id) if window with a matching class is open' for wid in cmd_output('bspc query -N -n .window').split('\n'): if win_class in get_class(wid): return wid return False