wayland: Throttle system bell requests
authorJonas Ådahl <jadahl@gmail.com>
Mon, 13 Mar 2017 06:42:38 +0000 (14:42 +0800)
committerJonas Ådahl <jadahl@gmail.com>
Thu, 20 Jul 2017 02:03:51 +0000 (10:03 +0800)
If a bad behaving application tries to make the window/display beep too
often, throttle the beep requests so that we don't end up filling the
Wayland socket queue.

The throttle is set to 50 beeps per second, which far more beeps than
will ever make any sense from a user experience point of view, but will
avoid terminating due to an excessive amount of requests.

https://bugzilla.gnome.org/show_bug.cgi?id=778188

gdk/wayland/gdkdisplay-wayland.c
gdk/wayland/gdkdisplay-wayland.h

index d7fb684bd69b62bdade490d3c3b3018ca93361ca..3c8eedbfdae894869bacb2bd112ffec36654bc32 100644 (file)
@@ -80,6 +80,8 @@
  * ]|
  */
 
+#define MIN_SYSTEM_BELL_DELAY_MS 20
+
 static void _gdk_wayland_display_load_cursor_theme (GdkWaylandDisplay *display_wayland);
 
 G_DEFINE_TYPE (GdkWaylandDisplay, gdk_wayland_display, GDK_TYPE_DISPLAY)
@@ -662,6 +664,7 @@ gdk_wayland_display_system_bell (GdkDisplay *display,
 {
   GdkWaylandDisplay *display_wayland;
   struct gtk_surface1 *gtk_surface;
+  gint64 now_ms;
 
   g_return_if_fail (GDK_IS_DISPLAY (display));
 
@@ -675,6 +678,12 @@ gdk_wayland_display_system_bell (GdkDisplay *display,
   else
     gtk_surface = NULL;
 
+  now_ms = g_get_monotonic_time () / 1000;
+  if (now_ms - display_wayland->last_bell_time_ms < MIN_SYSTEM_BELL_DELAY_MS)
+    return;
+
+  display_wayland->last_bell_time_ms = now_ms;
+
   gtk_shell1_system_bell (display_wayland->gtk_shell, gtk_surface);
 }
 
index a9fd4831a49c15e8577c191615044ef20aac6db4..3ae114e048fb412bcb0158d05fb4ed8b514bb3c0 100644 (file)
@@ -110,6 +110,8 @@ struct _GdkWaylandDisplay
 
   GPtrArray *monitors;
 
+  gint64 last_bell_time_ms;
+
   /* egl info */
   EGLDisplay egl_display;
   int egl_major_version;