moltenbar/moltenbar
2016-09-27 13:05:00 +03:00

96 lines
1.6 KiB
Ruby
Executable File

#!/usr/bin/env ruby
require 'yaml'
require 'erb'
$queue = Queue.new
$panel_data = Hash.new("")
$children = []
class ModBasic
def mainloop()
thread = Thread.new {
self.data_loop()
}
return thread
end
def data_loop()
while true do
t = Time.new
$panel_data[:dummy] = "#{t}: I am a dummy!"
$queue << 1
sleep(1)
end
end
end
class ::String
def erb
return ERB.new(self).result
end
end
def get_x_dims
return `xrandr`.scan(/current (\d+) x (\d+)/).flatten
end
at_exit do
$children.each do |pid|
puts "Killing pid: #{pid}"
Process.kill("TERM", pid)
end
end
if ENV["XDG_CONFIG_HOME"] == nil
conf_dir = ENV["HOME"] + "/.config/moltenbar"
else
conf_dir = ENV["XDG_CONFIG_HOME"] + "/moltenbar"
end
config_file = conf_dir + "/rc.yaml"
mod_dir = conf_dir + "/mod"
$config = YAML.load_file(config_file)
Dir["#{mod_dir}/*"].each do |file|
load file
end
if $config['geometry'] == nil
$config['gap'] ||= 0
$config['height'] ||= 14
gap = $config['gap'].to_i
if $config['width'] == nil
y, x = get_x_dims()
$config['width'] = y.to_i - (gap * 2)
end
$config['geometry'] = "#{$config['width']}x#{$config['height']}+#{gap}+#{gap}"
end
lemonbar_cmd = [
"lemonbar",
"-g", $config['geometry'],
"-f", $config['fontspec'],
"-n", $config['window_name'],
"-a", $config['active_areas'],
"-F", $config['colours']['fg'],
"-B", $config['colours']['bg']
]
puts "Launching lemonbar as: " + lemonbar_cmd.join(" ")
trap("SIGINT") { exit 0 }
trap("SIGUSR1") { $queue << 1 }
IO.popen(lemonbar_cmd, "w") do |pipe|
while true do
data = $queue.pop
pipe.puts $config['format'].erb
end
end