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

Mouse grabbing and Moving on X11 #1300

Open
1 of 2 tasks
Gamma-42 opened this issue Nov 30, 2024 · 4 comments
Open
1 of 2 tasks

Mouse grabbing and Moving on X11 #1300

Gamma-42 opened this issue Nov 30, 2024 · 4 comments

Comments

@Gamma-42
Copy link

Gamma-42 commented Nov 30, 2024

WslLogs-2024-11-30_05-23-24.zip

Windows Version

Microsoft Windows [Version 10.0.22631.4460]

WSL Version

2.3.26.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.167.4-1

Distro Version

Ubuntu 22.04

Other Software

No response

Repro Steps

Simply open an X11 Window with C and try to use the XGrabPointer function or try to define an "invisible" (empty texture) cursor with XDefineCursor.
I put my code in Diagnostic Log.
compile with: cc filename.c -lX11 -lXext -I/usr/include -L/usr/lib
run with: ./a.out

Expected Behavior

For XGrabPointer the mouse events should only be passed to the X11 Window, so that the Mouse is basically trapped inside. The window basically reserves the mouse pointer.

For XDefineCursor the Cursor Image should be set to the passed Image.
I tested these functions also on my other laptop where the same Ubuntu is installed normally (without wsl) everything there works as expected.

Actual Behavior

Even after XGrapPointer the mouse moves freely over the screen and isn't reserved by the window.
Instead of an custom image the cursor also just shows the standard image. (Changing the cursor image with XCreateFontCursor works)

Diagnostic Logs

#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

struct color_struct {
unsigned long black, white;
};

#define SCREEN (DefaultScreen(display))
#define ROOT_WINDOW (DefaultRootWindow(display))

Cursor create_invisible_cursor(Display *display, Window root) {
Pixmap bitmap_no_data;
XColor black;
static char no_data[] = { 0,0,0,0,0,0,0,0 };
black.red = black.green = black.blue = 0;

bitmap_no_data = XCreateBitmapFromData(display, root, no_data, 8, 8);
return XCreatePixmapCursor(display, bitmap_no_data, bitmap_no_data, &black, &black, 0, 0);

}

int main(void) {
int depth;
char *display_name;
struct color_struct *color = malloc(sizeof(struct color_struct));

Display *display;
Window main_window;

display = XOpenDisplay(0);
assert(display);

printf("Default display opened\n");
printf("Size: %dx%d\n", XDisplayWidth(display, SCREEN),
    XDisplayHeight(display, SCREEN));

color->black = XBlackPixel(display, SCREEN);
color->white = XWhitePixel(display, SCREEN);

main_window = XCreateSimpleWindow(display, ROOT_WINDOW, 0, 0, 200, 100, 0,
    color->black, color->black);
assert(main_window);

printf("Main window created\n");

XMapWindow(display, main_window);
XGrabPointer(display, main_window, True, 0, GrabModeAsync, GrabModeAsync, main_window, None, CurrentTime);

// Create and set an invisible cursor
Cursor invisible_cursor = create_invisible_cursor(display, ROOT_WINDOW);
XDefineCursor(display, main_window, invisible_cursor);
XFlush(display);

while (1) {
    // Move the pointer to the top-left corner of the main window
    XWarpPointer(display, None, main_window, 0, 0, 0, 0, 0, 0);
    XGrabPointer(display, main_window, True, 0, GrabModeAsync, GrabModeAsync, main_window, None, CurrentTime);
    sleep(2);
    
}

// Cleanup (not reached in this example)
XFreeCursor(display, invisible_cursor);
free(color);
XCloseDisplay(display);

return 0;

}

Copy link

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The script will output the path of the log file once done.

If this is a networking issue, please use collect-networking-logs.ps1, following the instructions here

Once completed please upload the output files to this Github issue.

Click here for more info on logging
If you choose to email these logs instead of attaching to the bug, please send them to [email protected] with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

Copy link

Diagnostic information
Issue was edited and new log file was found: https://github.com/user-attachments/files/17964171/WslLogs-2024-11-30_05-23-24.zip
Detected appx version: 2.3.26.0

@Gamma-42
Copy link
Author

Adding a Log seems unnecessary, but ok

@OneBlue OneBlue transferred this issue from microsoft/WSL Dec 2, 2024
@MamiyaOtaru
Copy link

This is basically #376

see also #374 and #240

It's unfortunately been around and known for years :(

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