test/testwm2.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5246 58265e606e4e
child 6677 c3202c29e352
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
     1 /*
     2   Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     3 
     4   This software is provided 'as-is', without any express or implied
     5   warranty.  In no event will the authors be held liable for any damages
     6   arising from the use of this software.
     7 
     8   Permission is granted to anyone to use this software for any purpose,
     9   including commercial applications, and to alter it and redistribute it
    10   freely.
    11 */
    12 
    13 #include <stdlib.h>
    14 #include <stdio.h>
    15 
    16 #include "common.h"
    17 
    18 static CommonState *state;
    19 
    20 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    21 static void
    22 quit(int rc)
    23 {
    24     CommonQuit(state);
    25     exit(rc);
    26 }
    27 
    28 int
    29 main(int argc, char *argv[])
    30 {
    31     int i, done;
    32     SDL_Event event;
    33 
    34     /* Initialize test framework */
    35     state = CommonCreateState(argv, SDL_INIT_VIDEO);
    36     if (!state) {
    37         return 1;
    38     }
    39     state->skip_renderer = SDL_TRUE;
    40     for (i = 1; i < argc;) {
    41         int consumed;
    42 
    43         consumed = CommonArg(state, i);
    44         if (consumed == 0) {
    45             consumed = -1;
    46         }
    47         if (consumed < 0) {
    48             fprintf(stderr, "Usage: %s %s\n", argv[0], CommonUsage(state));
    49             quit(1);
    50         }
    51         i += consumed;
    52     }
    53     if (!CommonInit(state)) {
    54         quit(2);
    55     }
    56 
    57     /* Main render loop */
    58     done = 0;
    59     while (!done) {
    60         /* Check for events */
    61         while (SDL_PollEvent(&event)) {
    62             CommonEvent(state, &event, &done);
    63 
    64             if (event.type == SDL_WINDOWEVENT) {
    65                 if (event.window.event == SDL_WINDOWEVENT_MOVED) {
    66                     SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
    67                     if (window) {
    68                         printf("Window %d moved to %d,%d (display %d)\n",
    69                             event.window.windowID,
    70                             event.window.data1,
    71                             event.window.data2,
    72                             SDL_GetWindowDisplay(window));
    73                     }
    74                 }
    75             }
    76         }
    77     }
    78     quit(0);
    79 	// keep the compiler happy ...
    80 	return(0);
    81 }
    82 
    83 /* vi: set ts=4 sw=4 expandtab: */