Some other shit

This commit is contained in:
2016-09-27 13:03:14 +03:00
parent b97d52cce5
commit 33b6dca429
4 changed files with 65 additions and 8 deletions

View File

@@ -5,6 +5,7 @@ require 'erb'
$queue = Queue.new
$panel_data = Hash.new("")
$children = []
class ModBasic
def mainloop()
@@ -25,6 +26,23 @@ class ModBasic
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
argv = ARGV
while argv[0] != nil
case argv[0]
@@ -35,12 +53,35 @@ while argv[0] != nil
argv.shift()
end
$config = YAML.load_file('./rc.yaml')
if ENV["XDG_CONFIG_HOME"] == nil
conf_dir = ENV["HOME"] + "/.config/moltenbar"
else
conf_dir = ENV["XDG_CONFIG_HOME"] + "/moltenbar"
end
Dir["./mod/*"].each do |file|
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'],
@@ -59,6 +100,6 @@ trap("SIGUSR1") { $queue << 1 }
IO.popen(lemonbar_cmd, "w") do |pipe|
while true do
data = $queue.pop
pipe.puts ERB.new($config['format']).result
pipe.puts $config['format'].erb
end
end