File: relative_mode.markdown

package info (click to toggle)
mame 0.251%2Bdfsg.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 859,568 kB
  • sloc: cpp: 4,850,249; xml: 2,104,459; ansic: 775,189; sh: 52,227; lisp: 19,397; python: 15,553; makefile: 11,465; cs: 10,485; yacc: 8,133; java: 7,151; javascript: 7,117; objc: 5,791; asm: 1,794; ada: 1,681; perl: 1,673; lex: 1,174; pascal: 1,139; ruby: 347; awk: 35
file content (58 lines) | stat: -rw-r--r-- 1,283 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Relative mode testing
=====================

See test program at the bottom of this file.

Initial tests:

 - When in relative mode, the mouse shouldn't be moveable outside of the window.
 - When the cursor is outside the window when relative mode is enabled, mouse
   clicks should not go to whatever app was under the cursor previously.
 - When alt/cmd-tabbing between a relative mode app and another app, clicks when
   in the relative mode app should also not go to whatever app was under the
   cursor previously.


Code
====

    #include <SDL.h>

    int PollEvents()
    {
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
                case SDL_QUIT:
                    return 1;
                default:
                    break;
            }
        }

        return 0;
    }

    int main(int argc, char *argv[])
    {
        SDL_Window *win;

        SDL_Init(SDL_INIT_VIDEO);

        win = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, 0);
        SDL_SetRelativeMouseMode(SDL_TRUE);

        while (1)
        {
            if (PollEvents())
                break;
        }

        SDL_DestroyWindow(win);

        SDL_Quit();

        return 0;
    }