diff --git a/lib/uh/wm/client.rb b/lib/uh/wm/client.rb index afb1802..90828b2 100644 --- a/lib/uh/wm/client.rb +++ b/lib/uh/wm/client.rb @@ -1,18 +1,28 @@ module Uh module WM class Client - attr_reader :window + attr_reader :window, :unmap_count attr_accessor :geo def initialize window, geo = nil - @window = window - @geo = geo + @window = window + @geo = geo + @visible = false + @unmap_count = 0 end def to_s "<#{name}> (#{wclass}) #{@geo} win: #{@window}" end + def visible? + @visible + end + + def hidden? + not visible? + end + def name @wname ||= @window.name end @@ -25,6 +35,25 @@ module Uh @window.moveresize @geo self end + + def show + @window.map + @visible = true + self + end + + def hide + @window.unmap + @visible = false + @unmap_count += 1 + self + end + + def focus + @window.raise + @window.focus + self + end end end end diff --git a/spec/uh/wm/client_spec.rb b/spec/uh/wm/client_spec.rb index f8b8d60..0904c88 100644 --- a/spec/uh/wm/client_spec.rb +++ b/spec/uh/wm/client_spec.rb @@ -8,6 +8,18 @@ module Uh end subject(:client) { described_class.new window, geo } + it 'is not visible' do + expect(client).not_to be_visible + end + + it 'is hidden' do + expect(client).to be_hidden + end + + it 'has an unmap count of 0' do + expect(client.unmap_count).to eq 0 + end + describe '#to_s' do it 'includes window name' do expect(client.to_s).to include 'wname' @@ -48,6 +60,63 @@ module Uh expect(client.moveresize).to be client end end + + describe '#show' do + it 'maps the window' do + expect(window).to receive :map + client.show + end + + it 'toggles the client as visible' do + expect { client.show } + .to change { client.visible? } + .from(false).to true + end + + it 'returns self' do + expect(client.show).to be client + end + end + + describe '#hide' do + it 'unmaps the window' do + expect(window).to receive :unmap + client.hide + end + + it 'toggles the client as hidden' do + client.show + expect { client.hide } + .to change { client.hidden? } + .from(false).to true + end + + it 'increments the unmap count' do + expect { client.hide } + .to change { client.unmap_count } + .from(0).to 1 + end + + it 'returns self' do + expect(client.hide).to be client + end + end + + describe '#focus' do + it 'raises the window' do + expect(window).to receive :raise + client.focus + end + + it 'focuses the window' do + expect(window).to receive :focus + client.focus + end + + it 'returns self' do + expect(client.focus).to be client + end + end end end end