uh 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1aab3d0e275ff50fdfa5f47250089dd20697f559
4
- data.tar.gz: 39853f92956681040368032c73c6a1bc0b71e011
3
+ metadata.gz: fcc44fc2385e50268d20f0a051066da0530f2ecd
4
+ data.tar.gz: 0c56a49e7e4a4716719b39b60df88ce83c0ef968
5
5
  SHA512:
6
- metadata.gz: 4d7de87048027b604563a94af2772d77b1b843f8779205e45894a255706ef200b8a09abf7b0a831d02d7dadae8f0616d738a0c4f3d1b519c54f872ca961743a8
7
- data.tar.gz: df157ac6be33b4a588c35b3966ed2a3fe0e598b56835df5e88746b86d8e86f90d93a0211e4b67fe0cb7e830ff247ad5c16e8d38f9372153372023c1a04cfc38a
6
+ metadata.gz: 39baca396e76b1a771080ea03e75d40423bceb7343145eba7adc66a83599c6487443eba06acd12532aa50837dfc31d3d28cb595c15437e54d0e760bf2cea8c61
7
+ data.tar.gz: b92d40aa23835104a271c86ddeb2edb445bafa27884cb4d84d973b6bd164f4cf479c2b6e440a9b8da98b854be3cda6708c3ffc15d71c4b9e43af5dfa868b7cd2
data/lib/uh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Uh
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.1.8'.freeze
3
3
  end
data/lib/uh/wm.rb CHANGED
@@ -42,6 +42,8 @@ module Uh
42
42
  def_delegator :@logger, :info, :log
43
43
  def_delegator :@logger, :error, :log_error
44
44
 
45
+ attr_reader :keys, :rules
46
+
45
47
  def initialize(layout, &block)
46
48
  @layout = layout
47
49
  @display = Display.new
@@ -51,10 +53,7 @@ module Uh
51
53
  end
52
54
  @manager = Manager.new(@logger)
53
55
  @keys = {}
54
-
55
- @manager.on_manage do |client|
56
- @display.listen_events client.window, PROPERTY_CHANGE_MASK
57
- end
56
+ @rules = {}
58
57
 
59
58
  return unless block_given?
60
59
  if block.arity == 1 then yield self else instance_eval &block end
@@ -71,6 +70,12 @@ module Uh
71
70
  @keys[[key, mod_mask]] = block
72
71
  end
73
72
 
73
+ def rule(selectors, &block)
74
+ [*selectors].each do |selector|
75
+ @rules[/\A#{selector}/i] = block
76
+ end
77
+ end
78
+
74
79
  def on_init(&block)
75
80
  @on_init = block
76
81
  end
@@ -183,7 +188,14 @@ module Uh
183
188
  end
184
189
 
185
190
  def handle_map_request(event)
186
- @manager.map event.window
191
+ if client = @manager.map(event.window)
192
+ @display.listen_events event.window, PROPERTY_CHANGE_MASK
193
+ @rules.each do |selector, action|
194
+ if client.wclass =~ selector
195
+ ActionHandler.new(self, @manager, @layout).call action
196
+ end
197
+ end
198
+ end
187
199
  end
188
200
 
189
201
  def handle_property_notify(event)
data/lib/uh/wm/manager.rb CHANGED
@@ -9,7 +9,6 @@ module Uh
9
9
  def initialize(logger)
10
10
  @logger = logger
11
11
  @clients = []
12
- @on_manage = []
13
12
  end
14
13
 
15
14
  def to_s
@@ -21,7 +20,7 @@ module Uh
21
20
  end
22
21
 
23
22
  def on_manage(&block)
24
- @on_manage << block
23
+ @on_manage = block
25
24
  end
26
25
 
27
26
  def on_unmanage(&block)
@@ -46,14 +45,15 @@ module Uh
46
45
 
47
46
  def map(window)
48
47
  if window.override_redirect?
49
- log "#{self.class.name}#map window.override_redirect, skipping"
48
+ log "#{self.class.name}#map #{window}.override_redirect, skipping"
50
49
  return
51
50
  end
52
51
 
53
52
  if client = client_for(window)
54
53
  log "#{self.class.name}#map #{client}, already managed"
54
+ nil
55
55
  else
56
- manage Client.new(window)
56
+ Client.new(window).tap { |o| manage o }
57
57
  end
58
58
  end
59
59
 
@@ -85,7 +85,7 @@ module Uh
85
85
  def manage(client)
86
86
  log "#{self.class.name}#manage #{client}"
87
87
  @clients << client
88
- @on_manage.each { |e| e.call client }
88
+ @on_manage.call client if @on_manage
89
89
  end
90
90
 
91
91
  def unmanage(client)
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+ require 'uh/wm'
3
+
4
+ module Uh
5
+ describe WM do
6
+ subject { WM.new(Object.new) }
7
+
8
+ it 'has no rules' do
9
+ assert_empty subject.rules
10
+ end
11
+
12
+ describe '#rule' do
13
+ let(:block) { proc { } }
14
+
15
+ it 'registers a new rule' do
16
+ subject.rule 'client', &block
17
+ assert_equal 1, subject.rules.size
18
+ end
19
+
20
+ it 'transforms the given selector as a regexp' do
21
+ subject.rule 'client', &block
22
+ assert_equal /\Aclient/i, subject.rules.keys[0]
23
+ end
24
+
25
+ it 'assigns the given block' do
26
+ subject.rule 'client', &block
27
+ assert_includes subject.rules.values, block
28
+ end
29
+
30
+ it 'accepts an array of selectors' do
31
+ subject.rule %w[foo bar], &block
32
+ assert_equal [/\Afoo/i, /\Abar/i], subject.rules.keys
33
+ end
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
@@ -108,6 +108,7 @@ files:
108
108
  - lib/uh/wm/workers/multiplexing_worker.rb
109
109
  - test/test_helper.rb
110
110
  - test/uh/test_geo.rb
111
+ - test/uh/test_wm.rb
111
112
  - uh.gemspec
112
113
  homepage: https://rubygems.org/gems/uh
113
114
  licenses: []
@@ -135,4 +136,5 @@ summary: Xlib simplified toolkit
135
136
  test_files:
136
137
  - test/test_helper.rb
137
138
  - test/uh/test_geo.rb
139
+ - test/uh/test_wm.rb
138
140
  has_rdoc: