Skip to content
Snippets Groups Projects
Commit aff8feb7 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Have the IC focus follow the X11 focus

Basically, If we get a FocusOut, call XUnsetICFocus(), and if we
get a FocusIn, call XSetICFocus().  Since we're doing this, don't
call XSetICFocus() unconditionally at start, wait for the server
to send us the initial FocusIn instead.

The only bit I'm not sure of is if I got the times to ignor
messages right... see here:
https://tronche.com/gui/x/xlib/events/input-focus/normal-and-grabbed.html
If you want to check my work.

May fix the focus follows mouse issue reported by Cyan.
parent e04a5488
Branches
Tags
No related merge requests found
Pipeline #6720 passed
......@@ -446,6 +446,10 @@ int x_initciolib(int mode)
xp_dlclose(dl);
return(-1);
}
if((x11.XUnsetICFocus=xp_dlsym(dl,XUnsetICFocus))==NULL) {
xp_dlclose(dl);
return(-1);
}
if((x11.XFilterEvent=xp_dlsym(dl,XFilterEvent))==NULL) {
xp_dlclose(dl);
return(-1);
......
......@@ -1069,9 +1069,10 @@ static int init_window()
gcv.graphics_exposures = False;
gc=x11.XCreateGC(dpy, win, GCFunction | GCForeground | GCBackground | GCGraphicsExposures, &gcv);
x11.XSelectInput(dpy, win, KeyReleaseMask | KeyPressMask |
ExposureMask | ButtonPressMask | PropertyChangeMask
| ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
x11.XSelectInput(dpy, win, KeyReleaseMask | KeyPressMask
| ExposureMask | ButtonPressMask | PropertyChangeMask
| ButtonReleaseMask | PointerMotionMask
| StructureNotifyMask | FocusChangeMask);
x11.XStoreName(dpy, win, "SyncConsole");
Atom protos[2];
......@@ -1732,6 +1733,29 @@ x11_event(XEvent *ev)
expose_rect(ev->xexpose.x, ev->xexpose.y, ev->xexpose.width, ev->xexpose.height);
break;
/* Focus Events */
case FocusIn:
case FocusOut:
{
if (ev->xfocus.mode == NotifyGrab)
break;
if (ev->xfocus.mode == NotifyUngrab)
break;
if (ev->xfocus.detail == NotifyInferior)
break;
if (ev->xfocus.detail == NotifyPointer)
break;
if (ev->type == FocusIn) {
if (ic)
x11.XSetICFocus(ic);
}
else {
if (ic)
x11.XUnsetICFocus(ic);
}
break;
}
/* Copy/Paste events */
case SelectionClear:
{
......
......@@ -105,6 +105,7 @@ struct x11 {
XIC (*XCreateIC)(XIM im, ...);
int (*XwcLookupString)(XIC ic, XKeyPressedEvent *event, wchar_t *buffer_return, int wchars_buffer, KeySym *keysym_return, Status *status_return);
void (*XSetICFocus)(XIC ic);
void (*XUnsetICFocus)(XIC ic);
Bool (*XFilterEvent)(XEvent *event, Window w);
Cursor (*XCreateFontCursor)(Display *display, unsigned int shape);
int (*XDefineCursor)(Display *display, Window w, Cursor cursor);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment