]> git.proxmox.com Git - mirror_qemu.git/blame - include/ui/console.h
QemuOpts: Convert qemu_opts_foreach() to Error
[mirror_qemu.git] / include / ui / console.h
CommitLineData
87ecb68b
PB
1#ifndef CONSOLE_H
2#define CONSOLE_H
3
28ecbaee 4#include "ui/qemu-pixman.h"
95be0669 5#include "qom/object.h"
7b1b5d19 6#include "qapi/qmp/qdict.h"
1de7afc9 7#include "qemu/notify.h"
83c9089e 8#include "monitor/monitor.h"
1048c88f 9#include "qapi-types.h"
7b1b5d19 10#include "qapi/error.h"
87ecb68b 11
cd2bc889 12#ifdef CONFIG_OPENGL
dcf30025 13# include <epoxy/gl.h>
cd2bc889
GH
14#endif
15
87ecb68b
PB
16/* keyboard/mouse support */
17
18#define MOUSE_EVENT_LBUTTON 0x01
19#define MOUSE_EVENT_RBUTTON 0x02
20#define MOUSE_EVENT_MBUTTON 0x04
21bae11a
GH
21#define MOUSE_EVENT_WHEELUP 0x08
22#define MOUSE_EVENT_WHEELDN 0x10
87ecb68b 23
03a23a85
GH
24/* identical to the ps/2 keyboard bits */
25#define QEMU_SCROLL_LOCK_LED (1 << 0)
26#define QEMU_NUM_LOCK_LED (1 << 1)
27#define QEMU_CAPS_LOCK_LED (1 << 2)
28
7ed9eba3 29/* in ms */
0f7b2864
GH
30#define GUI_REFRESH_INTERVAL_DEFAULT 30
31#define GUI_REFRESH_INTERVAL_IDLE 3000
7ed9eba3 32
87ecb68b 33typedef void QEMUPutKBDEvent(void *opaque, int keycode);
03a23a85 34typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
87ecb68b
PB
35typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
36
72711efb 37typedef struct QEMUPutMouseEntry QEMUPutMouseEntry;
5a37532d 38typedef struct QEMUPutKbdEntry QEMUPutKbdEntry;
72711efb 39typedef struct QEMUPutLEDEntry QEMUPutLEDEntry;
03a23a85 40
5a37532d
GH
41QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
42 void *opaque);
87ecb68b
PB
43QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
44 void *opaque, int absolute,
45 const char *name);
46void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
6fef28ee
AL
47void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
48
03a23a85
GH
49QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
50void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
87ecb68b 51
03a23a85 52void kbd_put_ledstate(int ledstate);
eb2e259d 53
bc24a225 54struct MouseTransformInfo {
a5d7eb65
AZ
55 /* Touchscreen resolution */
56 int x;
57 int y;
58 /* Calibration values as used/generated by tslib */
59 int a[7];
60};
61
3e5a50d6 62void hmp_mouse_set(Monitor *mon, const QDict *qdict);
87ecb68b
PB
63
64/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
65 constants) */
66#define QEMU_KEY_ESC1(c) ((c) | 0xe100)
67#define QEMU_KEY_BACKSPACE 0x007f
68#define QEMU_KEY_UP QEMU_KEY_ESC1('A')
69#define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
70#define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
71#define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
72#define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
73#define QEMU_KEY_END QEMU_KEY_ESC1(4)
74#define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
75#define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
76#define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
77
78#define QEMU_KEY_CTRL_UP 0xe400
79#define QEMU_KEY_CTRL_DOWN 0xe401
80#define QEMU_KEY_CTRL_LEFT 0xe402
81#define QEMU_KEY_CTRL_RIGHT 0xe403
82#define QEMU_KEY_CTRL_HOME 0xe404
83#define QEMU_KEY_CTRL_END 0xe405
84#define QEMU_KEY_CTRL_PAGEUP 0xe406
85#define QEMU_KEY_CTRL_PAGEDOWN 0xe407
86
3f9a6e85 87void kbd_put_keysym_console(QemuConsole *s, int keysym);
50ef4679 88bool kbd_put_qcode_console(QemuConsole *s, int qcode);
bdef9724 89void kbd_put_string_console(QemuConsole *s, const char *str, int len);
87ecb68b
PB
90void kbd_put_keysym(int keysym);
91
92/* consoles */
93
95be0669
GH
94#define TYPE_QEMU_CONSOLE "qemu-console"
95#define QEMU_CONSOLE(obj) \
96 OBJECT_CHECK(QemuConsole, (obj), TYPE_QEMU_CONSOLE)
97#define QEMU_CONSOLE_GET_CLASS(obj) \
98 OBJECT_GET_CLASS(QemuConsoleClass, (obj), TYPE_QEMU_CONSOLE)
99#define QEMU_CONSOLE_CLASS(klass) \
100 OBJECT_CLASS_CHECK(QemuConsoleClass, (klass), TYPE_QEMU_CONSOLE)
101
102typedef struct QemuConsoleClass QemuConsoleClass;
103
104struct QemuConsoleClass {
105 ObjectClass parent_class;
106};
107
77bfcf28 108#define QEMU_ALLOCATED_FLAG 0x01
7d957bd8
AL
109
110struct PixelFormat {
111 uint8_t bits_per_pixel;
112 uint8_t bytes_per_pixel;
113 uint8_t depth; /* color depth in bits */
114 uint32_t rmask, gmask, bmask, amask;
115 uint8_t rshift, gshift, bshift, ashift;
116 uint8_t rmax, gmax, bmax, amax;
90a1e3c0 117 uint8_t rbits, gbits, bbits, abits;
7d957bd8
AL
118};
119
120struct DisplaySurface {
69c77777
GH
121 pixman_format_code_t format;
122 pixman_image_t *image;
7d957bd8 123 uint8_t flags;
cd2bc889
GH
124#ifdef CONFIG_OPENGL
125 GLenum glformat;
126 GLenum gltype;
127 GLuint texture;
128#endif
7d957bd8
AL
129};
130
6f90f3d7
GH
131typedef struct QemuUIInfo {
132 /* geometry */
133 int xoff;
134 int yoff;
135 uint32_t width;
136 uint32_t height;
137} QemuUIInfo;
138
254e5950
GH
139/* cursor data format is 32bit RGBA */
140typedef struct QEMUCursor {
141 int width, height;
142 int hot_x, hot_y;
143 int refcount;
144 uint32_t data[];
145} QEMUCursor;
146
147QEMUCursor *cursor_alloc(int width, int height);
148void cursor_get(QEMUCursor *c);
149void cursor_put(QEMUCursor *c);
150QEMUCursor *cursor_builtin_hidden(void);
151QEMUCursor *cursor_builtin_left_ptr(void);
152void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
153int cursor_get_mono_bpl(QEMUCursor *c);
154void cursor_set_mono(QEMUCursor *c,
155 uint32_t foreground, uint32_t background, uint8_t *image,
156 int transparent, uint8_t *mask);
157void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
158void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
159
7c20b4a3
GH
160typedef struct DisplayChangeListenerOps {
161 const char *dpy_name;
162
bc2ed970 163 void (*dpy_refresh)(DisplayChangeListener *dcl);
7c20b4a3
GH
164
165 void (*dpy_gfx_update)(DisplayChangeListener *dcl,
7c20b4a3 166 int x, int y, int w, int h);
c12aeb86 167 void (*dpy_gfx_switch)(DisplayChangeListener *dcl,
c12aeb86 168 struct DisplaySurface *new_surface);
7c20b4a3 169 void (*dpy_gfx_copy)(DisplayChangeListener *dcl,
bc2ed970 170 int src_x, int src_y,
a93a4a22 171 int dst_x, int dst_y, int w, int h);
49743df3
BH
172 bool (*dpy_gfx_check_format)(DisplayChangeListener *dcl,
173 pixman_format_code_t format);
a93a4a22 174
7c20b4a3 175 void (*dpy_text_cursor)(DisplayChangeListener *dcl,
7c20b4a3
GH
176 int x, int y);
177 void (*dpy_text_resize)(DisplayChangeListener *dcl,
7c20b4a3
GH
178 int w, int h);
179 void (*dpy_text_update)(DisplayChangeListener *dcl,
7c20b4a3
GH
180 int x, int y, int w, int h);
181
182 void (*dpy_mouse_set)(DisplayChangeListener *dcl,
7c20b4a3
GH
183 int x, int y, int on);
184 void (*dpy_cursor_define)(DisplayChangeListener *dcl,
7c20b4a3
GH
185 QEMUCursor *cursor);
186} DisplayChangeListenerOps;
7d957bd8 187
7c20b4a3 188struct DisplayChangeListener {
0f7b2864 189 uint64_t update_interval;
7c20b4a3
GH
190 const DisplayChangeListenerOps *ops;
191 DisplayState *ds;
284d1c6b 192 QemuConsole *con;
bf2fde70 193
87e487a1 194 QLIST_ENTRY(DisplayChangeListener) next;
7d957bd8
AL
195};
196
64840c66 197DisplayState *init_displaystate(void);
30f1e661
GH
198DisplaySurface *qemu_create_displaysurface_from(int width, int height,
199 pixman_format_code_t format,
200 int linesize, uint8_t *data);
a77549b3
GH
201DisplaySurface *qemu_create_displaysurface_guestmem(int width, int height,
202 pixman_format_code_t format,
203 int linesize,
204 uint64_t addr);
0da2ea1b 205PixelFormat qemu_default_pixelformat(int bpp);
7d957bd8 206
da229ef3
GH
207DisplaySurface *qemu_create_displaysurface(int width, int height);
208void qemu_free_displaysurface(DisplaySurface *surface);
7b5d76da
AL
209
210static inline int is_surface_bgr(DisplaySurface *surface)
211{
30f1e661
GH
212 if (PIXMAN_FORMAT_BPP(surface->format) == 32 &&
213 PIXMAN_FORMAT_TYPE(surface->format) == PIXMAN_TYPE_ABGR) {
7b5d76da 214 return 1;
30f1e661 215 } else {
7b5d76da 216 return 0;
30f1e661 217 }
7b5d76da
AL
218}
219
7d957bd8
AL
220static inline int is_buffer_shared(DisplaySurface *surface)
221{
187cd1d9 222 return !(surface->flags & QEMU_ALLOCATED_FLAG);
7d957bd8
AL
223}
224
5209089f 225void register_displaychangelistener(DisplayChangeListener *dcl);
0f7b2864
GH
226void update_displaychangelistener(DisplayChangeListener *dcl,
227 uint64_t interval);
7c20b4a3
GH
228void unregister_displaychangelistener(DisplayChangeListener *dcl);
229
b7fb49f0 230bool dpy_ui_info_supported(QemuConsole *con);
6f90f3d7
GH
231int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info);
232
c78f7137
GH
233void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h);
234void dpy_gfx_replace_surface(QemuConsole *con,
da229ef3 235 DisplaySurface *surface);
c78f7137 236void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y,
7c20b4a3 237 int dst_x, int dst_y, int w, int h);
c78f7137
GH
238void dpy_text_cursor(QemuConsole *con, int x, int y);
239void dpy_text_update(QemuConsole *con, int x, int y, int w, int h);
240void dpy_text_resize(QemuConsole *con, int w, int h);
241void dpy_mouse_set(QemuConsole *con, int x, int y, int on);
242void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor);
243bool dpy_cursor_define_supported(QemuConsole *con);
49743df3
BH
244bool dpy_gfx_check_format(QemuConsole *con,
245 pixman_format_code_t format);
bf2fde70 246
626e3b34
GH
247static inline int surface_stride(DisplaySurface *s)
248{
249 return pixman_image_get_stride(s->image);
250}
251
252static inline void *surface_data(DisplaySurface *s)
253{
254 return pixman_image_get_data(s->image);
255}
256
257static inline int surface_width(DisplaySurface *s)
258{
259 return pixman_image_get_width(s->image);
260}
261
262static inline int surface_height(DisplaySurface *s)
263{
264 return pixman_image_get_height(s->image);
265}
266
267static inline int surface_bits_per_pixel(DisplaySurface *s)
268{
269 int bits = PIXMAN_FORMAT_BPP(s->format);
270 return bits;
271}
272
273static inline int surface_bytes_per_pixel(DisplaySurface *s)
274{
275 int bits = PIXMAN_FORMAT_BPP(s->format);
276 return (bits + 7) / 8;
277}
278
e444ea34
HR
279static inline pixman_format_code_t surface_format(DisplaySurface *s)
280{
281 return s->format;
282}
283
df00bed0
DP
284#ifdef CONFIG_CURSES
285#include <curses.h>
286typedef chtype console_ch_t;
287#else
c227f099 288typedef unsigned long console_ch_t;
df00bed0 289#endif
c227f099 290static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
4d3b6f6e 291{
f6d20d0f
BK
292 if (!(ch & 0xff))
293 ch |= ' ';
9ae19b65 294 *dest = ch;
4d3b6f6e
AZ
295}
296
380cd056
GH
297typedef struct GraphicHwOps {
298 void (*invalidate)(void *opaque);
299 void (*gfx_update)(void *opaque);
300 void (*text_update)(void *opaque, console_ch_t *text);
dea1b0bd 301 void (*update_interval)(void *opaque, uint64_t interval);
6f90f3d7 302 int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
380cd056 303} GraphicHwOps;
87ecb68b 304
5643706a 305QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head,
aa2beaa1 306 const GraphicHwOps *ops,
c78f7137 307 void *opaque);
1c1f9498
GH
308void graphic_console_set_hwops(QemuConsole *con,
309 const GraphicHwOps *hw_ops,
310 void *opaque);
3023f332 311
1dbfa005
GH
312void graphic_hw_update(QemuConsole *con);
313void graphic_hw_invalidate(QemuConsole *con);
314void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
87ecb68b 315
284d1c6b 316QemuConsole *qemu_console_lookup_by_index(unsigned int index);
5643706a 317QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
81c0d5a6
GH
318bool qemu_console_is_visible(QemuConsole *con);
319bool qemu_console_is_graphic(QemuConsole *con);
320bool qemu_console_is_fixedsize(QemuConsole *con);
779ce88f 321char *qemu_console_get_label(QemuConsole *con);
d4c85337 322int qemu_console_get_index(QemuConsole *con);
5643706a 323uint32_t qemu_console_get_head(QemuConsole *con);
6f90f3d7 324QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con);
d4c85337
GH
325int qemu_console_get_width(QemuConsole *con, int fallback);
326int qemu_console_get_height(QemuConsole *con, int fallback);
81c0d5a6 327
2796dae0 328void text_consoles_set_display(DisplayState *ds);
87ecb68b
PB
329void console_select(unsigned int index);
330void console_color_init(DisplayState *ds);
c78f7137
GH
331void qemu_console_resize(QemuConsole *con, int width, int height);
332void qemu_console_copy(QemuConsole *con, int src_x, int src_y,
3023f332 333 int dst_x, int dst_y, int w, int h);
c78f7137 334DisplaySurface *qemu_console_surface(QemuConsole *con);
87ecb68b 335
cd2bc889
GH
336/* console-gl.c */
337typedef struct ConsoleGLState ConsoleGLState;
338#ifdef CONFIG_OPENGL
339ConsoleGLState *console_gl_init_context(void);
340void console_gl_fini_context(ConsoleGLState *gls);
341bool console_gl_check_format(DisplayChangeListener *dcl,
342 pixman_format_code_t format);
343void surface_gl_create_texture(ConsoleGLState *gls,
344 DisplaySurface *surface);
345void surface_gl_update_texture(ConsoleGLState *gls,
346 DisplaySurface *surface,
347 int x, int y, int w, int h);
348void surface_gl_render_texture(ConsoleGLState *gls,
349 DisplaySurface *surface);
350void surface_gl_destroy_texture(ConsoleGLState *gls,
351 DisplaySurface *surface);
352void surface_gl_setup_viewport(ConsoleGLState *gls,
353 DisplaySurface *surface,
354 int ww, int wh);
355#endif
356
87ecb68b 357/* sdl.c */
0b71a5d5 358void sdl_display_early_init(int opengl);
87ecb68b
PB
359void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
360
361/* cocoa.m */
362void cocoa_display_init(DisplayState *ds, int full_screen);
363
364/* vnc.c */
14f7143e 365void vnc_display_init(const char *id);
4db14629 366void vnc_display_open(const char *id, Error **errp);
14f7143e
GH
367void vnc_display_add_client(const char *id, int csock, bool skipauth);
368char *vnc_display_local_addr(const char *id);
821601ea 369#ifdef CONFIG_VNC
14f7143e
GH
370int vnc_display_password(const char *id, const char *password);
371int vnc_display_pw_expire(const char *id, time_t expires);
4db14629 372QemuOpts *vnc_parse_func(const char *str);
28d0de7a 373int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp);
821601ea 374#else
14f7143e 375static inline int vnc_display_password(const char *id, const char *password)
821601ea 376{
821601ea
JS
377 return -ENODEV;
378}
14f7143e 379static inline int vnc_display_pw_expire(const char *id, time_t expires)
821601ea 380{
821601ea
JS
381 return -ENODEV;
382};
821601ea 383#endif
87ecb68b 384
4d3b6f6e
AZ
385/* curses.c */
386void curses_display_init(DisplayState *ds, int full_screen);
387
1048c88f 388/* input.c */
1048c88f 389int index_from_key(const char *key);
1048c88f 390
a4ccabcf 391/* gtk.c */
97edf3bd 392void early_gtk_display_init(int opengl);
881249c7 393void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover);
a4ccabcf 394
87ecb68b 395#endif