xorg_lock_smasher_set_active (GSGrab  *grab,
                              gboolean active)
{
        int status, event, error;

	if (!XF86MiscQueryExtension (GDK_DISPLAY (), &event, &error)) {
		gs_debug ("No XFree86-Misc extension present");
		return;
	}

        if (active) {
                gs_debug ("Enabling the x.org grab smasher");
        } else {
                gs_debug ("Disabling the x.org grab smasher");
        }

        gdk_error_trap_push ();

        status = XF86MiscSetGrabKeysState (GDK_DISPLAY (), active);

        gdk_display_sync (gdk_display_get_default ());
        gdk_error_trap_pop ();

        if (active && status == MiscExtGrabStateAlready) {
                /* shut up, consider this success */
                status = MiscExtGrabStateSuccess;
        }

        gs_debug ("XF86MiscSetGrabKeysState(%s) returned %s\n",
                  active ? "on" : "off",
                  (status == MiscExtGrabStateSuccess ? "MiscExtGrabStateSuccess" :
                   status == MiscExtGrabStateLocked  ? "MiscExtGrabStateLocked"  :
                   status == MiscExtGrabStateAlready ? "MiscExtGrabStateAlready" :
                   "unknown value"));
}
xorg_lock_smasher_set_active (GSGrab  *grab,
                              gboolean active)
{
        int status, event, error;

	if (!XF86MiscQueryExtension (GDK_DISPLAY (), &event, &error)) {
		gs_debug ("No XFree86-Misc extension present");
		return;
	}

        if (active) {
                gs_debug ("Enabling the x.org grab smasher");
        } else {
                gs_debug ("Disabling the x.org grab smasher");
        }

        gdk_error_trap_push ();

        status = XF86MiscSetGrabKeysState (GDK_DISPLAY (), active);

        gdk_display_sync (gdk_display_get_default ());
        gdk_error_trap_pop ();

        if (active && status == MiscExtGrabStateAlready) {
                 
                status = MiscExtGrabStateSuccess;
        }

        gs_debug ("XF86MiscSetGrabKeysState(%s) returned %s\n",
                  active ? "on" : "off",
                  (status == MiscExtGrabStateSuccess ? "MiscExtGrabStateSuccess" :
                   status == MiscExtGrabStateLocked  ? "MiscExtGrabStateLocked"  :
                   status == MiscExtGrabStateAlready ? "MiscExtGrabStateAlready" :
                   "unknown value"));
}