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

view

the view object which contains this area



496
497
498
499
# File 'lib/rumai/wm.rb', line 496

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.



491
492
493
# File 'lib/rumai/wm.rb', line 491

def view
  @view
end

Class Method Details

.currObject

Returns the currently focused area.



522
523
524
# File 'lib/rumai/wm.rb', line 522

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

.floating(view = View.curr) ⇒ Object

Returns the floating area in the given view.



529
530
531
# File 'lib/rumai/wm.rb', line 529

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.



538
539
540
# File 'lib/rumai/wm.rb', line 538

def chain
  @view.areas
end

#client_idsObject

Returns the IDs of the clients in this area.



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

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)


511
512
513
# File 'lib/rumai/wm.rb', line 511

def column?
  not floating?
end

#concat(area) ⇒ Object

Concatenates the given area to the bottom of this area.



653
654
655
# File 'lib/rumai/wm.rb', line 653

def concat area
  push area.clients
end

#each(&block) ⇒ Object

Iterates through each client in this container.



563
564
565
# File 'lib/rumai/wm.rb', line 563

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

#exist?Boolean

Checks if this object exists in the chain.

Returns:

  • (Boolean)


545
546
547
# File 'lib/rumai/wm.rb', line 545

def exist?
  chain.include? self
end

#floating?Boolean

Checks if this area is the floating area.

Returns:

  • (Boolean)


504
505
506
# File 'lib/rumai/wm.rb', line 504

def floating?
  @id == FLOATING_AREA_ID
end

#focusObject

Puts focus on this area.



586
587
588
# File 'lib/rumai/wm.rb', line 586

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

#insert(*clients) ⇒ Object

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



624
625
626
627
628
629
630
631
# File 'lib/rumai/wm.rb', line 624

def insert *clients
  clients.flatten!
  return if clients.empty?

  clients.each do |c|
    import_client c
  end
end

#layout=(mode) ⇒ Object

Sets the layout of clients in this column.



570
571
572
573
574
575
576
577
# File 'lib/rumai/wm.rb', line 570

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.



597
598
599
# File 'lib/rumai/wm.rb', line 597

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.



663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
# File 'lib/rumai/wm.rb', line 663

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.



604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/rumai/wm.rb', line 604

def push *clients
  clients.flatten!
  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.



636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/rumai/wm.rb', line 636

def unshift *clients
  clients.flatten!
  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