some checks, todo fix randr

This commit is contained in:
vaxerski 2021-11-22 22:37:01 +01:00
parent 7b7ba35b0c
commit 5b551d13af
6 changed files with 56 additions and 10 deletions

View File

@ -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);
}

View File

@ -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() {

View File

@ -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))
#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);

View File

@ -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);

View File

@ -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!");

View File

@ -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]);
}