internal: Unsafe state reworks (#3114)

This commit is contained in:
Vaxry 2023-09-01 22:03:56 +02:00 committed by GitHub
parent 774a5bedf8
commit d9292800a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 59 deletions

View file

@ -57,27 +57,15 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
return; return;
} }
if (g_pCompositor->m_bUnsafeState) { if (g_pCompositor->m_bUnsafeState)
Debug::log(WARN, "Recovering from an unsafe state. May you be lucky."); Debug::log(WARN, "Recovering from an unsafe state. May you be lucky.");
}
// add it to real // add it to real
std::shared_ptr<CMonitor>* PNEWMONITORWRAP = nullptr; std::shared_ptr<CMonitor>* PNEWMONITORWRAP = nullptr;
for (auto& rm : g_pCompositor->m_vRealMonitors) { PNEWMONITORWRAP = &g_pCompositor->m_vRealMonitors.emplace_back(std::make_shared<CMonitor>());
if (rm->szName == OUTPUT->name) {
PNEWMONITORWRAP = &rm;
Debug::log(LOG, "Recovering a removed monitor.");
break;
}
}
if (!PNEWMONITORWRAP) { (*PNEWMONITORWRAP)->ID = g_pCompositor->getNextAvailableMonitorID(OUTPUT->name);
Debug::log(LOG, "Adding completely new monitor.");
PNEWMONITORWRAP = &g_pCompositor->m_vRealMonitors.emplace_back(std::make_shared<CMonitor>());
(*PNEWMONITORWRAP)->ID = g_pCompositor->getNextAvailableMonitorID(OUTPUT->name);
}
const auto PNEWMONITOR = PNEWMONITORWRAP->get(); const auto PNEWMONITOR = PNEWMONITORWRAP->get();
@ -91,6 +79,20 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
// ready to process cuz we have a monitor // ready to process cuz we have a monitor
if (PNEWMONITOR->m_bEnabled) { if (PNEWMONITOR->m_bEnabled) {
if (g_pCompositor->m_bUnsafeState) {
// recover workspaces
for (auto& ws : g_pCompositor->m_vWorkspaces) {
g_pCompositor->moveWorkspaceToMonitor(ws.get(), PNEWMONITOR);
}
g_pHyprRenderer->m_pMostHzMonitor = PNEWMONITOR;
const auto POS = PNEWMONITOR->vecPosition + PNEWMONITOR->vecSize / 2.f;
if (g_pCompositor->m_sSeat.mouse)
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, POS.x, POS.y);
}
g_pCompositor->m_bReadyToProcess = true; g_pCompositor->m_bReadyToProcess = true;
g_pCompositor->m_bUnsafeState = false; g_pCompositor->m_bUnsafeState = false;
} }
@ -184,12 +186,9 @@ void Events::listener_monitorDestroy(void* owner, void* data) {
pMonitor->output = nullptr; pMonitor->output = nullptr;
pMonitor->m_bRenderingInitPassed = false; pMonitor->m_bRenderingInitPassed = false;
// cleanup if not unsafe Debug::log(LOG, "Removing monitor %s from realMonitors", pMonitor->szName.c_str());
if (!g_pCompositor->m_bUnsafeState) {
Debug::log(LOG, "Removing monitor %s from realMonitors", pMonitor->szName.c_str());
std::erase_if(g_pCompositor->m_vRealMonitors, [&](std::shared_ptr<CMonitor>& el) { return el.get() == pMonitor; }); std::erase_if(g_pCompositor->m_vRealMonitors, [&](std::shared_ptr<CMonitor>& el) { return el.get() == pMonitor; });
}
} }
void Events::listener_monitorStateRequest(void* owner, void* data) { void Events::listener_monitorStateRequest(void* owner, void* data) {

View file

@ -252,33 +252,31 @@ void CMonitor::onDisconnect() {
if (!BACKUPMON) { if (!BACKUPMON) {
Debug::log(WARN, "Unplugged last monitor, entering an unsafe state. Good luck my friend."); Debug::log(WARN, "Unplugged last monitor, entering an unsafe state. Good luck my friend.");
hyprListener_monitorStateRequest.removeCallback();
hyprListener_monitorDestroy.removeCallback();
g_pCompositor->m_bUnsafeState = true; g_pCompositor->m_bUnsafeState = true;
std::erase_if(g_pCompositor->m_vMonitors, [&](std::shared_ptr<CMonitor>& el) { return el.get() == this; });
return;
} }
// snap cursor if (BACKUPMON) {
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, BACKUPMON->vecPosition.x + BACKUPMON->vecTransformedSize.x / 2.f, // snap cursor
BACKUPMON->vecPosition.y + BACKUPMON->vecTransformedSize.y / 2.f); wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, BACKUPMON->vecPosition.x + BACKUPMON->vecTransformedSize.x / 2.f,
BACKUPMON->vecPosition.y + BACKUPMON->vecTransformedSize.y / 2.f);
// move workspaces // move workspaces
std::deque<CWorkspace*> wspToMove; std::deque<CWorkspace*> wspToMove;
for (auto& w : g_pCompositor->m_vWorkspaces) { for (auto& w : g_pCompositor->m_vWorkspaces) {
if (w->m_iMonitorID == ID) { if (w->m_iMonitorID == ID) {
wspToMove.push_back(w.get()); wspToMove.push_back(w.get());
}
} }
}
for (auto& w : wspToMove) { for (auto& w : wspToMove) {
w->m_szLastMonitor = szName; w->m_szLastMonitor = szName;
g_pCompositor->moveWorkspaceToMonitor(w, BACKUPMON); g_pCompositor->moveWorkspaceToMonitor(w, BACKUPMON);
w->startAnim(true, true, true); w->startAnim(true, true, true);
}
} else {
g_pCompositor->m_pLastFocus = nullptr;
g_pCompositor->m_pLastWindow = nullptr;
g_pCompositor->m_pLastMonitor = nullptr;
} }
activeWorkspace = -1; activeWorkspace = -1;
@ -289,8 +287,6 @@ void CMonitor::onDisconnect() {
wlr_output_commit(output); wlr_output_commit(output);
std::erase_if(g_pCompositor->m_vWorkspaces, [&](std::unique_ptr<CWorkspace>& el) { return el->m_iMonitorID == ID; });
if (g_pCompositor->m_pLastMonitor == this) if (g_pCompositor->m_pLastMonitor == this)
g_pCompositor->setActiveMonitor(BACKUPMON); g_pCompositor->setActiveMonitor(BACKUPMON);

View file

@ -3,8 +3,10 @@
#include "HookSystemManager.hpp" #include "HookSystemManager.hpp"
int wlTick(void* data) { int wlTick(void* data) {
if (g_pAnimationManager)
g_pAnimationManager->onTicked();
if (g_pCompositor->m_bSessionActive && g_pAnimationManager && g_pHookSystem && if (g_pCompositor->m_bSessionActive && g_pAnimationManager && g_pHookSystem && !g_pCompositor->m_bUnsafeState &&
std::ranges::any_of(g_pCompositor->m_vMonitors, [](const auto& mon) { return mon->m_bEnabled && mon->output; })) { std::ranges::any_of(g_pCompositor->m_vMonitors, [](const auto& mon) { return mon->m_bEnabled && mon->output; })) {
g_pAnimationManager->tick(); g_pAnimationManager->tick();
EMIT_HOOK_EVENT("tick", nullptr); EMIT_HOOK_EVENT("tick", nullptr);
@ -37,10 +39,11 @@ void CAnimationManager::addBezierWithName(std::string name, const Vector2D& p1,
m_mBezierCurves[name].setup(&points); m_mBezierCurves[name].setup(&points);
} }
void CAnimationManager::tick() { void CAnimationManager::onTicked() {
m_bTickScheduled = false; m_bTickScheduled = false;
}
void CAnimationManager::tick() {
static std::chrono::time_point lastTick = std::chrono::high_resolution_clock::now(); static std::chrono::time_point lastTick = std::chrono::high_resolution_clock::now();
m_fLastTickTime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - lastTick).count() / 1000.0; m_fLastTickTime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - lastTick).count() / 1000.0;
lastTick = std::chrono::high_resolution_clock::now(); lastTick = std::chrono::high_resolution_clock::now();
@ -247,8 +250,8 @@ void CAnimationManager::tick() {
const auto EXTENTS = PDECO->getWindowDecorationExtents(); const auto EXTENTS = PDECO->getWindowDecorationExtents();
wlr_box dmg = {PWINDOW->m_vRealPosition.vec().x - EXTENTS.topLeft.x, PWINDOW->m_vRealPosition.vec().y - EXTENTS.topLeft.y, wlr_box dmg = {PWINDOW->m_vRealPosition.vec().x - EXTENTS.topLeft.x, PWINDOW->m_vRealPosition.vec().y - EXTENTS.topLeft.y,
PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x, PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x,
PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y}; PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y};
if (!*PSHADOWIGNOREWINDOW) { if (!*PSHADOWIGNOREWINDOW) {
// easy, damage the entire box // easy, damage the entire box

View file

@ -14,6 +14,7 @@ class CAnimationManager {
void tick(); void tick();
bool shouldTickForNext(); bool shouldTickForNext();
void onTicked();
void scheduleTick(); void scheduleTick();
void addBezierWithName(std::string, const Vector2D&, const Vector2D&); void addBezierWithName(std::string, const Vector2D&, const Vector2D&);
void removeAllBeziers(); void removeAllBeziers();

View file

@ -215,7 +215,7 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) {
} }
bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) { bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) {
if (!g_pCompositor->m_bSessionActive) { if (!g_pCompositor->m_bSessionActive || g_pCompositor->m_bUnsafeState) {
m_dPressedKeycodes.clear(); m_dPressedKeycodes.clear();
m_dPressedKeysyms.clear(); m_dPressedKeysyms.clear();
return true; return true;
@ -1502,7 +1502,6 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) {
} }
bool requestedWorkspaceIsAlreadyOpen = false; bool requestedWorkspaceIsAlreadyOpen = false;
bool requestedWorkspaceExists = g_pCompositor->getWorkspaceByID(workspaceID);
const auto PMONITOR = *PFOLLOWMOUSE == 1 ? g_pCompositor->getMonitorFromCursor() : g_pCompositor->m_pLastMonitor; const auto PMONITOR = *PFOLLOWMOUSE == 1 ? g_pCompositor->getMonitorFromCursor() : g_pCompositor->m_pLastMonitor;
int specialOpenOnMonitor = PMONITOR->specialWorkspaceID; int specialOpenOnMonitor = PMONITOR->specialWorkspaceID;

View file

@ -58,16 +58,11 @@ void CXDGOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver
} }
CXDGOutputProtocol::CXDGOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CXDGOutputProtocol::CXDGOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
g_pHookSystem->hookDynamic("monitorLayoutChanged", [&](void* self, std::any param) { this->updateAllOutputs(); }); g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, std::any param) { this->updateAllOutputs(); });
g_pHookSystem->hookDynamic("configReloaded", [&](void* self, std::any param) { this->updateAllOutputs(); }); g_pHookSystem->hookDynamic("configReloaded", [this](void* self, std::any param) { this->updateAllOutputs(); });
g_pHookSystem->hookDynamic("monitorRemoved", [&](void* self, std::any param) { g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, std::any param) {
const auto PMONITOR = std::any_cast<CMonitor*>(param); const auto PMONITOR = std::any_cast<CMonitor*>(param);
std::erase_if(m_vXDGOutputs, [&](const auto& other) { std::erase_if(m_vXDGOutputs, [&](const auto& other) { return other->monitor == PMONITOR; });
const bool R = other->monitor == PMONITOR;
if (R)
other->resource->markDefunct();
return R;
});
}); });
} }