View Single Post
Posts: 77 | Thanked: 63 times | Joined on Sep 2009
#29
Originally Posted by rcs1000 View Post
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.

qobi@tlamachilistli>cat ~/c/set-focus.c
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
Display *display;
Window window = 0;
if (argc!=2) {
fprintf(stderr, "usage: set-focus <id>\n");
exit(EXIT_FAILURE);
}
if (sscanf(argv[1], "0x%lx", &window)!=1) {
fprintf(stderr, "id must be in parsable by 0x%%lx\n");
exit(EXIT_FAILURE);
}
display = XOpenDisplay("");
if (display==NULL) {
fprintf(stderr, "can't open display\n");
exit(EXIT_FAILURE);
}
XSetInputFocus(display, window, RevertToParent, CurrentTime);
//XSetInputFocus(display, window, RevertToPointerRoot, CurrentTime);
//XSetInputFocus(display, window, RevertToNone, CurrentTime);
XFlush(display);
return EXIT_SUCCESS;
}
qobi@tlamachilistli>cat ~/bin/keep-emacs-focus
#!/bin/bash
while true
do if xwininfo -name emacs@oguguisi >/dev/null 2>/dev/null
then
id=`xwininfo -name emacs@oguguisi|fgrep id:|cut -d ' ' -f 4`
while xprop -id $id _MB_CURRENT_APP_WINDOW >/dev/null 2>/dev/null
do if [[ `xprop -id $id _MB_CURRENT_APP_WINDOW|cut -d ' ' -f 5` == $id ]]
then set-focus $id
fi
sleep 1
done
fi
sleep 1
done
qobi@tlamachilistli>
 

The Following 2 Users Say Thank You to qobi For This Useful Post: