def rm_win_from_tabbed(wid): root_wid = cmd_output('xwininfo -root').split('\n')[0].split()[3] cmd_run(f'xdotool windowreparent {wid} {root_wid}')
def swallow(): ''' monitore node_add and node_remove events and store swallowed windows in a dictionary ''' swallowed = {} for event in execute('bspc subscribe node_add node_remove'): try: logging.debug(f'Processing Event: {event}') event = event.split() if not event: continue if event[0] == 'node_add': new_wid = event[-1] last_wid = cmd_output( "bspc query -N -d -n 'last.window.!floating.!fullscreen'") print(new_wid, last_wid) print(swallow_cond(new_wid, last_wid)) if not swallow_cond(new_wid, last_wid): continue new_pid = get_pid(new_wid) last_pid = get_pid(last_wid) print(new_pid, last_pid) print(advance_is_child(last_pid, new_pid)) if not all([new_pid, last_pid]): continue if advance_is_child(last_pid, new_pid): cmd_run(f'bspc node {last_wid} --flag private=on') cmd_run(f'bspc node --swap {last_wid} --follow') cmd_run(f'bspc node {last_wid} --flag hidden=on') cmd_run(f'bspc node {new_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}') except Exception as e: print(e) print(traceback.format_exc()) logging.debug('Error occured in mainloop:' f'\n{e}\n{traceback.format_exc()}')
def hideall(): for win in cmd_output( "bspc query -N -d -n '.!hidden.window.!focused'").split('\n'): cmd_run(f'bspc node {win} -g hidden=on')
def add_win_to_tabbed(wid, tabbed_wid): cmd_run(f'xdotool windowreparent {wid} {tabbed_wid}')
def start_terminal(termclass, termargs): cmd_run(f'{os.getenv("TERMINAL")} -N {termclass} {" ".join(termargs)}')
def set_single_wallpaper(path): cmd_run(f'feh --bg-fill "{path}"')
if __name__ == '__main__': wid = cmd_output("bspc query -N -d -n 'any.floating.window.!hidden'").strip() if wid == '': sys.exit() win_gt = win_geometry(wid) current_monitor = cmd_output('bspc query -M --names -m focused').strip() scr_dim = screen_dim(current_monitor) at_rightedge = win_gt['x_pos'] + win_gt['width'] == scr_dim['width'] at_leftedge = win_gt['x_pos'] == 0 at_bottom = win_gt['y_pos'] + win_gt['height'] == scr_dim['height'] if (at_bottom and at_rightedge) or (at_bottom and at_leftedge): if at_rightedge: cmd_run( f'bspc node {wid} --move -{scr_dim["width"]-win_gt["width"]} 0' ) elif at_leftedge: cmd_run( f'bspc node {wid} --move {scr_dim["width"]-win_gt["width"]} 0') else: cmd_run( f'bspc node {wid} --move ' f'{scr_dim["width"]-win_gt["width"]-win_gt["x_pos"]} ' f'{scr_dim["height"]-win_gt["height"]-win_gt["y_pos"]}' )
def toggle_hide(wid): 'toggle the hidden flag of the passed node' cmd_run(f'bspc node {wid} --flag hidden') if not is_hidden(wid): cmd_run(f'bspc node --focus {wid}')
if len(hidden_windows.split('\n')) == 0: sys.exit() elif len(hidden_windows.split('\n')) == 1: selected_window = hidden_windows else: try: wins_titles = '\n'.join([ f'{i}|' + cmd_output('xtitle ' + win_id) for i, win_id in enumerate(hidden_windows.split('\n')) ]) selected_window = cmd_output( f'echo "{wins_titles}" | rofi -dmenu -dpi 0 -theme {rofi_theme}') selected_window = hidden_windows.split('\n')[int( selected_window.split('|')[0])] except subprocess.CalledProcessError: sys.exit() try: current_win = cmd_output('bspc query -N -n focused') except subprocess.CalledProcessError: pass cmd_run(f'bspc node {selected_window} --flag hidden=off') cmd_run(f'bspc node {selected_window} --flag private=on') if swap_flag: cmd_run(f'bspc node {current_win} --flag private=on') cmd_run(f'bspc node --swap {selected_window} --follow') cmd_run(f'bspc node {current_win} -g hidden=on') cmd_run(f'bspc node -f {selected_window}')
def swallow(): ''' monitore node_add and node_remove events and store swallowed windows in a dictionary ''' swallowed = {} for event in execute('bspc subscribe node_add node_remove'): try: logging.debug(f'Processing Event: {event}') event = event.split() if not event: continue if event[0] == 'node_add': rotate_flag = False new_wid = event[-1] last_wid = cmd_output( "bspc query -N -d -n 'last.window.!floating.!fullscreen'") if not swallow_cond(new_wid, last_wid): continue new_pid = get_pid(new_wid) last_pid = get_pid(last_wid) if not all([new_pid, last_pid]): continue if advance_is_child(last_pid, new_pid): capture_layout() last_path = temp_paths[last_wid]['path'] print(last_path) new_path = last_path + '/1' print(new_path) cmd_run(f'bspc node {last_wid} --flag hidden=on') cmd_run(f"bspc node {new_wid} --to-node {new_path}") 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] del swallowed[removed_wid] cmd_run(f'bspc node {swallowed_id} --flag hidden=off') cmd_run(f"bspc node {last_wid} --to-node {last_path}") print(last_path.split(':')[-1]) if not len(last_path.split(':')[-1]) <= 5: if last_path[-3] == '2': cmd_run(f'bspc node {last_path[:-4]} --rotate 270') else: cmd_run(f'bspc node {last_path[:-4]} --rotate 90') cmd_run(f'bspc node --focus {swallowed_id}') except Exception as e: print(e) print(traceback.format_exc()) logging.debug('Error occured in mainloop:' f'\n{e}\n{traceback.format_exc()}')
def main(bg_hex, trans): bg_hex = randomize_hue(bg_hex) + trans cmd_run(f"mlterm --fontsize {GDKSCALE*15} --bg '{bg_hex}' "+' '.join(sys.argv[1:]))
#!/usr/bin/env python # Python version of the following code # https://github.com/phenax/dotfiles/blob/master/.config/bspwm/scripts/resize.sh import sys from wmutils.utils import is_floating from wmutils.processes import cmd_run, cmd_output dir_ = sys.argv[1] delta = 40 if len(sys.argv) < 3 else sys.argv[2] x = f'+{delta}' if dir_ == 'right' else f'-{delta}' if dir_ == 'left' else '0' y = f'+{delta}' if dir_ == 'down' else f'-{delta}' if dir_ == 'up' else '0' pair_dict = { 'right': 'left', 'left': 'right', 'top': 'bottom', 'bottom': 'top' } DIR_ = 'right' if dir_ in ('left', 'right') else 'top' FALLDIR = pair_dict[DIR_] cmd_run(f'bspc node --resize {DIR_} {x} {y}') if not is_floating(cmd_output('bspc query -N -n')): cmd_run(f'bspc node --resize {FALLDIR} {x} {y}')
#!/usr/bin/env python import time from wmutils.processes import cmd_run, cmd_output from wmutils.utils import is_desk_empty, bspwm_events events = bspwm_events('node_remove') for event in events: if is_desk_empty(cmd_output("bspc query -D -d --names")): try: time.sleep(4) if is_desk_empty(cmd_output("bspc query -D -d --names")): cmd_run('bspc desktop --focus last.occupied') except Exception: pass