aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-10-21 21:29:06 +0800
committercrupest <crupest@outlook.com>2021-10-21 21:29:06 +0800
commit6f1edc1604341b32e13371c8a4ad431e9a00cc87 (patch)
tree73b719af474789b14bfec9c7323c896a7927a45e /src
parent2d8237bf58ef0a9074d05aed2fe98d739f5e3bf0 (diff)
downloadcru-6f1edc1604341b32e13371c8a4ad431e9a00cc87.tar.gz
cru-6f1edc1604341b32e13371c8a4ad431e9a00cc87.tar.bz2
cru-6f1edc1604341b32e13371c8a4ad431e9a00cc87.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/osx/gui/InputMethod.mm11
-rw-r--r--src/osx/gui/UiApplication.mm10
-rw-r--r--src/osx/gui/Window.mm13
-rw-r--r--src/osx/gui/WindowPrivate.h4
4 files changed, 26 insertions, 12 deletions
diff --git a/src/osx/gui/InputMethod.mm b/src/osx/gui/InputMethod.mm
index 2331d8b7..2c4ac643 100644
--- a/src/osx/gui/InputMethod.mm
+++ b/src/osx/gui/InputMethod.mm
@@ -3,6 +3,7 @@
#import <AppKit/AppKit.h>
#include "InputMethodPrivate.h"
#include "WindowPrivate.h"
+#include "cru/common/Logger.hpp"
#include "cru/osx/Convert.hpp"
#include "cru/osx/gui/Window.hpp"
@@ -54,9 +55,15 @@ OsxInputMethodContext::OsxInputMethodContext(OsxWindow* window)
OsxInputMethodContext::~OsxInputMethodContext() {}
-void OsxInputMethodContext::EnableIME() { p_->Activate(); }
+void OsxInputMethodContext::EnableIME() {
+ log::Debug(u"Enable IME.");
+ p_->Activate();
+}
-void OsxInputMethodContext::DisableIME() { p_->Deactivate(); }
+void OsxInputMethodContext::DisableIME() {
+ log::Debug(u"Disable IME.");
+ p_->Deactivate();
+}
bool OsxInputMethodContext::ShouldManuallyDrawCompositionText() { return true; }
diff --git a/src/osx/gui/UiApplication.mm b/src/osx/gui/UiApplication.mm
index 11763af6..d6cf14f3 100644
--- a/src/osx/gui/UiApplication.mm
+++ b/src/osx/gui/UiApplication.mm
@@ -17,7 +17,7 @@
#include <unordered_map>
#include <vector>
-@interface AppDelegate : NSObject <NSApplicationDelegate>
+@interface CruAppDelegate : NSObject <NSApplicationDelegate>
- (id)init:(cru::platform::gui::osx::details::OsxUiApplicationPrivate*)p;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
- (void)applicationWillTerminate:(NSNotification*)notification;
@@ -32,7 +32,7 @@ class OsxUiApplicationPrivate {
public:
explicit OsxUiApplicationPrivate(OsxUiApplication* osx_ui_application)
: osx_ui_application_(osx_ui_application) {
- app_delegate_ = [[AppDelegate alloc] init:this];
+ app_delegate_ = [[CruAppDelegate alloc] init:this];
}
CRU_DELETE_COPY(OsxUiApplicationPrivate)
@@ -44,7 +44,7 @@ class OsxUiApplicationPrivate {
private:
OsxUiApplication* osx_ui_application_;
- AppDelegate* app_delegate_;
+ CruAppDelegate* app_delegate_;
std::vector<std::function<void()>> quit_handlers_;
long long current_timer_id_ = 1;
@@ -67,6 +67,8 @@ void OsxUiApplicationPrivate::CallQuitHandlers() {
OsxUiApplication::OsxUiApplication()
: OsxGuiResource(this), p_(new details::OsxUiApplicationPrivate(this)) {
+ [NSApplication sharedApplication];
+
// Add stdio logger.
log::Logger::GetInstance()->AddSource(std::make_unique<log::StdioLogSource>());
@@ -165,7 +167,7 @@ void OsxUiApplication::UnregisterWindow(OsxWindow* window) {
}
}
-@implementation AppDelegate {
+@implementation CruAppDelegate {
cru::platform::gui::osx::details::OsxUiApplicationPrivate* _p;
}
diff --git a/src/osx/gui/Window.mm b/src/osx/gui/Window.mm
index 56a1405d..8e21518e 100644
--- a/src/osx/gui/Window.mm
+++ b/src/osx/gui/Window.mm
@@ -149,14 +149,14 @@ bool OsxWindow::IsVisible() {
void OsxWindow::SetVisible(bool is_visible) {
if (p_->window_) {
if (is_visible) {
- [p_->window_ orderFront:p_->window_];
+ [p_->window_ orderFront:nil];
} else {
- [p_->window_ orderOut:p_->window_];
+ [p_->window_ orderOut:nil];
}
} else {
if (is_visible) {
CreateWindow();
- [p_->window_ orderFront:p_->window_];
+ [p_->window_ orderFront:nil];
}
}
}
@@ -220,6 +220,7 @@ void OsxWindow::CreateWindow() {
NSWindowStyleMask style_mask = CalcWindowStyleMask(p_->frame_);
p_->window_ = [[CruWindow alloc] init:p_.get() contentRect:content_rect style:style_mask];
+ Ensures(p_->window_);
[p_->window_ setDelegate:p_->window_delegate_];
@@ -281,11 +282,14 @@ IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_metho
defer:false];
_p = p;
- [self setIgnoresMouseEvents:FALSE];
[self setAcceptsMouseMovedEvents:YES];
return self;
}
+
+- (BOOL)canBecomeKeyWindow {
+ return YES;
+}
@end
@implementation CruView {
@@ -340,6 +344,7 @@ IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_metho
- (void)mouseDown:(NSEvent*)event {
// cru::log::TagDebug(u"CruView", u"Recieved mouse down.");
+ [[self window] makeKeyWindow];
cru::platform::gui::KeyModifier key_modifier;
if (event.modifierFlags & NSEventModifierFlagControl)
diff --git a/src/osx/gui/WindowPrivate.h b/src/osx/gui/WindowPrivate.h
index 7b788ba6..e3b93f8a 100644
--- a/src/osx/gui/WindowPrivate.h
+++ b/src/osx/gui/WindowPrivate.h
@@ -68,8 +68,8 @@ class OsxWindowPrivate {
bool frame_;
Rect content_rect_;
- NSWindow* window_;
- CruWindowDelegate* window_delegate_;
+ NSWindow* window_ = nil;
+ CruWindowDelegate* window_delegate_ = nil;
CGLayerRef draw_layer_;