Skip to content
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

[WIP][MAC] Fixes Popup IME integration #15641

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
ED3791C42862E1F40080BD62 /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED3791C32862E1F40080BD62 /* UniformTypeIdentifiers.framework */; };
ED754D262A97306B0078B4DF /* PlatformRenderTimer.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED754D252A97306B0078B4DF /* PlatformRenderTimer.mm */; };
EDF8CDCD2964CB01001EE34F /* PlatformSettings.mm in Sources */ = {isa = PBXBuildFile; fileRef = EDF8CDCC2964CB01001EE34F /* PlatformSettings.mm */; };
F166293E2BE8D02B00582430 /* AvnPopup.h in Headers */ = {isa = PBXBuildFile; fileRef = F166293D2BE8D02B00582430 /* AvnPopup.h */; };
F16D46362BF4B363009EF53D /* AvnPopup.mm in Sources */ = {isa = PBXBuildFile; fileRef = F16D46352BF4B363009EF53D /* AvnPopup.mm */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -125,6 +127,8 @@
ED3791C32862E1F40080BD62 /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
ED754D252A97306B0078B4DF /* PlatformRenderTimer.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformRenderTimer.mm; sourceTree = "<group>"; };
EDF8CDCC2964CB01001EE34F /* PlatformSettings.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformSettings.mm; sourceTree = "<group>"; };
F166293D2BE8D02B00582430 /* AvnPopup.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AvnPopup.h; sourceTree = "<group>"; };
F16D46352BF4B363009EF53D /* AvnPopup.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AvnPopup.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -164,6 +168,8 @@
AB7A61E62147C814003C5833 = {
isa = PBXGroup;
children = (
F166293D2BE8D02B00582430 /* AvnPopup.h */,
F16D46352BF4B363009EF53D /* AvnPopup.mm */,
ED754D252A97306B0078B4DF /* PlatformRenderTimer.mm */,
855EDC9E28C6546F00807998 /* PlatformBehaviorInhibition.mm */,
8D2F3511292F6AAE007FCF54 /* AvnTextInputMethodDelegate.h */,
Expand Down Expand Up @@ -245,6 +251,7 @@
8D300D65292D0A6800320C49 /* AvnTextInputMethod.h in Headers */,
8D2F3512292F6AAE007FCF54 /* AvnTextInputMethodDelegate.h in Headers */,
18391C28BF1823B5464FDD36 /* ResizeScope.h in Headers */,
F166293E2BE8D02B00582430 /* AvnPopup.h in Headers */,
18391ED5F611FF62C45F196D /* AvnView.h in Headers */,
18391E1381E2D5BFD60265A9 /* AutoFitContentView.h in Headers */,
18391F1E2411C79405A9943A /* WindowProtocol.h in Headers */,
Expand Down Expand Up @@ -324,6 +331,7 @@
BC11A5BF2608D58F0017BAD0 /* automation.mm in Sources */,
37E2330F21583241000CB7E2 /* KeyTransform.mm in Sources */,
855EDC9F28C6546F00807998 /* PlatformBehaviorInhibition.mm in Sources */,
F16D46362BF4B363009EF53D /* AvnPopup.mm in Sources */,
520624B322973F4100C4DCEF /* menu.mm in Sources */,
8D300D69292E1E5D00320C49 /* AvnTextInputMethod.mm in Sources */,
37A517B32159597E00FBA241 /* Screens.mm in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
version = "1.3">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand Down Expand Up @@ -36,7 +36,7 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "YES"
customWorkingDirectory = "$PROJECT_DIR/../../../../samples/ControlCatalog.NetCore"
customWorkingDirectory = "/Users/benediktstebner/RiderProjects/Avalonia/samples/Sandbox/bin/Debug/net8.0"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
Expand All @@ -56,7 +56,7 @@
</MacroExpansion>
<CommandLineArguments>
<CommandLineArgument
argument = "bin/Debug/net8.0/ControlCatalog.NetCore.dll"
argument = "Sandbox.dll"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
Expand Down
16 changes: 16 additions & 0 deletions native/Avalonia.Native/src/OSX/AvnPopup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// AvnPopup.h
// Avalonia.Native.OSX
//
// Created by Benedikt Stebner on 06.05.24.
// Copyright © 2024 Avalonia. All rights reserved.
//

#pragma once

#import <AppKit/AppKit.h>

@protocol AvnPopupProtocol
-(double) getExtendedTitleBarHeight;
-(bool) shouldTryToHandleEvents;
@end
25 changes: 25 additions & 0 deletions native/Avalonia.Native/src/OSX/AvnPopup.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#import <AppKit/AppKit.h>
#include "AvnPopup.h"
#import "WindowInterfaces.h"

@implementation AvnPopup
{
ComPtr<WindowBaseImpl> _parent;
}

- (AvnPopup * _Nonnull)initWithWindowImpl:(WindowBaseImpl * _Nonnull)windowImpl contentRect:(NSRect)contentRect {

self = [super initWithContentRect:contentRect styleMask: NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:false];

return self;
}

- (double)getExtendedTitleBarHeight {
return 0;
}

- (bool)shouldTryToHandleEvents {
return YES;
}

@end
12 changes: 8 additions & 4 deletions native/Avalonia.Native/src/OSX/AvnView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ - (void)keyDown:(NSEvent *)event
return;
}

auto keyDownHandled = NO;

_lastKeyDownEvent = event;

auto timestamp = static_cast<uint64_t>([event timestamp] * 1000);
Expand All @@ -548,7 +550,9 @@ - (void)keyDown:(NSEvent *)event

//Handle keyDown first if an input modifier is present
if(hasInputModifier){
if([self handleKeyDown:timestamp withKey:key withPhysicalKey:physicalKey withModifiers:modifiers withKeySymbol:keySymbol]){
keyDownHandled = [self handleKeyDown:timestamp withKey:key withPhysicalKey:physicalKey withModifiers:modifiers withKeySymbol:keySymbol];

if(keyDownHandled){
//User code has handled the event
_lastKeyDownEvent = nullptr;

Expand All @@ -561,15 +565,15 @@ - (void)keyDown:(NSEvent *)event

//Only raise a keyDown if we don't have a modifier
if(!hasInputModifier){
[self handleKeyDown:timestamp withKey:key withPhysicalKey:physicalKey withModifiers:modifiers withKeySymbol:keySymbol];
keyDownHandled = [self handleKeyDown:timestamp withKey:key withPhysicalKey:physicalKey withModifiers:modifiers withKeySymbol:keySymbol];
}
}

}
//InputMethod not active
else{
auto keyDownHandled = [self handleKeyDown:timestamp withKey:key withPhysicalKey:physicalKey withModifiers:modifiers withKeySymbol:keySymbol];
keyDownHandled = [self handleKeyDown:timestamp withKey:key withPhysicalKey:physicalKey withModifiers:modifiers withKeySymbol:keySymbol];

//Raise text input event for unhandled key down
if(!keyDownHandled){
if(keySymbol != nullptr && key != AvnKeyEnter){
Expand Down