I've got my engine running on Linux thanks to Allegro, however one very simple thing is puzzling me... right now I would just like to be able to bring the window of my choice into focus. Such as either my Allegro window or my console window. What's the easiest way to go about this? It's like a galaxy of libraries, there's apparently nothing close to Win32API ...
https://duckduckgo.com/?q=linux+change+window+focus+x11+c&t=seamonkey&ia=qa
Second link :
You probably want the XGetInputFocus call.
Window focused; int revert_to; XGetInputFocus(dpy, &focused, &revert_to);
In this snippet, focused will be the window with current input focus, getting keyboard events and mouse button presses.
This will work even if the window manager does not set the _NET_ACTIVE_WINDOW property on the root window, as specified by EWMH. A few window managers, such as dwm and my 9wm, don't set this.
shareeditflag
answered Mar 6 '15 at 2:47
Neale Pickett
13613
3
upvote
flag
He also asked "how to change it", XSetInputFocus can do that, for example: XSetInputFocus(display, window_to_focus, RevertToNone, CurrentTime); – Sam Watkins Nov 19 '16 at 4:14
I'm surprised that Allegro doesn't have a way to do this.
Is libX11 going to be available on every graphical Linux distro?
I'm surprised that Allegro doesn't have a way to do this
People have long debated a sys.allegro module/addon.
I'm working on a Allegro enhanced with D these days, for my own games, currently called Molto Allegro (Allegro means lively pace, Molto means "a little faster".) I'm going to definitely have sys calls even if Allegro proper doesn't add them. (It'd be really funny if someone or I make a C-wrapper for my library. So it goes C->D->C. We must go deeper!)
CDC... Centers for Disease Creation?
Sorry, I realize this not an xlib forum, but it doesn't seem to be working.
This is what I'm doing (Forth source)
variable _hwnd variable _disp 0 XOpenDisplay _disp ! _disp @ _hwnd here XGetInputFocus : HWND _hwnd @ ; : focus ?dup -exit _disp @ swap 0 0 XSetInputFocus ; : >display display al_get_x_window_id focus ;
I seem to be getting the display handle, but XSetInputFocus doesn't do anything when testing interactively. My Allegro window stays in the background and input focus remains in the terminal.
EDIT: I figured it out. You need to call XSync to make your changes take effect.