From 92492c3ffe70c087954fe406fa60ee0f1df1e0b1 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 18 Nov 2021 22:08:28 +0100 Subject: [PATCH] added borders --- src/events/events.cpp | 6 +++++ src/events/events.hpp | 1 + src/window.hpp | 2 ++ src/windowManager.cpp | 56 +++++++++++++++++++++++++++++++++++++++---- src/windowManager.hpp | 6 +++++ 5 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/events/events.cpp b/src/events/events.cpp index 9d47841..688d1b7 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -10,6 +10,12 @@ void Events::eventEnter(xcb_generic_event_t* event) { WindowManager::getWindowFromDrawable(E->event)->setDirty(true); } +void Events::eventLeave(xcb_generic_event_t* event) { + const auto E = reinterpret_cast(event); + + // +} + void Events::eventDestroy(xcb_generic_event_t* event) { const xcb_destroy_notify_event_t* E = reinterpret_cast(event); xcb_kill_client(WindowManager::DisplayConnection, E->window); diff --git a/src/events/events.hpp b/src/events/events.hpp index a7547f5..80ca4b0 100644 --- a/src/events/events.hpp +++ b/src/events/events.hpp @@ -3,6 +3,7 @@ namespace Events { EVENT(Enter); + EVENT(Leave); EVENT(Destroy); EVENT(MapWindow); }; \ No newline at end of file diff --git a/src/window.hpp b/src/window.hpp index f881a73..c1a3d99 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -19,6 +19,8 @@ public: EXPOSED_MEMBER(Dirty, bool, b); EXPOSED_MEMBER(Size, Vector2D, vec); + EXPOSED_MEMBER(EffectiveSize, Vector2D, vec); + EXPOSED_MEMBER(EffectivePosition, Vector2D, vec); EXPOSED_MEMBER(Position, Vector2D, vec); EXPOSED_MEMBER(IsFloating, bool, b); EXPOSED_MEMBER(Drawable, xcb_drawable_t, i); diff --git a/src/windowManager.cpp b/src/windowManager.cpp index a557697..85eb542 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -33,6 +33,10 @@ bool WindowManager::handleEvent() { Events::eventEnter(ev); Debug::log(LOG, "Event dispatched ENTER"); break; + case XCB_LEAVE_NOTIFY: + Events::eventLeave(ev); + Debug::log(LOG, "Event dispatched LEAVE"); + break; case XCB_DESTROY_NOTIFY: Events::eventDestroy(ev); Debug::log(LOG, "Event dispatched DESTROY"); @@ -61,14 +65,35 @@ bool WindowManager::handleEvent() { void WindowManager::refreshDirtyWindows() { for(auto& window : windows) { if (window.getDirty()) { - Values[0] = (int)window.getSize().x; - Values[1] = (int)window.getSize().y; + Values[0] = (int)window.getEffectiveSize().x; + Values[1] = (int)window.getEffectiveSize().y; xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values); - Values[0] = (int)window.getPosition().x; - Values[1] = (int)window.getPosition().y; + Values[0] = (int)window.getEffectivePosition().x; + Values[1] = (int)window.getEffectivePosition().y; xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values); + // Focused special border. + if (window.getDrawable() == WindowManager::LastWindow) { + Values[0] = (int)BORDERSIZE; + xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_BORDER_WIDTH, Values); + + // Update the position because the border makes the window jump + // I have added the bordersize vec2d before in the setEffectiveSizePosUsingConfig function. + Values[0] = (int)window.getEffectivePosition().x - BORDERSIZE; + Values[1] = (int)window.getEffectivePosition().y - BORDERSIZE; + xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values); + + Values[0] = 0xFF3333; // RED :) + xcb_change_window_attributes(WindowManager::DisplayConnection, window.getDrawable(), XCB_CW_BORDER_PIXEL, Values); + } else { + Values[0] = 0; + xcb_configure_window(WindowManager::DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_BORDER_WIDTH, Values); + + Values[0] = 0x555555; // GRAY :) + xcb_change_window_attributes(WindowManager::DisplayConnection, window.getDrawable(), XCB_CW_BORDER_PIXEL, Values); + } + window.setDirty(false); Debug::log(LOG, "Refreshed dirty window."); @@ -79,6 +104,11 @@ void WindowManager::refreshDirtyWindows() { void WindowManager::setFocusedWindow(xcb_drawable_t window) { if (window && window != WindowManager::Screen->root) { xcb_set_input_focus(WindowManager::DisplayConnection, XCB_INPUT_FOCUS_POINTER_ROOT, window, XCB_CURRENT_TIME); + + // Fix border from the old window that was in focus. + if (const auto PLASTWINDOW = WindowManager::getWindowFromDrawable(WindowManager::LastWindow); PLASTWINDOW) + PLASTWINDOW->setDirty(true); + WindowManager::LastWindow = window; } } @@ -120,6 +150,17 @@ void WindowManager::removeWindowFromVectorSafe(xcb_drawable_t window) { } } +void setEffectiveSizePosUsingConfig(CWindow* pWindow) { + // for now only border. + // todo: gaps. + + if (!pWindow) + return; + + pWindow->setEffectivePosition(pWindow->getPosition() + Vector2D(BORDERSIZE, BORDERSIZE)); + pWindow->setEffectiveSize(pWindow->getSize() - (Vector2D(BORDERSIZE, BORDERSIZE) * 2)); +} + void calculateNewTileSetOldTile(CWindow* pWindow) { const auto PLASTWINDOW = WindowManager::getWindowFromDrawable(WindowManager::LastWindow); if (PLASTWINDOW) { @@ -142,6 +183,9 @@ void calculateNewTileSetOldTile(CWindow* pWindow) { pWindow->setSize(Vector2D(WindowManager::Screen->width_in_pixels, WindowManager::Screen->height_in_pixels)); pWindow->setPosition(Vector2D(0, 0)); } + + setEffectiveSizePosUsingConfig(pWindow); + setEffectiveSizePosUsingConfig(PLASTWINDOW); } void WindowManager::calculateNewWindowParams(CWindow* pWindow) { @@ -218,9 +262,11 @@ void WindowManager::fixWindowOnClose(CWindow* pClosedWindow) { if (!neighbor) return; // No neighbor. Don't update, easy. - // update neighbor to "eat" closed. eatWindow(neighbor, pClosedWindow); neighbor->setDirty(true); + WindowManager::setFocusedWindow(neighbor->getDrawable()); // Set focus. :) + + setEffectiveSizePosUsingConfig(neighbor); } \ No newline at end of file diff --git a/src/windowManager.hpp b/src/windowManager.hpp index 042ed27..7bea7a5 100644 --- a/src/windowManager.hpp +++ b/src/windowManager.hpp @@ -5,6 +5,12 @@ #include + +// temp config values +#define BORDERSIZE 1 +#define GAPS_IN 10 +#define GAPS_OUT 20 + namespace WindowManager { inline xcb_connection_t* DisplayConnection; inline xcb_screen_t* Screen;