javispedro: Is it not possible to write a tiny utility that will set the WM_HINTS on any arbitrary window? I could use wmctrl to find the window ID of the broken window, and then use this little fixer utility to fix the WM_HINTS on that window... That would be a very very workable solution for me.
You don't XSetInputFocus (which is a hack) but rather fix the WM_HINTS, which is the real issue here (and not the window manager). If you want examples please search my posts, qwerty's patch to xev, or the multiple debian bug reports opened about the issue (in apps/toolkits).
I might be wrong but I don't believe that WM_HINTS is the issue.
emacs already has input_hints->input == True and input_hints->flags&InputHint but still does not get focus.
Originally Posted by qole
Is it not possible to write a tiny utility that will set the WM_HINTS on any arbitrary window? I could use wmctrl to find the window ID of the broken window, and then use this little fixer utility to fix the WM_HINTS on that window... That would be a very very workable solution for me.
Here is an app that I wrote that does this. But as I said above, at least emacs already has the appropriate hints set so this doesn't work for emacs.
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
Display *display;
Window window = 0;
XWMHints *input_hints;
if (argc!=2) {fprintf(stderr, "usage: set-input-hint <id>\n"); exit(-1);}
if (sscanf(argv[1], "0x%lx", &window)!=1) {
fprintf(stderr, "id must be in parsable by 0x%%lx\n");
exit(-1);
}
display = XOpenDisplay("");
if (display==NULL) {fprintf(stderr, "can't open display\n"); exit(-1);}
input_hints = XGetWMHints(display, window);
if (input_hints==NULL) {
XWMHints input_hints = { .input = True, .flags = InputHint };
XSetWMHints(display, window, &input_hints);
}
else {
input_hints->input = True;
input_hints->flags |= InputHint;
XSetWMHints(display, window, input_hints);
XFree(input_hints);
}
XFlush(display);
}
EDIT: I am adding the libx11-dev package to my development Debian chroot as we speak... going to try compiling my first C app (well, first time ever issuing the gcc command)...
Let me just check: this application - when run as 'qobi-wmhint-fix &' will sit in the background and attempt to make sure input is directed to the 'in focus' window.
Let me just check: this application - when run as 'qobi-wmhint-fix &' will sit in the background and attempt to make sure input is directed to the 'in focus' window.
Am I right?
No. You first obtain the window id (a 32bit number represented in hex).
One way to do this is with xwininfo.
% xwininfo -name <window name>|fgrep id:
Then you call it with the id as the sole arg. It doesn't sit in the background.
It just changes two bits in the window manager hints structure for the window. You have to call it for a specific window and recall it for each new window that you wish to apply it to.
As I said, it doesn't work for all apps. In particular, it doesn't work for emacs. I don't know why it works for some apps and not others.
I have a different approach that does work for emacs. That approach does sit in the background and detects when a window is exposed and calls XSetInputFocus on that window. I posted an earlier version. Here is a more recent version that works better.