#Drag Window with Mouse

1 messages · Page 1 of 1 (latest)

crisp musk
#

I'm trying to drag the window with the mouse to implement custom window decorations, but this is proving to be a bit more painful that it probably should. The only way to move the window I can find is to set the position with WindowPosition::At(new_pos) However, to find the current window position, you need to look at the WindowMove events - ideally we could just call window.position() to get the current window position.

Finally, to drag the window, I take the latest position, and add the mouse delta. The issue here is that the window keeps moving when it reaches the edge of the screen, because mouse deltas are still sent when the cursor runs into the edge of a screen.

Is there a less complicated way to do this? I swear I prototyped this a year back and it was way simpler.

quaint wagon
#

I tried to look at a way to add a delta in WindowMove -someone in #general had a similar need) but:

  • this event is actually a "copy" of a Winit event, and this Winit event doesn't have a delta either
  • this event is not fired every frame I think, it may even be fired only when you release the window? not sure about that
    There was no easy way to access the "previous position" of the window in that context, so I felt like it was too complicated for me to implement :x
crisp musk
#

Adding the delta wouldn't really help.

#

If anything, I need the mouse position in screen coords

#

I'd rather not use deltas as the conversion between Vec and IVec is causing drift.

#

The only workaround I can think of would be spawning a transparent fullscreen window with passthrough, and getting the cursor position on that window. That would be a horrifying hack though.

quaint wagon
#

oh no not that I'm dumb

#

I should think before writing XD

crisp musk
#

That is not relevant here. That gives the 3d world position. I'm asking about the screen coordinates, the same coordinates used to specify the window position.

#

Right now the only way to get cursor position is either with a delta (which doesn't actually tell me where the mouse is) or cursor position (which only works when the mouse is over the window).

quaint wagon
#

I think (but I'm not sure) it's actually an OS limitation, there's no way for winit to know where the mouse is when it's not on the window :x

#

That's what this comment seem to indicate at least : https://github.com/rust-windowing/winit/issues/883#issuecomment-496207749 "when the cursor reaches the border of the monitor, [...] the actual location of the cursor does not change."

GitHub

A common case is to get the location on screen a user clicks. The way to do that currently is to create a variable that stores the cursor location, which is updated whenever CursorMoved is received...