Skip to content

Commit

Permalink
sdl2: rename sdl2_state to sdl2_console, move to header file
Browse files Browse the repository at this point in the history
Create sdl2.h header file, in preparation for sdl2 code splitup.
Populate it with sdl2_console struct (renamed from sdl2_state).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
  • Loading branch information
kraxel committed Dec 17, 2014
1 parent d29c431 commit 5d0fe65
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 36 deletions.
16 changes: 16 additions & 0 deletions include/ui/sdl2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef SDL2_H
#define SDL2_H

struct sdl2_console {
DisplayChangeListener dcl;
DisplaySurface *surface;
SDL_Texture *texture;
SDL_Window *real_window;
SDL_Renderer *real_renderer;
int idx;
int last_vm_running; /* per console for caption reasons */
int x, y;
int hidden;
};

#endif /* SDL2_H */
63 changes: 27 additions & 36 deletions ui/sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,13 @@
#include "qemu-common.h"
#include "ui/console.h"
#include "ui/input.h"
#include "ui/sdl2.h"
#include "sysemu/sysemu.h"

#include "sdl2-keymap.h"

static int sdl2_num_outputs;
static struct sdl2_state {
DisplayChangeListener dcl;
DisplaySurface *surface;
SDL_Texture *texture;
SDL_Window *real_window;
SDL_Renderer *real_renderer;
int idx;
int last_vm_running; /* per console for caption reasons */
int x, y;
int hidden;
} *sdl2_console;
static struct sdl2_console *sdl2_console;

static SDL_Surface *guest_sprite_surface;
static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
Expand All @@ -71,9 +62,9 @@ static SDL_Cursor *guest_sprite;
static int scaling_active;
static Notifier mouse_mode_notifier;

static void sdl_update_caption(struct sdl2_state *scon);
static void sdl_update_caption(struct sdl2_console *scon);

