testwm2.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely.
  9. */
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include "SDL_test_common.h"
  13. static SDLTest_CommonState *state;
  14. /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
  15. static void
  16. quit(int rc)
  17. {
  18. SDLTest_CommonQuit(state);
  19. exit(rc);
  20. }
  21. int
  22. main(int argc, char *argv[])
  23. {
  24. static const char *cursorNames[] = {
  25. "arrow",
  26. "ibeam",
  27. "wait",
  28. "crosshair",
  29. "waitarrow",
  30. "sizeNWSE",
  31. "sizeNESW",
  32. "sizeWE",
  33. "sizeNS",
  34. "sizeALL",
  35. "NO",
  36. "hand",
  37. };
  38. int i, done;
  39. SDL_Event event;
  40. int system_cursor = -1;
  41. SDL_Cursor *cursor = NULL;
  42. /* Enable standard application logging */
  43. SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  44. SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
  45. /* Initialize test framework */
  46. state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
  47. if (!state) {
  48. return 1;
  49. }
  50. state->skip_renderer = SDL_TRUE;
  51. for (i = 1; i < argc;) {
  52. int consumed;
  53. consumed = SDLTest_CommonArg(state, i);
  54. if (consumed == 0) {
  55. consumed = -1;
  56. }
  57. if (consumed < 0) {
  58. SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
  59. quit(1);
  60. }
  61. i += consumed;
  62. }
  63. if (!SDLTest_CommonInit(state)) {
  64. quit(2);
  65. }
  66. /* Main render loop */
  67. done = 0;
  68. while (!done) {
  69. /* Check for events */
  70. while (SDL_PollEvent(&event)) {
  71. SDLTest_CommonEvent(state, &event, &done);
  72. if (event.type == SDL_WINDOWEVENT) {
  73. if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
  74. SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
  75. if (window) {
  76. SDL_Log("Window %d resized to %dx%d\n",
  77. event.window.windowID,
  78. event.window.data1,
  79. event.window.data2);
  80. }
  81. }
  82. if (event.window.event == SDL_WINDOWEVENT_MOVED) {
  83. SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
  84. if (window) {
  85. SDL_Log("Window %d moved to %d,%d (display %s)\n",
  86. event.window.windowID,
  87. event.window.data1,
  88. event.window.data2,
  89. SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
  90. }
  91. }
  92. }
  93. if (event.type == SDL_KEYUP) {
  94. SDL_bool updateCursor = SDL_FALSE;
  95. if (event.key.keysym.sym == SDLK_LEFT) {
  96. --system_cursor;
  97. if (system_cursor < 0) {
  98. system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
  99. }
  100. updateCursor = SDL_TRUE;
  101. } else if (event.key.keysym.sym == SDLK_RIGHT) {
  102. ++system_cursor;
  103. if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
  104. system_cursor = 0;
  105. }
  106. updateCursor = SDL_TRUE;
  107. }
  108. if (updateCursor) {
  109. SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
  110. SDL_FreeCursor(cursor);
  111. cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
  112. SDL_SetCursor(cursor);
  113. }
  114. }
  115. }
  116. }
  117. SDL_FreeCursor(cursor);
  118. quit(0);
  119. /* keep the compiler happy ... */
  120. return(0);
  121. }
  122. /* vi: set ts=4 sw=4 expandtab: */