Started adding DEBUG logging to library code. Wrote RWindowFlagToStr function for better logging capabilities.
This commit is contained in:
@@ -35,6 +35,8 @@ enum class RWindowFlags: uint8_t {
|
||||
MAX_FLAG
|
||||
};
|
||||
|
||||
std::string RWindowFlagToStr(RWindowFlags flag);
|
||||
|
||||
enum class RenderingAPI: uint8_t {
|
||||
OPENGL = 0,
|
||||
//Vulkan is unimplemented.
|
||||
|
@@ -8,6 +8,8 @@
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
|
||||
#include <jlog/jlog.hpp>
|
||||
|
||||
|
||||
|
||||
// TODO: Move all "global" members to be instantiated class members of Window
|
||||
@@ -29,15 +31,38 @@ Atom windowTypeUtilityAtom;
|
||||
XSizeHints hints;
|
||||
GLXContext glContext;
|
||||
|
||||
std::string RWindowFlagToStr(RWindowFlags flag)
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
case RWindowFlags::IN_FOCUS: return "IN_FOCUS";
|
||||
case RWindowFlags::FULLSCREEN: return "FULLSCREEN";
|
||||
case RWindowFlags::RESIZABLE: return "RESIZEABLE";
|
||||
case RWindowFlags::VSYNC: return "VSYNC";
|
||||
case RWindowFlags::QUIT: return "QUIT";
|
||||
case RWindowFlags::MAX_FLAG: return "MAX_FLAG";
|
||||
}
|
||||
};
|
||||
|
||||
using namespace ReWindow;
|
||||
|
||||
void RWindow::raise() const { XRaiseWindow(display, window); }
|
||||
void RWindow::lower() const { XLowerWindow(display, window); }
|
||||
void RWindow::raise() const {
|
||||
DEBUG(std::format("Raising window '{}'", this->title));
|
||||
XRaiseWindow(display, window);
|
||||
}
|
||||
|
||||
void RWindow::lower() const
|
||||
{
|
||||
DEBUG(std::format("Lowering window '{}'", this->title));
|
||||
XLowerWindow(display, window);
|
||||
}
|
||||
|
||||
void RWindow::destroyWindow() {
|
||||
DEBUG(std::format("Destroying window '{}'", this->title));
|
||||
XDestroySubwindows(display, window);
|
||||
XDestroyWindow(display, window);
|
||||
delete this;
|
||||
DEBUG(std::format("Destroyed window '{}'", this->title));
|
||||
}
|
||||
|
||||
void RWindow::refresh() {
|
||||
@@ -57,11 +82,13 @@ void RWindow::setFlag(RWindowFlags flag, bool state) {
|
||||
flags[(int) flag] = state;
|
||||
//Once you've done this you cannot make it resizable again.
|
||||
if (flag == RWindowFlags::RESIZABLE && !state) {
|
||||
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);
|
||||
}
|
||||
DEBUG(std::format("Set flag '{}' to state '{}' for window '{}'", RWindowFlagToStr(flag), state, this->title));
|
||||
}
|
||||
|
||||
void RWindow::pollEvents() {
|
||||
@@ -69,6 +96,7 @@ void RWindow::pollEvents() {
|
||||
XNextEvent(display, &xev);
|
||||
|
||||
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");
|
||||
@@ -76,6 +104,7 @@ void RWindow::pollEvents() {
|
||||
}
|
||||
|
||||
if (xev.type == FocusIn) {
|
||||
DEBUG(std::format("Recieved event '{}'", "FocusIn"));
|
||||
XAutoRepeatOff(display);
|
||||
//focusGained.Invoke();
|
||||
RWindowEvent event {};
|
||||
@@ -84,6 +113,7 @@ void RWindow::pollEvents() {
|
||||
}
|
||||
|
||||
if (xev.type == FocusOut) {
|
||||
DEBUG(std::format("Recieved event '{}'", "FocusOut"));
|
||||
XAutoRepeatOn(display);
|
||||
//focusLost.Invoke();
|
||||
RWindowEvent event {};
|
||||
@@ -92,6 +122,7 @@ void RWindow::pollEvents() {
|
||||
}
|
||||
|
||||
if (xev.type == KeyRelease) {
|
||||
DEBUG(std::format("Recieved event '{}'", "KeyRelease"));
|
||||
auto scancode = (X11Scancode) xev.xkey.keycode;
|
||||
auto key = GetKeyFromX11Scancode(scancode);
|
||||
OnKeyUpEvent(key);
|
||||
@@ -100,6 +131,7 @@ void RWindow::pollEvents() {
|
||||
}
|
||||
|
||||
if (xev.type == KeyPress) {
|
||||
DEBUG(std::format("Recieved event '{}'", "KeyPress"));
|
||||
auto scancode = (X11Scancode) xev.xkey.keycode;
|
||||
auto key = GetKeyFromX11Scancode(scancode);
|
||||
OnKeyDownEvent(key);
|
||||
@@ -109,6 +141,7 @@ void RWindow::pollEvents() {
|
||||
}
|
||||
|
||||
if (xev.type == ButtonRelease) {
|
||||
DEBUG(std::format("Recieved event '{}'", "ButtonRelease"));
|
||||
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
|
||||
auto eventData = MouseButtonUpEvent();
|
||||
eventData.Button = button;
|
||||
@@ -117,6 +150,7 @@ void RWindow::pollEvents() {
|
||||
}
|
||||
|
||||
if (xev.type == ButtonPress) {
|
||||
DEBUG(std::format("Recieved event '{}'", "ButtonPress"));
|
||||
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
|
||||
auto eventData = MouseButtonDownEvent(button);
|
||||
eventData.Button = button;
|
||||
@@ -125,12 +159,20 @@ void RWindow::pollEvents() {
|
||||
OnMouseButtonDown(eventData);
|
||||
}
|
||||
|
||||
if (xev.type == Expose) {}
|
||||
if (xev.type == Expose)
|
||||
{
|
||||
DEBUG(std::format("Recieved 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 (xev.type == MotionNotify)
|
||||
{
|
||||
DEBUG("NOTE: This event is functionally useless, as it only informs of the very beginning and end of a mouse movement.");
|
||||
DEBUG(std::format("Recieved event '{}'", "MotionNotify"));
|
||||
}
|
||||
|
||||
if (xev.type == ResizeRequest) {
|
||||
DEBUG(std::format("Recieved event '{}'", "ResizeRequest"));
|
||||
auto eventData = WindowResizeRequestEvent();
|
||||
lastKnownWindowSize = eventData.Size;
|
||||
eventData.Size = {(float)xev.xresizerequest.width, (float)xev.xresizerequest.height};
|
||||
@@ -149,6 +191,8 @@ void RWindow::pollEvents() {
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
XResizeWindow(display, window, width, height);
|
||||
DEBUG("Might make the window go off the screen on some window managers.");
|
||||
DEBUG(std::format("Set size for window '{}'. width={} height={}", this->title, newWidth, newHeight));
|
||||
}
|
||||
|
||||
Vector2 RWindow::getCursorPos() const {
|
||||
@@ -208,6 +252,7 @@ void RWindow::pollEvents() {
|
||||
}
|
||||
|
||||
void RWindow::fullscreen() {
|
||||
DEBUG(std::format("Fullscreening window '{}'", this->title));
|
||||
fullscreenmode = true;
|
||||
|
||||
XEvent xev;
|
||||
@@ -224,9 +269,11 @@ void RWindow::pollEvents() {
|
||||
xev.xclient.data.l[1] = fullscreenmode;
|
||||
xev.xclient.data.l[2] = 0;
|
||||
XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
DEBUG(std::format("Fullscreened window '{}'", this->title));
|
||||
}
|
||||
|
||||
void RWindow::restoreFromFullscreen() {
|
||||
DEBUG(std::format("Restoring window '{}' from fullscreen", this->title));
|
||||
fullscreenmode = false;
|
||||
XEvent xev;
|
||||
Atom wm_state = XInternAtom(display, "_NET_WM_STATE", False);
|
||||
@@ -240,6 +287,7 @@ void RWindow::pollEvents() {
|
||||
xev.xclient.data.l[1] = fullscreenmode;
|
||||
xev.xclient.data.l[2] = 0;
|
||||
XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
DEBUG(std::format("Restored window '{}' from fullscreen", this->title));
|
||||
}
|
||||
|
||||
void RWindow::setVsyncEnabled(bool b) {
|
||||
|
Reference in New Issue
Block a user