static struct sdl2_state *get_scon_from_window(uint32_t window_id)
static struct sdl2_console *get_scon_from_window(uint32_t window_id)
{
int i;
for (i = 0; i < sdl2_num_outputs; i++) {
Expand All @@ -87,7 +78,7 @@ static struct sdl2_state *get_scon_from_window(uint32_t window_id)
static void sdl_update(DisplayChangeListener *dcl,
int x, int y, int w, int h)
{
struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl);
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
SDL_Rect rect;
DisplaySurface *surf = qemu_console_surface(dcl->con);

Expand All @@ -109,7 +100,7 @@ static void sdl_update(DisplayChangeListener *dcl,
SDL_RenderPresent(scon->real_renderer);
}

static void do_sdl_resize(struct sdl2_state *scon, int width, int height,
static void do_sdl_resize(struct sdl2_console *scon, int width, int height,
int bpp)
{
int flags;
Expand Down Expand Up @@ -149,7 +140,7 @@ static void do_sdl_resize(struct sdl2_state *scon, int width, int height,
static void sdl_switch(DisplayChangeListener *dcl,
DisplaySurface *new_surface)
{
struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl);
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
int format = 0;
int idx = scon->idx;
DisplaySurface *old_surface = scon->surface;
Expand Down Expand Up @@ -191,7 +182,7 @@ static void sdl_switch(DisplayChangeListener *dcl,
}
}

static void reset_keys(struct sdl2_state *scon)
static void reset_keys(struct sdl2_console *scon)
{
QemuConsole *con = scon ? scon->dcl.con : NULL;
int i;
Expand All @@ -205,7 +196,7 @@ static void reset_keys(struct sdl2_state *scon)
}
}

static void sdl_process_key(struct sdl2_state *scon,
static void sdl_process_key(struct sdl2_console *scon,
SDL_KeyboardEvent *ev)
{
int qcode = sdl2_scancode_to_qcode[ev->keysym.scancode];
Expand Down Expand Up @@ -257,7 +248,7 @@ static void sdl_process_key(struct sdl2_state *scon,
}
}

static void sdl_update_caption(struct sdl2_state *scon)
static void sdl_update_caption(struct sdl2_console *scon)
{
char win_title[1024];
char icon_title[1024];
Expand Down Expand Up @@ -321,7 +312,7 @@ static void sdl_show_cursor(void)
}
}

static void sdl_grab_start(struct sdl2_state *scon)
static void sdl_grab_start(struct sdl2_console *scon)
{
QemuConsole *con = scon ? scon->dcl.con : NULL;

Expand Down Expand Up @@ -349,15 +340,15 @@ static void sdl_grab_start(struct sdl2_state *scon)
sdl_update_caption(scon);
}

static void sdl_grab_end(struct sdl2_state *scon)
static void sdl_grab_end(struct sdl2_console *scon)
{
SDL_SetWindowGrab(scon->real_window, SDL_FALSE);
gui_grab = 0;
sdl_show_cursor();
sdl_update_caption(scon);
}

static void absolute_mouse_grab(struct sdl2_state *scon)
static void absolute_mouse_grab(struct sdl2_console *scon)
{
int mouse_x, mouse_y;
int scr_w, scr_h;
Expand All @@ -384,7 +375,7 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
}
}

static void sdl_send_mouse_event(struct sdl2_state *scon, int dx, int dy,
static void sdl_send_mouse_event(struct sdl2_console *scon, int dx, int dy,
int x, int y, int state)
{
static uint32_t bmap[INPUT_BUTTON_MAX] = {
Expand All @@ -407,7 +398,7 @@ static void sdl_send_mouse_event(struct sdl2_state *scon, int dx, int dy,
int i;

for (i = 0; i < sdl2_num_outputs; i++) {
struct sdl2_state *thiscon = &sdl2_console[i];
struct sdl2_console *thiscon = &sdl2_console[i];
if (thiscon->real_window && thiscon->surface) {
SDL_GetWindowSize(thiscon->real_window, &scr_w, &scr_h);
cur_off_x = thiscon->x;
Expand Down Expand Up @@ -441,14 +432,14 @@ static void sdl_send_mouse_event(struct sdl2_state *scon, int dx, int dy,
qemu_input_event_sync();
}

static void sdl_scale(struct sdl2_state *scon, int width, int height)
static void sdl_scale(struct sdl2_console *scon, int width, int height)
{
int bpp = 0;
do_sdl_resize(scon, width, height, bpp);
scaling_active = 1;
}

static void toggle_full_screen(struct sdl2_state *scon)
static void toggle_full_screen(struct sdl2_console *scon)
{
int width = surface_width(scon->surface);
int height = surface_height(scon->surface);
Expand Down Expand Up @@ -482,7 +473,7 @@ static void toggle_full_screen(struct sdl2_state *scon)
static void handle_keydown(SDL_Event *ev)
{
int mod_state, win;
struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);

if (alt_grab) {
mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
Expand Down Expand Up @@ -560,7 +551,7 @@ static void handle_keydown(SDL_Event *ev)
static void handle_keyup(SDL_Event *ev)
{
int mod_state;
struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);

if (!alt_grab) {
mod_state = (ev->key.keysym.mod & gui_grab_code);
Expand Down Expand Up @@ -590,7 +581,7 @@ static void handle_keyup(SDL_Event *ev)

static void handle_textinput(SDL_Event *ev)
{
struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
QemuConsole *con = scon ? scon->dcl.con : NULL;

if (qemu_console_is_graphic(con)) {
Expand All @@ -602,7 +593,7 @@ static void handle_textinput(SDL_Event *ev)
static void handle_mousemotion(SDL_Event *ev)
{
int max_x, max_y;
struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);

if (qemu_input_is_absolute() || absolute_enabled) {
int scr_w, scr_h;
Expand All @@ -629,7 +620,7 @@ static void handle_mousebutton(SDL_Event *ev)
{
int buttonstate = SDL_GetMouseState(NULL, NULL);
SDL_MouseButtonEvent *bev;
struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);

bev = &ev->button;
if (!gui_grab && !qemu_input_is_absolute()) {
Expand All @@ -649,7 +640,7 @@ static void handle_mousebutton(SDL_Event *ev)

static void handle_mousewheel(SDL_Event *ev)
{
struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
SDL_MouseWheelEvent *wev = &ev->wheel;
InputButton btn;

Expand All @@ -670,7 +661,7 @@ static void handle_mousewheel(SDL_Event *ev)
static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)
{
int w, h;
struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);

switch (ev->window.event) {
case SDL_WINDOWEVENT_RESIZED:
Expand Down Expand Up @@ -717,7 +708,7 @@ static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)

static void sdl_refresh(DisplayChangeListener *dcl)
{
struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl);
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
SDL_Event ev1, *ev = &ev1;

if (scon->last_vm_running != runstate_is_running()) {
Expand Down Expand Up @@ -766,7 +757,7 @@ static void sdl_refresh(DisplayChangeListener *dcl)
static void sdl_mouse_warp(DisplayChangeListener *dcl,
int x, int y, int on)
{
struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl);
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
if (on) {
if (!guest_cursor) {
sdl_show_cursor();
Expand Down Expand Up @@ -871,7 +862,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
}
}
sdl2_num_outputs = i;
sdl2_console = g_new0(struct sdl2_state, sdl2_num_outputs);
sdl2_console = g_new0(struct sdl2_console, sdl2_num_outputs);
for (i = 0; i < sdl2_num_outputs; i++) {
QemuConsole *con = qemu_console_lookup_by_index(i);
if (!qemu_console_is_graphic(con)) {
Expand Down

0 comments on commit 5d0fe65

Please sign in to comment.