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