Email or username:

Password:

Forgot your password?
Devil Lu Linvega

Anyone familiar with #x11 could give me a hand with something?

I'm trying to send a key event to a previously focused window that is not itself.

For example, you focus on firefox, then open a terminal window and run this, the event is sent to firefox, and not itself.

paste.sr.ht/~rabbits/c6e817d57

17 comments
David JONES

@neauoire i don't in general see how the program could know what "the previously focused window" is. I don't think X keeps track of it. Do you have other means of knowing it? (if you do, it seems like you could modify xfake.c to send an event to any particular window; X definitely supports that).

Devil Lu Linvega

@drj I'm not sure, is there a way I could send events to a particular window by recording which window I could out to, from my program? Like, if I loose focus to focus on a second window, is there a way to know that window's id?

David JONES

@neauoire a) what are you up to?; b) i'm not sure; c) any X program knows the IDs of any windows it creates, and it is free to tell anyone (you, me, another program) about those IDs. And given an ID (they are 32-bit numbers i think) any program can now send events to that window. I think xterm for example advertises its Window ID in its env so that cli programs can, in principle, do X things to their containing xterm.; d) i don't use X any more so i can't poke around easily.

Devil Lu Linvega

@drj my goal is to make an on-screen keyboard in Uxn, it's something I'd use daily.
The uxn emulator I have is written in x11 itself, but I would like not to have to modify the emulator, ideally I'd use a small intermediate program, like:

uxn11 keyboard.rom | some_little_program

The keyboard rom will send stdout events, and some_little_program will be the bit that handles the logic of which keycode to send, and which window to send it to

David JONES

@neauoire so some_little_program needs to know the X window ID to send events to. Some ideas: you could just type it in; some_little_program could observe what window has focus at the moment it starts and use that one forever; one of the programs (I'm not sure which one) could make you click on the target window and listen for the event and use the target of the click for all future events.

Devil Lu Linvega

@drj Oooh! Yes, okay, let say I wanted to make it so some_little_program waits for a click on a window(`click on any window`), do you know how I can do this?

David JONES

@neauoire I only ever wrote 1 X11 program, but it was using XLib and none of the new-fangled framework nonsense (it was on a DEC Ultrix machine in about 1994). I _think_ you "simply" call XNextEvent; see how xev.c does it gitlab.freedesktop.org/xorg/ap

I _think_ by default an X11 client gets all events (for all windows!) unless it has requested only events for particular windows (like their own, which most apps would do); i think that's XSelectInput.

Devil Lu Linvega

@drj aaah! amazing, thank you so much, that should be enough for me to get it working :)

ArBe

@neauoire @drj Not sure if this is helpful, but the `xprop` allows you to click on a window, and then it prints its properties to stdout. You could probably hook it up with a shell script, or maybe look into the source if you want to do something similar with the API

Anders Conbere

@neauoire I’d probably set up a global key event listener and then keep track of my windows on my own. Like this keylogger. Not sure if this is quite what you want though.

github.com/anko/xkbcat/blob/ma

marmarta

@neauoire X11 doesn't keep track of focus history, you would have to hook yourself to the FocusIn event and keep track yourself.

Devil Lu Linvega

@marmarta So you mean, that when the window(ex, firefox) looses focus to focus on the new one(my program), I could record what that one is?

pengaru

@neauoire I don't think core Xlib has any information about previously focused windows maintained in the display server, you'd likely have to have a client watching for focus change events a priori which could then know what was formerly focused.

penguin42

@neauoire You might look at xwininfo that can list all the windows on the display with their IDs, as a way of finding your target window (I don't mean using that program, just the way it works)

Devil Lu Linvega

@timthelion the order of the enumeration doesn't seem to change based on the z index of the window, it seems more like the order in the windows were created

Go Up