active_window_x 0.0.2 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,8 @@ module ActiveWindowX
16
16
  # set false if you want to terminate #start loop when next timeout or event receiving
17
17
  attr_accessor :continue
18
18
 
19
+ # _name_ : a display name. if you give nil, EventListener use a Default Display
20
+ # _timeout_ : an intervel to check an interaction for the termination of the listening loop
19
21
  def initialize name=nil, timeout=DEFAULT_TIMEOUT, &block
20
22
  @display = Display.new name
21
23
  @default_timeout = timeout
@@ -52,9 +54,6 @@ module ActiveWindowX
52
54
  event = listen timeout
53
55
  next if not event
54
56
 
55
- if window_closed?(event.window)
56
- event.window = @root.active_window
57
- end
58
57
  yield event if event.type
59
58
  end
60
59
  ensure
@@ -63,7 +62,7 @@ module ActiveWindowX
63
62
  end
64
63
 
65
64
  def destroy
66
- @display.close if @display.closed?
65
+ @display.close
67
66
  end
68
67
 
69
68
  # receive a event
@@ -78,10 +77,19 @@ module ActiveWindowX
78
77
  return nil
79
78
  end
80
79
 
80
+ event = listen_with_no_select
81
+
82
+ event
83
+ end
84
+
85
+ def listen_with_no_select
81
86
  type = nil
82
87
  active_window = nil
83
88
 
84
89
  event = @display.next_event
90
+ if event.class != PropertyEvent
91
+ return nil
92
+ end
85
93
  if event.atom == @aw_atom
86
94
  type = :active_window
87
95
  active_window = @root.active_window
@@ -96,7 +104,20 @@ module ActiveWindowX
96
104
  @active_window.select_input(Xlib::PropertyChangeMask) if @active_window
97
105
  end
98
106
 
99
- Event.new type, active_window
107
+ event = Event.new type, active_window
108
+ if window_closed?(event.window)
109
+ event.window = @root.active_window
110
+ end
111
+
112
+ event
113
+ end
114
+
115
+ def pending_events_num
116
+ @display.pending
117
+ end
118
+
119
+ def connection
120
+ @display.connection
100
121
  end
101
122
 
102
123
  def window_closed? w
@@ -1,3 +1,3 @@
1
1
  module ActiveWindowX
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.2"
3
3
  end
data/sample/simple.rb CHANGED
@@ -2,5 +2,5 @@ require 'rubygems'
2
2
  require 'active_window_x'
3
3
 
4
4
  ActiveWindowX::EventListener.new do |e|
5
- puts "#{e.type}:\t#{e.window ? e.window.name : nil}"
5
+ puts "#{e.type}:\t#{e.window ? e.window.title : nil}"
6
6
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_window_x
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
8
+ - 1
9
9
  - 2
10
- version: 0.0.2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Keiichiro Ui
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-16 00:00:00 Z
18
+ date: 2012-06-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  requirements: []
125
125
 
126
126
  rubyforge_project:
127
- rubygems_version: 1.7.2
127
+ rubygems_version: 1.8.15
128
128
  signing_key:
129
129
  specification_version: 3
130
130
  summary: observer an active window on Linux (X Window System).