Skip to content

Latest commit

 

History

History
243 lines (195 loc) · 7.42 KB

SDL_waylandwindow.c

File metadata and controls

243 lines (195 loc) · 7.42 KB
 
Dec 14, 2013
Dec 14, 2013
1
2
/*
Simple DirectMedia Layer
Feb 2, 2014
Feb 2, 2014
3
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Dec 14, 2013
Dec 14, 2013
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
Jan 9, 2014
Jan 9, 2014
22
#include "../../SDL_internal.h"
Dec 14, 2013
Dec 14, 2013
23
Jan 20, 2014
Jan 20, 2014
24
25
#if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL
Dec 14, 2013
Dec 14, 2013
26
27
28
29
30
#include "../SDL_sysvideo.h"
#include "../../events/SDL_windowevents_c.h"
#include "../SDL_egl_c.h"
#include "SDL_waylandwindow.h"
#include "SDL_waylandvideo.h"
Dec 27, 2013
Dec 27, 2013
31
#include "SDL_waylandtouch.h"
Dec 14, 2013
Dec 14, 2013
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
static void
handle_ping(void *data, struct wl_shell_surface *shell_surface,
uint32_t serial)
{
wl_shell_surface_pong(shell_surface, serial);
}
static void
handle_configure(void *data, struct wl_shell_surface *shell_surface,
uint32_t edges, int32_t width, int32_t height)
{
}
static void
handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
{
}
static const struct wl_shell_surface_listener shell_surface_listener = {
handle_ping,
handle_configure,
handle_popup_done
};
Dec 27, 2013
Dec 27, 2013
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
static void
handle_onscreen_visibility(void *data,
struct qt_extended_surface *qt_extended_surface, int32_t visible)
{
}
static void
handle_set_generic_property(void *data,
struct qt_extended_surface *qt_extended_surface, const char *name,
struct wl_array *value)
{
}
static void
handle_close(void *data, struct qt_extended_surface *qt_extended_surface)
{
SDL_WindowData *window = (SDL_WindowData *)data;
SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
}
static const struct qt_extended_surface_listener extended_surface_listener = {
handle_onscreen_visibility,
handle_set_generic_property,
handle_close,
};
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
Dec 14, 2013
Dec 14, 2013
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
SDL_bool
Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
info->info.wl.display = data->waylandData->display;
info->info.wl.surface = data->surface;
info->info.wl.shell_surface = data->shell_surface;
info->subsystem = SDL_SYSWM_WAYLAND;
return SDL_TRUE;
}
void Wayland_ShowWindow(_THIS, SDL_Window *window)
{
SDL_WindowData *wind = window->driverdata;
if (window->flags & SDL_WINDOW_FULLSCREEN)
wl_shell_surface_set_fullscreen(wind->shell_surface,
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
0, NULL);
else
wl_shell_surface_set_toplevel(wind->shell_surface);
Jan 9, 2014
Jan 9, 2014
109
WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
Dec 14, 2013
Dec 14, 2013
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
}
void
Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
SDL_VideoDisplay * _display, SDL_bool fullscreen)
{
SDL_WindowData *wind = window->driverdata;
if (fullscreen)
wl_shell_surface_set_fullscreen(wind->shell_surface,
WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE,
0, NULL);
else
wl_shell_surface_set_toplevel(wind->shell_surface);
Jan 9, 2014
Jan 9, 2014
125
WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
Dec 14, 2013
Dec 14, 2013
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
}
int Wayland_CreateWindow(_THIS, SDL_Window *window)
{
SDL_WindowData *data;
SDL_VideoData *c;
struct wl_region *region;
data = calloc(1, sizeof *data);
if (data == NULL)
return 0;
c = _this->driverdata;
window->driverdata = data;
if (!(window->flags & SDL_WINDOW_OPENGL)) {
SDL_GL_LoadLibrary(NULL);
window->flags |= SDL_WINDOW_OPENGL;
}
if (window->x == SDL_WINDOWPOS_UNDEFINED) {
window->x = 0;
}
if (window->y == SDL_WINDOWPOS_UNDEFINED) {
window->y = 0;
}
data->waylandData = c;
data->sdlwindow = window;
data->surface =
wl_compositor_create_surface(c->compositor);
wl_surface_set_user_data(data->surface, data);
data->shell_surface = wl_shell_get_shell_surface(c->shell,
data->surface);
Dec 27, 2013
Dec 27, 2013
161
162
163
164
165
166
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
if (c->surface_extension) {
data->extended_surface = qt_surface_extension_get_extended_surface(
c->surface_extension, data->surface);
}
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
Jan 9, 2014
Jan 9, 2014
167
data->egl_window = WAYLAND_wl_egl_window_create(data->surface,
Dec 14, 2013
Dec 14, 2013
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
window->w, window->h);
/* Create the GLES window surface */
data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
if (data->egl_surface == EGL_NO_SURFACE) {
SDL_SetError("failed to create a window surface");
return -1;
}
if (data->shell_surface) {
wl_shell_surface_set_user_data(data->shell_surface, data);
wl_shell_surface_add_listener(data->shell_surface,
&shell_surface_listener, data);
}
Dec 27, 2013
Dec 27, 2013
184
185
186
187
188
189
190
191
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
if (data->extended_surface) {
qt_extended_surface_set_user_data(data->extended_surface, data);
qt_extended_surface_add_listener(data->extended_surface,
&extended_surface_listener, data);
}
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
Dec 14, 2013
Dec 14, 2013
192
193
194
195
196
region = wl_compositor_create_region(c->compositor);
wl_region_add(region, 0, 0, window->w, window->h);
wl_surface_set_opaque_region(data->surface, region);
wl_region_destroy(region);
Jan 9, 2014
Jan 9, 2014
197
WAYLAND_wl_display_flush(c->display);
Dec 14, 2013
Dec 14, 2013
198
199
200
201
202
203
204
205
206
207
return 0;
}
void Wayland_SetWindowSize(_THIS, SDL_Window * window)
{
SDL_VideoData *data = _this->driverdata;
SDL_WindowData *wind = window->driverdata;
struct wl_region *region;
Jan 9, 2014
Jan 9, 2014
208
WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
Dec 14, 2013
Dec 14, 2013
209
Jan 9, 2014
Jan 9, 2014
210
region =wl_compositor_create_region(data->compositor);
Dec 14, 2013
Dec 14, 2013
211
212
213
214
215
216
217
218
219
220
221
222
223
224
wl_region_add(region, 0, 0, window->w, window->h);
wl_surface_set_opaque_region(wind->surface, region);
wl_region_destroy(region);
}
void Wayland_DestroyWindow(_THIS, SDL_Window *window)
{
SDL_VideoData *data = _this->driverdata;
SDL_WindowData *wind = window->driverdata;
window->driverdata = NULL;
if (data) {
SDL_EGL_DestroySurface(_this, wind->egl_surface);
Jan 9, 2014
Jan 9, 2014
225
WAYLAND_wl_egl_window_destroy(wind->egl_window);
Dec 14, 2013
Dec 14, 2013
226
227
228
229
if (wind->shell_surface)
wl_shell_surface_destroy(wind->shell_surface);
Dec 27, 2013
Dec 27, 2013
230
231
232
233
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
if (wind->extended_surface)
qt_extended_surface_destroy(wind->extended_surface);
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
Dec 14, 2013
Dec 14, 2013
234
235
236
wl_surface_destroy(wind->surface);
SDL_free(wind);
Jan 9, 2014
Jan 9, 2014
237
WAYLAND_wl_display_flush(data->display);
Dec 14, 2013
Dec 14, 2013
238
239
240
}
}
Jan 20, 2014
Jan 20, 2014
241
242
#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */
Dec 14, 2013
Dec 14, 2013
243
/* vi: set ts=4 sw=4 expandtab: */