test/testwm2.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 10 Feb 2011 14:44:25 -0800
changeset 5246 58265e606e4e
parent 3338 9de326b3099c
child 5535 96594ac5fd1a
permissions -rw-r--r--
Window coordinates are in the global space and windows are not tied to a particular display.
Also added Ctrl-Enter keybinding to the test code to toggle fullscreen mode for testing.
     1 
     2 #include <stdlib.h>
     3 #include <stdio.h>
     4 
     5 #include "common.h"
     6 
     7 static CommonState *state;
     8 
     9 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    10 static void
    11 quit(int rc)
    12 {
    13     CommonQuit(state);
    14     exit(rc);
    15 }
    16 
    17 int
    18 main(int argc, char *argv[])
    19 {
    20     int i, done;
    21     SDL_Event event;
    22 
    23     /* Initialize test framework */
    24     state = CommonCreateState(argv, SDL_INIT_VIDEO);
    25     if (!state) {
    26         return 1;
    27     }
    28     state->skip_renderer = SDL_TRUE;
    29     for (i = 1; i < argc;) {
    30         int consumed;
    31 
    32         consumed = CommonArg(state, i);
    33         if (consumed == 0) {
    34             consumed = -1;
    35         }
    36         if (consumed < 0) {
    37             fprintf(stderr, "Usage: %s %s\n", argv[0], CommonUsage(state));
    38             quit(1);
    39         }
    40         i += consumed;
    41     }
    42     if (!CommonInit(state)) {
    43         quit(2);
    44     }
    45 
    46     /* Main render loop */
    47     done = 0;
    48     while (!done) {
    49         /* Check for events */
    50         while (SDL_PollEvent(&event)) {
    51             CommonEvent(state, &event, &done);
    52 
    53             if (event.type == SDL_WINDOWEVENT) {
    54                 if (event.window.event == SDL_WINDOWEVENT_MOVED) {
    55                     SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
    56                     if (window) {
    57                         printf("Window %d moved to %d,%d (display %d)\n",
    58                             event.window.windowID,
    59                             event.window.data1,
    60                             event.window.data2,
    61                             SDL_GetWindowDisplay(window));
    62                     }
    63                 }
    64             }
    65         }
    66     }
    67     quit(0);
    68 	// keep the compiler happy ...
    69 	return(0);
    70 }
    71 
    72 /* vi: set ts=4 sw=4 expandtab: */