lemonbar: Implement modular approach for conky slow and conky fast

This commit is contained in:
kuben
2019-08-19 11:57:40 +02:00
parent 4aba84ced0
commit a88a619702
5 changed files with 178 additions and 95 deletions

View File

@@ -20,7 +20,6 @@ import time
from subprocess import call
import i3ipc
import i3_lemonbar_config as config
import i3_lemonbar_common as common
class State(object):
@@ -59,21 +58,22 @@ class i3ws(object):
focus_callbacks = []
def __init__(self, state=None, fifo_file=None):
def __init__(self, logger, state=None, fifo_file=None):
if state:
self.state = state
if fifo_file:
self.fifo = open(fifo_file, 'w')
self.logger = logger
common.add_callbacks(self)
def work(self):
# While loop to restart connection as long as there is an i3 ipc socket
while self.running:
self.resetConn()
common.logger.debug('Started i3 workspaces manager')
self.logger.debug('Started i3 workspaces manager')
self.enterMain()
common.logger.debug('Finished i3 workspaces manager')
time.sleep(0.5) # TODO max number of attempts + catch exception instead
self.logger.debug('Finished i3 workspaces manager')
time.sleep(0.5) # TODO max number of attempts + catch exception instead
def resetConn(self):
self.conn = i3ipc.Connection()
@@ -93,12 +93,12 @@ class i3ws(object):
# Locking call
self.conn.main()
except BrokenPipeError:
common.logger.debug('Broken pipe in i3 workspaces thread, exiting')
self.logger.debug('Broken pipe in i3 workspaces thread, exiting')
except:
common.logger.debug('Unknown exception in i3 workspaces thread, exiting')
self.logger.debug('Unknown exception in i3 workspaces thread, exiting')
def shutdown(self, i3, e):
common.logger.debug('Shut down i3ipc')
self.logger.debug('Shut down i3ipc')
def change(self, i3, e):
# Receives event and workspace data
@@ -154,7 +154,7 @@ class i3ws(object):
sys.stdout.flush()
def quit(self):
common.logger.debug('Quitting i3 workspace script')
self.logger.debug('Quitting i3 workspace script')
self.running = False
self.conn.main_quit()
if self.fifo is not None:
@@ -170,18 +170,20 @@ def handle_exit(signal, frame):
sys.exit(1)
if __name__ == '__main__':
# Run as stand-alone
# Setup logger to stdout with debug log level
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
common.logger = logging.getLogger('Normal logger')
common.logger.setLevel(logging.DEBUG)
common.logger.addHandler(handler)
logger = logging.getLogger('Normal logger')
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
# Capture Keyboard Interrupt (i3ipc captures this internally)
signal.signal(signal.SIGINT, handle_exit)
# Start main
ws = i3ws()
ws = i3ws(logger = logger)
ws.work()