From patchwork Thu Dec 11 10:49:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 420015 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9CE451400A0 for ; Thu, 11 Dec 2014 21:52:12 +1100 (AEDT) Received: from localhost ([::1]:50167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz1Lu-0003kY-LE for incoming@patchwork.ozlabs.org; Thu, 11 Dec 2014 05:52:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz1Jd-0000Bh-65 for qemu-devel@nongnu.org; Thu, 11 Dec 2014 05:49:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xz1JW-0007Qj-R1 for qemu-devel@nongnu.org; Thu, 11 Dec 2014 05:49:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60393) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz1JW-0007QF-IC for qemu-devel@nongnu.org; Thu, 11 Dec 2014 05:49:42 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBBAne8w010043 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 11 Dec 2014 05:49:40 -0500 Received: from nilsson.home.kraxel.org (ovpn-116-68.ams2.redhat.com [10.36.116.68]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBBAncXZ004257; Thu, 11 Dec 2014 05:49:39 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 70C1B82BE0; Thu, 11 Dec 2014 11:49:37 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 11 Dec 2014 11:49:25 +0100 Message-Id: <1418294973-21790-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1418294973-21790-1-git-send-email-kraxel@redhat.com> References: <1418294973-21790-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann , Anthony Liguori Subject: [Qemu-devel] [PATCH 02/10] sdl2: rename sdl2_state to sdl2_console, move to header file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- include/ui/sdl2.h | 11 ++++++++++ ui/sdl2.c | 63 ++++++++++++++++++++++++------------------------------- 2 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 include/ui/sdl2.h diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h new file mode 100644 index 0000000..7f91a75 --- /dev/null +++ b/include/ui/sdl2.h @@ -0,0 +1,11 @@ +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; +}; diff --git a/ui/sdl2.c b/ui/sdl2.c index 45f23b1..375e1a3 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -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 */ @@ -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++) { @@ -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); @@ -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; @@ -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; @@ -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; @@ -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]; @@ -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]; @@ -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; @@ -349,7 +340,7 @@ 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; @@ -357,7 +348,7 @@ static void sdl_grab_end(struct sdl2_state *scon) 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; @@ -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] = { @@ -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; @@ -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); @@ -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)) == @@ -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); @@ -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)) { @@ -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; @@ -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()) { @@ -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; @@ -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: @@ -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()) { @@ -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(); @@ -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)) {