parkouss / pyewmh

An implementation of EWMH (Extended Window Manager Hints) for python, based on Xlib.
GNU Lesser General Public License v3.0
40 stars 15 forks source link

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

Open pumpkinhi11 opened 3 years ago

pumpkinhi11 commented 3 years ago

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