156 lines
4.5 KiB
Python
Executable File
156 lines
4.5 KiB
Python
Executable File
import subprocess
|
|
from enum import Enum
|
|
|
|
import i3_lemonbar_config as config
|
|
|
|
p_screen = None
|
|
kill_on_unfocus = []
|
|
|
|
# Loggers, initialized in main function
|
|
logger = None
|
|
health_logger = None
|
|
|
|
class bar_mode(Enum):
|
|
power, normal, control = range(-1,2) # Don't cycle through power
|
|
|
|
def cycle(self):
|
|
try:
|
|
return bar_mode(self.value + 1)
|
|
except ValueError:
|
|
return bar_mode(0)
|
|
|
|
mode = bar_mode.normal
|
|
|
|
screen_args = ['screen', '-D', '-R', '-U' '-S' 'lemonbar']
|
|
|
|
floatterm_args = lambda prog : ['terminator', '-r', 'FLOAT_TERM', '-p'
|
|
, 'dark', '-e', 'echo kill_unfocus $$ > {}; exec {}'.format(
|
|
config.fifo_file_executor, prog)]
|
|
def date_comm(args):
|
|
subprocess.Popen(['yad', '--no-buttons', '--calendar', '--sticky'
|
|
, '--on-top' , '--class' , '"YADWIN"', '--posx=1650', '--posy=24'
|
|
, '--close-on-unfocus'])
|
|
|
|
def pavu_comm(args):
|
|
global kill_on_unfocus
|
|
p = subprocess.Popen(['pavucontrol', '--class=FLOAT_PAVU'])
|
|
kill_on_unfocus.append(p.pid)
|
|
|
|
def htop_comm(args):
|
|
subprocess.Popen(floatterm_args('htop'))
|
|
|
|
def nmtui_comm(args):
|
|
subprocess.Popen(floatterm_args('nmtui'))
|
|
def lang_comm(args):
|
|
subprocess.Popen(['sh', '/home/kuba/.i3/scripts/lang.sh', 'next'])
|
|
def dpms_comm(args):
|
|
subprocess.Popen(['sh', '/home/kuba/.i3/scripts/dpmsctl.sh'])
|
|
def adj_br(args):
|
|
subprocess.Popen(['/home/kuba/.i3/scripts/adjbr.sh', '-b', config.fifo_file_executor])
|
|
def i3msg_comm(args):
|
|
subprocess.Popen(args.split())
|
|
def add_tokill(args):
|
|
global kill_on_unfocus
|
|
kill_on_unfocus.append(int(args.split()[1]))
|
|
def set_mode(args):
|
|
global mode
|
|
new_mode = args.split()[1]
|
|
if new_mode == "cycle":
|
|
mode = mode.cycle()
|
|
|
|
for m in bar_mode:
|
|
if new_mode == m.name:
|
|
mode = m
|
|
break
|
|
def bluetooth(args):
|
|
btcargs = args.split()[1:]
|
|
btcargs = [a.replace('pxc550', '00:16:94:22:29:0E') for a in btcargs]
|
|
btcargs.append('\n')
|
|
inp = ' '.join(btcargs)
|
|
p_screen.stdin.write(inp)
|
|
p_screen.stdin.flush()
|
|
|
|
show_secs = False
|
|
def toggle_secs(args):
|
|
global show_secs
|
|
show_secs = not show_secs
|
|
|
|
# Keymaps
|
|
def_keymap = 'pl'
|
|
keymaps = {'Firefox': 'se'}
|
|
cur_class = ''
|
|
def set_lang(args):
|
|
global keymaps
|
|
lang = args.split()[1]
|
|
keymaps[cur_class] = lang
|
|
|
|
commands_dict = {'toggle_secs': toggle_secs
|
|
,'date': date_comm
|
|
,'pavu': pavu_comm
|
|
,'load': htop_comm
|
|
,'wlan': nmtui_comm
|
|
,'dpms': dpms_comm
|
|
,'i3-msg': i3msg_comm
|
|
,'switch_lang': lang_comm
|
|
,'kill_unfocus': add_tokill
|
|
,'mode': set_mode
|
|
,'adj_br': adj_br
|
|
,'setlang': set_lang
|
|
,'bluetooth': bluetooth
|
|
}
|
|
|
|
# Callbacks for workspaces
|
|
def add_callbacks(i3ws):
|
|
i3ws.change_callbacks.append(set_bg)
|
|
i3ws.focus_callbacks.append(set_keymap)
|
|
i3ws.focus_callbacks.append(kill_floating_windows)
|
|
|
|
def img_path(num):
|
|
dir = '/home/kuba/Obrazy/Wallpapers/'
|
|
return dir + {
|
|
1: '1_main',
|
|
2: '2_web',
|
|
3: '3_music',
|
|
4: '4_work',
|
|
5: '5_terms',
|
|
6: '6_stats',
|
|
7: '7',
|
|
8: '8',
|
|
9: '9',
|
|
}.get(int(num), 'default')
|
|
|
|
def set_bg(i3ws):
|
|
cmd_args = ['sh', '/home/kuba/scripts/set_bg.sh']
|
|
for output in i3ws.outputs:
|
|
if output.active:
|
|
bg = img_path(output.current_workspace.partition(' ')[0])
|
|
cmd_args.append(bg)
|
|
subprocess.call(cmd_args)
|
|
|
|
def kill_floating_windows(i3ws):
|
|
global kill_on_unfocus, logger
|
|
role = i3ws.focused_window.window_role
|
|
wclass = i3ws.focused_window.window_class
|
|
|
|
if role != 'FLOAT_TERM' and wclass != 'FLOAT_PAVU' and wclass != 'YADWINBR':
|
|
# Is there a window that the bar has opened?
|
|
for pid in kill_on_unfocus:
|
|
try:
|
|
os.kill(pid, signal.SIGTERM)
|
|
except ProcessLookupError:
|
|
logger.debug('Tried killing process {} but it doesn\'t exist'.format(pid))
|
|
kill_on_unfocus = []
|
|
|
|
def set_keymap(i3ws):
|
|
global cur_class, keymaps, logger
|
|
wclass = i3ws.focused_window.window_class
|
|
cur_class = wclass
|
|
|
|
if wclass in keymaps:
|
|
new_km = keymaps[wclass]
|
|
logger.debug('Setting {} as keymap for {}'.format(new_km, wclass))
|
|
else:
|
|
new_km = def_keymap
|
|
logger.debug('Setting default keymap {} for {}'.format(def_keymap, wclass))
|
|
subprocess.call(['/home/kuba/.i3/scripts/lang.sh', 'qset', new_km])
|