Skip to content

Commit

Permalink
Fix the limitation of mouse event on the candidate window on macOS 15.
Browse files Browse the repository at this point in the history
* Used the RendererReceiver class as a proxy to receive messages from MozcRenderer.

PiperOrigin-RevId: 683089226
  • Loading branch information
hiroyuki-komatsu committed Oct 7, 2024
1 parent c55cd75 commit 120bd93
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/mac/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ mozc_objc_library(
deps = [
":imk_controller",
":imk_server",
":renderer_receiver",
"//base:const",
"//base:crash_report_handler",
"//base:init_mozc",
Expand Down Expand Up @@ -145,6 +146,7 @@ mozc_objc_library(
":common",
":imk_server",
":keycode_map",
":renderer_receiver",
"//base:const",
"//base:process",
"//base:util",
Expand Down
8 changes: 8 additions & 0 deletions src/mac/GoogleJapaneseInputController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#import "mac/KeyCodeMap.h"
#import "mac/common.h"
#import "mac/renderer_receiver.h"

#include <cstdint>
#include <memory>
Expand Down Expand Up @@ -106,6 +107,12 @@
IBOutlet NSMenu *menu_;
}

/** Sets the RendererReceiver used by all instances of the controller.
* the RendererReceiver is a singleton object used as a proxy to receive messages from
* the renderer process and propage it to the active controller instance.
*/
+ (void)setGlobalRendererReceiver:(RendererReceiver *)rendererReceiver;

/** sendCommand: is called to send SessionCommand to the server from the renderer, when the user
* clicks a candidate item in candidate windows or when the renderer sends the usage stats event
* information. */
Expand Down Expand Up @@ -134,4 +141,5 @@

/** Sets the RendererInterface to use in the controller. */
- (void)setRenderer:(std::unique_ptr<mozc::renderer::RendererInterface>)newRenderer;

@end
16 changes: 11 additions & 5 deletions src/mac/GoogleJapaneseInputController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#import "mac/GoogleJapaneseInputControllerInterface.h"
#import "mac/GoogleJapaneseInputServer.h"
#import "mac/KeyCodeMap.h"
#import "mac/renderer_receiver.h"

#include "absl/log/log.h"
#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -77,6 +78,10 @@
using SetOfString = std::set<std::string, std::less<>>;

namespace {
// Global object used as a singleton used as a proxy to receive messages from
// the renderer process.
RendererReceiver *gRendererReceiver = nil;

// TODO(horo): This value should be get from system configuration.
// DoubleClickInterval can be get from NSEvent (MacOSX ver >= 10.6)
constexpr NSTimeInterval kDoubleTapInterval = 0.5;
Expand Down Expand Up @@ -280,11 +285,8 @@ - (void)activateServer:(id)sender {
}
[self handleConfig];

// This is a workaroud due to the crash issue on macOS 15.
NSOperatingSystemVersion versionInfo = [[NSProcessInfo processInfo] operatingSystemVersion];
if (versionInfo.majorVersion < 15) {
[imkServer_ setCurrentController:self];
}
// Sets this controller as the active controller to receive messages from the renderer process.
[gRendererReceiver setCurrentController:self];

std::string window_name, window_owner;
if (mozc::MacUtil::GetFrontmostWindowNameAndOwner(&window_name, &window_owner)) {
Expand Down Expand Up @@ -955,4 +957,8 @@ - (void)outputResult:(mozc::commands::Output *)output {
}
[self commitText:output->result().value().c_str() client:[self client]];
}

+ (void)setGlobalRendererReceiver:(RendererReceiver *)rendererReceiver {
gRendererReceiver = rendererReceiver;
}
@end
1 change: 1 addition & 0 deletions src/mac/mac.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
'GoogleJapaneseInputServer.mm',
'KeyCodeMap.mm',
'main.mm',
'renderer_receiver.mm',
],
'product_name': '<(branding)',
'dependencies': [
Expand Down
15 changes: 8 additions & 7 deletions src/mac/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#import <Cocoa/Cocoa.h>

#include <memory>
#import <Foundation/Foundation.h>

#import "mac/GoogleJapaneseInputController.h"
#import "mac/GoogleJapaneseInputServer.h"
#import "mac/renderer_receiver.h"

#include <memory>

#include "absl/flags/flag.h"
#include "absl/log/log.h"
Expand Down Expand Up @@ -69,11 +71,10 @@ int main(int argc, char *argv[]) {
}
DLOG(INFO) << mozc::kProductNameInEnglish << " initialized";

// This is a workaroud due to the crash issue on macOS 15.
NSOperatingSystemVersion versionInfo = [[NSProcessInfo processInfo] operatingSystemVersion];
if (versionInfo.majorVersion < 15) {
[imkServer registerRendererConnection];
}
NSString *rendererConnectionName = @kProductPrefix "_Renderer_Connection";
RendererReceiver *rendererReceiver =
[[RendererReceiver alloc] initWithName:rendererConnectionName];
[GoogleJapaneseInputController setGlobalRendererReceiver:rendererReceiver];

// Start the converter server at this time explicitly to prevent the
// slow-down of the response for initial key event.
Expand Down

0 comments on commit 120bd93

Please sign in to comment.