From 6284df23786ea42cf4d8b32b2f27d5feebfc805f Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Sun, 10 Mar 2024 17:09:58 +0800 Subject: [PATCH 1/8] fix: multi screen window show --- Easydict.xcodeproj/project.pbxproj | 4 ++ Easydict/App/Localizable.xcstrings | 51 +++++++++++++++++++ .../Feature/Configuration/Configuration.swift | 2 + Easydict/Feature/Service/Model/EZEnumTypes.h | 5 ++ .../EZCoordinateUtils/EZCoordinateUtils.m | 7 ++- .../Configuration+Defaults.swift | 6 +++ .../WindowMultiScreenTypeExtensions.swift | 36 +++++++++++++ .../View/SettingView/Tabs/GeneralTab.swift | 7 +++ 8 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 Easydict/NewApp/Utility/Extensions/WindowMultiScreenTypeExtensions.swift diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 6f7b89dae..d562b154f 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -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 */; }; @@ -809,6 +810,7 @@ 9672D7D02B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MASShortcutBinder+EZMASShortcutBinder.h"; sourceTree = ""; }; 9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MASShortcutBinder+EZMASShortcutBinder.m"; sourceTree = ""; }; 967712ED2B5B943400105E0F /* Shortcut.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shortcut.swift; sourceTree = ""; }; + 96E1555C2B9DA60A00433EF3 /* WindowMultiScreenTypeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowMultiScreenTypeExtensions.swift; sourceTree = ""; }; 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 = ""; }; C415C0AC2B450D4800A9D231 /* GeminiService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeminiService.swift; sourceTree = ""; }; C4DD01E82B12B3C80025EE8E /* TencentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TencentService.swift; sourceTree = ""; }; @@ -2393,6 +2395,7 @@ EAED41F02B54B1A60005FE0A /* QueryService+ConfigurableService */, EA9943E72B534D8900EE7B97 /* LanguageDetectOptimizeExtensions.swift */, EA9943ED2B5353AB00EE7B97 /* WindowTypeExtensions.swift */, + 96E1555C2B9DA60A00433EF3 /* WindowMultiScreenTypeExtensions.swift */, EA9943EF2B5354C400EE7B97 /* ShowWindowPositionExtensions.swift */, EA9943F12B5358BF00EE7B97 /* LanguageExtensions.swift */, ); @@ -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 */, diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index b7f0ca931..3bde67d98 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -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" : { @@ -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" : { diff --git a/Easydict/Feature/Configuration/Configuration.swift b/Easydict/Feature/Configuration/Configuration.swift index f73c44218..560ba69a6 100644 --- a/Easydict/Feature/Configuration/Configuration.swift +++ b/Easydict/Feature/Configuration/Configuration.swift @@ -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 diff --git a/Easydict/Feature/Service/Model/EZEnumTypes.h b/Easydict/Feature/Service/Model/EZEnumTypes.h index cad41e525..a089037c7 100644 --- a/Easydict/Feature/Service/Model/EZEnumTypes.h +++ b/Easydict/Feature/Service/Model/EZEnumTypes.h @@ -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); diff --git a/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m b/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m index 6b17ff1de..5880d2a43 100644 --- a/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m +++ b/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m @@ -7,6 +7,7 @@ // #import "EZCoordinateUtils.h" +#import "Easydict-Swift.h" @implementation EZCoordinateUtils @@ -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 + } } CGRect visibleFrame = screen.visibleFrame; if (CGRectContainsRect(visibleFrame, frame)) { diff --git a/Easydict/NewApp/Configuration/Configuration+Defaults.swift b/Easydict/NewApp/Configuration/Configuration+Defaults.swift index 63568e242..f9db41382 100644 --- a/Easydict/NewApp/Configuration/Configuration+Defaults.swift +++ b/Easydict/NewApp/Configuration/Configuration+Defaults.swift @@ -66,6 +66,12 @@ extension Defaults.Keys { "EZConfiguration_kShowFixedWindowPositionKey", default: .right ) + + static let showWindowMultiScreen = Key( + "EZConfiguration_kShowWindowMultiScreenKey", + default: .fixed + ) + static let mouseSelectTranslateWindowType = Key( "EZConfiguration_kMouseSelectTranslateWindowTypeKey", default: .mini diff --git a/Easydict/NewApp/Utility/Extensions/WindowMultiScreenTypeExtensions.swift b/Easydict/NewApp/Utility/Extensions/WindowMultiScreenTypeExtensions.swift new file mode 100644 index 000000000..76d213ab3 --- /dev/null +++ b/Easydict/NewApp/Utility/Extensions/WindowMultiScreenTypeExtensions.swift @@ -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" + } + } +} diff --git a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift index 1a1554198..d86c787b9 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift @@ -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") } @@ -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 From cdc0b9d2080c572eaea3a5c4f4797ce64babe465 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Mon, 11 Mar 2024 21:09:24 +0800 Subject: [PATCH 2/8] fix: remove option multi screen type --- Easydict.xcodeproj/project.pbxproj | 4 -- Easydict/App/Localizable.xcstrings | 51 ------------------- Easydict/Feature/Service/Model/EZEnumTypes.h | 5 -- .../WindowMultiScreenTypeExtensions.swift | 36 ------------- .../View/SettingView/Tabs/GeneralTab.swift | 6 --- 5 files changed, 102 deletions(-) delete mode 100644 Easydict/NewApp/Utility/Extensions/WindowMultiScreenTypeExtensions.swift diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index d562b154f..6f7b89dae 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -286,7 +286,6 @@ 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 */; }; @@ -810,7 +809,6 @@ 9672D7D02B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MASShortcutBinder+EZMASShortcutBinder.h"; sourceTree = ""; }; 9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MASShortcutBinder+EZMASShortcutBinder.m"; sourceTree = ""; }; 967712ED2B5B943400105E0F /* Shortcut.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shortcut.swift; sourceTree = ""; }; - 96E1555C2B9DA60A00433EF3 /* WindowMultiScreenTypeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowMultiScreenTypeExtensions.swift; sourceTree = ""; }; 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 = ""; }; C415C0AC2B450D4800A9D231 /* GeminiService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeminiService.swift; sourceTree = ""; }; C4DD01E82B12B3C80025EE8E /* TencentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TencentService.swift; sourceTree = ""; }; @@ -2395,7 +2393,6 @@ EAED41F02B54B1A60005FE0A /* QueryService+ConfigurableService */, EA9943E72B534D8900EE7B97 /* LanguageDetectOptimizeExtensions.swift */, EA9943ED2B5353AB00EE7B97 /* WindowTypeExtensions.swift */, - 96E1555C2B9DA60A00433EF3 /* WindowMultiScreenTypeExtensions.swift */, EA9943EF2B5354C400EE7B97 /* ShowWindowPositionExtensions.swift */, EA9943F12B5358BF00EE7B97 /* LanguageExtensions.swift */, ); @@ -3045,7 +3042,6 @@ 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 */, diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 3bde67d98..b7f0ca931 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -3571,23 +3571,6 @@ } } }, - "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" : { @@ -4074,40 +4057,6 @@ } } }, - "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" : { diff --git a/Easydict/Feature/Service/Model/EZEnumTypes.h b/Easydict/Feature/Service/Model/EZEnumTypes.h index a089037c7..cad41e525 100644 --- a/Easydict/Feature/Service/Model/EZEnumTypes.h +++ b/Easydict/Feature/Service/Model/EZEnumTypes.h @@ -27,11 +27,6 @@ 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); diff --git a/Easydict/NewApp/Utility/Extensions/WindowMultiScreenTypeExtensions.swift b/Easydict/NewApp/Utility/Extensions/WindowMultiScreenTypeExtensions.swift deleted file mode 100644 index 76d213ab3..000000000 --- a/Easydict/NewApp/Utility/Extensions/WindowMultiScreenTypeExtensions.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// 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" - } - } -} diff --git a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift index d86c787b9..becefd4cb 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift @@ -110,12 +110,6 @@ 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") } From 7ba23ed194736f9bbcd07ae1dd480973a9030184 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Mon, 11 Mar 2024 21:11:15 +0800 Subject: [PATCH 3/8] fix: remove option multi screen type --- Easydict/Feature/Configuration/Configuration.swift | 2 -- Easydict/NewApp/Configuration/Configuration+Defaults.swift | 4 ---- Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift | 1 - 3 files changed, 7 deletions(-) diff --git a/Easydict/Feature/Configuration/Configuration.swift b/Easydict/Feature/Configuration/Configuration.swift index 560ba69a6..f73c44218 100644 --- a/Easydict/Feature/Configuration/Configuration.swift +++ b/Easydict/Feature/Configuration/Configuration.swift @@ -90,8 +90,6 @@ class Configuration: NSObject { @DefaultsWrapper(.fixedWindowPosition) var fixedWindowPosition: EZShowWindowPosition - @DefaultsWrapper(.showWindowMultiScreen) var showWindowMultiScreen: EZShowWindowMultiScreen - @DefaultsWrapper(.mouseSelectTranslateWindowType) var mouseSelectTranslateWindowType: EZWindowType @DefaultsWrapper(.shortcutSelectTranslateWindowType) var shortcutSelectTranslateWindowType: EZWindowType diff --git a/Easydict/NewApp/Configuration/Configuration+Defaults.swift b/Easydict/NewApp/Configuration/Configuration+Defaults.swift index f9db41382..853c55d51 100644 --- a/Easydict/NewApp/Configuration/Configuration+Defaults.swift +++ b/Easydict/NewApp/Configuration/Configuration+Defaults.swift @@ -67,10 +67,6 @@ extension Defaults.Keys { default: .right ) - static let showWindowMultiScreen = Key( - "EZConfiguration_kShowWindowMultiScreenKey", - default: .fixed - ) static let mouseSelectTranslateWindowType = Key( "EZConfiguration_kMouseSelectTranslateWindowTypeKey", diff --git a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift index becefd4cb..1a1554198 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift @@ -282,7 +282,6 @@ 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 From c04a1bd7a708d8d1ba5b340a4c77843a11b83a62 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 12 Mar 2024 12:36:03 +0800 Subject: [PATCH 4/8] feat: add record for start query screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 
 --- .../EZCoordinateUtils/EZCoordinateUtils.h | 2 ++ .../EZCoordinateUtils/EZCoordinateUtils.m | 18 +++++++++++++----- .../EZBaseQueryViewController.m | 4 ++++ .../Configuration/Configuration+Defaults.swift | 2 -- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.h b/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.h index df268b6fc..47f616aa5 100644 --- a/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.h +++ b/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.h @@ -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; diff --git a/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m b/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m index 5880d2a43..1ea061327 100644 --- a/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m +++ b/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m @@ -7,10 +7,17 @@ // #import "EZCoordinateUtils.h" -#import "Easydict-Swift.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]; @@ -31,10 +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) { - if (Configuration.shared.showWindowMultiScreen == EZShowWindowMultiScreenAuto) { - screen = [self screenOfMousePosition]; + if ([self startQueryScreen]) { + screen = [self startQueryScreen]; } else { - screen = NSScreen.mainScreen; // EZShowWindowMultiScreenFixed fixed in main screen + + screen = [self screenOfMousePosition]; } } CGRect visibleFrame = screen.visibleFrame; diff --git a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m index 066bb8128..66795c863 100644 --- a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m +++ b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m @@ -376,6 +376,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; diff --git a/Easydict/NewApp/Configuration/Configuration+Defaults.swift b/Easydict/NewApp/Configuration/Configuration+Defaults.swift index 853c55d51..63568e242 100644 --- a/Easydict/NewApp/Configuration/Configuration+Defaults.swift +++ b/Easydict/NewApp/Configuration/Configuration+Defaults.swift @@ -66,8 +66,6 @@ extension Defaults.Keys { "EZConfiguration_kShowFixedWindowPositionKey", default: .right ) - - static let mouseSelectTranslateWindowType = Key( "EZConfiguration_kMouseSelectTranslateWindowTypeKey", default: .mini From 68b2648e328606125b967944011a295f456a21cb Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 12 Mar 2024 12:52:05 +0800 Subject: [PATCH 5/8] feat: remove start query screen when floating window close --- .../ViewController/Window/WindowManager/EZWindowManager.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m index aba0cecb8..fa12391ff 100644 --- a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m +++ b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m @@ -931,6 +931,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. From 8346158f8f444c53331851c7a3f201a45f735f3d Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 12 Mar 2024 05:04:27 +0000 Subject: [PATCH 6/8] remove blank line --- Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m b/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m index 1ea061327..3e1d16dfb 100644 --- a/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m +++ b/Easydict/Feature/Utility/EZCoordinateUtils/EZCoordinateUtils.m @@ -41,7 +41,6 @@ + (CGRect)getSafeAreaFrame:(CGRect)frame inScreen:(nullable NSScreen *)screen { if ([self startQueryScreen]) { screen = [self startQueryScreen]; } else { - screen = [self screenOfMousePosition]; } } From 9a7fc3610755e934193d4efe663dd615ad5896ce Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Wed, 13 Mar 2024 22:50:44 +0800 Subject: [PATCH 7/8] pref: record screen using selection translation by Accessibility --- Easydict/Feature/EventMonitor/EZEventMonitor.m | 8 ++++++++ .../Window/BaseQueryWindow/EZBaseQueryViewController.m | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Easydict/Feature/EventMonitor/EZEventMonitor.m b/Easydict/Feature/EventMonitor/EZEventMonitor.m index f3acfe5ab..ea05a60aa 100644 --- a/Easydict/Feature/EventMonitor/EZEventMonitor.m +++ b/Easydict/Feature/EventMonitor/EZEventMonitor.m @@ -511,6 +511,14 @@ - (void)getSelectedTextByAccessibility:(void (^)(NSString *_Nullable text, AXErr CGRect selectedTextFrame = [self getSelectedTextFrame]; // NSLog(@"selected text: %@", @(selectedTextFrame)); + // record screen + NSArray *screens = NSScreen.screens; + for (NSScreen *screen in screens) { + if (NSMouseInRect(selectedTextFrame.origin, screen.frame, NO)) { + EZCoordinateUtils.startQueryScreen = screen; + } + } + self.selectedTextFrame = [EZCoordinateUtils convertRectToBottomLeft:selectedTextFrame]; if (getFocusedUIElementError == kAXErrorSuccess) { diff --git a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m index 15475cafb..36884c99c 100644 --- a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m +++ b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m @@ -399,8 +399,10 @@ - (void)startQueryText:(NSString *)text actionType:(EZActionType)actionType { } // record current screen when start query - NSScreen *current = [EZCoordinateUtils screenForPoint: [NSEvent mouseLocation]]; - EZCoordinateUtils.startQueryScreen = current; + if (EZCoordinateUtils.startQueryScreen == nil) { + NSScreen *current = [EZCoordinateUtils screenForPoint: [NSEvent mouseLocation]]; + EZCoordinateUtils.startQueryScreen = current; + } self.inputText = text; self.queryModel.actionType = actionType; From 74515c9febe457d041a004a07ec657298e09c6d8 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Wed, 13 Mar 2024 23:36:10 +0800 Subject: [PATCH 8/8] pref: record screen using selection translation by apple script --- .../Feature/EventMonitor/EZEventMonitor.m | 4 ++- .../AppleScript/EZAppleScriptManager.m | 27 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Easydict/Feature/EventMonitor/EZEventMonitor.m b/Easydict/Feature/EventMonitor/EZEventMonitor.m index ea05a60aa..9d0a258d5 100644 --- a/Easydict/Feature/EventMonitor/EZEventMonitor.m +++ b/Easydict/Feature/EventMonitor/EZEventMonitor.m @@ -515,7 +515,9 @@ - (void)getSelectedTextByAccessibility:(void (^)(NSString *_Nullable text, AXErr NSArray *screens = NSScreen.screens; for (NSScreen *screen in screens) { if (NSMouseInRect(selectedTextFrame.origin, screen.frame, NO)) { - EZCoordinateUtils.startQueryScreen = screen; + if (EZCoordinateUtils.startQueryScreen == nil) { + EZCoordinateUtils.startQueryScreen = screen; + } } } diff --git a/Easydict/Feature/Utility/AppleScript/EZAppleScriptManager.m b/Easydict/Feature/Utility/AppleScript/EZAppleScriptManager.m index 6cf871203..612d7d58f 100644 --- a/Easydict/Feature/Utility/AppleScript/EZAppleScriptManager.m +++ b/Easydict/Feature/Utility/AppleScript/EZAppleScriptManager.m @@ -9,7 +9,7 @@ #import "EZAppleScriptManager.h" #import "EZConfiguration.h" #import "Easydict-Swift.h" - +#import "EZCoordinateUtils.h" @interface EZAppleScriptManager () @property (nonatomic, strong) EZScriptExecutor *scriptExecutor; @@ -70,6 +70,7 @@ - (BOOL)isChromeKernelBrowser:(NSString *)bundleID { - (void)getBrowserSelectedText:(NSString *)bundleID completion:(AppleScriptCompletionHandler)completion { // NSLog(@"get Browser selected text: %@", bundleID); + [self recordBrowerLocaledInScreen:bundleID]; if ([self isSafari:bundleID]) { [self getSafariSelectedText:completion]; @@ -80,6 +81,30 @@ - (void)getBrowserSelectedText:(NSString *)bundleID completion:(AppleScriptCompl } } +- (void)recordBrowerLocaledInScreen:(NSString *)bundleID { + NSArray *runningApplications = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID]; + if (runningApplications.count > 0) { + CGRect browerFrame = CGRectZero; + NSRunningApplication *brower = runningApplications.firstObject; + + NSArray *windows = (__bridge_transfer NSArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); + for (NSDictionary *windowInfo in windows) { + if ([[windowInfo objectForKey:@"kCGWindowOwnerName"] isEqualToString:brower.localizedName]) { + CGRectMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)[windowInfo objectForKey:@"kCGWindowBounds"], &browerFrame); + } + } + + for (NSScreen *screen in NSScreen.screens) { + if (!CGRectEqualToRect(browerFrame, CGRectZero) && + NSIntersectsRect(screen.frame, browerFrame)) { + if (EZCoordinateUtils.startQueryScreen == nil) { + EZCoordinateUtils.startQueryScreen = screen; + } + } + } + } +} + /// Get Safari selected text by AppleScript. Cost ~100ms - (void)getSafariSelectedText:(AppleScriptCompletionHandler)completion { NSString *bundleID = @"com.apple.Safari";