Skip to content
Discussion options

You must be logged in to vote

That is low level code winuser.h which really only works on Windows. For Linux you've to look an analog library, probably using the libX11.so. I really don't know if the code below works, but could give you an hint.

using System;
using X11;

class FocusX11
{
    static void Main()
    {
        IntPtr display = Xlib.XOpenDisplay(null);
        if (display == IntPtr.Zero) return;

        // Obtain your window ID somehow
        IntPtr window = new IntPtr(0x123456); 

        Xlib.XRaiseWindow(display, window);
        Xlib.XSetInputFocus(display, window, (int)Xlib.RevertToPointerRoot, IntPtr.Zero);
        Xlib.XFlush(display);
    }
}

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@BDisp
Comment options

BDisp Jan 28, 2026
Collaborator

Answer selected by LMSSonos
@LMSSonos
Comment options

@BDisp
Comment options

BDisp Jan 28, 2026
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants