X11 FocusIn is not working

x11 events
x11 programming
event mask
xevent keypress
xlib events

As long as I understand it, the X11 FocusIn event is triggered whenever the window comes into focused. It the the window that the keyboard input is sent to. I am having trouble triggering this event. I have made sure to give it the FocusChangeMask when creating the window. I have created a breakpoint inside my event handler where the FocusIn event is supposed to happen and it is not stopping.

I have 2 separate window, a transparent one and one non-transparent. Currently I have it so the transparent window is always on top of the non transparent window. Whenever I switch focus and then switch back to the transparent window, the non-transparent window is directly underneath. This causes other windows to be stuck in 'between' the transparent and non-transparent window.

I have noticed that whenever I focus on the non-transparent window that is underneath that triggers the FocusIn event. I can not get the transparent window to trigger the event. Does this have something to do with the window being in 32-bit color?

What am I missing?

while(!renderer->stop)
    {
        XNextEvent(renderer->x_display, &event);
        switch(event.type)
        {
            case Expose:
            if (event.xexpose.window == gstreamer_window)
            {
                XRaiseWindow(renderer->x_display, renderer->opengl_window);
            }
            break;

            case FocusIn:
            if (event.xfocus.window == renderer->opengl_window)
            {
                XRaiseWindow(renderer->x_display, gstreamer_window);
            }
            break;

            case ConfigureNotify:
            if (event.xconfigure.window == renderer->opengl_window)
            {
                XMoveWindow(renderer->x_display, gstreamer_window,
                            event.xconfigure.x, event.xconfigure.y - top_border_offset);
            }
            break;
        }
    }

Here is how I created the window.

XSetWindowAttributes  swa;
    swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask | FocusChangeMask;
    swa.colormap = XCreateColormap(x_display, XDefaultRootWindow(x_display), visual, AllocNone);
    swa.background_pixel = 0;
    swa.border_pixel = 0;

    /* Create a window */
    opengl_window = XCreateWindow (
              x_display, parent,
              0, 0, m_plane_width, m_plane_height, 0,
              depth, InputOutput,
              visual, CWEventMask | CWBackPixel | CWColormap | CWBorderPixel,
              &swa );

It appears as though I set the FocusChangeMask at the wrong place. By adding the line XSelectInput(x_display, opengl_window, FocusChangeMask) , it now triggers the FocusIn event. It was triggering the other display because it had the mask but this one didn't.

linux - X11 FocusIn is not working -, linux - X11 FocusIn is not working - when creating window. have created breakpoint inside event handler focusin event supposed happen , not stopping. The reason ssh X forwarding wasn't working was because I have a /etc/ssh/sshrc config file. The end of the sshd(8) man page states: If ~/.ssh/rc exists, runs it; else if /etc/ssh/sshrc exists, runs it; otherwise runs xauth So I add the following commands to /etc/ssh/sshrc

It's not clear from your question whether the windows referenced in your question are top level application windows, or secondary, ancillary windows that are child windows of your top level application windows.

But in all cases, proper input focus handling requires you to inform the window manager exactly how your application expects to handle input focus.

See section 4.1.7 of the ICCCM specification for more information. Unfortunately, it's not enough just to code an event loop that handles FocusIn messages, and expect them to fall out of the sky. First, you need to tell your window manager how exactly you are going to handle input focus switching, then respond to the window manager's messages, as explained in the ICCCM specification; perhaps by explicitly sending the SetInputFocus requests for your own application windows.

Xlib Programming Manual: Input Focus Events, The X server can report FocusIn or FocusOut events to clients wanting however​, the X protocol does not constrain the ordering of FocusOut events with respect  If the buttons on your X1 Voice Remote (model XR11) are still unresponsive, you may need to perform a factory reset. To perform a factory reset: Press the Setup button until the LED at the top of the remote changes from red to green. The LED will blink green twice to indicate that the remote was reset. The factory reset unpairs your remote and

X Protocol Reference Manual for X11, Release 6, FocusCut with detail PointerRoot (or None. is generated on all root windows. • If A is not a root window, Focusin with detail Nonlinear Virtual is generated on  Focus XII Located in St. Cloud, Focus XII Residential is medium intensity, abstinence-based program that serves men 18 and older who are chemically dependent and have recently completed a licensed chemical dependency treatment program. This program is licensed through both the Minnesota Department of Human Services and Department of Health. With 24-hour staff Read more »

The NeWS Book: An Introduction to the Network/Extensible Window System, Examples of functions included in the X11 protocol but not built into NeWS are: input focus, and for sending Focusin and FocusOut events when it changes. I have x11 (classic, from apps->utils->x11) and xquartz2.5.3 and both of them have a focus problem. It is for this reason that I belive that the problem is with Mac OSX and not the individual app itself. After around 2-3 seconds the current x11 window loses focus. This happens to all apps that use x11. Examples are gimp, matlab, xterm, nxclient

Xlib Programming Manual: XSetInputFocus, XSetInputFocus() causes the X server to generate FocusIn and FocusOut events. If the focus window later becomes not viewable, the X server evaluates the  The onfocusin event occurs when an element is about to get focus. Tip: The onfocusin event is similar to the onfocus event. The main difference is that the onfocus event does not bubble. Therefore, if you want to find out whether an element or its child gets the focus, you should use the onfocusin event.

Java X11 Library / Bugs / #3 Focusin & FocusOut event use wrong , FocusIn.Java and FocusOut.java should have a window offset of 4, not 8. So this: public FocusIn (Display display, byte [] data) { super (display  Because of the complexity involved in implementing an X11 server, this wouldn’t actually work well in practice, however a graphics driver for the X.Org X11 server is currently being written. This driver functions as a display and set of input devices which implement the Guacamole protocol, and should be quite fast.

Comments
  • FocusChangeMask works where you had it until you add the XSelectInput line. I came here because I just added XSelectInput and my other events stopped working, including ExposureMask etc... I have no idea whats going on, but you had it correct before, but this command overrides not adds to the overall masks somehow. I'm not sure how its really supposed to work. I'm going to add mine to another answer to maybe help future travelers.
  • -1 as was just casting asparagus at the question, and not attempting to answer why he was having the issue or apparent side effect.