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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
9672D7D22B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = 9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */; };
967712EA2B5B913600105E0F /* KeyHolder in Frameworks */ = {isa = PBXBuildFile; productRef = 967712E92B5B913600105E0F /* KeyHolder */; };
967712EE2B5B943400105E0F /* Shortcut.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967712ED2B5B943400105E0F /* Shortcut.swift */; };
96E1555D2B9DA60A00433EF3 /* WindowMultiScreenTypeExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E1555C2B9DA60A00433EF3 /* WindowMultiScreenTypeExtensions.swift */; };
A0B65CA0F31AC8ECFB8347CC /* Pods_EasydictTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 378E73A7EA8FC8FB9C975A63 /* Pods_EasydictTests.framework */; };
B87AC7E36367075BA5D13234 /* Pods_Easydict.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6372B33DFF803C7096A82250 /* Pods_Easydict.framework */; };
C415C0AD2B450D4800A9D231 /* GeminiService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415C0AC2B450D4800A9D231 /* GeminiService.swift */; };
Expand Down Expand Up @@ -809,6 +810,7 @@
9672D7D02B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MASShortcutBinder+EZMASShortcutBinder.h"; sourceTree = "<group>"; };
9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MASShortcutBinder+EZMASShortcutBinder.m"; sourceTree = "<group>"; };
967712ED2B5B943400105E0F /* Shortcut.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shortcut.swift; sourceTree = "<group>"; };
96E1555C2B9DA60A00433EF3 /* WindowMultiScreenTypeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowMultiScreenTypeExtensions.swift; sourceTree = "<group>"; };
A230E9A2358C7FBC7FB26189 /* Pods-EasydictTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EasydictTests.debug.xcconfig"; path = "Target Support Files/Pods-EasydictTests/Pods-EasydictTests.debug.xcconfig"; sourceTree = "<group>"; };
C415C0AC2B450D4800A9D231 /* GeminiService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeminiService.swift; sourceTree = "<group>"; };
C4DD01E82B12B3C80025EE8E /* TencentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TencentService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2393,6 +2395,7 @@
EAED41F02B54B1A60005FE0A /* QueryService+ConfigurableService */,
EA9943E72B534D8900EE7B97 /* LanguageDetectOptimizeExtensions.swift */,
EA9943ED2B5353AB00EE7B97 /* WindowTypeExtensions.swift */,
96E1555C2B9DA60A00433EF3 /* WindowMultiScreenTypeExtensions.swift */,
EA9943EF2B5354C400EE7B97 /* ShowWindowPositionExtensions.swift */,
EA9943F12B5358BF00EE7B97 /* LanguageExtensions.swift */,
);
Expand Down Expand Up @@ -3042,6 +3045,7 @@
03832F542B5F6BE200D0DC64 /* AdvancedTab.swift in Sources */,
0AC8A8452B6A4D97006DA5CC /* ServiceConfigurationCells.swift in Sources */,
276742092B3DC230002A2C75 /* AboutTab.swift in Sources */,
96E1555D2B9DA60A00433EF3 /* WindowMultiScreenTypeExtensions.swift in Sources */,
03008B2E2941956D0062B821 /* EZURLSchemeHandler.m in Sources */,
DC6D9C872B352EBC0055EFFC /* FontSizeHintView.swift in Sources */,
03B0232429231FA6001C7E63 /* NSUserDefaults+MM.m in Sources */,
Expand Down
51 changes: 51 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -3571,6 +3571,23 @@
}
}
},
"setting.general.window.show_window_multi_screen" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Multi Screen Query Window Location"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "多屏幕查询后窗口位置"
}
}
}
},
"setting.general.windows.header" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -4057,6 +4074,40 @@
}
}
},
"show_window_multi_screen_auto" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Auto"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "自动"
}
}
}
},
"show_window_multi_screen_fixed" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Fixed"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "固定"
}
}
}
},
"silent_screenshot_ocr" : {
"localizations" : {
"en" : {
Expand Down
2 changes: 2 additions & 0 deletions Easydict/Feature/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class Configuration: NSObject {

@DefaultsWrapper(.fixedWindowPosition) var fixedWindowPosition: EZShowWindowPosition

@DefaultsWrapper(.showWindowMultiScreen) var showWindowMultiScreen: EZShowWindowMultiScreen

@DefaultsWrapper(.mouseSelectTranslateWindowType) var mouseSelectTranslateWindowType: EZWindowType

@DefaultsWrapper(.shortcutSelectTranslateWindowType) var shortcutSelectTranslateWindowType: EZWindowType
Expand Down
5 changes: 5 additions & 0 deletions Easydict/Feature/Service/Model/EZEnumTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ typedef NS_ENUM(NSUInteger, EZShowWindowPosition) {
EZShowWindowPositionCenter = 3,
};

typedef NS_ENUM(NSUInteger, EZShowWindowMultiScreen) {
EZShowWindowMultiScreenAuto = 0,
EZShowWindowMultiScreenFixed = 1,
};

FOUNDATION_EXPORT NSString *const EZServiceTypeKey;

typedef NSString *EZServiceType NS_STRING_ENUM NS_SWIFT_NAME(ServiceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "EZCoordinateUtils.h"
#import "Easydict-Swift.h"

@implementation EZCoordinateUtils

Expand All @@ -30,7 +31,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 (Configuration.shared.showWindowMultiScreen == EZShowWindowMultiScreenAuto) {
screen = [self screenOfMousePosition];
} else {
screen = NSScreen.mainScreen; // EZShowWindowMultiScreenFixed fixed in main screen
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it should not use mainScreen here, it should use the screen when selecting words.

}
}
CGRect visibleFrame = screen.visibleFrame;
if (CGRectContainsRect(visibleFrame, frame)) {
Expand Down
6 changes: 6 additions & 0 deletions Easydict/NewApp/Configuration/Configuration+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ extension Defaults.Keys {
"EZConfiguration_kShowFixedWindowPositionKey",
default: .right
)

static let showWindowMultiScreen = Key<EZShowWindowMultiScreen>(
"EZConfiguration_kShowWindowMultiScreenKey",
default: .fixed
)

static let mouseSelectTranslateWindowType = Key<EZWindowType>(
"EZConfiguration_kMouseSelectTranslateWindowTypeKey",
default: .mini
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// WindowMultiScreenTypeExtensions.swift
// Easydict
//
// Created by Sharker on 2024/3/10.
// Copyright © 2024 izual. All rights reserved.
//

import Defaults
import Foundation

// MARK: - EZShowWindowMultiScreen + Defaults.Serializable

extension EZShowWindowMultiScreen: Defaults.Serializable {}

// MARK: - EZShowWindowMultiScreen + CaseIterable

extension EZShowWindowMultiScreen: CaseIterable {
public static let allCases: [EZShowWindowMultiScreen] = [.auto, .fixed]
}

// MARK: - EZShowWindowMultiScreen + CustomLocalizedStringResourceConvertible

@available(macOS 13, *)
extension EZShowWindowMultiScreen: CustomLocalizedStringResourceConvertible {
public var localizedStringResource: LocalizedStringResource {
switch self {
case .auto:
"show_window_multi_screen_auto"
case .fixed:
"show_window_multi_screen_fixed"
@unknown default:
"unknown_option"
}
}
}
7 changes: 7 additions & 0 deletions Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ struct GeneralTab: View {
.tag(option)
}
}
Picker("setting.general.window.show_window_multi_screen", selection: $showWindowMultiScreen) {
ForEach(EZShowWindowMultiScreen.allCases, id: \.rawValue) { option in
Text(option.localizedStringResource)
.tag(option)
}
}
} header: {
Text("setting.general.windows.header")
}
Expand Down Expand Up @@ -282,6 +288,7 @@ struct GeneralTab: View {
@Default(.defaultTTSServiceType) private var defaultTTSServiceType

@Default(.fixedWindowPosition) private var fixedWindowPosition
@Default(.showWindowMultiScreen) private var showWindowMultiScreen
@Default(.mouseSelectTranslateWindowType) private var mouseSelectTranslateWindowType
@Default(.shortcutSelectTranslateWindowType) private var shortcutSelectTranslateWindowType
@Default(.enableBetaFeature) private var enableBetaFeature
Expand Down