Class: Barr::Blocks::Bspwm
- Inherits:
-
Barr::Block
- Object
- Barr::Block
- Barr::Blocks::Bspwm
- Defined in:
- lib/barr/blocks/bspwm.rb
Instance Attribute Summary collapse
-
#focus_markers ⇒ Object
readonly
Returns the value of attribute focus_markers.
-
#invert_focus_colors ⇒ Object
Returns the value of attribute invert_focus_colors.
-
#monitor ⇒ Object
readonly
Returns the value of attribute monitor.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Attributes inherited from Barr::Block
#align, #bgcolor, #fgcolor, #icon, #interval, #manager, #output
Instance Method Summary collapse
- #bsp_tree ⇒ Object
- #first_monitor ⇒ Object
- #focused_desktop(desktop) ⇒ Object
-
#initialize(opts = {}) ⇒ Bspwm
constructor
A new instance of Bspwm.
- #sys_cmd ⇒ Object
- #unfocused_desktop(desktop) ⇒ Object
- #update! ⇒ Object
Methods inherited from Barr::Block
#<<, #colors, #destroy, #destroy!, #draw, #reassign_deprecated_option, #tmp_filename, #update
Constructor Details
#initialize(opts = {}) ⇒ Bspwm
Returns a new instance of Bspwm.
11 12 13 14 15 16 |
# File 'lib/barr/blocks/bspwm.rb', line 11 def initialize opts={} super @monitor = opts[:monitor] || first_monitor @invert_focus_colors = opts[:invert_focus_colors] || false @focus_markers = opts[:focus_markers] || %w(> <) end |
Instance Attribute Details
#focus_markers ⇒ Object (readonly)
Returns the value of attribute focus_markers.
9 10 11 |
# File 'lib/barr/blocks/bspwm.rb', line 9 def focus_markers @focus_markers end |
#invert_focus_colors ⇒ Object
Returns the value of attribute invert_focus_colors.
10 11 12 |
# File 'lib/barr/blocks/bspwm.rb', line 10 def invert_focus_colors @invert_focus_colors end |
#monitor ⇒ Object (readonly)
Returns the value of attribute monitor.
9 10 11 |
# File 'lib/barr/blocks/bspwm.rb', line 9 def monitor @monitor end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
9 10 11 |
# File 'lib/barr/blocks/bspwm.rb', line 9 def tree @tree end |
Instance Method Details
#bsp_tree ⇒ Object
39 40 41 |
# File 'lib/barr/blocks/bspwm.rb', line 39 def bsp_tree @tree ||= JSON.parse(sys_cmd) end |
#first_monitor ⇒ Object
63 64 65 |
# File 'lib/barr/blocks/bspwm.rb', line 63 def first_monitor bsp_tree["primaryMonitorName"] end |
#focused_desktop(desktop) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/barr/blocks/bspwm.rb', line 43 def focused_desktop desktop op = "" op += invert_colors if @invert_focus_colors op += @focus_markers[0] + " " op += desktop["name"] op += " " + @focus_markers[1] op += invert_colors if @invert_focus_colors op end |
#sys_cmd ⇒ Object
67 68 69 |
# File 'lib/barr/blocks/bspwm.rb', line 67 def sys_cmd `bspc wm -d`.chomp end |
#unfocused_desktop(desktop) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/barr/blocks/bspwm.rb', line 54 def unfocused_desktop desktop op = "" op += "%{A:bspc desktop -f #{desktop["name"].gsub(":","\:")}:} " op += "#{desktop["name"]}" op += " %{A}" return op end |
#update! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/barr/blocks/bspwm.rb', line 18 def update! @tree = nil op = [] focused = "" bsp_tree["monitors"].each do |monitor| next if monitor["name"] != @monitor focused = monitor["focusedDesktopName"] monitor["desktops"].each do |desktop| if desktop["name"] == focused op << focused_desktop(desktop) else op << unfocused_desktop(desktop) end end end @output = op.join(" ") end |