From de8a4ca48c45270b5f2ef082eea17c9ea7006a8a Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 25 Dec 2021 22:56:02 +0100 Subject: [PATCH] fix for a randr event spam bug --- README.md | 6 ++---- src/events/events.cpp | 22 ++++++++++++++++++++++ src/events/events.hpp | 4 ++++ src/windowManager.cpp | 4 ++-- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c784f9f..69667c4 100644 --- a/README.md +++ b/README.md @@ -45,11 +45,9 @@ You have to use a config, place it in ~/.config/hypr/hypr.conf See the [Wiki](https://github.com/vaxerski/Hypr/wiki/Building) to see build instructions. # Known issues -- RandR sometimes bugs at launch and starts spamming events, which will make the WM sluggish. Has never happened to me on a real machine though, only in a nested X11 session. (fix: restart X) - Picom's shadow and effects do not update for cheap animations while animating -- Non-cheap animations are choppy (duh!) -- The config is still pretty simple, although riceable! -- Popups sometimes are created pretty small +- Non-cheap animations are choppy (duh!)rgith +- Popups sometimes are created a bit off # Contributions Refer to [CONTRIBUTING.md](https://github.com/vaxerski/Hypr/blob/main/CONTRIBUTING.md) and the [Wiki](https://github.com/vaxerski/Hypr/wiki/Contributing-&-Debugging) for contributing instructions and guidelines. diff --git a/src/events/events.cpp b/src/events/events.cpp index b4a1525..d8e9d7b 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -821,6 +821,28 @@ void Events::eventClientMessage(xcb_generic_event_t* event) { void Events::eventRandRScreenChange(xcb_generic_event_t* event) { + // fix sus randr events, that sometimes happen + // it will spam these for no reason + // so we check if we have > 9 consecutive randr events less than 1s between each + // and if so, we stop listening for them + const auto DELTA = std::chrono::duration_cast(lastRandREvent - std::chrono::high_resolution_clock::now()); + + if (susRandREventNo < 10) { + if (DELTA.count() <= 1000) { + susRandREventNo += 1; + Debug::log(WARN, "Suspicious RandR event no. " + std::to_string(susRandREventNo) + "!"); + if (susRandREventNo > 9) + Debug::log(WARN, "Disabling RandR event listening because of excess suspicious RandR events (bug!)"); + } + else + susRandREventNo = 0; + } + + if (susRandREventNo > 9) + return; + // randr sus fixed + // + // redetect screens g_pWindowManager->monitors.clear(); g_pWindowManager->setupRandrMonitors(); diff --git a/src/events/events.hpp b/src/events/events.hpp index 99fc598..47bc660 100644 --- a/src/events/events.hpp +++ b/src/events/events.hpp @@ -34,4 +34,8 @@ namespace Events { // Fix focus on open inline std::deque ignoredEvents; + + // Fix spammed RandR events + inline std::chrono::high_resolution_clock::time_point lastRandREvent = std::chrono::high_resolution_clock::now(); + inline int susRandREventNo = 0; }; \ No newline at end of file diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 8174285..73a5d3a 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -313,12 +313,12 @@ void CWindowManager::recieveEvent() { default: - if ((EVENTCODE != 14) && (EVENTCODE != 13) && (EVENTCODE != 0) && (EVENTCODE != 22)) + if ((EVENTCODE != 14) && (EVENTCODE != 13) && (EVENTCODE != 0) && (EVENTCODE != 22) && (TYPE - RandREventBase != XCB_RANDR_SCREEN_CHANGE_NOTIFY)) Debug::log(WARN, "Unknown event: " + std::to_string(ev->response_type & ~0x80)); break; } - if (TYPE - RandREventBase == XCB_RANDR_SCREEN_CHANGE_NOTIFY) { + if ((int)TYPE - RandREventBase == XCB_RANDR_SCREEN_CHANGE_NOTIFY && RandREventBase > 0) { Events::eventRandRScreenChange(ev); Debug::log(LOG, "Event dispatched RANDR_SCREEN_CHANGE"); }