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

Add Mouse Capture/Grab #394

Closed
Robert42 opened this Issue May 21, 2013 · 6 comments

Comments

Projects
None yet
5 participants
@Robert42

Robert42 commented May 21, 2013

When programming an application in window mode, which is using the mouse movement but is not using the mouse position (like a first person shooter), one need to make sure the cursor won't leave the window.

One common way to realize this is to set the mouse cursor to the center of the window after each frame.

But there's a problem if the mouse-movement is too fast and/or the framerate of the application too low. In that case the cursor can leave the window for a small period of time. If the user clicks the mouse right in this moment, the window will loose the focus.

I suggest to wrap around the methods to capture/grap the mouse provided by the operating system. Maybe some kind of sf::Window::grabMouse().

For discussion about this feature request, see the forum.

In the forum, there are also operating-system functions suggested to realize this:

@MarioLiebisch

This comment has been minimized.

Member

MarioLiebisch commented May 21, 2013

Question: What do you think? Should the cursor be clipped to the whole window (client + frame), or the actual client area only? Maybe even add a toggle/flag?

@ghost

This comment has been minimized.

ghost commented May 22, 2013

It's always just the client window. Never the frame.

@retep998

This comment has been minimized.

retep998 commented May 22, 2013

It shouldn't include the frame/decorations, because if the user quickly moves the mouse and clicks, they may end up clicking on the frame rather than the client area, and in worst case scenarios they may even click the close button!

@MarioLiebisch

This comment has been minimized.

Member

MarioLiebisch commented May 22, 2013

Updated the code to use a single function now. It traps the cursor within the client area while the window is active.

@MarioLiebisch

This comment has been minimized.

Member

MarioLiebisch commented Jun 10, 2013

Oh, completely forgot to post an update here for those that are subscribed or whatever. My implementation (see pull request above) now works for both Windows and X11, I just need someone to do the MacOS X part (or buy me a Mac).

@Bromeon Bromeon added feature and removed undecided labels Apr 1, 2014

@Bromeon Bromeon added this to the 2.2 milestone Apr 1, 2014

@Bromeon Bromeon self-assigned this Apr 1, 2014

@Bromeon Bromeon modified the milestone: 2.2 Apr 1, 2014

@mantognini mantognini assigned mantognini and unassigned Bromeon May 22, 2014

mantognini added a commit that referenced this issue May 22, 2014

Moved more responsibilities to SFOpenGLView
These changes will ease the implementation of mouse grab (#394)

mantognini added a commit that referenced this issue May 22, 2014

Moved more responsibilities to SFOpenGLView
These changes will ease the implementation of mouse grab (#394)

mantognini added a commit that referenced this issue May 23, 2014

Moved more responsibilities to SFOpenGLView
These changes will ease the implementation of mouse grab (#394)

@mantognini mantognini referenced this issue May 25, 2014

Merged

Feature/grab mouse #614

3 of 5 tasks complete

@mantognini mantognini modified the milestones: 2.x, 2.2 May 28, 2014

@mantognini

This comment has been minimized.

Member

mantognini commented Jun 14, 2014

Superseded by #614.

@mantognini mantognini closed this Jun 14, 2014

@mantognini mantognini self-assigned this Feb 7, 2016

binary1248 added a commit that referenced this issue Mar 12, 2016

Added Unix implementation of sf::Window::setCursorGrabbed (#394), fix…
…ed xcb_set_input_focus being called on a window before it is viewable on some window managers (#991).

mantognini added a commit that referenced this issue Mar 31, 2016

Added Unix implementation of sf::Window::setCursorGrabbed (#394), fix…
…ed xcb_set_input_focus being called on a window before it is viewable on some window managers (#991).

mantognini added a commit that referenced this issue Apr 25, 2016

Added Unix implementation of sf::Window::setCursorGrabbed (#394), fix…
…ed xcb_set_input_focus being called on a window before it is viewable on some window managers (#991).

mantognini added a commit that referenced this issue May 9, 2016

Added Unix implementation of sf::Window::setCursorGrabbed (#394), fix…
…ed xcb_set_input_focus being called on a window before it is viewable on some window managers (#991).

mantognini added a commit that referenced this issue May 10, 2016

Added Unix implementation of sf::Window::setCursorGrabbed (#394), fix…
…ed xcb_set_input_focus being called on a window before it is viewable on some window managers (#991).

mantognini added a commit that referenced this issue Jun 8, 2016

Added Unix implementation of sf::Window::setCursorGrabbed (#394), fix…
…ed xcb_set_input_focus being called on a window before it is viewable on some window managers (#991).

mantognini added a commit that referenced this issue Jun 8, 2016

Added Unix implementation of sf::Window::setCursorGrabbed (#394), fix…
…ed xcb_set_input_focus being called on a window before it is viewable on some window managers (#991).

eXpl0it3r added a commit that referenced this issue Jul 17, 2016

Added Unix implementation of sf::Window::setCursorGrabbed (#394), fix…
…ed xcb_set_input_focus being called on a window before it is viewable on some window managers (#991).

@mantognini mantognini added this to the 2.4 milestone Aug 5, 2016

iamPHEN added a commit to Bablawn3d5/SFML that referenced this issue Mar 11, 2017

Added Unix implementation of sf::Window::setCursorGrabbed (SFML#394),…
… fixed xcb_set_input_focus being called on a window before it is viewable on some window managers (SFML#991).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment