Class: Rumai::View
- Inherits:
-
WidgetNode
- Object
- Node
- WidgetNode
- Rumai::View
- Includes:
- Enumerable, Chain, ClientContainer, WidgetImpl
- Defined in:
- lib/rumai/wm.rb
Overview
The visualization of a tag.
Instance Attribute Summary
Attributes included from WidgetImpl
Attributes inherited from Node
Class Method Summary collapse
-
.curr ⇒ Object
Returns the currently focused view.
Instance Method Summary collapse
-
#area_ids ⇒ Object
Returns the IDs of all areas in this view.
-
#area_of_client(client_or_id) ⇒ Object
Returns the area which contains the given client in this view.
-
#areas ⇒ Object
Returns all areas in this view.
-
#arrange_columns(lengths, layout = nil) ⇒ Object
Applies the given length to each column in sequence.
-
#chain ⇒ Object
Returns a list of all views.
-
#client_ids(area_id = '\S+') ⇒ Object
Returns the IDs of the clients contained in the given area within this view.
-
#columns ⇒ Object
(also: #managed_areas)
Returns all columns (managed areas) in this view.
-
#each(&block) ⇒ Object
Iterates through each area in this view.
-
#each_column(starting_column_id = 1) ⇒ Object
(also: #each_managed_area)
Resiliently iterates through possibly destructive changes to each column.
-
#floating_area ⇒ Object
Returns the floating area of this view.
-
#focus ⇒ Object
Focuses this view.
-
#grid(max_clients_per_column = nil) ⇒ Object
(also: #arrange_in_grid)
Arranges the clients in this view, while maintaining their relative order, in (at best) a square grid.
-
#initialize(view_id) ⇒ View
constructor
A new instance of View.
-
#manifest ⇒ Object
Returns the manifest of all areas and clients in this view.
-
#select(direction) ⇒ Object
Moves the focus from the current client in the given direction.
-
#stack(num_columns = 2) ⇒ Object
(also: #arrange_in_stacks)
Arranges the clients in this view, while maintaining their relative order, in the given number of columns.
-
#tile_inward ⇒ Object
(also: #arrange_in_diamond)
Arranges columns with the following number of clients in them:.
-
#tile_left ⇒ Object
Arranges columns with the following number of clients in them:.
-
#tile_leftward ⇒ Object
Arranges columns with the following number of clients in them:.
-
#tile_outward ⇒ Object
Arranges columns with the following number of clients in them:.
-
#tile_right ⇒ Object
(also: #arrange_as_larswm)
Arranges columns with the following number of clients in them:.
-
#tile_rightward ⇒ Object
Arranges columns with the following number of clients in them:.
Methods included from ClientContainer
Methods included from Chain
Methods included from WidgetImpl
Methods inherited from Node
#[], #children, #clear, #create, #directory?, #each_line, #entries, #exist?, #method_missing, #open, #parent, #read, #remove, #stat, #write
Methods included from ExportInstanceMethods
Constructor Details
#initialize(view_id) ⇒ View
Returns a new instance of View.
749 750 751 |
# File 'lib/rumai/wm.rb', line 749 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
.curr ⇒ Object
Returns the currently focused view.
760 761 762 |
# File 'lib/rumai/wm.rb', line 760 def self.curr new FOCUSED_WIDGET_ID end |
Instance Method Details
#area_ids ⇒ Object
Returns the IDs of all areas in this view.
847 848 849 |
# File 'lib/rumai/wm.rb', line 847 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.
830 831 832 833 834 835 836 837 838 839 840 841 842 |
# File 'lib/rumai/wm.rb', line 830 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 |
#areas ⇒ Object
Returns all areas in this view.
854 855 856 |
# File 'lib/rumai/wm.rb', line 854 def areas area_ids.map! {|i| Area.new i, self } end |
#arrange_columns(lengths, layout = nil) ⇒ Object
Applies the given length to each column in sequence. Also, the given layout is applied to all columns, if specified.
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 |
# File 'lib/rumai/wm.rb', line 1031 def arrange_columns lengths, layout = nil i = 0 maintain_focus do each_column do |column| if i < lengths.length column.length = lengths[i] column.layout = layout if layout i += 1 else break end end end end |
#chain ⇒ Object
Returns a list of all views.
778 779 780 |
# File 'lib/rumai/wm.rb', line 778 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.
790 791 792 |
# File 'lib/rumai/wm.rb', line 790 def client_ids area_id = '\S+' manifest.scan(/^#{area_id} (0x\S+)/).flatten end |
#columns ⇒ Object Also known as: managed_areas
Returns all columns (managed areas) in this view.
868 869 870 |
# File 'lib/rumai/wm.rb', line 868 def columns areas[1..-1] end |
#each(&block) ⇒ Object
Iterates through each area in this view.
801 802 803 |
# File 'lib/rumai/wm.rb', line 801 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.
879 880 881 882 883 884 885 886 887 888 889 890 891 892 |
# File 'lib/rumai/wm.rb', line 879 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_area ⇒ Object
Returns the floating area of this view.
861 862 863 |
# File 'lib/rumai/wm.rb', line 861 def floating_area Area.floating self end |
#focus ⇒ Object
Focuses this view.
767 768 769 |
# File 'lib/rumai/wm.rb', line 767 def focus IXP_FS_ROOT.ctl.write "view #{@id}" end |
#grid(max_clients_per_column = nil) ⇒ Object Also known as: arrange_in_grid
Arranges the clients in this view, while maintaining their relative order, in (at best) a square grid.
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 |
# File 'lib/rumai/wm.rb', line 1001 def 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 |
#manifest ⇒ Object
Returns the manifest of all areas and clients in this view.
812 813 814 |
# File 'lib/rumai/wm.rb', line 812 def manifest index.read || '' end |
#select(direction) ⇒ Object
Moves the focus from the current client in the given direction.
819 820 821 |
# File 'lib/rumai/wm.rb', line 819 def select direction ctl.write "select #{direction}" end |
#stack(num_columns = 2) ⇒ Object Also known as: arrange_in_stacks
Arranges the clients in this view, while maintaining their relative order, in the given number of columns.
991 992 993 994 995 |
# File 'lib/rumai/wm.rb', line 991 def stack num_columns = 2 heights = [num_managed_clients / num_columns] * num_columns heights[-1] += num_managed_clients % num_columns arrange_columns heights, :stack end |
#tile_inward ⇒ Object Also known as: arrange_in_diamond
Arranges columns with the following number of clients in them:
1, 2, 3, …, 3, 2, 1
Imagine two equilateral triangles with their bases on the left and right sides of the screen and their peaks meeting in the middle of the screen.
956 957 958 |
# File 'lib/rumai/wm.rb', line 956 def tile_inward arrange_columns calculate_equilateral_triangle.flatten, :default end |
#tile_left ⇒ Object
Arranges columns with the following number of clients in them:
N, 1
929 930 931 |
# File 'lib/rumai/wm.rb', line 929 def tile_left arrange_columns [num_managed_clients-1, 1], :default end |
#tile_leftward ⇒ Object
Arranges columns with the following number of clients in them:
…, 3, 2, 1
Imagine an equilateral triangle with its base on the left side of the screen and its peak on the right side of the screen.
942 943 944 945 946 |
# File 'lib/rumai/wm.rb', line 942 def tile_leftward width, summit = calculate_right_triangle heights = (1 .. width).to_a.push(summit).reverse arrange_columns heights, :default end |
#tile_outward ⇒ Object
Arranges columns with the following number of clients in them:
…, 3, 2, 1, 2, 3, …
Imagine two equilateral triangles with their bases meeting in the middle of the screen and their peaks reaching outward to the left and right sides of the screen.
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 |
# File 'lib/rumai/wm.rb', line 969 def tile_outward rising, summit, falling = calculate_equilateral_triangle heights = falling[0..-2].concat(rising) # distribute extra clients on the outsides extra = summit[0].to_i + falling[-1].to_i if extra > 0 split = extra / 2 carry = extra % 2 # put the remainder on the left side to minimize the need for # rearrangement when clients are removed or added to the view heights.unshift split + carry heights.push split end arrange_columns heights, :default end |
#tile_right ⇒ Object Also known as: arrange_as_larswm
Arranges columns with the following number of clients in them:
1, N
905 906 907 |
# File 'lib/rumai/wm.rb', line 905 def tile_right arrange_columns [1, num_managed_clients-1], :default end |
#tile_rightward ⇒ Object
Arranges columns with the following number of clients in them:
1, 2, 3, …
Imagine an equilateral triangle with its base on the right side of the screen and its peak on the left side of the screen.
918 919 920 921 922 |
# File 'lib/rumai/wm.rb', line 918 def tile_rightward width, summit = calculate_right_triangle heights = (1 .. width).to_a.push(summit) arrange_columns heights, :default end |