diff --git a/client/CFocusableHelper.cpp b/client/CFocusableHelper.cpp new file mode 100644 index 000000000..e4e3c6cfe --- /dev/null +++ b/client/CFocusableHelper.cpp @@ -0,0 +1,21 @@ +/* + * CFocusableHelper.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#include "CFocusableHelper.h" +#include "../Global.h" +#include "widgets/TextControls.h" + +void removeFocusFromActiveInput() +{ + if(CFocusable::inputWithFocus == nullptr) + return; + CFocusable::inputWithFocus->focus = false; + CFocusable::inputWithFocus->redraw(); + CFocusable::inputWithFocus = nullptr; +} diff --git a/client/CFocusableHelper.h b/client/CFocusableHelper.h new file mode 100644 index 000000000..6ee0927a3 --- /dev/null +++ b/client/CFocusableHelper.h @@ -0,0 +1,11 @@ +/* + * CFocusableHelper.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +void removeFocusFromActiveInput(); diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 4004e814e..62d47278e 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -145,6 +145,16 @@ set(client_HEADERS SDLRWwrapper.h ) +if(APPLE_IOS) + set(client_SRCS ${client_SRCS} + SDL_uikit_main.mm + CFocusableHelper.cpp + ) + set(client_HEADERS ${client_HEADERS} + CFocusableHelper.h + ) +endif() + assign_source_group(${client_SRCS} ${client_HEADERS} VCMI_client.rc) if(ANDROID) # android needs client/server to be libraries, not executables, so we can't reuse the build part of this script @@ -153,8 +163,6 @@ endif() if(WIN32) set(client_ICON "VCMI_client.rc") -elseif(APPLE_IOS) - set(client_SRCS ${client_SRCS} SDL_uikit_main.m) endif() if(ENABLE_DEBUG_CONSOLE) diff --git a/client/SDL_uikit_main.m b/client/SDL_uikit_main.mm similarity index 90% rename from client/SDL_uikit_main.m rename to client/SDL_uikit_main.mm index cb3eb0e99..c1f94a796 100644 --- a/client/SDL_uikit_main.m +++ b/client/SDL_uikit_main.mm @@ -8,9 +8,11 @@ #include #include -@import UIKit; +#include "../Global.h" +#include "CMT.h" +#include "CFocusableHelper.h" -extern SDL_Window * mainWindow; +#import @interface SDLViewObserver : NSObject @@ -89,6 +91,9 @@ main(int argc, char *argv[]) [NSNotificationCenter.defaultCenter addObserverForName:UIWindowDidBecomeKeyNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { [UIApplication.sharedApplication.keyWindow.rootViewController addObserver:observer forKeyPath:NSStringFromSelector(@selector(view)) options:NSKeyValueObservingOptionNew context:NULL]; }]; + [NSNotificationCenter.defaultCenter addObserverForName:UIKeyboardDidHideNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { + removeFocusFromActiveInput(); + }]; return SDL_UIKitRunApp(argc, argv, SDL_main); } }