You are not logged in.

#1 2022-08-10 10:30:28

shako
Member
Registered: 2021-11-16
Posts: 50

dmenu/dwm: select running app and swith to relative tag

I found this pretty cool script which presumably creates a dmenu menu with all running applications, lets you select one of the entries, and then switches to the relative tab in dwm. I would love to add such a feature to my dwm build. Problem is, if run as it is, it only highlights the tab which contains the selected application, without switching to it. I would like to add such feature to the script. May someone help me?

Here is the script: https://github.com/jukil/dmenu-scripts- … nning_apps

Dependencies are xdotool and xorg-xlsclients, and (obviously) dmenu.

According to the xdotool manpage:

_NET_ACTIVE_WINDOW
           Allows you to query and set the active window by asking the window manager to bring it forward. Support for
           this enables these commands: "windowactivate", "getactivewindow".

So I think that may be a key piece.

Also:

_NET_WM_DESKTOP
           Query and set what desktop a window is living in. Support for this enables these commands:
           "set_desktop_for_window", "get_desktop_for_window".

Which seems even more pertinent, but running $ xdotool get_desktop_for_window "APPLICATION_NAME" gives me:

Your windowmanager claims not to support _NET_WM_DESKTOP, so the attempt to query a window's desktop location was aborted.
0

So I think dwm simply does not support this feature (I'm not sure "desktop" is equivalent to "tag" in this context, but whatever).

May someone give me a hint on how to correct the script?

Offline

#2 2022-08-10 12:49:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,520
Website

Re: dmenu/dwm: select running app and swith to relative tag

That script only activates the window - it does not switch tags (unless dwm is otherwise configured to switch to a tag on window activiation).  But the bigger issue here is the core logic of what you want the script to do simply cannot work on dwm.  A client in dwm can be on several tags -  so assuming you detect the bitmask field that defines a given clients tag memberships, which one would you want activated?  Perhaps you could activate just the first tag that a given client belongs to.

This would be done in dwms code, however, not in a script.  Just add a function to dwm that pipes/forks/runs dmenu, cycles through the client list feeding titles to dmenu's stdin, then reads the result, cycles through the list again to find that client, then switches to the first tag in that client's tags field.  You'd then bind this function to a keypress and you'd be all set.

Last edited by Trilby (2022-08-10 12:54:49)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2022-08-10 14:56:48

shako
Member
Registered: 2021-11-16
Posts: 50

Re: dmenu/dwm: select running app and swith to relative tag

Thank you @Trilby. I managed to fix everything just by applying the focusonnetactive patch. Now the script work as intended, but you are right: if I have, for instance, multiple instances of the same app open over different tagspaces, I  seem to switch to the last evoked one. I didn't think about it. Do you have some tip on how to refine my script?

Last edited by shako (2022-08-10 14:57:38)

Offline

#4 2022-08-10 15:31:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,520
Website

Re: dmenu/dwm: select running app and swith to relative tag

I wasn't referring to several instances of the same program, but rather how dwm tags work.  A single window can be assigned many tags.

For mutliple windows withe same identifier I'd just get the list of windows once (with window ids), feed that list to dwm, then activate the selected window by id rather than by just trying to match a title/class-name.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB