From d8a74e8a3cf50b6b15feb72d8b736cd669504e1b Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Tue, 2 Oct 2018 16:03:48 +0900 Subject: [PATCH] glfw/x11_window/selection: timeout if no answer for two seconds This prevents kitty to hang forever if a bad client does not give selection --- glfw/x11_window.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 04648e14d..db7565827 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -873,6 +873,7 @@ static const char* getSelectionString(Atom selection) Atom actualType; int actualFormat; unsigned long itemCount, bytesAfter; + double start = glfwGetTime(); XEvent notification, dummy; XConvertSelection(_glfw.x11.display, @@ -887,7 +888,10 @@ static const char* getSelectionString(Atom selection) SelectionNotify, ¬ification)) { - waitForX11Event(-1); + double time = glfwGetTime(); + if (time - start > 2) + return ""; + waitForX11Event(2.0 - (time - start)); } if (notification.xselection.property == None) @@ -918,12 +922,16 @@ static const char* getSelectionString(Atom selection) for (;;) { + start = glfwGetTime(); while (!XCheckIfEvent(_glfw.x11.display, &dummy, isSelPropNewValueNotify, (XPointer) ¬ification)) { - waitForX11Event(-1); + double time = glfwGetTime(); + if (time - start > 2) + return ""; + waitForX11Event(2.0 - (time - start)); } XFree(data);