X11: ring the bell as well, when appropriate

This commit is contained in:
Přemysl Eric Janouch 2022-08-24 09:35:28 +02:00
parent da14bdbd39
commit 179e0a123b
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 42 additions and 36 deletions

View File

@ -4051,7 +4051,7 @@ help_tab_on_action (enum action action)
if (action == ACTION_NONE || action == ACTION_CHOOSE /* avoid recursion */) if (action == ACTION_NONE || action == ACTION_CHOOSE /* avoid recursion */)
return false; return false;
// XXX: We can't propagate failure, which produces beeps in the TUI, but we // XXX: We can't propagate failure to ring the terminal/X11 bell, but we
// don't want to let our caller show a bad "can't do that" message either. // don't want to let our caller show a bad "can't do that" message either.
return app_process_action (action), true; return app_process_action (action), true;
} }
@ -5917,7 +5917,7 @@ x11_convert_keysym (KeySym keysym)
return TERMO_SYM_UNKNOWN; return TERMO_SYM_UNKNOWN;
} }
static void static bool
on_x11_keypress (XEvent *e) on_x11_keypress (XEvent *e)
{ {
// A kibibyte long buffer will have to suffice for anyone. // A kibibyte long buffer will have to suffice for anyone.
@ -5942,14 +5942,16 @@ on_x11_keypress (XEvent *e)
{ {
key.type = TERMO_TYPE_FUNCTION; key.type = TERMO_TYPE_FUNCTION;
key.code.number = 1 + keysym - XK_F1; key.code.number = 1 + keysym - XK_F1;
app_process_termo_event (&key); return app_process_termo_event (&key);
} }
else if ((key.code.sym = x11_convert_keysym (keysym)) != TERMO_SYM_UNKNOWN) if ((key.code.sym = x11_convert_keysym (keysym)) != TERMO_SYM_UNKNOWN)
{ {
key.type = TERMO_TYPE_KEYSYM; key.type = TERMO_TYPE_KEYSYM;
app_process_termo_event (&key); return app_process_termo_event (&key);
} }
else if (len)
bool result = true;
if (len)
{ {
key.type = TERMO_TYPE_KEY; key.type = TERMO_TYPE_KEY;
key.modifiers &= ~TERMO_KEYMOD_SHIFT; key.modifiers &= ~TERMO_KEYMOD_SHIFT;
@ -5970,9 +5972,11 @@ on_x11_keypress (XEvent *e)
k.code.codepoint = cp + 64; k.code.codepoint = cp + 64;
else else
k.code.codepoint = cp + 96; k.code.codepoint = cp + 96;
app_process_termo_event (&k); if (!app_process_termo_event (&k))
result = false;
} }
} }
return result;
} }
static void static void
@ -5988,22 +5992,20 @@ x11_init_pixmap (void)
= XRenderCreatePicture (g.dpy, g.x11_pixmap, format, 0, NULL); = XRenderCreatePicture (g.dpy, g.x11_pixmap, format, 0, NULL);
} }
static void static bool
on_x11_input_event (XEvent *ev) on_x11_input_event (XEvent *ev)
{ {
static XEvent last_button_event; static XEvent last_button_event;
if (ev->type == KeyPress) if (ev->type == KeyPress)
{ {
last_button_event = (XEvent) {}; last_button_event = (XEvent) {};
on_x11_keypress (ev); return on_x11_keypress (ev);
return;
} }
if (ev->type == MotionNotify) if (ev->type == MotionNotify)
{ {
// We only select for Button1MotionMask, so this works out. // We only select for Button1MotionMask, so this works out.
int x = ev->xmotion.x, y = ev->xmotion.y; int x = ev->xmotion.x, y = ev->xmotion.y;
app_process_mouse (TERMO_MOUSE_DRAG, x, y, 1, false); return app_process_mouse (TERMO_MOUSE_DRAG, x, y, 1, false);
return;
} }
// See tui_on_tty_event(). Just here we know the button on button release. // See tui_on_tty_event(). Just here we know the button on button release.
@ -6015,16 +6017,19 @@ on_x11_input_event (XEvent *ev)
&& abs (last_button_event.xbutton.y - y) < 5 && abs (last_button_event.xbutton.y - y) < 5
&& last_button_event.xbutton.button == button; && last_button_event.xbutton.button == button;
if (ev->type == ButtonPress)
app_process_mouse (TERMO_MOUSE_PRESS, x, y, button, double_click);
if (ev->type == ButtonRelease)
app_process_mouse (TERMO_MOUSE_RELEASE, x, y, button, double_click);
// Prevent interpreting triple clicks as two double clicks. // Prevent interpreting triple clicks as two double clicks.
// FIXME: This doesn't work: we skip ButtonPress, but use ButtonRelease. // FIXME: This doesn't work: we skip ButtonPress, but use ButtonRelease.
last_button_event = (XEvent) {}; last_button_event = (XEvent) {};
if (!double_click) if (!double_click)
last_button_event = *ev; last_button_event = *ev;
if (ev->type == ButtonPress)
return app_process_mouse
(TERMO_MOUSE_PRESS, x, y, button, double_click);
if (ev->type == ButtonRelease)
return app_process_mouse
(TERMO_MOUSE_RELEASE, x, y, button, double_click);
return false;
} }
static void static void
@ -6037,6 +6042,23 @@ on_x11_event (XEvent *ev)
if (!ev->xexpose.count) if (!ev->xexpose.count)
poller_idle_set (&g.flip_event); poller_idle_set (&g.flip_event);
break; break;
case ConfigureNotify:
if (g.ui_width == ev->xconfigure.width
&& g.ui_height == ev->xconfigure.height)
break;
g.ui_width = ev->xconfigure.width;
g.ui_height = ev->xconfigure.height;
XRenderFreePicture (g.dpy, g.x11_pixmap_picture);
XFreePixmap (g.dpy, g.x11_pixmap);
x11_init_pixmap ();
XftDrawChange (g.xft_draw, g.x11_pixmap);
app_invalidate ();
break;
case UnmapNotify:
app_quit ();
break;
case FocusIn: case FocusIn:
key.type = TERMO_TYPE_FOCUS; key.type = TERMO_TYPE_FOCUS;
key.code.focused = true; key.code.focused = true;
@ -6051,24 +6073,8 @@ on_x11_event (XEvent *ev)
case ButtonPress: case ButtonPress:
case ButtonRelease: case ButtonRelease:
case MotionNotify: case MotionNotify:
on_x11_input_event (ev); if (!on_x11_input_event (ev))
break; XkbBell (g.dpy, ev->xany.window, 0, None);
case UnmapNotify:
app_quit ();
break;
case ConfigureNotify:
if (g.ui_width == ev->xconfigure.width
&& g.ui_height == ev->xconfigure.height)
break;
g.ui_width = ev->xconfigure.width;
g.ui_height = ev->xconfigure.height;
XRenderFreePicture (g.dpy, g.x11_pixmap_picture);
XFreePixmap (g.dpy, g.x11_pixmap);
x11_init_pixmap ();
XftDrawChange (g.xft_draw, g.x11_pixmap);
app_invalidate ();
} }
} }