From da349a03b225a20144fbee7df5d9b1107539cab5 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 1 Dec 2021 22:23:16 +0100 Subject: [PATCH] Added #12 Added %WINCLASS% to percent tokens --- src/bar/Bar.hpp | 1 + src/bar/BarCommands.cpp | 5 +++++ src/events/events.cpp | 8 ++++++++ src/ipc/ipc.cpp | 12 +++++------- src/ipc/ipc.hpp | 1 + src/window.hpp | 1 + src/windowManager.cpp | 12 ++++++++++++ 7 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/bar/Bar.hpp b/src/bar/Bar.hpp index 15c5f51..47c3a9f 100644 --- a/src/bar/Bar.hpp +++ b/src/bar/Bar.hpp @@ -43,6 +43,7 @@ public: EXPOSED_MEMBER(MonitorID, int, i); EXPOSED_MEMBER(StatusCommand, std::string, sz); // TODO: make the bar better EXPOSED_MEMBER(LastWindowName, std::string, sz); + EXPOSED_MEMBER(LastWindowClass, std::string, sz); EXPOSED_MEMBER(IsCovered, bool, b); void draw(); diff --git a/src/bar/BarCommands.cpp b/src/bar/BarCommands.cpp index 24fcc45..8ca68bb 100644 --- a/src/bar/BarCommands.cpp +++ b/src/bar/BarCommands.cpp @@ -108,12 +108,17 @@ std::string getCurrentWindowName() { return g_pWindowManager->statusBar->getLastWindowName(); } +std::string getCurrentWindowClass() { + return g_pWindowManager->statusBar->getLastWindowClass(); +} + std::string BarCommands::parsePercent(std::string token) { // check what the token is and act accordingly. if (token == "RAM") return getRamString(); else if (token == "CPU") return getCpuString(); else if (token == "WINNAME") return getCurrentWindowName(); + else if (token == "WINCLASS") return getCurrentWindowClass(); Debug::log(ERR, "Unknown token while parsing module: %" + token + "%"); diff --git a/src/events/events.cpp b/src/events/events.cpp index 759861b..9720f3d 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -105,6 +105,10 @@ CWindow* Events::remapFloatingWindow(int windowID, int forcemonitor) { Debug::log(LOG, "New window got name: " + WINNAME); window.setName(WINNAME); + const auto WINCLASSNAME = getClassName(windowID); + Debug::log(LOG, "New window got class: " + WINCLASSNAME.second); + window.setClassName(WINCLASSNAME.second); + // For all floating windows, get their default size const auto GEOMETRYCOOKIE = xcb_get_geometry(g_pWindowManager->DisplayConnection, windowID); const auto GEOMETRY = xcb_get_geometry_reply(g_pWindowManager->DisplayConnection, GEOMETRYCOOKIE, 0); @@ -205,6 +209,10 @@ CWindow* Events::remapWindow(int windowID, bool wasfloating, int forcemonitor) { Debug::log(LOG, "New window got name: " + WINNAME); window.setName(WINNAME); + const auto WINCLASSNAME = getClassName(windowID); + Debug::log(LOG, "New window got class: " + WINCLASSNAME.second); + window.setClassName(WINCLASSNAME.second); + // For all floating windows, get their default size const auto GEOMETRYCOOKIE = xcb_get_geometry(g_pWindowManager->DisplayConnection, windowID); const auto GEOMETRY = xcb_get_geometry_reply(g_pWindowManager->DisplayConnection, GEOMETRYCOOKIE, 0); diff --git a/src/ipc/ipc.cpp b/src/ipc/ipc.cpp index 5fa89d0..dab8043 100644 --- a/src/ipc/ipc.cpp +++ b/src/ipc/ipc.cpp @@ -67,16 +67,12 @@ void IPCSendMessage(const std::string path, SIPCMessageMainToBar smessage) { message += IPC_MESSAGE_SEPARATOR + "barfullscreenwindow" + IPC_MESSAGE_EQUALITY + (smessage.fullscreenOnBar ? "1" : "0"); - message += IPC_MESSAGE_SEPARATOR + "lastwindowname" + IPC_MESSAGE_EQUALITY; + message += IPC_MESSAGE_SEPARATOR + "lastwindowname" + IPC_MESSAGE_EQUALITY + smessage.lastWindowName; - if (const auto PLASTWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow); PLASTWINDOW) { - message += PLASTWINDOW->getName() + IPC_MESSAGE_SEPARATOR; - } else { - message += IPC_MESSAGE_SEPARATOR; - } + message += IPC_MESSAGE_SEPARATOR + "lastwindowclass" + IPC_MESSAGE_EQUALITY + smessage.lastWindowClass; // append the EOF - message += IPC_END_OF_FILE; + message += IPC_MESSAGE_SEPARATOR + IPC_END_OF_FILE; // Send writeToIPCChannel(path, message); @@ -137,6 +133,8 @@ void IPCRecieveMessageB(const std::string path) { std::sort(g_pWindowManager->statusBar->openWorkspaces.begin(), g_pWindowManager->statusBar->openWorkspaces.end()); } else if (PROPNAME == "lastwindowname") { g_pWindowManager->statusBar->setLastWindowName(PROPVALUE); + } else if (PROPNAME == "lastwindowclass") { + g_pWindowManager->statusBar->setLastWindowClass(PROPVALUE); } else if (PROPNAME == "barfullscreenwindow") { g_pWindowManager->statusBar->setIsCovered(PROPVALUE == "1" ? true : false); } diff --git a/src/ipc/ipc.hpp b/src/ipc/ipc.hpp index aeca5c1..68d06c4 100644 --- a/src/ipc/ipc.hpp +++ b/src/ipc/ipc.hpp @@ -12,6 +12,7 @@ struct SIPCMessageMainToBar { std::vector openWorkspaces; uint64_t activeWorkspace; std::string lastWindowName; + std::string lastWindowClass; bool fullscreenOnBar; }; diff --git a/src/window.hpp b/src/window.hpp index e1adb00..d2d47d1 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -33,6 +33,7 @@ public: // ------------------------------------- // EXPOSED_MEMBER(Name, std::string, sz); + EXPOSED_MEMBER(ClassName, std::string, sz); // Tells the window manager to reload the window's params EXPOSED_MEMBER(Dirty, bool, b); diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 8a4bf25..f6989c2 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -1191,7 +1191,9 @@ void CWindowManager::updateBarInfo() { message.activeWorkspace = activeWorkspaces[getMonitorFromCursor()->ID]; + auto winname = getWindowFromDrawable(LastWindow) ? getWindowFromDrawable(LastWindow)->getName() : ""; + auto winclassname = getWindowFromDrawable(LastWindow) ? getWindowFromDrawable(LastWindow)->getClassName() : ""; for (auto& c : winname) { // Remove illegal chars @@ -1201,8 +1203,18 @@ void CWindowManager::updateBarInfo() { c = ' '; } + for (auto& c : winclassname) { + // Remove illegal chars + if (c == '=') + c = ' '; + else if (c == '\t') + c = ' '; + } + message.lastWindowName = winname; + message.lastWindowClass = winclassname; + message.fullscreenOnBar = getWorkspaceByID(activeWorkspaces[ConfigManager::getInt("bar:monitor") > monitors.size() ? 0 : ConfigManager::getInt("bar:monitor")])->getHasFullscreenWindow(); for (auto& workspace : workspaces) {