From: Andreas Winkelbauer <andreas.winkelbauer@gmx.at>
To: Avi Kivity <avi@qumranet.com>
Cc: kvm-devel@lists.sourceforge.net
Subject: [PATCH] kvm: qemu: don't die if switching to fullscreen mode fails
Date: Mon, 25 Feb 2008 21:38:59 +0100 [thread overview]
Message-ID: <47C32763.1010006@gmx.at> (raw)
[-- Attachment #1: Type: text/plain, Size: 941 bytes --]
hi,
the attached patch fixes some glitches when switching to fullscreen mode
using ctrl+alt+f or when booting using -full-screen.
up to now the VM simply dies if one of the following situations occur:
* user switches from windowed to fullscreen mode using a resolution
which is too high (meaning higher than the maximum resolution of the
display)
* guest boots in fullscreen mode using a resolution which is too high
* guest is in fullscreen mode and the user switches to a resolution
which is too high
IMO this is not what the "normal" user would expect.
This patch changes the behaviour as follows:
* deny switching to fullscreen mode if the resolution is too high and
print a message to the console
* use windowed mode as fallback option if we are already in
fullscreen mode and the new resolution is too high and print a message
to the console
Signed-off-by: Andreas Winkelbauer <andreas.winkelbauer@gmx.at>
[-- Attachment #2: qemu-sdl-fullscreen.patch --]
[-- Type: text/x-patch, Size: 5267 bytes --]
--- kvm-61.orig/qemu/sdl.c 2008-02-19 15:58:28.000000000 +0100
+++ kvm-61/qemu/sdl.c 2008-02-25 21:04:28.000000000 +0100
@@ -56,46 +56,60 @@ static void sdl_update(DisplayState *ds,
SDL_UpdateRect(screen, x, y, w, h);
}
-static void sdl_resize(DisplayState *ds, int w, int h)
+static int sdl_resize2(DisplayState *ds, int w, int h, int full_screen, int no_frame)
{
+ SDL_Surface *screen_tmp;
int flags;
- // printf("resizing to %d %d\n", w, h);
+ //printf("trying to resize from w=%d h=%d %s to w=%d h=%d %s\n", width, height, gui_fullscreen ? "fullscreen" : "windowed", w, h, full_screen ? "fullscreen" : "windowed");
flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
- if (gui_fullscreen)
+ if (full_screen)
flags |= SDL_FULLSCREEN;
- if (gui_noframe)
+ if (no_frame)
flags |= SDL_NOFRAME;
- width = w;
- height = h;
-
- again:
- screen = SDL_SetVideoMode(w, h, 0, flags);
- if (!screen) {
- fprintf(stderr, "Could not open SDL display\n");
- exit(1);
- }
- if (!screen->pixels && (flags & SDL_HWSURFACE) && (flags & SDL_FULLSCREEN)) {
- flags &= ~SDL_HWSURFACE;
- goto again;
+ if (!(screen_tmp = SDL_SetVideoMode(w, h, 0, flags))) {
+ //fprintf(stderr, "Could not open SDL display (try #1)\n");
+ return -1;
+ } else if (!screen_tmp->pixels && (flags & SDL_HWSURFACE) && (flags & SDL_FULLSCREEN)) {
+ screen_tmp = SDL_SetVideoMode(w, h, 0, flags & ~SDL_HWSURFACE);
}
- if (!screen->pixels) {
- fprintf(stderr, "Could not open SDL display\n");
- exit(1);
- }
- ds->data = screen->pixels;
- ds->linesize = screen->pitch;
- ds->depth = screen->format->BitsPerPixel;
- if (ds->depth == 32 && screen->format->Rshift == 0) {
- ds->bgr = 1;
+ if (!screen_tmp || !screen_tmp->pixels) {
+ //fprintf(stderr, "Could not open SDL display (try #2)\n");
+ return -1;
} else {
- ds->bgr = 0;
+ screen = screen_tmp;
+ gui_fullscreen = full_screen;
+ gui_noframe = no_frame;
+
+ ds->data = screen->pixels;
+ ds->linesize = screen->pitch;
+ ds->depth = screen->format->BitsPerPixel;
+ if (ds->depth == 32 && screen->format->Rshift == 0) {
+ ds->bgr = 1;
+ } else {
+ ds->bgr = 0;
+ }
+ ds->width = width = w;
+ ds->height = height = h;
+ }
+}
+
+static void sdl_resize(DisplayState *ds, int w, int h)
+{
+ if (sdl_resize2(ds, w, h, gui_fullscreen, gui_noframe) == -1) {
+ fprintf(stderr, "Could not resize display to %d x %d (%s)\n",
+ w, h, gui_fullscreen ? "fullscreen" : "windowed");
+
+ /* if we are in fullscreen mode use windowed mode as fallback */
+ if (!gui_fullscreen || sdl_resize2(ds, w, h, 0, gui_noframe) == -1) {
+ exit(1);
+ } else {
+ fprintf(stderr, "Using windowed mode as fallback\n");
+ }
}
- ds->width = w;
- ds->height = h;
}
/* generic keyboard conversion */
@@ -332,17 +346,21 @@ static void sdl_send_mouse_event(int dz)
static void toggle_full_screen(DisplayState *ds)
{
- gui_fullscreen = !gui_fullscreen;
- sdl_resize(ds, screen->w, screen->h);
- if (gui_fullscreen) {
- gui_saved_grab = gui_grab;
- sdl_grab_start();
- } else {
- if (!gui_saved_grab)
- sdl_grab_end();
+ if (sdl_resize2(ds, screen->w, screen->h, !gui_fullscreen, gui_noframe) != -1) {
+ if (gui_fullscreen) {
+ gui_saved_grab = gui_grab;
+ sdl_grab_start();
+ } else {
+ if (!gui_saved_grab)
+ sdl_grab_end();
+ }
+ vga_hw_invalidate();
+ vga_hw_update();
+ }
+ else {
+ fprintf(stderr, "Could not switch to %s mode\n",
+ !gui_fullscreen ? "fullscreen" : "windowed");
}
- vga_hw_invalidate();
- vga_hw_update();
}
static void sdl_refresh(DisplayState *ds)
@@ -605,14 +623,14 @@ void sdl_display_init(DisplayState *ds,
exit(1);
}
- if (no_frame)
- gui_noframe = 1;
-
flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
if (SDL_Init (flags)) {
fprintf(stderr, "Could not initialize SDL - exiting\n");
exit(1);
}
+
+ atexit(sdl_cleanup);
+
#ifndef _WIN32
/* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */
signal(SIGINT, SIG_DFL);
@@ -626,7 +644,10 @@ void sdl_display_init(DisplayState *ds,
ds->mouse_set = sdl_mouse_warp;
ds->cursor_define = sdl_mouse_define;
- sdl_resize(ds, 640, 400);
+ if (sdl_resize2(ds, 640, 400, full_screen, no_frame) == -1) {
+ fprintf(stderr, "Could not resize display in sdl_display_init()\n");
+ exit(1);
+ }
sdl_update_caption();
SDL_EnableKeyRepeat(250, 50);
SDL_EnableUNICODE(1);
@@ -635,9 +656,7 @@ void sdl_display_init(DisplayState *ds,
sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0);
sdl_cursor_normal = SDL_GetCursor();
- atexit(sdl_cleanup);
- if (full_screen) {
- gui_fullscreen = 1;
+ if (gui_fullscreen) {
gui_fullscreen_initial_grab = 1;
sdl_grab_start();
}
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 158 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel
reply other threads:[~2008-02-25 20:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47C32763.1010006@gmx.at \
--to=andreas.winkelbauer@gmx.at \
--cc=avi@qumranet.com \
--cc=kvm-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.