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