blob: d23f3606ac2effc4051642578a6a96fa4ec74946 [file] [log] [blame]
pbrook87ecb682007-11-17 17:14:51 +00001#ifndef CONSOLE_H
2#define CONSOLE_H
3
4#include "qemu-char.h"
Luiz Capitulinod54908a2009-08-28 15:27:13 -03005#include "qdict.h"
Anthony Liguori7e581fb2010-03-09 13:25:00 -06006#include "notify.h"
Jes Sorensen821601e2011-03-16 13:33:36 +01007#include "qerror.h"
8#include "monitor.h"
pbrook87ecb682007-11-17 17:14:51 +00009
10/* keyboard/mouse support */
11
12#define MOUSE_EVENT_LBUTTON 0x01
13#define MOUSE_EVENT_RBUTTON 0x02
14#define MOUSE_EVENT_MBUTTON 0x04
15
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010016/* identical to the ps/2 keyboard bits */
17#define QEMU_SCROLL_LOCK_LED (1 << 0)
18#define QEMU_NUM_LOCK_LED (1 << 1)
19#define QEMU_CAPS_LOCK_LED (1 << 2)
20
aliguori7ed9eba2008-08-21 20:12:05 +000021/* in ms */
22#define GUI_REFRESH_INTERVAL 30
23
pbrook87ecb682007-11-17 17:14:51 +000024typedef void QEMUPutKBDEvent(void *opaque, int keycode);
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010025typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
pbrook87ecb682007-11-17 17:14:51 +000026typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
27
28typedef struct QEMUPutMouseEntry {
29 QEMUPutMouseEvent *qemu_put_mouse_event;
30 void *qemu_put_mouse_event_opaque;
31 int qemu_put_mouse_event_absolute;
32 char *qemu_put_mouse_event_name;
33
Anthony Liguori6fef28e2010-03-09 20:52:22 -060034 int index;
35
pbrook87ecb682007-11-17 17:14:51 +000036 /* used internally by qemu for handling mice */
Anthony Liguori6fef28e2010-03-09 20:52:22 -060037 QTAILQ_ENTRY(QEMUPutMouseEntry) node;
pbrook87ecb682007-11-17 17:14:51 +000038} QEMUPutMouseEntry;
39
Juha Riihimäki90041a82010-03-18 18:07:08 +020040typedef struct QEMUPutKBDEntry {
41 QEMUPutKBDEvent *put_kbd_event;
42 void *opaque;
Juha Riihimäki90041a82010-03-18 18:07:08 +020043 QTAILQ_ENTRY(QEMUPutKBDEntry) next;
44} QEMUPutKBDEntry;
45
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010046typedef struct QEMUPutLEDEntry {
47 QEMUPutLEDEvent *put_led;
48 void *opaque;
49 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
50} QEMUPutLEDEntry;
51
pbrook87ecb682007-11-17 17:14:51 +000052void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
Juha Riihimäki90041a82010-03-18 18:07:08 +020053void qemu_remove_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
pbrook87ecb682007-11-17 17:14:51 +000054QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
55 void *opaque, int absolute,
56 const char *name);
57void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
Anthony Liguori6fef28e2010-03-09 20:52:22 -060058void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
59
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010060QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
61void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
pbrook87ecb682007-11-17 17:14:51 +000062
63void kbd_put_keycode(int keycode);
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010064void kbd_put_ledstate(int ledstate);
pbrook87ecb682007-11-17 17:14:51 +000065void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
Anthony Liguorieb2e2592010-03-09 14:26:40 -060066
67/* Does the current mouse generate absolute events */
pbrook87ecb682007-11-17 17:14:51 +000068int kbd_mouse_is_absolute(void);
Anthony Liguori7e581fb2010-03-09 13:25:00 -060069void qemu_add_mouse_mode_change_notifier(Notifier *notify);
70void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
pbrook87ecb682007-11-17 17:14:51 +000071
Anthony Liguorieb2e2592010-03-09 14:26:40 -060072/* Of all the mice, is there one that generates absolute events */
73int kbd_mouse_has_absolute(void);
74
Paul Brookbc24a222009-05-10 01:44:56 +010075struct MouseTransformInfo {
balroga5d7eb62008-04-14 21:28:11 +000076 /* Touchscreen resolution */
77 int x;
78 int y;
79 /* Calibration values as used/generated by tslib */
80 int a[7];
81};
82
Luiz Capitulinoe78c48e2009-12-10 17:16:04 -020083void do_info_mice_print(Monitor *mon, const QObject *data);
84void do_info_mice(Monitor *mon, QObject **ret_data);
Luiz Capitulinod54908a2009-08-28 15:27:13 -030085void do_mouse_set(Monitor *mon, const QDict *qdict);
pbrook87ecb682007-11-17 17:14:51 +000086
87/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
88 constants) */
89#define QEMU_KEY_ESC1(c) ((c) | 0xe100)
90#define QEMU_KEY_BACKSPACE 0x007f
91#define QEMU_KEY_UP QEMU_KEY_ESC1('A')
92#define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
93#define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
94#define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
95#define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
96#define QEMU_KEY_END QEMU_KEY_ESC1(4)
97#define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
98#define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
99#define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
100
101#define QEMU_KEY_CTRL_UP 0xe400
102#define QEMU_KEY_CTRL_DOWN 0xe401
103#define QEMU_KEY_CTRL_LEFT 0xe402
104#define QEMU_KEY_CTRL_RIGHT 0xe403
105#define QEMU_KEY_CTRL_HOME 0xe404
106#define QEMU_KEY_CTRL_END 0xe405
107#define QEMU_KEY_CTRL_PAGEUP 0xe406
108#define QEMU_KEY_CTRL_PAGEDOWN 0xe407
109
110void kbd_put_keysym(int keysym);
111
112/* consoles */
113
aliguori7d957bd2009-01-15 22:14:11 +0000114#define QEMU_BIG_ENDIAN_FLAG 0x01
115#define QEMU_ALLOCATED_FLAG 0x02
Stefano Stabellinic18a2c32009-06-24 11:58:25 +0100116#define QEMU_REALPIXELS_FLAG 0x04
aliguori7d957bd2009-01-15 22:14:11 +0000117
118struct PixelFormat {
119 uint8_t bits_per_pixel;
120 uint8_t bytes_per_pixel;
121 uint8_t depth; /* color depth in bits */
122 uint32_t rmask, gmask, bmask, amask;
123 uint8_t rshift, gshift, bshift, ashift;
124 uint8_t rmax, gmax, bmax, amax;
aliguori90a1e3c2009-01-26 15:37:30 +0000125 uint8_t rbits, gbits, bbits, abits;
aliguori7d957bd2009-01-15 22:14:11 +0000126};
127
128struct DisplaySurface {
129 uint8_t flags;
pbrook87ecb682007-11-17 17:14:51 +0000130 int width;
131 int height;
aliguori7d957bd2009-01-15 22:14:11 +0000132 int linesize; /* bytes per line */
133 uint8_t *data;
134
135 struct PixelFormat pf;
136};
137
Gerd Hoffmann254e5952010-05-21 11:54:32 +0200138/* cursor data format is 32bit RGBA */
139typedef struct QEMUCursor {
140 int width, height;
141 int hot_x, hot_y;
142 int refcount;
143 uint32_t data[];
144} QEMUCursor;
145
146QEMUCursor *cursor_alloc(int width, int height);
147void cursor_get(QEMUCursor *c);
148void cursor_put(QEMUCursor *c);
149QEMUCursor *cursor_builtin_hidden(void);
150QEMUCursor *cursor_builtin_left_ptr(void);
151void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
152int cursor_get_mono_bpl(QEMUCursor *c);
153void cursor_set_mono(QEMUCursor *c,
154 uint32_t foreground, uint32_t background, uint8_t *image,
155 int transparent, uint8_t *mask);
156void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
157void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
158
aliguori7d957bd2009-01-15 22:14:11 +0000159struct DisplayChangeListener {
160 int idle;
aurel32f442e082008-03-13 19:20:33 +0000161 uint64_t gui_timer_interval;
pbrook87ecb682007-11-17 17:14:51 +0000162
163 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
aliguori7d957bd2009-01-15 22:14:11 +0000164 void (*dpy_resize)(struct DisplayState *s);
165 void (*dpy_setdata)(struct DisplayState *s);
pbrook87ecb682007-11-17 17:14:51 +0000166 void (*dpy_refresh)(struct DisplayState *s);
167 void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y,
168 int dst_x, int dst_y, int w, int h);
169 void (*dpy_fill)(struct DisplayState *s, int x, int y,
170 int w, int h, uint32_t c);
balrog4d3b6f62008-02-10 16:33:14 +0000171 void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
aliguori7d957bd2009-01-15 22:14:11 +0000172
173 struct DisplayChangeListener *next;
174};
175
aliguori7b5d76d2009-03-13 15:02:13 +0000176struct DisplayAllocator {
177 DisplaySurface* (*create_displaysurface)(int width, int height);
178 DisplaySurface* (*resize_displaysurface)(DisplaySurface *surface, int width, int height);
179 void (*free_displaysurface)(DisplaySurface *surface);
180};
181
aliguori7d957bd2009-01-15 22:14:11 +0000182struct DisplayState {
183 struct DisplaySurface *surface;
184 void *opaque;
185 struct QEMUTimer *gui_timer;
186
aliguori7b5d76d2009-03-13 15:02:13 +0000187 struct DisplayAllocator* allocator;
aliguori7d957bd2009-01-15 22:14:11 +0000188 struct DisplayChangeListener* listeners;
189
pbrook87ecb682007-11-17 17:14:51 +0000190 void (*mouse_set)(int x, int y, int on);
Gerd Hoffmann254e5952010-05-21 11:54:32 +0200191 void (*cursor_define)(QEMUCursor *cursor);
aliguori3023f332009-01-16 19:04:14 +0000192
193 struct DisplayState *next;
pbrook87ecb682007-11-17 17:14:51 +0000194};
195
aliguori3023f332009-01-16 19:04:14 +0000196void register_displaystate(DisplayState *ds);
197DisplayState *get_displaystate(void);
aliguori7d957bd2009-01-15 22:14:11 +0000198DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
199 int linesize, uint8_t *data);
Jes Sorensenffe8b822011-03-16 13:33:30 +0100200void qemu_alloc_display(DisplaySurface *surface, int width, int height,
201 int linesize, PixelFormat pf, int newflags);
malc0da2ea12009-01-23 19:56:19 +0000202PixelFormat qemu_different_endianness_pixelformat(int bpp);
203PixelFormat qemu_default_pixelformat(int bpp);
aliguori7d957bd2009-01-15 22:14:11 +0000204
aliguori7b5d76d2009-03-13 15:02:13 +0000205DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da);
aliguori7b5d76d2009-03-13 15:02:13 +0000206
207static inline DisplaySurface* qemu_create_displaysurface(DisplayState *ds, int width, int height)
208{
209 return ds->allocator->create_displaysurface(width, height);
210}
211
212static inline DisplaySurface* qemu_resize_displaysurface(DisplayState *ds, int width, int height)
213{
214 return ds->allocator->resize_displaysurface(ds->surface, width, height);
215}
216
217static inline void qemu_free_displaysurface(DisplayState *ds)
218{
219 ds->allocator->free_displaysurface(ds->surface);
220}
221
222static inline int is_surface_bgr(DisplaySurface *surface)
223{
224 if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0)
225 return 1;
226 else
227 return 0;
228}
229
aliguori7d957bd2009-01-15 22:14:11 +0000230static inline int is_buffer_shared(DisplaySurface *surface)
231{
Stefano Stabellinic18a2c32009-06-24 11:58:25 +0100232 return (!(surface->flags & QEMU_ALLOCATED_FLAG) &&
233 !(surface->flags & QEMU_REALPIXELS_FLAG));
aliguori7d957bd2009-01-15 22:14:11 +0000234}
235
236static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
237{
238 dcl->next = ds->listeners;
239 ds->listeners = dcl;
240}
241
pbrook87ecb682007-11-17 17:14:51 +0000242static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
243{
aliguori7d957bd2009-01-15 22:14:11 +0000244 struct DisplayChangeListener *dcl = s->listeners;
245 while (dcl != NULL) {
246 dcl->dpy_update(s, x, y, w, h);
247 dcl = dcl->next;
248 }
pbrook87ecb682007-11-17 17:14:51 +0000249}
250
aliguori7d957bd2009-01-15 22:14:11 +0000251static inline void dpy_resize(DisplayState *s)
pbrook87ecb682007-11-17 17:14:51 +0000252{
aliguori7d957bd2009-01-15 22:14:11 +0000253 struct DisplayChangeListener *dcl = s->listeners;
254 while (dcl != NULL) {
255 dcl->dpy_resize(s);
256 dcl = dcl->next;
257 }
pbrook87ecb682007-11-17 17:14:51 +0000258}
259
aliguori7d957bd2009-01-15 22:14:11 +0000260static inline void dpy_setdata(DisplayState *s)
balrog4d3b6f62008-02-10 16:33:14 +0000261{
aliguori7d957bd2009-01-15 22:14:11 +0000262 struct DisplayChangeListener *dcl = s->listeners;
263 while (dcl != NULL) {
264 if (dcl->dpy_setdata) dcl->dpy_setdata(s);
265 dcl = dcl->next;
266 }
267}
268
269static inline void dpy_refresh(DisplayState *s)
270{
271 struct DisplayChangeListener *dcl = s->listeners;
272 while (dcl != NULL) {
273 if (dcl->dpy_refresh) dcl->dpy_refresh(s);
274 dcl = dcl->next;
275 }
276}
277
278static inline void dpy_copy(struct DisplayState *s, int src_x, int src_y,
279 int dst_x, int dst_y, int w, int h) {
280 struct DisplayChangeListener *dcl = s->listeners;
281 while (dcl != NULL) {
282 if (dcl->dpy_copy)
283 dcl->dpy_copy(s, src_x, src_y, dst_x, dst_y, w, h);
284 else /* TODO */
285 dcl->dpy_update(s, dst_x, dst_y, w, h);
286 dcl = dcl->next;
287 }
288}
289
290static inline void dpy_fill(struct DisplayState *s, int x, int y,
291 int w, int h, uint32_t c) {
292 struct DisplayChangeListener *dcl = s->listeners;
293 while (dcl != NULL) {
294 if (dcl->dpy_fill) dcl->dpy_fill(s, x, y, w, h, c);
295 dcl = dcl->next;
296 }
297}
298
299static inline void dpy_cursor(struct DisplayState *s, int x, int y) {
300 struct DisplayChangeListener *dcl = s->listeners;
301 while (dcl != NULL) {
302 if (dcl->dpy_text_cursor) dcl->dpy_text_cursor(s, x, y);
303 dcl = dcl->next;
304 }
balrog4d3b6f62008-02-10 16:33:14 +0000305}
306
aliguori0e1f5a02008-11-24 19:29:13 +0000307static inline int ds_get_linesize(DisplayState *ds)
308{
aliguori7d957bd2009-01-15 22:14:11 +0000309 return ds->surface->linesize;
aliguori0e1f5a02008-11-24 19:29:13 +0000310}
311
312static inline uint8_t* ds_get_data(DisplayState *ds)
313{
aliguori7d957bd2009-01-15 22:14:11 +0000314 return ds->surface->data;
aliguori0e1f5a02008-11-24 19:29:13 +0000315}
316
317static inline int ds_get_width(DisplayState *ds)
318{
aliguori7d957bd2009-01-15 22:14:11 +0000319 return ds->surface->width;
aliguori0e1f5a02008-11-24 19:29:13 +0000320}
321
322static inline int ds_get_height(DisplayState *ds)
323{
aliguori7d957bd2009-01-15 22:14:11 +0000324 return ds->surface->height;
aliguori0e1f5a02008-11-24 19:29:13 +0000325}
326
327static inline int ds_get_bits_per_pixel(DisplayState *ds)
328{
aliguori7d957bd2009-01-15 22:14:11 +0000329 return ds->surface->pf.bits_per_pixel;
aliguori0e1f5a02008-11-24 19:29:13 +0000330}
331
aliguori8927bcf2009-01-15 22:07:16 +0000332static inline int ds_get_bytes_per_pixel(DisplayState *ds)
333{
aliguori7d957bd2009-01-15 22:14:11 +0000334 return ds->surface->pf.bytes_per_pixel;
aliguori8927bcf2009-01-15 22:07:16 +0000335}
336
Devin J. Pohlydf00bed2011-09-07 15:44:36 -0400337#ifdef CONFIG_CURSES
338#include <curses.h>
339typedef chtype console_ch_t;
340#else
Anthony Liguoric227f092009-10-01 16:12:16 -0500341typedef unsigned long console_ch_t;
Devin J. Pohlydf00bed2011-09-07 15:44:36 -0400342#endif
Anthony Liguoric227f092009-10-01 16:12:16 -0500343static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
balrog4d3b6f62008-02-10 16:33:14 +0000344{
Bernhard Kauerf6d20d02010-05-21 14:05:55 +0200345 if (!(ch & 0xff))
346 ch |= ' ';
Aurelien Jarno9ae19b62011-01-04 21:58:24 +0100347 *dest = ch;
balrog4d3b6f62008-02-10 16:33:14 +0000348}
349
pbrook87ecb682007-11-17 17:14:51 +0000350typedef void (*vga_hw_update_ptr)(void *);
351typedef void (*vga_hw_invalidate_ptr)(void *);
352typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
Anthony Liguoric227f092009-10-01 16:12:16 -0500353typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
pbrook87ecb682007-11-17 17:14:51 +0000354
aliguori3023f332009-01-16 19:04:14 +0000355DisplayState *graphic_console_init(vga_hw_update_ptr update,
356 vga_hw_invalidate_ptr invalidate,
357 vga_hw_screen_dump_ptr screen_dump,
358 vga_hw_text_update_ptr text_update,
359 void *opaque);
360
pbrook87ecb682007-11-17 17:14:51 +0000361void vga_hw_update(void);
362void vga_hw_invalidate(void);
363void vga_hw_screen_dump(const char *filename);
Anthony Liguoric227f092009-10-01 16:12:16 -0500364void vga_hw_text_update(console_ch_t *chardata);
pbrook87ecb682007-11-17 17:14:51 +0000365
366int is_graphic_console(void);
balrogc21bbcf2008-09-24 03:32:33 +0000367int is_fixedsize_console(void);
Kevin Wolf6e1db572011-06-01 13:29:11 +0200368int text_console_init(QemuOpts *opts, CharDriverState **_chr);
aliguori2796dae2009-01-16 20:23:27 +0000369void text_consoles_set_display(DisplayState *ds);
pbrook87ecb682007-11-17 17:14:51 +0000370void console_select(unsigned int index);
371void console_color_init(DisplayState *ds);
aliguori3023f332009-01-16 19:04:14 +0000372void qemu_console_resize(DisplayState *ds, int width, int height);
373void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
374 int dst_x, int dst_y, int w, int h);
pbrook87ecb682007-11-17 17:14:51 +0000375
376/* sdl.c */
377void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
378
379/* cocoa.m */
380void cocoa_display_init(DisplayState *ds, int full_screen);
381
382/* vnc.c */
383void vnc_display_init(DisplayState *ds);
384void vnc_display_close(DisplayState *ds);
385int vnc_display_open(DisplayState *ds, const char *display);
Daniel P. Berrange13661082011-06-23 13:31:42 +0100386void vnc_display_add_client(DisplayState *ds, int csock, int skipauth);
Anthony Liguori1cd20f82011-01-31 14:27:36 -0600387int vnc_display_disable_login(DisplayState *ds);
Jes Sorensen821601e2011-03-16 13:33:36 +0100388char *vnc_display_local_addr(DisplayState *ds);
389#ifdef CONFIG_VNC
390int vnc_display_password(DisplayState *ds, const char *password);
Gerd Hoffmann3c9405a2010-10-07 11:50:45 +0200391int vnc_display_pw_expire(DisplayState *ds, time_t expires);
Jes Sorensen821601e2011-03-16 13:33:36 +0100392#else
393static inline int vnc_display_password(DisplayState *ds, const char *password)
394{
395 qerror_report(QERR_FEATURE_DISABLED, "vnc");
396 return -ENODEV;
397}
398static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
399{
400 qerror_report(QERR_FEATURE_DISABLED, "vnc");
401 return -ENODEV;
402};
Jes Sorensen821601e2011-03-16 13:33:36 +0100403#endif
pbrook87ecb682007-11-17 17:14:51 +0000404
balrog4d3b6f62008-02-10 16:33:14 +0000405/* curses.c */
406void curses_display_init(DisplayState *ds, int full_screen);
407
pbrook87ecb682007-11-17 17:14:51 +0000408#endif