pythonx11xcbewmh

Can't change _NET_WM_STRUT_PARTIAL property


I want to reserve some space on the screen for my Gtk application written in Python. I've wrote this function:

import xcb, xcb.xproto
import struct
def reserve_space(xid, data):
    connection = xcb.connect()
    atom_cookie = connection.core.InternAtom(True, len("_NET_WM_STRUT_PARTIAL"), 
        "_NET_WM_STRUT_PARTIAL")
    type_cookie = connection.core.InternAtom(True, len("CARDINAL"), "CARDINAL")
    atom = atom_cookie.reply().atom
    atom_type = type_cookie.reply().atom
    data_p = struct.pack("I I I I I I I I I I I I", *data)
    strat_cookie = connection.core.ChangeProperty(xcb.xproto.PropMode.Replace, xid,
        atom, xcb.xproto.Atom.CARDINAL, 32, len(data_p), data_p)
    connection.flush()

It's call looks like this:

utils.reserve_space(xid, [0, 60, 0, 0, 0, 0, 24, 767, 0, 0, 0, 0])

Unfortunately, it doesn't work. Where is an error in my code?

UPD: Here is my xprop output. My WM is Compiz.


Solution

  • Changing to using ChangePropertyChecked(), and then checking the result gives a BadLength exception.

    I think the bug here is that the ChangeProperty() parameter data_len is the number of elements of the size given by format , not the number of bytes, in the property data data.

    Slightly modified code which works for me:

    def reserve_space(xid, data):
        connection = xcb.connect()
        atom_cookie = connection.core.InternAtom(False, len("_NET_WM_STRUT_PARTIAL"),
            "_NET_WM_STRUT_PARTIAL")
        atom = atom_cookie.reply().atom
        data_p = struct.pack("12I", *data)
        strat_cookie = connection.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, xid,
            atom, xcb.xproto.Atom.CARDINAL, 32, len(data_p)/4, data_p)
        strat_cookie.check()
        connection.flush()