Class: Rumai::View

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

Overview

The visualization of a tag.

Instance Attribute Summary

Attributes included from WidgetImpl

#id

Attributes inherited from Node

#path

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?

Methods inherited from Node

#[], #children, #clear, #create, #directory?, #each_line, #entries, #exist?, #method_missing, #open, #parent, #read, #remove, #stat, #write

Methods included from ExportInstanceMethods

extended

Constructor Details

#initialize(view_id) ⇒ View

Returns a new instance of View.



760
761
762
# File 'lib/rumai/wm.rb', line 760

def initialize view_id
  super view_id, '/tag'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rumai::Node

Class Method Details

.currObject

Returns the currently focused view.



721
722
723
# File 'lib/rumai/wm.rb', line 721

def self.curr
  new FOCUSED_WIDGET_ID
end

Instance Method Details

#area_idsObject

Returns the IDs of all areas in this view.



806
807
808
# File 'lib/rumai/wm.rb', line 806

def area_ids
  manifest.scan(/^# (\d+)/).flatten.unshift(FLOATING_AREA_ID)
end

#area_of_client(client_or_id) ⇒ Object

Returns the area which contains the given client in this view.



789
790
791
792
793
794
795
796
797
798
799
800
801
# File 'lib/rumai/wm.rb', line 789

def area_of_client client_or_id
  arg =
    if client_or_id.respond_to? :id
      client_or_id.id
    else
      client_or_id
    end

  manifest =~ /^(\S+) #{arg}/
  if area_id = $1
    Area.new area_id, self
  end
end

#areasObject

Returns all areas in this view.



813
814
815
# File 'lib/rumai/wm.rb', line 813

def areas
  area_ids.map! {|i| Area.new i, self }
end

#arrange_as_larswmObject

Arranges the clients in this view, while maintaining their relative order, in the tiling fashion of LarsWM.

Only the first client in the primary column is kept; all others are evicted to the top of the secondary column. Any subsequent columns are squeezed into the bottom of the secondary column.



867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
# File 'lib/rumai/wm.rb', line 867

def arrange_as_larswm
  maintain_focus do
    # keep only one client in the primary column
    main = Area.new(1, self)
    main.length = 1
    main.layout = :default

    # collapse remaining areas into secondary column
    extra = squeeze_columns(1..-1)

    if dock = extra.first
      dock.layout = :default
    end
  end
end

#arrange_in_diamondObject

Arranges the clients in this view, while maintaining their relative order, in a (at best) equilateral triangle. However, the resulting arrangement appears like a diamond because wmii does not waste screen space.



940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
# File 'lib/rumai/wm.rb', line 940

def arrange_in_diamond
  num_clients = num_managed_clients
  return unless num_clients > 1

  # determine dimensions of the rising sub-triangle
  rise = num_clients / 2

  span = sum = 0
  1.upto rise do |h|
    if sum + h > rise
      break
    else
      sum += h
      span += 1
    end
  end

  peak = num_clients - (sum * 2)

  # describe the overall triangle as a sequence of heights
  rise_seq = (1..span).to_a
  fall_seq = rise_seq.reverse

  heights = rise_seq
  heights << peak if peak > 0
  heights.concat fall_seq

  # apply the heights
  maintain_focus do
    each_column do |col|
      if h = heights.shift
        col.length = h
        col.layout = :default
      end
    end
  end
end

#arrange_in_grid(max_clients_per_column = nil) ⇒ Object

Arranges the clients in this view, while maintaining their relative order, in a (at best) square grid.



887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
# File 'lib/rumai/wm.rb', line 887

def arrange_in_grid max_clients_per_column = nil
  # compute client distribution
  unless max_clients_per_column
    num_clients = num_managed_clients
    return unless num_clients > 0

    num_columns = Math.sqrt(num_clients)
    max_clients_per_column = (num_clients / num_columns).round
  end

  return if max_clients_per_column < 1

  # apply the distribution
  maintain_focus do
    each_column do |a|
      a.length = max_clients_per_column
      a.layout = :default
    end
  end
end

#arrange_in_stacks(num_stacks) ⇒ Object

Arranges the clients in this view, while maintaining their relative order, in the given number of columns.



912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
# File 'lib/rumai/wm.rb', line 912

def arrange_in_stacks num_stacks
  return if num_stacks < 1

  # compute client distribution
  num_clients = num_managed_clients
  return unless num_clients > 0

  stack_length = num_clients / num_stacks
  return if stack_length < 1

  # apply the distribution
  maintain_focus do
    each_column do |a|
      a.length = stack_length
      a.layout = :stack
    end

    squeeze_columns num_stacks-1..-1
  end
end

#chainObject

Returns a list of all views.



737
738
739
# File 'lib/rumai/wm.rb', line 737

def chain
  Rumai.views
end

#client_ids(area_id = '\S+') ⇒ Object

Returns the IDs of the clients contained in the given area within this view.



747
748
749
# File 'lib/rumai/wm.rb', line 747

def client_ids area_id = '\S+'
  manifest.scan(/^#{area_id} (0x\S+)/).flatten
end

#columnsObject Also known as: managed_areas

Returns all columns (managed areas) in this view.



827
828
829
# File 'lib/rumai/wm.rb', line 827

def columns
  areas[1..-1]
end

#each(&block) ⇒ Object

Iterates through each area in this view.



756
757
758
# File 'lib/rumai/wm.rb', line 756

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

#each_column(starting_column_id = 1) ⇒ Object Also known as: each_managed_area

Resiliently iterates through possibly destructive changes to each column. That is, if the given block creates new columns, then those will also be processed in the iteration.



838
839
840
841
842
843
844
845
846
847
848
849
850
851
# File 'lib/rumai/wm.rb', line 838

def each_column starting_column_id = 1
  i = starting_column_id
  loop do
    a = Area.new i, self

    if a.exist?
      yield a
    else
      break
    end

    i += 1
  end
end

#floating_areaObject

Returns the floating area of this view.



820
821
822
# File 'lib/rumai/wm.rb', line 820

def floating_area
  Area.floating self
end

#focusObject

Focuses this view.



728
729
730
# File 'lib/rumai/wm.rb', line 728

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

#manifestObject

Returns the manifest of all areas and clients in this view.



771
772
773
# File 'lib/rumai/wm.rb', line 771

def manifest
  index.read || ''
end

#select(direction) ⇒ Object

Moves the focus from the current client in the given direction.



778
779
780
# File 'lib/rumai/wm.rb', line 778

def select direction
  ctl.write "select #{direction}"
end