Skip to content

Commit

Permalink
workspacerules: fix on-created-empty window focus (#7657)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungyoonc authored Sep 5, 2024
1 parent 727f1b5 commit 0fad7a0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/desktop/Workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)});
Expand Down
32 changes: 20 additions & 12 deletions src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);

Expand All @@ -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, ';');
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/managers/KeybindManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0fad7a0

Please sign in to comment.