Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Commit

Permalink
added mode label
Browse files Browse the repository at this point in the history
  • Loading branch information
city41 committed Aug 12, 2018
1 parent 0d9a23a commit c18222e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
9 changes: 6 additions & 3 deletions i3conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
from log import log

class WorkspaceSub(threading.Thread):
def __init__(self, con, callback):
def __init__(self, con, callback, modeCallback):
self.con = con

i3callback = lambda _, workspaces: callback(self.con.get_workspaces())
i3ModeCallback = lambda _, mode: modeCallback(mode)
self.con.on('workspace', i3callback)
self.con.on('mode', i3ModeCallback)

threading.Thread.__init__(self)
self.start()
Expand Down Expand Up @@ -76,11 +78,12 @@ def go_to_workspace(self, workspace_name):
throwawayCon.command('workspace ' + workspace_name)
throwawayCon.close()

def subscribe(self, callback):
def subscribe(self, callback, modeCallback):
if not self.con:
raise "subscribing but there is no connection"
self.callback = callback
self.sub = WorkspaceSub(self.con, self.callback)
self.modeCallback = modeCallback
self.sub = WorkspaceSub(self.con, self.callback, self.modeCallback)

def close(self):
log('I3Conn close')
Expand Down
2 changes: 1 addition & 1 deletion log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

SHOULD_LOG = True
SHOULD_LOG = False
have_logged = False

def log(message):
Expand Down
28 changes: 27 additions & 1 deletion matei3applet.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def destroy(self, event):
def init_widgets(self):
self.box = Gtk.HBox()
self.applet.add(self.box)
self.modeLabel = Gtk.Label('')
self.modeLabel.set_use_markup(True)

def set_initial_buttons(self):
self.set_workspace_buttons(self.i3conn.get_workspaces())
Expand All @@ -83,14 +85,30 @@ def close_sub(self):

def open_sub(self):
log('open_sub')
self.i3conn.subscribe(self.on_workspace_event)
self.i3conn.subscribe(self.on_workspace_event, self.on_mode_event)

def on_workspace_event(self, workspaces):
log('on_workspace_event')

if workspaces:
GLib.idle_add(self.set_workspace_buttons, workspaces)

def on_mode_event(self, mode):
log('on_mode_event')
log(mode.change)

GLib.idle_add(self.set_mode_label_text, mode.change)

def set_mode_label_text(self, text):
if text == 'default':
self.modeLabel.set_text('')
else:
textToSet = '<span background="%s"><b> %s </b></span>' % (self.colors['urgent_workspace_bg'], text)
self.modeLabel.set_text(textToSet)

self.modeLabel.set_use_markup(True)
self.modeLabel.show()

def go_to_workspace(self, workspace):
if not workspace['focused']:
self.i3conn.go_to_workspace(workspace['name'])
Expand Down Expand Up @@ -130,6 +148,14 @@ def get_button(workspace):
for workspace in workspaces:
self.box.pack_start(get_button(workspace), False, False, 0)

self.box.pack_start(self.modeLabel, False, False, 0)

# if mode != 'default':
# modeLabel = Gtk.Label('<span background="%s"><b> %s </b></span>' % (self.colors['urgent_workspace_bg'], mode))
# modeLabel.set_use_markup(True)
# self.box.park_start(modeLabel, False, False, 0)


self.box.show_all()

def show(self):
Expand Down

0 comments on commit c18222e

Please sign in to comment.