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.
slouken@1895
     1
slouken@1933
     2
#include <stdlib.h>
slouken@1933
     3
#include <stdio.h>
slouken@1895
     4
slouken@1933
     5
#include "common.h"
slouken@1895
     6
slouken@1933
     7
static CommonState *state;
slouken@1895
     8
slouken@1895
     9
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
slouken@1895
    10
static void
slouken@1895
    11
quit(int rc)
slouken@1895
    12
{
slouken@1933
    13
    CommonQuit(state);
slouken@1895
    14
    exit(rc);
slouken@1895
    15
}
slouken@1895
    16
slouken@1895
    17
int
slouken@1895
    18
main(int argc, char *argv[])
slouken@1895
    19
{
slouken@1895
    20
    int i, done;
slouken@1895
    21
    SDL_Event event;
slouken@1895
    22
slouken@1933
    23
    /* Initialize test framework */
slouken@1933
    24
    state = CommonCreateState(argv, SDL_INIT_VIDEO);
slouken@1933
    25
    if (!state) {
slouken@1933
    26
        return 1;
slouken@1933
    27
    }
slouken@1933
    28
    state->skip_renderer = SDL_TRUE;
slouken@1933
    29
    for (i = 1; i < argc;) {
slouken@1933
    30
        int consumed;
slouken@1933
    31
slouken@1933
    32
        consumed = CommonArg(state, i);
slouken@1933
    33
        if (consumed == 0) {
slouken@1933
    34
            consumed = -1;
slouken@1933
    35
        }
slouken@1933
    36
        if (consumed < 0) {
slouken@1985
    37
            fprintf(stderr, "Usage: %s %s\n", argv[0], CommonUsage(state));
slouken@1933
    38
            quit(1);
slouken@1933
    39
        }
slouken@1933
    40
        i += consumed;
slouken@1933
    41
    }
slouken@1933
    42
    if (!CommonInit(state)) {
slouken@1933
    43
        quit(2);
slouken@1895
    44
    }
slouken@1895
    45
slouken@1933
    46
    /* Main render loop */
slouken@1895
    47
    done = 0;
slouken@1895
    48
    while (!done) {
slouken@1895
    49
        /* Check for events */
slouken@1895
    50
        while (SDL_PollEvent(&event)) {
slouken@1933
    51
            CommonEvent(state, &event, &done);
slouken@5246
    52
slouken@5246
    53
            if (event.type == SDL_WINDOWEVENT) {
slouken@5246
    54
                if (event.window.event == SDL_WINDOWEVENT_MOVED) {
slouken@5246
    55
                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
slouken@5246
    56
                    if (window) {
slouken@5246
    57
                        printf("Window %d moved to %d,%d (display %d)\n",
slouken@5246
    58
                            event.window.windowID,
slouken@5246
    59
                            event.window.data1,
slouken@5246
    60
                            event.window.data2,
slouken@5246
    61
                            SDL_GetWindowDisplay(window));
slouken@5246
    62
                    }
slouken@5246
    63
                }
slouken@5246
    64
            }
slouken@1895
    65
        }
slouken@1895
    66
    }
slouken@1895
    67
    quit(0);
slouken@3338
    68
	// keep the compiler happy ...
slouken@3338
    69
	return(0);
slouken@1895
    70
}
slouken@1895
    71
slouken@1895
    72
/* vi: set ts=4 sw=4 expandtab: */