Skip to content

Commit

Permalink
forceFocus on window close, HotkeyBinding, cli command
Browse files Browse the repository at this point in the history
closes #65
  • Loading branch information
nikitabobko committed Dec 22, 2023
1 parent 208e3a7 commit 0569bb0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ class HotkeyBinding {

func activate() {
hotKey = HotKey(key: key, modifiers: modifiers, keyUpHandler: { [commands] in
refreshSession {
refreshSession(forceFocus: true) {
var subject = CommandSubject.focused
commands.run(&subject)
_ = commands.run(&subject)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/refresh.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// It's one of the most important function of the whole application.
/// The function is called as a feedback response on every user input.
/// The function is idempotent.
func refreshSession<T>(startup: Bool = false, body: () -> T) -> T {
func refreshSession<T>(startup: Bool = false, forceFocus: Bool = false, body: () -> T) -> T {
check(Thread.current.isMainThread)
gc()

Expand All @@ -22,7 +22,7 @@ func refreshSession<T>(startup: Bool = false, body: () -> T) -> T {
}

if TrayMenuModel.shared.isEnabled {
syncFocusToMacOs(nativeFocused, startup: startup, force: focusBefore != focusAfter)
syncFocusToMacOs(nativeFocused, startup: startup, force: forceFocus || focusBefore != focusAfter)

updateTrayText()
layoutWorkspaces()
Expand Down
2 changes: 1 addition & 1 deletion src/server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private func newConnection(_ socket: Socket) async { // todo add exit codes
}
if let command {
let (success, stdout) = await Task { @MainActor in
refreshSession {
refreshSession(forceFocus: true) {
var focused = CommandSubject.focused // todo restore subject from "exec session"
var stdout = ""
let success = command.run(&focused, &stdout)
Expand Down
2 changes: 1 addition & 1 deletion src/tree/MacWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class MacWindow: Window, CustomStringConvertible {
// todo the if is an approximation to filter out cases when window just closed itself (or was killed remotely)
// we might want to track the time of the latest workspace switch to make the approximation more accurate
if workspace == previousFocusedWorkspaceName || workspace == focusedWorkspaceName {
refreshSession {
refreshSession(forceFocus: true) {
WorkspaceCommand(args: WorkspaceCmdArgs(
target: .workspaceName(name: workspace, autoBackAndForth: false)
)).runOnFocusedSubject()
Expand Down

0 comments on commit 0569bb0

Please sign in to comment.