console.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. #ifndef CONSOLE_H
  2. #define CONSOLE_H
  3. #include "qemu-char.h"
  4. /* keyboard/mouse support */
  5. #define MOUSE_EVENT_LBUTTON 0x01
  6. #define MOUSE_EVENT_RBUTTON 0x02
  7. #define MOUSE_EVENT_MBUTTON 0x04
  8. /* in ms */
  9. #define GUI_REFRESH_INTERVAL 30
  10. typedef void QEMUPutKBDEvent(void *opaque, int keycode);
  11. typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
  12. typedef struct QEMUPutMouseEntry {
  13. QEMUPutMouseEvent *qemu_put_mouse_event;
  14. void *qemu_put_mouse_event_opaque;
  15. int qemu_put_mouse_event_absolute;
  16. char *qemu_put_mouse_event_name;
  17. /* used internally by qemu for handling mice */
  18. struct QEMUPutMouseEntry *next;
  19. } QEMUPutMouseEntry;
  20. void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
  21. QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
  22. void *opaque, int absolute,
  23. const char *name);
  24. void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
  25. void kbd_put_keycode(int keycode);
  26. void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
  27. int kbd_mouse_is_absolute(void);
  28. struct mouse_transform_info_s {
  29. /* Touchscreen resolution */
  30. int x;
  31. int y;
  32. /* Calibration values as used/generated by tslib */
  33. int a[7];
  34. };
  35. void do_info_mice(void);
  36. void do_mouse_set(int index);
  37. /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
  38. constants) */
  39. #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
  40. #define QEMU_KEY_BACKSPACE 0x007f
  41. #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
  42. #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
  43. #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
  44. #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
  45. #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
  46. #define QEMU_KEY_END QEMU_KEY_ESC1(4)
  47. #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
  48. #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
  49. #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
  50. #define QEMU_KEY_CTRL_UP 0xe400
  51. #define QEMU_KEY_CTRL_DOWN 0xe401
  52. #define QEMU_KEY_CTRL_LEFT 0xe402
  53. #define QEMU_KEY_CTRL_RIGHT 0xe403
  54. #define QEMU_KEY_CTRL_HOME 0xe404
  55. #define QEMU_KEY_CTRL_END 0xe405
  56. #define QEMU_KEY_CTRL_PAGEUP 0xe406
  57. #define QEMU_KEY_CTRL_PAGEDOWN 0xe407
  58. void kbd_put_keysym(int keysym);
  59. /* consoles */
  60. #define QEMU_BIG_ENDIAN_FLAG 0x01
  61. #define QEMU_ALLOCATED_FLAG 0x02
  62. struct PixelFormat {
  63. uint8_t bits_per_pixel;
  64. uint8_t bytes_per_pixel;
  65. uint8_t depth; /* color depth in bits */
  66. uint32_t rmask, gmask, bmask, amask;
  67. uint8_t rshift, gshift, bshift, ashift;
  68. uint8_t rmax, gmax, bmax, amax;
  69. uint8_t rbits, gbits, bbits, abits;
  70. };
  71. struct DisplaySurface {
  72. uint8_t flags;
  73. int width;
  74. int height;
  75. int linesize; /* bytes per line */
  76. uint8_t *data;
  77. struct PixelFormat pf;
  78. };
  79. struct DisplayChangeListener {
  80. int idle;
  81. uint64_t gui_timer_interval;
  82. void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
  83. void (*dpy_resize)(struct DisplayState *s);
  84. void (*dpy_setdata)(struct DisplayState *s);
  85. void (*dpy_refresh)(struct DisplayState *s);
  86. void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y,
  87. int dst_x, int dst_y, int w, int h);
  88. void (*dpy_fill)(struct DisplayState *s, int x, int y,
  89. int w, int h, uint32_t c);
  90. void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
  91. struct DisplayChangeListener *next;
  92. };
  93. struct DisplayState {
  94. struct DisplaySurface *surface;
  95. void *opaque;
  96. struct QEMUTimer *gui_timer;
  97. struct DisplayChangeListener* listeners;
  98. void (*mouse_set)(int x, int y, int on);
  99. void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
  100. uint8_t *image, uint8_t *mask);
  101. struct DisplayState *next;
  102. };
  103. void register_displaystate(DisplayState *ds);
  104. DisplayState *get_displaystate(void);
  105. DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int linesize);
  106. DisplaySurface* qemu_resize_displaysurface(DisplaySurface *surface,
  107. int width, int height, int bpp, int linesize);
  108. DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
  109. int linesize, uint8_t *data);
  110. void qemu_free_displaysurface(DisplaySurface *surface);
  111. PixelFormat qemu_different_endianness_pixelformat(int bpp);
  112. PixelFormat qemu_default_pixelformat(int bpp);
  113. static inline int is_buffer_shared(DisplaySurface *surface)
  114. {
  115. return (!(surface->flags & QEMU_ALLOCATED_FLAG));
  116. }
  117. static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
  118. {
  119. dcl->next = ds->listeners;
  120. ds->listeners = dcl;
  121. }
  122. static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
  123. {
  124. struct DisplayChangeListener *dcl = s->listeners;
  125. while (dcl != NULL) {
  126. dcl->dpy_update(s, x, y, w, h);
  127. dcl = dcl->next;
  128. }
  129. }
  130. static inline void dpy_resize(DisplayState *s)
  131. {
  132. struct DisplayChangeListener *dcl = s->listeners;
  133. while (dcl != NULL) {
  134. dcl->dpy_resize(s);
  135. dcl = dcl->next;
  136. }
  137. }
  138. static inline void dpy_setdata(DisplayState *s)
  139. {
  140. struct DisplayChangeListener *dcl = s->listeners;
  141. while (dcl != NULL) {
  142. if (dcl->dpy_setdata) dcl->dpy_setdata(s);
  143. dcl = dcl->next;
  144. }
  145. }
  146. static inline void dpy_refresh(DisplayState *s)
  147. {
  148. struct DisplayChangeListener *dcl = s->listeners;
  149. while (dcl != NULL) {
  150. if (dcl->dpy_refresh) dcl->dpy_refresh(s);
  151. dcl = dcl->next;
  152. }
  153. }
  154. static inline void dpy_copy(struct DisplayState *s, int src_x, int src_y,
  155. int dst_x, int dst_y, int w, int h) {
  156. struct DisplayChangeListener *dcl = s->listeners;
  157. while (dcl != NULL) {
  158. if (dcl->dpy_copy)
  159. dcl->dpy_copy(s, src_x, src_y, dst_x, dst_y, w, h);
  160. else /* TODO */
  161. dcl->dpy_update(s, dst_x, dst_y, w, h);
  162. dcl = dcl->next;
  163. }
  164. }
  165. static inline void dpy_fill(struct DisplayState *s, int x, int y,
  166. int w, int h, uint32_t c) {
  167. struct DisplayChangeListener *dcl = s->listeners;
  168. while (dcl != NULL) {
  169. if (dcl->dpy_fill) dcl->dpy_fill(s, x, y, w, h, c);
  170. dcl = dcl->next;
  171. }
  172. }
  173. static inline void dpy_cursor(struct DisplayState *s, int x, int y) {
  174. struct DisplayChangeListener *dcl = s->listeners;
  175. while (dcl != NULL) {
  176. if (dcl->dpy_text_cursor) dcl->dpy_text_cursor(s, x, y);
  177. dcl = dcl->next;
  178. }
  179. }
  180. static inline int ds_get_linesize(DisplayState *ds)
  181. {
  182. return ds->surface->linesize;
  183. }
  184. static inline uint8_t* ds_get_data(DisplayState *ds)
  185. {
  186. return ds->surface->data;
  187. }
  188. static inline int ds_get_width(DisplayState *ds)
  189. {
  190. return ds->surface->width;
  191. }
  192. static inline int ds_get_height(DisplayState *ds)
  193. {
  194. return ds->surface->height;
  195. }
  196. static inline int ds_get_bits_per_pixel(DisplayState *ds)
  197. {
  198. return ds->surface->pf.bits_per_pixel;
  199. }
  200. static inline int ds_get_bytes_per_pixel(DisplayState *ds)
  201. {
  202. return ds->surface->pf.bytes_per_pixel;
  203. }
  204. typedef unsigned long console_ch_t;
  205. static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
  206. {
  207. cpu_to_le32wu((uint32_t *) dest, ch);
  208. }
  209. typedef void (*vga_hw_update_ptr)(void *);
  210. typedef void (*vga_hw_invalidate_ptr)(void *);
  211. typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
  212. typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
  213. DisplayState *graphic_console_init(vga_hw_update_ptr update,
  214. vga_hw_invalidate_ptr invalidate,
  215. vga_hw_screen_dump_ptr screen_dump,
  216. vga_hw_text_update_ptr text_update,
  217. void *opaque);
  218. void vga_hw_update(void);
  219. void vga_hw_invalidate(void);
  220. void vga_hw_screen_dump(const char *filename);
  221. void vga_hw_text_update(console_ch_t *chardata);
  222. int is_graphic_console(void);
  223. int is_fixedsize_console(void);
  224. CharDriverState *text_console_init(const char *p);
  225. void text_consoles_set_display(DisplayState *ds);
  226. void console_select(unsigned int index);
  227. void console_color_init(DisplayState *ds);
  228. void qemu_console_resize(DisplayState *ds, int width, int height);
  229. void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
  230. int dst_x, int dst_y, int w, int h);
  231. /* sdl.c */
  232. void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
  233. /* cocoa.m */
  234. void cocoa_display_init(DisplayState *ds, int full_screen);
  235. /* vnc.c */
  236. void vnc_display_init(DisplayState *ds);
  237. void vnc_display_close(DisplayState *ds);
  238. int vnc_display_open(DisplayState *ds, const char *display);
  239. int vnc_display_password(DisplayState *ds, const char *password);
  240. void do_info_vnc(void);
  241. /* curses.c */
  242. void curses_display_init(DisplayState *ds, int full_screen);
  243. /* FIXME: term_printf et al should probably go elsewhere so everything
  244. does not need to include console.h */
  245. /* monitor.c */
  246. void monitor_init(CharDriverState *hd, int show_banner);
  247. void term_puts(const char *str);
  248. void term_vprintf(const char *fmt, va_list ap);
  249. void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
  250. void term_print_filename(const char *filename);
  251. void term_flush(void);
  252. void term_print_help(void);
  253. void monitor_suspend(void);
  254. void monitor_resume(void);
  255. int monitor_read_bdrv_key(BlockDriverState *bs);
  256. /* readline.c */
  257. typedef void ReadLineFunc(void *opaque, const char *str);
  258. extern int completion_index;
  259. void add_completion(const char *str);
  260. void readline_handle_byte(int ch);
  261. void readline_find_completion(const char *cmdline);
  262. const char *readline_get_history(unsigned int index);
  263. void readline_start(const char *prompt, int is_password,
  264. ReadLineFunc *readline_func, void *opaque);
  265. #endif