From 15f966654b0d20de0169a18fa036d9eb0bbdaae1 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Thu, 16 Apr 2015 18:28:17 +0000 Subject: [PATCH 1/4] Implement client visibility state --- lib/uh/wm/client.rb | 13 +++++++++++-- spec/uh/wm/client_spec.rb | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/uh/wm/client.rb b/lib/uh/wm/client.rb index afb1802..ec08d3e 100644 --- a/lib/uh/wm/client.rb +++ b/lib/uh/wm/client.rb @@ -5,14 +5,23 @@ module Uh attr_accessor :geo def initialize window, geo = nil - @window = window - @geo = geo + @window = window + @geo = geo + @visible = false 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 diff --git a/spec/uh/wm/client_spec.rb b/spec/uh/wm/client_spec.rb index f8b8d60..06a81bb 100644 --- a/spec/uh/wm/client_spec.rb +++ b/spec/uh/wm/client_spec.rb @@ -8,6 +8,14 @@ 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 + describe '#to_s' do it 'includes window name' do expect(client.to_s).to include 'wname' From 870e11a7026488416db66256cf7ab081fa351f2f Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Thu, 16 Apr 2015 18:32:22 +0000 Subject: [PATCH 2/4] Implement Client#show --- lib/uh/wm/client.rb | 6 ++++++ spec/uh/wm/client_spec.rb | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/uh/wm/client.rb b/lib/uh/wm/client.rb index ec08d3e..0d80e63 100644 --- a/lib/uh/wm/client.rb +++ b/lib/uh/wm/client.rb @@ -34,6 +34,12 @@ module Uh @window.moveresize @geo self end + + def show + @window.map + @visible = true + self + end end end end diff --git a/spec/uh/wm/client_spec.rb b/spec/uh/wm/client_spec.rb index 06a81bb..da133d4 100644 --- a/spec/uh/wm/client_spec.rb +++ b/spec/uh/wm/client_spec.rb @@ -56,6 +56,23 @@ 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 end end end From 3cf62cc07d06fc75acbaae78ffbcc523b16384ec Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Thu, 16 Apr 2015 18:39:12 +0000 Subject: [PATCH 3/4] Implement Client#hide --- lib/uh/wm/client.rb | 16 ++++++++++++---- spec/uh/wm/client_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/uh/wm/client.rb b/lib/uh/wm/client.rb index 0d80e63..a5c57fc 100644 --- a/lib/uh/wm/client.rb +++ b/lib/uh/wm/client.rb @@ -1,13 +1,14 @@ 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 - @visible = false + @window = window + @geo = geo + @visible = false + @unmap_count = 0 end def to_s @@ -40,6 +41,13 @@ module Uh @visible = true self end + + def hide + @window.unmap + @visible = false + @unmap_count += 1 + self + end end end end diff --git a/spec/uh/wm/client_spec.rb b/spec/uh/wm/client_spec.rb index da133d4..482d385 100644 --- a/spec/uh/wm/client_spec.rb +++ b/spec/uh/wm/client_spec.rb @@ -16,6 +16,10 @@ module Uh 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' @@ -73,6 +77,30 @@ module Uh 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 end end end From b4240a8b4f8c32f8627438c533887376b085d3fd Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Thu, 16 Apr 2015 18:42:25 +0000 Subject: [PATCH 4/4] Implement Client#focus --- lib/uh/wm/client.rb | 6 ++++++ spec/uh/wm/client_spec.rb | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/uh/wm/client.rb b/lib/uh/wm/client.rb index a5c57fc..90828b2 100644 --- a/lib/uh/wm/client.rb +++ b/lib/uh/wm/client.rb @@ -48,6 +48,12 @@ module Uh @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 482d385..0904c88 100644 --- a/spec/uh/wm/client_spec.rb +++ b/spec/uh/wm/client_spec.rb @@ -101,6 +101,22 @@ module Uh 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