Wednesday, 28 November 2018

Xlib ConfigureRequest with custom configuration not working

I am using python and python3-xlib (which is a pure python implementation of the Xlib interface but basically is very similar to the C Xlib). For educational purposes, I am trying to create a simple window manager which should be able to force windows to have some specific sizes, when they are opened. In my example, I want to force the windows to have a width and height of 500px.

I listen for the ConfigureRequest event and for the MapRequest event. If I don't change width and height, but directly pass the hints of the opening window without changing them, to the window's configuration, everything works as expected.

However, when I specify a size that is not the intended size of the newly opening window, the MapRequest is delayed by more than 3 seconds (window becomes visible >3s after ConfigureRequest). This was the case, when I tested this using xterm. When I tested gnome-terminal, the MapRequest was fired before the ConfigureRequest, became immediately visible, but did not redraw (although I could close it by blindly typing exit Return).

This is obviously not the expected behavior. Am I doing anything wrong?

The relevant code:

def handle_event(self):
    try:
        event = self.display.next_event()
    except Xlib.error.ConnectionClosedError:
        print("The connection to display '"+self.display.get_display_name()+"' was closed by the server")
        print("Exiting now")
        sys.exit(0)
    if event.type in self.event_map:
        self.event_map[event.type](event) # calls on_configure_request or on_map_request depending on event type

.

def handle_configure_request(self, event):
    window = event.window
    args = { 'border_width': 3 }
    if event.value_mask & Xlib.X.CWX:
        args['x'] = event.x
    if event.value_mask & Xlib.X.CWY:
        args['y'] = event.y
    if event.value_mask & Xlib.X.CWWidth:
        args['width'] = event.width
    if event.value_mask & Xlib.X.CWHeight:
        args['height'] = event.height
    if event.value_mask & Xlib.X.CWSibling:
        args['sibling'] = event.above
    if event.value_mask & Xlib.X.CWStackMode:
        args['stack_mode'] = event.stack_mode
    args["width"] = 500
    args["height"] = 500
    window.configure(**args)
    print("Configured") # printed twice for every window -> is this normal?

.

def on_map_request(self, event):
    print("Mapping now") # when width and height are changed like above, this is printed more than 3s after on_configure_request when testing with xterm
    event.window.map()
    print("Mapped")



from Xlib ConfigureRequest with custom configuration not working

No comments:

Post a Comment