Merge: doc: fixed some typos and other misc. corrections
[nit.git] / lib / sdl2 / syswm.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Window manager related SDL 2 services
18 module syswm is pkgconfig "sdl2"
19
20 import sdl2_base
21
22 in "C Header" `{
23 #include <SDL2/SDL_syswm.h>
24 `}
25
26 redef extern class SDLWindow
27 # Get the `SDLSysVMInfo` for the system running this window
28 #
29 # The returned value must be freed.
30 fun wm_info: SDLSysWMInfo `{
31 SDL_SysWMinfo *val = malloc(sizeof(SDL_SysWMinfo));
32
33 SDL_VERSION(&val->version);
34
35 if(SDL_GetWindowWMInfo(self, val) <= 0) {
36 free(val);
37 return NULL;
38 }
39
40 return val;
41 `}
42 end
43
44 # Information on the window manager
45 #
46 # Created using `SDLWindow::vm_info`
47 extern class SDLSysWMInfo `{ SDL_SysWMinfo * `}
48 # Is this an unknown window manager?
49 fun is_unknown: Bool `{ return self->subsystem == SDL_SYSWM_UNKNOWN; `}
50
51 # Is this a Windows system?
52 fun is_windows: Bool `{ return self->subsystem == SDL_SYSWM_WINDOWS; `}
53
54 # Is this the X11 window manager?
55 fun is_x11: Bool `{ return self->subsystem == SDL_SYSWM_X11; `}
56
57 # Is this a direct DirectFB?
58 fun is_direcfb: Bool `{ return self->subsystem == SDL_SYSWM_DIRECTFB; `}
59
60 # Is this system an OS X?
61 fun is_cocoa: Bool `{ return self->subsystem == SDL_SYSWM_COCOA; `}
62
63 # Is this system an iOS?
64 fun is_uikit: Bool `{ return self->subsystem == SDL_SYSWM_UIKIT; `}
65
66 # It this window manager Wayland?
67 fun is_wayland: Bool `{
68 #if SDL_VERSION_ATLEAST(2, 0, 2)
69 return self->subsystem == SDL_SYSWM_WAYLAND;
70 #else
71 return 0;
72 #endif
73 `}
74
75 # It this window manager Mir?
76 fun is_mir: Bool `{
77 #if SDL_VERSION_ATLEAST(2, 0, 3)
78 return self->subsystem == SDL_SYSWM_MIR;
79 #else
80 return 0;
81 #endif
82 `}
83
84 # Is this system a Windows RT?
85 fun is_winrt: Bool `{
86 #if SDL_VERSION_ATLEAST(2, 0, 3)
87 return self->subsystem == SDL_SYSWM_WINRT;
88 #else
89 return 0;
90 #endif
91 `}
92
93 # Is this system an Android?
94 fun is_android: Bool `{
95 #if SDL_VERSION_ATLEAST(2, 0, 4)
96 return self->subsystem == SDL_SYSWM_ANDROID;
97 #else
98 return 0;
99 #endif
100 `}
101
102 # Handle to the window
103 fun window_handle: Pointer `{
104 #ifdef _WIN32
105 return (void*)self->info.win.window;
106 #else
107 return (void*)self->info.x11.window;
108 #endif
109 `}
110
111 # Handle to the display or device context
112 fun display_handle: Pointer `{
113 #ifdef _WIN32
114 return (void*)self->info.win.hdc;
115 #else
116 return (void*)self->info.x11.display;
117 #endif
118 `}
119 end