[PATCH v2] winemac.drv: Allow mac IME to clear text in system input method

Ken Thomases ken at codeweavers.com
Mon May 6 02:12:40 CDT 2019


On May 3, 2019, at 9:39 PM, Aric Stewart <aric at codeweavers.com> wrote:
> 
> v2: correct Extra semicolon spotted by Zhiyi Zhang
> Signed-off-by: Aric Stewart <aric at codeweavers.com>
> ---
> dlls/winemac.drv/cocoa_window.m | 16 ++++++++++++++++
> dlls/winemac.drv/ime.c          |  2 +-
> dlls/winemac.drv/macdrv_cocoa.h |  2 ++
> 3 files changed, 19 insertions(+), 1 deletion(-)
> 
> 
> diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m
> index f43b26b8e3..94e5798c0b 100644
> --- a/dlls/winemac.drv/cocoa_window.m
> +++ b/dlls/winemac.drv/cocoa_window.m
> @@ -3907,3 +3907,19 @@ void macdrv_send_text_input_event(int pressed, unsigned int flags, int repeat, i
>          macdrv_release_event(event);
>      });
>  }
> +
> +void macdrv_clear_ime_text()
> +{
> +    OnMainThreadAsync(^{
> +        WineWindow* window = (WineWindow*)[NSApp keyWindow];
> +        if (![window isKindOfClass:[WineWindow class]])
> +        {
> +            window = (WineWindow*)[NSApp mainWindow];
> +            if (![window isKindOfClass:[WineWindow class]])
> +                window = [[WineApplicationController sharedController] frontWineWindow];
> +        }
> +        if (window) {

Please put opening braces for the compound statement on a new line in Mac driver code.  Although, for a single statement, just leave out the braces.

> +            [[[window contentView] inputContext] unmarkText];

This isn't the correct method to call.  You do want to call a method on the text input context, but the -unmarkText method is a method on the text input client (our view), not the text input context.  Also, -unmarkText (if called on our view) actually accepts/commits the current marked text.  It doesn't discard it.

The correct method to call is -discardMarkedText.  However, we have to do more than just call that.  We need to clear our notion of the current marked text.  We basically have to do the same as the last three lines of our -completeText: method:

        [markedText deleteCharactersInRange:NSMakeRange(0, [markedText length])];
        markedTextSelection = NSMakeRange(0, 0);
        [[self inputContext] discardMarkedText];

Since that involves manipulating instance variables, it's best if that's done by a method of the view class.  So, extract such a method from -completeText: and have the code here in macdrv_clear_ime_text() call that newly-extracted method on the view.

-Ken




More information about the wine-devel mailing list