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