diff --git a/lib/rbindkeys/key_event_handler.rb b/lib/rbindkeys/key_event_handler.rb index ef00ae5..fb842a2 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 @@ -176,15 +179,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: :app_name => \"#{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..69e18dd 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]) - @title = (h[:title] or h[:name]) + @app_name = h[:app_name] + @app_class = h[:app_class] || h[:class] + @title = h[:title] || 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 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