mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-19 00:09:48 +01:00
workspacerules: fix on-created-empty window focus (#7657)
This commit is contained in:
parent
727f1b54cd
commit
0fad7a0bb0
3 changed files with 23 additions and 14 deletions
|
@ -51,7 +51,7 @@ void CWorkspace::init(PHLWORKSPACE self) {
|
|||
|
||||
if (self->m_bWasCreatedEmpty)
|
||||
if (auto cmd = WORKSPACERULE.onCreatedEmptyRunCmd)
|
||||
g_pKeybindManager->spawn(*cmd);
|
||||
g_pKeybindManager->spawnWithRules(*cmd, self);
|
||||
|
||||
g_pEventManager->postEvent({"createworkspace", m_szName});
|
||||
g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)});
|
||||
|
|
|
@ -34,7 +34,7 @@ using namespace Hyprutils::String;
|
|||
#include <sys/consio.h>
|
||||
#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");
|
||||
|
||||
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;
|
||||
|
||||
result.push_back(std::make_pair<>(
|
||||
"HL_INITIAL_WORKSPACE_TOKEN",
|
||||
g_pTokenManager->registerNewToken(
|
||||
SInitialWorkspaceToken{{}, PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspace->getConfigName() : PMONITOR->activeWorkspace->getConfigName()},
|
||||
std::chrono::months(1337))));
|
||||
if (!pInitialWorkspace) {
|
||||
if (PMONITOR->activeSpecialWorkspace)
|
||||
pInitialWorkspace = PMONITOR->activeSpecialWorkspace;
|
||||
else
|
||||
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;
|
||||
}
|
||||
|
@ -846,8 +850,12 @@ bool CKeybindManager::handleInternalKeybinds(xkb_keysym_t keysym) {
|
|||
}
|
||||
|
||||
// Dispatchers
|
||||
|
||||
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);
|
||||
|
||||
|
@ -859,7 +867,7 @@ SDispatchResult CKeybindManager::spawn(std::string args) {
|
|||
args = args.substr(args.find_first_of(']') + 1);
|
||||
}
|
||||
|
||||
const uint64_t PROC = spawnRawProc(args);
|
||||
const uint64_t PROC = spawnRawProc(args, pInitialWorkspace);
|
||||
|
||||
if (!RULES.empty()) {
|
||||
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());
|
||||
}
|
||||
|
||||
return {.success = PROC > 0, .error = std::format("Failed to start process {}", args)};
|
||||
return PROC;
|
||||
}
|
||||
|
||||
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)};
|
||||
}
|
||||
|
||||
uint64_t CKeybindManager::spawnRawProc(std::string args) {
|
||||
uint64_t CKeybindManager::spawnRawProc(std::string args, PHLWORKSPACE pInitialWorkspace) {
|
||||
Debug::log(LOG, "Executing {}", args);
|
||||
|
||||
const auto HLENV = getHyprlandLaunchEnv();
|
||||
const auto HLENV = getHyprlandLaunchEnv(pInitialWorkspace);
|
||||
|
||||
int socket[2];
|
||||
if (pipe(socket) != 0) {
|
||||
|
|
|
@ -149,7 +149,8 @@ class CKeybindManager {
|
|||
static void moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& dir = "");
|
||||
static void moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection);
|
||||
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 -------------- //
|
||||
static SDispatchResult killActive(std::string);
|
||||
|
|
Loading…
Reference in a new issue