blob: f990684ef4d294ce94ff70ebaa6c06d83f580946 [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"
Luiz Capitulinod7098132012-05-21 16:41:37 -030010#include "error.h"
pbrook87ecb682007-11-17 17:14:51 +000011
12/* keyboard/mouse support */
13
14#define MOUSE_EVENT_LBUTTON 0x01
15#define MOUSE_EVENT_RBUTTON 0x02
16#define MOUSE_EVENT_MBUTTON 0x04
17
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010018/* identical to the ps/2 keyboard bits */
19#define QEMU_SCROLL_LOCK_LED (1 << 0)
20#define QEMU_NUM_LOCK_LED (1 << 1)
21#define QEMU_CAPS_LOCK_LED (1 << 2)
22
aliguori7ed9eba2008-08-21 20:12:05 +000023/* in ms */
24#define GUI_REFRESH_INTERVAL 30
25
pbrook87ecb682007-11-17 17:14:51 +000026typedef void QEMUPutKBDEvent(void *opaque, int keycode);
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010027typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
pbrook87ecb682007-11-17 17:14:51 +000028typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
29
30typedef struct QEMUPutMouseEntry {
31 QEMUPutMouseEvent *qemu_put_mouse_event;
32 void *qemu_put_mouse_event_opaque;
33 int qemu_put_mouse_event_absolute;
34 char *qemu_put_mouse_event_name;
35
Anthony Liguori6fef28e2010-03-09 20:52:22 -060036 int index;
37
pbrook87ecb682007-11-17 17:14:51 +000038 /* used internally by qemu for handling mice */
Anthony Liguori6fef28e2010-03-09 20:52:22 -060039 QTAILQ_ENTRY(QEMUPutMouseEntry) node;
pbrook87ecb682007-11-17 17:14:51 +000040} QEMUPutMouseEntry;
41
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010042typedef struct QEMUPutLEDEntry {
43 QEMUPutLEDEvent *put_led;
44 void *opaque;
45 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
46} QEMUPutLEDEntry;
47
pbrook87ecb682007-11-17 17:14:51 +000048void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
Jes Sorensen46aaebf2010-06-08 15:12:18 +020049void qemu_remove_kbd_event_handler(void);
pbrook87ecb682007-11-17 17:14:51 +000050QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
51 void *opaque, int absolute,
52 const char *name);
53void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
Anthony Liguori6fef28e2010-03-09 20:52:22 -060054void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
55
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010056QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
57void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
pbrook87ecb682007-11-17 17:14:51 +000058
59void kbd_put_keycode(int keycode);
Gerd Hoffmann03a23a82010-02-26 17:17:36 +010060void kbd_put_ledstate(int ledstate);
pbrook87ecb682007-11-17 17:14:51 +000061void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
Anthony Liguorieb2e2592010-03-09 14:26:40 -060062
63/* Does the current mouse generate absolute events */
pbrook87ecb682007-11-17 17:14:51 +000064int kbd_mouse_is_absolute(void);
Anthony Liguori7e581fb2010-03-09 13:25:00 -060065void qemu_add_mouse_mode_change_notifier(Notifier *notify);
66void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
pbrook87ecb682007-11-17 17:14:51 +000067
Anthony Liguorieb2e2592010-03-09 14:26:40 -060068/* Of all the mice, is there one that generates absolute events */
69int kbd_mouse_has_absolute(void);
70
Paul Brookbc24a222009-05-10 01:44:56 +010071struct MouseTransformInfo {
balroga5d7eb62008-04-14 21:28:11 +000072 /* Touchscreen resolution */
73 int x;
74 int y;
75 /* Calibration values as used/generated by tslib */
76 int a[7];
77};
78
Luiz Capitulinod54908a2009-08-28 15:27:13 -030079void do_mouse_set(Monitor *mon, const QDict *qdict);
pbrook87ecb682007-11-17 17:14:51 +000080
81/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
82 constants) */
83#define QEMU_KEY_ESC1(c) ((c) | 0xe100)
84#define QEMU_KEY_BACKSPACE 0x007f
85#define QEMU_KEY_UP QEMU_KEY_ESC1('A')
86#define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
87#define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
88#define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
89#define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
90#define QEMU_KEY_END QEMU_KEY_ESC1(4)
91#define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
92#define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
93#define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
94
95#define QEMU_KEY_CTRL_UP 0xe400
96#define QEMU_KEY_CTRL_DOWN 0xe401
97#define QEMU_KEY_CTRL_LEFT 0xe402
98#define QEMU_KEY_CTRL_RIGHT 0xe403
99#define QEMU_KEY_CTRL_HOME 0xe404
100#define QEMU_KEY_CTRL_END 0xe405
101#define QEMU_KEY_CTRL_PAGEUP 0xe406
102#define QEMU_KEY_CTRL_PAGEDOWN 0xe407
103
104void kbd_put_keysym(int keysym);
105
106/* consoles */
107
aliguori7d957bd2009-01-15 22:14:11 +0000108#define QEMU_BIG_ENDIAN_FLAG 0x01
109#define QEMU_ALLOCATED_FLAG 0x02
Stefano Stabellinic18a2c32009-06-24 11:58:25 +0100110#define QEMU_REALPIXELS_FLAG 0x04
aliguori7d957bd2009-01-15 22:14:11 +0000111
112struct PixelFormat {
113 uint8_t bits_per_pixel;
114 uint8_t bytes_per_pixel;
115 uint8_t depth; /* color depth in bits */
116 uint32_t rmask, gmask, bmask, amask;
117 uint8_t rshift, gshift, bshift, ashift;
118 uint8_t rmax, gmax, bmax, amax;
aliguori90a1e3c2009-01-26 15:37:30 +0000119 uint8_t rbits, gbits, bbits, abits;
aliguori7d957bd2009-01-15 22:14:11 +0000120};
121
122struct DisplaySurface {
123 uint8_t flags;
pbrook87ecb682007-11-17 17:14:51 +0000124 int width;
125 int height;
aliguori7d957bd2009-01-15 22:14:11 +0000126 int linesize; /* bytes per line */
127 uint8_t *data;
128
129 struct PixelFormat pf;
130};
131
Gerd Hoffmann254e5952010-05-21 11:54:32 +0200132/* cursor data format is 32bit RGBA */
133typedef struct QEMUCursor {
134 int width, height;
135 int hot_x, hot_y;
136 int refcount;
137 uint32_t data[];
138} QEMUCursor;
139
140QEMUCursor *cursor_alloc(int width, int height);
141void cursor_get(QEMUCursor *c);
142void cursor_put(QEMUCursor *c);
143QEMUCursor *cursor_builtin_hidden(void);
144QEMUCursor *cursor_builtin_left_ptr(void);
145void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
146int cursor_get_mono_bpl(QEMUCursor *c);
147void cursor_set_mono(QEMUCursor *c,
148 uint32_t foreground, uint32_t background, uint8_t *image,
149 int transparent, uint8_t *mask);
150void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
151void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
152
aliguori7d957bd2009-01-15 22:14:11 +0000153struct DisplayChangeListener {
154 int idle;
aurel32f442e082008-03-13 19:20:33 +0000155 uint64_t gui_timer_interval;
pbrook87ecb682007-11-17 17:14:51 +0000156
157 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
aliguori7d957bd2009-01-15 22:14:11 +0000158 void (*dpy_resize)(struct DisplayState *s);
159 void (*dpy_setdata)(struct DisplayState *s);
pbrook87ecb682007-11-17 17:14:51 +0000160 void (*dpy_refresh)(struct DisplayState *s);
161 void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y,
162 int dst_x, int dst_y, int w, int h);
163 void (*dpy_fill)(struct DisplayState *s, int x, int y,
164 int w, int h, uint32_t c);
balrog4d3b6f62008-02-10 16:33:14 +0000165 void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
aliguori7d957bd2009-01-15 22:14:11 +0000166
167 struct DisplayChangeListener *next;
168};
169
aliguori7b5d76d2009-03-13 15:02:13 +0000170struct DisplayAllocator {
171 DisplaySurface* (*create_displaysurface)(int width, int height);
172 DisplaySurface* (*resize_displaysurface)(DisplaySurface *surface, int width, int height);
173 void (*free_displaysurface)(DisplaySurface *surface);
174};
175
aliguori7d957bd2009-01-15 22:14:11 +0000176struct DisplayState {
177 struct DisplaySurface *surface;
178 void *opaque;
179 struct QEMUTimer *gui_timer;
180
aliguori7b5d76d2009-03-13 15:02:13 +0000181 struct DisplayAllocator* allocator;
aliguori7d957bd2009-01-15 22:14:11 +0000182 struct DisplayChangeListener* listeners;
183
pbrook87ecb682007-11-17 17:14:51 +0000184 void (*mouse_set)(int x, int y, int on);
Gerd Hoffmann254e5952010-05-21 11:54:32 +0200185 void (*cursor_define)(QEMUCursor *cursor);
aliguori3023f332009-01-16 19:04:14 +0000186
187 struct DisplayState *next;
pbrook87ecb682007-11-17 17:14:51 +0000188};
189
aliguori3023f332009-01-16 19:04:14 +0000190void register_displaystate(DisplayState *ds);
191DisplayState *get_displaystate(void);
aliguori7d957bd2009-01-15 22:14:11 +0000192DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
193 int linesize, uint8_t *data);
Jes Sorensenffe8b822011-03-16 13:33:30 +0100194void qemu_alloc_display(DisplaySurface *surface, int width, int height,
195 int linesize, PixelFormat pf, int newflags);
malc0da2ea12009-01-23 19:56:19 +0000196PixelFormat qemu_different_endianness_pixelformat(int bpp);
197PixelFormat qemu_default_pixelformat(int bpp);
aliguori7d957bd2009-01-15 22:14:11 +0000198
aliguori7b5d76d2009-03-13 15:02:13 +0000199DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da);
aliguori7b5d76d2009-03-13 15:02:13 +0000200
201static inline DisplaySurface* qemu_create_displaysurface(DisplayState *ds, int width, int height)
202{
203 return ds->allocator->create_displaysurface(width, height);
204}
205
206static inline DisplaySurface* qemu_resize_displaysurface(DisplayState *ds, int width, int height)
207{
Alon Levycdbc19d2012-03-11 18:11:26 +0200208 trace_displaysurface_resize(ds, ds->surface, width, height);
aliguori7b5d76d2009-03-13 15:02:13 +0000209 return ds->allocator->resize_displaysurface(ds->surface, width, height);
210}
211
212static inline void qemu_free_displaysurface(DisplayState *ds)
213{
Alon Levycdbc19d2012-03-11 18:11:26 +0200214 trace_displaysurface_free(ds, ds->surface);
aliguori7b5d76d2009-03-13 15:02:13 +0000215 ds->allocator->free_displaysurface(ds->surface);
216}
217
218static inline int is_surface_bgr(DisplaySurface *surface)
219{
220 if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0)
221 return 1;
222 else
223 return 0;
224}
225
aliguori7d957bd2009-01-15 22:14:11 +0000226static inline int is_buffer_shared(DisplaySurface *surface)
227{
Stefano Stabellinic18a2c32009-06-24 11:58:25 +0100228 return (!(surface->flags & QEMU_ALLOCATED_FLAG) &&
229 !(surface->flags & QEMU_REALPIXELS_FLAG));
aliguori7d957bd2009-01-15 22:14:11 +0000230}
231
232static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
233{
234 dcl->next = ds->listeners;
235 ds->listeners = dcl;
236}
237
pbrook87ecb682007-11-17 17:14:51 +0000238static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
239{
aliguori7d957bd2009-01-15 22:14:11 +0000240 struct DisplayChangeListener *dcl = s->listeners;
241 while (dcl != NULL) {
242 dcl->dpy_update(s, x, y, w, h);
243 dcl = dcl->next;
244 }
pbrook87ecb682007-11-17 17:14:51 +0000245}
246
aliguori7d957bd2009-01-15 22:14:11 +0000247static inline void dpy_resize(DisplayState *s)
pbrook87ecb682007-11-17 17:14:51 +0000248{
aliguori7d957bd2009-01-15 22:14:11 +0000249 struct DisplayChangeListener *dcl = s->listeners;
250 while (dcl != NULL) {
251 dcl->dpy_resize(s);
252 dcl = dcl->next;
253 }
pbrook87ecb682007-11-17 17:14:51 +0000254}
255
aliguori7d957bd2009-01-15 22:14:11 +0000256static inline void dpy_setdata(DisplayState *s)
balrog4d3b6f62008-02-10 16:33:14 +0000257{
aliguori7d957bd2009-01-15 22:14:11 +0000258 struct DisplayChangeListener *dcl = s->listeners;
259 while (dcl != NULL) {
260 if (dcl->dpy_setdata) dcl->dpy_setdata(s);
261 dcl = dcl->next;
262 }
263}
264
265static inline void dpy_refresh(DisplayState *s)
266{
267 struct DisplayChangeListener *dcl = s->listeners;
268 while (dcl != NULL) {
269 if (dcl->dpy_refresh) dcl->dpy_refresh(s);
270 dcl = dcl->next;
271 }
272}
273
274static inline void dpy_copy(struct DisplayState *s, int src_x, int src_y,
275 int dst_x, int dst_y, int w, int h) {
276 struct DisplayChangeListener *dcl = s->listeners;
277 while (dcl != NULL) {
278 if (dcl->dpy_copy)
279 dcl->dpy_copy(s, src_x, src_y, dst_x, dst_y, w, h);
280 else /* TODO */
281 dcl->dpy_update(s, dst_x, dst_y, w, h);
282 dcl = dcl->next;
283 }
284}
285
286static inline void dpy_fill(struct DisplayState *s, int x, int y,
287 int w, int h, uint32_t c) {
288 struct DisplayChangeListener *dcl = s->listeners;
289 while (dcl != NULL) {
290 if (dcl->dpy_fill) dcl->dpy_fill(s, x, y, w, h, c);
291 dcl = dcl->next;
292 }
293}
294
295static inline void dpy_cursor(struct DisplayState *s, int x, int y) {
296 struct DisplayChangeListener *dcl = s->listeners;
297 while (dcl != NULL) {
298 if (dcl->dpy_text_cursor) dcl->dpy_text_cursor(s, x, y);
299 dcl = dcl->next;
300 }
balrog4d3b6f62008-02-10 16:33:14 +0000301}
302
aliguori0e1f5a02008-11-24 19:29:13 +0000303static inline int ds_get_linesize(DisplayState *ds)
304{
aliguori7d957bd2009-01-15 22:14:11 +0000305 return ds->surface->linesize;
aliguori0e1f5a02008-11-24 19:29:13 +0000306}
307
308static inline uint8_t* ds_get_data(DisplayState *ds)
309{
aliguori7d957bd2009-01-15 22:14:11 +0000310 return ds->surface->data;
aliguori0e1f5a02008-11-24 19:29:13 +0000311}
312
313static inline int ds_get_width(DisplayState *ds)
314{
aliguori7d957bd2009-01-15 22:14:11 +0000315 return ds->surface->width;
aliguori0e1f5a02008-11-24 19:29:13 +0000316}
317
318static inline int ds_get_height(DisplayState *ds)
319{
aliguori7d957bd2009-01-15 22:14:11 +0000320 return ds->surface->height;
aliguori0e1f5a02008-11-24 19:29:13 +0000321}
322
323static inline int ds_get_bits_per_pixel(DisplayState *ds)
324{
aliguori7d957bd2009-01-15 22:14:11 +0000325 return ds->surface->pf.bits_per_pixel;
aliguori0e1f5a02008-11-24 19:29:13 +0000326}
327
aliguori8927bcf2009-01-15 22:07:16 +0000328static inline int ds_get_bytes_per_pixel(DisplayState *ds)
329{
aliguori7d957bd2009-01-15 22:14:11 +0000330 return ds->surface->pf.bytes_per_pixel;
aliguori8927bcf2009-01-15 22:07:16 +0000331}
332
Devin J. Pohlydf00bed2011-09-07 15:44:36 -0400333#ifdef CONFIG_CURSES
334#include <curses.h>
335typedef chtype console_ch_t;
336#else
Anthony Liguoric227f092009-10-01 16:12:16 -0500337typedef unsigned long console_ch_t;
Devin J. Pohlydf00bed2011-09-07 15:44:36 -0400338#endif
Anthony Liguoric227f092009-10-01 16:12:16 -0500339static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
balrog4d3b6f62008-02-10 16:33:14 +0000340{
Bernhard Kauerf6d20d02010-05-21 14:05:55 +0200341 if (!(ch & 0xff))
342 ch |= ' ';
Aurelien Jarno9ae19b62011-01-04 21:58:24 +0100343 *dest = ch;
balrog4d3b6f62008-02-10 16:33:14 +0000344}
345
pbrook87ecb682007-11-17 17:14:51 +0000346typedef void (*vga_hw_update_ptr)(void *);
347typedef void (*vga_hw_invalidate_ptr)(void *);
Luiz Capitulinod7098132012-05-21 16:41:37 -0300348typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
349 Error **errp);
Anthony Liguoric227f092009-10-01 16:12:16 -0500350typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
pbrook87ecb682007-11-17 17:14:51 +0000351
aliguori3023f332009-01-16 19:04:14 +0000352DisplayState *graphic_console_init(vga_hw_update_ptr update,
353 vga_hw_invalidate_ptr invalidate,
354 vga_hw_screen_dump_ptr screen_dump,
355 vga_hw_text_update_ptr text_update,
356 void *opaque);
357
pbrook87ecb682007-11-17 17:14:51 +0000358void vga_hw_update(void);
359void vga_hw_invalidate(void);
Anthony Liguoric227f092009-10-01 16:12:16 -0500360void vga_hw_text_update(console_ch_t *chardata);
pbrook87ecb682007-11-17 17:14:51 +0000361
362int is_graphic_console(void);
balrogc21bbcf2008-09-24 03:32:33 +0000363int is_fixedsize_console(void);
Markus Armbruster1f514702012-02-07 15:09:08 +0100364CharDriverState *text_console_init(QemuOpts *opts);
aliguori2796dae2009-01-16 20:23:27 +0000365void text_consoles_set_display(DisplayState *ds);
pbrook87ecb682007-11-17 17:14:51 +0000366void console_select(unsigned int index);
367void console_color_init(DisplayState *ds);
aliguori3023f332009-01-16 19:04:14 +0000368void qemu_console_resize(DisplayState *ds, int width, int height);
369void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
370 int dst_x, int dst_y, int w, int h);
pbrook87ecb682007-11-17 17:14:51 +0000371
372/* sdl.c */
373void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
374
375/* cocoa.m */
376void cocoa_display_init(DisplayState *ds, int full_screen);
377
378/* vnc.c */
379void vnc_display_init(DisplayState *ds);
380void vnc_display_close(DisplayState *ds);
381int vnc_display_open(DisplayState *ds, const char *display);
Daniel P. Berrange13661082011-06-23 13:31:42 +0100382void vnc_display_add_client(DisplayState *ds, int csock, int skipauth);
Anthony Liguori1cd20f82011-01-31 14:27:36 -0600383int vnc_display_disable_login(DisplayState *ds);
Jes Sorensen821601e2011-03-16 13:33:36 +0100384char *vnc_display_local_addr(DisplayState *ds);
385#ifdef CONFIG_VNC
386int vnc_display_password(DisplayState *ds, const char *password);
Gerd Hoffmann3c9405a2010-10-07 11:50:45 +0200387int vnc_display_pw_expire(DisplayState *ds, time_t expires);
Jes Sorensen821601e2011-03-16 13:33:36 +0100388#else
389static inline int vnc_display_password(DisplayState *ds, const char *password)
390{
Jes Sorensen821601e2011-03-16 13:33:36 +0100391 return -ENODEV;
392}
393static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
394{
Jes Sorensen821601e2011-03-16 13:33:36 +0100395 return -ENODEV;
396};
Jes Sorensen821601e2011-03-16 13:33:36 +0100397#endif
pbrook87ecb682007-11-17 17:14:51 +0000398
balrog4d3b6f62008-02-10 16:33:14 +0000399/* curses.c */
400void curses_display_init(DisplayState *ds, int full_screen);
401
Amos Kong1048c882012-08-31 10:56:25 +0800402/* input.c */
Amos Kong1048c882012-08-31 10:56:25 +0800403int index_from_key(const char *key);
404int index_from_keycode(int code);
405
pbrook87ecb682007-11-17 17:14:51 +0000406#endif