From 7c708b370bed44f8f0a082a90ecf79aa280577ad Mon Sep 17 00:00:00 2001 From: qwertyyb Date: Sat, 22 Apr 2023 15:30:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E4=B8=8B(safari=E5=9C=B0=E5=9D=80=E6=A0=8F)?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=97=B6=EF=BC=8C=E4=BB=8E=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E5=88=87=E5=88=B0=E8=8B=B1=E6=96=87=E6=A8=A1=E5=BC=8F=E4=B8=8B?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8E=9F=E7=A0=81=E4=B8=8D=E4=BC=9A=E4=B8=8A?= =?UTF-8?q?=E5=B1=8F=E5=92=8C=E6=B8=85=E9=99=A4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Fire/CandidatesWindow.swift | 6 ++---- Fire/FireInputController.swift | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Fire/CandidatesWindow.swift b/Fire/CandidatesWindow.swift index f3db529..065eb10 100644 --- a/Fire/CandidatesWindow.swift +++ b/Fire/CandidatesWindow.swift @@ -65,10 +65,8 @@ class CandidatesWindow: NSWindow, NSWindowDelegate { events.forEach { (observer) in NotificationCenter.default.addObserver( forName: observer.name, object: nil, queue: nil, using: observer.callback )} - /** - * 1. 由于使用recognizedEvents在一些场景下不能监听到flagChanged事件,比如保存文件场景 - * 所以这里需要使用NSEvent.addGlobalMonitorForEvents监听shift键被按下 - */ + // 由于使用IMKInputController recognizedEvents在一些场景下不能监听到flagChanged事件,比如保存文件和lanchPad场景 + // 所以这里需要使用NSEvent.addGlobalMonitorForEvents监听shift键被按下 NSEvent.addGlobalMonitorForEvents(matching: .flagsChanged) { (event) in NSLog("[CandidatesWindow] globalMonitorForEvents flagsChanged: \(event)") if !InputSource.shared.isSelected() { diff --git a/Fire/FireInputController.swift b/Fire/FireInputController.swift index 376149e..52df21f 100644 --- a/Fire/FireInputController.swift +++ b/Fire/FireInputController.swift @@ -299,6 +299,14 @@ class FireInputController: IMKInputController { override func handle(_ event: NSEvent!, client sender: Any!) -> Bool { NSLog("[FireInputController] handle: \(event.debugDescription)") + + // 在activateServer中有把IMKInputController绑定给CandidatesWindow + // 然而在实际运行中发现,在Safari地址栏输入部分原码后,再按shift切到英文输入模式下时,候选窗消失了,但原码没有上屏 + // 排查发现,因为shift切换中英文是通过CandidatesWindow调用绑定的inputController方法实现的,而在safari地址栏时,接受键盘输入的inputController + // 和CandidatesWindow绑定的inputController并不是同一个,所以出现了此问题 + // 这里猜测之所以会出现不一致,是因为在Safari地址栏输入场景下,会有多个TextInputClient而创建多个inputController, activateServer也会多次执行 + // 但是activateServer的调用顺序并不能保证最后调用的就是接受输入事件的TextInputClient对应的inputController, 所以仅是在activateServer中绑定inputController是不行的,需要在此处再绑定一下 + CandidatesWindow.shared.inputController = self let handler = Utils.shared.processHandlers(handlers: [ hotkeyHandler,