1 #ifndef CONSOLE_H
2 #define CONSOLE_H
3
4 #include "qemu-char.h"
5
6 /* keyboard/mouse support */
7
8 #define MOUSE_EVENT_LBUTTON 0x01
9 #define MOUSE_EVENT_RBUTTON 0x02
10 #define MOUSE_EVENT_MBUTTON 0x04
11
12 /* in ms */
13 #if 1 /* ANDROID */
14 #define GUI_REFRESH_INTERVAL (1000/60) /* 60 frames/s is better */
15 #else
16 #define GUI_REFRESH_INTERVAL 30
17 #endif
18
19 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
20 typedef void QEMUPutKBDEventN(void *opaque, int* keycodes, int count);
21 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
22 typedef void QEMUPutGenericEvent(void* opaque, int type, int code, int value);
23
24 typedef struct QEMUPutMouseEntry {
25 QEMUPutMouseEvent *qemu_put_mouse_event;
26 void *qemu_put_mouse_event_opaque;
27 int qemu_put_mouse_event_absolute;
28 char *qemu_put_mouse_event_name;
29
30 /* used internally by qemu for handling mice */
31 struct QEMUPutMouseEntry *next;
32 } QEMUPutMouseEntry;
33
34 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
35 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
36 void *opaque, int absolute,
37 const char *name);
38 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
39
40 void kbd_put_keycode(int keycode);
41 void kbd_put_keycodes(int* keycodes, int count);
42 void kbd_generic_event(int type, int code, int value);
43 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
44 int kbd_mouse_is_absolute(void);
45
46 struct mouse_transform_info_s {
47 /* Touchscreen resolution */
48 int x;
49 int y;
50 /* Calibration values as used/generated by tslib */
51 int a[7];
52 };
53
54 void do_info_mice(void);
55 void do_mouse_set(int index);
56
57 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
58 constants) */
59 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
60 #define QEMU_KEY_BACKSPACE 0x007f
61 #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
62 #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
63 #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
64 #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
65 #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
66 #define QEMU_KEY_END QEMU_KEY_ESC1(4)
67 #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
68 #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
69 #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
70
71 #define QEMU_KEY_CTRL_UP 0xe400
72 #define QEMU_KEY_CTRL_DOWN 0xe401
73 #define QEMU_KEY_CTRL_LEFT 0xe402
74 #define QEMU_KEY_CTRL_RIGHT 0xe403
75 #define QEMU_KEY_CTRL_HOME 0xe404
76 #define QEMU_KEY_CTRL_END 0xe405
77 #define QEMU_KEY_CTRL_PAGEUP 0xe406
78 #define QEMU_KEY_CTRL_PAGEDOWN 0xe407
79
80 void kbd_put_keysym(int keysym);
81
82 /* consoles */
83
84 struct DisplayState {
85 uint8_t *data;
86 int linesize;
87 int depth;
88 int bgr; /* BGR color order instead of RGB. Only valid for depth == 32 */
89 int width;
90 int height;
91 void *opaque;
92 struct QEMUTimer *gui_timer;
93 uint64_t gui_timer_interval;
94 int idle; /* there is nothing to update (window invisible), set by vnc/sdl */
95
96 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
97 void (*dpy_resize)(struct DisplayState *s, int w, int h);
98 void (*dpy_refresh)(struct DisplayState *s);
99 void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y,
100 int dst_x, int dst_y, int w, int h);
101 void (*dpy_fill)(struct DisplayState *s, int x, int y,
102 int w, int h, uint32_t c);
103 void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
104 void (*mouse_set)(int x, int y, int on);
105 void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
106 uint8_t *image, uint8_t *mask);
107 };
108
dpy_update(DisplayState * s,int x,int y,int w,int h)109 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
110 {
111 s->dpy_update(s, x, y, w, h);
112 }
113
dpy_resize(DisplayState * s,int w,int h)114 static inline void dpy_resize(DisplayState *s, int w, int h)
115 {
116 s->dpy_resize(s, w, h);
117 }
118
dpy_cursor(DisplayState * s,int x,int y)119 static inline void dpy_cursor(DisplayState *s, int x, int y)
120 {
121 if (s->dpy_text_cursor)
122 s->dpy_text_cursor(s, x, y);
123 }
124
125 typedef unsigned long console_ch_t;
console_write_ch(console_ch_t * dest,uint32_t ch)126 static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
127 {
128 cpu_to_le32wu((uint32_t *) dest, ch);
129 }
130
131 typedef void (*vga_hw_update_ptr)(void *);
132 typedef void (*vga_hw_invalidate_ptr)(void *);
133 typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
134 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
135
136 TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
137 vga_hw_invalidate_ptr invalidate,
138 vga_hw_screen_dump_ptr screen_dump,
139 vga_hw_text_update_ptr text_update,
140 void *opaque);
141 void vga_hw_update(void);
142 void vga_hw_invalidate(void);
143 void vga_hw_screen_dump(const char *filename);
144 void vga_hw_text_update(console_ch_t *chardata);
145
146 int is_graphic_console(void);
147 CharDriverState *text_console_init(DisplayState *ds, const char *p);
148 void console_select(unsigned int index);
149 void console_color_init(DisplayState *ds);
150 void qemu_console_resize(QEMUConsole *console, int width, int height);
151
152 /* sdl.c */
153 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
154
155 /* cocoa.m */
156 void cocoa_display_init(DisplayState *ds, int full_screen);
157
158 /* vnc.c */
159 void vnc_display_init(DisplayState *ds);
160 void vnc_display_close(DisplayState *ds);
161 int vnc_display_open(DisplayState *ds, const char *display);
162 int vnc_display_password(DisplayState *ds, const char *password);
163 void do_info_vnc(void);
164
165 /* curses.c */
166 void curses_display_init(DisplayState *ds, int full_screen);
167
168 /* x_keymap.c */
169 extern uint8_t _translate_keycode(const int key);
170
171 /* FIXME: term_printf et al should probably go elsewhere so everything
172 does not need to include console.h */
173 /* monitor.c */
174 void monitor_init(CharDriverState *hd, int show_banner);
175 void term_puts(const char *str);
176 void term_vprintf(const char *fmt, va_list ap);
177 void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
178 void term_print_filename(const char *filename);
179 void term_flush(void);
180 void term_print_help(void);
181 void monitor_readline(const char *prompt, int is_password,
182 char *buf, int buf_size);
183
184 /* readline.c */
185 typedef void ReadLineFunc(void *opaque, const char *str);
186
187 extern int completion_index;
188 void add_completion(const char *str);
189 void readline_handle_byte(int ch);
190 void readline_find_completion(const char *cmdline);
191 const char *readline_get_history(unsigned int index);
192 void readline_start(const char *prompt, int is_password,
193 ReadLineFunc *readline_func, void *opaque);
194
195 #endif
196