Skip to content

fix: keep console mode (export / test) headless #issue-#1770 - #1771

Open
palepal wants to merge 10 commits into
FashionFreedom:developfrom
palepal:issue-#1770
Open

palepal wants to merge 10 commits into
FashionFreedom:developfrom
palepal:issue-#1770

Conversation

@palepal

@palepal palepal commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Change and reason

Fixes #1770. Console mode (-b/--basename export, --test) flashed a maximized main window, stole focus, and on macOS showed a Dock icon.

  • mainwindow.cpp: showMaximized() in the MainWindow constructor ran unconditionally. It is now guarded by Application2D::isGUIMode(), like the existing window.show() in main.cpp.
  • macOS: a bundled app registers as a regular Dock app as soon as AppKit starts in the QApplication constructor, before the command line is parsed, so changing activation policy afterwards still leaves a Dock icon for about a second (measured). Instead, Info.plist sets LSUIElement, and main.cpp calls new showDockIcon() (core/macos_dock.mm, setActivationPolicy(Regular)) in GUI mode before the event loop starts. Console mode never gets a Dock icon.
  • macOS: Qt's Cocoa plugin still activated every app it started (qt.qpa.application: Launched with <frontmost app> as frontmost application. Activating ... instead.), so each console run took focus, closed open menus and swallowed typing in the active app. main.cpp sets QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM before the app is created and unsets it in GUI mode. Qt reads it again when the event loop starts, so GUI launches still come to the front.

Linux/Windows behaviour changes only through the showMaximized() guard.

Automated validation

  • Linux unit tests passed.
  • Linux AppImage, macOS, and Windows matrix builds passed.

Integration testing (before approval)

  • Built the PR locally and launched it.
  • Opened and modified sample patterns and measurement files.
  • Created/edited points, lines, curves, and arcs.
  • Tested mirror, move, rotate, and true darts (explain any N/A).
  • Created and edited pieces.
  • Generated and exported layouts. (console mode, see below)
  • Saved, closed, reopened, and verified geometry, formulas, and dependencies.
  • Observed no data loss, unexpected geometry changes, or crashes. (in the exports below)
  • Attached screenshots of the corrected behavior in the running application.
  • Tested other affected platforms and SeamlyMe where applicable.

Tester/date: palepal, 2026-10-18

OS/version/architecture: macOS 26 (Darwin 25.6.0), arm64

Tested commit SHA / version: 6eaeb94, focus fix re-tested on 7f1f5f8 (local build with Homebrew Qt 6.12.0, arm64 only)

Sample files, steps, screenshots, and findings:

Copy of src/app/share/samples/patterns/trousers.sm2d. The window list and Dock items were polled during each run (CoreGraphics window list, Dock accessibility items, lsappinfo).

Run Before After
-b out -f 0 (SVG) export main window on screen, maximized, frontmost, Dock icon ~3 s no on-screen window, no Dock icon (but the app still took focus, fixed in 7f1f5f8, see below)
--test same same as above
GUI launch from Terminal and via open (LaunchServices) Dock icon, frontmost, menu bar unchanged: Dock icon, frontmost, full menu bar (File … Help), window maximized

Focus (7f1f5f8, 2026-10-19), with another app frontmost and QT_LOGGING_RULES='qt.qpa.application*=true', copy of jacket3_40-146.sm2d:

Run Before After
--test, 3 + 20 runs Activating ... instead logged once per run, open menus in the active app closed no activation logged, frontmost app unchanged (polled with lsappinfo front during 8 runs), exit 0
-b export, -f 0 SVG, -f 1 PDF, -f 2 tiled PDF activation logged no activation logged, files written, exit 0
--test, 11 runs while a GUI instance has a pattern open behind another app no activation logged, frontmost app unchanged (polled every 10 ms), exit 0
--test, 5 runs while a GUI instance is frontmost the GUI instance stays frontmost, exit 0
GUI launch from Terminal activated, Foreground unchanged: activated, Foreground (Dock icon)
GUI via open -n -a Seamly2D.app (Dock/Finder path) frontmost, Foreground, full menu bar (File … Help) after the Welcome dialog
open -n -a Seamly2D.app pattern.sm2d (Finder double-click path) frontmost, Foreground, the pattern opens in the main window, same as release 2026.10.12

