From b01792ec1bbf629995473269128df5b4f6a4bda0 Mon Sep 17 00:00:00 2001 From: fbt Date: Tue, 27 Sep 2016 04:18:43 +0300 Subject: [PATCH] eh it works sorta maybe Signed-off-by: fbt --- mod/bspwm_pager | 57 +++++++++++++++++++++++++++++++++++++++++++ mod/date | 15 ++++++++++++ moltenbar | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ rc | 15 ++++++++++++ rc.yaml | 19 +++++++++++++++ 5 files changed, 171 insertions(+) create mode 100644 mod/bspwm_pager create mode 100644 mod/date mode change 100644 => 100755 moltenbar create mode 100644 rc create mode 100644 rc.yaml diff --git a/mod/bspwm_pager b/mod/bspwm_pager new file mode 100644 index 0000000..ec36dba --- /dev/null +++ b/mod/bspwm_pager @@ -0,0 +1,57 @@ +# vim: ft=ruby + +class ModBspwmPager < ModBasic + @@mod_name = 'bspwm_pager' + + def data_loop() + while true do + IO.popen("bspc subscribe").each do |line| + $panel_data[@@mod_name.to_sym] = parse_data(line.chomp) + $queue << 1 + 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 = [] + + string.split(":").each do |part| + n = part[1..-1] + + if $config['mod']['bspwm_pager']['blacklist'] != nil + if $config['mod']['bspwm_pager']['blacklist'].include? n + next + end + end + + case part + when /^(O|F|U).+/ + out << "%{B#{$config['colours']['bg_focused']}} #{n} %{B-}" + when /^u.+/ + out << "%{A:bspc desktop -f #{n}:}%{R} #{n} %{R}%{A}" + when /^o.+/ + out << "%{A:bspc desktop -f #{n}:} #{n} %{A}" + when /^f.+/ + if $config['mod']['bspwm_pager']['show_empty_desktops'] + out << " #{n} " + end + when /^L.+/ + @layout = n + end + end + + case @layout + when "T" + layout_flag = "t" + when "M" + layout_flag = "m" + end + + out << " #{layout_flag} " + + return out.join.chomp + end +end + +$workers << ModBspwmPager.new.mainloop() diff --git a/mod/date b/mod/date new file mode 100644 index 0000000..67f10b7 --- /dev/null +++ b/mod/date @@ -0,0 +1,15 @@ +# vim: ft=ruby + +class ModDate < ModBasic + @@mod_name = 'date' + + def data_loop() + while true do + $panel_data[@@mod_name.to_sym] = Time.now.strftime($config['mod']['date']['format']) + $queue << 1 + sleep 1 + end + end +end + +$workers << ModDate.new.mainloop() diff --git a/moltenbar b/moltenbar old mode 100644 new mode 100755 index 49ffd26..bb87a29 --- a/moltenbar +++ b/moltenbar @@ -1 +1,66 @@ #!/usr/bin/env ruby + +require 'yaml' + +$queue = Queue.new +$workers = [] +$panel_data = Hash.new("") + +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 + +argv = ARGV +while argv[0] != nil + case argv[0] + when "-h", "--help" + puts "HELP" + end + + argv.shift() +end + +$config = YAML.load_file('./rc.yaml') + +load './rc' + +Dir["./mod/*"].each do |file| + load file +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 draw() + end +end diff --git a/rc b/rc new file mode 100644 index 0000000..2e0d865 --- /dev/null +++ b/rc @@ -0,0 +1,15 @@ +# vim: ft=ruby + +def draw() + bg_f = $config['colours']['bg_focused'] + + panel = [ + $panel_data[:bspwm_pager], + "%{r}", + "%{F#{bg_f}}%{F-}%{B#{bg_f}} ", + $panel_data[:date], + " %{B-}" + ] + + return panel.join +end diff --git a/rc.yaml b/rc.yaml new file mode 100644 index 0000000..116b575 --- /dev/null +++ b/rc.yaml @@ -0,0 +1,19 @@ +# vim: ft=yaml + +geometry: '1902x14+9+9' +fontspec: '-*-terminesspowerline-medium-*-normal-*-14-*-*-*-*-*-iso10646-*' +window_name: 'moltenbar' +active_areas: '128' +colours: + fg: '#f9f9f9' + fg_focused: '#f9f9f9' + bg: '#29303A' + bg_focused: '#467EC2' +mod: + bspwm_pager: + colour_focused: '#f9f9f9' + show_empty_desktops: false + blacklist: + -h + date: + format: '%A, %Y.%m.%d %H:%M:%S'