Implement Manager#unmap

This commit is contained in:
Thibault Jouan 2015-04-20 10:17:51 +00:00
parent 7722909c22
commit 09d7b6ebb5
2 changed files with 60 additions and 0 deletions

View File

@ -61,6 +61,16 @@ module Uh
@events.emit :manage, args: client @events.emit :manage, args: client
end end
def unmap window
return unless client = client_for(window)
if client.unmap_count > 0
client.unmap_count -= 1
else
@clients.delete client
@events.emit :unmanage, args: client
end
end
def handle_next_event def handle_next_event
handle @display.next_event handle @display.next_event
end end

View File

@ -164,6 +164,56 @@ module Uh
end end
end end
describe '#unmap' do
before { manager.map window }
context 'when client unmap count is 0 or less' do
it 'preserves the client unmap count' do
client = manager.clients[0]
expect { manager.unmap window }
.not_to change { client.unmap_count }
end
it 'unregisters the client' do
expect { manager.unmap window }
.to change { manager.clients.size }.from(1).to 0
end
it 'emits :unmanage event with the client' do
events.on :unmanage, &block
expect(block).to receive(:call).with manager.clients[0]
manager.unmap window
end
end
context 'when client unmap count is strictly positive' do
before { manager.clients[0].unmap_count += 1 }
it 'does not unregister the client' do
expect { manager.unmap window }.not_to change { manager.clients }
end
it 'decrements the unmap count' do
manager.unmap window
expect(manager.clients[0].unmap_count).to eq 0
end
end
context 'with unknown window' do
let(:unknown_window) { window.dup }
it 'does not change registered clients' do
expect { manager.unmap unknown_window }
.not_to change { manager.clients }
end
it 'does not emit any event' do
expect(events).not_to receive :emit
manager.unmap unknown_window
end
end
end
describe '#handle_next_event' do describe '#handle_next_event' do
it 'handles the next available event on display' do it 'handles the next available event on display' do
event = double 'event' event = double 'event'