From cf346542c5368cc69e6c6c06fe3579826d6f4837 Mon Sep 17 00:00:00 2001 From: Roman Geraskin Date: Wed, 20 Aug 2025 18:44:24 +0300 Subject: [PATCH 1/2] refactor(hud): add universal hud with dynamic width --- Amethyst/Managers/ScreenManager.swift | 28 ++++++++++++----- Amethyst/View/LayoutNameWindow.swift | 43 +++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/Amethyst/Managers/ScreenManager.swift b/Amethyst/Managers/ScreenManager.swift index bbf4f6d9..1a5bfdb9 100644 --- a/Amethyst/Managers/ScreenManager.swift +++ b/Amethyst/Managers/ScreenManager.swift @@ -341,11 +341,26 @@ final class ScreenManager: NSObject, Codable { } func displayLayoutHUD() { + guard userConfiguration.enablesLayoutHUD(), space?.type == CGSSpaceTypeUser else { + return + } + + let currentLayoutName = currentLayout.flatMap({ $0.layoutName }) ?? "None" + let currentLayoutDescription = currentLayout?.layoutDescription ?? "" + + displayCustomHUD(title: currentLayoutName, description: currentLayoutDescription) + } + + @objc func hideLayoutHUD(_ sender: AnyObject) { + layoutNameWindowController.close() + } + + func displayCustomHUD(title: String, description: String = "") { guard let screen = screen else { return } - guard userConfiguration.enablesLayoutHUD(), space?.type == CGSSpaceTypeUser else { + guard space?.type == CGSSpaceTypeUser else { return } @@ -358,23 +373,20 @@ final class ScreenManager: NSObject, Codable { return } + // Use new displayNotification method with dynamic sizing + layoutNameWindow.displayNotification(title: title, description: description) + + // Center the window after resizing let screenFrame = screen.frame() let screenCenter = CGPoint(x: screenFrame.midX, y: screenFrame.midY) let windowOrigin = CGPoint( x: screenCenter.x - layoutNameWindow.frame.width / 2.0, y: screenCenter.y - layoutNameWindow.frame.height / 2.0 ) - - layoutNameWindow.layoutNameField?.stringValue = currentLayout.flatMap({ $0.layoutName }) ?? "None" - layoutNameWindow.layoutDescriptionLabel?.stringValue = currentLayout?.layoutDescription ?? "" layoutNameWindow.setFrameOrigin(NSPointFromCGPoint(windowOrigin)) layoutNameWindowController.showWindow(self) } - - @objc func hideLayoutHUD(_ sender: AnyObject) { - layoutNameWindowController.close() - } } extension ScreenManager: Comparable { diff --git a/Amethyst/View/LayoutNameWindow.swift b/Amethyst/View/LayoutNameWindow.swift index ec239a09..135c2296 100644 --- a/Amethyst/View/LayoutNameWindow.swift +++ b/Amethyst/View/LayoutNameWindow.swift @@ -33,4 +33,47 @@ class LayoutNameWindow: NSWindow { backgroundColor = NSColor.clear level = .floating } + + // Display custom notification with dynamic sizing + func displayNotification(title: String, description: String) { + // layoutDescriptionLabel?.isHidden = false + layoutNameField?.stringValue = title + layoutDescriptionLabel?.stringValue = description + + // Calculate size needed for both name and description + let longerText = title.count > description.count ? title : description + resizeToFitText(text: longerText) + } + + // Dynamic window resizing based on text content + private func resizeToFitText(text: String) { + guard let textField = layoutNameField else { return } + + // Calculate text width with current font + let font = textField.font ?? NSFont.systemFont(ofSize: 20) + let textSize = text.size(withAttributes: [.font: font]) + + // Add padding (40px on each side + extra space) + let minWidth: CGFloat = 200 + let maxWidth: CGFloat = 500 + let padding: CGFloat = 80 + let calculatedWidth = textSize.width + padding + + // Constrain width between min and max + let newWidth = max(minWidth, min(maxWidth, calculatedWidth)) + + // Keep the same height + let currentFrame = frame + let newFrame = NSRect( + x: currentFrame.origin.x, + y: currentFrame.origin.y, + width: newWidth, + height: currentFrame.height + ) + + setFrame(newFrame, display: true, animate: false) + + // Update content view layer frame + contentView?.layer?.frame = NSRectToCGRect(contentView!.frame) + } } From ac5ae4a6afcac3cd42bf383437089aec88af4fad Mon Sep 17 00:00:00 2001 From: Roman Geraskin Date: Wed, 20 Aug 2025 19:33:08 +0300 Subject: [PATCH 2/2] feat(hotkey): add window count hotkey and hud --- Amethyst/Events/HotKeyManager.swift | 18 ++++ Amethyst/Managers/WindowManager.swift | 13 +++ .../GeneralPreferencesViewController.xib | 98 +++++++++++-------- Amethyst/Preferences/UserConfiguration.swift | 35 +++++++ Amethyst/default.amethyst | 1 + docs/configuration-files.md | 3 + 6 files changed, 125 insertions(+), 43 deletions(-) diff --git a/Amethyst/Events/HotKeyManager.swift b/Amethyst/Events/HotKeyManager.swift index 5e4bf6ee..501109c7 100644 --- a/Amethyst/Events/HotKeyManager.swift +++ b/Amethyst/Events/HotKeyManager.swift @@ -247,6 +247,22 @@ class HotKeyManager: NSObject { appDelegate?.relaunch(self) } + constructCommandWithCommandKey(CommandKey.increaseWindowMaxCount.rawValue) { + self.userConfiguration.increaseWindowMaxCount() + windowManager.markAllScreensForReflow(withChange: .unknown) + DispatchQueue.main.async { + windowManager.displayWindowCountHUD() + } + } + + constructCommandWithCommandKey(CommandKey.decreaseWindowMaxCount.rawValue) { + self.userConfiguration.decreaseWindowMaxCount() + windowManager.markAllScreensForReflow(withChange: .unknown) + DispatchQueue.main.async { + windowManager.displayWindowCountHUD() + } + } + LayoutType.availableLayoutStrings().forEach { (layoutKey, _) in self.constructCommandWithCommandKey(UserConfiguration.constructLayoutKeyString(layoutKey)) { let screenManager: ScreenManager>? = windowManager.focusedScreenManager() @@ -367,6 +383,8 @@ class HotKeyManager: NSObject { hotKeyNameToDefaultsKey.append(["Expand main pane", CommandKey.expandMain.rawValue]) hotKeyNameToDefaultsKey.append(["Increase main pane count", CommandKey.increaseMain.rawValue]) hotKeyNameToDefaultsKey.append(["Decrease main pane count", CommandKey.decreaseMain.rawValue]) + hotKeyNameToDefaultsKey.append(["Increase window max count", CommandKey.increaseWindowMaxCount.rawValue]) + hotKeyNameToDefaultsKey.append(["Decrease window max count", CommandKey.decreaseWindowMaxCount.rawValue]) hotKeyNameToDefaultsKey.append(["Custom layout command 1", CommandKey.command1.rawValue]) hotKeyNameToDefaultsKey.append(["Custom layout command 2", CommandKey.command2.rawValue]) hotKeyNameToDefaultsKey.append(["Custom layout command 3", CommandKey.command3.rawValue]) diff --git a/Amethyst/Managers/WindowManager.swift b/Amethyst/Managers/WindowManager.swift index a2dfb187..6f7ad649 100644 --- a/Amethyst/Managers/WindowManager.swift +++ b/Amethyst/Managers/WindowManager.swift @@ -322,6 +322,19 @@ extension WindowManager { } } + func displayWindowCountHUD() { + guard userConfiguration.enablesWindowCountHUD() else { + return + } + + for screenManager in screens.screenManagers { + let currentCount = userConfiguration.windowMaxCount() ?? 0 + let countText = currentCount == 0 ? "Unlimited" : "\(currentCount)" + let title = "Window Max Count: \(countText)" + screenManager.displayCustomHUD(title: title) + } + } + func add(runningApplication: NSRunningApplication) { switch runningApplication.isManageable { case .manageable: diff --git a/Amethyst/Preferences/GeneralPreferencesViewController.xib b/Amethyst/Preferences/GeneralPreferencesViewController.xib index 32aa189c..ad1d41f8 100644 --- a/Amethyst/Preferences/GeneralPreferencesViewController.xib +++ b/Amethyst/Preferences/GeneralPreferencesViewController.xib @@ -13,11 +13,11 @@ - + - + @@ -26,7 +26,7 @@ - + @@ -56,7 +56,7 @@ - + @@ -77,7 +77,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -95,7 +95,7 @@ - + @@ -110,7 +110,7 @@ - + @@ -119,7 +119,7 @@ - + @@ -127,7 +127,7 @@ - + @@ -136,7 +136,7 @@ - + @@ -151,7 +151,7 @@ - + @@ -160,7 +160,7 @@ - + @@ -168,7 +168,7 @@ - + @@ -176,7 +176,7 @@ - + @@ -185,7 +185,7 @@ - + @@ -194,7 +194,7 @@ - + @@ -207,7 +207,7 @@ - + @@ -215,7 +215,7 @@ - + @@ -224,7 +224,7 @@ - + @@ -237,7 +237,7 @@ - + @@ -245,7 +245,7 @@ - + @@ -254,7 +254,7 @@ - + @@ -267,7 +267,7 @@ - + @@ -275,7 +275,7 @@ - + @@ -284,7 +284,7 @@ - + @@ -297,7 +297,7 @@ - + @@ -305,7 +305,7 @@ - + @@ -314,7 +314,7 @@ - + @@ -323,15 +323,15 @@ - + - + + + - + @@ -362,7 +374,7 @@ - + @@ -404,7 +416,7 @@ - + @@ -419,7 +431,7 @@