Skip to content

Rework WindowGrabber under x11 to not call xprop #233

Closed

Description

@zeridon

Describe the feature idea
Reimplement the backend of page change functionality in the case of X11 backend to not use external programs

Additional context
While looking around i stumbled on a python gist (https://gist.github.com/ssokolow/e7c9aae63fb7973e4d64cff969a78ae8) that implements most of the active window change logic just in python for the cost of a single library (xlib).

Benefits include faster run time (no forking) and the possibility (not sure) of doing this in an async way.

Activity

  1. Core447 commented on Sep 18, 2024

    @Core447
    Member

    Looks interesting - Will try this out when I have some time (is not a prio right now as my focus is on Gnome (with the extension) and Wayland)!

  2. teras commented on Sep 29, 2024

    @teras

    I tried this code and it is possible to grab the X11 event of focus. I put it here in case that you find it useful.
    It's a minimal example just to make things going
    It is configured to display the wm_class:

    from Xlib import X, display
    from Xlib.protocol import event
    
    def get_window_class(d, w):
        try:
            wm_class = w.get_wm_class()
            if wm_class:
                return " ".join(wm_class)
        except:
            pass
        return None
    
    def check_focus():
        d = display.Display()
        root = d.screen().root
        NET_WM_NAME = d.intern_atom('_NET_ACTIVE_WINDOW')
        root.change_attributes(event_mask=X.PropertyChangeMask)
        # Event loop
        while True:
            event = d.next_event()
            if event.type == X.PropertyNotify and event.atom == NET_WM_NAME:
                active_window = root.get_full_property(NET_WM_NAME, X.AnyPropertyType).value[0]
                window = d.create_resource_object('window', active_window)
                wm_class = get_window_class(d, window)
                if wm_class:
                    print(f"{wm_class}")
    if __name__ == "__main__":
        check_focus()
  3. Core447 commented on May 5, 2025

    @Core447
    Member

    Closing this, as the current xprop implementation works. If someone wants to to update the x11 code, feel free to do so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions