Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import i3ipc
- import subprocess
- i3 = i3ipc.Connection()
- # define colors
- focus_bg_color = "#ffb52a"
- visible_bg_color = "#808080"
- bg_color = "#393939"
- inactive_bg_color = "#393939"
- text_color = "#f3f4f5"
- inactive_text_color = "#676E7D"
- urgent_bg_color = "#E53935"
- seperator_color = "#cae1ff"
- seperator_text_color = "#008b8b"
- #seperator_text_color = "#393939"
- def get_monitor_setup():
- xrandr=subprocess.check_output(['xrandr', '--listactivemonitors']).decode("utf-8")
- lines=xrandr.split("\n")
- number=int(lines[0][-1])
- screens={}
- for i in lines[1:number+1]:
- position=(i.split("+")[2])
- name=(i.split(" ")[-1])
- screens.update({position:name})
- order=[]
- for i in sorted(screens):
- order.append(screens[i])
- return order
- def lemon_escape(ws):
- return ws.replace(':', '\\:')
- def lemon_click(ws):
- if ws['num']!=0:
- return """%{A1:i3-msg workspace """+lemon_escape(str(ws['name']))+""":}"""+ws['name']+"""%{A}"""
- else:
- return """%{A1:i3-msg workspace """+lemon_escape(str(ws['name']))+""":}"""+"♪:Music"+"""%{A}"""
- def decorate_normal(ws):
- return " "+lemon_click(ws)+" "
- def decorate_urgent(ws):
- return "%{u"+urgent_bg_color+"} "+lemon_click(ws)+" %{-u}"
- def decorate_focused(ws):
- return "%{u"+focus_bg_color+"} "+lemon_click(ws)+" %{-u}"
- def decorate_visible(ws):
- return "%{u"+visible_bg_color+"} "+lemon_click(ws)+" %{-u}"
- def decorate_output(output):
- if output != "LVDS-1":
- return "%{F"+seperator_text_color+"} %{F-}"
- else:
- return "%{F"+seperator_text_color+"} %{F-}"
- def print_workspaces(setup):
- workspaces = i3.get_workspaces()
- output=[]
- for i in range(len(setup)):
- output.append([])
- for i in workspaces:
- if i['focused']==True:
- tmp = decorate_focused(i)
- elif i['urgent']==True:
- tmp = decorate_urgent(i)
- elif i['visible']==True:
- tmp = decorate_visible(i)
- else:
- tmp = decorate_normal(i)
- screen_index=setup.index(i['output'])
- output[screen_index].append(tmp)
- printout=""
- for i in range(len(setup)):
- printout+=decorate_output(setup[i])+"".join(output[i])
- return printout
- setup=get_monitor_setup()
- with open("/tmp/i3-monitor-setup.dat","w") as file:
- for item in setup:
- file.write("%s\n" % item)
- print(print_workspaces(setup))
- def on_workspace_focus(self, e):
- out=print_workspaces(setup)
- print(out)
- # Show current mode
- def on_mode_change(self, event):
- out = event.change
- if out != "default":
- print ("%{B"+urgent_bg_color+"}"+out+"%{B-}"+print_workspaces(setup))
- else:
- print(print_workspaces(setup))
- i3.on('workspace::', on_workspace_focus)
- i3.on('mode::', on_mode_change)
- i3.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement