Class: Rumai::Area

Inherits:
Object show all
Includes:
Enumerable, Chain, ClientContainer, WidgetImpl
Defined in:
lib/rumai/wm.rb

Overview

A region that contains clients. This can be either the floating area or a column in the managed area.

Instance Attribute Summary collapse

Attributes included from WidgetImpl

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClientContainer

#clients, #grouping

Methods included from Chain

#next, #prev

Methods included from WidgetImpl

#==, #current?

Constructor Details

#initialize(area_id, view = View.curr) ⇒ Area

Returns a new instance of Area.

Parameters:

  • view (Rumai::View) (defaults to: View.curr)

    the view object which contains this area



526
527
528
529
# File 'lib/rumai/wm.rb', line 526

def initialize area_id, view = View.curr
  @id = Integer(area_id) rescue area_id
  @view = view
end

Instance Attribute Details

#viewObject (readonly)

Returns the value of attribute view.



520
521
522
# File 'lib/rumai/wm.rb', line 520

def view
  @view
end

Class Method Details

.currObject

Returns the currently focused area.



554
555
556
# File 'lib/rumai/wm.rb', line 554

def self.curr
  View.curr.area_of_client Client.curr
end

.floating(view = View.curr) ⇒ Object

Returns the floating area in the given view.



561
562
563
# File 'lib/rumai/wm.rb', line 561

def self.floating view = View.curr
  new FLOATING_AREA_ID, view
end

Instance Method Details

#chainObject

Returns a list of all areas in the current view.



572
573
574
# File 'lib/rumai/wm.rb', line 572

def chain
  @view.areas
end

#client_idsObject

Returns the IDs of the clients in this area.



590
591
592
# File 'lib/rumai/wm.rb', line 590

def client_ids
  @view.client_ids @id
end

#column?Boolean Also known as: managed?

Checks if this is a managed area (a column).

Returns:

  • (Boolean)


541
542
543
# File 'lib/rumai/wm.rb', line 541

def column?
  not floating?
end

#concat(area) ⇒ Object

Concatenates the given area to the bottom of this area.



686
687
688
# File 'lib/rumai/wm.rb', line 686

def concat area
  push *area.clients
end

#each(&block) ⇒ Object

Iterates through each client in this container.



601
602
603
# File 'lib/rumai/wm.rb', line 601

def each &block
  clients.each(&block)
end

#exist?Boolean

Checks if this object exists in the chain.

Returns:

  • (Boolean)


579
580
581
# File 'lib/rumai/wm.rb', line 579

def exist?
  chain.include? self
end

#floating?Boolean

Checks if this area is the floating area.

Returns:

  • (Boolean)


534
535
536
# File 'lib/rumai/wm.rb', line 534

def floating?
  @id == FLOATING_AREA_ID
end

#focusObject

Puts focus on this area.



612
613
614
# File 'lib/rumai/wm.rb', line 612

def focus
  @view.ctl.write "select #{@id}"
end

#insert(*clients) ⇒ Object

Inserts the given clients after the currently focused client in this area.



661
662
663
664
665
# File 'lib/rumai/wm.rb', line 661

def insert *clients
  clients.each do |c|
    import_client c
  end
end

#layout=(mode) ⇒ Object

Sets the layout of clients in this column.



619
620
621
622
623
624
625
626
# File 'lib/rumai/wm.rb', line 619

def layout= mode
  case mode
  when :stack then mode = 'stack-max'
  when :max   then mode = 'stack+max'
  end

  @view.ctl.write "colmode #{@id} #{mode}"
end

#lengthObject

Returns the number of clients in this area.



635
636
637
# File 'lib/rumai/wm.rb', line 635

def length
  client_ids.length
end

#length=(max_clients) ⇒ Object

Ensures that this area has at most the given number of clients.

Areas to the right of this one serve as a buffer into which excess clients are evicted and from which deficit clients are imported.



696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
# File 'lib/rumai/wm.rb', line 696

def length= max_clients
  return unless max_clients > 0
  len, out = length, fringe

  if len > max_clients
    out.unshift *clients[max_clients..-1]

  elsif len < max_clients
    until (diff = max_clients - length) == 0
      importable = out.clients[0, diff]
      break if importable.empty?

      push *importable
    end
  end
end

#push(*clients) ⇒ Object Also known as: <<

Inserts the given clients at the bottom of this area.



642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/rumai/wm.rb', line 642

def push *clients
  return if clients.empty?

  insert *clients

  # move inserted clients to bottom
  clients.reverse.each_with_index do |c, i|
    until c.id == self.client_ids[-i.succ]
      c.send :down
    end
  end
end

#unshift(*clients) ⇒ Object

Inserts the given clients at the top of this area.



670
671
672
673
674
675
676
677
678
679
680
681
# File 'lib/rumai/wm.rb', line 670

def unshift *clients
  return if clients.empty?

  insert *clients

  # move inserted clients to top
  clients.each_with_index do |c, i|
    until c.id == self.client_ids[i]
      c.send :up
    end
  end
end