You are not logged in.

#1 2022-10-07 09:26:18

zw963
Member
Registered: 2018-06-18
Posts: 213

Write a script to switch to konsole in Wayland from other app.

Hi, I want to write a bash script, the expected behavior is: (assume i binding it to S_SPC)

- if current app is not konsole, when pressing S_SPC, switch and active konsole.
- if current app is konsole, when pressing S_SPC, switch back to previous come from app.
- i should switch to konsole from any app and back.

In fact, i wrote a script, it work quite well for several years, use wmctrl. but only for Xorg or Xwayland.

The reason i use wmctrl is, i can know how many app is current opened use following command:


 ╰─ $ wmctrl -xl
0x01200007  0 konsole.konsole       lggram   — Konsole
0x01e0003e  0 Navigator.firefox     lggram Post new topic / Arch Linux Forums — Mozilla Firefox
0x0200052f  0 emacs.Emacs           lggram ~/.profile - Emacs 28.2.50

And, i can get the current active window id use:

 ╰─ $ printf "0x%08x" `xprop -root _NET_ACTIVE_WINDOW |egrep -oe '0x[a-f0-9]+'|head -n1`
0x01200007

So, i current know the active window is konsole, if i want to active the firefox, i can switch and active use wmctrl

 ╰─ $ wmctrl -i -a 0x01e0003e  # here 0x01e0003e is firefox process id

Okay, it time to explain my issue.

As post on https://bbs.archlinux.org/viewtopic.php?id=279607,  firefox not work well with Xwayland.
this issue take effect a lot for me, but i don't want give me firefox anyway.

so, i have to switch to wayland instead use `export MOZ_ENABLE_WAYLAND=1`

But, the issue is, if firefix working on wayland mode, the firefox is missing when use `wmctrl -lx`.

So, my question is:

Is there another command line tools is equivalent to the wmctrl in wayland?

Or, maybe i need keeping move on to use a more robust solution to archive same effect instead,
i am really a old fashion linux user, probably don't know many new things, any advice?

Thank you.

Last edited by zw963 (2022-10-07 09:34:29)

Offline

#2 2022-10-07 10:23:35

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,263

Re: Write a script to switch to konsole in Wayland from other app.

"Wayland" is not a single entity like "Xorg" and theere's is no single API for managing arbitrary clients like on xorg. Doing anything like this depends on your compositor which is managing your windows. Assuming this is KDE you^ll need to script this for KWin. You can either do this with KWin's built-in scripting API: https://develop.kde.org/docs/extend/plasma/kwin/ or via dbus calls.

Last edited by V1del (2022-10-07 10:24:12)

Offline

#3 2022-10-07 10:33:48

arojas
Developer
From: Spain
Registered: 2011-10-09
Posts: 2,291

Re: Write a script to switch to konsole in Wayland from other app.

Have you considered using yakuake? It seems to me that it would do exactly what you want without needing to tinker with shortcuts and window managers.

Online

#4 2022-10-07 14:41:24

zw963
Member
Registered: 2018-06-18
Posts: 213

Re: Write a script to switch to konsole in Wayland from other app.

arojas wrote:

Have you considered using yakuake? It seems to me that it would do exactly what you want without needing to tinker with shortcuts and window managers.

Hi,  i try it,  i found some feature(keybinding) not available.

e.g.

-  Toggle maximum current view.
- Enlarge font
- Shrink font

And, I consider yakuake still not stable enough, right?

I meet really bad performance when i enable auto hide when i disable `keep window open when it loses focus`.

Last edited by zw963 (2022-10-07 15:02:35)

Offline

#5 2022-10-07 14:49:54

zw963
Member
Registered: 2018-06-18
Posts: 213

Re: Write a script to switch to konsole in Wayland from other app.

V1del wrote:

"Wayland" is not a single entity like "Xorg" and theere's is no single API for managing arbitrary clients like on xorg. Doing anything like this depends on your compositor which is managing your windows. Assuming this is KDE you^ll need to script this for KWin. You can either do this with KWin's built-in scripting API: https://develop.kde.org/docs/extend/plasma/kwin/ or via dbus calls.


i use all GNOME default components, i am not sure, mutter, right?
How to do same things for GNOME?

Offline

#6 2022-10-13 11:00:01

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,263

Re: Write a script to switch to konsole in Wayland from other app.

By writing a GNOME extension: https://gjs.guide/extensions/development/creating.html

https://gjs.guide/extensions/overview/a … tml#mutter

FWIW I found https://extensions.gnome.org/extension/ … dow-calls/ which will expose these things via DBUS and will allow you to script it via the command line directly, see the documentation in the github link.

Last edited by V1del (2022-10-13 11:11:10)

Offline

#7 2022-10-13 12:40:33

zw963
Member
Registered: 2018-06-18
Posts: 213

Re: Write a script to switch to konsole in Wayland from other app.

V1del wrote:

By writing a GNOME extension: https://gjs.guide/extensions/development/creating.html

https://gjs.guide/extensions/overview/a … tml#mutter

FWIW I found https://extensions.gnome.org/extension/ … dow-calls/ which will expose these things via DBUS and will allow you to script it via the command line directly, see the documentation in the github link.

Cool, thank you.

Offline

#8 2022-10-14 09:58:21

zw963
Member
Registered: 2018-06-18
Posts: 213

Re: Write a script to switch to konsole in Wayland from other app.

zw963 wrote:
V1del wrote:

By writing a GNOME extension: https://gjs.guide/extensions/development/creating.html

https://gjs.guide/extensions/overview/a … tml#mutter

FWIW I found https://extensions.gnome.org/extension/ … dow-calls/ which will expose these things via DBUS and will allow you to script it via the command line directly, see the documentation in the github link.

Cool, thank you.

Hi, this new extension not work, partly

i do some hack myself on my fork https://github.com/zw963/window-calls to output the focus attribute when get current window list.

but, there is another issue:  this extension only activate a window, but not focus the cursor on it, e.g.

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Activate 11223

the window of id 11223 is active, and show foreground, but the cursor not focus, any idea?

Thank you.

Last edited by zw963 (2022-10-14 10:07:40)

Offline

Board footer

Powered by FluxBB