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

[Regression] SDL_VIDEODRIVER=x11 Phosh+XWayland single finger drag handling completely broken for both SDL_TOUCH_MOUSEID mouse events and finger events #5924

Closed
ell1e opened this issue Jul 16, 2022 · 5 comments
Assignees
Milestone

Comments

@ell1e
Copy link
Contributor

ell1e commented Jul 16, 2022

(scroll down for steps to reproduce)

Running an SDL app with SDL_VIDEODRIVER=x11 using the Phosh desktop (which is wayland-only so this uses XWayland), single finger drag handling is now completely broken for both SDL_TOUCH_MOUSEID mouse events and finger events. Mouse up/down touch up/down events are issued for the same set of coordinates always no matter how far you drag a single finger across screen, completely breaking any application that either has scrollbars to be dragged, or any drag and drop UI elements, or requires touch scrolling to navigate larger screens. This used to work with an older SDL2 and Phosh version, or in other words I am not sure which one of the two changed and broke this.

SDL2 version tested: 2.0.22-r0 (as shipped by postmarketOS 22.06)

Phosh version tested: 0.17.0 (as shipped by postmarketOS 22.06)

Device tested: PinePhone 1.2 CE 3GB Allwinner model

Steps to reproduce:

  1. Be on a Phosh desktop on a touch device. I imagine installing Phosh on an x64 laptop as shipped by Fedora if your laptop has a touch screen should work. Edit: apparently this is maybe not Phosh-related, so KDE or GNOME should then reproduce it as well, but I didn't have the chance to try!

  2. Save this code to sdlx11phoshbug.c:

#include <assert.h>
#include <SDL2/SDL.h>
#include <stdio.h>
#include <string.h>


int main(int argc, const char **argv) {
    printf("SDL_Init(...)\n");
    int result = SDL_Init(SDL_INIT_EVENTS|SDL_INIT_TIMER|
        SDL_INIT_VIDEO|SDL_INIT_HAPTIC|SDL_INIT_GAMECONTROLLER);
    assert(result == 0);
    printf("SDL_CreateWindow(...)\n");
    SDL_Window *window = SDL_CreateWindow("sdl dpi bug", 0, 0, 200, 200,
        SDL_WINDOW_RESIZABLE|SDL_WINDOW_OPENGL);
    assert(window != NULL);
    printf("SDL_CreateRenderer(...)\n");
    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC|
        SDL_RENDERER_ACCELERATED);

    double dpi = 1.0;
    int square1x = 100 * 0.5 * dpi;
    int square1y = 100 * 0.5 * dpi;
    int square2x = 100 * 0.5 * dpi;
    int square2y = 100 * 0.5 * dpi;
    int notquit = 1;
    while (notquit) {
        SDL_Event e = {0};
        while (SDL_PollEvent(&e)) {
            if (e.type == SDL_QUIT) {
                notquit = 0;
                break;
            } else if (e.type == SDL_WINDOWEVENT) {
                if (e.window.event == SDL_WINDOWEVENT_CLOSE) {
                    notquit = 0;
                    break;
                }
            } else if (e.type == SDL_MOUSEBUTTONDOWN &&
                    e.button.which == SDL_TOUCH_MOUSEID) {
                square1x = e.button.x * dpi;
                square1y = e.button.y * dpi;
                printf("touch down at: %d,%d\n", square1x, square1y);
            } else if (e.type == SDL_MOUSEBUTTONUP &&
                    e.button.which == SDL_TOUCH_MOUSEID) {
                square2x = e.button.x * dpi;
                square2y = e.button.y * dpi;
                printf("touch up at: %d,%d\n", square2x, square2y);
            } 
        }
        SDL_SetRenderDrawColor(renderer, 50, 0, 40, 255);
        SDL_RenderClear(renderer);
        SDL_SetRenderDrawColor(renderer, 240, 30, 230, 255);
        SDL_Rect r = {0};
        r.w = dpi * 20;
        r.h = dpi * 20;
        r.x = -0.5 * r.w + square1x;
        r.y = -0.5 * r.h + square1y;
        SDL_RenderFillRect(renderer, &r);
        SDL_SetRenderDrawColor(renderer, 140, 255, 130, 255);
        memset(&r, 0, sizeof(r));
        r.w = dpi * 20;
        r.h = dpi * 20;
        r.x = -0.5 * r.w + square2x;
        r.y = -0.5 * r.h + square2y;
        SDL_RenderFillRect(renderer, &r);
        SDL_RenderPresent(renderer);
    }
    return 0;
}
  1. Compile via gcc -o sdlx11phoshbug sdlx11phoshbug.c -lSDL2 and run ./sdlx11phoshbug
  2. Drag your finger across the window and lift it again
  3. Expected behavior: one square where your drag started, another where it stopped. Actual behavior: both squares are always where your finger drag started, which is rather wrong. You can also see the terminal output for the mouse button up shows wrong coordinates.
@ell1e
Copy link
Contributor Author

ell1e commented Jul 16, 2022

I also noticed the number of fingers reported by SDL is 0 both right after the mouse down/finger down and the mouse up/finger up events. I think for the first pair at least this is wrong or unexpected and should be 1. Not sure if related or not

@slouken slouken added this to the 2.24.0 milestone Jul 16, 2022
@dos1
Copy link
Contributor

dos1 commented Jul 19, 2022

This isn't related to Phosh at all, touch handling under X11 in SDL is broken since 2.0.22. I see test/testgesture working fine on Plasma with SDL 2.0.20 and broken with 2.0.22.

@dos1
Copy link
Contributor

dos1 commented Jul 19, 2022

Touch on X11 was broken by 5ff4243. A workaround is to set SDL_MOUSE_AUTO_CAPTURE=0.

@dos1
Copy link
Contributor

dos1 commented Jul 21, 2022

This is a duplicate of #5652.

@ell1e
Copy link
Contributor Author

ell1e commented Jul 21, 2022

Looks like it, closing (I hope that's the reasonable action)

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

4 participants