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

Query to find active window on unfocused desktop not working #1474

Open
tom8347 opened this issue Nov 28, 2023 · 7 comments
Open

Query to find active window on unfocused desktop not working #1474

tom8347 opened this issue Nov 28, 2023 · 7 comments

Comments

@tom8347
Copy link

tom8347 commented Nov 28, 2023

I have 1 monitor with 9 desktops. I'm trying to write a script which will give me informatio about windows on the various desktops. I want to get the id/name of the window on each desktop that has focus on that desktop. Looking at the man page I thought it should be something like bspc query -N -n .window.active -d 4, for desktop 4 for example, and similar for all the desktops. This doesn't return anything.

I should note that bspc query -N -n .window -d 4 and bspc query -N -n .window.!active -d 4 both return the expected list of window IDs.

bspc query -N -n .window -d 4 returns 0x0680000E 0x04A00003 0x04800003 (as expected, all the windows I can see on desktop 4)

bspc query -N -n .window.!active -d 4 returns 0x0680000E 0x04800003 (as expected all the windows on desktop 4 apart from the one which has focus

@tom8347 tom8347 changed the title q Query to find active window on unfocused desktop not working Nov 28, 2023
@emanuele6
Copy link
Contributor

emanuele6 commented Nov 28, 2023

Hm, yes, I recall .active not working correctly for nodes, and having to work around it in one of my script a while ago, but I don't think I have ever actually investigated the issue.

As a workaround, if you need to get this information, you can use query -T (or wm -d) and extract it from the JSON output:

# "bspc query -N -n .window.active"
bspc wm -d |
jq '
  .monitors[].dekstops[] |
  # active nodes
  first(
    .focusedNodeId as $activeid |
    .root |
    .. |
    select(.id? == $activeid)
  ) |
  # that are windows
  select(.client)
  .id
'

# "bspc query -N -n '.window.!active' -d 4"
bspc query -T -d 4 |
jq '
  .focusedNodeId as $activeid |
  .root |
  .. |
  # windows
  select(.client?)
  .id |
  # that are not the active node
  select(. != $activeid)
'

# "bspc query -N -n '.window.active' -d 4"
bspc query -T -d 4 |
jq '
  # the active node
  first(
    .focusedNodeId as $activeid |
    .root |
    .. |
    select(.id? == $activeid)
  ) |
  # only if it is a window
  select(.client)
  .id
'

@tom8347
Copy link
Author

tom8347 commented Nov 28, 2023

Thanks for the information

@tom8347
Copy link
Author

tom8347 commented Nov 29, 2023

This works but seems to be slowing my script down quite a bit. I'm not sure what exactly is slowing it down (whether it's the bspc call or the jq call). Is there any way of speeding it up?

@ortango
Copy link

ortango commented Dec 4, 2023

does changing the second active conditional in query.c:node_matches() to

if (sel->active != OPTION_NONE &&
    loc->desktop == mon->desk) {
        return false;
}

give you expected output? removing that second conditional entirely would get focused included with active, which allows for .active.!focused which I like more.


update: this is wrong, and should be ignored. It does seem to give sane output on a single monitor setup, but totally incorrect on a multimonitor setup.

@tom8347
Copy link
Author

tom8347 commented Dec 4, 2023

Not sure what you mean by the second conditional in query.c:node_matches()? How should I modify

# "bspc query -N -n '.window.active' -d 4"
bspc query -T -d 4 |
jq '
  # the active node
  first(
    .focusedNodeId as $activeid |
    .root |
    .. |
    select(.id? == $activeid)
  ) |
  # only if it is a window
  select(.client)
  .id
'

to test what you mean?

@ortango
Copy link

ortango commented Dec 4, 2023

@tom8347 in bspwm's source:

bspwm/src/query.c

Lines 1104 to 1109 in af3bd8b

if (sel->active != OPTION_NONE &&
loc->desktop != loc->monitor->desk
? sel->active == OPTION_TRUE
: sel->active == OPTION_FALSE) {
return false;
}

@tom8347
Copy link
Author

tom8347 commented Dec 4, 2023

Oh I see. I'm not sure. If I'm feeling adventurous I'll try to have a look later. I don't usually poke around in source code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants