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

near, #next, next, prev, #prev

Methods included from WidgetImpl

#==, #current?

Constructor Details

- (Area) initialize(area_id, view = View.curr)

A new instance of Area

Parameters:

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

    the view object which contains this area



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

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

Instance Attribute Details

- (Object) view (readonly)

Returns the value of attribute view



536
537
538
# File 'lib/rumai/wm.rb', line 536

def view
  @view
end

Class Method Details

+ (Object) curr

Returns the currently focused area.



570
571
572
# File 'lib/rumai/wm.rb', line 570

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

+ (Object) floating(view = View.curr)

Returns the floating area in the given view.



577
578
579
# File 'lib/rumai/wm.rb', line 577

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

Instance Method Details

- (Object) chain

Returns a list of all areas in the current view.



588
589
590
# File 'lib/rumai/wm.rb', line 588

def chain
  @view.areas
end

- (Object) client_ids

Returns the IDs of the clients in this area.



606
607
608
# File 'lib/rumai/wm.rb', line 606

def client_ids
  @view.client_ids @id
end

- (Boolean) column? Also known as: managed?

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

Returns:

  • (Boolean)


557
558
559
# File 'lib/rumai/wm.rb', line 557

def column?
  not floating?
end

- (Object) concat(area)

Concatenates the given area to the bottom of this area.



702
703
704
# File 'lib/rumai/wm.rb', line 702

def concat area
  push *area.clients
end

- (Object) each(&block)

Iterates through each client in this container.



617
618
619
# File 'lib/rumai/wm.rb', line 617

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

- (Boolean) exist?

Checks if this object exists in the chain.

Returns:

  • (Boolean)


595
596
597
# File 'lib/rumai/wm.rb', line 595

def exist?
  chain.include? self
end

- (Boolean) floating?

Checks if this area is the floating area.

Returns:

  • (Boolean)


550
551
552
# File 'lib/rumai/wm.rb', line 550

def floating?
  @id == FLOATING_AREA_ID
end

- (Object) focus

Puts focus on this area.



628
629
630
# File 'lib/rumai/wm.rb', line 628

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

- (Object) insert(*clients)

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



677
678
679
680
681
# File 'lib/rumai/wm.rb', line 677

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

- (Object) layout=(mode)

Sets the layout of clients in this column.



635
636
637
638
639
640
641
642
# File 'lib/rumai/wm.rb', line 635

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

- (Object) length

Returns the number of clients in this area.



651
652
653
# File 'lib/rumai/wm.rb', line 651

def length
  client_ids.length
end

- (Object) length=(max_clients)

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.



712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
# File 'lib/rumai/wm.rb', line 712

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

- (Object) push(*clients) Also known as: <<

Inserts the given clients at the bottom of this area.



658
659
660
661
662
663
664
665
666
667
668
669
# File 'lib/rumai/wm.rb', line 658

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

- (Object) unshift(*clients)

Inserts the given clients at the top of this area.



686
687
688
689
690
691
692
693
694
695
696
697
# File 'lib/rumai/wm.rb', line 686

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