1#ifndef CONSOLE_H
2#define CONSOLE_H
3
4#include "ui/qemu-pixman.h"
5#include "qom/object.h"
6#include "qapi/qmp/qdict.h"
7#include "qemu/notify.h"
8#include "monitor/monitor.h"
9#include "trace.h"
10#include "qapi-types.h"
11#include "qapi/error.h"
12
13
14
15#define MOUSE_EVENT_LBUTTON 0x01
16#define MOUSE_EVENT_RBUTTON 0x02
17#define MOUSE_EVENT_MBUTTON 0x04
18
19
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
24
25#define GUI_REFRESH_INTERVAL_DEFAULT 30
26#define GUI_REFRESH_INTERVAL_IDLE 3000
27
28typedef void QEMUPutKBDEvent(void *opaque, int keycode);
29typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
30typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
31
32typedef struct QEMUPutMouseEntry QEMUPutMouseEntry;
33typedef struct QEMUPutKbdEntry QEMUPutKbdEntry;
34typedef struct QEMUPutLEDEntry QEMUPutLEDEntry;
35
36QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
37 void *opaque);
38void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
39QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
40 void *opaque, int absolute,
41 const char *name);
42void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
43void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
44
45QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
46void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
47
48void kbd_put_keycode(int keycode);
49void kbd_put_ledstate(int ledstate);
50void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
51
52
53int kbd_mouse_is_absolute(void);
54void qemu_add_mouse_mode_change_notifier(Notifier *notify);
55void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
56
57
58int kbd_mouse_has_absolute(void);
59
60struct MouseTransformInfo {
61
62 int x;
63 int y;
64
65 int a[7];
66};
67
68void do_mouse_set(Monitor *mon, const QDict *qdict);
69
70
71
72#define QEMU_KEY_ESC1(c) ((c) | 0xe100)
73#define QEMU_KEY_BACKSPACE 0x007f
74#define QEMU_KEY_UP QEMU_KEY_ESC1('A')
75#define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
76#define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
77#define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
78#define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
79#define QEMU_KEY_END QEMU_KEY_ESC1(4)
80#define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
81#define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
82#define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
83
84#define QEMU_KEY_CTRL_UP 0xe400
85#define QEMU_KEY_CTRL_DOWN 0xe401
86#define QEMU_KEY_CTRL_LEFT 0xe402
87#define QEMU_KEY_CTRL_RIGHT 0xe403
88#define QEMU_KEY_CTRL_HOME 0xe404
89#define QEMU_KEY_CTRL_END 0xe405
90#define QEMU_KEY_CTRL_PAGEUP 0xe406
91#define QEMU_KEY_CTRL_PAGEDOWN 0xe407
92
93void kbd_put_keysym(int keysym);
94
95
96
97#define TYPE_QEMU_CONSOLE "qemu-console"
98#define QEMU_CONSOLE(obj) \
99 OBJECT_CHECK(QemuConsole, (obj), TYPE_QEMU_CONSOLE)
100#define QEMU_CONSOLE_GET_CLASS(obj) \
101 OBJECT_GET_CLASS(QemuConsoleClass, (obj), TYPE_QEMU_CONSOLE)
102#define QEMU_CONSOLE_CLASS(klass) \
103 OBJECT_CLASS_CHECK(QemuConsoleClass, (klass), TYPE_QEMU_CONSOLE)
104
105typedef struct QemuConsoleClass QemuConsoleClass;
106
107struct QemuConsoleClass {
108 ObjectClass parent_class;
109};
110
111#define QEMU_BIG_ENDIAN_FLAG 0x01
112#define QEMU_ALLOCATED_FLAG 0x02
113
114struct PixelFormat {
115 uint8_t bits_per_pixel;
116 uint8_t bytes_per_pixel;
117 uint8_t depth;
118 uint32_t rmask, gmask, bmask, amask;
119 uint8_t rshift, gshift, bshift, ashift;
120 uint8_t rmax, gmax, bmax, amax;
121 uint8_t rbits, gbits, bbits, abits;
122};
123
124struct DisplaySurface {
125 pixman_format_code_t format;
126 pixman_image_t *image;
127 uint8_t flags;
128
129 struct PixelFormat pf;
130};
131
132
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
153typedef struct DisplayChangeListenerOps {
154 const char *dpy_name;
155
156 void (*dpy_refresh)(DisplayChangeListener *dcl);
157
158 void (*dpy_gfx_update)(DisplayChangeListener *dcl,
159 int x, int y, int w, int h);
160 void (*dpy_gfx_switch)(DisplayChangeListener *dcl,
161 struct DisplaySurface *new_surface);
162 void (*dpy_gfx_copy)(DisplayChangeListener *dcl,
163 int src_x, int src_y,
164 int dst_x, int dst_y, int w, int h);
165
166 void (*dpy_text_cursor)(DisplayChangeListener *dcl,
167 int x, int y);
168 void (*dpy_text_resize)(DisplayChangeListener *dcl,
169 int w, int h);
170 void (*dpy_text_update)(DisplayChangeListener *dcl,
171 int x, int y, int w, int h);
172
173 void (*dpy_mouse_set)(DisplayChangeListener *dcl,
174 int x, int y, int on);
175 void (*dpy_cursor_define)(DisplayChangeListener *dcl,
176 QEMUCursor *cursor);
177} DisplayChangeListenerOps;
178
179struct DisplayChangeListener {
180 uint64_t update_interval;
181 const DisplayChangeListenerOps *ops;
182 DisplayState *ds;
183 QemuConsole *con;
184
185 QLIST_ENTRY(DisplayChangeListener) next;
186};
187
188DisplayState *init_displaystate(void);
189DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
190 int linesize, uint8_t *data,
191 bool byteswap);
192PixelFormat qemu_different_endianness_pixelformat(int bpp);
193PixelFormat qemu_default_pixelformat(int bpp);
194
195DisplaySurface *qemu_create_displaysurface(int width, int height);
196void qemu_free_displaysurface(DisplaySurface *surface);
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
206static inline int is_buffer_shared(DisplaySurface *surface)
207{
208 return !(surface->flags & QEMU_ALLOCATED_FLAG);
209}
210
211void register_displaychangelistener(DisplayChangeListener *dcl);
212void update_displaychangelistener(DisplayChangeListener *dcl,
213 uint64_t interval);
214void unregister_displaychangelistener(DisplayChangeListener *dcl);
215
216void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h);
217void dpy_gfx_replace_surface(QemuConsole *con,
218 DisplaySurface *surface);
219void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y,
220 int dst_x, int dst_y, int w, int h);
221void dpy_text_cursor(QemuConsole *con, int x, int y);
222void dpy_text_update(QemuConsole *con, int x, int y, int w, int h);
223void dpy_text_resize(QemuConsole *con, int w, int h);
224void dpy_mouse_set(QemuConsole *con, int x, int y, int on);
225void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor);
226bool dpy_cursor_define_supported(QemuConsole *con);
227
228static inline int surface_stride(DisplaySurface *s)
229{
230 return pixman_image_get_stride(s->image);
231}
232
233static inline void *surface_data(DisplaySurface *s)
234{
235 return pixman_image_get_data(s->image);
236}
237
238static inline int surface_width(DisplaySurface *s)
239{
240 return pixman_image_get_width(s->image);
241}
242
243static inline int surface_height(DisplaySurface *s)
244{
245 return pixman_image_get_height(s->image);
246}
247
248static inline int surface_bits_per_pixel(DisplaySurface *s)
249{
250 int bits = PIXMAN_FORMAT_BPP(s->format);
251 return bits;
252}
253
254static inline int surface_bytes_per_pixel(DisplaySurface *s)
255{
256 int bits = PIXMAN_FORMAT_BPP(s->format);
257 return (bits + 7) / 8;
258}
259
260#ifdef CONFIG_CURSES
261#include <curses.h>
262typedef chtype console_ch_t;
263#else
264typedef unsigned long console_ch_t;
265#endif
266static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
267{
268 if (!(ch & 0xff))
269 ch |= ' ';
270 *dest = ch;
271}
272
273typedef struct GraphicHwOps {
274 void (*invalidate)(void *opaque);
275 void (*gfx_update)(void *opaque);
276 void (*text_update)(void *opaque, console_ch_t *text);
277 void (*update_interval)(void *opaque, uint64_t interval);
278} GraphicHwOps;
279
280QemuConsole *graphic_console_init(DeviceState *dev,
281 const GraphicHwOps *ops,
282 void *opaque);
283
284void graphic_hw_update(QemuConsole *con);
285void graphic_hw_invalidate(QemuConsole *con);
286void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
287
288QemuConsole *qemu_console_lookup_by_index(unsigned int index);
289QemuConsole *qemu_console_lookup_by_device(DeviceState *dev);
290bool qemu_console_is_visible(QemuConsole *con);
291bool qemu_console_is_graphic(QemuConsole *con);
292bool qemu_console_is_fixedsize(QemuConsole *con);
293
294void text_consoles_set_display(DisplayState *ds);
295void console_select(unsigned int index);
296void console_color_init(DisplayState *ds);
297void qemu_console_resize(QemuConsole *con, int width, int height);
298void qemu_console_copy(QemuConsole *con, int src_x, int src_y,
299 int dst_x, int dst_y, int w, int h);
300DisplaySurface *qemu_console_surface(QemuConsole *con);
301DisplayState *qemu_console_displaystate(QemuConsole *console);
302
303typedef CharDriverState *(VcHandler)(ChardevVC *vc);
304
305CharDriverState *vc_init(ChardevVC *vc);
306void register_vc_handler(VcHandler *handler);
307
308
309void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
310
311
312void cocoa_display_init(DisplayState *ds, int full_screen);
313
314
315void vnc_display_init(DisplayState *ds);
316void vnc_display_open(DisplayState *ds, const char *display, Error **errp);
317void vnc_display_add_client(DisplayState *ds, int csock, bool skipauth);
318char *vnc_display_local_addr(DisplayState *ds);
319#ifdef CONFIG_VNC
320int vnc_display_password(DisplayState *ds, const char *password);
321int vnc_display_pw_expire(DisplayState *ds, time_t expires);
322#else
323static inline int vnc_display_password(DisplayState *ds, const char *password)
324{
325 return -ENODEV;
326}
327static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
328{
329 return -ENODEV;
330};
331#endif
332
333
334void curses_display_init(DisplayState *ds, int full_screen);
335
336
337int index_from_key(const char *key);
338int index_from_keycode(int code);
339
340
341void early_gtk_display_init(void);
342void gtk_display_init(DisplayState *ds, bool full_screen);
343
344#endif
345