From e6130b7111d79c54e955a66f3a2d8efda22208a9 Mon Sep 17 00:00:00 2001 From: Keiichiro Ui Date: Thu, 24 Dec 2015 12:27:16 +0900 Subject: [PATCH 1/4] Add a function which match app_class a patch by Tetsuya Hoya --- lib/rbindkeys/key_event_handler.rb | 7 ++++--- lib/rbindkeys/window_matcher.rb | 14 ++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/rbindkeys/key_event_handler.rb b/lib/rbindkeys/key_event_handler.rb index ef00ae5..9d77d56 100644 --- a/lib/rbindkeys/key_event_handler.rb +++ b/lib/rbindkeys/key_event_handler.rb @@ -176,15 +176,16 @@ def active_window_changed window if not window.nil? title = window.title app_name = window.app_name + app_class = window.app_class if LOG.info? LOG.info "" unless LOG.debug? - LOG.info "change active_window: :class => \"#{app_name}\", :title => \"#{title}\"" + LOG.info "change active_window: :class => \"#{app_name}\", :app_class => \"#{app_class}\", :title => \"#{title}\"" end @window_bind_resolver_map.each do |matcher, bind_resolver| - if matcher.match? app_name, title + if matcher.match? app_name, app_class, title if LOG.info? - LOG.info "=> matcher #{matcher.app_name.inspect}, #{matcher.title.inspect}" + LOG.info "=> matcher #{matcher.app_name.inspect}, #{matcher.app_class.inspect}, #{matcher.title.inspect}" LOG.info " bind_resolver #{bind_resolver.inspect}" end set_bind_resolver bind_resolver diff --git a/lib/rbindkeys/window_matcher.rb b/lib/rbindkeys/window_matcher.rb index afabf70..672aa63 100644 --- a/lib/rbindkeys/window_matcher.rb +++ b/lib/rbindkeys/window_matcher.rb @@ -6,20 +6,22 @@ module Rbindkeys class WindowMatcher - attr_reader :app_name, :title + attr_reader :app_name, :title, :app_class def initialize h - @app_name = (h[:class] or h[:app_name] or h[:app_class]) + @app_name = (h[:class] or h[:app_name]) + @app_class = (h[:app_class]) @title = (h[:title] or h[:name]) - if not @app_name.nil? and not @title.nil? + if @app_name.nil? and @app_class.nil? and @title.nil? raise ArgumentError, 'expect to be given :class, :app_name,'+ ' :app_class, :title or :name ' end end - def match? app_name, title + def match? app_name, app_class, title (@app_name.nil? or match_app?(app_name)) and + (@app_class.nil? or match_class?(app_class)) and (@title.nil? or match_title?(title)) end @@ -27,6 +29,10 @@ def match_app? app_name app_name and app_name.match @app_name end + def match_class? app_class + app_class and app_class.match @app_class + end + def match_title? title title and title.match @title end From 3a7703f6f3171ca442b7486c1d4fcde0092ec423 Mon Sep 17 00:00:00 2001 From: Keiichiro Ui Date: Thu, 24 Dec 2015 12:29:14 +0900 Subject: [PATCH 2/4] Apply :ignore if no key-bind in two-stroke key-bind a patch by Tetsuya Hoya --- lib/rbindkeys/key_event_handler.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/rbindkeys/key_event_handler.rb b/lib/rbindkeys/key_event_handler.rb index 9d77d56..f1e4c10 100644 --- a/lib/rbindkeys/key_event_handler.rb +++ b/lib/rbindkeys/key_event_handler.rb @@ -139,6 +139,9 @@ def handle_press_event event r end else + if @bind_resolver.two_stroke? + set_bind_resolver (@window_bind_resolver or @default_bind_resolver) + end r end end From d64f08ee375b57fa9f51a907fb4b0dce8794fff8 Mon Sep 17 00:00:00 2001 From: Keiichiro Ui Date: Fri, 25 Dec 2015 01:14:37 +0900 Subject: [PATCH 3/4] Fix WindowMatcher and it's testfor app_class --- lib/rbindkeys/window_matcher.rb | 6 +++--- spec/key_event_handler/handle_spec.rb | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/rbindkeys/window_matcher.rb b/lib/rbindkeys/window_matcher.rb index 672aa63..69e18dd 100644 --- a/lib/rbindkeys/window_matcher.rb +++ b/lib/rbindkeys/window_matcher.rb @@ -9,9 +9,9 @@ class WindowMatcher attr_reader :app_name, :title, :app_class def initialize h - @app_name = (h[:class] or h[:app_name]) - @app_class = (h[:app_class]) - @title = (h[:title] or h[:name]) + @app_name = h[:app_name] + @app_class = h[:app_class] || h[:class] + @title = h[:title] || h[:name] if @app_name.nil? and @app_class.nil? and @title.nil? raise ArgumentError, 'expect to be given :class, :app_name,'+ diff --git a/spec/key_event_handler/handle_spec.rb b/spec/key_event_handler/handle_spec.rb index ac6c2ef..5b2f36b 100644 --- a/spec/key_event_handler/handle_spec.rb +++ b/spec/key_event_handler/handle_spec.rb @@ -187,6 +187,7 @@ before do @window = double ActiveWindowX::Window allow(@window).to receive(:app_name) { 'qux' } + allow(@window).to receive(:app_class) { 'Qux' } @resolver2 = double BindResolver allow(BindResolver).to receive(:new) { @resolver2 } end From 0f74cf915947b308a09ba4e3be5e748ec75d984e Mon Sep 17 00:00:00 2001 From: Keiichiro Ui Date: Sun, 3 Jan 2016 10:23:52 +0900 Subject: [PATCH 4/4] Fix log message --- lib/rbindkeys/key_event_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rbindkeys/key_event_handler.rb b/lib/rbindkeys/key_event_handler.rb index f1e4c10..fb842a2 100644 --- a/lib/rbindkeys/key_event_handler.rb +++ b/lib/rbindkeys/key_event_handler.rb @@ -182,7 +182,7 @@ def active_window_changed window app_class = window.app_class if LOG.info? LOG.info "" unless LOG.debug? - LOG.info "change active_window: :class => \"#{app_name}\", :app_class => \"#{app_class}\", :title => \"#{title}\"" + LOG.info "change active_window: :app_name => \"#{app_name}\", :app_class => \"#{app_class}\", :title => \"#{title}\"" end @window_bind_resolver_map.each do |matcher, bind_resolver|