commit 6891941013de08a4c38b74db404f1e6b2977f02e
parent 8f1a726b306014e1857b6f65417674d517a3e4fa
Author: Suraj N. Kurapati <sunaku@gmail.com>
Date: Thu, 31 Aug 2006 01:34:33 -0700
[project @ 52277d186dd75614d25dedcfc16b45dd0fb1cdfc]
[project @ 15]
add Wmii#with_selection method
up send left, right, toggle, and kill shortcuts accordingly
Diffstat:
| wmii.rb | | | 32 | +++++++++++++++++++++++++------- |
| wmiirc | | | 27 | +++++++++++++++++++++++---- |
2 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/wmii.rb b/wmii.rb
@@ -57,12 +57,32 @@ class Wmii
tags.map {|v| View.new self, "/#{v}"}
end
+ def clients
+ Area.new(self, "/client").clients
+ end
+
def select_none
View.new(self, "/#{SELECTION_TAG}").unselect!
end
- def with_selection # :yields: client
- #todo
+ # Invokes the given block upon all selected clients in the current view. If there are no selected clients, then the block is invoked upon the currently focused client.
+ def with_selection # :yields: client
+ # determine selected clients in current view
+ clientList = current_view.areas.map do |a|
+ a.clients.select do |c|
+ c.tags.include? SELECTION_TAG
+ end
+ end
+ clientList.flatten!
+
+ if clientList.empty?
+ clientList << current_client
+ end
+
+ clientList.each do |c|
+ c.focus!
+ yield c
+ end
end
# Creates the given WM path.
@@ -85,7 +105,6 @@ class Wmii
# Writes the given content to the given WM path.
def write aPath, aContent
- p "writing: #{aPath}", aContent if $DEBUG
begin
@cl.open(aPath) do |f|
f.write aContent.to_s
@@ -118,7 +137,7 @@ class Wmii
# Shows the view with the given name.
def showView aName
- write '/ctl', "view #{aName}"
+ View.new(self, "/#{aName}").focus!
end
# Shows a WM menu with the given content and returns its output.
@@ -167,9 +186,8 @@ class Wmii
# Changes the current view to an adjacent one (:left or :right).
def cycleView aTarget
- tags = read('/tags').split
-
- curTag = read('/view/name')
+ tags = self.tags
+ curTag = current_view.name
curIndex = tags.index(curTag)
newIndex =
diff --git a/wmiirc b/wmiirc
@@ -145,10 +145,29 @@ SHORTCUTS = {
"#{PROGRAM}j" => lambda do system 'nautilus --no-desktop &' end,
- "#{SEND}#{LEFT}" => lambda do WM.write '/view/sel/sel/ctl', 'sendto prev' end,
- "#{SEND}#{RIGHT}" => lambda do WM.write '/view/sel/sel/ctl', 'sendto next' end,
- "#{SEND}space" => lambda do WM.write '/view/sel/sel/ctl', 'sendto toggle' end,
- "#{SEND}Delete" => lambda do WM.write '/view/sel/sel/ctl', 'kill' end,
+ "#{SEND}#{LEFT}" => lambda do
+ WM.with_selection do
+ WM.write '/view/sel/sel/ctl', 'sendto prev'
+ end
+ end,
+
+ "#{SEND}#{RIGHT}" => lambda do
+ WM.with_selection do
+ WM.write '/view/sel/sel/ctl', 'sendto next'
+ end
+ end,
+
+ "#{SEND}space" => lambda do
+ WM.with_selection do
+ WM.write '/view/sel/sel/ctl', 'sendto toggle'
+ end
+ end,
+
+ "#{SEND}Delete" => lambda do
+ WM.with_selection do
+ WM.write '/view/sel/sel/ctl', 'kill'
+ end
+ end,
# change the tag of the current client
# +tag -tag idea from Jonas Pfenniger <http://zimbatm.oree.ch/articles/2006/06/15/wmii-3-and-ruby>