3 #include "kvm/framebuffer.h"
14 static u8 keymap
[255] = {
27 [22] = 0x66, /* <backspace> */
40 [36] = 0x5a, /* <enter> */
52 [50] = 0x12, /* <left shift> */
66 [62] = 0x59, /* <right shift> */
67 [65] = 0x29, /* <space> */
70 static u8
to_code(u8 scancode
)
72 return keymap
[scancode
];
75 static void *sdl__thread(void *p
)
77 Uint32 rmask
, gmask
, bmask
, amask
;
78 struct framebuffer
*fb
= p
;
79 SDL_Surface
*guest_screen
;
84 if (SDL_Init(SDL_INIT_VIDEO
) != 0)
85 die("Unable to initialize SDL");
92 guest_screen
= SDL_CreateRGBSurfaceFrom(fb
->mem
, fb
->width
, fb
->height
, fb
->depth
, fb
->width
* fb
->depth
/ 8, rmask
, gmask
, bmask
, amask
);
94 die("Unable to create SDL RBG surface");
96 flags
= SDL_HWSURFACE
| SDL_ASYNCBLIT
| SDL_HWACCEL
| SDL_DOUBLEBUF
;
98 SDL_WM_SetCaption("KVM tool", "KVM tool");
100 screen
= SDL_SetVideoMode(fb
->width
, fb
->height
, fb
->depth
, flags
);
102 die("Unable to set SDL video mode");
104 SDL_EnableKeyRepeat(200, 50);
107 SDL_BlitSurface(guest_screen
, NULL
, screen
, NULL
);
110 while (SDL_PollEvent(&ev
)) {
113 u8 code
= to_code(ev
.key
.keysym
.scancode
);
117 pr_warning("key '%d' not found in keymap", ev
.key
.keysym
.scancode
);
121 u8 code
= to_code(ev
.key
.keysym
.scancode
);
133 SDL_Delay(1000 / FRAME_RATE
);
141 static int sdl__start(struct framebuffer
*fb
)
145 if (pthread_create(&thread
, NULL
, sdl__thread
, fb
) != 0)
151 static struct fb_target_operations sdl_ops
= {
155 void sdl__init(struct framebuffer
*fb
)
157 fb__attach(fb
, &sdl_ops
);