wmiirc-rumai

git clone git://oldgit.suckless.org/wmiirc-rumai/
Log | Files | Refs | README | LICENSE

commit 7986a71694bfa39e1132205a9d2efc14e512a001
parent fcf5d220af0587823bed9a1b9ba9c84d8bd1853a
Author: Suraj N. Kurapati <sunaku@gmail.com>
Date:   Tue, 12 Sep 2006 08:19:46 -0700

[project @ 6eabd75b5ffe66c6bdf6749d93d4ec97bc87c80b]

[project @ 74]
IXPException are no longer hidden away... exceptions should be handled
note  still largely untested code that must handle exceptions now

Diffstat:
fs.rb | 45++++++++++++++-------------------------------
wm.rb | 30++++++++++++++++--------------
wmiish | 2+-
3 files changed, 31 insertions(+), 46 deletions(-)

diff --git a/fs.rb b/fs.rb @@ -31,27 +31,18 @@ module Ixp # Creates a file at the given path. def self.create aPath - begin - @@ixp.create aPath - rescue IXP::IXPException => e - puts e, e.backtrace - end + @@ixp.create aPath end # Deletes the given path. def self.remove aPath - begin - @@ixp.remove aPath - rescue IXP::IXPException => e - puts e, e.backtrace - end + @@ixp.remove aPath end # Writes the given content to the given path. def self.write aPath, aContent open(aPath) do |f| f.write aContent.to_s - # puts '', "#{self.class}.write #{aPath}, #{aContent.inspect}", caller # if $DEBUG end end @@ -73,31 +64,24 @@ module Ixp end end - # Returns true if the given path is a file. + # Tests if the given path is a file. def self.file? aPath - open(aPath) {|f| f.instance_of? IXP::File} + open(aPath) {|f| f.instance_of? IXP::File} rescue false end - # Returns true if the given path is a directory. + # Tests if the given path is a directory. def self.directory? aPath - open(aPath) {|f| f.instance_of? IXP::Directory} + open(aPath) {|f| f.instance_of? IXP::Directory} rescue false end - # Returns true if the given path exists. + # Tests if the given path exists. def self.exist? aPath - open(aPath) {true} + open(aPath) {true} rescue false end # Opens the given path for reading and writing and passes it to the given block. - def self.open aPath # :yields: IO - if block_given? - begin - @@ixp.open(aPath) do |f| - return yield(f) - end - rescue IXP::IXPException - end - end + def self.open aPath, &aBlock # :yields: IO + @@ixp.open aPath, &aBlock end # An entry in the IXP file system. @@ -130,17 +114,17 @@ module Ixp Ixp.read @path end - # Returns true if this node is a file. + # Tests if this node is a file. def file? Ixp.file? @path end - # Returns true if this node is a directory. + # Tests if this node is a directory. def directory? Ixp.directory? @path end - # Returns true if this node exists in the file system. + # Tests if this node exists in the file system. def exist? Ixp.exist? @path end @@ -166,8 +150,7 @@ module Ixp # Writes to the given sub-path. def []= aSubPath, aContent - child = Ixp::Node.new("#{@path}/#{aSubPath}") - child.write! aContent if child.file? + Ixp::Node.new("#{@path}/#{aSubPath}").write! aContent end # Provides easy access to sub-nodes. diff --git a/wm.rb b/wm.rb @@ -80,11 +80,14 @@ module Wmii areas.each do |a| if a.indices.detect {|i| i == aClientId} + puts "found client #{a[aClientId].inspect}" return a[aClientId] end end end + puts "could not find #{aClientId}" + nil end @@ -136,9 +139,10 @@ module Wmii # A region in the window manager's hierarchy. class Node < Ixp::Node - def initialize aParentClass, aChildClass, *aArgs + def initialize aParentClass, aChildClass, aFocusCommand, *aArgs @parentClass = aParentClass @childClass = aChildClass + @focusCmd = aFocusCommand super(*aArgs) end @@ -170,11 +174,7 @@ module Wmii # Returns a list of indices of items in this region. def indices - if list = self.read - list.grep(/^\d+$/).map {|s| s.to_i} - else - [] - end + self.read.grep(/^\d+$/).map {|s| s.to_i} rescue [] end # Returns a list of items in this region. @@ -205,15 +205,13 @@ module Wmii # Puts focus on this region. def focus! - ['select', 'view'].each do |cmd| - parent.ctl = "#{cmd} #{basename}" - end + parent.ctl = "#{@focusCmd} #{basename}" end end class Client < Node def initialize *aArgs - super Area, Ixp::Node, *aArgs + super Area, Ixp::Node, :select, *aArgs end undef index @@ -278,7 +276,7 @@ module Wmii class Area < Node def initialize *aArgs - super View, Client, *aArgs + super View, Client, :select, *aArgs end alias clients children @@ -315,7 +313,10 @@ module Wmii end setup_for_insertion! aClients.shift - clients.first.ctl = 'swap down' + + if top = clients.first + top.ctl = 'swap down' + end dst = self.index aClients.each do |c| @@ -342,7 +343,7 @@ module Wmii maxIdx = parent.indices.last maxCol = parent[maxIdx] - aFirstClient = Wmii.find_client(aFirstClient.index, maxCol) + aFirstClient = Wmii.find_client(aFirstClient.basename, maxCol) # move *into* final destination if maxCol.indices.length > 1 @@ -362,7 +363,7 @@ module Wmii class View < Node def initialize *aArgs - super Ixp::Node, Area, *aArgs + super Ixp::Node, Area, :view, *aArgs end alias areas children @@ -450,6 +451,7 @@ end class Array alias original_each each + # Supports destructive operations on each client in this array. def each return unless block_given? diff --git a/wmiish b/wmiish @@ -30,7 +30,7 @@ require 'irb/completion' module IRB # Starts IRB within the context of the given object. def IRB.start_session aContextObj - IRB.setup nil unless $irb + IRB.setup __FILE__ unless $irb ws = WorkSpace.new(aContextObj)