From 1a05147c925ebc8aaac575fb0e5cdf883ace89a1 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 29 Nov 2021 21:51:01 +0100 Subject: [PATCH] Bar now fully works with transparency. --- CMakeLists.txt | 1 + src/bar/Bar.cpp | 11 ++++++---- src/windowManager.cpp | 47 +++++++++++++++++++++++++++---------------- src/windowManager.hpp | 4 +++- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d9b7817..28620fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,5 +32,6 @@ target_link_libraries(Hypr xcb-xinerama xcb-cursor xcb-shape + xcb-util ${CMAKE_THREAD_LIBS_INIT} ) \ No newline at end of file diff --git a/src/bar/Bar.cpp b/src/bar/Bar.cpp index fd42b36..1633c17 100644 --- a/src/bar/Bar.cpp +++ b/src/bar/Bar.cpp @@ -59,7 +59,7 @@ int64_t barMainThread() { g_pWindowManager->setupRandrMonitors(); // Init depth - g_pWindowManager->setupDepth(); + g_pWindowManager->setupColormapAndStuff(); // Setup our bar CStatusBar STATUSBAR; @@ -154,12 +154,15 @@ void CStatusBar::setup(int MonitorID) { message.windowID = m_iWindowID; IPCSendMessage(g_pWindowManager->m_sIPCBarPipeOut.szPipeName, message); - values[0] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE; + values[0] = ConfigManager::getInt("bar:col.bg"); + values[1] = ConfigManager::getInt("bar:col.bg"); + values[2] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE; + values[3] = g_pWindowManager->Colormap; xcb_create_window(g_pWindowManager->DisplayConnection, g_pWindowManager->Depth, m_iWindowID, g_pWindowManager->Screen->root, m_vecPosition.x, m_vecPosition.y, m_vecSize.x, m_vecSize.y, - 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, g_pWindowManager->Screen->root_visual, - XCB_CW_EVENT_MASK, values); + 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, g_pWindowManager->VisualType->visual_id, + XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP, values); // Set the state to dock to avoid some issues xcb_atom_t dockAtom[] = { HYPRATOMS["_NET_WM_WINDOW_TYPE_DOCK"] }; diff --git a/src/windowManager.cpp b/src/windowManager.cpp index ebb2223..95933bc 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -2,28 +2,26 @@ #include "./events/events.hpp" #include -xcb_visualtype_t* CWindowManager::setupColors() { +xcb_visualtype_t* CWindowManager::setupColors(const int& desiredDepth) { auto depthIter = xcb_screen_allowed_depths_iterator(Screen); - xcb_visualtype_iterator_t visualIter; - for (; depthIter.rem; xcb_depth_next(&depthIter)) { - if (depthIter.data->depth == Depth) { - visualIter = xcb_depth_visuals_iterator(depthIter.data); - return visualIter.data; + if (depthIter.data) { + for (; depthIter.rem; xcb_depth_next(&depthIter)) { + if (desiredDepth == 0 || desiredDepth == depthIter.data->depth) { + for (auto it = xcb_depth_visuals_iterator(depthIter.data); it.rem; xcb_visualtype_next(&it)) { + return it.data; + } + } + } + if (desiredDepth > 0) { + return setupColors(0); } } - return nullptr; } void CWindowManager::setupDepth() { - // init visual type, default 32 bit depth - // TODO: fix this, ugh - Depth = 24; //32 - VisualType = setupColors(); - if (VisualType == NULL) { - Depth = 24; - VisualType = setupColors(); - } + Depth = 24; + VisualType = setupColors(Depth); } void CWindowManager::createAndOpenAllPipes() { @@ -49,6 +47,22 @@ void CWindowManager::updateRootCursor() { xcb_change_window_attributes(DisplayConnection, Screen->root, XCB_CW_CURSOR, values); } +void CWindowManager::setupColormapAndStuff() { + VisualType = xcb_aux_find_visual_by_attrs(Screen, -1, 32); // Transparency by default + + Depth = xcb_aux_get_depth_of_visual(Screen, VisualType->visual_id); + Colormap = xcb_generate_id(DisplayConnection); + const auto COOKIE = xcb_create_colormap(DisplayConnection, XCB_COLORMAP_ALLOC_NONE, Colormap, Screen->root, VisualType->visual_id); + + const auto XERR = xcb_request_check(DisplayConnection, COOKIE); + + if (XERR != NULL) { + Debug::log(ERR, "Error in setupColormapAndStuff! Code: " + std::to_string(XERR->error_code)); + } + + free(XERR); +} + void CWindowManager::setupRandrMonitors() { XCBQUERYCHECK(RANDRVER, xcb_randr_query_version_reply( @@ -136,6 +150,7 @@ void CWindowManager::setupRandrMonitors() { } void CWindowManager::setupManager() { + setupColormapAndStuff(); EWMH::setupInitEWMH(); setupRandrMonitors(); @@ -162,8 +177,6 @@ void CWindowManager::setupManager() { Debug::log(LOG, "Workspace protos done."); // - setupDepth(); - // ---- INIT THE THREAD FOR ANIM & CONFIG ---- // // start its' update thread diff --git a/src/windowManager.hpp b/src/windowManager.hpp index f4543f7..52f8cfe 100644 --- a/src/windowManager.hpp +++ b/src/windowManager.hpp @@ -36,6 +36,7 @@ public: uint8_t Depth = 32; xcb_visualtype_t* VisualType; + xcb_colormap_t Colormap; std::vector windows; // windows never left. It has always been hiding amongst us. xcb_drawable_t LastWindow = -1; @@ -98,6 +99,7 @@ public: void setupRandrMonitors(); void createAndOpenAllPipes(); void setupDepth(); + void setupColormapAndStuff(); void updateActiveWindowName(); void updateBarInfo(); @@ -115,7 +117,7 @@ public: void calculateNewFloatingWindow(CWindow* pWindow); void setEffectiveSizePosUsingConfig(CWindow* pWindow); void cleanupUnusedWorkspaces(); - xcb_visualtype_t* setupColors(); + xcb_visualtype_t* setupColors(const int&); void updateRootCursor(); void applyRoundedCornersToWindow(CWindow* pWindow); };