]> git.proxmox.com Git - qemu.git/blame - console.h
fdc-test: split test_media_change() test, so insert part can be reused
[qemu.git] / console.h
CommitLineData
87ecb68b
PB
1#ifndef CONSOLE_H
2#define CONSOLE_H
3
4#include "qemu-char.h"
69c77777 5#include "qemu-pixman.h"
d54908a5 6#include "qdict.h"
7e581fb3 7#include "notify.h"
821601ea 8#include "monitor.h"
cdbc19dd 9#include "trace.h"
1048c88f 10#include "qapi-types.h"
d7098135 11#include "error.h"
87ecb68b
PB
12
13/* keyboard/mouse support */
14
15#define MOUSE_EVENT_LBUTTON 0x01
16#define MOUSE_EVENT_RBUTTON 0x02
17#define MOUSE_EVENT_MBUTTON 0x04
18
03a23a85
GH
19/* identical to the ps/2 keyboard bits */
20#define QEMU_SCROLL_LOCK_LED (1 << 0)
21#define QEMU_NUM_LOCK_LED (1 << 1)
22#define QEMU_CAPS_LOCK_LED (1 << 2)
23
7ed9eba3
AL
24/* in ms */
25#define GUI_REFRESH_INTERVAL 30
26
87ecb68b 27typedef void QEMUPutKBDEvent(void *opaque, int keycode);
03a23a85 28typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
87ecb68b
PB
29typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
30
31typedef struct QEMUPutMouseEntry {
32 QEMUPutMouseEvent *qemu_put_mouse_event;
33 void *qemu_put_mouse_event_opaque;
34 int qemu_put_mouse_event_absolute;
35 char *qemu_put_mouse_event_name;
36
6fef28ee
AL
37 int index;
38
87ecb68b 39 /* used internally by qemu for handling mice */
6fef28ee 40 QTAILQ_ENTRY(QEMUPutMouseEntry) node;
87ecb68b
PB
41} QEMUPutMouseEntry;
42
03a23a85
GH
43typedef struct QEMUPutLEDEntry {
44 QEMUPutLEDEvent *put_led;
45 void *opaque;
46 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
47} QEMUPutLEDEntry;
48
87ecb68b 49void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
46aaebff 50void qemu_remove_kbd_event_handler(void);
87ecb68b
PB
51QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
52 void *opaque, int absolute,
53 const char *name);
54void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
6fef28ee
AL
55void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
56
03a23a85
GH
57QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
58void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
87ecb68b
PB
59
60void kbd_put_keycode(int keycode);
03a23a85 61void kbd_put_ledstate(int ledstate);
87ecb68b 62void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
eb2e259d
AL
63
64/* Does the current mouse generate absolute events */
87ecb68b 65int kbd_mouse_is_absolute(void);
7e581fb3
AL
66void qemu_add_mouse_mode_change_notifier(Notifier *notify);
67void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
87ecb68b 68
eb2e259d
AL
69/* Of all the mice, is there one that generates absolute events */
70int kbd_mouse_has_absolute(void);
71
bc24a225 72struct MouseTransformInfo {
a5d7eb65
AZ
73 /* Touchscreen resolution */
74 int x;
75 int y;
76 /* Calibration values as used/generated by tslib */
77 int a[7];
78};
79
d54908a5 80void do_mouse_set(Monitor *mon, const QDict *qdict);
87ecb68b
PB
81
82/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
83 constants) */
84#define QEMU_KEY_ESC1(c) ((c) | 0xe100)
85#define QEMU_KEY_BACKSPACE 0x007f
86#define QEMU_KEY_UP QEMU_KEY_ESC1('A')
87#define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
88#define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
89#define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
90#define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
91#define QEMU_KEY_END QEMU_KEY_ESC1(4)
92#define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
93#define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
94#define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
95
96#define QEMU_KEY_CTRL_UP 0xe400
97#define QEMU_KEY_CTRL_DOWN 0xe401
98#define QEMU_KEY_CTRL_LEFT 0xe402
99#define QEMU_KEY_CTRL_RIGHT 0xe403
100#define QEMU_KEY_CTRL_HOME 0xe404
101#define QEMU_KEY_CTRL_END 0xe405
102#define QEMU_KEY_CTRL_PAGEUP 0xe406
103#define QEMU_KEY_CTRL_PAGEDOWN 0xe407
104
105void kbd_put_keysym(int keysym);
106
107/* consoles */
108
7d957bd8
AL
109#define QEMU_BIG_ENDIAN_FLAG 0x01
110#define QEMU_ALLOCATED_FLAG 0x02
111
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;
90a1e3c0 119 uint8_t rbits, gbits, bbits, abits;
7d957bd8
AL
120};
121
122struct DisplaySurface {
69c77777
GH
123 pixman_format_code_t format;
124 pixman_image_t *image;
7d957bd8 125 uint8_t flags;
7d957bd8
AL
126
127 struct PixelFormat pf;
128};
129
254e5950
GH
130/* cursor data format is 32bit RGBA */
131typedef struct QEMUCursor {
132 int width, height;
133 int hot_x, hot_y;
134 int refcount;
135 uint32_t data[];
136} QEMUCursor;
137
138QEMUCursor *cursor_alloc(int width, int height);
139void cursor_get(QEMUCursor *c);
140void cursor_put(QEMUCursor *c);
141QEMUCursor *cursor_builtin_hidden(void);
142QEMUCursor *cursor_builtin_left_ptr(void);
143void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
144int cursor_get_mono_bpl(QEMUCursor *c);
145void cursor_set_mono(QEMUCursor *c,
146 uint32_t foreground, uint32_t background, uint8_t *image,
147 int transparent, uint8_t *mask);
148void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
149void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
150
7d957bd8
AL
151struct DisplayChangeListener {
152 int idle;
f442e08b 153 uint64_t gui_timer_interval;
87ecb68b 154
87ecb68b 155 void (*dpy_refresh)(struct DisplayState *s);
a93a4a22
GH
156
157 void (*dpy_gfx_update)(struct DisplayState *s, int x, int y, int w, int h);
158 void (*dpy_gfx_resize)(struct DisplayState *s);
159 void (*dpy_gfx_setdata)(struct DisplayState *s);
160 void (*dpy_gfx_copy)(struct DisplayState *s, int src_x, int src_y,
161 int dst_x, int dst_y, int w, int h);
a93a4a22 162
4d3b6f6e 163 void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
a93a4a22
GH
164 void (*dpy_text_resize)(struct DisplayState *s, int w, int h);
165 void (*dpy_text_update)(struct DisplayState *s, int x, int y, int w, int h);
7d957bd8 166
bf2fde70
GH
167 void (*dpy_mouse_set)(struct DisplayState *s, int x, int y, int on);
168 void (*dpy_cursor_define)(struct DisplayState *s, QEMUCursor *cursor);
169
87e487a1 170 QLIST_ENTRY(DisplayChangeListener) next;
7d957bd8
AL
171};
172
173struct DisplayState {
174 struct DisplaySurface *surface;
175 void *opaque;
176 struct QEMUTimer *gui_timer;
a93a4a22
GH
177 bool have_gfx;
178 bool have_text;
7d957bd8 179
87e487a1 180 QLIST_HEAD(, DisplayChangeListener) listeners;
7d957bd8 181
3023f332 182 struct DisplayState *next;
87ecb68b
PB
183};
184
3023f332
AL
185void register_displaystate(DisplayState *ds);
186DisplayState *get_displaystate(void);
7d957bd8
AL
187DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
188 int linesize, uint8_t *data);
0da2ea1b 189PixelFormat qemu_different_endianness_pixelformat(int bpp);
190PixelFormat qemu_default_pixelformat(int bpp);
7d957bd8 191
187cd1d9
GH
192DisplaySurface *qemu_create_displaysurface(DisplayState *ds,
193 int width, int height);
194DisplaySurface *qemu_resize_displaysurface(DisplayState *ds,
195 int width, int height);
196void qemu_free_displaysurface(DisplayState *ds);
7b5d76da
AL
197
198static inline int is_surface_bgr(DisplaySurface *surface)
199{
200 if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0)
201 return 1;
202 else
203 return 0;
204}
205
7d957bd8
AL
206static inline int is_buffer_shared(DisplaySurface *surface)
207{
187cd1d9 208 return !(surface->flags & QEMU_ALLOCATED_FLAG);
7d957bd8
AL
209}
210
35c9e0a5
GH
211void gui_setup_refresh(DisplayState *ds);
212
7d957bd8
AL
213static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
214{
87e487a1 215 QLIST_INSERT_HEAD(&ds->listeners, dcl, next);
35c9e0a5 216 gui_setup_refresh(ds);
e250d949
GH
217 if (dcl->dpy_gfx_resize) {
218 dcl->dpy_gfx_resize(ds);
219 }
35c9e0a5
GH
220}
221
222static inline void unregister_displaychangelistener(DisplayState *ds,
223 DisplayChangeListener *dcl)
224{
225 QLIST_REMOVE(dcl, next);
226 gui_setup_refresh(ds);
7d957bd8
AL
227}
228
a93a4a22 229static inline void dpy_gfx_update(DisplayState *s, int x, int y, int w, int h)
87ecb68b 230{
87e487a1
GH
231 struct DisplayChangeListener *dcl;
232 QLIST_FOREACH(dcl, &s->listeners, next) {
a93a4a22
GH
233 if (dcl->dpy_gfx_update) {
234 dcl->dpy_gfx_update(s, x, y, w, h);
235 }
7d957bd8 236 }
87ecb68b
PB
237}
238
a93a4a22 239static inline void dpy_gfx_resize(DisplayState *s)
87ecb68b 240{
87e487a1
GH
241 struct DisplayChangeListener *dcl;
242 QLIST_FOREACH(dcl, &s->listeners, next) {
a93a4a22
GH
243 if (dcl->dpy_gfx_resize) {
244 dcl->dpy_gfx_resize(s);
245 }
7d957bd8 246 }
87ecb68b
PB
247}
248
a93a4a22 249static inline void dpy_gfx_setdata(DisplayState *s)
4d3b6f6e 250{
87e487a1
GH
251 struct DisplayChangeListener *dcl;
252 QLIST_FOREACH(dcl, &s->listeners, next) {
a93a4a22
GH
253 if (dcl->dpy_gfx_setdata) {
254 dcl->dpy_gfx_setdata(s);
87e487a1 255 }
7d957bd8
AL
256 }
257}
258
259static inline void dpy_refresh(DisplayState *s)
260{
87e487a1
GH
261 struct DisplayChangeListener *dcl;
262 QLIST_FOREACH(dcl, &s->listeners, next) {
263 if (dcl->dpy_refresh) {
264 dcl->dpy_refresh(s);
265 }
7d957bd8
AL
266 }
267}
268
a93a4a22 269static inline void dpy_gfx_copy(struct DisplayState *s, int src_x, int src_y,
87e487a1
GH
270 int dst_x, int dst_y, int w, int h)
271{
272 struct DisplayChangeListener *dcl;
273 QLIST_FOREACH(dcl, &s->listeners, next) {
a93a4a22
GH
274 if (dcl->dpy_gfx_copy) {
275 dcl->dpy_gfx_copy(s, src_x, src_y, dst_x, dst_y, w, h);
87e487a1 276 } else { /* TODO */
a93a4a22 277 dcl->dpy_gfx_update(s, dst_x, dst_y, w, h);
87e487a1 278 }
7d957bd8
AL
279 }
280}
281
bf2fde70 282static inline void dpy_text_cursor(struct DisplayState *s, int x, int y)
87e487a1
GH
283{
284 struct DisplayChangeListener *dcl;
285 QLIST_FOREACH(dcl, &s->listeners, next) {
286 if (dcl->dpy_text_cursor) {
287 dcl->dpy_text_cursor(s, x, y);
288 }
7d957bd8 289 }
4d3b6f6e
AZ
290}
291
a93a4a22
GH
292static inline void dpy_text_update(DisplayState *s, int x, int y, int w, int h)
293{
294 struct DisplayChangeListener *dcl;
295 QLIST_FOREACH(dcl, &s->listeners, next) {
296 if (dcl->dpy_text_update) {
297 dcl->dpy_text_update(s, x, y, w, h);
298 }
299 }
300}
301
302static inline void dpy_text_resize(DisplayState *s, int w, int h)
303{
304 struct DisplayChangeListener *dcl;
305 QLIST_FOREACH(dcl, &s->listeners, next) {
306 if (dcl->dpy_text_resize) {
307 dcl->dpy_text_resize(s, w, h);
308 }
309 }
310}
311
bf2fde70
GH
312static inline void dpy_mouse_set(struct DisplayState *s, int x, int y, int on)
313{
314 struct DisplayChangeListener *dcl;
315 QLIST_FOREACH(dcl, &s->listeners, next) {
316 if (dcl->dpy_mouse_set) {
317 dcl->dpy_mouse_set(s, x, y, on);
318 }
319 }
320}
321
322static inline void dpy_cursor_define(struct DisplayState *s, QEMUCursor *cursor)
323{
324 struct DisplayChangeListener *dcl;
325 QLIST_FOREACH(dcl, &s->listeners, next) {
326 if (dcl->dpy_cursor_define) {
327 dcl->dpy_cursor_define(s, cursor);
328 }
329 }
330}
331
332static inline bool dpy_cursor_define_supported(struct DisplayState *s)
333{
334 struct DisplayChangeListener *dcl;
335 QLIST_FOREACH(dcl, &s->listeners, next) {
336 if (dcl->dpy_cursor_define) {
337 return true;
338 }
339 }
340 return false;
341}
342
0e1f5a0c
AL
343static inline int ds_get_linesize(DisplayState *ds)
344{
64f73592 345 return pixman_image_get_stride(ds->surface->image);
0e1f5a0c
AL
346}
347
348static inline uint8_t* ds_get_data(DisplayState *ds)
349{
64f73592 350 return (void *)pixman_image_get_data(ds->surface->image);
0e1f5a0c
AL
351}
352
353static inline int ds_get_width(DisplayState *ds)
354{
64f73592 355 return pixman_image_get_width(ds->surface->image);
0e1f5a0c
AL
356}
357
358static inline int ds_get_height(DisplayState *ds)
359{
64f73592 360 return pixman_image_get_height(ds->surface->image);
0e1f5a0c
AL
361}
362
363static inline int ds_get_bits_per_pixel(DisplayState *ds)
364{
64f73592
GH
365 int bits = PIXMAN_FORMAT_BPP(ds->surface->format);
366 return bits;
0e1f5a0c
AL
367}
368
8927bcfd
AL
369static inline int ds_get_bytes_per_pixel(DisplayState *ds)
370{
64f73592
GH
371 int bits = PIXMAN_FORMAT_BPP(ds->surface->format);
372 return (bits + 7) / 8;
373}
374
375static inline pixman_format_code_t ds_get_format(DisplayState *ds)
376{
377 return ds->surface->format;
8927bcfd
AL
378}
379
d9a86569
GH
380static inline pixman_image_t *ds_get_image(DisplayState *ds)
381{
382 return ds->surface->image;
383}
384
aa32b38c
BZ
385static inline int ds_get_depth(DisplayState *ds)
386{
387 return ds->surface->pf.depth;
388}
389
390static inline int ds_get_rmask(DisplayState *ds)
391{
392 return ds->surface->pf.rmask;
393}
394
395static inline int ds_get_gmask(DisplayState *ds)
396{
397 return ds->surface->pf.gmask;
398}
399
400static inline int ds_get_bmask(DisplayState *ds)
401{
402 return ds->surface->pf.bmask;
403}
404
df00bed0
DP
405#ifdef CONFIG_CURSES
406#include <curses.h>
407typedef chtype console_ch_t;
408#else
c227f099 409typedef unsigned long console_ch_t;
df00bed0 410#endif
c227f099 411static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
4d3b6f6e 412{
f6d20d0f
BK
413 if (!(ch & 0xff))
414 ch |= ' ';
9ae19b65 415 *dest = ch;
4d3b6f6e
AZ
416}
417
87ecb68b
PB
418typedef void (*vga_hw_update_ptr)(void *);
419typedef void (*vga_hw_invalidate_ptr)(void *);
d7098135
LC
420typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
421 Error **errp);
c227f099 422typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
87ecb68b 423
3023f332
AL
424DisplayState *graphic_console_init(vga_hw_update_ptr update,
425 vga_hw_invalidate_ptr invalidate,
426 vga_hw_screen_dump_ptr screen_dump,
427 vga_hw_text_update_ptr text_update,
428 void *opaque);
429
87ecb68b
PB
430void vga_hw_update(void);
431void vga_hw_invalidate(void);
c227f099 432void vga_hw_text_update(console_ch_t *chardata);
87ecb68b
PB
433
434int is_graphic_console(void);
c21bbcfa 435int is_fixedsize_console(void);
1f51470d 436CharDriverState *text_console_init(QemuOpts *opts);
2796dae0 437void text_consoles_set_display(DisplayState *ds);
87ecb68b
PB
438void console_select(unsigned int index);
439void console_color_init(DisplayState *ds);
3023f332
AL
440void qemu_console_resize(DisplayState *ds, int width, int height);
441void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
442 int dst_x, int dst_y, int w, int h);
87ecb68b
PB
443
444/* sdl.c */
445void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
446
447/* cocoa.m */
448void cocoa_display_init(DisplayState *ds, int full_screen);
449
450/* vnc.c */
451void vnc_display_init(DisplayState *ds);
007fcd3e 452void vnc_display_open(DisplayState *ds, const char *display, Error **errp);
13661089 453void vnc_display_add_client(DisplayState *ds, int csock, int skipauth);
821601ea
JS
454char *vnc_display_local_addr(DisplayState *ds);
455#ifdef CONFIG_VNC
456int vnc_display_password(DisplayState *ds, const char *password);
3c9405a0 457int vnc_display_pw_expire(DisplayState *ds, time_t expires);
821601ea
JS
458#else
459static inline int vnc_display_password(DisplayState *ds, const char *password)
460{
821601ea
JS
461 return -ENODEV;
462}
463static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
464{
821601ea
JS
465 return -ENODEV;
466};
821601ea 467#endif
87ecb68b 468
4d3b6f6e
AZ
469/* curses.c */
470void curses_display_init(DisplayState *ds, int full_screen);
471
1048c88f 472/* input.c */
1048c88f
AK
473int index_from_key(const char *key);
474int index_from_keycode(int code);
475
87ecb68b 476#endif