commit 0663fd8b984d3c6d1dde96b9db4e997a4e4fb594
parent 833fa847eda19c244a0e4761344a0008b143126d
Author: Suraj N. Kurapati <sunaku@gmail.com>
Date: Thu, 31 Aug 2006 05:51:29 -0700
[project @ c522670e2586dddfd6b8d864c3fed5503bd7e5ec]
[project @ 21]
up visual reformatting
mv status script as a thread in wmiirc
Diffstat:
| status | | | 17 | ----------------- |
| wmii.rb | | | 185 | +++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- |
| wmiirc | | | 43 | ++++++++++++++++++++++++++++++++++++++++--- |
3 files changed, 150 insertions(+), 95 deletions(-)
diff --git a/status b/status
@@ -1,17 +0,0 @@
-#!/usr/bin/ruby -w
-# periodically print date and load average to the bar
-
-$: << File.dirname(__FILE__)
-require 'wmii'
-
-DELAY = 1
-
-WM = Wmii.instance
-
-WM.remove '/bar/status'
-WM.create '/bar/status'
-WM.write '/bar/status/colors', ENV['WMII_NORMCOLORS']
-
-while WM.write('/bar/status/data', Time.now.to_s << " " << `uptime`.scan(/\d+\.\d+/).join(' '))
- sleep DELAY
-end
diff --git a/wmii.rb b/wmii.rb
@@ -27,6 +27,14 @@ require 'singleton'
class Wmii
include Singleton
+ SELECTION_TAG = 'SEL'
+ DETACHED_TAG = 'status'
+
+
+ ##
+ # IXP file system
+ #
+
def initialize
begin
@cl = IXP::Client.new
@@ -35,50 +43,6 @@ class Wmii
end
end
- SELECTION_TAG = 'SEL'
-
- def current_client
- Client.new(self, "/view/sel/sel")
- end
-
- def current_area
- Area.new(self, "/view/sel")
- end
-
- def current_view
- View.new(self, "/view")
- end
-
- def tags
- read('/tags').split
- end
-
- def views
- 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
-
- # Returns a list of all selected clients in the current view. If there are no selected clients, then the currently focused client is returned in the list.
- def selected_clients
- list = current_view.areas.map do |a|
- a.clients.select do |c| c.selected? end
- end
- list.flatten!
-
- if list.empty?
- list << current_client
- end
-
- list
- end
-
# Creates the given WM path.
def create aPath
begin
@@ -129,26 +93,46 @@ class Wmii
end
end
- # Shows the view with the given name.
- def focus_view aName
- View.new(self, "/#{aName}").focus!
+
+ ##
+ # WM state access
+ #
+
+ def current_client
+ Client.new(self, "/view/sel/sel")
end
- # Shows a WM menu with the given content and returns its output.
- def show_menu aContent
- output = nil
+ def current_area
+ Area.new(self, "/view/sel")
+ end
- IO.popen('wmiimenu', 'r+') do |menu|
- menu.write aContent
- menu.close_write
+ def current_view
+ View.new(self, "/view")
+ end
- output = menu.read
- end
+ def tags
+ read('/tags').split
+ end
- output
+ def views
+ tags.map {|v| View.new self, "/#{v}"}
+ end
+
+ def clients
+ Area.new(self, "/client").clients
+ end
+
+
+ ##
+ # WM state manipulation
+ #
+
+ # Focuses the view with the given name.
+ def focus_view aName
+ View.new(self, "/#{aName}").focus!
end
- # Shows the client which has the given ID.
+ # Focuses the client which has the given ID.
def focus_client aClientId
views.each do |v|
v.areas.each do |a|
@@ -164,20 +148,6 @@ class Wmii
end
end
- DETACHED_TAG = 'status'
-
- # Detach the currently selected client
- def detach_current_client
- current_client.tags = DETACHED_TAG
- end
-
- # Attach the most recently detached client
- def attach_last_client
- if c = View.new(self, "/#{DETACHED_TAG}").areas.first.clients.first
- c.tags = read('/view/name')
- end
- end
-
# Changes the current view to an adjacent one (:left or :right).
def cycle_view aTarget
tags = self.tags
@@ -200,6 +170,11 @@ class Wmii
focus_view tags[newIndex]
end
+
+ ##
+ # View arrangement
+ #
+
# Applies wmii-2 style tiling layout to the current view while maintaining the order of clients in the current view. Only the first client in the primary column is kept; all others are evicted to the *top* of the secondary column. Any teritiary, quaternary, etc. columns are squeezed into the *bottom* of the secondary column.
def apply_tiling_layout
areaList = read('/view').split.grep(/^[^0]\d*$/)
@@ -290,6 +265,65 @@ class Wmii
end
end
+
+ ##
+ # Multiple client selection
+ #
+
+ # Returns a list of all selected clients in the current view. If there are no selected clients, then the currently focused client is returned in the list.
+ def selected_clients
+ list = current_view.areas.map do |a|
+ a.clients.select do |c| c.selected? end
+ end
+ list.flatten!
+
+ if list.empty?
+ list << current_client
+ end
+
+ list
+ end
+
+ def select_none
+ View.new(self, "/#{SELECTION_TAG}").unselect!
+ end
+
+
+ ##
+ # wmii-2 style client detaching
+ #
+
+ # Detach the currently selected client
+ def detach_current_client
+ current_client.tags = DETACHED_TAG
+ end
+
+ # Attach the most recently detached client
+ def attach_last_client
+ if c = View.new(self, "/#{DETACHED_TAG}").areas.first.clients.first
+ c.tags = read('/view/name')
+ end
+ end
+
+
+ ##
+ # Utility methods
+ #
+
+ # Shows a WM menu with the given content and returns its output.
+ def show_menu aContent
+ output = nil
+
+ IO.popen('wmiimenu', 'r+') do |menu|
+ menu.write aContent
+ menu.close_write
+
+ output = menu.read
+ end
+
+ output
+ end
+
# Returns a list of program names available in the given paths.
def find_programs *aPaths
list = []
@@ -304,6 +338,11 @@ class Wmii
end
+ ##
+ # Subclasses
+ #
+
+ # Encapsulates access to a file in the IXP file system
class IxpFile
attr_reader :wm, :path
@@ -326,7 +365,6 @@ class Wmii
end
end
-
class Container < IxpFile
def indices
if list = @wm.read(@path)
@@ -370,7 +408,6 @@ class Wmii
end
end
-
class Client < Container
TAG_DELIMITER = "+"
@@ -414,7 +451,6 @@ class Wmii
end
end
-
class Area < Container
def initialize *args
super
@@ -424,7 +460,6 @@ class Wmii
alias clients subordinates
end
-
class View < Container
def initialize *args
super
diff --git a/wmiirc b/wmiirc
@@ -23,18 +23,27 @@ require 'wmii'
WM = Wmii.instance
+##
# WM STARTUP
-# terminate other running wmiirc
-sleep 1 until WM.write('/event', "Start wmiirc\n")
+#
+# terminate other running wmiirc's
+ sleep 1 until WM.write('/event', "Start wmiirc\n")
+
+##
# UI CONFIGURATION
+#
+
ENV['WMII_FONT'] = '-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1'
ENV['WMII_SELCOLORS']='#ffffff #285577 #4c7899'
ENV['WMII_NORMCOLORS']='#222222 #eeeeee #666666'
+##
# WM CONFIGURATION
+#
+
WM.write '/def/border', 2
WM.write '/def/font', ENV['WMII_FONT']
WM.write '/def/selcolors', ENV['WMII_SELCOLORS']
@@ -43,7 +52,10 @@ WM.write '/def/colmode', 'default'
WM.write '/def/colwidth', 0
+##
# TAGGING RULES
+#
+
WM.write '/def/rules', <<EOF
/QEMU.*/ -> ~
/jEdit.*/ -> code
@@ -59,15 +71,20 @@ WM.write '/def/rules', <<EOF
EOF
+##
# MISC CONFIGURATION
+#
+
# system 'xsetroot -solid "#333333"'
-system 'status &'
PROGRAM_MENU = WM.find_programs(*ENV['PATH'].split(':')).join("\n")
ACTION_MENU = WM.find_programs('/home/sun/dry/apps/wmii/etc/wmii-3', '~/.wmii-3').join("\n")
+##
# KEY CONFIGURATION
+#
+
MODKEY='Mod1'
UP='t'
DOWN='n'
@@ -325,7 +342,27 @@ WM.write '/def/grabmod', MODKEY
WM.write '/def/keys', SHORTCUTS.keys.join("\n")
+##
+# MINI SCRIPTS
+#
+
+# display time and system status in the bar
+ Thread.new do
+ status = Wmii::IxpFile.new(WM, "/bar/status")
+ WM.create status.path
+
+ status.colors = ENV['WMII_NORMCOLORS']
+
+ loop do
+ status.data = Time.now.to_s << " " << `uptime`.scan(/\d+\.\d+/).join(' ')
+ sleep 5
+ end
+ end
+
+##
# EVENT LOOP
+#
+
begin
IO.popen('wmiir read /event') do |io|
while event = io.readline.chomp