Skip to content

Fix foreign toplevel handle eligibility and app_id handling for Wayland manager/list#4946

Draft
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-wrong-creation-logic
Draft

Fix foreign toplevel handle eligibility and app_id handling for Wayland manager/list#4946
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-wrong-creation-logic

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

Related: n/a

What's new?

Foreign toplevel handle creation was over-inclusive (non-app windows), under-inclusive (freestyle windows), and sometimes emitted meaningless metadata (blank app_id/title). This change aligns both foreign-toplevel implementations to expose only eligible app toplevels with stable app identity.

  • Shared handle policy (deduplicated logic)

    • Added foreign_toplevel_handle_creation.h with:
      • should_create_foreign_toplevel_handle(surface, app_id) (single eligibility gate)
    • Removed the earlier foreign_toplevel_app_id(...) helper (it was only test-facing and unnecessary).
    • Both foreign_toplevel_manager_v1.cpp and foreign_toplevel_list_v1.cpp use this shared policy.
  • Correct eligibility semantics

    • Eligibility is now derived from a single surface plus app_id:
      • live session required
      • non-empty app_id required
      • depth layer must be mir_depth_layer_application
      • window must be focusable (focus_mode != mir_focus_mode_disabled)
      • supported types: normal, utility, and freestyle
    • This excludes windows outside the application layer and windows that cannot gain focus.
    • Freestyle windows are now correctly included.
  • Correct app_id emission semantics and performance

    • Handle metadata prefers surface->application_id() when present.
    • resolve_app_id() is called only when application_id is empty (including application_id_set_to paths), avoiding unnecessary expensive resolution.
    • On application_id_set_to, eligibility is re-evaluated so handles can be created/closed as app identity becomes known.
  • Re-evaluate on depth-layer changes

    • Added depth_layer_set_to(...) handling in both foreign-toplevel observers so eligibility updates when a surface moves between layers.
  • Focused tests

    • Updated test_foreign_toplevel_handle_creation.cpp to validate the new surface-derived eligibility policy:
      • application-layer normal window allowed
      • freestyle window allowed
      • utility window allowed in application layer
      • non-application-layer windows denied
      • non-focusable windows denied
      • missing session denied
      • empty app_id denied
    • Registered in frontend_wayland unit test CMake list.

How to test

  • Configure/build unit tests.
  • Run focused tests:
    • mir_unit_tests.bin --gtest_filter=ForeignToplevelHandleCreation*
  • Run related regression slice:
    • mir_unit_tests.bin --gtest_filter=DesktopFileManager*

Checklist

  • Tests added and pass
  • Adequate documentation added
  • (optional) Added Screenshots or videos

Copilot AI and others added 2 commits May 11, 2026 12:11
Agent-Logs-Url: https://github.com/canonical/mir/sessions/c43861cd-8934-4436-b91c-e180b8e155c4

Co-authored-by: AlanGriffiths <9048879+AlanGriffiths@users.noreply.github.com>
Agent-Logs-Url: https://github.com/canonical/mir/sessions/c43861cd-8934-4436-b91c-e180b8e155c4

Co-authored-by: AlanGriffiths <9048879+AlanGriffiths@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix wrong ForeignToplevelHandleV1 creation logic Fix foreign toplevel handle eligibility and app_id source for Wayland manager/list May 11, 2026
Copilot AI requested a review from AlanGriffiths May 11, 2026 12:15
else
{
should_have_handle = false;
app_id = foreign_toplevel_app_id(surface->application_id(), desktop_file_manager->resolve_app_id(surface.get()));
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.

Calling resolve_app_id is potentially expensive. We should only call it if surface->application_id() is empty.

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.

@copilot please address this thread

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in commit a5eeedf: resolve_app_id() is now only called when the surface/event application_id is empty (in both foreign_toplevel_list_v1.cpp and foreign_toplevel_manager_v1.cpp).

Agent-Logs-Url: https://github.com/canonical/mir/sessions/0e9c5b86-3758-4f59-8e49-373941df5945

Co-authored-by: AlanGriffiths <9048879+AlanGriffiths@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Fix foreign toplevel handle eligibility and app_id source for Wayland manager/list Fix foreign toplevel handle eligibility and app_id handling for Wayland manager/list May 11, 2026
Copy link
Copy Markdown
Contributor

@AlanGriffiths AlanGriffiths left a comment

Choose a reason for hiding this comment

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

@copilot please address issues raised in this therad

Comment on lines +26 to +33
inline auto foreign_toplevel_app_id(std::string const& application_id, std::string const& resolved_app_id) -> std::string
{
if (!application_id.empty())
return application_id;

return resolved_app_id;
}

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.

This is only used in tests: it isn't needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 90f623e: removed the unused foreign_toplevel_app_id() helper from foreign_toplevel_handle_creation.h.

Comment on lines +34 to +37
inline auto should_create_foreign_toplevel_handle(
MirWindowType type,
bool has_session,
std::string const& app_id) -> bool
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.

All the parameters need to be derived from the same surface: it would be better to pass the surface than repeat this at each call site.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 90f623e: should_create_foreign_toplevel_handle() now takes scene::Surface const& and derives eligibility inputs from that single surface.

Comment on lines +38 to +40
{
return has_session && type == mir_window_type_normal && !app_id.empty();
}
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.

This will incorrectly identify windows outside the application layer and windows that cannot get focus. It will not identify freestyle windows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 90f623e: eligibility now requires application layer and focusable windows, and includes freestyle windows; also re-evaluates on depth-layer updates. Added focused coverage in e3b2678.

Copilot AI and others added 2 commits May 12, 2026 06:46
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 12, 2026

@copilot please address issues raised in this therad

Addressed in 90f623e (logic updates) and e3b2678 (additional test coverage).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

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.

Wrong ForeignToplevelHandleV1 creation logic

3 participants