anr: open anr dialog on parent's workspace (#12509)

This commit is contained in:
EvilLary 2026-01-06 16:29:17 +03:00 committed by GitHub
parent 9817553c66
commit cbfbd9712a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 147 additions and 15 deletions

View file

@ -4,6 +4,8 @@
#include <algorithm>
#include <unistd.h>
#include "../managers/eventLoop/EventLoopManager.hpp"
#include "../desktop/rule/windowRule/WindowRule.hpp"
#include "../desktop/rule/Engine.hpp"
using namespace Hyprutils::OS;
@ -119,6 +121,9 @@ SP<CPromise<std::string>> CAsyncDialogBox::open() {
m_selfReference = m_selfWeakReference.lock();
if (!m_execRuleToken.empty())
proc.addEnv(Desktop::Rule::EXEC_RULE_ENV_NAME, m_execRuleToken);
if (!proc.runAsync()) {
Log::logger->log(Log::ERR, "CAsyncDialogBox::open: failed to run async");
wl_event_source_remove(m_readEventSource);
@ -154,3 +159,9 @@ pid_t CAsyncDialogBox::getPID() const {
SP<CAsyncDialogBox> CAsyncDialogBox::lockSelf() {
return m_selfWeakReference.lock();
}
void CAsyncDialogBox::setExecRule(std::string&& s) {
auto rule = Desktop::Rule::CWindowRule::buildFromExecString(std::move(s));
m_execRuleToken = rule->execToken();
Desktop::Rule::ruleEngine()->registerRule(std::move(rule));
}

View file

@ -27,6 +27,7 @@ class CAsyncDialogBox {
void kill();
bool isRunning() const;
pid_t getPID() const;
void setExecRule(std::string&& s);
SP<CAsyncDialogBox> lockSelf();
@ -41,7 +42,8 @@ class CAsyncDialogBox {
pid_t m_dialogPid = 0;
wl_event_source* m_readEventSource = nullptr;
Hyprutils::OS::CFileDescriptor m_pipeReadFd;
std::string m_stdout = "";
std::string m_stdout = "";
std::string m_execRuleToken = "";
const std::string m_title;
const std::string m_description;

View file

@ -188,21 +188,25 @@ void CANRManager::SANRData::runDialog(const std::string& appName, const std::str
const auto OPTION_TERMINATE_STR = I18n::i18nEngine()->localize(I18n::TXT_KEY_ANR_OPTION_TERMINATE, {});
const auto OPTION_WAIT_STR = I18n::i18nEngine()->localize(I18n::TXT_KEY_ANR_OPTION_WAIT, {});
const auto OPTIONS = std::vector{OPTION_TERMINATE_STR, OPTION_WAIT_STR};
const auto CLASS_STR = appClass.empty() ? I18n::i18nEngine()->localize(I18n::TXT_KEY_ANR_PROP_UNKNOWN, {}) : appClass;
const auto TITLE_STR = appName.empty() ? I18n::i18nEngine()->localize(I18n::TXT_KEY_ANR_PROP_UNKNOWN, {}) : appName;
const auto DESCRIPTION_STR = I18n::i18nEngine()->localize(I18n::TXT_KEY_ANR_CONTENT, {{"title", TITLE_STR}, {"class", CLASS_STR}});
dialogBox =
CAsyncDialogBox::create(I18n::i18nEngine()->localize(I18n::TXT_KEY_ANR_TITLE, {}),
I18n::i18nEngine()->localize(I18n::TXT_KEY_ANR_CONTENT,
{
//
{"class", appClass.empty() ? I18n::i18nEngine()->localize(I18n::TXT_KEY_ANR_PROP_UNKNOWN, {}) : appClass}, //
{"title", appName.empty() ? I18n::i18nEngine()->localize(I18n::TXT_KEY_ANR_PROP_UNKNOWN, {}) : appName} //
}),
std::vector<std::string>{
//
OPTION_TERMINATE_STR, //
OPTION_WAIT_STR //
} //
);
dialogBox = CAsyncDialogBox::create(I18n::i18nEngine()->localize(I18n::TXT_KEY_ANR_TITLE, {}), DESCRIPTION_STR, OPTIONS);
for (const auto& w : g_pCompositor->m_windows) {
if (!w->m_isMapped)
continue;
if (!fitsWindow(w))
continue;
if (w->m_workspace)
dialogBox->setExecRule(std::format("workspace {} silent", w->m_workspace->getConfigName()));
break;
}
dialogBox->open()->then([dialogWmPID, this, OPTION_TERMINATE_STR, OPTION_WAIT_STR](SP<CPromiseResult<std::string>> r) {
if (r->hasError()) {