blob: 7934b1189420989622698e6b2a7b06e187d55823 [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 "monitor.h"
Alon Levycdbc19d2012-03-11 18:11:26 +02008#include "trace.h"
Amos Kong1048c882012-08-31 10:56:25 +08009#include "qapi-types.h"
pbrook87ecb682007-11-17 17:14:51 +000010
11/* keyboard/mouse support */
12
13#define MOUSE_EVENT_LBUTTON 0x01
14#define MOUSE_EVENT_RBUTTON 0x02
15#define MOUSE_EVENT_MBUTTON 0x04
16
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010017/* identical to the ps/2 keyboard bits */
18#define QEMU_SCROLL_LOCK_LED (1 << 0)
19#define QEMU_NUM_LOCK_LED (1 << 1)
20#define QEMU_CAPS_LOCK_LED (1 << 2)
21
aliguori7ed9eba2008-08-21 20:12:05 +000022/* in ms */
23#define GUI_REFRESH_INTERVAL 30
24
pbrook87ecb682007-11-17 17:14:51 +000025typedef void QEMUPutKBDEvent(void *opaque, int keycode);
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010026typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
pbrook87ecb682007-11-17 17:14:51 +000027typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
28
29typedef struct QEMUPutMouseEntry {
30 QEMUPutMouseEvent *qemu_put_mouse_event;
31 void *qemu_put_mouse_event_opaque;
32 int qemu_put_mouse_event_absolute;
33 char *qemu_put_mouse_event_name;
34
Anthony Liguori6fef28e2010-03-09 20:52:22 -060035 int index;
36
pbrook87ecb682007-11-17 17:14:51 +000037 /* used internally by qemu for handling mice */
Anthony Liguori6fef28e2010-03-09 20:52:22 -060038 QTAILQ_ENTRY(QEMUPutMouseEntry) node;
pbrook87ecb682007-11-17 17:14:51 +000039} QEMUPutMouseEntry;
40
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010041typedef struct QEMUPutLEDEntry {
42 QEMUPutLEDEvent *put_led;
43 void *opaque;
44 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
45} QEMUPutLEDEntry;
46
pbrook87ecb682007-11-17 17:14:51 +000047void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
Jes Sorensen46aaebf2010-06-08 15:12:18 +020048void qemu_remove_kbd_event_handler(void);
pbrook87ecb682007-11-17 17:14:51 +000049QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
50 void *opaque, int absolute,
51 const char *name);
52void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
Anthony Liguori6fef28e2010-03-09 20:52:22 -060053void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
54
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010055QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
56void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
pbrook87ecb682007-11-17 17:14:51 +000057
58void kbd_put_keycode(int keycode);
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010059void kbd_put_ledstate(int ledstate);
pbrook87ecb682007-11-17 17:14:51 +000060void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
Anthony Liguorieb2e2592010-03-09 14:26:40 -060061
62/* Does the current mouse generate absolute events */
pbrook87ecb682007-11-17 17:14:51 +000063int kbd_mouse_is_absolute(void);
Anthony Liguori7e581fb2010-03-09 13:25:00 -060064void qemu_add_mouse_mode_change_notifier(Notifier *notify);
65void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
pbrook87ecb682007-11-17 17:14:51 +000066
Anthony Liguorieb2e2592010-03-09 14:26:40 -060067/* Of all the mice, is there one that generates absolute events */
68int kbd_mouse_has_absolute(void);
69
Paul Brookbc24a222009-05-10 01:44:56 +010070struct MouseTransformInfo {
balroga5d7eb62008-04-14 21:28:11 +000071 /* Touchscreen resolution */
72 int x;
73 int y;
74 /* Calibration values as used/generated by tslib */
75 int a[7];
76};
77
Luiz Capitulinod54908a2009-08-28 15:27:13 -030078void do_mouse_set(Monitor *mon, const QDict *qdict);
pbrook87ecb682007-11-17 17:14:51 +000079
80/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
81 constants) */
82#define QEMU_KEY_ESC1(c) ((c) | 0xe100)
83#define QEMU_KEY_BACKSPACE 0x007f
84#define QEMU_KEY_UP QEMU_KEY_ESC1('A')
85#define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
86#define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
87#define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
88#define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
89#define QEMU_KEY_END QEMU_KEY_ESC1(4)
90#define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
91#define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
92#define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
93
94#define QEMU_KEY_CTRL_UP 0xe400
95#define QEMU_KEY_CTRL_DOWN 0xe401
96#define QEMU_KEY_CTRL_LEFT 0xe402
97#define QEMU_KEY_CTRL_RIGHT 0xe403
98#define QEMU_KEY_CTRL_HOME 0xe404
99#define QEMU_KEY_CTRL_END 0xe405
100#define QEMU_KEY_CTRL_PAGEUP 0xe406
101#define QEMU_KEY_CTRL_PAGEDOWN 0xe407
102
103void kbd_put_keysym(int keysym);
104
105/* consoles */
106
aliguori7d957bd2009-01-15 22:14:11 +0000107#define QEMU_BIG_ENDIAN_FLAG 0x01
108#define QEMU_ALLOCATED_FLAG 0x02
Stefano Stabellinic18a2c32009-06-24 11:58:25 +0100109#define QEMU_REALPIXELS_FLAG 0x04
aliguori7d957bd2009-01-15 22:14:11 +0000110
111struct PixelFormat {
112 uint8_t bits_per_pixel;
113 uint8_t bytes_per_pixel;
114 uint8_t depth; /* color depth in bits */
115 uint32_t rmask, gmask, bmask, amask;
116 uint8_t rshift, gshift, bshift, ashift;
117 uint8_t rmax, gmax, bmax, amax;
aliguori90a1e3c2009-01-26 15:37:30 +0000118 uint8_t rbits, gbits, bbits, abits;
aliguori7d957bd2009-01-15 22:14:11 +0000119};
120
121struct DisplaySurface {
122 uint8_t flags;
pbrook87ecb682007-11-17 17:14:51 +0000123 int width;
124 int height;
aliguori7d957bd2009-01-15 22:14:11 +0000125 int linesize; /* bytes per line */
126 uint8_t *data;
127
128 struct PixelFormat pf;
129};
130
Gerd Hoffmann254e5952010-05-21 11:54:32 +0200131/* cursor data format is 32bit RGBA */
132typedef struct QEMUCursor {
133 int width, height;
134 int hot_x, hot_y;
135 int refcount;
136 uint32_t data[];
137} QEMUCursor;
138
139QEMUCursor *cursor_alloc(int width, int height);
140void cursor_get(QEMUCursor *c);
141void cursor_put(QEMUCursor *c);
142QEMUCursor *cursor_builtin_hidden(void);
143QEMUCursor *cursor_builtin_left_ptr(void);
144void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
145int cursor_get_mono_bpl(QEMUCursor *c);
146void cursor_set_mono(QEMUCursor *c,
147 uint32_t foreground, uint32_t background, uint8_t *image,
148 int transparent, uint8_t *mask);
149void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
150void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
151
aliguori7d957bd2009-01-15 22:14:11 +0000152struct DisplayChangeListener {
153 int idle;
aurel32f442e082008-03-13 19:20:33 +0000154 uint64_t gui_timer_interval;
pbrook87ecb682007-11-17 17:14:51 +0000155
156 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
aliguori7d957bd2009-01-15 22:14:11 +0000157 void (*dpy_resize)(struct DisplayState *s);
158 void (*dpy_setdata)(struct DisplayState *s);
pbrook87ecb682007-11-17 17:14:51 +0000159 void (*dpy_refresh)(struct DisplayState *s);
160 void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y,
161 int dst_x, int dst_y, int w, int h);
162 void (*dpy_fill)(struct DisplayState *s, int x, int y,
163 int w, int h, uint32_t c);
balrog4d3b6f62008-02-10 16:33:14 +0000164 void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
aliguori7d957bd2009-01-15 22:14:11 +0000165
166 struct DisplayChangeListener *next;
167};
168
aliguori7b5d76d2009-03-13 15:02:13 +0000169struct DisplayAllocator {
170 DisplaySurface* (*create_displaysurface)(int width, int height);
171 DisplaySurface* (*resize_displaysurface)(DisplaySurface *surface, int width, int height);
172 void (*free_displaysurface)(DisplaySurface *surface);
173};
174
aliguori7d957bd2009-01-15 22:14:11 +0000175struct DisplayState {
176 struct DisplaySurface *surface;
177 void *opaque;
178 struct QEMUTimer *gui_timer;
179
aliguori7b5d76d2009-03-13 15:02:13 +0000180 struct DisplayAllocator* allocator;
aliguori7d957bd2009-01-15 22:14:11 +0000181 struct DisplayChangeListener* listeners;
182
pbrook87ecb682007-11-17 17:14:51 +0000183 void (*mouse_set)(int x, int y, int on);
Gerd Hoffmann254e5952010-05-21 11:54:32 +0200184 void (*cursor_define)(QEMUCursor *cursor);
aliguori3023f332009-01-16 19:04:14 +0000185
186 struct DisplayState *next;
pbrook87ecb682007-11-17 17:14:51 +0000187};
188
aliguori3023f332009-01-16 19:04:14 +0000189void register_displaystate(DisplayState *ds);
190DisplayState *get_displaystate(void);
aliguori7d957bd2009-01-15 22:14:11 +0000191DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
192 int linesize, uint8_t *data);
Jes Sorensenffe8b822011-03-16 13:33:30 +0100193void qemu_alloc_display(DisplaySurface *surface, int width, int height,
194 int linesize, PixelFormat pf, int newflags);
malc0da2ea12009-01-23 19:56:19 +0000195PixelFormat qemu_different_endianness_pixelformat(int bpp);
196PixelFormat qemu_default_pixelformat(int bpp);
aliguori7d957bd2009-01-15 22:14:11 +0000197
aliguori7b5d76d2009-03-13 15:02:13 +0000198DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da);
aliguori7b5d76d2009-03-13 15:02:13 +0000199
200static inline DisplaySurface* qemu_create_displaysurface(DisplayState *ds, int width, int height)
201{
202 return ds->allocator->create_displaysurface(width, height);
203}
204
205static inline DisplaySurface* qemu_resize_displaysurface(DisplayState *ds, int width, int height)
206{
Alon Levycdbc19d2012-03-11 18:11:26 +0200207 trace_displaysurface_resize(ds, ds->surface, width, height);
aliguori7b5d76d2009-03-13 15:02:13 +0000208 return ds->allocator->resize_displaysurface(ds->surface, width, height);
209}
210
211static inline void qemu_free_displaysurface(DisplayState *ds)
212{
Alon Levycdbc19d2012-03-11 18:11:26 +0200213 trace_displaysurface_free(ds, ds->surface);
aliguori7b5d76d2009-03-13 15:02:13 +0000214 ds->allocator->free_displaysurface(ds->surface);
215}
216
217static inline int is_surface_bgr(DisplaySurface *surface)
218{
219 if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0)
220 return 1;
221 else
222 return 0;
223}
224
aliguori7d957bd2009-01-15 22:14:11 +0000225static inline int is_buffer_shared(DisplaySurface *surface)
226{
Stefano Stabellinic18a2c32009-06-24 11:58:25 +0100227 return (!(surface->flags & QEMU_ALLOCATED_FLAG) &&
228 !(surface->flags & QEMU_REALPIXELS_FLAG));
aliguori7d957bd2009-01-15 22:14:11 +0000229}
230
231static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
232{
233 dcl->next = ds->listeners;
234 ds->listeners = dcl;
235}
236
pbrook87ecb682007-11-17 17:14:51 +0000237static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
238{
aliguori7d957bd2009-01-15 22:14:11 +0000239 struct DisplayChangeListener *dcl = s->listeners;
240 while (dcl != NULL) {
241 dcl->dpy_update(s, x, y, w, h);
242 dcl = dcl->next;
243 }
pbrook87ecb682007-11-17 17:14:51 +0000244}
245
aliguori7d957bd2009-01-15 22:14:11 +0000246static inline void dpy_resize(DisplayState *s)
pbrook87ecb682007-11-17 17:14:51 +0000247{
aliguori7d957bd2009-01-15 22:14:11 +0000248 struct DisplayChangeListener *dcl = s->listeners;
249 while (dcl != NULL) {
250 dcl->dpy_resize(s);
251 dcl = dcl->next;
252 }
pbrook87ecb682007-11-17 17:14:51 +0000253}
254
aliguori7d957bd2009-01-15 22:14:11 +0000255static inline void dpy_setdata(DisplayState *s)
balrog4d3b6f62008-02-10 16:33:14 +0000256{
aliguori7d957bd2009-01-15 22:14:11 +0000257 struct DisplayChangeListener *dcl = s->listeners;
258 while (dcl != NULL) {
259 if (dcl->dpy_setdata) dcl->dpy_setdata(s);
260 dcl = dcl->next;
261 }
262}
263
264static inline void dpy_refresh(DisplayState *s)
265{
266 struct DisplayChangeListener *dcl = s->listeners;
267 while (dcl != NULL) {
268 if (dcl->dpy_refresh) dcl->dpy_refresh(s);
269 dcl = dcl->next;
270 }
271}
272
273static inline void dpy_copy(struct DisplayState *s, int src_x, int src_y,
274 int dst_x, int dst_y, int w, int h) {
275 struct DisplayChangeListener *dcl = s->listeners;
276 while (dcl != NULL) {
277 if (dcl->dpy_copy)
278 dcl->dpy_copy(s, src_x, src_y, dst_x, dst_y, w, h);
279 else /* TODO */
280 dcl->dpy_update(s, dst_x, dst_y, w, h);
281 dcl = dcl->next;
282 }
283}
284
285static inline void dpy_fill(struct DisplayState *s, int x, int y,
286 int w, int h, uint32_t c) {
287 struct DisplayChangeListener *dcl = s->listeners;
288 while (dcl != NULL) {
289 if (dcl->dpy_fill) dcl->dpy_fill(s, x, y, w, h, c);
290 dcl = dcl->next;
291 }
292}
293
294static inline void dpy_cursor(struct DisplayState *s, int x, int y) {
295 struct DisplayChangeListener *dcl = s->listeners;
296 while (dcl != NULL) {
297 if (dcl->dpy_text_cursor) dcl->dpy_text_cursor(s, x, y);
298 dcl = dcl->next;
299 }
balrog4d3b6f62008-02-10 16:33:14 +0000300}
301
aliguori0e1f5a02008-11-24 19:29:13 +0000302static inline int ds_get_linesize(DisplayState *ds)
303{
aliguori7d957bd2009-01-15 22:14:11 +0000304 return ds->surface->linesize;
aliguori0e1f5a02008-11-24 19:29:13 +0000305}
306
307static inline uint8_t* ds_get_data(DisplayState *ds)
308{
aliguori7d957bd2009-01-15 22:14:11 +0000309 return ds->surface->data;
aliguori0e1f5a02008-11-24 19:29:13 +0000310}
311
312static inline int ds_get_width(DisplayState *ds)
313{
aliguori7d957bd2009-01-15 22:14:11 +0000314 return ds->surface->width;
aliguori0e1f5a02008-11-24 19:29:13 +0000315}
316
317static inline int ds_get_height(DisplayState *ds)
318{
aliguori7d957bd2009-01-15 22:14:11 +0000319 return ds->surface->height;
aliguori0e1f5a02008-11-24 19:29:13 +0000320}
321
322static inline int ds_get_bits_per_pixel(DisplayState *ds)
323{
aliguori7d957bd2009-01-15 22:14:11 +0000324 return ds->surface->pf.bits_per_pixel;
aliguori0e1f5a02008-11-24 19:29:13 +0000325}
326
aliguori8927bcf2009-01-15 22:07:16 +0000327static inline int ds_get_bytes_per_pixel(DisplayState *ds)
328{
aliguori7d957bd2009-01-15 22:14:11 +0000329 return ds->surface->pf.bytes_per_pixel;
aliguori8927bcf2009-01-15 22:07:16 +0000330}
331
Devin J. Pohlydf00bed2011-09-07 15:44:36 -0400332#ifdef CONFIG_CURSES
333#include <curses.h>
334typedef chtype console_ch_t;
335#else
Anthony Liguoric227f092009-10-01 16:12:16 -0500336typedef unsigned long console_ch_t;
Devin J. Pohlydf00bed2011-09-07 15:44:36 -0400337#endif
Anthony Liguoric227f092009-10-01 16:12:16 -0500338static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
balrog4d3b6f62008-02-10 16:33:14 +0000339{
Bernhard Kauerf6d20d02010-05-21 14:05:55 +0200340 if (!(ch & 0xff))
341 ch |= ' ';
Aurelien Jarno9ae19b62011-01-04 21:58:24 +0100342 *dest = ch;
balrog4d3b6f62008-02-10 16:33:14 +0000343}
344
pbrook87ecb682007-11-17 17:14:51 +0000345typedef void (*vga_hw_update_ptr)(void *);
346typedef void (*vga_hw_invalidate_ptr)(void *);
Gerd Hoffmann45efb162012-02-24 12:43:45 +0100347typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch);
Anthony Liguoric227f092009-10-01 16:12:16 -0500348typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
pbrook87ecb682007-11-17 17:14:51 +0000349
aliguori3023f332009-01-16 19:04:14 +0000350DisplayState *graphic_console_init(vga_hw_update_ptr update,
351 vga_hw_invalidate_ptr invalidate,
352 vga_hw_screen_dump_ptr screen_dump,
353 vga_hw_text_update_ptr text_update,
354 void *opaque);
355
pbrook87ecb682007-11-17 17:14:51 +0000356void vga_hw_update(void);
357void vga_hw_invalidate(void);
358void vga_hw_screen_dump(const char *filename);
Anthony Liguoric227f092009-10-01 16:12:16 -0500359void vga_hw_text_update(console_ch_t *chardata);
pbrook87ecb682007-11-17 17:14:51 +0000360
361int is_graphic_console(void);
balrogc21bbcf2008-09-24 03:32:33 +0000362int is_fixedsize_console(void);
Markus Armbruster1f514702012-02-07 15:09:08 +0100363CharDriverState *text_console_init(QemuOpts *opts);
aliguori2796dae2009-01-16 20:23:27 +0000364void text_consoles_set_display(DisplayState *ds);
pbrook87ecb682007-11-17 17:14:51 +0000365void console_select(unsigned int index);
366void console_color_init(DisplayState *ds);
aliguori3023f332009-01-16 19:04:14 +0000367void qemu_console_resize(DisplayState *ds, int width, int height);
368void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
369 int dst_x, int dst_y, int w, int h);
pbrook87ecb682007-11-17 17:14:51 +0000370
371/* sdl.c */
372void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
373
374/* cocoa.m */
375void cocoa_display_init(DisplayState *ds, int full_screen);
376
377/* vnc.c */
378void vnc_display_init(DisplayState *ds);
379void vnc_display_close(DisplayState *ds);
380int vnc_display_open(DisplayState *ds, const char *display);
Daniel P. Berrange13661082011-06-23 13:31:42 +0100381void vnc_display_add_client(DisplayState *ds, int csock, int skipauth);
Anthony Liguori1cd20f82011-01-31 14:27:36 -0600382int vnc_display_disable_login(DisplayState *ds);
Jes Sorensen821601e2011-03-16 13:33:36 +0100383char *vnc_display_local_addr(DisplayState *ds);
384#ifdef CONFIG_VNC
385int vnc_display_password(DisplayState *ds, const char *password);
Gerd Hoffmann3c9405a2010-10-07 11:50:45 +0200386int vnc_display_pw_expire(DisplayState *ds, time_t expires);
Jes Sorensen821601e2011-03-16 13:33:36 +0100387#else
388static inline int vnc_display_password(DisplayState *ds, const char *password)
389{
Jes Sorensen821601e2011-03-16 13:33:36 +0100390 return -ENODEV;
391}
392static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
393{
Jes Sorensen821601e2011-03-16 13:33:36 +0100394 return -ENODEV;
395};
Jes Sorensen821601e2011-03-16 13:33:36 +0100396#endif
pbrook87ecb682007-11-17 17:14:51 +0000397
balrog4d3b6f62008-02-10 16:33:14 +0000398/* curses.c */
399void curses_display_init(DisplayState *ds, int full_screen);
400
Amos Kong1048c882012-08-31 10:56:25 +0800401/* input.c */
402extern const int key_defs[];
403int index_from_key(const char *key);
404int index_from_keycode(int code);
405
pbrook87ecb682007-11-17 17:14:51 +0000406#endif