The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Problem with MouseWarp on Raspberry pi in sdl 2.0.4
gepatto


Joined: 14 Sep 2015
Posts: 6
Location: Breda, The Netherlands
Hi All,

I am currently helping the people from OpenFL to get OpenFL working on the Raspberry Pi 2.
It uses SDL2 (2.0.4) to render via opengl es2 using the rapsberry pi video driver and libudev .
We are getting pretty close, normal rendering works fine but I am having 2 problems with the (rpi)mouse cursor.

I'll describe the first problem in this post:
Whenever the mouse cursor crosses the right or bottom border off the screen (display) the cursor gets garbled.
When it's completely outside the screen rect and you move the mouse back into the screenrect your are left with a white square as a cursor
When you move it just 1 pixel over the right screen edge you can see something that looks like a scaling-effect in the x-direction.


Can someone help me figure out what's going wrong?
Thanks in advance


How to reproduce?
Here's a piece of sample code (based on the sdl_image_example)
https://gist.github.com/gepatto/e1f7b925296d9c124cbd

SDL2 was configured with these options:
../configure --host=armv7l-raspberry-linux-gnueabihf --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11 --disable-video-opengl

I defined HAVE_LIBUDEV_H 1 in sdl_config.h
and had to manually add the source and headers files for SDL_udev.h and SDL_udev.c , and an object build rule in the makefile
gepatto


Joined: 14 Sep 2015
Posts: 6
Location: Breda, The Netherlands
I think I solved it myself,

vc_dispmanx_element_change_attributes with ELEMENT_CHANGE_DEST_RECT does not appear to function as expected.
I changed it to read from src to dst

Here's the new WarpMouseGlobal function
Code:

/* Warp the mouse to (x,y) */
static void
RPI_WarpMouseGlobal(int x, int y)
{
    RPI_CursorData *curdata;
    DISPMANX_UPDATE_HANDLE_T update;
    int ret;
    VC_RECT_T dst_rect;
    VC_RECT_T src_rect;
    SDL_Mouse *mouse = SDL_GetMouse();
   
    if (mouse != NULL && mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
        curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
        if (curdata->element != DISPMANX_NO_HANDLE) {
            update = vc_dispmanx_update_start( 10 );
            SDL_assert( update );
            src_rect.x = 0;
            src_rect.y = 0;
            src_rect.width  = curdata->w << 16;
            src_rect.height = curdata->h << 16;
            dst_rect.x = x;
            dst_rect.y = y;
            dst_rect.width  = curdata->w;
            dst_rect.height = curdata->h;

            ret = vc_dispmanx_element_change_attributes(
                update,
                curdata->element,
                0,
                0,
                0,
                &dst_rect,
                &src_rect,
                DISPMANX_NO_HANDLE,
                DISPMANX_NO_ROTATE);
            SDL_assert( ret == DISPMANX_SUCCESS );
            /* Submit asynchronously, otherwise the peformance suffers a lot */
            ret = vc_dispmanx_update_submit( update, 0, NULL );
            SDL_assert( ret == DISPMANX_SUCCESS );
        }
    }   
}