Repository navigation
feat: add a recent windows switcher on mod-tab #264
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b80ad4c
feat: add a recent windows switcher on mod-tab
qeude 58cc3a5
fix(recent-windows): round the panel shadow and pin the badge to the …
qeude 6fdd6f1
refactor(recent-windows): share the cheat sheet's panel surface
qeude 12618bb
fix(recent-windows): tear down the switcher when its last window closes
qeude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import DefiIPC | ||
| import DefiMacOS | ||
| import DefiModel | ||
| import DefiRuntime | ||
| import Foundation | ||
|
|
||
| @NavigationActor | ||
| extension Daemon { | ||
| func handleRecentWindows(_ action: RecentWindowsAction) -> CommandResponse { | ||
| switch action { | ||
| case .next, .previous: | ||
| guard !overviewState.isOpen else { | ||
| return .failure("recent windows are unavailable while the Overview is open") | ||
| } | ||
| let opening = !recentWindows.isOpen | ||
| recentWindows.step(forward: action == .next, in: state) | ||
| guard recentWindows.isOpen else { return .failure("no managed window to switch to") } | ||
| guard opening else { | ||
| presentRecentWindows() | ||
| return .success() | ||
| } | ||
| hotKeys?.setRecentWindowsOpen(true) | ||
| recentWindowsMonitorID = activeMonitorID ?? state.monitors.first?.id | ||
| // Like Niri's open delay: a brief press switches without drawing anything. | ||
| recentWindowsShowTask = Task { [weak self] in | ||
| try? await Task.sleep(for: .milliseconds(150)) | ||
| guard !Task.isCancelled, let self, self.recentWindows.isOpen else { return } | ||
| self.recentWindowsShowTask = nil | ||
| self.recentWindowsVisible = true | ||
| self.presentRecentWindows() | ||
| } | ||
| return .success() | ||
| case .confirm: | ||
| guard let windowID = closeRecentWindows() else { return .success() } | ||
| return handle("focus-window-id \(windowID.rawValue)") | ||
| case .cancel: | ||
| closeRecentWindows() | ||
| return .success() | ||
| } | ||
| } | ||
|
|
||
| /// Closes the switcher without focusing anything and returns its selection. | ||
| @discardableResult | ||
| func closeRecentWindows() -> WindowID? { | ||
| guard recentWindows.isOpen else { return nil } | ||
| recentWindowsShowTask?.cancel() | ||
| recentWindowsShowTask = nil | ||
| hotKeys?.setRecentWindowsOpen(false) | ||
| if recentWindowsVisible { | ||
| recentWindowsVisible = false | ||
| DispatchQueue.main.async { [self] in recentWindowsController?.close() } | ||
| } | ||
| return recentWindows.close() | ||
| } | ||
|
|
||
| /// Windows that close while the switcher is open leave it; the Overview closes it. | ||
| func refreshRecentWindowsIfOpen() { | ||
| guard recentWindows.isOpen else { return } | ||
| var retained = recentWindows | ||
| retained.retainManagedWindows(in: state) | ||
| // Close before pruning: an emptied switcher would read as already closed. | ||
| guard retained.isOpen, !overviewState.isOpen else { | ||
| closeRecentWindows() | ||
| return | ||
| } | ||
| recentWindows = retained | ||
| presentRecentWindows() | ||
| } | ||
|
|
||
| private func presentRecentWindows() { | ||
| guard recentWindowsVisible else { return } | ||
| let entries = recentWindows.windowIDs.map { | ||
| RecentWindowsEntry(id: $0, title: state.windows[$0]?.title ?? "", processID: state.windows[$0]?.processID) | ||
| } | ||
| let (selection, monitorID, previews) = | ||
| (recentWindows.selection, recentWindowsMonitorID, config.overview.windowPreviews) | ||
| DispatchQueue.main.async { [self] in | ||
| let controller = recentWindowsController ?? RecentWindowsController() | ||
| recentWindowsController = controller | ||
| controller.show(entries, selection: selection, on: monitorID, previews: previews) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.