Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import i3ipc
  4. import subprocess
  5.  
  6. i3 = i3ipc.Connection()
  7.  
  8. # define colors
  9. focus_bg_color = "#ffb52a"
  10. visible_bg_color = "#808080"
  11. bg_color = "#393939"
  12. inactive_bg_color = "#393939"
  13. text_color = "#f3f4f5"
  14. inactive_text_color = "#676E7D"
  15. urgent_bg_color = "#E53935"
  16. seperator_color = "#cae1ff"
  17. seperator_text_color = "#008b8b"
  18. #seperator_text_color = "#393939"
  19.  
  20. def get_monitor_setup():
  21. xrandr=subprocess.check_output(['xrandr', '--listactivemonitors']).decode("utf-8")
  22. lines=xrandr.split("\n")
  23. number=int(lines[0][-1])
  24. screens={}
  25. for i in lines[1:number+1]:
  26. position=(i.split("+")[2])
  27. name=(i.split(" ")[-1])
  28. screens.update({position:name})
  29. order=[]
  30. for i in sorted(screens):
  31. order.append(screens[i])
  32. return order
  33.  
  34. def lemon_escape(ws):
  35. return ws.replace(':', '\\:')
  36.  
  37.  
  38. def lemon_click(ws):
  39. if ws['num']!=0:
  40. return """%{A1:i3-msg workspace """+lemon_escape(str(ws['name']))+""":}"""+ws['name']+"""%{A}"""
  41. else:
  42. return """%{A1:i3-msg workspace """+lemon_escape(str(ws['name']))+""":}"""+"♪:Music"+"""%{A}"""
  43.  
  44. def decorate_normal(ws):
  45. return " "+lemon_click(ws)+" "
  46.  
  47. def decorate_urgent(ws):
  48. return "%{u"+urgent_bg_color+"} "+lemon_click(ws)+" %{-u}"
  49.  
  50. def decorate_focused(ws):
  51. return "%{u"+focus_bg_color+"} "+lemon_click(ws)+" %{-u}"
  52.  
  53. def decorate_visible(ws):
  54. return "%{u"+visible_bg_color+"} "+lemon_click(ws)+" %{-u}"
  55.  
  56. def decorate_output(output):
  57. if output != "LVDS-1":
  58. return "%{F"+seperator_text_color+"}  %{F-}"
  59. else:
  60. return "%{F"+seperator_text_color+"}  %{F-}"
  61.  
  62. def print_workspaces(setup):
  63. workspaces = i3.get_workspaces()
  64. output=[]
  65. for i in range(len(setup)):
  66. output.append([])
  67. for i in workspaces:
  68. if i['focused']==True:
  69. tmp = decorate_focused(i)
  70. elif i['urgent']==True:
  71. tmp = decorate_urgent(i)
  72. elif i['visible']==True:
  73. tmp = decorate_visible(i)
  74. else:
  75. tmp = decorate_normal(i)
  76. screen_index=setup.index(i['output'])
  77. output[screen_index].append(tmp)
  78. printout=""
  79. for i in range(len(setup)):
  80. printout+=decorate_output(setup[i])+"".join(output[i])
  81. return printout
  82.  
  83. setup=get_monitor_setup()
  84. with open("/tmp/i3-monitor-setup.dat","w") as file:
  85. for item in setup:
  86. file.write("%s\n" % item)
  87.  
  88. print(print_workspaces(setup))
  89.  
  90. def on_workspace_focus(self, e):
  91. out=print_workspaces(setup)
  92. print(out)
  93.  
  94.  
  95. # Show current mode
  96. def on_mode_change(self, event):
  97. out = event.change
  98. if out != "default":
  99. print ("%{B"+urgent_bg_color+"}"+out+"%{B-}"+print_workspaces(setup))
  100. else:
  101. print(print_workspaces(setup))
  102.  
  103.  
  104. i3.on('workspace::', on_workspace_focus)
  105.  
  106. i3.on('mode::', on_mode_change)
  107.  
  108. i3.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement