2016-09-27 01:18:43 +00:00
|
|
|
# vim: ft=ruby
|
|
|
|
|
2016-09-28 20:30:07 +00:00
|
|
|
class BspwmPager < Worker
|
|
|
|
def mainloop()
|
2016-10-22 23:08:29 +00:00
|
|
|
IO.popen("bspc subscribe") do |pipe|
|
2016-09-27 10:03:14 +00:00
|
|
|
pipe.each do |line|
|
2017-05-22 18:38:46 +00:00
|
|
|
self.write parse_data(line)
|
2016-09-27 01:18:43 +00:00
|
|
|
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 = []
|
2017-05-23 03:20:28 +00:00
|
|
|
monitor = ""
|
|
|
|
state = {
|
2017-05-24 13:39:18 +00:00
|
|
|
monitors: {}
|
2017-05-23 03:20:28 +00:00
|
|
|
}
|
2016-09-27 01:18:43 +00:00
|
|
|
|
2017-05-23 03:20:28 +00:00
|
|
|
string.chomp[1..-1].split(":").each do |part|
|
2016-09-27 01:18:43 +00:00
|
|
|
n = part[1..-1]
|
|
|
|
|
2017-05-23 03:20:28 +00:00
|
|
|
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"
|
2017-05-24 13:39:18 +00:00
|
|
|
state[:monitors][monitor][:layout] = n
|
2017-05-23 03:20:28 +00:00
|
|
|
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} "
|
2016-09-27 01:18:43 +00:00
|
|
|
end
|
|
|
|
end
|
2017-05-22 18:38:46 +00:00
|
|
|
|
2017-05-23 03:20:28 +00:00
|
|
|
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
|
2016-10-04 12:34:25 +00:00
|
|
|
if @my_config['show_empty_desktops']
|
2017-05-23 03:20:28 +00:00
|
|
|
out << " #{d_name} "
|
2017-05-22 18:38:46 +00:00
|
|
|
end
|
2017-05-23 03:20:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-24 13:39:18 +00:00
|
|
|
if m[:layout] == "T"
|
2017-05-23 03:20:28 +00:00
|
|
|
out << " t "
|
2017-05-24 13:39:18 +00:00
|
|
|
elsif m[:layout] == "M"
|
2017-05-23 03:20:28 +00:00
|
|
|
out << " m "
|
2016-09-27 01:18:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return out.join.chomp
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-28 20:30:07 +00:00
|
|
|
Modules.add("bspwm_pager", "BspwmPager")
|