XGrabPointer doesn't seem to be doing what I want.

This commit is contained in:
Menotdan
2023-05-18 15:42:04 -04:00
parent 408d620b17
commit f5d3e30972
3 changed files with 32 additions and 8 deletions

View File

@@ -5,6 +5,7 @@
#include "Engine/Core/Math/Vector2.h"
#include "Engine/Core/Delegate.h"
#include "Engine/Core/Log.h"
#include "Engine/Platform/Linux/LinuxPlatform.h"
#include "Engine/Platform/Linux/IncludeX11.h"
@@ -40,7 +41,7 @@ Int2 ScreenUtilities::GetScreenCursorPosition()
X11::Window rootWindowBuffer;
int rootX, rootY;
int winXBuffer, winYBuffer;
uint maskBuffer;
unsigned int maskBuffer;
int gotPointer = X11::XQueryPointer(display, rootWindow, &rootWindowBuffer, &rootWindowBuffer, &rootX, &rootY, &winXBuffer, &winYBuffer, &maskBuffer);
if (!gotPointer) {
@@ -59,28 +60,43 @@ class ScreenUtilitiesLinux
{
public:
static void BlockAndReadMouse();
static void xEventHandler(void* event);
};
void ScreenUtilitiesLinux::xEventHandler(void* eventPtr) {
X11::XEvent* event = (X11::XEvent*) eventPtr;
LOG(Warning, "Got event. {0}", event->type);
if (0) {
LOG(Warning, "Got MOUSE CLICK event.");
X11::Display* display = X11::XOpenDisplay(NULL);
LOG(Warning, "Tried to ungrab pointer. {0}", X11::XUngrabPointer(display, CurrentTime));
X11::XCloseDisplay(display);
LinuxPlatform::xEventRecieved.Unbind(xEventHandler); // Unbind the event, we only want to handle one click event.
}
}
void ScreenUtilitiesLinux::BlockAndReadMouse()
{
X11::Display* display = X11::XOpenDisplay(NULL);
X11::Window rootWindow = X11::XRootWindow(display, X11::XDefaultScreen(display));
int grabbedPointer = X11::XGrabPointer(display, rootWindow, 0, Button1Mask, GrabModeAsync, GrabModeAsync, rootWindow, NULL, CurrentTime);
int grabbedPointer = X11::XGrabPointer(display, rootWindow, 1, Button1Mask, GrabModeAsync, GrabModeAsync, rootWindow, NULL, CurrentTime);
if (grabbedPointer != GrabSuccess) {
LOG(Error, "Failed to grab cursor for events.");
return;
}
// No idea how to proceed from here for events.
return;
LinuxPlatform::xEventRecieved.Bind(xEventHandler);
}
Delegate<Color32> ScreenUtilities::PickColorDone;
void ScreenUtilities::PickColor()
{
return;
ScreenUtilitiesLinux::BlockAndReadMouse();
}
#endif

View File

@@ -5,6 +5,7 @@
#include "LinuxPlatform.h"
#include "LinuxWindow.h"
#include "LinuxInput.h"
#include "IncludeX11.h"
#include "Engine/Core/Log.h"
#include "Engine/Core/Types/Guid.h"
#include "Engine/Core/Types/String.h"
@@ -30,7 +31,6 @@
#include "Engine/Input/Input.h"
#include "Engine/Input/Mouse.h"
#include "Engine/Input/Keyboard.h"
#include "IncludeX11.h"
#include <sys/resource.h>
#include <sys/sysinfo.h>
#include <sys/time.h>
@@ -2217,6 +2217,8 @@ void LinuxPlatform::BeforeRun()
{
}
Delegate<void*> LinuxPlatform::xEventRecieved;
void LinuxPlatform::Tick()
{
UnixPlatform::Tick();
@@ -2234,7 +2236,8 @@ void LinuxPlatform::Tick()
if (X11::XFilterEvent(&event, 0))
continue;
xEventRecieved(&event); // Fire the event, since we recieved an event.
LinuxWindow* window;
switch (event.type)
{

View File

@@ -33,6 +33,11 @@ public:
/// <returns>The user home directory.</returns>
static const String& GetHomeDirectory();
/// <summary>
/// An event that is fired when an XEvent is recieved by Flax.
/// </summary>
static Delegate<void*> xEventRecieved;
public:
// [UnixPlatform]