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

pid selector for window rules (V2) #6653

Closed
leon-erd opened this issue Jun 24, 2024 · 10 comments
Closed

pid selector for window rules (V2) #6653

leon-erd opened this issue Jun 24, 2024 · 10 comments
Labels
enhancement New feature or request

Comments

@leon-erd
Copy link
Contributor

Description

Being able to target a specific window with a window rule using its pid would be really nice.
Currently, dynamic window rules are broken with the exec dispatcher because the dispatcher sets them only once, and as per the wiki: "dynamic window rules are re-evaluated every time a property changes" (for example changing the focus of the spawned window) which discards the rule set by the dispatcher (see #6593).
Under the hood, the exec dispatcher could set the dynamic window rules for the created window with the proposed pid selector which would fix this issue.
The pid selector would also fix #4648

@leon-erd leon-erd added the enhancement New feature or request label Jun 24, 2024
@MightyPlaza
Copy link
Contributor

use hyprctl setprop

@leon-erd
Copy link
Contributor Author

Ah I just found out that setprop supports pid
But its not mentioned anywhere.
On the hyprland wiki it only says in the example

hyprctl setprop address:0x13371337 forcenoanims 1 lock  # with locking
hyprctl setprop address:0x13371337 nomaxsize 0          # without locking

and hyprctl only gives this information

➜  ~ hyprctl setprop --help
usage: hyprctl [flags] setprop <regex> <property> <value> [lock]

regex:
    Regular expression by which a window will be searched
...

Do you know what selection options are available? Then I will add this to the wiki

@MightyPlaza
Copy link
Contributor

that's not a pid, it's the window address (aka the hex value at the start of hyprctl clients after 0x)

see the getWindowByRegex in src/Compositor.cpp for all the options

PHLWINDOW CCompositor::getWindowByRegex(const std::string& regexp) {
    if (regexp.starts_with("active"))
        return m_pLastWindow.lock();

    eFocusWindowMode mode = MODE_CLASS_REGEX;

    std::regex       regexCheck(regexp);
    std::string      matchCheck;
    if (regexp.starts_with("class:")) {
        regexCheck = std::regex(regexp.substr(6));
    } else if (regexp.starts_with("initialclass:")) {
        mode       = MODE_INITIAL_CLASS_REGEX;
        regexCheck = std::regex(regexp.substr(13));
    } else if (regexp.starts_with("title:")) {
        mode       = MODE_TITLE_REGEX;
        regexCheck = std::regex(regexp.substr(6));
    } else if (regexp.starts_with("initialtitle:")) {
        mode       = MODE_INITIAL_TITLE_REGEX;
        regexCheck = std::regex(regexp.substr(13));
    } else if (regexp.starts_with("address:")) {
        mode       = MODE_ADDRESS;
        matchCheck = regexp.substr(8);
    } else if (regexp.starts_with("pid:")) {
        mode       = MODE_PID;
        matchCheck = regexp.substr(4);
    } else if (regexp.starts_with("floating") || regexp.starts_with("tiled")) {
        // first floating on the current ws
        if (!valid(m_pLastWindow))
            return nullptr;

        const bool FLOAT = regexp.starts_with("floating");

        for (auto& w : m_vWindows) {
            if (!w->m_bIsMapped || w->m_bIsFloating != FLOAT || w->m_pWorkspace != m_pLastWindow->m_pWorkspace || w->isHidden())
                continue;

            return w;
        }

        return nullptr;
    }

@leon-erd
Copy link
Contributor Author

that's not a pid, it's the window address (aka the hex value at the start of hyprctl clients after 0x)

Yeah I know. I just found out that hyprctl setprop pid:<...> ... works.
Thanks! The snippet helps. Will make a MR for the wiki :)

@Vaisakhkm2625
Copy link

Vaisakhkm2625 commented Dec 3, 2024

for me still didn't worked :(, if i toggle the special workspace, the transparency would be lost..

bind = $mainMod SHIFT, o,exec, hyprctl setprop pid:$(hyprctl activewindow -j | jq .pid) alpha 0.8 

@leon-erd
Copy link
Contributor Author

leon-erd commented Dec 6, 2024

setprop has been moved from hyprctl to the dispatchers in this MR #8275.
So please try the dispatcher instead. Also you might try locking the rule.

@MightyPlaza why have you removed a lot of the documentation of the setprop command in this MR hyprwm/hyprland-wiki#832? You have only copied the prop list over but not the rest. Did you change something in the underlying code such that the documentation wasn't true anymore? Otherwise I think having the rest of the documentation in the wiki is very much needed. Else there is no mention anywhere of

  1. what locking does
  2. how the modes work
  3. where to find window address etc

@MightyPlaza
Copy link
Contributor

locking doesn't exist anymore, I removed it a while ago but didn't notice it was still in the wiki
the modes where removed since they're just duplicated from window parameters
address is what appears in hyprctl clients with 0x in front

bind = $mainMod SHIFT, o,setprop, active alpha 0.8

@leon-erd
Copy link
Contributor Author

leon-erd commented Dec 7, 2024

Thanks for the explanation!
In the wiki's window parameters there is only a mention of:
"activewindow an active window"
(Does this mean the first active window?)
Is active the same as activewindow?
This should also be mentioned then somewhere I think.

@MightyPlaza
Copy link
Contributor

it's anything that starts with active
see

PHLWINDOW CCompositor::getWindowByRegex(const std::string& regexp_) {
    auto regexp = trim(regexp_);

    if (regexp.starts_with("active"))
        return m_pLastWindow.lock();
    else if (regexp.starts_with("floating") || regexp.starts_with("tiled")) {
        // first floating on the current ws
        if (!valid(m_pLastWindow))
            return nullptr;

        const bool FLOAT = regexp.starts_with("floating");

        for (auto const& w : m_vWindows) {
            if (!w->m_bIsMapped || w->m_bIsFloating != FLOAT || w->m_pWorkspace != m_pLastWindow->m_pWorkspace || w->isHidden())
                continue;

            return w;
        }

        return nullptr;
    }

    eFocusWindowMode mode = MODE_CLASS_REGEX;

    std::regex       regexCheck(regexp_);
    std::string      matchCheck;
    if (regexp.starts_with("class:")) {
        regexCheck = std::regex(regexp.substr(6));
    } else if (regexp.starts_with("initialclass:")) {
        mode       = MODE_INITIAL_CLASS_REGEX;
        regexCheck = std::regex(regexp.substr(13));
    } else if (regexp.starts_with("title:")) {
        mode       = MODE_TITLE_REGEX;
        regexCheck = std::regex(regexp.substr(6));
    } else if (regexp.starts_with("initialtitle:")) {
        mode       = MODE_INITIAL_TITLE_REGEX;
        regexCheck = std::regex(regexp.substr(13));
    } else if (regexp.starts_with("address:")) {
        mode       = MODE_ADDRESS;
        matchCheck = regexp.substr(8);
    } else if (regexp.starts_with("pid:")) {
        mode       = MODE_PID;
        matchCheck = regexp.substr(4);
    }

@leon-erd
Copy link
Contributor Author

Thanks! :)

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

No branches or pull requests

3 participants