Class: Barr::Blocks::I3

Inherits:
Barr::Block show all
Defined in:
lib/barr/blocks/i3.rb

Instance Attribute Summary collapse

Attributes inherited from Barr::Block

#align, #bgcolor, #fgcolor, #icon, #interval, #output

Instance Method Summary collapse

Methods inherited from Barr::Block

#<<, #colors, #destroy, #draw, #reassign_deprecated_option, #update

Constructor Details

#initialize(opts = {}) ⇒ I3

Returns a new instance of I3.



10
11
12
13
14
15
# File 'lib/barr/blocks/i3.rb', line 10

def initialize(opts = {})
  super

  @focus_markers = opts[:focus_markers] || %w(> <)
  @i3 = i3_connection
end

Instance Attribute Details

#focus_markersObject (readonly)

Returns the value of attribute focus_markers.



8
9
10
# File 'lib/barr/blocks/i3.rb', line 8

def focus_markers
  @focus_markers
end

#i3Object (readonly)

Returns the value of attribute i3.



8
9
10
# File 'lib/barr/blocks/i3.rb', line 8

def i3
  @i3
end

#workspacesObject (readonly)

Returns the value of attribute workspaces.



8
9
10
# File 'lib/barr/blocks/i3.rb', line 8

def workspaces
  @workspaces
end

Instance Method Details

#destroy!Object



29
30
31
# File 'lib/barr/blocks/i3.rb', line 29

def destroy!
  @i3.close
end

#i3_connectionObject



33
34
35
# File 'lib/barr/blocks/i3.rb', line 33

def i3_connection
  I3Ipc::Connection.new
end

#update!Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/barr/blocks/i3.rb', line 17

def update!
  @workspaces = @i3.workspaces.map do |wsp|
    if wsp.focused
      "#{l_marker}#{wsp.name}#{r_marker}"
    else
      "%{A:barr_i3ipc workspace #{wsp.num}:} #{wsp.name} %{A}"
    end
  end

  @output = @workspaces.join('')
end