Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU SDL display driver |
| 3 | * |
| 4 | * Copyright (c) 2003 Fabrice Bellard |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */ |
| 25 | |
| 26 | /* Avoid compiler warning because macro is redefined in SDL_syswm.h. */ |
| 27 | #undef WIN32_LEAN_AND_MEAN |
| 28 | |
| 29 | #include <SDL.h> |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 30 | #include <SDL_syswm.h> |
| 31 | |
| 32 | #include "qemu-common.h" |
| 33 | #include "ui/console.h" |
| 34 | #include "ui/input.h" |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 35 | #include "ui/sdl2.h" |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 36 | #include "sysemu/sysemu.h" |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 37 | |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 38 | static int sdl2_num_outputs; |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 39 | static struct sdl2_console *sdl2_console; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 40 | |
| 41 | static SDL_Surface *guest_sprite_surface; |
| 42 | static int gui_grab; /* if true, all keyboard/mouse events are grabbed */ |
| 43 | |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 44 | static int gui_saved_grab; |
| 45 | static int gui_fullscreen; |
| 46 | static int gui_noframe; |
| 47 | static int gui_key_modifier_pressed; |
| 48 | static int gui_keysym; |
| 49 | static int gui_grab_code = KMOD_LALT | KMOD_LCTRL; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 50 | static SDL_Cursor *sdl_cursor_normal; |
| 51 | static SDL_Cursor *sdl_cursor_hidden; |
| 52 | static int absolute_enabled; |
| 53 | static int guest_cursor; |
| 54 | static int guest_x, guest_y; |
| 55 | static SDL_Cursor *guest_sprite; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 56 | static Notifier mouse_mode_notifier; |
| 57 | |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 58 | static void sdl_update_caption(struct sdl2_console *scon); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 59 | |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 60 | static struct sdl2_console *get_scon_from_window(uint32_t window_id) |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 61 | { |
| 62 | int i; |
| 63 | for (i = 0; i < sdl2_num_outputs; i++) { |
| 64 | if (sdl2_console[i].real_window == SDL_GetWindowFromID(window_id)) { |
| 65 | return &sdl2_console[i]; |
| 66 | } |
| 67 | } |
| 68 | return NULL; |
| 69 | } |
| 70 | |
Gerd Hoffmann | 2c3056f | 2014-11-11 13:22:49 +0100 | [diff] [blame] | 71 | void sdl2_window_create(struct sdl2_console *scon) |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 72 | { |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 73 | int flags = 0; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 74 | |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 75 | if (!scon->surface) { |
| 76 | return; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 77 | } |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 78 | assert(!scon->real_window); |
| 79 | |
| 80 | if (gui_fullscreen) { |
| 81 | flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; |
| 82 | } else { |
| 83 | flags |= SDL_WINDOW_RESIZABLE; |
| 84 | } |
| 85 | if (scon->hidden) { |
| 86 | flags |= SDL_WINDOW_HIDDEN; |
| 87 | } |
| 88 | |
| 89 | scon->real_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, |
| 90 | SDL_WINDOWPOS_UNDEFINED, |
| 91 | surface_width(scon->surface), |
| 92 | surface_height(scon->surface), |
| 93 | flags); |
| 94 | scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0); |
| 95 | sdl_update_caption(scon); |
| 96 | } |
| 97 | |
Gerd Hoffmann | 2c3056f | 2014-11-11 13:22:49 +0100 | [diff] [blame] | 98 | void sdl2_window_destroy(struct sdl2_console *scon) |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 99 | { |
| 100 | if (!scon->real_window) { |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | SDL_DestroyRenderer(scon->real_renderer); |
| 105 | scon->real_renderer = NULL; |
| 106 | SDL_DestroyWindow(scon->real_window); |
| 107 | scon->real_window = NULL; |
| 108 | } |
| 109 | |
Gerd Hoffmann | 2c3056f | 2014-11-11 13:22:49 +0100 | [diff] [blame] | 110 | void sdl2_window_resize(struct sdl2_console *scon) |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 111 | { |
| 112 | if (!scon->real_window) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | SDL_SetWindowSize(scon->real_window, |
| 117 | surface_width(scon->surface), |
| 118 | surface_height(scon->surface)); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 119 | } |
| 120 | |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 121 | static void sdl_update_caption(struct sdl2_console *scon) |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 122 | { |
| 123 | char win_title[1024]; |
| 124 | char icon_title[1024]; |
| 125 | const char *status = ""; |
| 126 | |
| 127 | if (!runstate_is_running()) { |
| 128 | status = " [Stopped]"; |
| 129 | } else if (gui_grab) { |
| 130 | if (alt_grab) { |
Gerd Hoffmann | 44f017d | 2014-11-11 12:02:50 +0100 | [diff] [blame] | 131 | status = " - Press Ctrl-Alt-Shift to exit grab"; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 132 | } else if (ctrl_grab) { |
Gerd Hoffmann | 44f017d | 2014-11-11 12:02:50 +0100 | [diff] [blame] | 133 | status = " - Press Right-Ctrl to exit grab"; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 134 | } else { |
Gerd Hoffmann | 44f017d | 2014-11-11 12:02:50 +0100 | [diff] [blame] | 135 | status = " - Press Ctrl-Alt to exit grab"; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | if (qemu_name) { |
| 140 | snprintf(win_title, sizeof(win_title), "QEMU (%s-%d)%s", qemu_name, |
| 141 | scon->idx, status); |
| 142 | snprintf(icon_title, sizeof(icon_title), "QEMU (%s)", qemu_name); |
| 143 | } else { |
| 144 | snprintf(win_title, sizeof(win_title), "QEMU%s", status); |
| 145 | snprintf(icon_title, sizeof(icon_title), "QEMU"); |
| 146 | } |
| 147 | |
| 148 | if (scon->real_window) { |
| 149 | SDL_SetWindowTitle(scon->real_window, win_title); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | static void sdl_hide_cursor(void) |
| 154 | { |
| 155 | if (!cursor_hide) { |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | if (qemu_input_is_absolute()) { |
| 160 | SDL_ShowCursor(1); |
| 161 | SDL_SetCursor(sdl_cursor_hidden); |
| 162 | } else { |
Cole Robinson | 2d968ff | 2014-04-01 16:37:11 -0400 | [diff] [blame] | 163 | SDL_SetRelativeMouseMode(SDL_TRUE); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | static void sdl_show_cursor(void) |
| 168 | { |
| 169 | if (!cursor_hide) { |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | if (!qemu_input_is_absolute()) { |
Cole Robinson | 2d968ff | 2014-04-01 16:37:11 -0400 | [diff] [blame] | 174 | SDL_SetRelativeMouseMode(SDL_FALSE); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 175 | SDL_ShowCursor(1); |
| 176 | if (guest_cursor && |
| 177 | (gui_grab || qemu_input_is_absolute() || absolute_enabled)) { |
| 178 | SDL_SetCursor(guest_sprite); |
| 179 | } else { |
| 180 | SDL_SetCursor(sdl_cursor_normal); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 185 | static void sdl_grab_start(struct sdl2_console *scon) |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 186 | { |
Gerd Hoffmann | f233579 | 2014-05-26 14:05:51 +0200 | [diff] [blame] | 187 | QemuConsole *con = scon ? scon->dcl.con : NULL; |
| 188 | |
| 189 | if (!con || !qemu_console_is_graphic(con)) { |
| 190 | return; |
| 191 | } |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 192 | /* |
| 193 | * If the application is not active, do not try to enter grab state. This |
| 194 | * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the |
| 195 | * application (SDL bug). |
| 196 | */ |
| 197 | if (!(SDL_GetWindowFlags(scon->real_window) & SDL_WINDOW_INPUT_FOCUS)) { |
| 198 | return; |
| 199 | } |
| 200 | if (guest_cursor) { |
| 201 | SDL_SetCursor(guest_sprite); |
| 202 | if (!qemu_input_is_absolute() && !absolute_enabled) { |
| 203 | SDL_WarpMouseInWindow(scon->real_window, guest_x, guest_y); |
| 204 | } |
| 205 | } else { |
| 206 | sdl_hide_cursor(); |
| 207 | } |
| 208 | SDL_SetWindowGrab(scon->real_window, SDL_TRUE); |
| 209 | gui_grab = 1; |
| 210 | sdl_update_caption(scon); |
| 211 | } |
| 212 | |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 213 | static void sdl_grab_end(struct sdl2_console *scon) |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 214 | { |
| 215 | SDL_SetWindowGrab(scon->real_window, SDL_FALSE); |
| 216 | gui_grab = 0; |
| 217 | sdl_show_cursor(); |
| 218 | sdl_update_caption(scon); |
| 219 | } |
| 220 | |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 221 | static void absolute_mouse_grab(struct sdl2_console *scon) |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 222 | { |
| 223 | int mouse_x, mouse_y; |
| 224 | int scr_w, scr_h; |
| 225 | SDL_GetMouseState(&mouse_x, &mouse_y); |
| 226 | SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h); |
| 227 | if (mouse_x > 0 && mouse_x < scr_w - 1 && |
| 228 | mouse_y > 0 && mouse_y < scr_h - 1) { |
| 229 | sdl_grab_start(scon); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | static void sdl_mouse_mode_change(Notifier *notify, void *data) |
| 234 | { |
| 235 | if (qemu_input_is_absolute()) { |
| 236 | if (!absolute_enabled) { |
| 237 | absolute_enabled = 1; |
| 238 | absolute_mouse_grab(&sdl2_console[0]); |
| 239 | } |
| 240 | } else if (absolute_enabled) { |
| 241 | if (!gui_fullscreen) { |
| 242 | sdl_grab_end(&sdl2_console[0]); |
| 243 | } |
| 244 | absolute_enabled = 0; |
| 245 | } |
| 246 | } |
| 247 | |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 248 | static void sdl_send_mouse_event(struct sdl2_console *scon, int dx, int dy, |
Cole Robinson | 3f2fde2 | 2014-04-21 18:58:50 -0400 | [diff] [blame] | 249 | int x, int y, int state) |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 250 | { |
| 251 | static uint32_t bmap[INPUT_BUTTON_MAX] = { |
| 252 | [INPUT_BUTTON_LEFT] = SDL_BUTTON(SDL_BUTTON_LEFT), |
| 253 | [INPUT_BUTTON_MIDDLE] = SDL_BUTTON(SDL_BUTTON_MIDDLE), |
| 254 | [INPUT_BUTTON_RIGHT] = SDL_BUTTON(SDL_BUTTON_RIGHT), |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 255 | }; |
| 256 | static uint32_t prev_state; |
| 257 | |
| 258 | if (prev_state != state) { |
| 259 | qemu_input_update_buttons(scon->dcl.con, bmap, prev_state, state); |
| 260 | prev_state = state; |
| 261 | } |
| 262 | |
| 263 | if (qemu_input_is_absolute()) { |
| 264 | int scr_w, scr_h; |
| 265 | int max_w = 0, max_h = 0; |
| 266 | int off_x = 0, off_y = 0; |
| 267 | int cur_off_x = 0, cur_off_y = 0; |
| 268 | int i; |
| 269 | |
| 270 | for (i = 0; i < sdl2_num_outputs; i++) { |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 271 | struct sdl2_console *thiscon = &sdl2_console[i]; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 272 | if (thiscon->real_window && thiscon->surface) { |
| 273 | SDL_GetWindowSize(thiscon->real_window, &scr_w, &scr_h); |
| 274 | cur_off_x = thiscon->x; |
| 275 | cur_off_y = thiscon->y; |
| 276 | if (scr_w + cur_off_x > max_w) { |
| 277 | max_w = scr_w + cur_off_x; |
| 278 | } |
| 279 | if (scr_h + cur_off_y > max_h) { |
| 280 | max_h = scr_h + cur_off_y; |
| 281 | } |
| 282 | if (i == scon->idx) { |
| 283 | off_x = cur_off_x; |
| 284 | off_y = cur_off_y; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_X, off_x + x, max_w); |
| 289 | qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_Y, off_y + y, max_h); |
Cole Robinson | afbc0dd | 2014-04-01 16:37:10 -0400 | [diff] [blame] | 290 | } else { |
| 291 | if (guest_cursor) { |
| 292 | x -= guest_x; |
| 293 | y -= guest_y; |
| 294 | guest_x += x; |
| 295 | guest_y += y; |
| 296 | dx = x; |
| 297 | dy = y; |
| 298 | } |
| 299 | qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_X, dx); |
| 300 | qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_Y, dy); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 301 | } |
| 302 | qemu_input_event_sync(); |
| 303 | } |
| 304 | |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 305 | static void toggle_full_screen(struct sdl2_console *scon) |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 306 | { |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 307 | gui_fullscreen = !gui_fullscreen; |
| 308 | if (gui_fullscreen) { |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 309 | SDL_SetWindowFullscreen(scon->real_window, |
| 310 | SDL_WINDOW_FULLSCREEN_DESKTOP); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 311 | gui_saved_grab = gui_grab; |
| 312 | sdl_grab_start(scon); |
| 313 | } else { |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 314 | if (!gui_saved_grab) { |
| 315 | sdl_grab_end(scon); |
| 316 | } |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 317 | SDL_SetWindowFullscreen(scon->real_window, 0); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 318 | } |
Gerd Hoffmann | 0d01b7c | 2014-11-11 13:31:08 +0100 | [diff] [blame] | 319 | sdl2_2d_redraw(scon); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | static void handle_keydown(SDL_Event *ev) |
| 323 | { |
Gerd Hoffmann | 363f59d | 2014-05-27 09:44:39 +0200 | [diff] [blame] | 324 | int mod_state, win; |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 325 | struct sdl2_console *scon = get_scon_from_window(ev->key.windowID); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 326 | |
| 327 | if (alt_grab) { |
| 328 | mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) == |
| 329 | (gui_grab_code | KMOD_LSHIFT); |
| 330 | } else if (ctrl_grab) { |
| 331 | mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL; |
| 332 | } else { |
| 333 | mod_state = (SDL_GetModState() & gui_grab_code) == gui_grab_code; |
| 334 | } |
| 335 | gui_key_modifier_pressed = mod_state; |
| 336 | |
| 337 | if (gui_key_modifier_pressed) { |
| 338 | switch (ev->key.keysym.scancode) { |
Gerd Hoffmann | 363f59d | 2014-05-27 09:44:39 +0200 | [diff] [blame] | 339 | case SDL_SCANCODE_2: |
| 340 | case SDL_SCANCODE_3: |
| 341 | case SDL_SCANCODE_4: |
| 342 | case SDL_SCANCODE_5: |
| 343 | case SDL_SCANCODE_6: |
| 344 | case SDL_SCANCODE_7: |
| 345 | case SDL_SCANCODE_8: |
| 346 | case SDL_SCANCODE_9: |
| 347 | win = ev->key.keysym.scancode - SDL_SCANCODE_1; |
| 348 | if (win < sdl2_num_outputs) { |
| 349 | sdl2_console[win].hidden = !sdl2_console[win].hidden; |
| 350 | if (sdl2_console[win].real_window) { |
| 351 | if (sdl2_console[win].hidden) { |
| 352 | SDL_HideWindow(sdl2_console[win].real_window); |
| 353 | } else { |
| 354 | SDL_ShowWindow(sdl2_console[win].real_window); |
| 355 | } |
| 356 | } |
| 357 | gui_keysym = 1; |
| 358 | } |
| 359 | break; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 360 | case SDL_SCANCODE_F: |
| 361 | toggle_full_screen(scon); |
| 362 | gui_keysym = 1; |
| 363 | break; |
| 364 | case SDL_SCANCODE_U: |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 365 | sdl2_window_destroy(scon); |
| 366 | sdl2_window_create(scon); |
Gerd Hoffmann | 0d01b7c | 2014-11-11 13:31:08 +0100 | [diff] [blame] | 367 | /* re-create texture */ |
| 368 | sdl2_2d_switch(&scon->dcl, scon->surface); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 369 | gui_keysym = 1; |
| 370 | break; |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 371 | #if 0 |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 372 | case SDL_SCANCODE_KP_PLUS: |
| 373 | case SDL_SCANCODE_KP_MINUS: |
| 374 | if (!gui_fullscreen) { |
| 375 | int scr_w, scr_h; |
| 376 | int width, height; |
| 377 | SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h); |
| 378 | |
| 379 | width = MAX(scr_w + (ev->key.keysym.scancode == |
| 380 | SDL_SCANCODE_KP_PLUS ? 50 : -50), |
| 381 | 160); |
| 382 | height = (surface_height(scon->surface) * width) / |
| 383 | surface_width(scon->surface); |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 384 | fprintf(stderr, "%s: scale to %dx%d\n", |
| 385 | __func__, width, height); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 386 | sdl_scale(scon, width, height); |
Gerd Hoffmann | 0d01b7c | 2014-11-11 13:31:08 +0100 | [diff] [blame] | 387 | sdl2_2d_redraw(scon); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 388 | gui_keysym = 1; |
| 389 | } |
Gerd Hoffmann | 46522a8 | 2014-11-11 13:12:02 +0100 | [diff] [blame] | 390 | #endif |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 391 | default: |
| 392 | break; |
| 393 | } |
| 394 | } |
| 395 | if (!gui_keysym) { |
Gerd Hoffmann | 8fc1a3f | 2014-11-11 10:58:19 +0100 | [diff] [blame] | 396 | sdl2_process_key(scon, &ev->key); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
| 400 | static void handle_keyup(SDL_Event *ev) |
| 401 | { |
| 402 | int mod_state; |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 403 | struct sdl2_console *scon = get_scon_from_window(ev->key.windowID); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 404 | |
| 405 | if (!alt_grab) { |
| 406 | mod_state = (ev->key.keysym.mod & gui_grab_code); |
| 407 | } else { |
| 408 | mod_state = (ev->key.keysym.mod & (gui_grab_code | KMOD_LSHIFT)); |
| 409 | } |
| 410 | if (!mod_state && gui_key_modifier_pressed) { |
| 411 | gui_key_modifier_pressed = 0; |
| 412 | if (gui_keysym == 0) { |
| 413 | /* exit/enter grab if pressing Ctrl-Alt */ |
| 414 | if (!gui_grab) { |
| 415 | sdl_grab_start(scon); |
| 416 | } else if (!gui_fullscreen) { |
| 417 | sdl_grab_end(scon); |
| 418 | } |
| 419 | /* SDL does not send back all the modifiers key, so we must |
| 420 | * correct it. */ |
Gerd Hoffmann | 8fc1a3f | 2014-11-11 10:58:19 +0100 | [diff] [blame] | 421 | sdl2_reset_keys(scon); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 422 | return; |
| 423 | } |
| 424 | gui_keysym = 0; |
| 425 | } |
| 426 | if (!gui_keysym) { |
Gerd Hoffmann | 8fc1a3f | 2014-11-11 10:58:19 +0100 | [diff] [blame] | 427 | sdl2_process_key(scon, &ev->key); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
Gerd Hoffmann | f233579 | 2014-05-26 14:05:51 +0200 | [diff] [blame] | 431 | static void handle_textinput(SDL_Event *ev) |
| 432 | { |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 433 | struct sdl2_console *scon = get_scon_from_window(ev->key.windowID); |
Gerd Hoffmann | f233579 | 2014-05-26 14:05:51 +0200 | [diff] [blame] | 434 | QemuConsole *con = scon ? scon->dcl.con : NULL; |
| 435 | |
| 436 | if (qemu_console_is_graphic(con)) { |
| 437 | return; |
| 438 | } |
| 439 | kbd_put_string_console(con, ev->text.text, strlen(ev->text.text)); |
| 440 | } |
| 441 | |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 442 | static void handle_mousemotion(SDL_Event *ev) |
| 443 | { |
| 444 | int max_x, max_y; |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 445 | struct sdl2_console *scon = get_scon_from_window(ev->key.windowID); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 446 | |
| 447 | if (qemu_input_is_absolute() || absolute_enabled) { |
| 448 | int scr_w, scr_h; |
| 449 | SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h); |
| 450 | max_x = scr_w - 1; |
| 451 | max_y = scr_h - 1; |
| 452 | if (gui_grab && (ev->motion.x == 0 || ev->motion.y == 0 || |
| 453 | ev->motion.x == max_x || ev->motion.y == max_y)) { |
| 454 | sdl_grab_end(scon); |
| 455 | } |
| 456 | if (!gui_grab && |
| 457 | (ev->motion.x > 0 && ev->motion.x < max_x && |
| 458 | ev->motion.y > 0 && ev->motion.y < max_y)) { |
| 459 | sdl_grab_start(scon); |
| 460 | } |
| 461 | } |
| 462 | if (gui_grab || qemu_input_is_absolute() || absolute_enabled) { |
Cole Robinson | 3f2fde2 | 2014-04-21 18:58:50 -0400 | [diff] [blame] | 463 | sdl_send_mouse_event(scon, ev->motion.xrel, ev->motion.yrel, |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 464 | ev->motion.x, ev->motion.y, ev->motion.state); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | static void handle_mousebutton(SDL_Event *ev) |
| 469 | { |
| 470 | int buttonstate = SDL_GetMouseState(NULL, NULL); |
| 471 | SDL_MouseButtonEvent *bev; |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 472 | struct sdl2_console *scon = get_scon_from_window(ev->key.windowID); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 473 | |
| 474 | bev = &ev->button; |
| 475 | if (!gui_grab && !qemu_input_is_absolute()) { |
| 476 | if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) { |
| 477 | /* start grabbing all events */ |
| 478 | sdl_grab_start(scon); |
| 479 | } |
| 480 | } else { |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 481 | if (ev->type == SDL_MOUSEBUTTONDOWN) { |
| 482 | buttonstate |= SDL_BUTTON(bev->button); |
| 483 | } else { |
| 484 | buttonstate &= ~SDL_BUTTON(bev->button); |
| 485 | } |
Cole Robinson | 3f2fde2 | 2014-04-21 18:58:50 -0400 | [diff] [blame] | 486 | sdl_send_mouse_event(scon, 0, 0, bev->x, bev->y, buttonstate); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
Cole Robinson | 3f2fde2 | 2014-04-21 18:58:50 -0400 | [diff] [blame] | 490 | static void handle_mousewheel(SDL_Event *ev) |
| 491 | { |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 492 | struct sdl2_console *scon = get_scon_from_window(ev->key.windowID); |
Cole Robinson | 3f2fde2 | 2014-04-21 18:58:50 -0400 | [diff] [blame] | 493 | SDL_MouseWheelEvent *wev = &ev->wheel; |
| 494 | InputButton btn; |
| 495 | |
| 496 | if (wev->y > 0) { |
| 497 | btn = INPUT_BUTTON_WHEEL_UP; |
| 498 | } else if (wev->y < 0) { |
| 499 | btn = INPUT_BUTTON_WHEEL_DOWN; |
| 500 | } else { |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | qemu_input_queue_btn(scon->dcl.con, btn, true); |
| 505 | qemu_input_event_sync(); |
| 506 | qemu_input_queue_btn(scon->dcl.con, btn, false); |
| 507 | qemu_input_event_sync(); |
| 508 | } |
| 509 | |
Max Reitz | 1dfc5c8 | 2014-12-12 10:52:51 +0100 | [diff] [blame^] | 510 | static void handle_windowevent(SDL_Event *ev) |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 511 | { |
Max Reitz | 1dfc5c8 | 2014-12-12 10:52:51 +0100 | [diff] [blame^] | 512 | struct sdl2_console *scon = get_scon_from_window(ev->window.windowID); |
| 513 | |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 514 | switch (ev->window.event) { |
| 515 | case SDL_WINDOWEVENT_RESIZED: |
Dave Airlie | 8b15d9f | 2014-03-25 16:50:36 +1000 | [diff] [blame] | 516 | { |
| 517 | QemuUIInfo info; |
| 518 | memset(&info, 0, sizeof(info)); |
| 519 | info.width = ev->window.data1; |
| 520 | info.height = ev->window.data2; |
| 521 | dpy_set_ui_info(scon->dcl.con, &info); |
| 522 | } |
Gerd Hoffmann | 0d01b7c | 2014-11-11 13:31:08 +0100 | [diff] [blame] | 523 | sdl2_2d_redraw(scon); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 524 | break; |
| 525 | case SDL_WINDOWEVENT_EXPOSED: |
Gerd Hoffmann | 0d01b7c | 2014-11-11 13:31:08 +0100 | [diff] [blame] | 526 | sdl2_2d_redraw(scon); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 527 | break; |
| 528 | case SDL_WINDOWEVENT_FOCUS_GAINED: |
| 529 | case SDL_WINDOWEVENT_ENTER: |
| 530 | if (!gui_grab && (qemu_input_is_absolute() || absolute_enabled)) { |
| 531 | absolute_mouse_grab(scon); |
| 532 | } |
| 533 | break; |
| 534 | case SDL_WINDOWEVENT_FOCUS_LOST: |
| 535 | if (gui_grab && !gui_fullscreen) { |
| 536 | sdl_grab_end(scon); |
| 537 | } |
| 538 | break; |
| 539 | case SDL_WINDOWEVENT_RESTORED: |
Gerd Hoffmann | 63ed490 | 2014-11-12 08:01:27 +0100 | [diff] [blame] | 540 | update_displaychangelistener(&scon->dcl, GUI_REFRESH_INTERVAL_DEFAULT); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 541 | break; |
| 542 | case SDL_WINDOWEVENT_MINIMIZED: |
Gerd Hoffmann | 63ed490 | 2014-11-12 08:01:27 +0100 | [diff] [blame] | 543 | update_displaychangelistener(&scon->dcl, 500); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 544 | break; |
| 545 | case SDL_WINDOWEVENT_CLOSE: |
| 546 | if (!no_quit) { |
| 547 | no_shutdown = 0; |
| 548 | qemu_system_shutdown_request(); |
| 549 | } |
| 550 | break; |
| 551 | } |
| 552 | } |
| 553 | |
Gerd Hoffmann | 63ed490 | 2014-11-12 08:01:27 +0100 | [diff] [blame] | 554 | void sdl2_poll_events(struct sdl2_console *scon) |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 555 | { |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 556 | SDL_Event ev1, *ev = &ev1; |
| 557 | |
| 558 | if (scon->last_vm_running != runstate_is_running()) { |
| 559 | scon->last_vm_running = runstate_is_running(); |
| 560 | sdl_update_caption(scon); |
| 561 | } |
| 562 | |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 563 | while (SDL_PollEvent(ev)) { |
| 564 | switch (ev->type) { |
| 565 | case SDL_KEYDOWN: |
| 566 | handle_keydown(ev); |
| 567 | break; |
| 568 | case SDL_KEYUP: |
| 569 | handle_keyup(ev); |
| 570 | break; |
Gerd Hoffmann | f233579 | 2014-05-26 14:05:51 +0200 | [diff] [blame] | 571 | case SDL_TEXTINPUT: |
| 572 | handle_textinput(ev); |
| 573 | break; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 574 | case SDL_QUIT: |
| 575 | if (!no_quit) { |
| 576 | no_shutdown = 0; |
| 577 | qemu_system_shutdown_request(); |
| 578 | } |
| 579 | break; |
| 580 | case SDL_MOUSEMOTION: |
| 581 | handle_mousemotion(ev); |
| 582 | break; |
| 583 | case SDL_MOUSEBUTTONDOWN: |
| 584 | case SDL_MOUSEBUTTONUP: |
| 585 | handle_mousebutton(ev); |
| 586 | break; |
Cole Robinson | 3f2fde2 | 2014-04-21 18:58:50 -0400 | [diff] [blame] | 587 | case SDL_MOUSEWHEEL: |
| 588 | handle_mousewheel(ev); |
| 589 | break; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 590 | case SDL_WINDOWEVENT: |
Max Reitz | 1dfc5c8 | 2014-12-12 10:52:51 +0100 | [diff] [blame^] | 591 | handle_windowevent(ev); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 592 | break; |
| 593 | default: |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | static void sdl_mouse_warp(DisplayChangeListener *dcl, |
| 600 | int x, int y, int on) |
| 601 | { |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 602 | struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 603 | if (on) { |
| 604 | if (!guest_cursor) { |
| 605 | sdl_show_cursor(); |
| 606 | } |
| 607 | if (gui_grab || qemu_input_is_absolute() || absolute_enabled) { |
| 608 | SDL_SetCursor(guest_sprite); |
| 609 | if (!qemu_input_is_absolute() && !absolute_enabled) { |
| 610 | SDL_WarpMouseInWindow(scon->real_window, x, y); |
| 611 | } |
| 612 | } |
| 613 | } else if (gui_grab) { |
| 614 | sdl_hide_cursor(); |
| 615 | } |
| 616 | guest_cursor = on; |
| 617 | guest_x = x, guest_y = y; |
| 618 | } |
| 619 | |
| 620 | static void sdl_mouse_define(DisplayChangeListener *dcl, |
| 621 | QEMUCursor *c) |
| 622 | { |
| 623 | |
| 624 | if (guest_sprite) { |
| 625 | SDL_FreeCursor(guest_sprite); |
| 626 | } |
| 627 | |
| 628 | if (guest_sprite_surface) { |
| 629 | SDL_FreeSurface(guest_sprite_surface); |
| 630 | } |
| 631 | |
| 632 | guest_sprite_surface = |
| 633 | SDL_CreateRGBSurfaceFrom(c->data, c->width, c->height, 32, c->width * 4, |
| 634 | 0xff0000, 0x00ff00, 0xff, 0xff000000); |
| 635 | |
| 636 | if (!guest_sprite_surface) { |
| 637 | fprintf(stderr, "Failed to make rgb surface from %p\n", c); |
| 638 | return; |
| 639 | } |
| 640 | guest_sprite = SDL_CreateColorCursor(guest_sprite_surface, |
| 641 | c->hot_x, c->hot_y); |
| 642 | if (!guest_sprite) { |
| 643 | fprintf(stderr, "Failed to make color cursor from %p\n", c); |
| 644 | return; |
| 645 | } |
| 646 | if (guest_cursor && |
| 647 | (gui_grab || qemu_input_is_absolute() || absolute_enabled)) { |
| 648 | SDL_SetCursor(guest_sprite); |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | static void sdl_cleanup(void) |
| 653 | { |
| 654 | if (guest_sprite) { |
| 655 | SDL_FreeCursor(guest_sprite); |
| 656 | } |
| 657 | SDL_QuitSubSystem(SDL_INIT_VIDEO); |
| 658 | } |
| 659 | |
Gerd Hoffmann | f1ddebd | 2014-11-11 11:09:26 +0100 | [diff] [blame] | 660 | static const DisplayChangeListenerOps dcl_2d_ops = { |
| 661 | .dpy_name = "sdl2-2d", |
| 662 | .dpy_gfx_update = sdl2_2d_update, |
Gerd Hoffmann | 2c3056f | 2014-11-11 13:22:49 +0100 | [diff] [blame] | 663 | .dpy_gfx_switch = sdl2_2d_switch, |
Gerd Hoffmann | 62959ff | 2014-11-12 08:03:34 +0100 | [diff] [blame] | 664 | .dpy_refresh = sdl2_2d_refresh, |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 665 | .dpy_mouse_set = sdl_mouse_warp, |
| 666 | .dpy_cursor_define = sdl_mouse_define, |
| 667 | }; |
| 668 | |
| 669 | void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) |
| 670 | { |
| 671 | int flags; |
| 672 | uint8_t data = 0; |
| 673 | char *filename; |
| 674 | int i; |
| 675 | |
| 676 | if (no_frame) { |
| 677 | gui_noframe = 1; |
| 678 | } |
| 679 | |
| 680 | #ifdef __linux__ |
| 681 | /* on Linux, SDL may use fbcon|directfb|svgalib when run without |
| 682 | * accessible $DISPLAY to open X11 window. This is often the case |
| 683 | * when qemu is run using sudo. But in this case, and when actually |
| 684 | * run in X11 environment, SDL fights with X11 for the video card, |
| 685 | * making current display unavailable, often until reboot. |
| 686 | * So make x11 the default SDL video driver if this variable is unset. |
| 687 | * This is a bit hackish but saves us from bigger problem. |
| 688 | * Maybe it's a good idea to fix this in SDL instead. |
| 689 | */ |
| 690 | setenv("SDL_VIDEODRIVER", "x11", 0); |
| 691 | #endif |
| 692 | |
| 693 | flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; |
| 694 | if (SDL_Init(flags)) { |
| 695 | fprintf(stderr, "Could not initialize SDL(%s) - exiting\n", |
| 696 | SDL_GetError()); |
| 697 | exit(1); |
| 698 | } |
Gerd Hoffmann | 44f017d | 2014-11-11 12:02:50 +0100 | [diff] [blame] | 699 | SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1"); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 700 | |
| 701 | for (i = 0;; i++) { |
| 702 | QemuConsole *con = qemu_console_lookup_by_index(i); |
Gerd Hoffmann | f233579 | 2014-05-26 14:05:51 +0200 | [diff] [blame] | 703 | if (!con) { |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 704 | break; |
| 705 | } |
| 706 | } |
| 707 | sdl2_num_outputs = i; |
Gerd Hoffmann | 5d0fe65 | 2014-11-11 10:21:24 +0100 | [diff] [blame] | 708 | sdl2_console = g_new0(struct sdl2_console, sdl2_num_outputs); |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 709 | for (i = 0; i < sdl2_num_outputs; i++) { |
| 710 | QemuConsole *con = qemu_console_lookup_by_index(i); |
Gerd Hoffmann | f233579 | 2014-05-26 14:05:51 +0200 | [diff] [blame] | 711 | if (!qemu_console_is_graphic(con)) { |
| 712 | sdl2_console[i].hidden = true; |
| 713 | } |
Gerd Hoffmann | f1ddebd | 2014-11-11 11:09:26 +0100 | [diff] [blame] | 714 | sdl2_console[i].dcl.ops = &dcl_2d_ops; |
Dave Airlie | 47c0374 | 2013-12-10 14:05:51 +1000 | [diff] [blame] | 715 | sdl2_console[i].dcl.con = con; |
| 716 | register_displaychangelistener(&sdl2_console[i].dcl); |
| 717 | sdl2_console[i].idx = i; |
| 718 | } |
| 719 | |
| 720 | /* Load a 32x32x4 image. White pixels are transparent. */ |
| 721 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "qemu-icon.bmp"); |
| 722 | if (filename) { |
| 723 | SDL_Surface *image = SDL_LoadBMP(filename); |
| 724 | if (image) { |
| 725 | uint32_t colorkey = SDL_MapRGB(image->format, 255, 255, 255); |
| 726 | SDL_SetColorKey(image, SDL_TRUE, colorkey); |
| 727 | SDL_SetWindowIcon(sdl2_console[0].real_window, image); |
| 728 | } |
| 729 | g_free(filename); |
| 730 | } |
| 731 | |
| 732 | if (full_screen) { |
| 733 | gui_fullscreen = 1; |
| 734 | sdl_grab_start(0); |
| 735 | } |
| 736 | |
| 737 | mouse_mode_notifier.notify = sdl_mouse_mode_change; |
| 738 | qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier); |
| 739 | |
| 740 | gui_grab = 0; |
| 741 | |
| 742 | sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0); |
| 743 | sdl_cursor_normal = SDL_GetCursor(); |
| 744 | |
| 745 | atexit(sdl_cleanup); |
| 746 | } |