From 231f7c59ff3fa95c3cd3b71929ef690ab094a87f Mon Sep 17 00:00:00 2001 From: rexim Date: Thu, 30 Jan 2020 00:28:58 +0700 Subject: [PATCH] (#78) Give more insights into a weird piece of code --- src/boomer.nim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/boomer.nim b/src/boomer.nim index 341fbdf..d9a94dc 100644 --- a/src/boomer.nim +++ b/src/boomer.nim @@ -169,11 +169,17 @@ proc selectWindow(display: PDisplay): TWindow = return root -proc xElevenErrorHandler(display: PDisplay, errorEvent: PXErrorEvent): cint{.cdecl.} = +# NOTE: This is needed primarily for -d:select along with +# -d:live. When we are constantly taking a screenshot of a resizing +# window sometimes you may not know exact shape of the window (because +# X11 request may lag behind) and you are trying to access invalid +# memory. X11 does not like that and simply crashes. With this error +# handler we force it not to crash. +proc customX11ErrorHandler(display: PDisplay, errorEvent: PXErrorEvent): cint{.cdecl.} = const CAPACITY = 256 var errorMessage: array[CAPACITY, char] discard XGetErrorText(display, errorEvent.error_code.cint, addr errorMessage, CAPACITY) - echo "X ELEVEN ERROR: ", $(addr errorMessage) + echo "X11: ", $(addr errorMessage) proc main() = let boomerDir = getConfigDir() / "boomer" @@ -272,7 +278,7 @@ proc main() = defer: discard XCloseDisplay(display) - discard XSetErrorHandler(xElevenErrorHandler) + discard XSetErrorHandler(customX11ErrorHandler) when defined(select): echo "Please select window:"