commit 3b503edeb98edeeaa467be9532797c647edde40f
parent 2c5c78209ab2f720d5ff5c5eca4028601a3f3824
Author: Suraj N. Kurapati <sunaku@gmail.com>
Date: Sun, 24 Sep 2006 13:09:17 -0700
[project @ 8f9ba50c9ba31c648f582b50e316b7aaa480896d]
add two-stage event handling, to minimize # of events missed while processing an event
Diffstat:
2 files changed, 43 insertions(+), 32 deletions(-)
diff --git a/wmiirc b/wmiirc
@@ -46,6 +46,8 @@ LOG.info "starting"
end
# load the configuration
+ Thread.abort_on_exception = true
+
begin
load File.join(File.dirname(__FILE__), 'wmiirc-config.rb')
diff --git a/wmiirc-config.rb b/wmiirc-config.rb
@@ -427,38 +427,47 @@ end
## WM event loop
-FS['event'].open do |f|
- while event = f.read.chomp
- type, arg = event.split(' ', 2)
-
- case type.to_sym
- when :BarClick
- clickedView, clickedButton = arg.split
-
- case clickedButton.to_i
- when PRIMARY_CLICK
- Wmii.focus_view clickedView
-
- when MIDDLE_CLICK
- Wmii.selected_clients.each do |c|
- c.tag! clickedView
- end
-
- when SECONDARY_CLICK
- Wmii.selected_clients.each do |c|
- c.untag! clickedView
- end
- end
-
- when :ClientClick
- clickedClient, clickedButton = arg.split
-
- if clickedButton.to_i != PRIMARY_CLICK
- Wmii.get_client(clickedClient).invert_selection!
- end
-
- when :Key
- SHORTCUTS[arg].call
+require 'thread'
+events = Queue.new
+
+Thread.new do
+ FS['event'].open do |f|
+ loop do
+ events.enq f.read.chomp
end
end
end
+
+while evt = events.deq
+ type, arg = evt.split(' ', 2)
+
+ case type.to_sym
+ when :BarClick
+ clickedView, clickedButton = arg.split
+
+ case clickedButton.to_i
+ when PRIMARY_CLICK
+ Wmii.focus_view clickedView
+
+ when MIDDLE_CLICK
+ Wmii.selected_clients.each do |c|
+ c.tag! clickedView
+ end
+
+ when SECONDARY_CLICK
+ Wmii.selected_clients.each do |c|
+ c.untag! clickedView
+ end
+ end
+
+ when :ClientClick
+ clickedClient, clickedButton = arg.split
+
+ if clickedButton.to_i != PRIMARY_CLICK
+ Wmii.get_client(clickedClient).invert_selection!
+ end
+
+ when :Key
+ SHORTCUTS[arg].call
+ end
+end