Merge branch 'client-visibility-handling'

Add client methods needed to manage visibility.
This commit is contained in:
Thibault Jouan 2015-04-16 21:11:24 +00:00
commit 042805b3a2
2 changed files with 101 additions and 3 deletions

View File

@ -1,18 +1,28 @@
module Uh module Uh
module WM module WM
class Client class Client
attr_reader :window attr_reader :window, :unmap_count
attr_accessor :geo attr_accessor :geo
def initialize window, geo = nil def initialize window, geo = nil
@window = window @window = window
@geo = geo @geo = geo
@visible = false
@unmap_count = 0
end end
def to_s def to_s
"<#{name}> (#{wclass}) #{@geo} win: #{@window}" "<#{name}> (#{wclass}) #{@geo} win: #{@window}"
end end
def visible?
@visible
end
def hidden?
not visible?
end
def name def name
@wname ||= @window.name @wname ||= @window.name
end end
@ -25,6 +35,25 @@ module Uh
@window.moveresize @geo @window.moveresize @geo
self self
end 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 end
end end

View File

@ -8,6 +8,18 @@ module Uh
end end
subject(:client) { described_class.new window, geo } 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 describe '#to_s' do
it 'includes window name' do it 'includes window name' do
expect(client.to_s).to include 'wname' expect(client.to_s).to include 'wname'
@ -48,6 +60,63 @@ module Uh
expect(client.moveresize).to be client expect(client.moveresize).to be client
end end
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 end
end end