Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing window border in Python xlib

Tags:

python

xlib

I'm working on a window manager written using python's xlib bindings and I'm (initially) attempting to mimic dwm's behavior in a more pythonic way. I've gotten much of what I need, but I'm having trouble using X's built in window border functionality to indicate window focus.

Assuming I've got an instance of Xlib's window class and that I'm reading the documentation correctly, this should do what I want to do (at least for now) - set the window border of a preexisting window to a garish 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 get nothing from this - I can add print statements to prove that my program is indeed running the callback function that I associated with the event, but I get absolutely no color change on the border. Can anyone identify what exactly I'm missing here? I can pastebin a more complete example, if it will help. I'm not exactly sure it will though as this is the only bit that handles the border.

like image 556
bbenne10 Avatar asked Oct 08 '22 00:10

bbenne10


1 Answers

Looks like this was complete PEBKAC. I've found an answer. Basically, I was doing 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 confusing X enough that it was doing nothing. The solution that I've stumbled upon was to remove the border_width portion from the window.change_attributes() call, like so:

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 on down the road!

like image 190
bbenne10 Avatar answered Oct 13 '22 12:10

bbenne10