static int sdl2_num_outputs;
static struct sdl2_console *sdl2_console;
-static DisplayOptions *opts;
static SDL_Surface *guest_sprite_surface;
static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
}
break;
case SDL_SCANCODE_U:
- sdl2_window_destroy(scon);
- sdl2_window_create(scon);
+ sdl2_window_resize(scon);
if (!scon->opengl) {
/* re-create scon->texture */
sdl2_2d_switch(&scon->dcl, scon->surface);
static void handle_textinput(SDL_Event *ev)
{
- struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
+ struct sdl2_console *scon = get_scon_from_window(ev->text.windowID);
QemuConsole *con = scon ? scon->dcl.con : NULL;
if (qemu_console_is_graphic(con)) {
static void handle_mousemotion(SDL_Event *ev)
{
int max_x, max_y;
- struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
+ struct sdl2_console *scon = get_scon_from_window(ev->motion.windowID);
- if (!qemu_console_is_graphic(scon->dcl.con)) {
+ if (!scon || !qemu_console_is_graphic(scon->dcl.con)) {
return;
}
{
int buttonstate = SDL_GetMouseState(NULL, NULL);
SDL_MouseButtonEvent *bev;
- struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
+ struct sdl2_console *scon = get_scon_from_window(ev->button.windowID);
- if (!qemu_console_is_graphic(scon->dcl.con)) {
+ if (!scon || !qemu_console_is_graphic(scon->dcl.con)) {
return;
}
static void handle_mousewheel(SDL_Event *ev)
{
- struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
+ struct sdl2_console *scon = get_scon_from_window(ev->wheel.windowID);
SDL_MouseWheelEvent *wev = &ev->wheel;
InputButton btn;
- if (!qemu_console_is_graphic(scon->dcl.con)) {
+ if (!scon || !qemu_console_is_graphic(scon->dcl.con)) {
return;
}
break;
case SDL_WINDOWEVENT_CLOSE:
if (qemu_console_is_graphic(scon->dcl.con)) {
- if (opts->has_window_close && !opts->window_close) {
+ if (scon->opts->has_window_close && !scon->opts->window_close) {
allow_close = false;
}
if (allow_close) {
handle_textinput(ev);
break;
case SDL_QUIT:
- if (opts->has_window_close && !opts->window_close) {
+ if (scon->opts->has_window_close && !scon->opts->window_close) {
allow_close = false;
}
if (allow_close) {
};
#endif
-void sdl_display_early_init(DisplayOptions *o)
+static void sdl2_display_early_init(DisplayOptions *o)
{
assert(o->type == DISPLAY_TYPE_SDL);
if (o->has_gl && o->gl) {
}
}
-void sdl_display_init(DisplayState *ds, DisplayOptions *o)
+static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
{
- int flags;
uint8_t data = 0;
char *filename;
int i;
SDL_SysWMinfo info;
assert(o->type == DISPLAY_TYPE_SDL);
- opts = o;
#ifdef __linux__
/* on Linux, SDL may use fbcon|directfb|svgalib when run without
setenv("SDL_VIDEODRIVER", "x11", 0);
#endif
- flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
- if (SDL_Init(flags)) {
+ if (SDL_Init(SDL_INIT_VIDEO)) {
fprintf(stderr, "Could not initialize SDL(%s) - exiting\n",
SDL_GetError());
exit(1);
memset(&info, 0, sizeof(info));
SDL_VERSION(&info.version);
+ gui_fullscreen = o->has_full_screen && o->full_screen;
+
for (i = 0;; i++) {
QemuConsole *con = qemu_console_lookup_by_index(i);
if (!con) {
for (i = 0; i < sdl2_num_outputs; i++) {
QemuConsole *con = qemu_console_lookup_by_index(i);
assert(con != NULL);
- if (!qemu_console_is_graphic(con)) {
+ if (!qemu_console_is_graphic(con) &&
+ qemu_console_get_index(con) != 0) {
sdl2_console[i].hidden = true;
}
sdl2_console[i].idx = i;
+ sdl2_console[i].opts = o;
#ifdef CONFIG_OPENGL
sdl2_console[i].opengl = display_opengl;
sdl2_console[i].dcl.ops = display_opengl ? &dcl_gl_ops : &dcl_2d_ops;
g_free(filename);
}
- if (opts->has_full_screen && opts->full_screen) {
- gui_fullscreen = 1;
+ gui_grab = 0;
+ if (gui_fullscreen) {
sdl_grab_start(0);
}
mouse_mode_notifier.notify = sdl_mouse_mode_change;
qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier);
- gui_grab = 0;
-
sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0);
sdl_cursor_normal = SDL_GetCursor();
atexit(sdl_cleanup);
}
+
+static QemuDisplay qemu_display_sdl2 = {
+ .type = DISPLAY_TYPE_SDL,
+ .early_init = sdl2_display_early_init,
+ .init = sdl2_display_init,
+};
+
+static void register_sdl1(void)
+{
+ qemu_display_register(&qemu_display_sdl2);
+}
+
+type_init(register_sdl1);