Skip to content

Commit

Permalink
perf: improve closing floating window
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed Apr 12, 2024
1 parent d705545 commit 7d7c8d4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
3 changes: 1 addition & 2 deletions Easydict/objc/EventMonitor/EZEventMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, copy) void (^selectedTextBlock)(NSString *selectedText);
@property (nonatomic, copy) void (^dismissPopButtonBlock)(void);
@property (nonatomic, copy) void (^dismissMiniWindowBlock)(void);
@property (nonatomic, copy) void (^dismissFixedWindowBlock)(void);
@property (nonatomic, copy) void (^dismissAllNotPinndFloatingWindowBlock)(void);
@property (nonatomic, copy) void (^doubleCommandBlock)(void);
@property (nonatomic, copy) void (^leftMouseDownBlock)(CGPoint clickPoint);
@property (nonatomic, copy) void (^rightMouseDownBlock)(CGPoint clickPoint);
Expand Down
15 changes: 2 additions & 13 deletions Easydict/objc/EventMonitor/EZEventMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -829,19 +829,8 @@ - (void)handleMonitorEvent:(NSEvent *)event {


- (void)dismissWindowsIfMouseLocationOutsideFloatingWindow {
EZWindowManager *windowManager = EZWindowManager.shared;
if (windowManager.floatingWindowType == EZWindowTypeMini) {
BOOL outsideMiniWindow = ![self checkIfMouseLocationInWindow:windowManager.miniWindow];
if (outsideMiniWindow && self.dismissMiniWindowBlock) {
self.dismissMiniWindowBlock();
}
} else {
if (windowManager.floatingWindowType == EZWindowTypeFixed) {
BOOL outsideFixedWindow = ![self checkIfMouseLocationInWindow:windowManager.fixedWindow];
if (outsideFixedWindow && self.dismissFixedWindowBlock) {
self.dismissFixedWindowBlock();
}
}
if (![self checkIfMouseLocationInWindow:EZWindowManager.shared.floatingWindow]) {
self.dismissAllNotPinndFloatingWindowBlock();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ - (void)windowDidResignKey:(NSNotification *)notification {
}

- (void)windowDidResize:(NSNotification *)aNotification {
// NSLog(@"MainWindow 窗口拉伸, (%.2f, %.2f)", self.width, self.height);
// NSLog(@"windowDidResize: %@, windowType: %ld", @(self.frame), self.windowType);

[[EZLayoutManager shared] updateWindowFrame:self];

if (self.resizeWindowBlock) {
Expand Down
24 changes: 12 additions & 12 deletions Easydict/objc/ViewController/Window/WindowManager/EZWindowManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,10 @@ - (void)setupEventMonitor {
[self.popButtonWindow close];
}];

[self.eventMonitor setDismissMiniWindowBlock:^{
[self.eventMonitor setDismissAllNotPinndFloatingWindowBlock:^{
mm_strongify(self);
[self closeFloatingWindowIfNotPinned];
}];

[self.eventMonitor setDismissFixedWindowBlock:^{
mm_strongify(self);
[self closeFloatingWindowIfNotPinned];
[self closeFloatingWindowIfNotPinnedOrMain:EZWindowTypeMini];
[self closeFloatingWindowIfNotPinnedOrMain:EZWindowTypeFixed];
}];

[self.eventMonitor setDoubleCommandBlock:^{
Expand Down Expand Up @@ -777,7 +773,7 @@ - (void)inputTranslate {

EZWindowType windowType = Configuration.shared.shortcutSelectTranslateWindowType;

if (self.floatingWindowType == windowType) {
if (self.floatingWindowType == windowType && self.floatingWindow.isVisible) {
[self closeFloatingWindow];
return;
}
Expand All @@ -797,7 +793,7 @@ - (void)showMiniFloatingWindow {

EZWindowType windowType = Configuration.shared.mouseSelectTranslateWindowType;

if (self.floatingWindowType == windowType) {
if (self.floatingWindowType == windowType && self.floatingWindow.isVisible) {
[self closeFloatingWindow];
return;
}
Expand Down Expand Up @@ -920,6 +916,10 @@ - (void)closeFloatingWindowIfNotPinned {
[self closeFloatingWindowIfNotPinned:self.floatingWindowType exceptWindowType:EZWindowTypeNone];
}

- (void)closeFloatingWindowIfNotPinnedOrMain:(EZWindowType)windowType {
[self closeFloatingWindowIfNotPinned:windowType exceptWindowType:EZWindowTypeMain];
}

- (void)closeFloatingWindowIfNotPinned:(EZWindowType)windowType exceptWindowType:(EZWindowType)exceptWindowType {
EZBaseQueryWindow *window = [self windowWithType:windowType];
if (!window.isPin && windowType != exceptWindowType) {
Expand All @@ -928,13 +928,13 @@ - (void)closeFloatingWindowIfNotPinned:(EZWindowType)windowType exceptWindowType
}

- (void)closeFloatingWindow:(EZWindowType)windowType {
NSLog(@"close window type: %ld", windowType);

EZBaseQueryWindow *floatingWindow = [self windowWithType:windowType];
if (!floatingWindow) {
if (!floatingWindow || !floatingWindow.isVisible) {
return;
}

NSLog(@"close window type: %ld", windowType);

// Stop playing audio
[floatingWindow.queryViewController stopPlayingQueryText];
floatingWindow.titleBar.pin = NO;
Expand Down

0 comments on commit 7d7c8d4

Please sign in to comment.