Skip to content

Conversation

@js202510
Copy link
Contributor

This adds a new mode to the "place" plug-in to position new windows centered under the mouse pointer, while keeping them fully within the workarea.

The advantage is that the user can control where the new window would be placed by pointing the mouse before starting an app (might be useless when starting apps from a panel, but works well when using wofi or starting apps via key binding, e.g. terminal). And the user can immediately interact with the new window or move it out of the way with minimal mouse effort.

No idea what this would do in a mouseless, touch-screen scenario.

{
wf::geometry_t window = view->get_pending_geometry();
wf::point_t pos = wf::get_core().get_cursor_position().round_down();
window.x = workarea.x + wf::clamp(pos.x - window.width / 2,
Copy link
Member

Choose a reason for hiding this comment

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

Prefer std::clamp, we had wf::clamp before moving to a newer C++ version, so it is there just for legacy code.

void pointer(wayfire_toplevel_view & view, wf::geometry_t workarea)
{
wf::geometry_t window = view->get_pending_geometry();
wf::point_t pos = wf::get_core().get_cursor_position().round_down();
Copy link
Member

@ammen99 ammen99 Nov 28, 2025

Choose a reason for hiding this comment

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

One thing to keep in mind is multiple outputs. get_core().get_cursor_position() returns the cursor position in the output-layout coordinate system. Views, however, are positioned in output-local coordinate system (i.e relative to their current output). You could look at whether the view is bound to any output (view->get_output(), should be non-null for most views), then use

/**
* Gets the cursor position relative to the output
*/
wf::pointf_t get_cursor_position() const;
to get the proper cursor coordinates.

Position new windows centered under the mouse pointer, while
keeping them fully within the workarea.
Copy link
Member

@ammen99 ammen99 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@ammen99 ammen99 merged commit 365aefb into WayfireWM:master Dec 1, 2025
4 checks passed
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