[FEAT]: Focus previous window when switching to unmanaged workspace #585

Closed
opened 2026-01-05 14:51:46 +01:00 by adam · 2 comments
Owner

Originally created by @fiso64 on GitHub (Mar 5, 2025).

Eligibility

Individual Commercial Use License

Suggestion

I have an unmanaged workspace. When I switch to a managed workspace, the previously focused window is focused again. However, when I switch back to the unmanaged workspace, no window is focused, which can often lead to unexpected results.

I propose to save the last focused window for the unmanaged workspaces as well and restore the focus when the user switches to an unmanaged workspace.

Alternatives Considered

Here is an unreliable and slow ahk script that does this (if the index of the unmanaged workspace is 0):

RunGetOutput(command) {
        user_dir := EnvGet("Homedrive") . EnvGet("Homepath")
	tmp_file := user_dir "/AppData/Local/Temp/ahk_output.tmp"
	RunWait("cmd /c " command " > " tmp_file, , "hide")
	output := FileRead(tmp_file)
	return Trim(output, " `t`n")
}

last_focused_win := -1
KomorebiSetWorkspace(index) {
	global last_focused_win
	unmanaged_workspace_idx := 0
	if (index == unmanaged_workspace_idx && last_focused_win != -1) {
		RunWait("komorebic.exe focus-workspace " index, , "Hide")
		try {
			WinActivate("ahk_id " last_focused_win)
		}
	}
	else {
		current := Integer(RunGetOutput("komorebic query focused-workspace-index"))
		if (current == index) 
			return
		if (current == 0) {
			try {
				last_focused_win := WinGetID("A")
			}
		}
		RunWait("komorebic.exe focus-workspace " index, , "Hide")
	}
}
Originally created by @fiso64 on GitHub (Mar 5, 2025). ### Eligibility Individual Commercial Use License ### Suggestion I have an unmanaged workspace. When I switch to a managed workspace, the previously focused window is focused again. However, when I switch back to the unmanaged workspace, no window is focused, which can often lead to unexpected results. I propose to save the last focused window for the unmanaged workspaces as well and restore the focus when the user switches to an unmanaged workspace. ### Alternatives Considered Here is an unreliable and slow ahk script that does this (if the index of the unmanaged workspace is 0): ```autohotkey RunGetOutput(command) { user_dir := EnvGet("Homedrive") . EnvGet("Homepath") tmp_file := user_dir "/AppData/Local/Temp/ahk_output.tmp" RunWait("cmd /c " command " > " tmp_file, , "hide") output := FileRead(tmp_file) return Trim(output, " `t`n") } last_focused_win := -1 KomorebiSetWorkspace(index) { global last_focused_win unmanaged_workspace_idx := 0 if (index == unmanaged_workspace_idx && last_focused_win != -1) { RunWait("komorebic.exe focus-workspace " index, , "Hide") try { WinActivate("ahk_id " last_focused_win) } } else { current := Integer(RunGetOutput("komorebic query focused-workspace-index")) if (current == index) return if (current == 0) { try { last_focused_win := WinGetID("A") } } RunWait("komorebic.exe focus-workspace " index, , "Hide") } } ```
adam added the enhancement label 2026-01-05 14:51:46 +01:00
adam closed this issue 2026-01-05 14:51:46 +01:00
Author
Owner

@github-actions[bot] commented on GitHub (Mar 5, 2025):

Feature requests on this repository are only open to current GitHub sponsors on the $5/month tier and above, people with a valid individual commercial use license, and approved contributors.
This issue has been automatically closed until one of those pre-requisites can be validated.

@github-actions[bot] commented on GitHub (Mar 5, 2025): Feature requests on this repository are only open to current [GitHub sponsors](https://github.com/sponsors/LGUG2Z) on the $5/month tier and above, people with a valid [individual commercial use license](https://lgug2z.com/software/komorebi), and approved contributors. This issue has been automatically closed until one of those pre-requisites can be validated.
Author
Owner

@LGUG2Z commented on GitHub (Mar 5, 2025):

I did not find your GitHub username in the list of Individual Commercial Use License users. You can confirm your GitHub username by emailing me at the address listed on the licensing page from the email address you used to purchase your license subscription.

@LGUG2Z commented on GitHub (Mar 5, 2025): I did not find your GitHub username in the list of Individual Commercial Use License users. You can confirm your GitHub username by emailing me at the address listed on the licensing page from the email address you used to purchase your license subscription.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/komorebi#585