diff --git a/lib/uh/wm/client.rb b/lib/uh/wm/client.rb index 328ccfa..c24b040 100644 --- a/lib/uh/wm/client.rb +++ b/lib/uh/wm/client.rb @@ -66,6 +66,20 @@ module Uh @window.focus self end + + def kill + if @window.icccm_wm_protocols.include? :WM_DELETE_WINDOW + @window.icccm_wm_delete + else + @window.kill + end + self + end + + def kill! + window.kill + self + end end end end diff --git a/spec/support/factories.rb b/spec/support/factories.rb index 73c32ab..3c7381a 100644 --- a/spec/support/factories.rb +++ b/spec/support/factories.rb @@ -17,11 +17,12 @@ module Factories modifier_mask: modifier_mask end - def mock_window override_redirect: false + def mock_window override_redirect: false, icccm_wm_protocols: [] instance_spy Uh::Window, 'window', to_s: 'wid', name: 'wname', wclass: 'wclass', - override_redirect?: override_redirect + override_redirect?: override_redirect, + icccm_wm_protocols: icccm_wm_protocols end end diff --git a/spec/uh/wm/client_spec.rb b/spec/uh/wm/client_spec.rb index d074646..807743c 100644 --- a/spec/uh/wm/client_spec.rb +++ b/spec/uh/wm/client_spec.rb @@ -1,7 +1,8 @@ module Uh module WM RSpec.describe Client do - let(:window) { mock_window } + let(:protocols) { [] } + let(:window) { mock_window icccm_wm_protocols: protocols } let(:geo) { build_geo } subject(:client) { described_class.new window, geo } @@ -143,6 +144,37 @@ module Uh expect(client.focus).to be client end end + + describe '#kill' do + it 'kills the window' do + expect(window).to receive :kill + client.kill + end + + it 'returns self' do + expect(client.kill).to be client + end + + context 'when window supports icccm wm delete' do + let(:protocols) { [:WM_DELETE_WINDOW] } + + it 'icccm deletes the window' do + expect(window).to receive :icccm_wm_delete + client.kill + end + end + end + + describe '#kill!' do + it 'kills the window' do + expect(window).to receive :kill + client.kill! + end + + it 'returns self' do + expect(client.kill!).to be client + end + end end end end