From 33b6dca429675abb34bec11df75652f8b38417d3 Mon Sep 17 00:00:00 2001 From: fbt Date: Tue, 27 Sep 2016 13:03:14 +0300 Subject: [PATCH] Some other shit --- mod/bspwm_pager | 5 +++- mod/bspwm_taskbar | 12 ++++++++-- moltenbar | 47 +++++++++++++++++++++++++++++++++++--- rc.yaml => rc.yaml.example | 9 ++++++-- 4 files changed, 65 insertions(+), 8 deletions(-) rename rc.yaml => rc.yaml.example (59%) diff --git a/mod/bspwm_pager b/mod/bspwm_pager index 0e0e41b..1a045f1 100644 --- a/mod/bspwm_pager +++ b/mod/bspwm_pager @@ -5,7 +5,10 @@ class ModBspwmPager < ModBasic def data_loop() while true do - IO.popen("bspc subscribe").each do |line| + pipe = IO.popen("bspc subscribe") + $children << pipe.pid + + pipe.each do |line| $panel_data[@@mod_name.to_sym] = parse_data(line.chomp) $queue << 1 end diff --git a/mod/bspwm_taskbar b/mod/bspwm_taskbar index d95552f..6415bb7 100644 --- a/mod/bspwm_taskbar +++ b/mod/bspwm_taskbar @@ -5,8 +5,16 @@ class ModBspwmTaskbar < ModBasic def data_loop() while true do - IO.popen("xtitle -s -f '%s'").each do |line| - $panel_data[@@mod_name.to_sym] = line.chomp + pipe = IO.popen("xtitle -s -f '%s'") + $children << pipe.pid + + pipe.each do |line| + if line == "\n" + $panel_data[@@mod_name.to_sym] = "" + else + $panel_data[@@mod_name.to_sym] = $config['mod']['bspwm_taskbar']['begin'].erb + line.chomp + $config['mod']['bspwm_taskbar']['end'].erb + end + $queue << 1 end end diff --git a/moltenbar b/moltenbar index eb4b431..69bde98 100755 --- a/moltenbar +++ b/moltenbar @@ -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 diff --git a/rc.yaml b/rc.yaml.example similarity index 59% rename from rc.yaml rename to rc.yaml.example index e738789..b9e0979 100644 --- a/rc.yaml +++ b/rc.yaml.example @@ -1,10 +1,12 @@ # vim: ft=yaml sw=2 et -geometry: '1902x14+9+9' +#geometry: '1902x14+9+9' +height: 14 +gap: 9 fontspec: '-*-terminesspowerline-medium-*-normal-*-14-*-*-*-*-*-iso10646-*' window_name: 'moltenbar' active_areas: '128' -format: "<%= $panel_data[:bspwm_pager] %>%{F<%= $config['colours']['bg'] %>}%{B<%= $config['colours']['bg_focused'] %>}%{F-} <%= $panel_data[:bspwm_taskbar] %>%{F<%= $config['colours']['bg_focused'] %>} %{B-} %{r}%{F<%= $config['colours']['bg_focused'] %>}%{F-}%{B<%= $config['colours']['bg_focused'] %>} LA: <%= $panel_data[:load_average] %> Network: <%= $panel_data[:network] %> <%= $panel_data[:date] %> %{B-}" +format: "<%= $panel_data[:bspwm_pager] %><%= $panel_data[:bspwm_taskbar] %>%{r}%{F<%= $config['colours']['bg_focused'] %>}%{F-}%{B<%= $config['colours']['bg_focused'] %>} LA: <%= $panel_data[:load_average] %> Network: <%= $panel_data[:network] %> <%= $panel_data[:date] %> %{B-}" colours: fg: '#f9f9f9' fg_focused: '#f9f9f9' @@ -16,6 +18,9 @@ mod: show_empty_desktops: false blacklist: -h + bspwm_taskbar: + begin: "%{F<%= $config['colours']['bg'] %>}%{B<%= $config['colours']['bg_focused'] %>}%{F-} " + end: "%{F<%= $config['colours']['bg_focused'] %>} %{B-} " date: format: '%A, %Y.%m.%d %H:%M:%S' load_average: