winemac: Ignore spurious or redundant notifications that the keyboard input source changed.
In particular, when an input method for an Asian language (e.g. Pinyin) is selected, we were getting repeated notifications. Querying the selected input method upon receiving them suggested that the keyboard layout changed to U.S. then back to Pinyin, then several redundant notifications with no apparent change. Since the handler for the posted KEYBOARD_CHANGED events sends WM_CANCELMODE to the active window, this was having bad effects. The spurious notifications can be distinguished by there being no current text input context or client. To detect redundant notifications, we track the last keyboard input source and keyboard layout input source and compare with the new ones to see if they really changed. Signed-off-by: Ken Thomases <ken@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
48548812fe
commit
feb19ee669
|
@ -50,6 +50,8 @@ @interface WineApplicationController : NSObject <NSApplicationDelegate>
|
|||
NSMutableSet* triedWindows;
|
||||
unsigned long windowFocusSerial;
|
||||
|
||||
TISInputSourceRef lastKeyboardInputSource;
|
||||
TISInputSourceRef lastKeyboardLayoutInputSource;
|
||||
CGEventSourceKeyboardType keyboardType;
|
||||
NSEvent* lastFlagsChanged;
|
||||
BOOL inputSourceIsInputMethod;
|
||||
|
|
|
@ -413,13 +413,45 @@ - (void) windowRejectedFocusEvent:(const macdrv_event*)event
|
|||
}
|
||||
}
|
||||
|
||||
- (void) keyboardSelectionDidChange
|
||||
static BOOL EqualInputSource(TISInputSourceRef source1, TISInputSourceRef source2)
|
||||
{
|
||||
TISInputSourceRef inputSourceLayout;
|
||||
if (!source1 && !source2)
|
||||
return TRUE;
|
||||
if (!source1 || !source2)
|
||||
return FALSE;
|
||||
return CFEqual(source1, source2);
|
||||
}
|
||||
|
||||
- (void) keyboardSelectionDidChange:(BOOL)force
|
||||
{
|
||||
TISInputSourceRef inputSource, inputSourceLayout;
|
||||
|
||||
if (!force)
|
||||
{
|
||||
NSTextInputContext* context = [NSTextInputContext currentInputContext];
|
||||
if (!context || ![context client])
|
||||
return;
|
||||
}
|
||||
|
||||
inputSource = TISCopyCurrentKeyboardInputSource();
|
||||
inputSourceLayout = TISCopyCurrentKeyboardLayoutInputSource();
|
||||
if (!force && EqualInputSource(inputSource, lastKeyboardInputSource) &&
|
||||
EqualInputSource(inputSourceLayout, lastKeyboardLayoutInputSource))
|
||||
{
|
||||
if (inputSource) CFRelease(inputSource);
|
||||
if (inputSourceLayout) CFRelease(inputSourceLayout);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lastKeyboardInputSource)
|
||||
CFRelease(lastKeyboardInputSource);
|
||||
lastKeyboardInputSource = inputSource;
|
||||
if (lastKeyboardLayoutInputSource)
|
||||
CFRelease(lastKeyboardLayoutInputSource);
|
||||
lastKeyboardLayoutInputSource = inputSourceLayout;
|
||||
|
||||
inputSourceIsInputMethodValid = FALSE;
|
||||
|
||||
inputSourceLayout = TISCopyCurrentKeyboardLayoutInputSource();
|
||||
if (inputSourceLayout)
|
||||
{
|
||||
CFDataRef uchr;
|
||||
|
@ -434,7 +466,7 @@ - (void) keyboardSelectionDidChange
|
|||
event->keyboard_changed.keyboard_type = self.keyboardType;
|
||||
event->keyboard_changed.iso_keyboard = (KBGetLayoutType(self.keyboardType) == kKeyboardISO);
|
||||
event->keyboard_changed.uchr = CFDataCreateCopy(NULL, uchr);
|
||||
event->keyboard_changed.input_source = TISCopyCurrentKeyboardInputSource();
|
||||
event->keyboard_changed.input_source = (TISInputSourceRef)CFRetain(inputSource);
|
||||
|
||||
if (event->keyboard_changed.uchr)
|
||||
{
|
||||
|
@ -448,17 +480,20 @@ - (void) keyboardSelectionDidChange
|
|||
|
||||
macdrv_release_event(event);
|
||||
}
|
||||
|
||||
CFRelease(inputSourceLayout);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) keyboardSelectionDidChange
|
||||
{
|
||||
[self keyboardSelectionDidChange:NO];
|
||||
}
|
||||
|
||||
- (void) setKeyboardType:(CGEventSourceKeyboardType)newType
|
||||
{
|
||||
if (newType != keyboardType)
|
||||
{
|
||||
keyboardType = newType;
|
||||
[self keyboardSelectionDidChange];
|
||||
[self keyboardSelectionDidChange:YES];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue