diff --git a/lib/uh/wm/manager.rb b/lib/uh/wm/manager.rb index fde8bb2..ce163b6 100644 --- a/lib/uh/wm/manager.rb +++ b/lib/uh/wm/manager.rb @@ -7,12 +7,13 @@ module Uh Events::SUBSTRUCTURE_NOTIFY_MASK | Events::STRUCTURE_NOTIFY_MASK - attr_reader :modifier, :display + attr_reader :modifier, :display, :clients def initialize events, modifier, display = Display.new @events = events @modifier = modifier @display = display + @clients = [] end def connect @@ -50,7 +51,8 @@ module Uh event.key.to_sym @events.emit :key, *key_selector when :map_request - @events.emit :manage, args: event.window + @clients << client = Client.new(event.window) + @events.emit :manage, args: client end end diff --git a/spec/uh/wm/manager_spec.rb b/spec/uh/wm/manager_spec.rb index 0557b31..6fe3a61 100644 --- a/spec/uh/wm/manager_spec.rb +++ b/spec/uh/wm/manager_spec.rb @@ -11,6 +11,10 @@ module Uh expect(manager.display).to be_a Display end + it 'has no clients' do + expect(manager.clients).to be_empty + end + describe '#connect', :xvfb do it 'opens the display' do expect(manager.display).to receive(:open).and_call_original @@ -139,12 +143,22 @@ module Uh context 'when map_request event is given' do let(:event) { double 'event', type: :map_request, window: :window } - it 'emits :manage event' do - events.on(:manage) { throw :manage_code } - expect { manager.handle event }.to throw_symbol :manage_code + it 'registers a new client wrapping the event window' do + manager.handle event + expect(manager.clients[0]) + .to be_a(Client) + .and have_attributes(window: :window) 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