usb: Also reset max_packet_size on ep_reset
[qemu/ar7.git] / include / ui / console.h
blob98edf413a6e8f9d687b1d4ac6c9ce0a4cd2e47aa
1 #ifndef CONSOLE_H
2 #define CONSOLE_H
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"
13 /* keyboard/mouse support */
15 #define MOUSE_EVENT_LBUTTON 0x01
16 #define MOUSE_EVENT_RBUTTON 0x02
17 #define MOUSE_EVENT_MBUTTON 0x04
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)
24 /* in ms */
25 #define GUI_REFRESH_INTERVAL_DEFAULT 30
26 #define GUI_REFRESH_INTERVAL_IDLE 3000
28 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
29 typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
30 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
32 typedef struct QEMUPutMouseEntry QEMUPutMouseEntry;
33 typedef struct QEMUPutKbdEntry QEMUPutKbdEntry;
34 typedef struct QEMUPutLEDEntry QEMUPutLEDEntry;
36 QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
37 void *opaque);
38 void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
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);
43 void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
45 QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
46 void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
48 void kbd_put_keycode(int keycode);
49 void kbd_put_ledstate(int ledstate);
50 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
52 /* Does the current mouse generate absolute events */
53 int kbd_mouse_is_absolute(void);
54 void qemu_add_mouse_mode_change_notifier(Notifier *notify);
55 void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
57 /* Of all the mice, is there one that generates absolute events */
58 int kbd_mouse_has_absolute(void);
60 struct MouseTransformInfo {
61 /* Touchscreen resolution */
62 int x;
63 int y;
64 /* Calibration values as used/generated by tslib */
65 int a[7];
68 void do_mouse_set(Monitor *mon, const QDict *qdict);
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)
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
93 void kbd_put_keysym(int keysym);
95 /* consoles */
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)
105 typedef struct QemuConsoleClass QemuConsoleClass;
107 struct QemuConsoleClass {
108 ObjectClass parent_class;
111 #define QEMU_BIG_ENDIAN_FLAG 0x01
112 #define QEMU_ALLOCATED_FLAG 0x02
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;
121 uint8_t rbits, gbits, bbits, abits;
124 struct DisplaySurface {
125 pixman_format_code_t format;
126 pixman_image_t *image;
127 uint8_t flags;
129 struct PixelFormat pf;
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;
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);
153 typedef struct DisplayChangeListenerOps {
154 const char *dpy_name;
156 void (*dpy_refresh)(DisplayChangeListener *dcl);
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);
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);
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;
179 struct DisplayChangeListener {
180 uint64_t update_interval;
181 const DisplayChangeListenerOps *ops;
182 DisplayState *ds;
183 QemuConsole *con;
185 QLIST_ENTRY(DisplayChangeListener) next;
188 DisplayState *init_displaystate(void);
189 DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
190 int linesize, uint8_t *data,
191 bool byteswap);
192 PixelFormat qemu_different_endianness_pixelformat(int bpp);
193 PixelFormat qemu_default_pixelformat(int bpp);
195 DisplaySurface *qemu_create_displaysurface(int width, int height);
196 void qemu_free_displaysurface(DisplaySurface *surface);
198 static inline int is_surface_bgr(DisplaySurface *surface)
200 if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0)
201 return 1;
202 else
203 return 0;
206 static inline int is_buffer_shared(DisplaySurface *surface)
208 return !(surface->flags & QEMU_ALLOCATED_FLAG);
211 void register_displaychangelistener(DisplayChangeListener *dcl);
212 void update_displaychangelistener(DisplayChangeListener *dcl,
213 uint64_t interval);
214 void unregister_displaychangelistener(DisplayChangeListener *dcl);
216 void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h);
217 void dpy_gfx_replace_surface(QemuConsole *con,
218 DisplaySurface *surface);
219 void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y,
220 int dst_x, int dst_y, int w, int h);
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);
228 static inline int surface_stride(DisplaySurface *s)
230 return pixman_image_get_stride(s->image);
233 static inline void *surface_data(DisplaySurface *s)
235 return pixman_image_get_data(s->image);
238 static inline int surface_width(DisplaySurface *s)
240 return pixman_image_get_width(s->image);
243 static inline int surface_height(DisplaySurface *s)
245 return pixman_image_get_height(s->image);
248 static inline int surface_bits_per_pixel(DisplaySurface *s)
250 int bits = PIXMAN_FORMAT_BPP(s->format);
251 return bits;
254 static inline int surface_bytes_per_pixel(DisplaySurface *s)
256 int bits = PIXMAN_FORMAT_BPP(s->format);
257 return (bits + 7) / 8;
260 #ifdef CONFIG_CURSES
261 #include <curses.h>
262 typedef chtype console_ch_t;
263 #else
264 typedef unsigned long console_ch_t;
265 #endif
266 static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
268 if (!(ch & 0xff))
269 ch |= ' ';
270 *dest = ch;
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);
277 void (*update_interval)(void *opaque, uint64_t interval);
278 } GraphicHwOps;
280 QemuConsole *graphic_console_init(DeviceState *dev,
281 const GraphicHwOps *ops,
282 void *opaque);
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);
288 QemuConsole *qemu_console_lookup_by_index(unsigned int index);
289 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev);
290 bool qemu_console_is_visible(QemuConsole *con);
291 bool qemu_console_is_graphic(QemuConsole *con);
292 bool qemu_console_is_fixedsize(QemuConsole *con);
294 void text_consoles_set_display(DisplayState *ds);
295 void console_select(unsigned int index);
296 void console_color_init(DisplayState *ds);
297 void qemu_console_resize(QemuConsole *con, int width, int height);
298 void qemu_console_copy(QemuConsole *con, int src_x, int src_y,
299 int dst_x, int dst_y, int w, int h);
300 DisplaySurface *qemu_console_surface(QemuConsole *con);
301 DisplayState *qemu_console_displaystate(QemuConsole *console);
303 typedef CharDriverState *(VcHandler)(ChardevVC *vc);
305 CharDriverState *vc_init(ChardevVC *vc);
306 void register_vc_handler(VcHandler *handler);
308 /* sdl.c */
309 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
311 /* cocoa.m */
312 void cocoa_display_init(DisplayState *ds, int full_screen);
314 /* vnc.c */
315 void vnc_display_init(DisplayState *ds);
316 void vnc_display_open(DisplayState *ds, const char *display, Error **errp);
317 void vnc_display_add_client(DisplayState *ds, int csock, bool skipauth);
318 char *vnc_display_local_addr(DisplayState *ds);
319 #ifdef CONFIG_VNC
320 int vnc_display_password(DisplayState *ds, const char *password);
321 int vnc_display_pw_expire(DisplayState *ds, time_t expires);
322 #else
323 static inline int vnc_display_password(DisplayState *ds, const char *password)
325 return -ENODEV;
327 static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
329 return -ENODEV;
331 #endif
333 /* curses.c */
334 void curses_display_init(DisplayState *ds, int full_screen);
336 /* input.c */
337 int index_from_key(const char *key);
338 int index_from_keycode(int code);
340 /* gtk.c */
341 void early_gtk_display_init(void);
342 void gtk_display_init(DisplayState *ds, bool full_screen);
344 #endif