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