Register clients in manager on map requests

This commit is contained in:
Thibault Jouan 2015-04-16 11:59:13 +00:00
parent 6e90225c9d
commit a0dcca07f9
2 changed files with 22 additions and 6 deletions

View File

@ -7,12 +7,13 @@ module Uh
Events::SUBSTRUCTURE_NOTIFY_MASK | Events::SUBSTRUCTURE_NOTIFY_MASK |
Events::STRUCTURE_NOTIFY_MASK Events::STRUCTURE_NOTIFY_MASK
attr_reader :modifier, :display attr_reader :modifier, :display, :clients
def initialize events, modifier, display = Display.new def initialize events, modifier, display = Display.new
@events = events @events = events
@modifier = modifier @modifier = modifier
@display = display @display = display
@clients = []
end end
def connect def connect
@ -50,7 +51,8 @@ module Uh
event.key.to_sym event.key.to_sym
@events.emit :key, *key_selector @events.emit :key, *key_selector
when :map_request when :map_request
@events.emit :manage, args: event.window @clients << client = Client.new(event.window)
@events.emit :manage, args: client
end end
end end

View File

@ -11,6 +11,10 @@ module Uh
expect(manager.display).to be_a Display expect(manager.display).to be_a Display
end end
it 'has no clients' do
expect(manager.clients).to be_empty
end
describe '#connect', :xvfb do describe '#connect', :xvfb do
it 'opens the display' do it 'opens the display' do
expect(manager.display).to receive(:open).and_call_original expect(manager.display).to receive(:open).and_call_original
@ -139,12 +143,22 @@ module Uh
context 'when map_request event is given' do context 'when map_request event is given' do
let(:event) { double 'event', type: :map_request, window: :window } let(:event) { double 'event', type: :map_request, window: :window }
it 'emits :manage event' do it 'registers a new client wrapping the event window' do
events.on(:manage) { throw :manage_code } manager.handle event
expect { manager.handle event }.to throw_symbol :manage_code expect(manager.clients[0])
.to be_a(Client)
.and have_attributes(window: :window)
end end
it 'emits :manage event with the client' it 'emits :manage event with the registered client' do
events.on :manage, &block
expect(block).to receive :call do |client|
expect(client)
.to be_a(Client)
.and have_attributes(window: :window)
end
manager.handle event
end
end end
end end
end end