mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-23 05:49:48 +01:00
internal: Unsafe state reworks (#3114)
This commit is contained in:
parent
774a5bedf8
commit
d9292800a2
6 changed files with 52 additions and 59 deletions
|
@ -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) {
|
|
||||||
if (rm->szName == OUTPUT->name) {
|
|
||||||
PNEWMONITORWRAP = &rm;
|
|
||||||
Debug::log(LOG, "Recovering a removed monitor.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PNEWMONITORWRAP) {
|
|
||||||
Debug::log(LOG, "Adding completely new monitor.");
|
|
||||||
PNEWMONITORWRAP = &g_pCompositor->m_vRealMonitors.emplace_back(std::make_shared<CMonitor>());
|
PNEWMONITORWRAP = &g_pCompositor->m_vRealMonitors.emplace_back(std::make_shared<CMonitor>());
|
||||||
|
|
||||||
(*PNEWMONITORWRAP)->ID = g_pCompositor->getNextAvailableMonitorID(OUTPUT->name);
|
(*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,13 +186,10 @@ 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
|
|
||||||
if (!g_pCompositor->m_bUnsafeState) {
|
|
||||||
Debug::log(LOG, "Removing monitor %s from realMonitors", pMonitor->szName.c_str());
|
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) {
|
||||||
const auto PMONITOR = (CMonitor*)owner;
|
const auto PMONITOR = (CMonitor*)owner;
|
||||||
|
|
|
@ -252,17 +252,10 @@ 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (BACKUPMON) {
|
||||||
// snap cursor
|
// snap cursor
|
||||||
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, BACKUPMON->vecPosition.x + BACKUPMON->vecTransformedSize.x / 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);
|
BACKUPMON->vecPosition.y + BACKUPMON->vecTransformedSize.y / 2.f);
|
||||||
|
@ -280,6 +273,11 @@ void CMonitor::onDisconnect() {
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue