Reduce number of calls to update XIM only if cursor position was changed
and user is not holding a key. In other words, send cursor position on
the last key release which change cursor position.
It also help reduce input lag problem with fcitx5 when holding keys.
---
st.c | 7 +++++--
x.c | 15 ++++++++++++++-
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/st.c b/st.c
index 3e48410..cb3a4dc 100644
--- a/st.c
+++ b/st.c
@@ -2570,7 +2570,7 @@ drawregion(int x1, int y1, int x2, int y2)
void
draw(void)
{
- int cx = term.c.x;
+ int cc, cx = term.c.x;
if (!xstartdraw())
return;
@@ -2586,9 +2586,12 @@ draw(void)
drawregion(0, 0, term.col, term.row);
xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
+ cc = term.ocx != cx || term.ocy != term.c.y;
term.ocx = cx, term.ocy = term.c.y;
xfinishdraw();
- xximspot(term.ocx, term.ocy);
+
+ if (cc)
+ xximspot(term.ocx, term.ocy);
}
void
diff --git a/x.c b/x.c
index 1f62129..bf6d605 100644
--- a/x.c
+++ b/x.c
@@ -94,6 +94,7 @@ typedef struct {
Drawable buf;
GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
Atom xembed, wmdeletewin, netwmname, netwmpid;
+ XKeyEvent lkr; /* last key release event */
struct {
XIM xim;
XIC xic;
@@ -107,6 +108,7 @@ typedef struct {
int isfixed; /* is fixed geometry? */
int l, t; /* left and top offset */
int gm; /* geometry mask */
+ int repeat; /* key repeat */
} XWindow;
typedef struct {
@@ -168,6 +170,7 @@ static void expose(XEvent *);
static void visibility(XEvent *);
static void unmap(XEvent *);
static void kpress(XEvent *);
+static void krelease(XEvent *);
static void cmessage(XEvent *);
static void resize(XEvent *);
static void focus(XEvent *);
@@ -190,6 +193,7 @@ static void usage(void);
static void (*handler[LASTEvent])(XEvent *) = {
[KeyPress] = kpress,
+ [KeyRelease] = krelease,
[ClientMessage] = cmessage,
[ConfigureNotify] = resize,
[VisibilityNotify] = visibility,
@@ -1627,7 +1631,7 @@ xfinishdraw(void)
void
xximspot(int x, int y)
{
- if (xw.ime.xic == NULL)
+ if (xw.ime.xic == NULL || xw.repeat)
return;
xw.ime.spot.x = borderpx + x * win.cw;
@@ -1782,6 +1786,9 @@ kpress(XEvent *ev)
if (IS_SET(MODE_KBDLOCK))
return;
+ /* keep track of repeat */
+ xw.repeat = xw.lkr.time == e->time && xw.lkr.keycode == e->keycode;
+
if (xw.ime.xic)
len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym,
&status);
else
@@ -1818,6 +1825,12 @@ kpress(XEvent *ev)
ttywrite(buf, len, 1);
}
+void
+krelease(XEvent *ev)
+{
+ xw.lkr = ev->xkey;
+}
+
void
cmessage(XEvent *e)
{
--
2.25.0