From 5b551d13af71125629aa59448a36a9db6d520367 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 22 Nov 2021 22:37:01 +0100 Subject: [PATCH] some checks, todo fix randr --- src/KeybindManager.cpp | 6 ------ src/bar/Bar.cpp | 4 ++-- src/defines.hpp | 14 +++++++++++++- src/events/events.cpp | 4 ++++ src/main.cpp | 5 +++++ src/windowManager.cpp | 33 ++++++++++++++++++++++++++++++++- 6 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/KeybindManager.cpp b/src/KeybindManager.cpp index 4c2b2ea..b3de7a9 100644 --- a/src/KeybindManager.cpp +++ b/src/KeybindManager.cpp @@ -112,12 +112,6 @@ void KeybindManager::changeworkspace(std::string arg) { Debug::log(LOG, "Changing the current workspace to " + std::to_string(ID)); const auto PLASTWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow); - SMonitor* MONITOR = nullptr; - if (PLASTWINDOW) { - MONITOR = g_pWindowManager->getMonitorFromWindow(PLASTWINDOW); - } else { - MONITOR = g_pWindowManager->getMonitorFromCursor(); - } g_pWindowManager->changeWorkspaceByID(ID); } diff --git a/src/bar/Bar.cpp b/src/bar/Bar.cpp index d3c0d9b..48a22df 100644 --- a/src/bar/Bar.cpp +++ b/src/bar/Bar.cpp @@ -87,8 +87,8 @@ void CStatusBar::setup(int MonitorID) { // Set the bar to be top - values[0] = XCB_STACK_MODE_ABOVE; - xcb_configure_window(g_pWindowManager->DisplayConnection, m_iWindowID, XCB_CONFIG_WINDOW_STACK_MODE, values); + //values[0] = XCB_STACK_MODE_ABOVE; + //xcb_configure_window(g_pWindowManager->DisplayConnection, m_iWindowID, XCB_CONFIG_WINDOW_STACK_MODE, values); } void CStatusBar::destroy() { diff --git a/src/defines.hpp b/src/defines.hpp index 3ced79d..df3b246 100644 --- a/src/defines.hpp +++ b/src/defines.hpp @@ -27,4 +27,16 @@ #define STICKS(a, b) abs((a) - (b)) < 2 -#define VECINRECT(vec, x1, y1, x2, y2) (vec.x >= (x1) && vec.x <= (x2) && vec.y >= (y1) && vec.y <= (y2)) \ No newline at end of file +#define VECINRECT(vec, x1, y1, x2, y2) (vec.x >= (x1) && vec.x <= (x2) && vec.y >= (y1) && vec.y <= (y2)) + +#define XCBQUERYCHECK(name, query, errormsg) \ + xcb_generic_error_t* error; \ + const auto name = query; \ + \ + if (error != NULL) { \ + Debug::log(ERR, errormsg); \ + free(error); \ + free(name); \ + return; \ + } \ + free(error); diff --git a/src/events/events.cpp b/src/events/events.cpp index fa31b7c..0a89b80 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -53,6 +53,10 @@ CWindow* Events::remapWindow(int windowID, bool wasfloating) { window.setDrawable(windowID); window.setIsFloating(false); window.setDirty(true); + if (!g_pWindowManager->getMonitorFromCursor()) { + Debug::log(ERR, "Monitor was null! (remapWindow)"); + // rip! we cannot continue. + } const auto CURRENTSCREEN = g_pWindowManager->getMonitorFromCursor()->ID; window.setWorkspaceID(g_pWindowManager->activeWorkspaces[CURRENTSCREEN]); window.setMonitor(CURRENTSCREEN); diff --git a/src/main.cpp b/src/main.cpp index fb1e7ba..f435ab8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,11 @@ int main(int argc, char** argv) { g_pWindowManager->Screen = xcb_setup_roots_iterator(xcb_get_setup(g_pWindowManager->DisplayConnection)).data; + if (!g_pWindowManager->Screen) { + Debug::log(CRIT, "Screen was null!"); + return 1; + } + g_pWindowManager->setupManager(); Debug::log(LOG, "Hypr Started!"); diff --git a/src/windowManager.cpp b/src/windowManager.cpp index bf62da1..d08e05c 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -16,6 +16,18 @@ xcb_visualtype_t* CWindowManager::setupColors() { } void CWindowManager::setupRandrMonitors() { + + // TODO: this stopped working on my machine for some reason. + // i3 works though...? + + // finds 0 monitors + + XCBQUERYCHECK(RANDRVER, xcb_randr_query_version_reply( + DisplayConnection, xcb_randr_query_version(DisplayConnection, XCB_RANDR_MAJOR_VERSION, XCB_RANDR_MINOR_VERSION), &error), "RandR query failed!" ); + + + free(RANDRVER); + auto ScreenResReply = xcb_randr_get_screen_resources_current_reply(DisplayConnection, xcb_randr_get_screen_resources_current(DisplayConnection, Screen->root), NULL); if (!ScreenResReply) { Debug::log(ERR, "ScreenResReply NULL!"); @@ -65,6 +77,8 @@ void CWindowManager::setupRandrMonitors() { //listen for screen change events xcb_randr_select_input(DisplayConnection, Screen->root, XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE); } + + xcb_flush(DisplayConnection); } void CWindowManager::setupManager() { @@ -74,7 +88,7 @@ void CWindowManager::setupManager() { // RandR failed! Debug::log(WARN, "RandR failed!"); - #define TESTING_MON_AMOUNT 3 + #define TESTING_MON_AMOUNT 1 for (int i = 0; i < TESTING_MON_AMOUNT /* Testing on 3 monitors, RandR shouldnt fail on a real desktop */; ++i) { monitors.push_back(SMonitor()); monitors[i].vecPosition = Vector2D(i * Screen->width_in_pixels / TESTING_MON_AMOUNT, 0); @@ -445,6 +459,11 @@ void CWindowManager::calculateNewTileSetOldTile(CWindow* pWindow) { // New window on this workspace. // Open a fullscreen window. const auto MONITOR = getMonitorFromCursor(); + if (!MONITOR) { + Debug::log(ERR, "Monitor was nullptr! (calculateNewTileSetOldTile)"); + return; + } + pWindow->setSize(Vector2D(MONITOR->vecSize.x, MONITOR->vecSize.y)); pWindow->setPosition(Vector2D(MONITOR->vecPosition.x, MONITOR->vecPosition.y)); @@ -678,6 +697,7 @@ void CWindowManager::warpCursorTo(Vector2D to) { xcb_query_pointer_reply_t* pointerreply = xcb_query_pointer_reply(DisplayConnection, POINTERCOOKIE, NULL); if (!pointerreply) { Debug::log(ERR, "Couldn't query pointer."); + free(pointerreply); return; } @@ -717,6 +737,11 @@ void CWindowManager::changeWorkspaceByID(int ID) { const auto MONITOR = getMonitorFromCursor(); + if (!MONITOR) { + Debug::log(ERR, "Monitor was nullptr! (changeWorkspaceByID)"); + return; + } + // mark old workspace dirty setAllWorkspaceWindowsDirtyByID(activeWorkspaces[MONITOR->ID]); @@ -816,6 +841,7 @@ Vector2D CWindowManager::getCursorPos() { xcb_query_pointer_reply_t* pointerreply = xcb_query_pointer_reply(DisplayConnection, POINTERCOOKIE, NULL); if (!pointerreply) { Debug::log(ERR, "Couldn't query pointer."); + free(pointerreply); return Vector2D(0,0); } @@ -843,5 +869,10 @@ void CWindowManager::updateBarInfo() { std::sort(statusBar.openWorkspaces.begin(), statusBar.openWorkspaces.end()); + if (!getMonitorFromCursor()) { + Debug::log(ERR, "Monitor was null! (updateBarInfo)"); + return; + } + statusBar.setCurrentWorkspace(activeWorkspaces[getMonitorFromCursor()->ID]); } \ No newline at end of file