]>
Commit | Line | Data |
---|---|---|
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" |
cdbc19dd | 9 | #include "trace.h" |
1048c88f | 10 | #include "qapi-types.h" |
7b1b5d19 | 11 | #include "qapi/error.h" |
87ecb68b PB |
12 | |
13 | /* keyboard/mouse support */ | |
14 | ||
15 | #define MOUSE_EVENT_LBUTTON 0x01 | |
16 | #define MOUSE_EVENT_RBUTTON 0x02 | |
17 | #define MOUSE_EVENT_MBUTTON 0x04 | |
18 | ||
03a23a85 GH |
19 | /* identical to the ps/2 keyboard bits */ |
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 | ||
7ed9eba3 | 24 | /* in ms */ |
0f7b2864 GH |
25 | #define GUI_REFRESH_INTERVAL_DEFAULT 30 |
26 | #define GUI_REFRESH_INTERVAL_IDLE 3000 | |
7ed9eba3 | 27 | |
87ecb68b | 28 | typedef void QEMUPutKBDEvent(void *opaque, int keycode); |
03a23a85 | 29 | typedef void QEMUPutLEDEvent(void *opaque, int ledstate); |
87ecb68b PB |
30 | typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state); |
31 | ||
72711efb | 32 | typedef struct QEMUPutMouseEntry QEMUPutMouseEntry; |
5a37532d | 33 | typedef struct QEMUPutKbdEntry QEMUPutKbdEntry; |
72711efb | 34 | typedef struct QEMUPutLEDEntry QEMUPutLEDEntry; |
03a23a85 | 35 | |
5a37532d GH |
36 | QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, |
37 | void *opaque); | |
38 | void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry); | |
87ecb68b PB |
39 | QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, |
40 | void *opaque, int absolute, | |
41 | const char *name); | |
42 | void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry); | |
6fef28ee AL |
43 | void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry); |
44 | ||
03a23a85 GH |
45 | QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque); |
46 | void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry); | |
87ecb68b PB |
47 | |
48 | void kbd_put_keycode(int keycode); | |
03a23a85 | 49 | void kbd_put_ledstate(int ledstate); |
87ecb68b | 50 | void kbd_mouse_event(int dx, int dy, int dz, int buttons_state); |
eb2e259d AL |
51 | |
52 | /* Does the current mouse generate absolute events */ | |
87ecb68b | 53 | int kbd_mouse_is_absolute(void); |
7e581fb3 AL |
54 | void qemu_add_mouse_mode_change_notifier(Notifier *notify); |
55 | void qemu_remove_mouse_mode_change_notifier(Notifier *notify); | |
87ecb68b | 56 | |
eb2e259d AL |
57 | /* Of all the mice, is there one that generates absolute events */ |
58 | int kbd_mouse_has_absolute(void); | |
59 | ||
bc24a225 | 60 | struct MouseTransformInfo { |
a5d7eb65 AZ |
61 | /* Touchscreen resolution */ |
62 | int x; | |
63 | int y; | |
64 | /* Calibration values as used/generated by tslib */ | |
65 | int a[7]; | |
66 | }; | |
67 | ||
d54908a5 | 68 | void do_mouse_set(Monitor *mon, const QDict *qdict); |
87ecb68b PB |
69 | |
70 | /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx | |
71 | constants) */ | |
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 | ||
93 | void kbd_put_keysym(int keysym); | |
94 | ||
95 | /* consoles */ | |
96 | ||
95be0669 GH |
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 | ||
105 | typedef struct QemuConsoleClass QemuConsoleClass; | |
106 | ||
107 | struct QemuConsoleClass { | |
108 | ObjectClass parent_class; | |
109 | }; | |
110 | ||
7d957bd8 AL |
111 | #define QEMU_BIG_ENDIAN_FLAG 0x01 |
112 | #define QEMU_ALLOCATED_FLAG 0x02 | |
113 | ||
114 | struct PixelFormat { | |
115 | uint8_t bits_per_pixel; | |
116 | uint8_t bytes_per_pixel; | |
117 | uint8_t depth; /* color depth in bits */ | |
118 | uint32_t rmask, gmask, bmask, amask; | |
119 | uint8_t rshift, gshift, bshift, ashift; | |
120 | uint8_t rmax, gmax, bmax, amax; | |
90a1e3c0 | 121 | uint8_t rbits, gbits, bbits, abits; |
7d957bd8 AL |
122 | }; |
123 | ||
124 | struct DisplaySurface { | |
69c77777 GH |
125 | pixman_format_code_t format; |
126 | pixman_image_t *image; | |
7d957bd8 | 127 | uint8_t flags; |
7d957bd8 AL |
128 | |
129 | struct PixelFormat pf; | |
130 | }; | |
131 | ||
254e5950 GH |
132 | /* cursor data format is 32bit RGBA */ |
133 | typedef struct QEMUCursor { | |
134 | int width, height; | |
135 | int hot_x, hot_y; | |
136 | int refcount; | |
137 | uint32_t data[]; | |
138 | } QEMUCursor; | |
139 | ||
140 | QEMUCursor *cursor_alloc(int width, int height); | |
141 | void cursor_get(QEMUCursor *c); | |
142 | void cursor_put(QEMUCursor *c); | |
143 | QEMUCursor *cursor_builtin_hidden(void); | |
144 | QEMUCursor *cursor_builtin_left_ptr(void); | |
145 | void cursor_print_ascii_art(QEMUCursor *c, const char *prefix); | |
146 | int cursor_get_mono_bpl(QEMUCursor *c); | |
147 | void cursor_set_mono(QEMUCursor *c, | |
148 | uint32_t foreground, uint32_t background, uint8_t *image, | |
149 | int transparent, uint8_t *mask); | |
150 | void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask); | |
151 | void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask); | |
152 | ||
7c20b4a3 GH |
153 | typedef struct DisplayChangeListenerOps { |
154 | const char *dpy_name; | |
155 | ||
bc2ed970 | 156 | void (*dpy_refresh)(DisplayChangeListener *dcl); |
7c20b4a3 GH |
157 | |
158 | void (*dpy_gfx_update)(DisplayChangeListener *dcl, | |
7c20b4a3 | 159 | int x, int y, int w, int h); |
c12aeb86 | 160 | void (*dpy_gfx_switch)(DisplayChangeListener *dcl, |
c12aeb86 | 161 | struct DisplaySurface *new_surface); |
7c20b4a3 | 162 | void (*dpy_gfx_copy)(DisplayChangeListener *dcl, |
bc2ed970 | 163 | int src_x, int src_y, |
a93a4a22 | 164 | int dst_x, int dst_y, int w, int h); |
a93a4a22 | 165 | |
7c20b4a3 | 166 | void (*dpy_text_cursor)(DisplayChangeListener *dcl, |
7c20b4a3 GH |
167 | int x, int y); |
168 | void (*dpy_text_resize)(DisplayChangeListener *dcl, | |
7c20b4a3 GH |
169 | int w, int h); |
170 | void (*dpy_text_update)(DisplayChangeListener *dcl, | |
7c20b4a3 GH |
171 | int x, int y, int w, int h); |
172 | ||
173 | void (*dpy_mouse_set)(DisplayChangeListener *dcl, | |
7c20b4a3 GH |
174 | int x, int y, int on); |
175 | void (*dpy_cursor_define)(DisplayChangeListener *dcl, | |
7c20b4a3 GH |
176 | QEMUCursor *cursor); |
177 | } DisplayChangeListenerOps; | |
7d957bd8 | 178 | |
7c20b4a3 | 179 | struct DisplayChangeListener { |
0f7b2864 | 180 | uint64_t update_interval; |
7c20b4a3 GH |
181 | const DisplayChangeListenerOps *ops; |
182 | DisplayState *ds; | |
284d1c6b | 183 | QemuConsole *con; |
bf2fde70 | 184 | |
87e487a1 | 185 | QLIST_ENTRY(DisplayChangeListener) next; |
7d957bd8 AL |
186 | }; |
187 | ||
64840c66 | 188 | DisplayState *init_displaystate(void); |
7d957bd8 | 189 | DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp, |
b1424e03 GH |
190 | int linesize, uint8_t *data, |
191 | bool byteswap); | |
0da2ea1b | 192 | PixelFormat qemu_different_endianness_pixelformat(int bpp); |
193 | PixelFormat qemu_default_pixelformat(int bpp); | |
7d957bd8 | 194 | |
da229ef3 GH |
195 | DisplaySurface *qemu_create_displaysurface(int width, int height); |
196 | void qemu_free_displaysurface(DisplaySurface *surface); | |
7b5d76da AL |
197 | |
198 | static 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 | ||
7d957bd8 AL |
206 | static inline int is_buffer_shared(DisplaySurface *surface) |
207 | { | |
187cd1d9 | 208 | return !(surface->flags & QEMU_ALLOCATED_FLAG); |
7d957bd8 AL |
209 | } |
210 | ||
5209089f | 211 | void register_displaychangelistener(DisplayChangeListener *dcl); |
0f7b2864 GH |
212 | void update_displaychangelistener(DisplayChangeListener *dcl, |
213 | uint64_t interval); | |
7c20b4a3 GH |
214 | void unregister_displaychangelistener(DisplayChangeListener *dcl); |
215 | ||
c78f7137 GH |
216 | void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h); |
217 | void dpy_gfx_replace_surface(QemuConsole *con, | |
da229ef3 | 218 | DisplaySurface *surface); |
c78f7137 | 219 | void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y, |
7c20b4a3 | 220 | int dst_x, int dst_y, int w, int h); |
c78f7137 GH |
221 | void dpy_text_cursor(QemuConsole *con, int x, int y); |
222 | void dpy_text_update(QemuConsole *con, int x, int y, int w, int h); | |
223 | void dpy_text_resize(QemuConsole *con, int w, int h); | |
224 | void dpy_mouse_set(QemuConsole *con, int x, int y, int on); | |
225 | void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor); | |
226 | bool dpy_cursor_define_supported(QemuConsole *con); | |
bf2fde70 | 227 | |
626e3b34 GH |
228 | static inline int surface_stride(DisplaySurface *s) |
229 | { | |
230 | return pixman_image_get_stride(s->image); | |
231 | } | |
232 | ||
233 | static inline void *surface_data(DisplaySurface *s) | |
234 | { | |
235 | return pixman_image_get_data(s->image); | |
236 | } | |
237 | ||
238 | static inline int surface_width(DisplaySurface *s) | |
239 | { | |
240 | return pixman_image_get_width(s->image); | |
241 | } | |
242 | ||
243 | static inline int surface_height(DisplaySurface *s) | |
244 | { | |
245 | return pixman_image_get_height(s->image); | |
246 | } | |
247 | ||
248 | static inline int surface_bits_per_pixel(DisplaySurface *s) | |
249 | { | |
250 | int bits = PIXMAN_FORMAT_BPP(s->format); | |
251 | return bits; | |
252 | } | |
253 | ||
254 | static inline int surface_bytes_per_pixel(DisplaySurface *s) | |
255 | { | |
256 | int bits = PIXMAN_FORMAT_BPP(s->format); | |
257 | return (bits + 7) / 8; | |
258 | } | |
259 | ||
df00bed0 DP |
260 | #ifdef CONFIG_CURSES |
261 | #include <curses.h> | |
262 | typedef chtype console_ch_t; | |
263 | #else | |
c227f099 | 264 | typedef unsigned long console_ch_t; |
df00bed0 | 265 | #endif |
c227f099 | 266 | static inline void console_write_ch(console_ch_t *dest, uint32_t ch) |
4d3b6f6e | 267 | { |
f6d20d0f BK |
268 | if (!(ch & 0xff)) |
269 | ch |= ' '; | |
9ae19b65 | 270 | *dest = ch; |
4d3b6f6e AZ |
271 | } |
272 | ||
380cd056 GH |
273 | typedef struct GraphicHwOps { |
274 | void (*invalidate)(void *opaque); | |
275 | void (*gfx_update)(void *opaque); | |
276 | void (*text_update)(void *opaque, console_ch_t *text); | |
dea1b0bd | 277 | void (*update_interval)(void *opaque, uint64_t interval); |
380cd056 | 278 | } GraphicHwOps; |
87ecb68b | 279 | |
aa2beaa1 GH |
280 | QemuConsole *graphic_console_init(DeviceState *dev, |
281 | const GraphicHwOps *ops, | |
c78f7137 | 282 | void *opaque); |
3023f332 | 283 | |
1dbfa005 GH |
284 | void graphic_hw_update(QemuConsole *con); |
285 | void graphic_hw_invalidate(QemuConsole *con); | |
286 | void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata); | |
87ecb68b | 287 | |
284d1c6b | 288 | QemuConsole *qemu_console_lookup_by_index(unsigned int index); |
14a93649 | 289 | QemuConsole *qemu_console_lookup_by_device(DeviceState *dev); |
81c0d5a6 GH |
290 | bool qemu_console_is_visible(QemuConsole *con); |
291 | bool qemu_console_is_graphic(QemuConsole *con); | |
292 | bool qemu_console_is_fixedsize(QemuConsole *con); | |
293 | ||
2796dae0 | 294 | void text_consoles_set_display(DisplayState *ds); |
87ecb68b PB |
295 | void console_select(unsigned int index); |
296 | void console_color_init(DisplayState *ds); | |
c78f7137 GH |
297 | void qemu_console_resize(QemuConsole *con, int width, int height); |
298 | void qemu_console_copy(QemuConsole *con, int src_x, int src_y, | |
3023f332 | 299 | int dst_x, int dst_y, int w, int h); |
c78f7137 GH |
300 | DisplaySurface *qemu_console_surface(QemuConsole *con); |
301 | DisplayState *qemu_console_displaystate(QemuConsole *console); | |
87ecb68b | 302 | |
702ec69c | 303 | typedef CharDriverState *(VcHandler)(ChardevVC *vc); |
d82831db | 304 | |
702ec69c | 305 | CharDriverState *vc_init(ChardevVC *vc); |
d82831db AL |
306 | void register_vc_handler(VcHandler *handler); |
307 | ||
87ecb68b PB |
308 | /* sdl.c */ |
309 | void sdl_display_init(DisplayState *ds, int full_screen, int no_frame); | |
310 | ||
311 | /* cocoa.m */ | |
312 | void cocoa_display_init(DisplayState *ds, int full_screen); | |
313 | ||
314 | /* vnc.c */ | |
315 | void vnc_display_init(DisplayState *ds); | |
007fcd3e | 316 | void vnc_display_open(DisplayState *ds, const char *display, Error **errp); |
13661089 | 317 | void vnc_display_add_client(DisplayState *ds, int csock, int skipauth); |
821601ea JS |
318 | char *vnc_display_local_addr(DisplayState *ds); |
319 | #ifdef CONFIG_VNC | |
320 | int vnc_display_password(DisplayState *ds, const char *password); | |
3c9405a0 | 321 | int vnc_display_pw_expire(DisplayState *ds, time_t expires); |
821601ea JS |
322 | #else |
323 | static inline int vnc_display_password(DisplayState *ds, const char *password) | |
324 | { | |
821601ea JS |
325 | return -ENODEV; |
326 | } | |
327 | static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires) | |
328 | { | |
821601ea JS |
329 | return -ENODEV; |
330 | }; | |
821601ea | 331 | #endif |
87ecb68b | 332 | |
4d3b6f6e AZ |
333 | /* curses.c */ |
334 | void curses_display_init(DisplayState *ds, int full_screen); | |
335 | ||
1048c88f | 336 | /* input.c */ |
1048c88f AK |
337 | int index_from_key(const char *key); |
338 | int index_from_keycode(int code); | |
339 | ||
a4ccabcf AL |
340 | /* gtk.c */ |
341 | void early_gtk_display_init(void); | |
342 | void gtk_display_init(DisplayState *ds); | |
343 | ||
87ecb68b | 344 | #endif |