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

Class Method Summary

Instance Method Summary

Methods included from WidgetImpl

#==, #current?

Methods included from Chain

#next, #prev

Methods included from ClientContainer

#clients, #grouping

Constructor Details

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

A new instance of Area

Parameters:

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

    the view object which contains this area



494
495
496
497
# File 'lib/rumai/wm.rb', line 494

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



488
489
490
# File 'lib/rumai/wm.rb', line 488

def view
  @view
end

Class Method Details

+ (Object) curr

Returns the currently focused area.



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

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

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

Returns the floating area in the given view.



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

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.



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

def chain
  @view.areas
end

- (Object) client_ids

Returns the IDs of the clients in this area.



552
553
554
# File 'lib/rumai/wm.rb', line 552

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)


509
510
511
# File 'lib/rumai/wm.rb', line 509

def column?
  not floating?
end

- (Object) concat(area)

Concatenates the given area to the bottom of this area.



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

def concat area
  push area.clients
end

- (Object) each(&block)

Iterates through each client in this container.



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

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

- (Boolean) exist?

Checks if this object exists in the chain.

Returns:

  • (Boolean)


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

def exist?
  chain.include? self
end

- (Boolean) floating?

Checks if this area is the floating area.

Returns:

  • (Boolean)


502
503
504
# File 'lib/rumai/wm.rb', line 502

def floating?
  @id == FLOATING_AREA_ID
end

- (Object) focus

Puts focus on this area.



584
585
586
# File 'lib/rumai/wm.rb', line 584

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

- (Object) insert(*clients)

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



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

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

  clients.each do |c|
    import_client c
  end
end

- (Object) layout=(mode)

Sets the layout of clients in this column.



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

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.



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

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.



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

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.



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

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

- (Object) unshift(*clients)

Inserts the given clients at the top of this area.



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

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