From 2af54e42f0aee7d5e31fe749d4b04f0220b4d036 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Thu, 2 Jul 2026 09:08:27 +0800 Subject: [PATCH] feat(indicator): add toggle for text input source icons. --- .../IndicatorWindowController+Indicator.swift | 4 ++- Input Source Pro/Models/PreferencesVM.swift | 4 +++ .../Resources/en.lproj/Localizable.strings | 1 + .../Resources/ja.lproj/Localizable.strings | 1 + .../Resources/ko.lproj/Localizable.strings | 1 + .../zh-Hans.lproj/Localizable.strings | 1 + .../zh-Hant.lproj/Localizable.strings | 1 + .../Components/CustomizedIndicatorView.swift | 5 +-- .../UI/Components/IndicatorView.swift | 3 +- .../UI/Components/KeyboardCustomization.swift | 6 ++-- .../UI/Screens/AppearanceSettingsView.swift | 12 +++++++ .../UI/Screens/KeyboardsSettingsView.swift | 3 +- .../Indicator/IndicatorViewConfig.swift | 32 +++++++++---------- 13 files changed, 51 insertions(+), 23 deletions(-) diff --git a/Input Source Pro/Controllers/IndicatorWindowController+Indicator.swift b/Input Source Pro/Controllers/IndicatorWindowController+Indicator.swift index bb1d1ce..cdde013 100644 --- a/Input Source Pro/Controllers/IndicatorWindowController+Indicator.swift +++ b/Input Source Pro/Controllers/IndicatorWindowController+Indicator.swift @@ -19,6 +19,7 @@ extension IndicatorWindowController { size: preferences.indicatorSize ?? .medium, bgColor: preferencesVM.defaultIndicatorBgNSColor, textColor: preferencesVM.defaultIndicatorTextNSColor, + prefersTextInputSourceIcons: preferences.prefersTextInputSourceIcons, badge: .init(glyph: mode.badgeGlyph, title: mode.displayName) )) @@ -34,7 +35,8 @@ extension IndicatorWindowController { kind: preferences.indicatorKind, size: preferences.indicatorSize ?? .medium, bgColor: preferencesVM.getBgNSColor(inputSource), - textColor: preferencesVM.getTextNSColor(inputSource) + textColor: preferencesVM.getTextNSColor(inputSource), + prefersTextInputSourceIcons: preferences.prefersTextInputSourceIcons )) if isActive { diff --git a/Input Source Pro/Models/PreferencesVM.swift b/Input Source Pro/Models/PreferencesVM.swift index e9dc183..f9134f1 100644 --- a/Input Source Pro/Models/PreferencesVM.swift +++ b/Input Source Pro/Models/PreferencesVM.swift @@ -319,6 +319,7 @@ struct Preferences { static let isAutoAppearanceMode = "isAutoAppearanceMode" static let appearanceMode = "appearanceMode" static let isShowInputSourcesLabel = "isShowInputSourcesLabel" + static let prefersTextInputSourceIcons = "prefersTextInputSourceIcons" static let indicatorBackground = "indicatorBackground" static let indicatorForgeground = "indicatorForgeground" @@ -505,6 +506,9 @@ struct Preferences { @CodableUserDefault(Preferences.Key.indicatorSize) var indicatorSize = IndicatorSize.medium + @UserDefault(Preferences.Key.prefersTextInputSourceIcons) + var prefersTextInputSourceIcons = true + @UserDefault(Preferences.Key.isAutoAppearanceMode) var isAutoAppearanceMode = true diff --git a/Input Source Pro/Resources/en.lproj/Localizable.strings b/Input Source Pro/Resources/en.lproj/Localizable.strings index 59c749b..a20914c 100644 --- a/Input Source Pro/Resources/en.lproj/Localizable.strings +++ b/Input Source Pro/Resources/en.lproj/Localizable.strings @@ -96,6 +96,7 @@ "Appearance" = "Appearance"; "Indicator Info" = "Indicator Info"; +"Use Text Input Source Icons" = "Use Text Input Source Icons"; "Icon and Title" = "Icon and Title"; "Icon" = "Icon"; "Title" = "Title"; diff --git a/Input Source Pro/Resources/ja.lproj/Localizable.strings b/Input Source Pro/Resources/ja.lproj/Localizable.strings index fd3146a..820bd4a 100644 --- a/Input Source Pro/Resources/ja.lproj/Localizable.strings +++ b/Input Source Pro/Resources/ja.lproj/Localizable.strings @@ -96,6 +96,7 @@ "Appearance" = "外観"; "Indicator Info" = "インジケーター情報"; +"Use Text Input Source Icons" = "文字入力ソースアイコンを使用"; "Icon and Title" = "アイコンとタイトル"; "Icon" = "アイコン"; "Title" = "タイトル"; diff --git a/Input Source Pro/Resources/ko.lproj/Localizable.strings b/Input Source Pro/Resources/ko.lproj/Localizable.strings index 0121c4f..63b8b69 100644 --- a/Input Source Pro/Resources/ko.lproj/Localizable.strings +++ b/Input Source Pro/Resources/ko.lproj/Localizable.strings @@ -96,6 +96,7 @@ "Appearance" = "외관"; "Indicator Info" = "표시기 정보"; +"Use Text Input Source Icons" = "텍스트 입력 소스 아이콘 사용"; "Icon and Title" = "아이콘 및 제목"; "Icon" = "아이콘"; "Title" = "제목"; diff --git a/Input Source Pro/Resources/zh-Hans.lproj/Localizable.strings b/Input Source Pro/Resources/zh-Hans.lproj/Localizable.strings index 8049db4..888d61b 100644 --- a/Input Source Pro/Resources/zh-Hans.lproj/Localizable.strings +++ b/Input Source Pro/Resources/zh-Hans.lproj/Localizable.strings @@ -98,6 +98,7 @@ "Appearance" = "外观"; "Indicator Info" = "指示器信息"; +"Use Text Input Source Icons" = "使用文字输入法图标"; "Icon and Title" = "图标和标题"; "Icon" = "图标"; "Title" = "标题"; diff --git a/Input Source Pro/Resources/zh-Hant.lproj/Localizable.strings b/Input Source Pro/Resources/zh-Hant.lproj/Localizable.strings index 7d93c8c..e42cfe5 100644 --- a/Input Source Pro/Resources/zh-Hant.lproj/Localizable.strings +++ b/Input Source Pro/Resources/zh-Hant.lproj/Localizable.strings @@ -98,6 +98,7 @@ "Appearance" = "外觀"; "Indicator Info" = "指示器資訊"; +"Use Text Input Source Icons" = "使用文字輸入法圖示"; "Icon and Title" = "圖示和標題"; "Icon" = "圖示"; "Title" = "標題"; diff --git a/Input Source Pro/UI/Components/CustomizedIndicatorView.swift b/Input Source Pro/UI/Components/CustomizedIndicatorView.swift index 81f1662..ad4167e 100644 --- a/Input Source Pro/UI/Components/CustomizedIndicatorView.swift +++ b/Input Source Pro/UI/Components/CustomizedIndicatorView.swift @@ -15,8 +15,9 @@ struct CustomizedIndicatorView: View { inputSource: inputSource, kind: preferencesVM.preferences.indicatorKind, size: preferencesVM.preferences.indicatorSize ?? .medium, - bgColor: NSColor(preferencesVM.getBgColor(inputSource)), - textColor: NSColor(preferencesVM.getTextColor(inputSource)) + bgColor: nil, + textColor: NSColor(preferencesVM.getTextColor(inputSource)), + prefersTextInputSourceIcons: preferencesVM.preferences.prefersTextInputSourceIcons )) } } diff --git a/Input Source Pro/UI/Components/IndicatorView.swift b/Input Source Pro/UI/Components/IndicatorView.swift index 6c292d0..d2639ba 100644 --- a/Input Source Pro/UI/Components/IndicatorView.swift +++ b/Input Source Pro/UI/Components/IndicatorView.swift @@ -15,7 +15,8 @@ struct IndicatorView: NSViewControllerRepresentable { kind: preferencesVM.preferences.indicatorKind, size: preferencesVM.preferences.indicatorSize ?? .medium, bgColor: NSColor(preferencesVM.preferences.indicatorBackgroundColor), - textColor: NSColor(preferencesVM.preferences.indicatorForgegroundColor) + textColor: NSColor(preferencesVM.preferences.indicatorForgegroundColor), + prefersTextInputSourceIcons: preferencesVM.preferences.prefersTextInputSourceIcons )) indicatorViewController.refresh() diff --git a/Input Source Pro/UI/Components/KeyboardCustomization.swift b/Input Source Pro/UI/Components/KeyboardCustomization.swift index 6a5eb24..c2399fc 100644 --- a/Input Source Pro/UI/Components/KeyboardCustomization.swift +++ b/Input Source Pro/UI/Components/KeyboardCustomization.swift @@ -30,7 +30,8 @@ struct KeyboardCustomization: View { kind: .alwaysOn, size: preferencesVM.preferences.indicatorSize ?? .medium, bgColor: NSColor(bgColor), - textColor: NSColor(textColor) + textColor: NSColor(textColor), + prefersTextInputSourceIcons: preferencesVM.preferences.prefersTextInputSourceIcons )) DumpIndicatorView(config: IndicatorViewConfig( @@ -38,7 +39,8 @@ struct KeyboardCustomization: View { kind: preferencesVM.preferences.indicatorKind, size: preferencesVM.preferences.indicatorSize ?? .medium, bgColor: NSColor(bgColor), - textColor: NSColor(textColor) + textColor: NSColor(textColor), + prefersTextInputSourceIcons: preferencesVM.preferences.prefersTextInputSourceIcons )) Text("Always-On Indicator Style") diff --git a/Input Source Pro/UI/Screens/AppearanceSettingsView.swift b/Input Source Pro/UI/Screens/AppearanceSettingsView.swift index 7b9874e..5cb446b 100644 --- a/Input Source Pro/UI/Screens/AppearanceSettingsView.swift +++ b/Input Source Pro/UI/Screens/AppearanceSettingsView.swift @@ -55,6 +55,18 @@ struct AppearanceSettingsView: View { .labelsHidden() .pickerStyle(.segmented) .padding() + + HStack { + Toggle("", isOn: $preferencesVM.preferences.prefersTextInputSourceIcons) + .toggleStyle(.switch) + .labelsHidden() + + Text("Use Text Input Source Icons".i18n()) + + Spacer() + } + .padding() + .border(width: 1, edges: [.top], color: NSColor.border2.color) } } diff --git a/Input Source Pro/UI/Screens/KeyboardsSettingsView.swift b/Input Source Pro/UI/Screens/KeyboardsSettingsView.swift index d2a3004..632f29b 100644 --- a/Input Source Pro/UI/Screens/KeyboardsSettingsView.swift +++ b/Input Source Pro/UI/Screens/KeyboardsSettingsView.swift @@ -137,8 +137,9 @@ struct KeyboardsSettingsView: View { inputSource: indicatorVM.state.inputSource, kind: preferencesVM.preferences.indicatorKind, size: preferencesVM.preferences.indicatorSize ?? .medium, - bgColor: preferencesVM.defaultIndicatorBgNSColor, + bgColor: nil, textColor: preferencesVM.defaultIndicatorTextNSColor, + prefersTextInputSourceIcons: preferencesVM.preferences.prefersTextInputSourceIcons, badge: .init( glyph: currentFunctionKeyMode.badgeGlyph, title: currentFunctionKeyMode.displayName diff --git a/Input Source Pro/Utilities/Indicator/IndicatorViewConfig.swift b/Input Source Pro/Utilities/Indicator/IndicatorViewConfig.swift index a8e3cfa..ee3a718 100644 --- a/Input Source Pro/Utilities/Indicator/IndicatorViewConfig.swift +++ b/Input Source Pro/Utilities/Indicator/IndicatorViewConfig.swift @@ -21,6 +21,7 @@ struct IndicatorViewConfig { let size: IndicatorSize let bgColor: NSColor? let textColor: NSColor? + let prefersTextInputSourceIcons: Bool /// When set, the indicator renders this glyph (SF Symbol or text) + title /// instead of the input source. Lets the same pill machinery show @@ -217,7 +218,9 @@ struct IndicatorViewConfig { } private func getImageView(_ inputSource: InputSource) -> NSView? { -// if let textImage = getTextImageView(inputSource) { return textImage } + if prefersTextInputSourceIcons, let textImage = getTextImageView(inputSource) { + return textImage + } guard let image = inputSource.icon else { return nil } @@ -265,26 +268,23 @@ struct IndicatorViewConfig { else { return nil } let labelView = NSTextField(labelWithString: labelName) - let view = NSView() - - view.addSubview(labelView) - view.wantsLayer = true - view.layer?.backgroundColor = textColor?.cgColor - view.layer?.cornerRadius = 2 + labelView.textColor = textColor + labelView.alignment = .center - labelView.snp.makeConstraints { - $0.center.equalTo(view) + switch size { + case .small: + labelView.font = .systemFont(ofSize: labelName.count > 1 ? 7 : 10, weight: .regular) + case .medium: + labelView.font = .systemFont(ofSize: labelName.count > 1 ? 10 : 13, weight: .regular) + case .large: + labelView.font = .systemFont(ofSize: labelName.count > 1 ? 15 : 20, weight: .regular) } - view.snp.makeConstraints { -// $0.width.equalTo(22) - $0.width.height.equalTo(16) + labelView.snp.makeConstraints { make in + make.width.equalTo(max(leadingIconWidth, labelView.intrinsicContentSize.width)) } - labelView.textColor = bgColor - labelView.font = .systemFont(ofSize: labelName.count > 1 ? 10 : 11, weight: .regular) - - return view + return labelView } private func getContainerView() -> NSView {