grabbing keyboard doesnt allow changing focus
Asked Answered
H

1

3

as soon as i use display.grab_keyboard, no other window seems to know of its own focus.

with the keyboardgrab running i can select other windows and even send keyevents to them, but if this window is a text input there will be no blinking cursor.

i read something about grab_keyboard generating focusevents, but that doesnt mean it blocks all focus events, does it?

what am i not getting here?

from Xlib import X,XK
from Xlib.display import Display
import signal,sys

root = None
display = None

def main():
    # current display
    global display,root
    display = Display()
    root = display.screen().root


    root.change_attributes(event_mask = X.KeyPressMask|X.KeyReleaseMask)

    root.grab_keyboard(True, X.GrabModeAsync, X.GrabModeAsync,X.CurrentTime)

    signal.signal(signal.SIGALRM, lambda a,b:sys.exit(1))
    signal.alarm(10)

    while True:
        event = display.next_event()
        print event.type

main()
Hoarfrost answered 10/8, 2013 at 10:27 Comment(0)
G
1

You are grabbing the keyboard, that means that all keyboard input will go to your program, no other window can receive keyboard input. That's the point of grabbing the keyboard.

Goldner answered 11/8, 2013 at 7:56 Comment(2)
i dont want other windows to receive keyboard input directly, but i want them to have the focus/blinking cursor. this is possible in theory, i wrote something that grabs the pointer too and then focuses the window under the pointer on mouseclick. but when i do this, i pretty much have to rewrite klicking and dragging and so on. is there a way around that?Hoarfrost
Not really, you've taken over the events, so you have to do what X/Xlib would have done with them.Goldner

© 2022 - 2024 — McMap. All rights reserved.