multimon patches

This commit is contained in:
vaxerski 2021-11-21 19:59:59 +01:00
parent abc4c6d36e
commit 5153db3934
7 changed files with 74 additions and 52 deletions

View file

@ -86,16 +86,13 @@ void KeybindManager::killactive(std::string args) {
void KeybindManager::call(std::string args) { void KeybindManager::call(std::string args) {
if (fork() == 0) { if (fork() == 0) {
setsid(); //setsid();
if (fork() != 0) {
_exit(0);
}
execl("/bin/sh", "/bin/sh", "-c", args.c_str(), nullptr); execl("/bin/sh", "/bin/sh", "-c", args.c_str(), nullptr);
_exit(0); _exit(0);
} }
wait(NULL); //wait(NULL);
} }
void KeybindManager::movewindow(std::string arg) { void KeybindManager::movewindow(std::string arg) {
@ -119,8 +116,8 @@ void KeybindManager::changeworkspace(std::string arg) {
MONITOR = g_pWindowManager->getMonitorFromCursor(); MONITOR = g_pWindowManager->getMonitorFromCursor();
} }
// vvvv shouldn't be nullptr wallah
g_pWindowManager->setAllWorkspaceWindowsDirtyByID(g_pWindowManager->activeWorkspaces[MONITOR->ID]->getID()); g_pWindowManager->setAllWorkspaceWindowsDirtyByID(g_pWindowManager->activeWorkspaces[MONITOR->ID]);
g_pWindowManager->changeWorkspaceByID(ID); g_pWindowManager->changeWorkspaceByID(ID);
g_pWindowManager->setAllWorkspaceWindowsDirtyByID(ID); g_pWindowManager->setAllWorkspaceWindowsDirtyByID(ID);
} }
@ -129,11 +126,11 @@ void KeybindManager::changeworkspace(std::string arg) {
void KeybindManager::toggleActiveWindowFullscreen(std::string unusedArg) { void KeybindManager::toggleActiveWindowFullscreen(std::string unusedArg) {
const auto MONITOR = g_pWindowManager->getMonitorFromWindow(g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow)); const auto MONITOR = g_pWindowManager->getMonitorFromWindow(g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow));
g_pWindowManager->setAllWorkspaceWindowsDirtyByID(g_pWindowManager->activeWorkspaces[MONITOR->ID]->getID()); g_pWindowManager->setAllWorkspaceWindowsDirtyByID(g_pWindowManager->activeWorkspaces[MONITOR->ID]);
if (auto WINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow) ; WINDOW) { if (auto WINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow) ; WINDOW) {
WINDOW->setFullscreen(!WINDOW->getFullscreen()); WINDOW->setFullscreen(!WINDOW->getFullscreen());
g_pWindowManager->activeWorkspaces[MONITOR->ID]->setHasFullscreenWindow(WINDOW->getFullscreen()); g_pWindowManager->getWorkspaceByID(g_pWindowManager->activeWorkspaces[MONITOR->ID])->setHasFullscreenWindow(WINDOW->getFullscreen());
} }
} }

View file

@ -123,7 +123,9 @@ int getTextWidth(std::string text, xcb_font_t font) {
void CStatusBar::draw() { void CStatusBar::draw() {
if (g_pWindowManager->activeWorkspaces[m_iMonitorID]->getHasFullscreenWindow()) const auto WORKSPACE = g_pWindowManager->getWorkspaceByID(g_pWindowManager->activeWorkspaces[m_iMonitorID]);
if (WORKSPACE->getHasFullscreenWindow())
return; // Do not draw a bar on a fullscreen window. return; // Do not draw a bar on a fullscreen window.
xcb_rectangle_t rectangles[] = {{m_vecPosition.x, m_vecPosition.y, m_vecSize.x + m_vecPosition.x, m_vecPosition.y + m_vecSize.y}}; xcb_rectangle_t rectangles[] = {{m_vecPosition.x, m_vecPosition.y, m_vecSize.x + m_vecPosition.x, m_vecPosition.y + m_vecSize.y}};
@ -140,13 +142,13 @@ void CStatusBar::draw() {
std::string workspaceName = std::to_string(i); std::string workspaceName = std::to_string(i);
if (WORKSPACE->getID() == g_pWindowManager->activeWorkspaces[m_iMonitorID]->getID()) { if (WORKSPACE->getID() == g_pWindowManager->activeWorkspaces[m_iMonitorID]) {
xcb_rectangle_t rectangleActive[] = { { m_vecSize.y * drawnWorkspaces, 0, m_vecSize.y, m_vecSize.y } }; xcb_rectangle_t rectangleActive[] = { { m_vecSize.y * drawnWorkspaces, 0, m_vecSize.y, m_vecSize.y } };
xcb_poly_fill_rectangle(g_pWindowManager->DisplayConnection, m_iPixmap, m_mContexts["MEDBG"].GContext, 1, rectangleActive); xcb_poly_fill_rectangle(g_pWindowManager->DisplayConnection, m_iPixmap, m_mContexts["MEDBG"].GContext, 1, rectangleActive);
} }
xcb_image_text_8(g_pWindowManager->DisplayConnection, workspaceName.length(), m_iPixmap, xcb_image_text_8(g_pWindowManager->DisplayConnection, workspaceName.length(), m_iPixmap,
WORKSPACE->getID() == g_pWindowManager->activeWorkspaces[m_iMonitorID]->getID() ? m_mContexts["HITEXT"].GContext : m_mContexts["BASETEXT"].GContext, WORKSPACE->getID() == g_pWindowManager->activeWorkspaces[m_iMonitorID] ? m_mContexts["HITEXT"].GContext : m_mContexts["BASETEXT"].GContext,
m_vecSize.y * drawnWorkspaces + m_vecSize.y / 2.f - 2, m_vecSize.y - (m_vecSize.y - 10) / 2, workspaceName.c_str()); m_vecSize.y * drawnWorkspaces + m_vecSize.y / 2.f - 2, m_vecSize.y - (m_vecSize.y - 10) / 2, workspaceName.c_str());
drawnWorkspaces++; drawnWorkspaces++;

View file

@ -16,7 +16,7 @@ void ConfigManager::init() {
configValues["bar_height"].intValue = 15; configValues["bar_height"].intValue = 15;
configValues["max_fps"].intValue = 60; configValues["max_fps"].intValue = 60;
ConfigManager::loadConfigLoadVars(); loadConfigLoadVars();
} }
void handleBind(const std::string& command, const std::string& value) { void handleBind(const std::string& command, const std::string& value) {
@ -139,9 +139,13 @@ void ConfigManager::loadConfigLoadVars() {
g_pWindowManager->setAllWindowsDirty(); g_pWindowManager->setAllWindowsDirty();
// Reload the bar as well // Reload the bar as well, don't load it before the default is loaded.
g_pWindowManager->statusBar.destroy(); if (loadBar) {
g_pWindowManager->statusBar.setup(Vector2D(-1,-1), Vector2D(g_pWindowManager->Screen->width_in_pixels, configValues["bar_height"].intValue)); g_pWindowManager->statusBar.destroy();
g_pWindowManager->statusBar.setup(Vector2D(-1, -1), Vector2D(g_pWindowManager->monitors[g_pWindowManager->statusBar.getMonitorID()].vecSize.x, configValues["bar_height"].intValue));
}
loadBar = true;
} }
void emptyEvent() { void emptyEvent() {

View file

@ -13,6 +13,8 @@ namespace ConfigManager {
inline std::map<std::string_view, SConfigValue> configValues; inline std::map<std::string_view, SConfigValue> configValues;
inline time_t lastModifyTime = 0; inline time_t lastModifyTime = 0;
inline bool loadBar = false;
void init(); void init();
void loadConfigLoadVars(); void loadConfigLoadVars();
void tick(); void tick();

View file

@ -63,7 +63,7 @@ void Events::eventMapWindow(xcb_generic_event_t* event) {
window.setIsFloating(false); window.setIsFloating(false);
window.setDirty(true); window.setDirty(true);
const auto CURRENTSCREEN = g_pWindowManager->getMonitorFromCursor()->ID; const auto CURRENTSCREEN = g_pWindowManager->getMonitorFromCursor()->ID;
window.setWorkspaceID(g_pWindowManager->activeWorkspaces[CURRENTSCREEN]->getID()); window.setWorkspaceID(g_pWindowManager->activeWorkspaces[CURRENTSCREEN]);
window.setMonitor(CURRENTSCREEN); window.setMonitor(CURRENTSCREEN);
window.setDefaultPosition(Vector2D(0,0)); window.setDefaultPosition(Vector2D(0,0));
@ -96,6 +96,8 @@ void Events::eventButtonPress(xcb_generic_event_t* event) {
for (auto& keybind : KeybindManager::keybinds) { for (auto& keybind : KeybindManager::keybinds) {
if (keybind.getKeysym() != 0 && keybind.getKeysym() == KEYSYM && KeybindManager::modToMask(keybind.getMod()) == E->state) { if (keybind.getKeysym() != 0 && keybind.getKeysym() == KEYSYM && KeybindManager::modToMask(keybind.getMod()) == E->state) {
keybind.getDispatcher()(keybind.getCommand()); keybind.getDispatcher()(keybind.getCommand());
return;
// TODO: fix duplicating keybinds
} }
} }
} }

View file

@ -22,17 +22,19 @@ void CWindowManager::setupRandrMonitors() {
return; return;
} }
Debug::log(LOG, "Setting up RandR!");
const auto MONITORNUM = xcb_randr_get_screen_resources_current_outputs_length(ScreenResReply); const auto MONITORNUM = xcb_randr_get_screen_resources_current_outputs_length(ScreenResReply);
auto OUTPUTS = xcb_randr_get_screen_resources_current_outputs(ScreenResReply); auto OUTPUTS = xcb_randr_get_screen_resources_current_outputs(ScreenResReply);
xcb_randr_get_output_info_reply_t* outputReply; xcb_randr_get_output_info_reply_t* outputReply;
xcb_randr_get_crtc_info_reply_t* crtcReply; xcb_randr_get_crtc_info_reply_t* crtcReply;
Debug::log(LOG, "Monitors found: " + std::to_string(MONITORNUM));
for (int i = 0; i < MONITORNUM; i++) { for (int i = 0; i < MONITORNUM; i++) {
outputReply = xcb_randr_get_output_info_reply(DisplayConnection, xcb_randr_get_output_info(DisplayConnection, OUTPUTS[i], XCB_CURRENT_TIME), NULL); outputReply = xcb_randr_get_output_info_reply(DisplayConnection, xcb_randr_get_output_info(DisplayConnection, OUTPUTS[i], XCB_CURRENT_TIME), NULL);
if (outputReply->crtc == XCB_NONE) if (!outputReply || outputReply->crtc == XCB_NONE)
continue; continue;
crtcReply = xcb_randr_get_crtc_info_reply(DisplayConnection, xcb_randr_get_crtc_info(DisplayConnection, outputReply->crtc, XCB_CURRENT_TIME), NULL); crtcReply = xcb_randr_get_crtc_info_reply(DisplayConnection, xcb_randr_get_crtc_info(DisplayConnection, outputReply->crtc, XCB_CURRENT_TIME), NULL);
if (!crtcReply) if (!crtcReply)
@ -40,17 +42,20 @@ void CWindowManager::setupRandrMonitors() {
monitors.push_back(SMonitor()); monitors.push_back(SMonitor());
monitors[i].vecPosition = Vector2D(crtcReply->x, crtcReply->y); monitors[monitors.size() - 1].vecPosition = Vector2D(crtcReply->x, crtcReply->y);
monitors[i].vecSize = Vector2D(crtcReply->width, crtcReply->height); monitors[monitors.size() - 1].vecSize = Vector2D(crtcReply->width == 0 ? 1920 : crtcReply->width, crtcReply->height);
monitors[i].ID = i; monitors[monitors.size() - 1].ID = i;
char* name = (char*)xcb_randr_get_output_info_name(outputReply); char* name = (char*)xcb_randr_get_output_info_name(outputReply);
int nameLen = xcb_randr_get_output_info_name_length(outputReply); int nameLen = xcb_randr_get_output_info_name_length(outputReply);
for (int j = 0; j < nameLen; ++j) { for (int j = 0; j < nameLen; ++j) {
monitors[i].szName += name[j]; monitors[monitors.size() - 1].szName += name[j];
} }
Debug::log(NONE, "Monitor " + monitors[monitors.size() - 1].szName + ": " + std::to_string(monitors[i].vecSize.x) + "x" + std::to_string(monitors[monitors.size() - 1].vecSize.y) +
", at " + std::to_string(monitors[monitors.size() - 1].vecPosition.x) + "," + std::to_string(monitors[monitors.size() - 1].vecSize.y));
} }
const auto EXTENSIONREPLY = xcb_get_extension_data(DisplayConnection, &xcb_randr_id); const auto EXTENSIONREPLY = xcb_get_extension_data(DisplayConnection, &xcb_randr_id);
@ -63,29 +68,32 @@ void CWindowManager::setupRandrMonitors() {
} }
void CWindowManager::setupManager() { void CWindowManager::setupManager() {
ConfigManager::init();
setupRandrMonitors(); setupRandrMonitors();
ConfigManager::init();
if (monitors.size() == 0) { if (monitors.size() == 0) {
// RandR failed! // RandR failed!
Debug::log(WARN, "RandR failed!"); Debug::log(WARN, "RandR failed!");
monitors.push_back(SMonitor()); monitors.push_back(SMonitor());
monitors[0].vecPosition = Vector2D(0,0); monitors[0].vecPosition = Vector2D(0, 0);
monitors[0].vecSize = Vector2D(Screen->width_in_pixels, Screen->height_in_pixels); monitors[0].vecSize = Vector2D(Screen->width_in_pixels / 2.f, Screen->height_in_pixels);
monitors[0].ID = 0; monitors[0].ID = 0;
monitors[0].szName = "Screen"; monitors[0].szName = "Screen";
monitors.push_back(SMonitor());
monitors[1].vecPosition = Vector2D(Screen->width_in_pixels / 2.f, 0);
monitors[1].vecSize = Vector2D(Screen->width_in_pixels / 2.f, Screen->height_in_pixels);
monitors[1].ID = 1;
monitors[1].szName = "Screen2";
} }
// TODO: get it normally. // TODO: get it normally.
if (monitors.size() > 1) { monitors[0].primary = true;
monitors[1].primary = true; monitors[0].hasABar = true;
monitors[1].hasABar = true;
} else {
monitors[0].primary = true;
monitors[0].hasABar = true;
}
Debug::log(LOG, "RandR done.");
Values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE; Values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE;
xcb_change_window_attributes_checked(DisplayConnection, Screen->root, xcb_change_window_attributes_checked(DisplayConnection, Screen->root,
@ -112,14 +120,19 @@ void CWindowManager::setupManager() {
xcb_flush(DisplayConnection); xcb_flush(DisplayConnection);
Debug::log(LOG, "Keys done.");
// Add workspaces to the monitors // Add workspaces to the monitors
for (int i = 0; i < monitors.size(); ++i) { for (int i = 0; i < monitors.size(); ++i) {
CWorkspace protoWorkspace; CWorkspace protoWorkspace;
protoWorkspace.setID(i + 1); protoWorkspace.setID(i + 1);
protoWorkspace.setMonitor(i); protoWorkspace.setMonitor(i);
protoWorkspace.setHasFullscreenWindow(false);
workspaces.push_back(protoWorkspace); workspaces.push_back(protoWorkspace);
activeWorkspaces.push_back(&workspaces[i]); activeWorkspaces.push_back(workspaces[i].getID());
} }
Debug::log(LOG, "Workspace protos done.");
// //
// init visual type, default 32 bit depth // init visual type, default 32 bit depth
@ -135,13 +148,20 @@ void CWindowManager::setupManager() {
for (auto& monitor : monitors) { for (auto& monitor : monitors) {
if (monitor.primary) { if (monitor.primary) {
statusBar.setup(Vector2D(monitor.vecPosition.x, monitor.vecPosition.y), Vector2D(monitor.vecSize.x, ConfigManager::getInt("bar_height"))); const Vector2D BARSIZE = Vector2D(monitor.vecSize.x, ConfigManager::getInt("bar_height"));
statusBar.setup(monitor.vecPosition, BARSIZE);
statusBar.setMonitorID(monitor.ID); statusBar.setMonitorID(monitor.ID);
} }
} }
// start its' update thread // start its' update thread
Events::setThread(); Events::setThread();
Debug::log(LOG, "Bar done.");
ConfigManager::loadConfigLoadVars();
Debug::log(LOG, "Finished setup!");
} }
bool CWindowManager::handleEvent() { bool CWindowManager::handleEvent() {
@ -392,7 +412,7 @@ CWindow* CWindowManager::findWindowAtCursor() {
const auto WORKSPACE = activeWorkspaces[getMonitorFromCursor()->ID]; const auto WORKSPACE = activeWorkspaces[getMonitorFromCursor()->ID];
for (auto& window : windows) { for (auto& window : windows) {
if (window.getWorkspaceID() == WORKSPACE->getID() && !window.getIsFloating()) { if (window.getWorkspaceID() == WORKSPACE && !window.getIsFloating()) {
if (cursorPos.x >= window.getPosition().x if (cursorPos.x >= window.getPosition().x
&& cursorPos.x <= window.getPosition().x + window.getSize().x && cursorPos.x <= window.getPosition().x + window.getSize().x
@ -546,7 +566,7 @@ void CWindowManager::fixWindowOnClose(CWindow* pClosedWindow) {
// Fix if was fullscreen // Fix if was fullscreen
if (pClosedWindow->getFullscreen()) if (pClosedWindow->getFullscreen())
WORKSPACE->setHasFullscreenWindow(false); g_pWindowManager->getWorkspaceByID(WORKSPACE)->setHasFullscreenWindow(false);
// get the first neighboring window // get the first neighboring window
CWindow* neighbor = nullptr; CWindow* neighbor = nullptr;
@ -656,19 +676,14 @@ void CWindowManager::moveActiveWindowTo(char dir) {
void CWindowManager::changeWorkspaceByID(int ID) { void CWindowManager::changeWorkspaceByID(int ID) {
const auto MONITOR = getMonitorFromCursor(); const auto MONITOR = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow)
? g_pWindowManager->getMonitorFromWindow(g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow)) : getMonitorFromCursor();
for (auto& workspace : workspaces) { for (auto& workspace : workspaces) {
if (workspace.getID() == ID) { if (workspace.getID() == ID) {
if (workspace.getMonitor() == MONITOR->ID) { activeWorkspaces[workspace.getMonitor()] = workspace.getID();
activeWorkspaces[MONITOR->ID] = &workspace; LastWindow = -1;
LastWindow = -1; return;
return;
} else {
activeWorkspaces[workspace.getMonitor()] = &workspace;
LastWindow = -1;
return;
}
} }
} }
@ -677,7 +692,7 @@ void CWindowManager::changeWorkspaceByID(int ID) {
newWorkspace.setID(ID); newWorkspace.setID(ID);
newWorkspace.setMonitor(MONITOR->ID); newWorkspace.setMonitor(MONITOR->ID);
workspaces.push_back(newWorkspace); workspaces.push_back(newWorkspace);
activeWorkspaces[MONITOR->ID] = &workspaces[workspaces.size() - 1]; activeWorkspaces[MONITOR->ID] = workspaces[workspaces.size() - 1].getID();
LastWindow = -1; LastWindow = -1;
} }
@ -754,7 +769,7 @@ SMonitor* CWindowManager::getMonitorFromCursor() {
bool CWindowManager::isWorkspaceVisible(int workspaceID) { bool CWindowManager::isWorkspaceVisible(int workspaceID) {
for (auto& workspace : activeWorkspaces) { for (auto& workspace : activeWorkspaces) {
if (workspace->getID() == workspaceID) if (workspace == workspaceID)
return true; return true;
} }

View file

@ -32,7 +32,7 @@ public:
xcb_drawable_t LastWindow = -1; xcb_drawable_t LastWindow = -1;
std::vector<CWorkspace> workspaces; std::vector<CWorkspace> workspaces;
std::vector<CWorkspace*> activeWorkspaces; std::vector<int> activeWorkspaces;
CStatusBar statusBar; CStatusBar statusBar;
std::thread* barThread; std::thread* barThread;