| 1 |
|
|---|
| 2 | #include <X11/Xutil.h>
|
|---|
| 3 | #include <SDL/SDL.h>
|
|---|
| 4 | #include <SDL/SDL_syswm.h>
|
|---|
| 5 |
|
|---|
| 6 | int
|
|---|
| 7 | main(void)
|
|---|
| 8 | {
|
|---|
| 9 | int rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE);
|
|---|
| 10 | SDL_Event event;
|
|---|
| 11 | SDL_SysWMinfo gSdlInfo;
|
|---|
| 12 |
|
|---|
| 13 | if (rc != 0)
|
|---|
| 14 | {
|
|---|
| 15 | printf("Error: SDL_InitSubSystem failed with message '%s'\n", SDL_GetError());
|
|---|
| 16 | return 1;
|
|---|
| 17 | }
|
|---|
| 18 | /* we need a video window for the keyboard stuff to work */
|
|---|
| 19 | if (!SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE | SDL_RESIZABLE))
|
|---|
| 20 | {
|
|---|
| 21 | printf("Error: could not set SDL video mode\n");
|
|---|
| 22 | return 1;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | SDL_VERSION(&gSdlInfo.version);
|
|---|
| 26 | if (!SDL_GetWMInfo(&gSdlInfo))
|
|---|
| 27 | {
|
|---|
| 28 | printf("Error: failed to retrieve WM info\n");
|
|---|
| 29 | return 1;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | SDL_WM_GrabInput(SDL_GRAB_ON);
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | // rc = XGrabKeyboard(gSdlInfo.info.x11.display, gSdlInfo.info.x11.window, False,
|
|---|
| 36 | // GrabModeAsync, GrabModeAsync, CurrentTime);
|
|---|
| 37 | while (SDL_WaitEvent(&event))
|
|---|
| 38 | {
|
|---|
| 39 | printf("(event->type=%d)\n", event.type);
|
|---|
| 40 | if (event.type == SDL_KEYDOWN)
|
|---|
| 41 | {
|
|---|
| 42 | printf("DOWN: MOD=%08x KEY=%08x %d %d\n",
|
|---|
| 43 | SDL_GetModState(), event.key.keysym.scancode,
|
|---|
| 44 | SDL_GetKeyState(NULL)[SDLK_RCTRL], SDL_GetKeyState(NULL)[SDLK_RSHIFT]);
|
|---|
| 45 | }
|
|---|
| 46 | else if (event.type == SDL_KEYUP)
|
|---|
| 47 | {
|
|---|
| 48 | printf("UP: MOD=%08x KEY=%08x %d %d\n",
|
|---|
| 49 | SDL_GetModState(), event.key.keysym.scancode,
|
|---|
| 50 | SDL_GetKeyState(NULL)[SDLK_RCTRL], SDL_GetKeyState(NULL)[SDLK_RSHIFT]);
|
|---|
| 51 | }
|
|---|
| 52 | else if (event.type == SDL_MOUSEMOTION)
|
|---|
| 53 | {
|
|---|
| 54 | printf("MOTION: %d %d\n",
|
|---|
| 55 | event.motion.x, event.motion.y);
|
|---|
| 56 | }
|
|---|
| 57 | else if (event.type == SDL_MOUSEBUTTONDOWN)
|
|---|
| 58 | {
|
|---|
| 59 | printf("BTNUP: %x, %d\n",
|
|---|
| 60 | event.button.button, event.button.state);
|
|---|
| 61 | }
|
|---|
| 62 | else if (event.type == SDL_MOUSEBUTTONUP)
|
|---|
| 63 | {
|
|---|
| 64 | printf("BTNUP: %x, %d\n",
|
|---|
| 65 | event.button.button, event.button.state);
|
|---|
| 66 | }
|
|---|
| 67 | #if 0
|
|---|
| 68 | else if (event.type == SDL_ACTIVEEVENT)
|
|---|
| 69 | {
|
|---|
| 70 | printf("ACTIVE: %x %x\n",
|
|---|
| 71 | ((SDL_ActiveEvent*)&event)->gain,
|
|---|
| 72 | ((SDL_ActiveEvent*)&event)->state);
|
|---|
| 73 | }
|
|---|
| 74 | #endif
|
|---|
| 75 | if (event.key.keysym.sym == SDLK_q)
|
|---|
| 76 | break;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | SDL_Quit();
|
|---|
| 80 | return 0;
|
|---|
| 81 | }
|
|---|