Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cursor warps maintain relative position within a window #6338

Merged
merged 5 commits into from
Jun 7, 2024

Conversation

memchr
Copy link
Contributor

@memchr memchr commented Jun 5, 2024

Enables hyprland to remember the position of the cursor relative to a window when the window is unfocused (unless caused by continuous cursor movement). later, when the window is refocused, the cursor will be warped back to its previously remembered position within that window, rather than to the centre of the window.

in addition, when moving a focused window, the relative cursor position would also be maintained instead of jumping to the centre. this includes

  • swap windows
  • moving windows
  • adding or removing windows from groups
  • moving windows to different workspaces

as a fallback, the cursor is still moved to the centre of the window when

  • the cursor is outside the window when it is unfocused
  • the cursor would be distorted outside the window if the relative position is remembered.

this behaviour is controlled by cursor:persistent_warps.

use case

improves usability for workflows where it is beneficial to maintain the cursor position within a window context, such as when frequently switching between multiple windows, e.g. between a browser and an ide.

this should be more noticeable to laptop users with trackpads, as these devices are relatively close to the keyboard and tend to be imprecise and require a lot of finger movement.

mechanism

terms

  • warp: a discontinuous cursor movement.
  • discontinuous unfocus: losing focus of a window that is not caused by moving the mouse continuously. currently it is usually caused by the movefocus dispatcher.
  • relative cursor position: the coordination of the cursor relative to the upper left corner of a window.

cursor position tracking

vector2d cwindow::m_vrelativecursorcoordsonlastwarp stores the cursor position relative to the window. it was updated whenever the window was about to lose focus discontinuously.

cursor warpping

void cwindow::warpcursor() handles the logic for warping the cursor.

  • if presistent_warps is disabled or the saved position is invalid, it behaves identically to g_pcompositor->warpcursorto(window->middle()), i.e. warp the cursor to the middle of the window;
  • otherwise it warps the cursor to the previously stored relative position.

integration with keybindings

  • updaterelativecursorcoords will update the relative cursor position before the last focused window is about to discontinuously lose focus.
  • several dispatchers are updated to call updaterelativecursorcoords before change of window position and to use the cwindow::warpcursor() method instead of warping the cursor to the centre of the window directly.

src/managers/KeybindManager.cpp Outdated Show resolved Hide resolved
src/desktop/Window.cpp Outdated Show resolved Hide resolved
Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

cool, rebase on master and wiki mr

Allows the cursor to return to its last relative position within a window when the window is refocused.

Allows the cursor to retain its relative position within a window when the window is swapped, moved, changed workspace, added to or removed from groups.

controlled with cursor:persistent_warps
memchr added a commit to memchr/hyprland-wiki that referenced this pull request Jun 7, 2024
@vaxerski vaxerski merged commit 41e1147 into hyprwm:main Jun 7, 2024
8 of 10 checks passed
vaxerski pushed a commit to hyprwm/hyprland-wiki that referenced this pull request Jun 7, 2024
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