Getting started on platform specific stuff
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m32s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m32s
This commit is contained in:
@@ -104,16 +104,35 @@ public:
|
||||
void SetVsyncEnabled(bool vsync);
|
||||
void SetSize(int width, int height);
|
||||
void SetSize(const Vector2& size);
|
||||
// Added here for now
|
||||
void SetPos(int x, int y);
|
||||
void SetPos(const Vector2& pos);
|
||||
//
|
||||
void SetTitle(const std::string& title);
|
||||
public:
|
||||
std::string GetTitle();
|
||||
Vector2 GetPos();
|
||||
Vector2 GetSize();
|
||||
int GetWidth();
|
||||
int GetHeight();
|
||||
float GetDeltaTime();
|
||||
float GetRefreshRate();
|
||||
float GetRefreshCounter();
|
||||
std::string GetTitle() const;
|
||||
Vector2 GetPos() const;
|
||||
Vector2 GetSize() const;
|
||||
int GetWidth() const;
|
||||
int GetHeight() const;
|
||||
float GetDeltaTime() const;
|
||||
float GetRefreshRate() const;
|
||||
float GetRefreshCounter() const;
|
||||
public:
|
||||
// Figure out what to do with these later
|
||||
void Raise() const;
|
||||
void Lower() const;
|
||||
void DestroyOSWindowHandle();
|
||||
void SetCursorVisible(bool cursor_enable);
|
||||
Vector2 GetAccurateMouseCoordinates() const;
|
||||
void GLSwapBuffers();
|
||||
void Fullscreen();
|
||||
void RestoreFromFullscreen();
|
||||
// I know this doesn't modify the class, but it indirectly modifies the window
|
||||
// Making it const just seems deceptive.
|
||||
void SetCursorStyle(CursorStyle style) const;
|
||||
Vector2 GetPositionOfRenderableArea() const;
|
||||
std::string getGraphicsDriverVendor();
|
||||
};
|
||||
|
||||
class ReWindow::RWindow : private RWindowImpl {
|
||||
|
@@ -18,6 +18,7 @@
|
||||
|
||||
using namespace ReWindow;
|
||||
|
||||
/*
|
||||
Window window;
|
||||
XEvent xev;
|
||||
Display* display = XOpenDisplay(nullptr);
|
||||
@@ -36,11 +37,46 @@ Cursor invisible_cursor = 0;
|
||||
Vector2 render_area_position = {0, 0};
|
||||
Vector2 position = {0, 0};
|
||||
bool should_poll_x_for_mouse_pos = true;
|
||||
*/
|
||||
|
||||
class RWindowImpl::Platform {
|
||||
public:
|
||||
Platform() = default;
|
||||
public:
|
||||
Window window;
|
||||
XEvent xev;
|
||||
Display* display = XOpenDisplay(nullptr);
|
||||
int defaultScreen = DefaultScreen(display);
|
||||
XVisualInfo* visual;
|
||||
XSetWindowAttributes xSetWindowAttributes;
|
||||
XWindowAttributes windowAttributes;
|
||||
Atom wmDeleteWindow;
|
||||
// Make it start as floating because fuck tiling WMs
|
||||
Atom windowTypeAtom;
|
||||
Atom windowTypeUtilityAtom;
|
||||
XSizeHints hints;
|
||||
GLXContext glContext;
|
||||
Cursor invisible_cursor = 0;
|
||||
|
||||
Vector2 render_area_position = {0, 0};
|
||||
Vector2 position = {0, 0};
|
||||
bool should_poll_x_for_mouse_pos = true;
|
||||
};
|
||||
|
||||
RWindowImpl::RWindowImpl(const std::string &wTitle, int wWidth, int wHeight, bool wFullscreen, bool wResizable, bool wVsync) : pPlatform(new Platform) {
|
||||
title = wTitle;
|
||||
width = wWidth;
|
||||
height = wHeight;
|
||||
fullscreen_mode = wFullscreen;
|
||||
resizable = wResizable;
|
||||
vsync = wVsync;
|
||||
}
|
||||
|
||||
RWindowImpl::~RWindowImpl() {
|
||||
if (pPlatform) { delete pPlatform; };
|
||||
if (open)
|
||||
DestroyOSWindowHandle();
|
||||
}
|
||||
|
||||
//using namespace ReWindow;
|
||||
|
||||
@@ -48,23 +84,23 @@ void RWindowImpl::Raise() const {
|
||||
Logger::Debug(std::format("Raising window '{}'", this->title));
|
||||
|
||||
// Get the position of the renderable area relative to the rest of the window.
|
||||
XGetWindowAttributes(display, window, &windowAttributes);
|
||||
render_area_position = { (float) windowAttributes.x, (float) windowAttributes.y };
|
||||
XGetWindowAttributes(pPlatform->display, pPlatform->window, &pPlatform->windowAttributes);
|
||||
pPlatform->render_area_position = { (float) pPlatform->windowAttributes.x, (float) pPlatform->windowAttributes.y };
|
||||
|
||||
XRaiseWindow(display, window);
|
||||
XRaiseWindow(pPlatform->display, pPlatform->window);
|
||||
}
|
||||
|
||||
void RWindowImpl::Lower() const
|
||||
{
|
||||
Logger::Debug(std::format("Lowering window '{}'", this->title));
|
||||
XLowerWindow(display, window);
|
||||
XLowerWindow(pPlatform->display, pPlatform->window);
|
||||
}
|
||||
|
||||
void RWindowImpl::DestroyOSWindowHandle() {
|
||||
Logger::Debug(std::format("Destroying window '{}'", this->title));
|
||||
XDestroySubwindows(display, window);
|
||||
XDestroySubwindows(pPlatform->display, pPlatform->window);
|
||||
Logger::Debug(std::format("Destroyed window '{}'", this->title));
|
||||
XDestroyWindow(display, window);
|
||||
XDestroyWindow(pPlatform->display, pPlatform->window);
|
||||
|
||||
system("xset r on"); // Re-set X-server parameter to enable key-repeat.
|
||||
|
||||
@@ -75,37 +111,39 @@ void RWindowImpl::DestroyOSWindowHandle() {
|
||||
|
||||
void RWindowImpl::SetCursorVisible(bool cursor_enable) {
|
||||
cursor_visible = cursor_enable;
|
||||
if (invisible_cursor == 0) {
|
||||
Pixmap blank_pixmap = XCreatePixmap(display, window, 1, 1, 1);
|
||||
if (pPlatform->invisible_cursor == 0) {
|
||||
Pixmap blank_pixmap = XCreatePixmap(pPlatform->display, pPlatform->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);
|
||||
pPlatform->invisible_cursor = XCreatePixmapCursor(pPlatform->display, blank_pixmap, blank_pixmap, &dummy, &dummy, 0, 0);
|
||||
XFreePixmap(pPlatform->display, blank_pixmap);
|
||||
}
|
||||
|
||||
if (!cursor_enable)
|
||||
XDefineCursor(display, window, invisible_cursor);
|
||||
XDefineCursor(pPlatform->display, pPlatform->window, pPlatform->invisible_cursor);
|
||||
|
||||
if (cursor_enable)
|
||||
XUndefineCursor(display, window);
|
||||
XUndefineCursor(pPlatform->display, pPlatform->window);
|
||||
}
|
||||
|
||||
void RWindowImpl::SetResizable(bool sizable) {
|
||||
XGetWindowAttributes(display,window,&windowAttributes);
|
||||
XGetWindowAttributes(pPlatform->display,pPlatform->window,&pPlatform->windowAttributes);
|
||||
|
||||
|
||||
this->resizable = sizable;
|
||||
if (!sizable)
|
||||
{
|
||||
Logger::Debug("Once you've done this you cannot make it resizable again.");
|
||||
hints.flags = PMinSize | PMaxSize;
|
||||
hints.min_width = hints.max_width = windowAttributes.width;
|
||||
hints.min_height = hints.max_height = windowAttributes.height;
|
||||
XSetWMNormalHints(display, window, &hints);
|
||||
pPlatform->hints.flags = PMinSize | PMaxSize;
|
||||
pPlatform->hints.min_width = pPlatform->hints.max_width = pPlatform->windowAttributes.width;
|
||||
pPlatform->hints.min_height = pPlatform->hints.max_height = pPlatform->windowAttributes.height;
|
||||
XSetWMNormalHints(pPlatform->display, pPlatform->window, &pPlatform->hints);
|
||||
}
|
||||
//this->SetFlag(RWindowFlags::RESIZABLE, resizable);
|
||||
|
||||
}
|
||||
|
||||
// Fuck you
|
||||
/*
|
||||
void RWindowImpl::SetFlag(RWindowFlags flag, bool state) {
|
||||
XGetWindowAttributes(display,window,&windowAttributes);
|
||||
flags[(int) flag] = state;
|
||||
@@ -119,81 +157,82 @@ void RWindowImpl::SetFlag(RWindowFlags flag, bool state) {
|
||||
}
|
||||
Logger::Debug(std::format("Set flag '{}' to state '{}' for window '{}'", RWindowFlagToStr(flag), state, this->title));
|
||||
}
|
||||
*/
|
||||
|
||||
void RWindowImpl::PollEvents() {
|
||||
while(XPending(display)) {
|
||||
XNextEvent(display, &xev);
|
||||
while(XPending(pPlatform->display)) {
|
||||
XNextEvent(pPlatform->display, &pPlatform->xev);
|
||||
|
||||
if (xev.type == ClientMessage)
|
||||
if (pPlatform->xev.type == ClientMessage)
|
||||
Logger::Info(std::format("Event '{}'", "ClientMessage"));
|
||||
|
||||
if (xev.xclient.message_type == XInternAtom(display, "WM_PROTOCOLS", False) && static_cast<Atom>(xev.xclient.data.l[0]) == wmDeleteWindow) {
|
||||
if (pPlatform->xev.xclient.message_type == XInternAtom(pPlatform->display, "WM_PROTOCOLS", False) && static_cast<Atom>(pPlatform->xev.xclient.data.l[0]) == pPlatform->wmDeleteWindow) {
|
||||
Close();
|
||||
}
|
||||
|
||||
if (xev.type == FocusIn) {
|
||||
if (pPlatform->xev.type == FocusIn) {
|
||||
Logger::Debug(std::format("Event'{}'", "FocusIn"));
|
||||
XAutoRepeatOff(display);
|
||||
XAutoRepeatOff(pPlatform->display);
|
||||
SetFlag(RWindowFlags::IN_FOCUS, true);
|
||||
|
||||
if (!cursor_visible)
|
||||
XDefineCursor(display, window, invisible_cursor);
|
||||
XDefineCursor(pPlatform->display, pPlatform->window, pPlatform->invisible_cursor);
|
||||
|
||||
// Get the position of the renderable area relative to the rest of the window.
|
||||
XGetWindowAttributes(display, window, &windowAttributes);
|
||||
render_area_position = { (float) windowAttributes.x, (float) windowAttributes.y };
|
||||
XGetWindowAttributes(pPlatform->display, pPlatform->window, &pPlatform->windowAttributes);
|
||||
pPlatform->render_area_position = { (float) pPlatform->windowAttributes.x, (float) pPlatform->windowAttributes.y };
|
||||
processFocusIn();
|
||||
}
|
||||
|
||||
if (xev.type == FocusOut) {
|
||||
if (pPlatform->xev.type == FocusOut) {
|
||||
Logger::Debug(std::format("Event '{}'", "FocusOut"));
|
||||
XAutoRepeatOn(display);
|
||||
XAutoRepeatOn(pPlatform->display);
|
||||
|
||||
SetFlag(RWindowFlags::IN_FOCUS, false);
|
||||
if (!cursor_visible)
|
||||
XUndefineCursor(display, window);
|
||||
XUndefineCursor(pPlatform->display, pPlatform->window);
|
||||
|
||||
processFocusOut();
|
||||
}
|
||||
|
||||
if (xev.type == KeyRelease) {
|
||||
if (pPlatform->xev.type == KeyRelease) {
|
||||
Logger::Debug(std::format("Event '{}'", "KeyRelease"));
|
||||
auto scancode = (X11Scancode) xev.xkey.keycode;
|
||||
auto scancode = (X11Scancode) pPlatform->xev.xkey.keycode;
|
||||
auto key = GetKeyFromX11Scancode(scancode);
|
||||
processKeyRelease(key);
|
||||
}
|
||||
|
||||
if (xev.type == KeyPress) {
|
||||
if (pPlatform->xev.type == KeyPress) {
|
||||
Logger::Debug(std::format("Event '{}'", "KeyPress"));
|
||||
auto scancode = (X11Scancode) xev.xkey.keycode;
|
||||
auto scancode = (X11Scancode) pPlatform->xev.xkey.keycode;
|
||||
auto key = GetKeyFromX11Scancode(scancode);
|
||||
processKeyPress(key);
|
||||
}
|
||||
|
||||
if (xev.type == ButtonRelease) {
|
||||
if (pPlatform->xev.type == ButtonRelease) {
|
||||
|
||||
// Mouse Wheel fires both the ButtonPress and ButtonRelease instantaneously.
|
||||
// Therefore, we handle it as a specific MouseWheel event rather than a MouseButton event,
|
||||
// and only call on ButtonPress, otherwise it will appear to duplicate the mouse wheel scroll.
|
||||
if (xev.xbutton.button != 4 && xev.xbutton.button != 5) {
|
||||
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
|
||||
if (pPlatform->xev.xbutton.button != 4 && pPlatform->xev.xbutton.button != 5) {
|
||||
MouseButton button = GetMouseButtonFromXButton(pPlatform->xev.xbutton.button);
|
||||
Logger::Debug(std::format("Event '{}'", "ButtonRelease"));
|
||||
processMouseRelease(button);
|
||||
}
|
||||
}
|
||||
|
||||
if (xev.type == ButtonPress) {
|
||||
if (pPlatform->xev.type == ButtonPress) {
|
||||
|
||||
// Mouse Wheel fires both the ButtonPress and ButtonRelease instantaneously.
|
||||
// Therefore, we handle it as a specific MouseWheel event rather than a MouseButton event,
|
||||
// and only call on ButtonPress, otherwise it will appear to duplicate the mouse wheel scroll.
|
||||
if (xev.xbutton.button == 4) {
|
||||
if (pPlatform->xev.xbutton.button == 4) {
|
||||
processMouseWheel(-1);
|
||||
} else if (xev.xbutton.button == 5) {
|
||||
} else if (pPlatform->xev.xbutton.button == 5) {
|
||||
processMouseWheel(1);
|
||||
} else
|
||||
{
|
||||
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
|
||||
MouseButton button = GetMouseButtonFromXButton(pPlatform->xev.xbutton.button);
|
||||
|
||||
Logger::Debug(std::format("Event: MouseButtonPress {}", button.Mnemonic));
|
||||
|
||||
@@ -201,26 +240,26 @@ void RWindowImpl::PollEvents() {
|
||||
}
|
||||
}
|
||||
|
||||
if (xev.type == Expose)
|
||||
if (pPlatform->xev.type == Expose)
|
||||
{
|
||||
Logger::Debug(std::format("Event '{}'", "Expose"));
|
||||
}
|
||||
|
||||
// NOTE: This event is functionally useless, as it only informs of the very beginning and end of a mouse movement.
|
||||
if (xev.type == MotionNotify)
|
||||
if (pPlatform->xev.type == MotionNotify)
|
||||
{
|
||||
Logger::Debug(std::format("Event '{}'", "MotionNotify"));
|
||||
}
|
||||
|
||||
if (xev.type == ConfigureNotify) {
|
||||
if (this->width != xev.xconfigurerequest.width || this->height != xev.xconfigurerequest.height) {
|
||||
if (pPlatform->xev.type == ConfigureNotify) {
|
||||
if (this->width != pPlatform->xev.xconfigurerequest.width || this->height != pPlatform->xev.xconfigurerequest.height) {
|
||||
Logger::Debug(std::format("Event '{}'", "ResizeRequest"));
|
||||
|
||||
this->width = xev.xconfigurerequest.width;
|
||||
this->height = xev.xconfigurerequest.height;
|
||||
this->width = pPlatform->xev.xconfigurerequest.width;
|
||||
this->height = pPlatform->xev.xconfigurerequest.height;
|
||||
|
||||
auto eventData = WindowResizeRequestEvent();
|
||||
eventData.Size = { (float) xev.xconfigurerequest.width, (float) xev.xconfigurerequest.height };
|
||||
eventData.Size = { (float) pPlatform->xev.xconfigurerequest.width, (float) pPlatform->xev.xconfigurerequest.height };
|
||||
lastKnownWindowSize = eventData.Size;
|
||||
|
||||
OnResizeRequest(eventData);
|
||||
@@ -228,8 +267,8 @@ void RWindowImpl::PollEvents() {
|
||||
}
|
||||
|
||||
//Window Moved.
|
||||
if (position.x != xev.xconfigurerequest.x || position.y != xev.xconfigurerequest.y)
|
||||
position = { (float) xev.xconfigurerequest.x, (float) xev.xconfigurerequest.y };
|
||||
if (pPlatform->position.x != pPlatform->xev.xconfigurerequest.x || pPlatform->position.y != pPlatform->xev.xconfigurerequest.y)
|
||||
pPlatform->position = { (float) pPlatform->xev.xconfigurerequest.x, (float) pPlatform->xev.xconfigurerequest.y };
|
||||
}
|
||||
|
||||
}
|
||||
@@ -244,8 +283,8 @@ void RWindowImpl::SetSize(int newWidth, int newHeight) {
|
||||
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
XResizeWindow(display, window, newWidth, newHeight);
|
||||
XFlush(display);
|
||||
XResizeWindow(pPlatform->display, pPlatform->window, newWidth, newHeight);
|
||||
XFlush(pPlatform->display);
|
||||
Logger::Info(std::format("Set size for '{}' to {} x {}", this->title, newWidth, newHeight));
|
||||
}
|
||||
|
||||
@@ -257,7 +296,7 @@ Vector2 RWindowImpl::GetAccurateMouseCoordinates() const {
|
||||
uint32_t mask_return;
|
||||
|
||||
// This seems to be relative to the top left corner of the renderable area.
|
||||
bool mouseAvailable = XQueryPointer(display, window, &root_return, &child_return, &root_x_ret, &root_y_ret, &win_x_ret, &win_y_ret, &mask_return);
|
||||
bool mouseAvailable = XQueryPointer(pPlatform->display, pPlatform->window, &root_return, &child_return, &root_x_ret, &root_y_ret, &win_x_ret, &win_y_ret, &mask_return);
|
||||
|
||||
if (mouseAvailable) {
|
||||
// TODO: normalize coordinates from displaySpace to windowSpace
|
||||
@@ -280,12 +319,12 @@ Vector2 RWindowImpl::GetSize() const {
|
||||
|
||||
// TODO: implement integer vector2/3 types
|
||||
Vector2 RWindowImpl::GetPos() const {
|
||||
return position;
|
||||
return pPlatform->position;
|
||||
}
|
||||
|
||||
void RWindowImpl::SetPos(int x, int y) {
|
||||
XMoveWindow(display, window, x, y);
|
||||
position = { (float) x, (float) y };
|
||||
XMoveWindow(pPlatform->display, pPlatform->window, x, y);
|
||||
pPlatform->position = { (float) x, (float) y };
|
||||
}
|
||||
|
||||
void RWindowImpl::SetPos(const Vector2& pos) {
|
||||
@@ -294,7 +333,7 @@ void RWindowImpl::SetPos(const Vector2& pos) {
|
||||
|
||||
|
||||
void RWindowImpl::GLSwapBuffers() {
|
||||
glXSwapBuffers(display,window);
|
||||
glXSwapBuffers(pPlatform->display,pPlatform->window);
|
||||
}
|
||||
|
||||
|
||||
@@ -303,19 +342,19 @@ void RWindowImpl::Fullscreen() {
|
||||
fullscreen_mode = true;
|
||||
|
||||
XEvent xev;
|
||||
Atom wm_state = XInternAtom(display, "_NET_WM_STATE", true);
|
||||
Atom wm_fullscreen = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", true);
|
||||
Atom wm_state = XInternAtom(pPlatform->display, "_NET_WM_STATE", true);
|
||||
Atom wm_fullscreen = XInternAtom(pPlatform->display, "_NET_WM_STATE_FULLSCREEN", true);
|
||||
|
||||
XChangeProperty(display, window, wm_state, XA_ATOM, 32, PropModeReplace, (unsigned char *)&wm_fullscreen, 1);
|
||||
XChangeProperty(pPlatform->display, pPlatform->window, wm_state, XA_ATOM, 32, PropModeReplace, (unsigned char *)&wm_fullscreen, 1);
|
||||
memset(&xev, 0, sizeof(xev));
|
||||
xev.type = ClientMessage;
|
||||
xev.xclient.window = window;
|
||||
xev.xclient.window = pPlatform->window;
|
||||
xev.xclient.message_type = wm_state;
|
||||
xev.xclient.format = 32;
|
||||
xev.xclient.data.l[0] = 1; // _NET_WM_STATE_ADD
|
||||
xev.xclient.data.l[1] = fullscreen_mode;
|
||||
xev.xclient.data.l[2] = 0;
|
||||
XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
XSendEvent(pPlatform->display, DefaultRootWindow(pPlatform->display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
Logger::Debug(std::format("Fullscreened '{}'", this->title));
|
||||
}
|
||||
|
||||
@@ -323,72 +362,74 @@ void RWindowImpl::RestoreFromFullscreen() {
|
||||
Logger::Debug(std::format("Restoring '{}' from Fullscreen", this->title));
|
||||
fullscreen_mode = false;
|
||||
XEvent xev;
|
||||
Atom wm_state = XInternAtom(display, "_NET_WM_STATE", False);
|
||||
Atom fullscreen = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", False);
|
||||
Atom wm_state = XInternAtom(pPlatform->display, "_NET_WM_STATE", False);
|
||||
Atom fullscreen = XInternAtom(pPlatform->display, "_NET_WM_STATE_FULLSCREEN", False);
|
||||
memset(&xev, 0, sizeof(xev));
|
||||
xev.type = ClientMessage;
|
||||
xev.xclient.window = window;
|
||||
xev.xclient.window = pPlatform->window;
|
||||
xev.xclient.message_type = wm_state;
|
||||
xev.xclient.format = 32;
|
||||
xev.xclient.data.l[0] = 0; // _NET_WM_STATE_REMOVE
|
||||
xev.xclient.data.l[1] = fullscreen_mode;
|
||||
xev.xclient.data.l[2] = 0;
|
||||
XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
XSendEvent(pPlatform->display, DefaultRootWindow(pPlatform->display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
Logger::Debug(std::format("Restored '{}' from Fullscreen", this->title));
|
||||
}
|
||||
|
||||
void RWindowImpl::SetVsyncEnabled(bool b) {
|
||||
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
|
||||
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
|
||||
glXSwapIntervalEXT(display, window, b);
|
||||
glXSwapIntervalEXT(pPlatform->display, pPlatform->window, b);
|
||||
}
|
||||
|
||||
|
||||
// I know this doesn't modify the class, but it indirectly modifies the window
|
||||
// Making it const just seems deceptive.
|
||||
void RWindowImpl::SetCursorStyle(CursorStyle style) const {
|
||||
u32 x11_cursor_resolved_enum = static_cast<u32>(style.X11Cursor);
|
||||
Cursor c = XCreateFontCursor(display, x11_cursor_resolved_enum);
|
||||
XDefineCursor(display, window, c);
|
||||
Cursor c = XCreateFontCursor(pPlatform->display, x11_cursor_resolved_enum);
|
||||
XDefineCursor(pPlatform->display, pPlatform->window, c);
|
||||
}
|
||||
|
||||
void RWindowImpl::Open() {
|
||||
xSetWindowAttributes.border_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.background_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.override_redirect = True;
|
||||
xSetWindowAttributes.event_mask = ExposureMask;
|
||||
pPlatform->xSetWindowAttributes.border_pixel = BlackPixel(pPlatform->display, pPlatform->defaultScreen);
|
||||
pPlatform->xSetWindowAttributes.background_pixel = BlackPixel(pPlatform->display, pPlatform->defaultScreen);
|
||||
pPlatform->xSetWindowAttributes.override_redirect = True;
|
||||
pPlatform->xSetWindowAttributes.event_mask = ExposureMask;
|
||||
//SetVsyncEnabled(vsync);
|
||||
if (renderer == RenderingAPI::OPENGL) {
|
||||
GLint glAttributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
|
||||
visual = glXChooseVisual(display, defaultScreen, glAttributes);
|
||||
glContext = glXCreateContext(display, visual, nullptr, GL_TRUE);
|
||||
pPlatform->visual = glXChooseVisual(pPlatform->display, pPlatform->defaultScreen, glAttributes);
|
||||
pPlatform->glContext = glXCreateContext(pPlatform->display, pPlatform->visual, nullptr, GL_TRUE);
|
||||
}
|
||||
|
||||
xSetWindowAttributes.colormap = XCreateColormap(display, RootWindow(display, defaultScreen), visual->visual, AllocNone);
|
||||
pPlatform->xSetWindowAttributes.colormap = XCreateColormap(pPlatform->display, RootWindow(pPlatform->display, pPlatform->defaultScreen), pPlatform->visual->visual, AllocNone);
|
||||
|
||||
window = XCreateWindow(display, RootWindow(display, defaultScreen), 0, 0, width, height, 0, visual->depth,
|
||||
InputOutput, visual->visual, CWBackPixel | CWColormap | CWBorderPixel | NoEventMask,
|
||||
&xSetWindowAttributes);
|
||||
pPlatform->window = XCreateWindow(pPlatform->display, RootWindow(pPlatform->display, pPlatform->defaultScreen), 0, 0, width, height, 0, pPlatform->visual->depth,
|
||||
InputOutput, pPlatform->visual->visual, CWBackPixel | CWColormap | CWBorderPixel | NoEventMask,
|
||||
&pPlatform->xSetWindowAttributes);
|
||||
// Set window to floating because fucking tiling WMs
|
||||
windowTypeAtom = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
|
||||
windowTypeUtilityAtom = XInternAtom(display, "_NET_WM_WINDOW_TYPE_UTILITY", False);
|
||||
XChangeProperty(display, window, windowTypeAtom, XA_ATOM, 32, PropModeReplace,
|
||||
(unsigned char *)&windowTypeUtilityAtom, 1);
|
||||
pPlatform->windowTypeAtom = XInternAtom(pPlatform->display, "_NET_WM_WINDOW_TYPE", False);
|
||||
pPlatform->windowTypeUtilityAtom = XInternAtom(pPlatform->display, "_NET_WM_WINDOW_TYPE_UTILITY", False);
|
||||
XChangeProperty(pPlatform->display, pPlatform->window, pPlatform->windowTypeAtom, XA_ATOM, 32, PropModeReplace,
|
||||
(unsigned char *)&pPlatform->windowTypeUtilityAtom, 1);
|
||||
//
|
||||
XSelectInput(display, window,
|
||||
XSelectInput(pPlatform->display, pPlatform->window,
|
||||
ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
|
||||
PointerMotionMask |
|
||||
PointerMotionHintMask | FocusChangeMask | StructureNotifyMask | SubstructureRedirectMask |
|
||||
SubstructureNotifyMask | CWColormap );
|
||||
XMapWindow(display, window);
|
||||
XStoreName(display, window, title.c_str());
|
||||
wmDeleteWindow = XInternAtom(display, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(display, window, &wmDeleteWindow, 1);
|
||||
XMapWindow(pPlatform->display, pPlatform->window);
|
||||
XStoreName(pPlatform->display, pPlatform->window, title.c_str());
|
||||
pPlatform->wmDeleteWindow = XInternAtom(pPlatform->display, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(pPlatform->display, pPlatform->window, &pPlatform->wmDeleteWindow, 1);
|
||||
|
||||
if (renderer == RenderingAPI::OPENGL)
|
||||
glXMakeCurrent(display, window, glContext);
|
||||
glXMakeCurrent(pPlatform->display, pPlatform->window, pPlatform->glContext);
|
||||
|
||||
// Get the position of the renderable area relative to the rest of the window.
|
||||
XGetWindowAttributes(display, window, &windowAttributes);
|
||||
render_area_position = { (float) windowAttributes.x, (float) windowAttributes.y };
|
||||
XGetWindowAttributes(pPlatform->display, pPlatform->window, &pPlatform->windowAttributes);
|
||||
pPlatform->render_area_position = { (float) pPlatform->windowAttributes.x, (float) pPlatform->windowAttributes.y };
|
||||
|
||||
open = true;
|
||||
|
||||
@@ -397,13 +438,13 @@ void RWindowImpl::Open() {
|
||||
|
||||
void RWindowImpl::SetTitle(const std::string &title) {
|
||||
this->title = title;
|
||||
XStoreName(display, window, title.c_str());
|
||||
XStoreName(pPlatform->display, pPlatform->window, title.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vector2 RWindowImpl::GetPositionOfRenderableArea() const {
|
||||
return render_area_position;
|
||||
return pPlatform->render_area_position;
|
||||
}
|
||||
|
||||
std::string RWindowImpl::getGraphicsDriverVendor() {
|
||||
|
Reference in New Issue
Block a user