pyewmh icon indicating copy to clipboard operation
pyewmh copied to clipboard

Attempting to activate windows with EWMH().setActiveWindow(window) on KDE Plasma.

Open pumpkinhi11 opened this issue 3 years ago • 0 comments

I'm creating a script that would allow me to activate a specific set of windows, however it doesn't seem to cooperate with KDE when using setActiveWindow.

I'm currently running Debian 10 Buster with KDE 5 Plasma as my desktop environment. When I tried using setActiveWindow all it would do was highlight the programs in my task bar. I am certain that window activation was possible in KDE through the Xlib library because the xdotool command was able to activate the windows without problem.

I wrote a small script comparing the use of both setActiveWindow and xdotool and tested in on KDE, Gnome and Xfce, for the later two ewmh seems to work fine without issue:

from ewmh import EWMH
from time import sleep
from os import system
from sys import argv

user_input = argv[1]
mode = argv[2]
ewmh = EWMH()
the_list = ewmh.getClientList()

def use_ewmh():     #using setActiveWindow, Python Xlib implementation
    for i in the_list:
        if mode == "0":                             #run "python3 test.py 0 0"
            sleep(1)
            ewmh.setActiveWindow(i)
            ewmh.display.flush()
        elif str(ewmh.getWmName(i)).count("Calc"):  #run "python3 test.py 0 1"
            ewmh.setActiveWindow(i)
            ewmh.display.flush()

def use_xdotool():  #using xdotool windowactivate, C implementation
    for i in the_list:
        the_id = str(i).find('0x')
        the_string = str(int(str(i)[the_id:the_id+10], 16))
        if mode == "0":                             #run "python3 test.py 1 0"
            sleep(1)
            system("xdotool windowactivate " + the_string)
        elif str(ewmh.getWmName(i)).count("Calc"):  #run "python3 test.py 1 1"
            system("xdotool windowactivate " + the_string)


if user_input == "0":
    use_ewmh()
else:
    use_xdotool()

I've recorded the results and the can be viewed here: https://www.youtube.com/watch?v=adgIoy7l1TU

pumpkinhi11 avatar Apr 05 '21 20:04 pumpkinhi11