Merge branch 'handle-window-property-changes'

This commit is contained in:
Thibault Jouan 2015-04-22 08:14:51 +00:00
commit 44a5be6bd9
11 changed files with 114 additions and 1 deletions

View File

@ -16,6 +16,10 @@ Feature: layout protocol
def remove client def remove client
puts "testing_#remove_#{client.name}" puts "testing_#remove_#{client.name}"
end end
def update client
puts "testing_#update_#{client.name}"
end
end end
""" """
@ -33,3 +37,9 @@ Feature: layout protocol
And a window is mapped And a window is mapped
When the window is unmapped When the window is unmapped
Then the output must contain "testing_#remove_XClient/default" Then the output must contain "testing_#remove_XClient/default"
Scenario: tells the layout to update a changed client with #update message
Given uhwm is running with options -v -r./layout -l Layout
And a window is mapped
When the window name changes to "testing_new_name"
Then the output must contain "testing_#update_testing_new_name"

View File

@ -0,0 +1,7 @@
Feature: clients window properties updating
Scenario: logs when the window properties of a client change
Given uhwm is running
And a window is mapped
When the window name changes to "testing_new_name"
Then the output must match /updat.+testing_new_name/i

View File

@ -28,6 +28,10 @@ When /^the window is destroyed$/ do
x_client.destroy.sync x_client.destroy.sync
end end
When /^the window name changes to "([^"]+)"$/ do |name|
x_client.window_name = name
end
Then /^it must connect to X display$/ do Then /^it must connect to X display$/ do
uhwm_wait_ready uhwm_wait_ready
expect(x_socket_check uhwm.pid).to be true expect(x_socket_check uhwm.pid).to be true

View File

@ -31,6 +31,11 @@ module Uh
@wclass ||= @window.wclass @wclass ||= @window.wclass
end end
def update_window_properties
@wname = @window.name
@wclass = @window.wclass
end
def configure def configure
@window.configure @geo @window.configure @geo
self self

View File

@ -59,6 +59,7 @@ module Uh
return if window.override_redirect? || client_for(window) return if window.override_redirect? || client_for(window)
@clients << client = Client.new(window) @clients << client = Client.new(window)
@events.emit :manage, args: client @events.emit :manage, args: client
@display.listen_events window, Events::PROPERTY_CHANGE_MASK
end end
def unmap window def unmap window
@ -77,6 +78,12 @@ module Uh
@events.emit :unmanage, args: client @events.emit :unmanage, args: client
end end
def update_properties window
return unless client = client_for(window)
client.update_window_properties
@events.emit :change, args: client
end
def handle_next_event def handle_next_event
handle @display.next_event handle @display.next_event
end end
@ -117,6 +124,10 @@ module Uh
map event.window map event.window
end end
def handle_property_notify event
update_properties event.window
end
def handle_unmap_notify event def handle_unmap_notify event
unmap event.window unmap event.window
end end

View File

@ -119,6 +119,10 @@ module Uh
log "Unmanaging client #{client}" log "Unmanaging client #{client}"
layout.remove client layout.remove client
end end
@events.on :change do |client|
log "Updating client #{client}"
layout.update client
end
end end
def register_keybinds_hooks def register_keybinds_hooks

View File

@ -159,6 +159,11 @@ module Uh
@name @name
end end
def window_name= name
@name = @window.name = name
window.name
end
def map times: 1 def map times: 1
times.times { window.map } times.times { window.map }
window.map window.map

View File

@ -47,6 +47,24 @@ module Uh
end end
end end
describe '#update_window_properties' do
it 'updates the cached window name' do
client.name
allow(window).to receive(:name) { 'new name' }
expect { client.update_window_properties }
.to change { client.name }
.from('wname').to 'new name'
end
it 'updates the cached window class' do
client.wclass
allow(window).to receive(:wclass) { 'new class' }
expect { client.update_window_properties }
.to change { client.wclass }
.from('wclass').to 'new class'
end
end
describe '#configure' do describe '#configure' do
it 'configures the window with client geo' do it 'configures the window with client geo' do
expect(window).to receive(:configure).with geo expect(window).to receive(:configure).with geo

View File

@ -133,6 +133,8 @@ module Uh
end end
describe '#map' do describe '#map' do
let(:display) { instance_spy Display }
it 'registers a new client wrapping the given window' do it 'registers a new client wrapping the given window' do
manager.map window manager.map window
expect(manager.clients[0]) expect(manager.clients[0])
@ -159,6 +161,13 @@ module Uh
end end
manager.map window manager.map window
end end
it 'listens for property notify events on given window' do
expect(display)
.to receive(:listen_events)
.with window, Events::PROPERTY_CHANGE_MASK
manager.map window
end
end end
describe '#unmap' do describe '#unmap' do
@ -239,6 +248,30 @@ module Uh
end end
end end
describe '#update_properties' do
context 'with known window' do
before { manager.clients << client }
it 'tells the client to update its window properties' do
expect(client).to receive :update_window_properties
manager.update_properties window
end
it 'emits :change event with the client' do
events.on :change, &block
expect(block).to receive(:call).with client
manager.update_properties window
end
end
context 'with unknown window' do
it 'does not emit any event' do
expect(events).not_to receive :emit
manager.update_properties window
end
end
end
describe '#handle_next_event' do describe '#handle_next_event' do
it 'handles the next available event on display' do it 'handles the next available event on display' do
event = double 'event' event = double 'event'
@ -338,6 +371,15 @@ module Uh
manager.handle event manager.handle event
end end
end end
context 'when property_notify event is given' do
let(:event) { mock_event :property_notify, window: :window }
it 'updates event window properties' do
expect(manager).to receive(:update_properties).with :window
manager.handle event
end
end
end end
end end
end end

View File

@ -5,6 +5,7 @@ SomeLayout = Class.new do
define_method(:suggest_geo) { build_geo 0, 0, 42, 42 } define_method(:suggest_geo) { build_geo 0, 0, 42, 42 }
define_method(:<<) { |*_| } define_method(:<<) { |*_| }
define_method(:remove) { |*_| } define_method(:remove) { |*_| }
define_method(:update) { |*_| }
end end
module Uh module Uh
@ -98,6 +99,12 @@ module Uh
expect(env.layout).to receive(:remove).with :client expect(env.layout).to receive(:remove).with :client
runner.events.emit :unmanage, args: :client runner.events.emit :unmanage, args: :client
end end
it 'registers for :change event' do
runner.register_event_hooks
expect(env.layout).to receive(:update).with :client
runner.events.emit :change, args: :client
end
end end
context 'keys hooks' do context 'keys hooks' do

View File

@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.executables = s.files.grep(/\Abin\//) { |f| File.basename(f) } s.executables = s.files.grep(/\Abin\//) { |f| File.basename(f) }
s.add_dependency 'uh', '2.0.0.pre2' s.add_dependency 'uh', '2.0.0.pre2'
s.add_dependency 'uh-layout', '0.2.0.pre' s.add_dependency 'uh-layout', '~> 0.2.2'
s.add_development_dependency 'aruba', '~> 0.6' s.add_development_dependency 'aruba', '~> 0.6'
s.add_development_dependency 'cucumber', '~> 2.0' s.add_development_dependency 'cucumber', '~> 2.0'