commit a7a489a6e122d09a0bf6c9e95ee5deb6681d5674
parent 686d7f5428f016f599faa3e0f04881cf446b7d47
Author: Suraj N. Kurapati <sunaku@gmail.com>
Date: Mon, 11 Sep 2006 01:11:32 -0700
[project @ 8705901f40bfc8038687f045552467310904b368]
[project @ 56]
spilt Wmii#focus_client into #find_client
up less resource intensive impl of Wmii#with_selection
Diffstat:
fs.rb | | | 1 | + |
wm.rb | | | 57 | +++++++++++++++++++++++++++++++++++++-------------------- |
2 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/fs.rb b/fs.rb
@@ -1,3 +1,4 @@
+## Abstractions for wmii's {IXP file system}[http://wmii.de/contrib/guide/wmii-3/guide-en/guide_en/node9.html] interface.
=begin
Copyright 2006 Suraj N. Kurapati
Copyright 2006 Stephan Maka
diff --git a/wm.rb b/wm.rb
@@ -70,19 +70,38 @@ class Wmii < IxpNode
# Focuses the client which has the given ID.
def focus_client aClientId
+ if c = find_client(aClientId)
+ v = (a = c.parent).parent
+
+ v.focus!
+ a.focus!
+ c.focus!
+ end
+ end
+
+ # Returns the client which has the given ID or +nil+ if not found. The search is performed in the given view, if specified.
+ def find_client aClientId, aView = nil
+ aClientId = aClientId.to_i
needle = Client.new("/client/#{aClientId}")
- haystack = needle.tags.map {|t| View.new("/#{t}")}
-
- haystack.each do |v|
- v.areas.each do |a|
- if a.indices.detect {|i| i == aClientId}
- v.focus!
- a.focus!
- a[aClientId].focus!
- return
+
+ if needle.exist?
+ haystack =
+ if aView && aView.exist?
+ [aView]
+ else
+ needle.tags.map {|t| View.new("/#{t}")}
+ end
+
+ haystack.each do |v|
+ v.areas.each do |a|
+ if a.indices.detect {|i| i == aClientId}
+ return a[aClientId]
+ end
end
end
end
+
+ nil
end
# Changes the currently focused view to an adjacent one (:left or :right).
@@ -133,18 +152,16 @@ class Wmii < IxpNode
def with_selection # :yields: client
return unless block_given?
- oldJobs = []
+ curView = focused_view
- loop do
- selection = selected_clients
- curJobs = selection.map {|c| c.index}
-
- pending = (curJobs - oldJobs)
- break if pending.empty?
+ selected_clients.each do |c|
+ # resolve stale paths caused by destructive operations
+ unless c.exist?
+ c = find_client(File.basename(c.path), curView)
+ c || next # skip upon failure
+ end
- job = pending.shift
- yield selection.detect {|i| i.index == job}
- oldJobs << job
+ yield c
end
end
@@ -432,7 +449,7 @@ class Wmii < IxpNode
end
else
- i = 1
+ i = 1 # skip the floating area
until i >= (areaList = self.areas).length
a = areaList[i]