baskerville / bspwm

A tiling window manager based on binary space partitioning
BSD 2-Clause "Simplified" License
7.72k stars 415 forks source link

better window matching for rules #1078

Closed absolutelynothelix closed 1 year ago

absolutelynothelix commented 4 years ago

can we have some love for rules? currently we can match windows either by class name or by instance name. it would be amazing if we could also match them by at least role.

i know about external_rules_command but i think matching windows by rule is basic enough to be implemented on our own.

if you're wondering, i'm trying to write a rule for firefox's picture-in-picture window and probably the only thing that allows to identify it is it's role.

i know that most likely i won't get any reply on this, but... hope dies last

emanuele6 commented 4 years ago

What is a the "role" of a window? What do you mean? @mighty9245

absolutelynothelix commented 4 years ago

@emanuele6, the WM_ROLE window property

emanuele6 commented 4 years ago

@mighty9245, I've never heard of it, but most windows don't have it: I tried checking the WM_ROLE of an urxvt window (see screenshot) and of a qutebrowser window and they both didn't have it.

wm_role_no_such_atom

Since most window don't even have this I don't see the point of being able to match windows via this atom when using bspc rule. You can easily just check the output of xprop -id "$1" WM_ROLE in your external_rules_command script if you want to apply a rule based on that atom.

Are you sure this is a standard atom? I can't find any reference to it online. Keep in mind that any atom can be set/created; e.g.:

xprop -id "$(pfw)" -format HELLO_WORLD 8s -set HELLO_WORLD 'hi there'

(set the focused window's HELLO_WORLD atom to hi there)


pfw

absolutelynothelix commented 4 years ago

oh, it's called WM_WINDOW_ROLE, my bad. i don't have much apps to test, but at least firefox, discord, atom and thunar have it.

emanuele6 commented 4 years ago

WM_WINDOW_ROLE

@mighty9245, I tried checking it on urxvt and qutebrowser and they didn't have it. I also checked on telegram-desktop and zathura and it doesn't have it. I even tried polybar and it doesn't have it.

That's basically all the GUI programs I use, none of them have it! It clearly is not as used as WM_CLASS and WM_NAME, you can just xprop -id "$1" WM_WINDOW_ROLE in your external rules script if you want to make a rule based on that; as you would do with the other uncoventional/custom atoms.

emanuele6 commented 4 years ago

@mighty9245, I just tried checking it on krita and it has it:

$ xprop -id "$(xdo id -Nkrita -nkrita | head -1)" WM_WINDOW_ROLE
WM_WINDOW_ROLE(STRING) = "MainWindow#1"

Most programs don't have it though; there is no point in allowing to set a rule based on this atom that most windows don't even have!


You can use:

#!/bin/env bash

wid="$1"
class="$2"
instance="$3"
window_role="$(xprop -id "$wid" WM_WINDOW_ROLE | sed -nE 's,^WM_WINDOW_ROLE[(]STRING[)] = "(.*)"$,\1,p')"

[[ "$class" = krita && "$instance" = krita && "$window_role" = MainWindow#1 ]] \
    && echo layer=below

(apply layer=below to windows which have class=krita, instance=krita and WM_WINDOW_ROLE=MainWindow#1)

This also has the benefit that you can use regular expression matching, i.e.

[[ "$class" = krita && "$instance" = krita && "$window_role" =~ ^MainWindow# ]] \
    && echo layer=below

(apply layer=below to windows which have class=krita, instance=krita and WM_WINDOW_ROLE that starts with MainWindow#)

I don't know how a WM_WINDOW_ROLE atom looks in general, but if they looks like krita's (i.e. something#n), you probably want regex matching or a custom matching anyway.

absolutelynothelix commented 1 year ago

i'm not using bspwm anymore, so i'm closing this to reduce the amount of open issues.