You are not logged in.

#1 2022-01-12 19:58:26

zictes
Member
Registered: 2021-05-23
Posts: 10

Can't switch windows with xdotool

I'm trying to create a script that will launch budgie's window switcher and hide all unfocused windows after it exits, but I can't get it to reliably open the window switcher.

I've tried these two approaches with xdotool, but both of them are extremely janky and only trigger the window switcher very vary rarely.

xdotool key alt+Tab
xdotool keydown alt key Tab; sleep 2; xdotool keyup alt

Most of the time both commands produce don't trigger the switcher and instead write this cryptic output to the terminal:

^[	%       

I'd like to avoid this janky way of emulating pressing alt and tab if possible, but I couldn't find any way to directly launch the window switcher. It doesn't seem to have its own executable, and the manpage for wmctrl also doesn't say anything about a command for the window switcher.

Offline

#2 2022-01-12 20:25:02

seth
Member
Registered: 2012-09-03
Posts: 26,568

Re: Can't switch windows with xdotool

"… keydown alt keydown Tab; sleep …; … keyup Tab keyup alt"?
Does the budgie WM maybe provide a dbus interface to activate that in a somewhat meaningful fashion?

Also:

launch budgie's window switcher and hide all unfocused windows after it exits

I'm not familiar w/ budgie or its WM but do you maybe want to use wmctrl to activate a specific window (and/or hide all others)?

Online

#3 2022-01-13 08:47:53

zictes
Member
Registered: 2021-05-23
Posts: 10

Re: Can't switch windows with xdotool

Thanks for your help again!

I contacted the budgie developers on their github page, you were right about the dbus interface: https://github.com/BuddiesOfBudgie/budg … ussions/33

It's kind of a pain though since you have to pass all available windows and the target window for switching manually, and doesn't even solve the problem since the tab switcher is hardcoded to close immediately if alt+tab or whatever combination you set in the keyboard settings is not pressed.

It's too bad there is no dbus message sent for the tab switcher exiting, that would allow me to run my own script to hide the other windows at that point.

I'm not familiar w/ budgie or its WM but do you maybe want to use wmctrl to activate a specific window (and/or hide all others)?

I thought about that too, but I would have preferred to just use the budgie tab switcher as is with the added feature of minimizing everything except for the new active window. wmctrl doesn't offer the selection menu that the budgie tab switcher does, I would have to create something like that from scratch or just use a different tab switcher.

Last edited by zictes (2022-01-13 08:48:41)

Offline

#4 2022-01-13 09:03:44

seth
Member
Registered: 2012-09-03
Posts: 26,568

Re: Can't switch windows with xdotool

And if you delay the tab release w/ xdotool (possibly doesn't even have to be long - in case there's conditional behaviour to display the switcher or just juggle the window, depending on brief the shortcut is held)?

Online

#5 2022-01-13 14:49:12

zictes
Member
Registered: 2021-05-23
Posts: 10

Re: Can't switch windows with xdotool

I tried that too, doesn't seem to make any difference.

I'm afraid the alt+tab emulation approach is impossible anyways, since you can't have a custom and system keyboard shortcut for the script mapped to the same combination. Budgie/Gnome will simply deactivate the tab switcher as soon as you use alt+tab for your custom shortcut.

That's exactly what it would take to make this work though, since you have to be holding that exact key combination, whether its alt+tab or something else, otherwise you won't be able to use the tab switcher even if you manage to properly launch it with a script.

Last edited by zictes (2022-01-13 14:49:41)

Offline

#6 2022-01-13 16:05:53

seth
Member
Registered: 2012-09-03
Posts: 26,568

Re: Can't switch windows with xdotool

The way those switchers usually work is that you press alt+tab and as long as you keep alt pressed, the tab key will select the next window - same with budgie?

In that case sth. like

xdotool keydown alt keydown Tab sleep 0.1 keyup Tab sleep 10 keyup alt

should trigger the tabbox and allow you to navigate it by only pressing tab.

Pitfalls:
- if the shortcut for your script involves the Alt key, you'll likely trigger a release w/ that
- the shortcut daemon might grab the input/server

The mitigation for both is the same: have the script eg. "sleep 0.25" ahead of everything in order to give yourself some time to release the shortcut keys before the actual xdotool action starts

Edit: maybe elaborate what your actual functional goal is here

Last edited by seth (2022-01-13 16:06:21)

Online

#7 2022-01-14 10:31:14

zictes
Member
Registered: 2021-05-23
Posts: 10

Re: Can't switch windows with xdotool

The goal is to switch windows in a way analog to creating an isolated workspace for each new window. I have gone back and forth between stacking and tiling wm's for a long time now, and I'm not really satisfied with either. Stacking wm's feel clunky since they're usually designed for cursor interaction with keyboard as an afterthought, and tiling wm's usually have problems dealing with applications that were designed for stacking, especially when it comes to small pop-up dialogs.

This is one step towards something I'd actually be happy with, allowing windows to keep their preferred size while removing the clutter of windows stacking over each other.

I've settled on this solution for now:

#!/bin/bash

interface=org.budgie_desktop.TabSwitcher
member=ShowSwitcher

dbus-monitor --profile "interface='$interface',member='$member'" |
while read -r line; do
  sleep .05
  wmctrl -k on
done

This script monitors dbus for the method that budgie calls internally to open the tab switcher, and then minimizes all windows right away as the tab switcher opens. I would have preferred to minimize everything after selecting a new window in the tab switcher, but this works too. The short sleep is there to prevent the tab switcher window from getting hidden as well, don't know why that happens without the delay since it's not really a window.

Kind of a stupid way to do it, but still better than reimplementing the whole tab switcher logic to call the dbus methods from a script. I've asked the budgie devs if they would consider giving their tab switcher a /usr/bin command that can receive the two keys to operate it as arguments, maybe something will come of that and this mess will be obsolete in the future. Most budgie apps like the run dialog or the window shuffler have an executable already, the tab switcher seems to be the only exception.

Last edited by zictes (2022-01-14 10:33:36)

Offline

#8 2022-01-14 14:57:29

seth
Member
Registered: 2012-09-03
Posts: 26,568

Re: Can't switch windows with xdotool

#!/bin/bash
while read actwin; do
    actwin=0x${actwin##* 0x}
    ((actwin == 0x0)) && continue
    leader="$(xprop -notype -id $actwin WM_CLIENT_LEADER)"
    leader=0x${leader##* 0x}
    [[ "$leader" = "0xWM_CLIENT_LEADER"* ]] && unset leader
    while read somewin junk; do
        ((somewin == actwin)) && continue
        if [ -n "$leader" ]; then
            someleader="$(xprop -notype -id $somewin WM_CLIENT_LEADER)"
            someleader=0x${someleader##* 0x}
            [[ "$someleader" != "0xWM_CLIENT_LEADER"* ]] && ((someleader == leader)) && continue
        fi
        wmctrl -i -r $somewin -b add,hidden
    done < <(wmctrl -l)
done < <(xprop -root -spy _NET_ACTIVE_WINDOW)

Online

#9 2022-01-14 16:04:53

zictes
Member
Registered: 2021-05-23
Posts: 10

Re: Can't switch windows with xdotool

Thanks, unfortunately doesn't work on my end. I just added this script to a custom shortcut in the budgie settings, is there something else I need to do? Doesn't produce any errors when I run it from the terminal, just does nothing. I definitely have wmctrl and xprop, is there another dependency I'm missing?

Offline

#10 2022-01-14 16:50:55

seth
Member
Registered: 2012-09-03
Posts: 26,568

Re: Can't switch windows with xdotool

The script is supposed  to run continuously in the backround.
It monitors the _NET_ACTIVE_WINDOW on the root window (which is supposed to be updated when the active window changes, you can try "xprop -root -spy _NET_ACTIVE_WINDOW" in an interactive shell) and then looks around what windows to hide.

Online

Board footer

Powered by FluxBB