← home

un-bust your x server

Once upon a time, I had my mouse and keyboard input rudely stolen from me by a rogue SDL app. I had way too much stuff going on in X to throw it all away for some rude app, so I fought my way back! Here's how I did it...

Kill the app

First order of business is to kill the app that's causing the problem in the first place. If you can switch to a console with Ctrl+Alt+Fn, you're good to go, otherwise you'll have to login remotely. If you have no other machines handy, you may have to admit defeat and either kill X with Ctrl+Alt+Backspace, or, even worse, reboot the machine. kill, kill, and kill -9 until there is no remaining trace of the program.

Get your input back

There's a number of loosely related and intertwined steps to this.

  • kill -USR1 - I honestly have no idea what this is meant for, but it surely did something. Namely, it messed up my virtual consoles, but only temporarily. A ^L or 'clear' in your shell should get them back to normal. Update: Another X lockup was completely fixed by doing this a few times in a row. So it is quite useful. :)
  • xrefresh - This didn't seem to do anything, but hey, maybe it'll do something for you.
  • xvidtune -unlock - This got my mouse input (mostly) back (woohoo!).
  • I found some sdl C code for grabbing/ungrabbing input from a google search, and in light of other things, I don't think it did anything for me. My logic is trying to tell me that it shouldn't really do anything, either, but I don't know much about sdl, so I'll just play stupid and put it on this page anyways. Maybe it'll help you.
    /* compile with: gcc `sdl-config --cflags --libs` foo.c */
    #include "SDL.h"
    int main(void) {
      SDL_Init(SDL_INIT_VIDEO);
      SDL_WM_GrabInput(SDL_GRAB_ON);
      SDL_ShowCursor(0);
      SDL_WM_GrabInput(SDL_GRAB_OFF);
      SDL_ShowCursor(1);
      SDL_Quit();
      return 0;
    }
    UPDATE - Apparently this does help; Neverball bombed on me, and this fixed my mouse afterwards.
  • Fix your window manager - My alt key was working for a alt+mouse keybinding I have set up, and Ctrl+Alt+worked, but normal keys weren't working. And if I tried to move windows around, my mouse would get in this funky maybe-grabbed-maybe-not state. I ended up killing and restarting my [http://kahakai.sf.net wm a couple times, however, it seemed to have no effect - which I believe might be due to the fact that I was in a virtual console the whole time. Logically that makes no sense to me, but it seems that you can't use logic with computers and expect it to work out perfectly. Finally, I just used the "restart" option on my root menu, and all was well! The missing link. However -- due to the way that most peoples' X sessions are set up to run, you may not have room to work here.

Thanks to "fhffhqvb" and "izn0g" from #debian on freenode, and "Yorick" from #sdl on freenode.


Nick Welch <nick@incise.org> · github