ok this time for sure
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
c477498102
commit
c1ffc8cb6c
|
@ -1,16 +1,12 @@
|
||||||
# vim: ft=ruby
|
# vim: ft=ruby
|
||||||
|
|
||||||
class ModBspwmPager < ModBasic
|
class BspwmPager < Worker
|
||||||
@@mod_name = 'bspwm_pager'
|
def mainloop()
|
||||||
|
|
||||||
def data_loop()
|
|
||||||
while true do
|
while true do
|
||||||
pipe = IO.popen("bspc subscribe")
|
pipe = IO.popen("bspc subscribe")
|
||||||
$children << pipe.pid
|
|
||||||
|
|
||||||
pipe.each do |line|
|
pipe.each do |line|
|
||||||
$panel_data[@@mod_name.to_sym] = parse_data(line.chomp)
|
@pipe_in.puts "bspwm_pager" + "\0" + parse_data(line)
|
||||||
$queue << 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,21 +18,21 @@ class ModBspwmPager < ModBasic
|
||||||
string.split(":").each do |part|
|
string.split(":").each do |part|
|
||||||
n = part[1..-1]
|
n = part[1..-1]
|
||||||
|
|
||||||
if $config['mod']['bspwm_pager']['blacklist'] != nil
|
if @config['mod']['bspwm_pager']['blacklist'] != nil
|
||||||
if $config['mod']['bspwm_pager']['blacklist'].include? n
|
if @config['mod']['bspwm_pager']['blacklist'].include? n
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
case part
|
case part
|
||||||
when /^(O|F|U).+/
|
when /^(O|F|U).+/
|
||||||
out << "%{B#{$config['colours']['bg_focused']}} #{n} %{B-}"
|
out << "%{B#{@config['colours']['bg_focused']}} #{n} %{B-}"
|
||||||
when /^u.+/
|
when /^u.+/
|
||||||
out << "%{A:bspc desktop -f #{n}:}%{R} #{n} %{R}%{A}"
|
out << "%{A:bspc desktop -f #{n}:}%{R} #{n} %{R}%{A}"
|
||||||
when /^o.+/
|
when /^o.+/
|
||||||
out << "%{A:bspc desktop -f #{n}:} #{n} %{A}"
|
out << "%{A:bspc desktop -f #{n}:} #{n} %{A}"
|
||||||
when /^f.+/
|
when /^f.+/
|
||||||
if $config['mod']['bspwm_pager']['show_empty_desktops']
|
if @config['mod']['bspwm_pager']['show_empty_desktops']
|
||||||
out << " #{n} "
|
out << " #{n} "
|
||||||
end
|
end
|
||||||
when /^L.+/
|
when /^L.+/
|
||||||
|
@ -57,4 +53,4 @@ class ModBspwmPager < ModBasic
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ModBspwmPager.new.mainloop()
|
Modules.add("bspwm_pager", "BspwmPager")
|
||||||
|
|
|
@ -1,24 +1,19 @@
|
||||||
# vim: ft=ruby
|
# vim: ft=ruby
|
||||||
|
|
||||||
class ModBspwmTaskbar < ModBasic
|
class BspwmTaskbar < Worker
|
||||||
@@mod_name = 'bspwm_taskbar'
|
def mainloop()
|
||||||
|
|
||||||
def data_loop()
|
|
||||||
while true do
|
while true do
|
||||||
pipe = IO.popen("xtitle -s -f '%s'")
|
pipe = IO.popen("xtitle -s -f '%s'")
|
||||||
$children << pipe.pid
|
|
||||||
|
|
||||||
pipe.each do |line|
|
pipe.each do |line|
|
||||||
if line == "\n"
|
if line == "\n"
|
||||||
$panel_data[@@mod_name.to_sym] = ""
|
self.write ""
|
||||||
else
|
else
|
||||||
$panel_data[@@mod_name.to_sym] = $config['mod']['bspwm_taskbar']['begin'].erb + line.chomp + $config['mod']['bspwm_taskbar']['end'].erb
|
self.write @config['mod']['bspwm_taskbar']['begin'].erb + line.chomp + @config['mod']['bspwm_taskbar']['end'].erb + "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
$queue << 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ModBspwmTaskbar.new.mainloop()
|
Modules.add("bspwm_taskbar", "BspwmTaskbar")
|
||||||
|
|
11
mod/date
11
mod/date
|
@ -1,15 +1,12 @@
|
||||||
# vim: ft=ruby
|
# vim: ft=ruby
|
||||||
|
|
||||||
class ModDate < ModBasic
|
class ModDate < Worker
|
||||||
@@mod_name = 'date'
|
def mainloop()
|
||||||
|
|
||||||
def data_loop()
|
|
||||||
while true do
|
while true do
|
||||||
$panel_data[@@mod_name.to_sym] = Time.now.strftime($config['mod']['date']['format'])
|
self.write Time.now.strftime(@config['mod']['date']['format'])
|
||||||
$queue << 1
|
|
||||||
sleep(1)
|
sleep(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ModDate.new.mainloop()
|
Modules.add("date", "ModDate")
|
||||||
|
|
|
@ -1,26 +1,23 @@
|
||||||
# vim: ft=ruby
|
# vim: ft=ruby
|
||||||
|
|
||||||
class ModLoadAverage < ModBasic
|
class LoadAverage < Worker
|
||||||
@@mod_name = 'load_average'
|
def mainloop()
|
||||||
|
|
||||||
def data_loop()
|
|
||||||
while true do
|
while true do
|
||||||
file = File.open("/proc/loadavg", "r")
|
file = File.open("/proc/loadavg", "r")
|
||||||
la_m = file.gets.split[0]
|
la_m = file.gets.split[0]
|
||||||
|
|
||||||
if la_m.to_i > $config['mod']['load_average']['crit_value']
|
if la_m.to_i > @config['mod']['load_average']['crit_value']
|
||||||
fg_colour = $config['mod']['load_average']['crit_colour']
|
fg_colour = @config['mod']['load_average']['crit_colour']
|
||||||
elsif la_m.to_i > $config['mod']['load_average']['warn_value']
|
elsif la_m.to_i > @config['mod']['load_average']['warn_value']
|
||||||
fg_colour = $config['mod']['load_average']['warn_colour']
|
fg_colour = @config['mod']['load_average']['warn_colour']
|
||||||
else
|
else
|
||||||
fg_colour = $config['mod']['load_average']['ok_colour']
|
fg_colour = @config['mod']['load_average']['ok_colour']
|
||||||
end
|
end
|
||||||
|
|
||||||
$panel_data[@@mod_name.to_sym] = "%{F#{fg_colour}}#{la_m}%{F-}"
|
self.write "%{F#{fg_colour}}#{la_m}%{F-}"
|
||||||
$queue << 1
|
|
||||||
sleep(5)
|
sleep(5)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ModLoadAverage.new.mainloop()
|
Modules.add("load_average", "LoadAverage")
|
||||||
|
|
24
mod/network
24
mod/network
|
@ -1,45 +1,41 @@
|
||||||
# vim: ft=ruby
|
# vim: ft=ruby
|
||||||
|
|
||||||
class ModNetwork < ModBasic
|
class Network < Worker
|
||||||
@@mod_name = 'network'
|
|
||||||
|
|
||||||
require 'open3'
|
require 'open3'
|
||||||
|
|
||||||
def data_loop()
|
def mainloop()
|
||||||
$panel_data[@@mod_name.to_sym] = "checking..."
|
self.write "checking..."
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
$panel_data[@@mod_name.to_sym] = network_status.chomp
|
self.write network_status
|
||||||
$queue << 1
|
|
||||||
sleep(10)
|
sleep(10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def network_status
|
def network_status
|
||||||
hosts = $config['mod']['network']['hosts']
|
hosts = @config['mod']['network']['hosts']
|
||||||
|
|
||||||
net_ok = 0
|
net_ok = 0
|
||||||
hosts.each do |h|
|
hosts.each do |h|
|
||||||
i,o,t = Open3.popen2("ping", "-c", "1", h)
|
i,o,t = Open3.popen2("ping", "-c", "1", h)
|
||||||
i.close; o.close
|
|
||||||
t.join
|
t.join
|
||||||
|
|
||||||
net_ok += 1 if t.value
|
net_ok += 1 if t.value.exitstatus == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if net_ok == 0
|
if net_ok == 0
|
||||||
status = "CRIT"
|
status = "CRIT"
|
||||||
fg_colour = $config['mod']['network']['crit_colour']
|
fg_colour = @config['mod']['network']['crit_colour']
|
||||||
elsif net_ok < hosts.length
|
elsif net_ok < hosts.length
|
||||||
status = "WARN"
|
status = "WARN"
|
||||||
fg_colour = $config['mod']['network']['warn_colour']
|
fg_colour = @config['mod']['network']['warn_colour']
|
||||||
else
|
else
|
||||||
status = "ok"
|
status = "ok"
|
||||||
fg_colour = $config['mod']['network']['ok_colour']
|
fg_colour = @config['mod']['network']['ok_colour']
|
||||||
end
|
end
|
||||||
|
|
||||||
return "%{F#{fg_colour}}#{status}%{F-}"
|
return "%{F#{fg_colour}}#{status}%{F-}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ModNetwork.new.mainloop()
|
Modules.add("network", "Network")
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Worker
|
||||||
|
|
||||||
def mainloop()
|
def mainloop()
|
||||||
loop do
|
loop do
|
||||||
@pipe_in.puts "#{@name}\0I am a dummy\n"
|
self.write("I am a dummy")
|
||||||
sleep(1)
|
sleep(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -44,6 +44,10 @@ class Worker
|
||||||
puts "#{err}: #{@wpid}"
|
puts "#{err}: #{@wpid}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def write(data)
|
||||||
|
@pipe_in.puts @name + "\0" + data
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ::String
|
class ::String
|
||||||
|
@ -96,7 +100,6 @@ config = YAML.load_file(config_file)
|
||||||
|
|
||||||
# Create a named pipe unless one exists
|
# Create a named pipe unless one exists
|
||||||
File.mkfifo(config['fifo_in']) unless File.exist?(config['fifo_in'])
|
File.mkfifo(config['fifo_in']) unless File.exist?(config['fifo_in'])
|
||||||
File.mkfifo(config['fifo_out']) unless File.exist?(config['fifo_out'])
|
|
||||||
|
|
||||||
for m in config['modules'] do
|
for m in config['modules'] do
|
||||||
load("#{mod_dir}/#{m}")
|
load("#{mod_dir}/#{m}")
|
||||||
|
|
|
@ -8,7 +8,6 @@ fontspec: '-*-terminesspowerline-medium-*-normal-*-14-*-*-*-*-*-iso10646-*'
|
||||||
window_name: 'moltenbar'
|
window_name: 'moltenbar'
|
||||||
active_areas: '128'
|
active_areas: '128'
|
||||||
fifo_in: "/run/user/1000/moltenbar_in.fifo"
|
fifo_in: "/run/user/1000/moltenbar_in.fifo"
|
||||||
fifo_out: "/run/user/1000/moltenbar_out.fifo"
|
|
||||||
modules:
|
modules:
|
||||||
- bspwm_pager
|
- bspwm_pager
|
||||||
- date
|
- date
|
||||||
|
|
Loading…
Reference in New Issue
Block a user