Skip to content

patches from Tetsuya Hoya #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/rbindkeys/key_event_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions lib/rbindkeys/window_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,33 @@
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

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
Expand Down
1 change: 1 addition & 0 deletions spec/key_event_handler/handle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down