59 lines
1.5 KiB
Python
Executable File
59 lines
1.5 KiB
Python
Executable File
import subprocess, os
|
|
import re # regexp
|
|
from enum import Enum
|
|
|
|
import i3_lemonbar_config as config
|
|
|
|
kill_on_unfocus = []
|
|
|
|
# Loggers, initialized in main function
|
|
logger = None
|
|
health_logger = None
|
|
|
|
screen_send_cmd = lambda s : None # TODO temporary until move actions to modules
|
|
write_queue = None # TODO Actually, why is this a queue? Just last element is important
|
|
|
|
# TODO bar mode can be moved to i3Module
|
|
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
|
|
|
|
show_secs = False
|
|
|
|
# Keymaps
|
|
def_keymap = 'pl'
|
|
keymaps = {'firefox': 'se'}
|
|
cur_class = ''
|
|
|
|
# Helper functions
|
|
ansi_escape = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
|
|
def strip_ansi_unicode(s):
|
|
# ANSI escape sequences are for colors in terminal and similar
|
|
strip_ansi = ansi_escape.sub('', s)
|
|
strip_unicode = (strip_ansi.encode('ascii', 'ignore')).decode('utf-8')
|
|
return strip_unicode
|
|
|
|
def create_new_fifo(fifo_file):
|
|
"""
|
|
Create new fifo file, removing old one if it exists
|
|
"""
|
|
try:
|
|
os.remove(fifo_file)
|
|
logger.debug('''Removed old fifo file''')
|
|
except OSError:
|
|
logger.debug('''No old fifo file, good''')
|
|
|
|
try:
|
|
os.mkfifo(fifo_file)
|
|
except OSError:
|
|
logger.error('''Failed, couldn't create fifo file''')
|
|
os.remove(config.pid_file) # Clean up own PID file
|
|
sys.exit(0)
|