Skip to content

Switch to minimized window in a single call via unified bring_window_to_top logic#96

Merged
Jeomon merged 1 commit intoCursorTouch:mainfrom
JezaChen:enhance-switch-app
Mar 10, 2026
Merged

Switch to minimized window in a single call via unified bring_window_to_top logic#96
Jeomon merged 1 commit intoCursorTouch:mainfrom
JezaChen:enhance-switch-app

Conversation

@JezaChen
Copy link
Contributor

@JezaChen JezaChen commented Mar 9, 2026

Problem

When using the App tool in switch mode to focus a minimized window (e.g., Zoom Workplace), the previous logic only restored the window from its minimized state — it did not bring it to the foreground. A second call to the same tool was required to actually switch focus to the window.

video.mp4

This happened because the original code branched on IsIconic:

  • If minimized → call ShowWindow(SW_RESTORE) only (no focus change)
  • If not minimized → call bring_window_to_top (which both restores and focuses)

Fix

Consolidated the two branches into a single unified call to bring_window_to_top, which already handles the minimized case internally by calling ShowWindow(SW_RESTORE) before setting the window as foreground. The was_minimized flag is retained solely for generating a descriptive return message.

# After — single path, always brings window to foreground regardless of state
was_minimized = uia.IsIconic(target_handle)
self.bring_window_to_top(target_handle)
if was_minimized:
    content = f"Restored {window_name.title()} from minimized and switched to it."
else:
    content = f"Switched to {window_name.title()} window."

bring_window_to_top already contains the restore-then-focus sequence:

def bring_window_to_top(self, target_handle: int):
    if win32gui.IsIconic(target_handle):
        win32gui.ShowWindow(target_handle, win32con.SW_RESTORE)
    # ... thread attachment and SetForegroundWindow logic

Result

Switching to a minimized window now works correctly in a single tool call — the window is both restored from minimized state and brought to the foreground atomically.


Thanks for building such a useful MCP server! Hope this small fix improves the experience.

Copilot AI review requested due to automatic review settings March 9, 2026 16:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where switching to a minimized window via the App tool's switch mode required two calls — the first only restored the window from minimized state without bringing it to the foreground. The fix consolidates the two code branches into a single call to the existing bring_window_to_top method, which already handles both restoring and focusing.

Changes:

  • Replaced the branched minimize-check-then-restore/focus logic in switch_app with a single bring_window_to_top call, retaining the was_minimized flag only for the user-facing message.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Jeomon Jeomon merged commit a87a15c into CursorTouch:main Mar 10, 2026
3 of 4 checks passed
@Jeomon
Copy link
Member

Jeomon commented Mar 10, 2026

Thanks pointing it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants