* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include "vl.h"
+#include "qemu-common.h"
+#include "console.h"
+#include "sysemu.h"
#include <SDL.h>
ds->data = screen->pixels;
ds->linesize = screen->pitch;
ds->depth = screen->format->BitsPerPixel;
- if (screen->format->Bshift > screen->format->Rshift) {
+ /* SDL BitsPerPixel never indicates any values other than
+ multiples of 8, so we need to check for strange depths. */
+ if (ds->depth == 16) {
+ uint32_t mask;
+
+ mask = screen->format->Rmask;
+ mask |= screen->format->Gmask;
+ mask |= screen->format->Bmask;
+ if ((mask & 0x8000) == 0)
+ ds->depth = 15;
+ }
+ if (ds->depth == 32 && screen->format->Rshift == 0) {
ds->bgr = 1;
} else {
ds->bgr = 0;
} else
sdl_hide_cursor();
SDL_WM_GrabInput(SDL_GRAB_ON);
- /* dummy read to avoid moving the mouse */
- SDL_GetRelativeMouseState(NULL, NULL);
gui_grab = 1;
sdl_update_caption();
}
sdl_update_caption();
}
-static void sdl_send_mouse_event(int dz)
+static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state)
{
- int dx, dy, state, buttons;
- state = SDL_GetRelativeMouseState(&dx, &dy);
+ int buttons;
buttons = 0;
if (state & SDL_BUTTON(SDL_BUTTON_LEFT))
buttons |= MOUSE_EVENT_LBUTTON;
absolute_enabled = 1;
}
- SDL_GetMouseState(&dx, &dy);
- dx = dx * 0x7FFF / width;
- dy = dy * 0x7FFF / height;
+ dx = x * 0x7FFF / (width - 1);
+ dy = y * 0x7FFF / (height - 1);
} else if (absolute_enabled) {
sdl_show_cursor();
absolute_enabled = 0;
} else if (guest_cursor) {
- SDL_GetMouseState(&dx, &dy);
- dx -= guest_x;
- dy -= guest_y;
- guest_x += dx;
- guest_y += dy;
+ x -= guest_x;
+ y -= guest_y;
+ guest_x += x;
+ guest_y += y;
+ dx = x;
+ dy = y;
}
kbd_mouse_event(dx, dy, dz, buttons);
{
SDL_Event ev1, *ev = &ev1;
int mod_state;
-
+ int buttonstate = SDL_GetMouseState(NULL, NULL);
+
if (last_vm_running != vm_running) {
last_vm_running = vm_running;
sdl_update_caption();
}
vga_hw_update();
+ SDL_EnableUNICODE(!is_graphic_console());
while (SDL_PollEvent(ev)) {
switch (ev->type) {
sdl_process_key(&ev->key);
break;
case SDL_QUIT:
- if (!no_quit) {
+ if (!no_quit)
qemu_system_shutdown_request();
- vm_start(); /* In case we're paused */
- }
break;
case SDL_MOUSEMOTION:
if (gui_grab || kbd_mouse_is_absolute() ||
absolute_enabled) {
- sdl_send_mouse_event(0);
+ sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
+ ev->motion.x, ev->motion.y, ev->motion.state);
}
break;
case SDL_MOUSEBUTTONDOWN:
SDL_MouseButtonEvent *bev = &ev->button;
if (!gui_grab && !kbd_mouse_is_absolute()) {
if (ev->type == SDL_MOUSEBUTTONDOWN &&
- (bev->state & SDL_BUTTON_LMASK)) {
+ (bev->button == SDL_BUTTON_LEFT)) {
/* start grabbing all events */
sdl_grab_start();
}
} else {
int dz;
dz = 0;
+ if (ev->type == SDL_MOUSEBUTTONDOWN) {
+ buttonstate |= SDL_BUTTON(bev->button);
+ } else {
+ buttonstate &= ~SDL_BUTTON(bev->button);
+ }
#ifdef SDL_BUTTON_WHEELUP
if (bev->button == SDL_BUTTON_WHEELUP && ev->type == SDL_MOUSEBUTTONDOWN) {
dz = -1;
} else if (bev->button == SDL_BUTTON_WHEELDOWN && ev->type == SDL_MOUSEBUTTONDOWN) {
dz = 1;
}
-#endif
- sdl_send_mouse_event(dz);
+#endif
+ sdl_send_mouse_event(0, 0, dz, bev->x, bev->y, buttonstate);
}
}
break;
!ev->active.gain && !gui_fullscreen_initial_grab) {
sdl_grab_end();
}
+ if (ev->active.state & SDL_APPACTIVE) {
+ if (ev->active.gain) {
+ /* Back to default interval */
+ ds->gui_timer_interval = 0;
+ ds->idle = 0;
+ } else {
+ /* Sleeping interval */
+ ds->gui_timer_interval = 500;
+ ds->idle = 1;
+ }
+ }
break;
default:
break;
fprintf(stderr, "Could not initialize SDL - exiting\n");
exit(1);
}
-#ifndef _WIN32
- /* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */
- signal(SIGINT, SIG_DFL);
- signal(SIGQUIT, SIG_DFL);
-#endif
ds->dpy_update = sdl_update;
ds->dpy_resize = sdl_resize;
sdl_resize(ds, 640, 400);
sdl_update_caption();
SDL_EnableKeyRepeat(250, 50);
- SDL_EnableUNICODE(1);
gui_grab = 0;
sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0);