SVG and PNG exports are byte-identical to the unpatched build. PDFs differ only in CreationDate/ModDate.

Result: NOT YET TESTED (full checklist)

Not-applicable steps and reasons: The change touches only startup window visibility and the macOS activation policy. Drafting, piece, and layout-editing paths are not modified, but the full checklist has not been run yet. Results will be added in a comment.

Unrelated, found while testing: with a fresh profile the Welcome dialog shows first and a file opened through LaunchServices is dropped (the main window opens untitled). Release 2026.10.12 does the same; with the Welcome dialog turned off the file opens. Not touched here.

Also unrelated: DXF export (-f 14) segfaults in console mode, including on release 2026.9.21. Not touched here; I'll file it separately.

🤖 Generated with Claude Code

MainWindow's constructor called showMaximized() unconditionally, so
command-line export and --test runs flashed a maximized main window and
stole focus. Only show it in GUI mode.

On macOS the bundle was also registered as a regular Dock app as soon as
AppKit started, before the command line is parsed, so a Dock icon still
appeared. Mark the bundle LSUIElement and promote it to a regular app
(Dock icon, menu bar) in GUI mode only, before the event loop starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Oct 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…reedom#1770

ImageTool asked with a QMessageBox when a pattern's background image
was missing or unreadable, even in console mode (export / test), so a
scripted export blocked until someone clicked. In console mode, log a
warning and skip the image, as answering No does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@palepal

palepal commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Added 83fe007: missing background image no longer prompts in console mode.

ImageTool called QMessageBox::question ("The image … could not be found. Do you want to update the file location?") and QMessageBox::critical even in console mode. So --test / export of a pattern whose background image had moved blocked until someone clicked. In console mode it now logs WARNING: The image <path> could not be found. and skips the image, the same as answering No. GUI behaviour is unchanged.

Tested with src/test/CollectionTest/share/all_tools_pattern/alltools_pattern.sm2d, whose image path is D:/Github/...:

  • before: a modal dialog appeared, and --test waited for it
  • after: --test exits 0 with the warning, and no window appears (checked with the CoreGraphics window list)

…shionFreedom#1770

Application2D::event() shows the main window on ApplicationActivate.
When a console export ran while another Seamly2D instance from the
same bundle was open, the export process got activated and its hidden,
maximized main window appeared. Only show it in GUI mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@palepal

palepal commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Added 0fd487f: app activation no longer shows the window in console mode (macOS).

Application2D::event() calls mainWindow->show() on QEvent::ApplicationActivate. When a console export ran while another Seamly2D instance from the same app bundle was open, the export process got activated, and its hidden main window appeared maximized near the end of the export. The handler now only shows the window in GUI mode.

Tested by running Seamly2D -b out -f 0 trousers.sm2d while a GUI instance of the same bundle was open and watching the CoreGraphics window list:

  • before: the maximized main window came on screen
  • after: no window on screen in 3 runs out of 3

…nFreedom#1770

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@slspencer

Copy link
Copy Markdown
Contributor

Hi @palepal — Thank you for the PR and for documenting your testing so thoroughly. We appreciate the care you've taken to validate the changes. We recognize that much of the PR checklist is geared toward GUI functionality and may not apply to headless operations, so we appreciate your judgment in identifying the relevant tests.

The CLI has received relatively little attention recently, so it's great to see improvements in this area, particularly with testing on macOS.

@DSCaskey DSCaskey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@csett86 can you look at the macOS Dock stuff here? thanks

@slspencer

Copy link
Copy Markdown
Contributor

@palepal — We're updating our CI workflow to better support PRs from forks. The CodeSee failure is on our side; no action is needed from you. Thanks for your patience.

slspencer and others added 4 commits October 18, 2026 18:11
…ionFreedom#1770

Qt's Cocoa plugin activates every app it starts, so each seamly2d -t or export
run closed open menus and stole keyboard input. Disable that transform before
the app is created and unset it again in GUI mode, which still comes to the front.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@slspencer
slspencer requested a review from csett86 October 25, 2026 15:50
@slspencer

Copy link
Copy Markdown
Contributor

@csett86 ?

Comment thread src/app/seamly2d/core/macos_dock.mm

This branch has not been deployed

No deployments
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.

Bug: console mode (export / --test) shows the main window and a Dock icon

5 participants