Drawing window border in Python xlib

I am working on a window manager written using xlib python bindings, and I (initially) try to mimic dwm behavior in a more pythonic way. I got a lot of what I need, but I'm having trouble using the X window's built-in function to indicate the focus of the window.

Assuming I have an instance of the Xlib window class and that I am reading the documentation correctly, this should do what I want to do (at least for now) - set the window border of the existing window to a bright color and set the border width to 2px.

def set_active_border(self, window):
    border_color = self.colormap.alloc_named_color(\
        "#ff00ff").pixel
    window.change_attributes(None,border_pixel=border_color,
           border_width = 2 )
    self.dpy.sync()

However, I don’t get anything from this - I can add print statements to prove that my program actually performs the callback function associated with the event, but I get absolutely no color change at the border. Can anyone determine what exactly I'm missing here? I can use a more complete example if this helps. I'm not sure what it will be, although this is the only bit that handles the border.

+5
source share
1 answer

It looks like it was full PEBKAC. I have found the answer. Essentially, I did this:

def set_active_border(self, window):
    border_color = self.colormap.alloc_named_color(
        "#ff00ff"
    ).pixel
    window.configure(border_width=2)
    window.change_attributes(
         None,
         border_pixel=border_color,
         border_width=2)
    self.dpy.sync()

Apparently, this was so confusing to X that he did nothing. The solution I came across was to remove the border_width part from the call to window.change_attributes (), like this:

def set_active_border(self, window):
    border_color = self.colormap.alloc_named_color(
        "#ff00ff"
    ).pixel
    window.configure(border_width=2)
    window.change_attributes(
        None,
        border_pixel=border_color
    )
    self.dpy.sync()

I hope this helps someone later in the future!

+4
source

All Articles