Quit on `mod1+q' key binding
* Loop our runner until it is "stopped"; * Use the event dispatcher to stop the runner on `mod1+q' key press; * Tell the manager to grab the `q' key.
This commit is contained in:
parent
224ae6be5f
commit
ceac19b346
1
bin/uhwm
1
bin/uhwm
@ -3,4 +3,3 @@
|
|||||||
require 'uh/wm'
|
require 'uh/wm'
|
||||||
|
|
||||||
Uh::WM::CLI.run(ARGV)
|
Uh::WM::CLI.run(ARGV)
|
||||||
sleep 8
|
|
||||||
|
6
features/actions/quit.feature
Normal file
6
features/actions/quit.feature
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Feature: quit action
|
||||||
|
|
||||||
|
Scenario: quits on keybing press
|
||||||
|
Given uhwm is running
|
||||||
|
When I press the default quit key binding
|
||||||
|
Then uhwm should terminate successfully
|
@ -4,6 +4,15 @@ def uhwm_run options = nil
|
|||||||
@interactive = @process = run command.join ' '
|
@interactive = @process = run command.join ' '
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uhwm_run_wait_ready
|
||||||
|
uhwm_run
|
||||||
|
uhwm_wait_output 'Connected to'
|
||||||
|
end
|
||||||
|
|
||||||
|
Given /^uhwm is running$/ do
|
||||||
|
uhwm_run_wait_ready
|
||||||
|
end
|
||||||
|
|
||||||
When /^I start uhwm$/ do
|
When /^I start uhwm$/ do
|
||||||
uhwm_run
|
uhwm_run
|
||||||
end
|
end
|
||||||
@ -15,3 +24,7 @@ end
|
|||||||
Then /^the exit status must be (\d+)$/ do |exit_status|
|
Then /^the exit status must be (\d+)$/ do |exit_status|
|
||||||
assert_exit_status exit_status.to_i
|
assert_exit_status exit_status.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Then /^uhwm should terminate successfully$/ do
|
||||||
|
assert_exit_status 0
|
||||||
|
end
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
def x_key key
|
||||||
|
fail "cannot simulate X key `#{key}'" unless system "xdotool key #{key}"
|
||||||
|
end
|
||||||
|
|
||||||
|
When /^I press the default quit key binding$/ do
|
||||||
|
x_key 'alt+q'
|
||||||
|
end
|
||||||
|
|
||||||
Then /^it must connect to X display$/ do
|
Then /^it must connect to X display$/ do
|
||||||
uhwm_wait_output 'Connected to'
|
uhwm_wait_output 'Connected to'
|
||||||
expect(`sockstat -u`.lines.grep /\s+ruby.+\s+#{@process.pid}/)
|
expect(`sockstat -u`.lines.grep /\s+ruby.+\s+#{@process.pid}/)
|
||||||
|
@ -4,7 +4,9 @@ module Uh
|
|||||||
class << self
|
class << self
|
||||||
def run env, **options
|
def run env, **options
|
||||||
runner = new env, **options
|
runner = new env, **options
|
||||||
|
runner.register_event_hooks
|
||||||
runner.connect_manager
|
runner.connect_manager
|
||||||
|
runner.run_until { runner.stopped? }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -25,14 +27,26 @@ module Uh
|
|||||||
@stopped = true
|
@stopped = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def register_event_hooks
|
||||||
|
register_key_bindings_hooks
|
||||||
|
end
|
||||||
|
|
||||||
def connect_manager
|
def connect_manager
|
||||||
@manager.connect
|
@manager.connect
|
||||||
@env.log "Connected to X server"
|
@env.log "Connected to X server"
|
||||||
|
@manager.grab_key :q
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_until &block
|
def run_until &block
|
||||||
@manager.handle_pending_events until block.call
|
@manager.handle_pending_events until block.call
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def register_key_bindings_hooks
|
||||||
|
@events.on(:key, :q) { stop! }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,6 +15,10 @@ module Uh
|
|||||||
described_class.run arguments, stdout: stdout, stderr: stderr
|
described_class.run arguments, stdout: stdout, stderr: stderr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# FIXME: remove this hack we currently need to prevent the Runner from
|
||||||
|
# blocking.
|
||||||
|
before { allow(Runner).to receive :run }
|
||||||
|
|
||||||
it 'builds a new CLI with given arguments' do
|
it 'builds a new CLI with given arguments' do
|
||||||
expect(described_class)
|
expect(described_class)
|
||||||
.to receive(:new).with(arguments, stdout: stdout).and_call_original
|
.to receive(:new).with(arguments, stdout: stdout).and_call_original
|
||||||
|
@ -5,15 +5,23 @@ module Uh
|
|||||||
subject(:runner) { described_class.new env }
|
subject(:runner) { described_class.new env }
|
||||||
|
|
||||||
describe '.run' do
|
describe '.run' do
|
||||||
subject(:run) { described_class.run env }
|
subject(:run) { described_class.run env, stopped: true }
|
||||||
|
|
||||||
it 'builds a new Runner with given env' do
|
it 'builds a new Runner with given env' do
|
||||||
expect(described_class).to receive(:new).with(env).and_call_original
|
expect(described_class)
|
||||||
|
.to receive(:new).with(env, anything).and_call_original
|
||||||
|
run
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'registers event hooks' do
|
||||||
|
runner.stop!
|
||||||
|
allow(described_class).to receive(:new) { runner }
|
||||||
|
expect(runner).to receive(:register_event_hooks)
|
||||||
run
|
run
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'connects the manager' do
|
it 'connects the manager' do
|
||||||
runner
|
runner.stop!
|
||||||
allow(described_class).to receive(:new) { runner }
|
allow(described_class).to receive(:new) { runner }
|
||||||
expect(runner).to receive(:connect_manager)
|
expect(runner).to receive(:connect_manager)
|
||||||
run
|
run
|
||||||
@ -62,7 +70,19 @@ module Uh
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#register_event_hooks' do
|
||||||
|
context 'key bindings' do
|
||||||
|
it 'registers key bindings event hooks' do
|
||||||
|
runner.register_event_hooks
|
||||||
|
expect(runner.events[:key, :q]).not_to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#connect_manager' do
|
describe '#connect_manager' do
|
||||||
|
let(:manager) { instance_spy Manager }
|
||||||
|
subject(:runner) { described_class.new env, manager: manager }
|
||||||
|
|
||||||
it 'connects the manager' do
|
it 'connects the manager' do
|
||||||
expect(runner.manager).to receive :connect
|
expect(runner.manager).to receive :connect
|
||||||
runner.connect_manager
|
runner.connect_manager
|
||||||
@ -72,6 +92,11 @@ module Uh
|
|||||||
expect(env).to receive(:log).with /connected/i
|
expect(env).to receive(:log).with /connected/i
|
||||||
runner.connect_manager
|
runner.connect_manager
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'tells the manager to grab keys' do
|
||||||
|
expect(runner.manager).to receive(:grab_key).with :q
|
||||||
|
runner.connect_manager
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#run_until' do
|
describe '#run_until' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user