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

fix: multi screen window show #450

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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 @@ -11,6 +11,8 @@
NS_ASSUME_NONNULL_BEGIN

@interface EZCoordinateUtils : NSObject
// record start query screen
@property (nonatomic, strong, class, nullable) NSScreen *startQueryScreen;

/// Get safe point, bottom-left coordinate.
+ (CGPoint)getFrameSafePoint:(CGRect)frame moveToPoint:(CGPoint)point inScreen:(NSScreen *)screen;
Expand Down
16 changes: 14 additions & 2 deletions Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
//

#import "EZCoordinateUtils.h"

@implementation EZCoordinateUtils

+ (void)setStartQueryScreen:(NSScreen *)startQueryScreen {
objc_setAssociatedObject(self, @selector(startQueryScreen), startQueryScreen, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

+ (NSScreen *)startQueryScreen {
return objc_getAssociatedObject(self, _cmd);
}


+ (CGPoint)getFrameSafePoint:(CGRect)frame moveToPoint:(CGPoint)point inScreen:(NSScreen *)screen {
CGRect newFrame = CGRectMake(point.x, point.y, frame.size.width, frame.size.height);
return [self getSafeLocation:newFrame inScreen:screen];
Expand All @@ -30,7 +38,11 @@ + (CGPoint)getSafeLocation:(CGRect)frame inScreen:(NSScreen *)screen {
/// Make sure frame show in screen visible frame, return left-bottom postion frame.
+ (CGRect)getSafeAreaFrame:(CGRect)frame inScreen:(nullable NSScreen *)screen {
if (!screen) {
screen = [self screenOfMousePosition];
if ([self startQueryScreen]) {
screen = [self startQueryScreen];
} else {
screen = [self screenOfMousePosition];
}
}
CGRect visibleFrame = screen.visibleFrame;
if (CGRectContainsRect(visibleFrame, frame)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ - (void)startQueryText:(NSString *)text actionType:(EZActionType)actionType {
return;
}

// record current screen when start query
NSScreen *current = [EZCoordinateUtils screenForPoint: [NSEvent mouseLocation]];
EZCoordinateUtils.startQueryScreen = current;

self.inputText = text;
self.queryModel.actionType = actionType;
self.queryView.isTypingChinese = NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,9 @@ - (void)closeFloatingWindow {
NSNumber *windowType = @(self.floatingWindowType);
[self.floatingWindowTypeArray removeObject:windowType];
[self.floatingWindowTypeArray insertObject:windowType atIndex:1];

// clear start quert screen
EZCoordinateUtils.startQueryScreen = nil;
}

/// Close floating window, except main window.
Expand Down