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

setMousePosition does not work on Wayland #780

Open
PierrickKoch opened this issue Jan 25, 2018 · 4 comments
Open

setMousePosition does not work on Wayland #780

PierrickKoch opened this issue Jan 25, 2018 · 4 comments

Comments

@PierrickKoch
Copy link
Member

in src/morse/blender/view_camera.py

setMousePosition does not work on Wayland (Fedora 26)

Result in unusable FPS view (using left CTRL)

@severin-lemaignan
Copy link
Contributor

You probably want to report that upstream...

@PierrickKoch
Copy link
Member Author

of course :) I will when I find time to reproduce it with minimal example, I'll keep track of any update here

@PierrickKoch
Copy link
Member Author

PierrickKoch commented Mar 1, 2018

here is a workaround, I'll open PR soon

diff --git a/src/morse/blender/view_camera.py b/src/morse/blender/view_camera.py
index da36f619..1e7c43db 100644
--- a/src/morse/blender/view_camera.py
+++ b/src/morse/blender/view_camera.py
@@ -18,6 +18,7 @@ from morse.core import blenderapi
 start_position = []
 start_orientation = []
 keyboard_ctrl_objects = []
+last_mouse_pose = None
 
 robots = []
 current_robot = 0
@@ -164,49 +165,36 @@ def rotate(contr):
                 # Hide the cursor while we control the camera
                 mouse_visible = False
                 if mouse.positive:
-                    # get width and height of game window
-                    width = blenderapi.render().getWindowWidth()
-                    height = blenderapi.render().getWindowHeight()
-
                     # get mouse movement from function
-                    move = mouse_move(camera, mouse, width, height)
-
+                    move = mouse_move(mouse)
                     # set mouse sensitivity
                     sensitivity = camera['Sensitivity']
-
                     # Amount, direction and sensitivity
                     leftRight = move[0] * sensitivity
                     upDown = move[1] * sensitivity
-
                     # set the values
                     camera.applyRotation( [0.0, 0.0, leftRight], 0 )
                     camera.applyRotation( [upDown, 0.0, 0.0], 1 )
 
-                    # Center mouse in game window
-                    # Using the '//' operator (floor division) to produce an integer result
-                    blenderapi.render().setMousePosition(width//2, height//2)
-
     # Set the cursor visibility
     blenderapi.mousepointer(visible = mouse_visible)
+    if mouse_visible:
+        global last_mouse_pose
+        last_mouse_pose = None
 
-def mouse_move(camera, mouse, width, height):
-    """ Get the movement of the mouse as an X, Y coordinate. """
-    # distance moved from screen center
-    # Using the '//' operator (floor division) to produce an integer result
-    x = width//2 - mouse.position[0]
-    y = height//2 - mouse.position[1]
-    
-    # intialize mouse so it doesn't jerk first time
-    try:
-        camera['mouseInit']
-    except KeyError:
-        x = 0
-        y = 0
-        # bug in Add Property
-        # can't use True.  Have to use 1
-        camera['mouseInit'] = 1
 
+def mouse_move(mouse):
+    """ Get the movement of the mouse as an X, Y coordinate. """
+    global last_mouse_pose
+    if not last_mouse_pose:
+        # intialize mouse so it doesn't jerk first time
+        last_mouse_pose = mouse.position
+        return 0, 0
+
+    # distance moved from last pose
+    x = last_mouse_pose[0] - mouse.position[0]
+    y = last_mouse_pose[1] - mouse.position[1]
     logger.debug("Read displacement: %s, %s" % (x, y))
-    
+    last_mouse_pose = mouse.position
     # return mouse movement
     return x, y

@PierrickKoch
Copy link
Member Author

Here is the ticket on d.b.o : https://developer.blender.org/T54238

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

No branches or pull requests

2 participants