commit 5b0db9a54aa160b7652e834c30abcfd506aafcd6
parent fe7dc60a030abc3d89529e5ebbd4fc54702e8471
Author: Suraj N. Kurapati <sunaku@gmail.com>
Date: Thu, 31 Aug 2006 07:34:40 -0700
[project @ 6bc701346b6f2c507a6ad11e612e3c9eede17c53]
[project @ 24]
add doc comments
fix indentation
up Container#indices doesn't give in reverse order
Diffstat:
| wmii.rb | | | 34 | +++++++++++++++++++++++++++------- |
| wmiirc | | | 120 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
2 files changed, 87 insertions(+), 67 deletions(-)
diff --git a/wmii.rb b/wmii.rb
@@ -92,6 +92,7 @@ class IxpFile
end
end
+ # Provides easy access to files contained within this file.
def method_missing aMeth, *aArgs
if aMeth.to_s =~ /=$/
write "#{@path}/#{$`}", *aArgs
@@ -101,6 +102,7 @@ class IxpFile
else
super
+
end
end
end
@@ -120,26 +122,32 @@ class Wmii < IxpFile
# WM state access
#
+ # Returns the currently focused client.
def current_client
Client.new("/view/sel/sel")
end
+ # Returns the currently focused area.
def current_area
Area.new("/view/sel")
end
+ # Returns the currently focused view.
def current_view
View.new("/view")
end
+ # Returns the current set of tags.
def tags
read('/tags').split
end
+ # Returns the current set of views.
def views
- tags.map {|v| View.new self, "/#{v}"}
+ tags.map {|v| View.new "/#{v}"}
end
+ # Returns the current set of clients.
def clients
Area.new("/client").clients
end
@@ -306,6 +314,7 @@ class Wmii < IxpFile
list
end
+ # Un-selects all selected clients.
def select_none
View.new("/#{SELECTION_TAG}").unselect!
end
@@ -322,7 +331,7 @@ class Wmii < IxpFile
# Attach the most recently detached client
def attach_last_client
- if c = View.new("/#{DETACHED_TAG}").areas.first.clients.first
+ if c = View.new("/#{DETACHED_TAG}").areas.last.clients.last
c.tags = read('/view/name')
end
end
@@ -361,45 +370,52 @@ class Wmii < IxpFile
##
- # subclasses
+ # Subclasses for more abstraction
#
+ # Encapsulates a graphical region and its file system properties.
class Container < IxpFile
+ # Returns a list of indices of items in this region.
def indices
if list = read(@path)
- # go in reverse order to accomodate destructive procedures
- list.split.grep(/^\d+$/).reverse
+ list.split.grep(/^\d+$/)
else
[]
end
end
+ # Returns a list of items in this region.
def subordinates
if @subordinateClass
- indices.map {|i| @subordinateClass.new "#{@path}/#{i}"}
+ # go in reverse order to accomodate destructive procedures
+ indices.reverse.map {|i| @subordinateClass.new "#{@path}/#{i}"}
else
[]
end
end
+ # Adds all clients in this region to the selection.
def select!
subordinates.each do |s|
s.select!
end
end
+ # Removes all clients in this region from the selection.
def unselect!
subordinates.each do |s|
s.unselect!
end
end
+ # Inverts the selection of clients in this region.
def invert_selection!
subordinates.each do |s|
s.invert_selection!
end
end
+ # Puts focus on this region.
def focus!
['select', 'view'].each do |cmd|
return if write "#{@path}/../ctl", "#{cmd} #{File.basename @path}"
@@ -407,24 +423,28 @@ class Wmii < IxpFile
end
end
+ # Represents a running, graphical program.
class Client < Container
TAG_DELIMITER = "+"
+ # Returns the tags associated with this client.
def tags
read("#{@path}/tags").split(TAG_DELIMITER)
end
+ # Modifies the tags associated with this client.
def tags= *aTags
write "#{@path}/tags", aTags.flatten.uniq.join(TAG_DELIMITER)
end
- # Do stuff (the given block) with this client's tags.
+ # Invokes the given block within the context of this client's list of tags.
def with_tags &aBlock
t = self.tags
t.instance_eval(&aBlock)
self.tags = t
end
+ # Returns true if this client is included in the selection.
def selected?
tags.include? SELECTION_TAG
end
diff --git a/wmiirc b/wmiirc
@@ -188,10 +188,10 @@ SHORTCUTS = {
"#{MENU}a" => lambda do
# prepare a list of menu choices
choices = WM.read('/client').split.inject([]) do |acc, id|
- tags = WM.read("/client/#{id}/tags")
- name = WM.read("/client/#{id}/name").downcase
+ tags = WM.read("/client/#{id}/tags")
+ name = WM.read("/client/#{id}/name").downcase
- acc << format("%d. [%s] %s", id, tags, name)
+ acc << format("%d. [%s] %s", id, tags, name)
end
@@ -199,7 +199,7 @@ SHORTCUTS = {
target = WM.show_menu(choices.join("\n"))
unless target.empty?
- WM.focus_client target.scan(/\d+/).first
+ WM.focus_client target.scan(/\d+/).first
end
end,
@@ -211,25 +211,25 @@ SHORTCUTS = {
"#{SEND}#{LEFT}" => lambda do
WM.selected_clients.each do |c|
- c.ctl = 'sendto prev'
+ c.ctl = 'sendto prev'
end
end,
"#{SEND}#{RIGHT}" => lambda do
WM.selected_clients.each do |c|
- c.ctl = 'sendto next'
+ c.ctl = 'sendto next'
end
end,
"#{SEND}space" => lambda do
WM.selected_clients.each do |c|
- c.ctl = 'sendto toggle'
+ c.ctl = 'sendto toggle'
end
end,
"#{SEND}Delete" => lambda do
WM.selected_clients.each do |c|
- c.ctl = 'kill'
+ c.ctl = 'kill'
end
end,
@@ -240,31 +240,31 @@ SHORTCUTS = {
target = WM.show_menu(choices.join("\n"))
WM.selected_clients.each do |c|
- c.with_tags do
- case target
- when /^\+/
- push $'
-
- when /^\-/
- delete $'
-
- else
- clear
- push target
- end
- end
+ c.with_tags do
+ case target
+ when /^\+/
+ push $'
+
+ when /^\-/
+ delete $'
+
+ else
+ clear
+ push target
+ end
+ end
end
end,
"#{SEND}d" => lambda do
# WM.with_selection do
- WM.detach_current_client
+ WM.detach_current_client
# end
end,
"#{SEND}Shift-d" => lambda do
# WM.with_selection do
- WM.attach_last_client
+ WM.attach_last_client
# end
end,
@@ -286,50 +286,50 @@ SHORTCUTS = {
k = (i - 1) % 10 # associate '1' with the leftmost label, instead of '0'
SHORTCUTS["#{FOCUS}#{i}"] = lambda do
- WM.focus_view(WM.read('/tags').split[k] || i)
+ WM.focus_view(WM.read('/tags').split[k] || i)
end
SHORTCUTS["#{SEND}#{i}"] = lambda do
- WM.write '/view/sel/sel/tags', (WM.read('/tags').split[k] || i)
+ WM.write '/view/sel/sel/tags', (WM.read('/tags').split[k] || i)
end
SHORTCUTS["#{LAYOUT}#{i}"] = lambda do
- WM.apply_grid_layout i
+ WM.apply_grid_layout i
end
# shortcuts for adding and removing tags of a client
SHORTCUTS["#{SEND}equal,#{i}"] =
SHORTCUTS["#{SEND}Shift-equal,#{i}"] = lambda do
- WM.selected_clients.each do |c|
- c.with_tags do
- push(WM.tags[k] || i)
- end
- end
+ WM.selected_clients.each do |c|
+ c.with_tags do
+ push(WM.tags[k] || i)
+ end
+ end
end
SHORTCUTS["#{SEND}minus,#{i}"] = lambda do
- WM.selected_clients.each do |c|
- c.with_tags do
- delete(WM.tags[k] || i)
- end
- end
+ WM.selected_clients.each do |c|
+ c.with_tags do
+ delete(WM.tags[k] || i)
+ end
+ end
end
SHORTCUTS["#{SEND}Shift-minus"] = lambda do
- WM.selected_clients.each do |c|
- c.with_tags do
- delete WM.current_view.name
- end
- end
+ WM.selected_clients.each do |c|
+ c.with_tags do
+ delete WM.current_view.name
+ end
+ end
end
end
('a'..'z').each do |char|
SHORTCUTS["#{MENU}v,#{char}"] = lambda do
- if view = WM.tags.select {|t| t =~ /^#{char}/i}.first
- WM.focus_view view
- end
+ if view = WM.tags.select {|t| t =~ /^#{char}/i}.first
+ WM.focus_view view
+ end
end
end
@@ -347,8 +347,8 @@ WM.config.keys = SHORTCUTS.keys.join("\n")
status.colors = ENV['WMII_NORMCOLORS']
loop do
- status.data = Time.now.to_s << " " << `uptime`.scan(/\d+\.\d+/).join(' ')
- sleep 5
+ status.data = Time.now.to_s << " " << `uptime`.scan(/\d+\.\d+/).join(' ')
+ sleep 5
end
end
@@ -359,25 +359,25 @@ WM.config.keys = SHORTCUTS.keys.join("\n")
begin
IO.popen('wmiir read /event') do |io|
while event = io.readline.chomp
- type, arg = event.split($;, 2)
+ type, arg = event.split($;, 2)
- p event, type, arg if $DEBUG
+ p event, type, arg if $DEBUG
- case type
- when 'Start'
- exit if arg == 'wmiirc'
+ case type
+ when 'Start'
+ exit if arg == 'wmiirc'
- when 'BarClick'
- view, button = arg.split
- WM.focus_view view
+ when 'BarClick'
+ view, button = arg.split
+ WM.focus_view view
- when 'ClientClick'
- client, button = arg.split
- Wmii::Client.new("/client/#{client}").invert_selection!
+ when 'ClientClick'
+ client, button = arg.split
+ Wmii::Client.new("/client/#{client}").invert_selection!
- when 'Key'
- SHORTCUTS[arg].call
- end
+ when 'Key'
+ SHORTCUTS[arg].call
+ end
end
end
rescue EOFError