Skip to content

Add --foreground option to control MPV window foreground behavior - #4

Merged
zhongfly merged 5 commits into
mainfrom
copilot/fix-1d784a4b-e77a-442d-bf53-0924854cf968
Sep 18, 2025
Merged

Add --foreground option to control MPV window foreground behavior#4
zhongfly merged 5 commits into
mainfrom
copilot/fix-1d784a4b-e77a-442d-bf53-0924854cf968

Conversation

Copilot AI commented Sep 17, 2025

Copy link
Copy Markdown
Contributor
  • Add new foreground option to Config struct with default value true
  • Add command-line flag --foreground to control window foreground behavior
  • Update resolveConfig function to handle the new foreground option
  • Modify main function to conditionally call setForegroundWindow based on the option
  • Update README.md to document the new option
  • Add configuration file example with the new option
  • Test the implementation to ensure it works correctly
  • Optimize getPid call to only execute when foreground=true
  • Fix config file foreground=false not working properly
  • Add --window-minimized=yes for new MPV instances when foreground=false

Summary

Successfully implemented a new --foreground option that allows users to control whether the MPV window is brought to the foreground after loading files.

Key Features:

  • Default behavior remains unchanged (foreground=true by default)
  • Command-line argument: --foreground=false to disable foreground behavior
  • Configuration file support: foreground=false in umpv.conf
  • Command-line arguments override configuration file settings
  • Full backward compatibility
  • Performance optimization: getPid() is only called when needed (when foreground=true)
  • Bug fix: Configuration file foreground setting now works correctly
  • New MPV instances: When starting new MPV instances with foreground=false, adds --window-minimized=yes to prevent focus stealing

Usage Examples:

  • Command line: umpv --foreground=false video.mkv
  • Config file: Add foreground=false to umpv.conf

The implementation handles both scenarios:

  1. Existing MPV instance: Uses setForegroundWindow() conditionally based on foreground setting
  2. New MPV instance: Adds --window-minimized=yes argument when foreground=false to prevent focus stealing

The implementation passes all validation tests for configuration parsing, flag handling, and priority resolution (CLI args override config file values).


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: zhongfly <11155705+zhongfly@users.noreply.github.com>
Copilot AI changed the title [WIP] 增加一个选项用于设置是否使用setForegroundWindow将mpv窗口前置,选项在命令行和配置文件中都可以使用 Add --foreground option to control MPV window foreground behavior Sep 17, 2025
Copilot AI requested a review from zhongfly September 17, 2025 15:08
@zhongfly

Copy link
Copy Markdown
Owner

@copilot 只在foreground为true时,运行getPid函数

Co-authored-by: zhongfly <11155705+zhongfly@users.noreply.github.com>

Copilot AI commented Sep 17, 2025

Copy link
Copy Markdown
Contributor Author

@copilot 只在foreground为true时,运行getPid函数

Done! Moved the getPid() call inside the foreground condition to avoid unnecessary MPV communication when foreground=false. Commit: 852bfa7

@zhongfly

Copy link
Copy Markdown
Owner

@copilot 修复问题:配置文件中设置foreground=false不生效

Co-authored-by: zhongfly <11155705+zhongfly@users.noreply.github.com>

Copilot AI commented Sep 18, 2025

Copy link
Copy Markdown
Contributor Author

@copilot 修复问题:配置文件中设置foreground=false不生效

Fixed! The issue was that the flag pointer was always passed to resolveConfig(), preventing config file values from being used. Now using flag.Visit() to detect when the user explicitly set --foreground, only then do we override the config file. Commit: c65f83c

@zhongfly

Copy link
Copy Markdown
Owner

@copilot 当foreground=false时,startMPV启动新的MPV进程时添加参数--window-minimized=yes使得mpv不抢占当前窗口的焦点

Co-authored-by: zhongfly <11155705+zhongfly@users.noreply.github.com>

Copilot AI commented Sep 18, 2025

Copy link
Copy Markdown
Contributor Author

@copilot 当foreground=false时,startMPV启动新的MPV进程时添加参数--window-minimized=yes使得mpv不抢占当前窗口的焦点

Done! Modified startMPV() to add --window-minimized=yes parameter when foreground=false. This prevents new MPV instances from stealing focus from the current window. Commit: dd28eee

@zhongfly
zhongfly marked this pull request as ready for review September 18, 2025 11:49
@zhongfly
zhongfly merged commit 2e08b85 into main Sep 18, 2025
4 checks passed
@zhongfly
zhongfly deleted the copilot/fix-1d784a4b-e77a-442d-bf53-0924854cf968 branch September 18, 2025 11:52
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.

2 participants