moltenbar/mod/bspwm_pager

84 lines
1.8 KiB
Plaintext
Raw Normal View History

# vim: ft=ruby
class BspwmPager < Worker
def mainloop()
IO.popen("bspc subscribe") do |pipe|
2016-09-27 10:03:14 +00:00
pipe.each do |line|
self.write parse_data(line)
end
end
end
def parse_data(string)
# Example: WMDVI-I-1:o1:o2:f3:f4:O5:f6:f7:f8:f9:fh:LT:TF:G
out = []
monitor = ""
state = {
monitors: {}
}
string.chomp[1..-1].split(":").each do |part|
n = part[1..-1]
if part[0] =~ /^[Mm]$/
monitor = n
state[:monitors][monitor] = {
desktops: {}
}
state[:monitors][monitor][:focused] = true if part[0] == "M"
elsif part[0] =~ /^[OFUofu]$/
d_focused = true if part[0] =~ /[OFU]/
d_occupied = true if part[0] =~ /[Oo]/
d_urgent = true if part[0] =~ /[Uu]/
state[:monitors][monitor][:desktops][n] = {
focused: d_focused,
occupied: d_occupied,
urgent: d_urgent
}
elsif part[0] == "L"
state[:monitors][monitor][:layout] = n
end
end
state[:monitors].each do |m_name, m|
if @my_config['monitors'] != nil
next unless @my_config['monitors'].include?(m_name)
end
if state[:monitors].count > 2 or @my_config['show_single_monitor']
if m[:focused]
out << "%{B#{@config['colours']['mon_focused']}} #{m_name} %{B-}"
else
out << " #{m_name} "
end
end
m[:desktops].each do |d_name, d|
if d[:focused]
out << "%{B#{@config['colours']['bg_focused']}} #{d_name} %{B-}"
elsif d[:urgent]
out << "%{A:bspc desktop -f #{d_name}:}%{R} #{d_name} %{R}%{A}"
elsif d[:occupied]
out << "%{A:bspc desktop -f #{d_name}:} #{d_name} %{A}"
else
if @my_config['show_empty_desktops']
out << " #{d_name} "
end
end
end
if m[:layout] == "T"
out << " t "
elsif m[:layout] == "M"
out << " m "
end
end
return out.join.chomp
end
end
Modules.add("bspwm_pager", "BspwmPager")