Commit feb19ee6 authored by Ken Thomases's avatar Ken Thomases Committed by Alexandre Julliard

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: 's avatarKen Thomases <ken@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 48548812
......@@ -50,6 +50,8 @@ enum {
NSMutableSet* triedWindows;
unsigned long windowFocusSerial;
TISInputSourceRef lastKeyboardInputSource;
TISInputSourceRef lastKeyboardLayoutInputSource;
CGEventSourceKeyboardType keyboardType;
NSEvent* lastFlagsChanged;
BOOL inputSourceIsInputMethod;
......
......@@ -413,13 +413,45 @@ static NSString* WineLocalizedString(unsigned int stringID)
}
}
- (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);
}
inputSourceIsInputMethodValid = FALSE;
- (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;
if (inputSourceLayout)
{
CFDataRef uchr;
......@@ -434,7 +466,7 @@ static NSString* WineLocalizedString(unsigned int stringID)
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 @@ static NSString* WineLocalizedString(unsigned int stringID)
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];
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment