$NetBSD: patch-ab,v 1.1 2007/10/13 11:44:39 tnn Exp $

--- x.c.orig	2006-06-14 05:34:41.000000000 +0200
+++ x.c
@@ -173,6 +173,14 @@ int warn_about_hotkey(Display *dpy, XErr
  */
 static Bool mouseOnScreen;
 
+static void atexit_ungrab(void) {
+  if (grabbed) {
+    fprintf(stderr, "%s: exit while grabbed, ungrabbing input devices\n",
+            programName);
+    ungrabit(-1, -1, DefaultRootWindow(dpy));
+  }
+}
+
 /*
  * CreateXWindow.
  */
@@ -534,6 +542,7 @@ Bool CreateXWindow(void)
   dumpcoord(&origo2);
   fprintf(stderr,"offset=%d, %d\n",x_offset,y_offset);
   */
+  atexit(atexit_ungrab);
     
   return True;
 }
