Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "debug/log/Logger.hpp"
#include "desktop/DesktopTypes.hpp"
#include "desktop/state/FocusState.hpp"
#include "desktop/history/WindowHistoryTracker.hpp"
#include "desktop/history/WorkspaceHistoryTracker.hpp"
#include "helpers/Splashes.hpp"
#include "config/ConfigValue.hpp"
#include "config/ConfigWatcher.hpp"
Expand Down Expand Up @@ -661,6 +663,11 @@ void CCompositor::initManagers(eManagersInitStage stage) {

Log::logger->log(Log::DEBUG, "Creating the SeatManager!");
g_pSeatManager = makeUnique<CSeatManager>();

// init focus state els
Desktop::History::windowTracker();
Desktop::History::workspaceTracker();

} break;
case STAGE_LATE: {
Log::logger->log(Log::DEBUG, "Creating CHyprCtl");
Expand Down Expand Up @@ -1447,16 +1454,14 @@ PHLWINDOW CCompositor::getWindowInDirection(const CBox& box, PHLWORKSPACE pWorks

// get idx
int windowIDX = -1;
const auto& HISTORY = Desktop::focusState()->windowHistory();
for (size_t i = 0; i < HISTORY.size(); ++i) {
const auto& HISTORY = Desktop::History::windowTracker()->fullHistory();
for (int64_t i = HISTORY.size() - 1; i >= 0; --i) {
if (HISTORY[i] == w) {
windowIDX = i;
break;
}
}

windowIDX = Desktop::focusState()->windowHistory().size() - windowIDX;

if (windowIDX > leaderValue) {
leaderValue = windowIDX;
leaderWindow = w;
Expand Down Expand Up @@ -1560,10 +1565,9 @@ static PHLWINDOW getWeakWindowPred(Iterator cur, Iterator end, Iterator begin, c
PHLWINDOW CCompositor::getWindowCycleHist(PHLWINDOWREF cur, bool focusableOnly, std::optional<bool> floating, bool visible, bool next) {
const auto FINDER = [&](const PHLWINDOWREF& w) { return isWindowAvailableForCycle(cur, w, focusableOnly, floating, visible); };
// also m_vWindowFocusHistory has reverse order, so when it is next - we need to reverse again
return next ? getWeakWindowPred(std::ranges::find(Desktop::focusState()->windowHistory() | std::views::reverse, cur), Desktop::focusState()->windowHistory().rend(),
Desktop::focusState()->windowHistory().rbegin(), FINDER) :
getWeakWindowPred(std::ranges::find(Desktop::focusState()->windowHistory(), cur), Desktop::focusState()->windowHistory().end(),
Desktop::focusState()->windowHistory().begin(), FINDER);
const auto& HISTORY = Desktop::History::windowTracker()->fullHistory();
return next ? getWeakWindowPred(std::ranges::find(HISTORY, cur), HISTORY.end(), HISTORY.begin(), FINDER) :
getWeakWindowPred(std::ranges::find(HISTORY | std::views::reverse, cur), HISTORY.rend(), HISTORY.rbegin(), FINDER);
}

PHLWINDOW CCompositor::getWindowCycle(PHLWINDOW cur, bool focusableOnly, std::optional<bool> floating, bool visible, bool prev) {
Expand Down Expand Up @@ -1808,9 +1812,6 @@ void CCompositor::swapActiveWorkspaces(PHLMONITOR pMonitorA, PHLMONITOR pMonitor
pMonitorA->m_activeWorkspace = PWORKSPACEB;
pMonitorB->m_activeWorkspace = PWORKSPACEA;

PWORKSPACEA->rememberPrevWorkspace(PWORKSPACEB);
PWORKSPACEB->rememberPrevWorkspace(PWORKSPACEA);

g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitorA->m_id);
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitorB->m_id);

Expand Down
8 changes: 5 additions & 3 deletions src/debug/HyprCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ using namespace Hyprutils::OS;
#include "helpers/MiscFunctions.hpp"
#include "../desktop/view/LayerSurface.hpp"
#include "../desktop/rule/Engine.hpp"
#include "../desktop/history/WindowHistoryTracker.hpp"
#include "../desktop/state/FocusState.hpp"
#include "../version.h"

Expand Down Expand Up @@ -354,9 +355,10 @@ static std::string getGroupedData(PHLWINDOW w, eHyprCtlOutputFormat format) {

std::string CHyprCtl::getWindowData(PHLWINDOW w, eHyprCtlOutputFormat format) {
auto getFocusHistoryID = [](PHLWINDOW wnd) -> int {
for (size_t i = 0; i < Desktop::focusState()->windowHistory().size(); ++i) {
if (Desktop::focusState()->windowHistory()[i].lock() == wnd)
return i;
const auto& HISTORY = Desktop::History::windowTracker()->fullHistory();
for (size_t i = 0; i < HISTORY.size(); ++i) {
if (HISTORY[i].lock() == wnd)
return HISTORY.size() - i - 1; // reverse order for backwards compat
}
return -1;
};
Expand Down
22 changes: 0 additions & 22 deletions src/desktop/Workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ void CWorkspace::init(PHLWORKSPACE self) {
EMIT_HOOK_EVENT("createWorkspace", this);
}

SWorkspaceIDName CWorkspace::getPrevWorkspaceIDName() const {
return m_prevWorkspace;
}

CWorkspace::~CWorkspace() {
Log::logger->log(Log::DEBUG, "Destroying workspace ID {}", m_id);

Expand All @@ -82,24 +78,6 @@ PHLWINDOW CWorkspace::getLastFocusedWindow() {
return m_lastFocusedWindow.lock();
}

void CWorkspace::rememberPrevWorkspace(const PHLWORKSPACE& prev) {
if (!prev) {
m_prevWorkspace.id = -1;
m_prevWorkspace.name = "";
return;
}

if (prev->m_id == m_id) {
Log::logger->log(Log::DEBUG, "Tried to set prev workspace to the same as current one");
return;
}

m_prevWorkspace.id = prev->m_id;
m_prevWorkspace.name = prev->m_name;

prev->m_monitor->addPrevWorkspaceID(prev->m_id);
}

std::string CWorkspace::getConfigName() {
if (m_isSpecialWorkspace) {
return m_name;
Expand Down
49 changes: 22 additions & 27 deletions src/desktop/Workspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,27 @@ class CWorkspace {
bool m_wasCreatedEmpty = true;

// Inert: destroyed and invalid. If this is true, release the ptr you have.
bool inert();
MONITORID monitorID();
PHLWINDOW getLastFocusedWindow();
void rememberPrevWorkspace(const PHLWORKSPACE& prevWorkspace);
std::string getConfigName();
bool matchesStaticSelector(const std::string& selector);
void markInert();
SWorkspaceIDName getPrevWorkspaceIDName() const;
void updateWindowDecos();
void updateWindowData();
int getWindows(std::optional<bool> onlyTiled = {}, std::optional<bool> onlyPinned = {}, std::optional<bool> onlyVisible = {});
int getGroups(std::optional<bool> onlyTiled = {}, std::optional<bool> onlyPinned = {}, std::optional<bool> onlyVisible = {});
bool hasUrgentWindow();
PHLWINDOW getFirstWindow();
PHLWINDOW getTopLeftWindow();
PHLWINDOW getFullscreenWindow();
bool isVisible();
bool isVisibleNotCovered();
void rename(const std::string& name = "");
void forceReportSizesToWindows();
void updateWindows();
void setPersistent(bool persistent);
bool isPersistent();
bool inert();
MONITORID monitorID();
PHLWINDOW getLastFocusedWindow();
std::string getConfigName();
bool matchesStaticSelector(const std::string& selector);
void markInert();
void updateWindowDecos();
void updateWindowData();
int getWindows(std::optional<bool> onlyTiled = {}, std::optional<bool> onlyPinned = {}, std::optional<bool> onlyVisible = {});
int getGroups(std::optional<bool> onlyTiled = {}, std::optional<bool> onlyPinned = {}, std::optional<bool> onlyVisible = {});
bool hasUrgentWindow();
PHLWINDOW getFirstWindow();
PHLWINDOW getTopLeftWindow();
PHLWINDOW getFullscreenWindow();
bool isVisible();
bool isVisibleNotCovered();
void rename(const std::string& name = "");
void forceReportSizesToWindows();
void updateWindows();
void setPersistent(bool persistent);
bool isPersistent();

struct {
CSignalT<> destroy;
Expand All @@ -89,10 +87,7 @@ class CWorkspace {
} m_events;

private:
void init(PHLWORKSPACE self);
// Previous workspace ID and name is stored during a workspace change, allowing travel
// to the previous workspace.
SWorkspaceIDName m_prevWorkspace;
void init(PHLWORKSPACE self);

SP<HOOK_CALLBACK_FN> m_focusedWindowHook;
bool m_inert = true;
Expand Down
55 changes: 55 additions & 0 deletions src/desktop/history/WindowHistoryTracker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "WindowHistoryTracker.hpp"

#include "../../managers/HookSystemManager.hpp"
#include "../view/Window.hpp"

using namespace Desktop;
using namespace Desktop::History;

SP<CWindowHistoryTracker> History::windowTracker() {
static SP<CWindowHistoryTracker> tracker = makeShared<CWindowHistoryTracker>();
return tracker;
}

CWindowHistoryTracker::CWindowHistoryTracker() {
static auto P = g_pHookSystem->hookDynamic("openWindowEarly", [this](void* self, SCallbackInfo& info, std::any data) {
auto window = std::any_cast<PHLWINDOW>(data);

// add a last track
m_history.insert(m_history.begin(), window);
});

static auto P1 = g_pHookSystem->hookDynamic("activeWindow", [this](void* self, SCallbackInfo& info, std::any data) {
auto window = std::any_cast<PHLWINDOW>(data);

track(window);
});
}

void CWindowHistoryTracker::track(PHLWINDOW w) {
std::erase(m_history, w);
m_history.emplace_back(w);
}

const std::vector<PHLWINDOWREF>& CWindowHistoryTracker::fullHistory() {
gc();
return m_history;
}

std::vector<PHLWINDOWREF> CWindowHistoryTracker::historyForWorkspace(PHLWORKSPACE ws) {
gc();
std::vector<PHLWINDOWREF> windows;

for (const auto& w : m_history) {
if (w->m_workspace != ws)
continue;

windows.emplace_back(w);
}

return windows;
}

void CWindowHistoryTracker::gc() {
std::erase_if(m_history, [](const auto& e) { return !e; });
}
30 changes: 30 additions & 0 deletions src/desktop/history/WindowHistoryTracker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "../DesktopTypes.hpp"

#include <vector>

namespace Desktop::History {
class CWindowHistoryTracker {
public:
CWindowHistoryTracker();
~CWindowHistoryTracker() = default;

CWindowHistoryTracker(const CWindowHistoryTracker&) = delete;
CWindowHistoryTracker(CWindowHistoryTracker&) = delete;
CWindowHistoryTracker(CWindowHistoryTracker&&) = delete;

// History is ordered old -> new, meaning .front() is oldest, while .back() is newest

const std::vector<PHLWINDOWREF>& fullHistory();
std::vector<PHLWINDOWREF> historyForWorkspace(PHLWORKSPACE ws);

private:
std::vector<PHLWINDOWREF> m_history;

void track(PHLWINDOW w);
void gc();
};

SP<CWindowHistoryTracker> windowTracker();
};
Loading
Loading