Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executing with rules on other program #8949

Open
littleblack111 opened this issue Jan 4, 2025 · 12 comments · May be fixed by #9479
Open

executing with rules on other program #8949

littleblack111 opened this issue Jan 4, 2025 · 12 comments · May be fixed by #9479
Labels
enhancement New feature or request

Comments

@littleblack111
Copy link
Contributor

Description

for example i have this exec that launches a floating window:

[float; size 40% 40%; workspace +0] program

this would work if the program created the window it's self, but for example, thunar have --daemon, then thunar with those rules wouldn't work as the windows are opened by the daemon. other applications with similar logics includes alacritty, ghostty(ghostty-org/ghostty#2442) etc

so a solution i thought of to this is to temporarily set the rules on another program(user specified)

@littleblack111 littleblack111 added the enhancement New feature or request label Jan 4, 2025
@vaxerski
Copy link
Member

vaxerski commented Jan 4, 2025

with a daemon I fail to see how we could handle that (other than, well, windowrules)

@littleblack111
Copy link
Contributor Author

with a daemon I fail to see how we could handle that (other than, well, windowrules)

Because the window rule applied to the client which just told the demand to spawn a window instead of spawning a window it's self, but the demon isn't affected by the window rule as the demon isn't launched with those rules

@littleblack111
Copy link
Contributor Author

littleblack111 commented Jan 12, 2025

i think we should add a window rule for that for something like "global"(e.g. [global; float]). and instead of getting the PID of that proc process(which is what we're doing rn), do something like a pidof to all of processes with the same name

Edit: typo

@vaxerski
Copy link
Member

...what?

@littleblack111
Copy link
Contributor Author

littleblack111 commented Jan 15, 2025

right now, exec calls spawn() which calls spawnWithRule() which have

    const uint64_t PROC = spawnRawProc(args, pInitialWorkspace);

...

            g_pConfigManager->addExecRule({r, (unsigned long)PROC});

only applying the rules to the PROC that it have just spawned(assuming PROC is it's PID).

but.. since instead of that proc spawning the program, the proc is communicating with the daemon with IPC, then the daemon will spawn the process, making the addexecrule useless.

so my proposed solution is that we find all the process with same name by it's pid (similar to the pidof program) then apply the rules to all of them. gated by a specifier(such as "global") which should be parsed in the spawnWithRule()(which should do the above), thus the daemon have those rules too, so spawning the program with rules would work.

also, i think we should delete those rules after it's spawned(maybe as a subprocess after a delay?) since the daemon could have a lot of rules that contradict with each other or chaos

@vaxerski
Copy link
Member

how would you match it though?

We create a process with PID X
it finds a server via some random pipe and sends it a request
PID X dies
PID Y opens a window

@littleblack111
Copy link
Contributor Author

Usually daemons are the same binary such as thunar's daemon is still thunar but with the --daemon argument

So I suggested applying the rule to all process names the same as PROC(I'm guessing you can directly filter by that or get its proc id after spawn)

@vaxerski
Copy link
Member

but how do we know what is the "name" of pid X?

@littleblack111
Copy link
Contributor Author

get it from /proc/pid/comm?

@vaxerski
Copy link
Member

that's not portable

@littleblack111
Copy link
Contributor Author

from stackoverflow:

Use the kinfo_getproc function
pid_t pid = ...;
struct kinfo_proc *proc = kinfo_getproc(pid);
if (proc) {
printf("Name %s\n", proc->ki_comm);
//ki_comm should be the program name
//see the sys/user.h header file for other relevant fields.
free(proc);
}

@jbeich
Copy link
Contributor

jbeich commented Jan 25, 2025

kinfo_getproc doesn't exist on DragonFly, NetBSD, OpenBSD. ki_comm does but named differently (affects the whole struct kinfo_proc, see ki_ppid example in Hyprland). For portability use sysctl directly instead of going through libutil, libkvm, libprocstat.

Note, linprocfs(5) lacks /proc/<pid>/comm (aka argv[0]) unlike /proc/<pid>/cmdline (NUL-separated argv[]). It's easier to test/port the latter e.g., https://gitlab.freedesktop.org/libinput/libei/-/commit/cc046f1f6719

@littleblack111 littleblack111 linked a pull request Feb 24, 2025 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants