workspacerules: fix on-created-empty window focus (#7657)

This commit is contained in:
Sungyoon Cho 2024-09-06 08:54:01 +09:00 committed by GitHub
parent 727f1b54cd
commit 0fad7a0bb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 14 deletions

View file

@ -51,7 +51,7 @@ void CWorkspace::init(PHLWORKSPACE self) {
if (self->m_bWasCreatedEmpty) if (self->m_bWasCreatedEmpty)
if (auto cmd = WORKSPACERULE.onCreatedEmptyRunCmd) if (auto cmd = WORKSPACERULE.onCreatedEmptyRunCmd)
g_pKeybindManager->spawn(*cmd); g_pKeybindManager->spawnWithRules(*cmd, self);
g_pEventManager->postEvent({"createworkspace", m_szName}); g_pEventManager->postEvent({"createworkspace", m_szName});
g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)}); g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)});

View file

@ -34,7 +34,7 @@ using namespace Hyprutils::String;
#include <sys/consio.h> #include <sys/consio.h>
#endif #endif
static std::vector<std::pair<std::string, std::string>> getHyprlandLaunchEnv() { static std::vector<std::pair<std::string, std::string>> getHyprlandLaunchEnv(PHLWORKSPACE pInitialWorkspace) {
static auto PINITIALWSTRACKING = CConfigValue<Hyprlang::INT>("misc:initial_workspace_tracking"); static auto PINITIALWSTRACKING = CConfigValue<Hyprlang::INT>("misc:initial_workspace_tracking");
if (!*PINITIALWSTRACKING || g_pConfigManager->isLaunchingExecOnce) if (!*PINITIALWSTRACKING || g_pConfigManager->isLaunchingExecOnce)
@ -46,11 +46,15 @@ static std::vector<std::pair<std::string, std::string>> getHyprlandLaunchEnv() {
std::vector<std::pair<std::string, std::string>> result; std::vector<std::pair<std::string, std::string>> result;
result.push_back(std::make_pair<>( if (!pInitialWorkspace) {
"HL_INITIAL_WORKSPACE_TOKEN", if (PMONITOR->activeSpecialWorkspace)
g_pTokenManager->registerNewToken( pInitialWorkspace = PMONITOR->activeSpecialWorkspace;
SInitialWorkspaceToken{{}, PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspace->getConfigName() : PMONITOR->activeWorkspace->getConfigName()}, else
std::chrono::months(1337)))); pInitialWorkspace = PMONITOR->activeWorkspace;
}
result.push_back(std::make_pair<>("HL_INITIAL_WORKSPACE_TOKEN",
g_pTokenManager->registerNewToken(SInitialWorkspaceToken{{}, pInitialWorkspace->getConfigName()}, std::chrono::months(1337))));
return result; return result;
} }
@ -846,8 +850,12 @@ bool CKeybindManager::handleInternalKeybinds(xkb_keysym_t keysym) {
} }
// Dispatchers // Dispatchers
SDispatchResult CKeybindManager::spawn(std::string args) { SDispatchResult CKeybindManager::spawn(std::string args) {
const uint64_t PROC = spawnWithRules(args, nullptr);
return {.success = PROC > 0, .error = std::format("Failed to start process {}", args)};
}
uint64_t CKeybindManager::spawnWithRules(std::string args, PHLWORKSPACE pInitialWorkspace) {
args = trim(args); args = trim(args);
@ -859,7 +867,7 @@ SDispatchResult CKeybindManager::spawn(std::string args) {
args = args.substr(args.find_first_of(']') + 1); args = args.substr(args.find_first_of(']') + 1);
} }
const uint64_t PROC = spawnRawProc(args); const uint64_t PROC = spawnRawProc(args, pInitialWorkspace);
if (!RULES.empty()) { if (!RULES.empty()) {
const auto RULESLIST = CVarList(RULES, 0, ';'); const auto RULESLIST = CVarList(RULES, 0, ';');
@ -871,18 +879,18 @@ SDispatchResult CKeybindManager::spawn(std::string args) {
Debug::log(LOG, "Applied {} rule arguments for exec.", RULESLIST.size()); Debug::log(LOG, "Applied {} rule arguments for exec.", RULESLIST.size());
} }
return {.success = PROC > 0, .error = std::format("Failed to start process {}", args)}; return PROC;
} }
SDispatchResult CKeybindManager::spawnRaw(std::string args) { SDispatchResult CKeybindManager::spawnRaw(std::string args) {
const uint64_t PROC = spawnRawProc(args); const uint64_t PROC = spawnRawProc(args, nullptr);
return {.success = PROC > 0, .error = std::format("Failed to start process {}", args)}; return {.success = PROC > 0, .error = std::format("Failed to start process {}", args)};
} }
uint64_t CKeybindManager::spawnRawProc(std::string args) { uint64_t CKeybindManager::spawnRawProc(std::string args, PHLWORKSPACE pInitialWorkspace) {
Debug::log(LOG, "Executing {}", args); Debug::log(LOG, "Executing {}", args);
const auto HLENV = getHyprlandLaunchEnv(); const auto HLENV = getHyprlandLaunchEnv(pInitialWorkspace);
int socket[2]; int socket[2];
if (pipe(socket) != 0) { if (pipe(socket) != 0) {

View file

@ -149,7 +149,8 @@ class CKeybindManager {
static void moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& dir = ""); static void moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& dir = "");
static void moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection); static void moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection);
static void switchToWindow(PHLWINDOW PWINDOWTOCHANGETO); static void switchToWindow(PHLWINDOW PWINDOWTOCHANGETO);
static uint64_t spawnRawProc(std::string); static uint64_t spawnRawProc(std::string, PHLWORKSPACE pInitialWorkspace);
static uint64_t spawnWithRules(std::string, PHLWORKSPACE pInitialWorkspace);
// -------------- Dispatchers -------------- // // -------------- Dispatchers -------------- //
static SDispatchResult killActive(std::string); static SDispatchResult killActive(std::string);