Set cursor visible (Linux)
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 24m43s

This commit is contained in:
2024-08-08 20:43:27 -04:00
parent 9b810101a4
commit c319acfffb
3 changed files with 29 additions and 7 deletions

View File

@@ -208,12 +208,6 @@ namespace ReWindow
bool isAlive() const; // TODO: Always returns true.
/// Sets whether the mouse is visible when inside the window.
void setMouseVisible(bool visible);
void setMouseLocked();
void setMouseCenter();
void restoreMouseFromLastCenter(); // Feels nicer for users
bool isKeyDown(Key key) const;
bool isMouseButtonDown(MouseButton button) const;
@@ -271,6 +265,10 @@ namespace ReWindow
void setCursorStyle(CursorStyle style) const;
void setCursorCustomIcon() const;
void setCursorLocked();
void setCursorCenter();
void restoreCursorFromLastCenter(); // Feels nicer for users
///Hides the cursor when it's inside of our window.
///Useful for 3D game camera.
void setCursorVisible(bool cursor_enable);

View File

@@ -30,6 +30,7 @@ Atom windowTypeAtom;
Atom windowTypeUtilityAtom;
XSizeHints hints;
GLXContext glContext;
Cursor invisible_cursor = 0;
using namespace ReWindow;
@@ -65,6 +66,23 @@ void RWindow::refresh() {
//std::this_thread::sleep_for(1ms);
}
void RWindow::setCursorVisible(bool cursor_enable) {
cursor_visible = cursor_enable;
if (invisible_cursor == 0) {
Pixmap blank_pixmap = XCreatePixmap(display, window, 1, 1, 1);
XColor dummy; dummy.pixel = 0; dummy.red = 0; dummy.flags = 0;
invisible_cursor = XCreatePixmapCursor(display, blank_pixmap, blank_pixmap, &dummy, &dummy, 0, 0);
XFreePixmap(display, blank_pixmap);
}
if (!cursor_enable)
XDefineCursor(display, window, invisible_cursor);
if (cursor_enable)
XUndefineCursor(display, window);
}
void RWindow::setFlag(RWindowFlags flag, bool state) {
XGetWindowAttributes(display,window,&windowAttributes);
flags[(int) flag] = state;
@@ -85,6 +103,7 @@ void RWindow::pollEvents() {
if (xev.type == ClientMessage)
DEBUG(std::format("Recieved event '{}'", "ClientMessage"));
if (xev.xclient.message_type == XInternAtom(display, "WM_PROTOCOLS", False) && static_cast<Atom>(xev.xclient.data.l[0]) == wmDeleteWindow) {
destroyWindow();
system("xset r on");
@@ -99,6 +118,9 @@ void RWindow::pollEvents() {
OnFocusGain(event);
OnFocusGainEvent(event);
setFlag(RWindowFlags::IN_FOCUS, true);
if (!cursor_visible)
XDefineCursor(display, window, invisible_cursor);
}
if (xev.type == FocusOut) {
@@ -109,6 +131,9 @@ void RWindow::pollEvents() {
OnFocusLost(event);
OnFocusLostEvent(event);
setFlag(RWindowFlags::IN_FOCUS, false);
if (!cursor_visible)
XUndefineCursor(display, window);
}
if (xev.type == KeyRelease) {

View File

@@ -1 +0,0 @@
// Base Window Implementation - Anything that is consistent across Windows, Linux, etc