1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-11 13:51:02 -05:00

tests: common: factor out intern atom calls

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2020-04-10 16:47:06 +01:00
parent 1614ae60a7
commit f504b1d37e
No known key found for this signature in database
GPG key ID: 37C999F617EA1A47

View file

@ -4,31 +4,28 @@ import xcffib
import time import time
import random import random
import string import string
def to_atom(conn, string):
return conn.core.InternAtom(False, len(string), string).reply().atom
def set_window_name(conn, wid, name): def set_window_name(conn, wid, name):
prop_name = "_NET_WM_NAME" prop_name = to_atom(conn, "_NET_WM_NAME")
prop_name = conn.core.InternAtom(False, len(prop_name), prop_name).reply().atom str_type = to_atom(conn, "UTF8_STRING")
str_type = "UTF8_STRING"
str_type = conn.core.InternAtom(False, len(str_type), str_type).reply().atom
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, prop_name, str_type, 8, len(name), name).check() conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, prop_name, str_type, 8, len(name), name).check()
prop_name = "WM_NAME" prop_name = to_atom(conn, "WM_NAME")
prop_name = conn.core.InternAtom(False, len(prop_name), prop_name).reply().atom str_type = to_atom(conn, "STRING")
str_type = "STRING"
str_type = conn.core.InternAtom(False, len(str_type), str_type).reply().atom
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, prop_name, str_type, 8, len(name), name).check() conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, prop_name, str_type, 8, len(name), name).check()
def set_window_class(conn, wid, name): def set_window_class(conn, wid, name):
if not isinstance(name, bytearray): if not isinstance(name, bytearray):
name = name.encode() name = name.encode()
name = name+b"\0"+name+b"\0" name = name+b"\0"+name+b"\0"
prop_name = "WM_CLASS" prop_name = to_atom(conn, "WM_CLASS")
prop_name = conn.core.InternAtom(False, len(prop_name), prop_name).reply().atom str_type = to_atom(conn, "STRING")
str_type = "STRING"
str_type = conn.core.InternAtom(False, len(str_type), str_type).reply().atom
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, prop_name, str_type, 8, len(name), name).check() conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, prop_name, str_type, 8, len(name), name).check()
def find_picom_window(conn): def find_picom_window(conn):
prop_name = "WM_NAME" prop_name = to_atom(conn, "WM_NAME")
prop_name = conn.core.InternAtom(False, len(prop_name), prop_name).reply().atom
setup = conn.get_setup() setup = conn.get_setup()
root = setup.roots[0].root root = setup.roots[0].root
windows = conn.core.QueryTree(root).reply() windows = conn.core.QueryTree(root).reply()