00001 #ifndef CONSOLE_H
00002 #define CONSOLE_H
00003
00004 #include "qemu-char.h"
00005
00006
00007
00008 #define MOUSE_EVENT_LBUTTON 0x01
00009 #define MOUSE_EVENT_RBUTTON 0x02
00010 #define MOUSE_EVENT_MBUTTON 0x04
00011
00012
00013 #define GUI_REFRESH_INTERVAL 30
00014
00015 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
00016 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
00017
00018 typedef struct QEMUPutMouseEntry {
00019 QEMUPutMouseEvent *qemu_put_mouse_event;
00020 void *qemu_put_mouse_event_opaque;
00021 int qemu_put_mouse_event_absolute;
00022 char *qemu_put_mouse_event_name;
00023
00024
00025 struct QEMUPutMouseEntry *next;
00026 } QEMUPutMouseEntry;
00027
00028 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
00029 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
00030 void *opaque, int absolute,
00031 const char *name);
00032 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
00033
00034 void kbd_put_keycode(int keycode);
00035 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
00036 int kbd_mouse_is_absolute(void);
00037
00038 struct mouse_transform_info_s {
00039
00040 int x;
00041 int y;
00042
00043 int a[7];
00044 };
00045
00046 void do_info_mice(void);
00047 void do_mouse_set(int index);
00048
00049
00050
00051 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
00052 #define QEMU_KEY_BACKSPACE 0x007f
00053 #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
00054 #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
00055 #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
00056 #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
00057 #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
00058 #define QEMU_KEY_END QEMU_KEY_ESC1(4)
00059 #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
00060 #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
00061 #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
00062
00063 #define QEMU_KEY_CTRL_UP 0xe400
00064 #define QEMU_KEY_CTRL_DOWN 0xe401
00065 #define QEMU_KEY_CTRL_LEFT 0xe402
00066 #define QEMU_KEY_CTRL_RIGHT 0xe403
00067 #define QEMU_KEY_CTRL_HOME 0xe404
00068 #define QEMU_KEY_CTRL_END 0xe405
00069 #define QEMU_KEY_CTRL_PAGEUP 0xe406
00070 #define QEMU_KEY_CTRL_PAGEDOWN 0xe407
00071
00072 void kbd_put_keysym(int keysym);
00073
00074
00075
00076 #define QEMU_BIG_ENDIAN_FLAG 0x01
00077 #define QEMU_ALLOCATED_FLAG 0x02
00078
00079 struct PixelFormat {
00080 uint8_t bits_per_pixel;
00081 uint8_t bytes_per_pixel;
00082 uint8_t depth;
00083 uint32_t rmask, gmask, bmask, amask;
00084 uint8_t rshift, gshift, bshift, ashift;
00085 uint8_t rmax, gmax, bmax, amax;
00086 uint8_t rbits, gbits, bbits, abits;
00087 };
00088
00089 struct DisplaySurface {
00090 uint8_t flags;
00091 int width;
00092 int height;
00093 int linesize;
00094 uint8_t *data;
00095
00096 struct PixelFormat pf;
00097 };
00098
00099 struct DisplayChangeListener {
00100 int idle;
00101 uint64_t gui_timer_interval;
00102
00103 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
00104 void (*dpy_resize)(struct DisplayState *s);
00105 void (*dpy_setdata)(struct DisplayState *s);
00106 void (*dpy_refresh)(struct DisplayState *s);
00107 void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y,
00108 int dst_x, int dst_y, int w, int h);
00109 void (*dpy_fill)(struct DisplayState *s, int x, int y,
00110 int w, int h, uint32_t c);
00111 void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
00112
00113 struct DisplayChangeListener *next;
00114 };
00115
00116 struct DisplayState {
00117 struct DisplaySurface *surface;
00118 void *opaque;
00119 struct QEMUTimer *gui_timer;
00120
00121 struct DisplayChangeListener* listeners;
00122
00123 void (*mouse_set)(int x, int y, int on);
00124 void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
00125 uint8_t *image, uint8_t *mask);
00126
00127 struct DisplayState *next;
00128 };
00129
00130 void register_displaystate(DisplayState *ds);
00131 DisplayState *get_displaystate(void);
00132 DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int linesize);
00133 DisplaySurface* qemu_resize_displaysurface(DisplaySurface *surface,
00134 int width, int height, int bpp, int linesize);
00135 DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
00136 int linesize, uint8_t *data);
00137 void qemu_free_displaysurface(DisplaySurface *surface);
00138 PixelFormat qemu_different_endianness_pixelformat(int bpp);
00139 PixelFormat qemu_default_pixelformat(int bpp);
00140
00141 static inline int is_buffer_shared(DisplaySurface *surface)
00142 {
00143 return (!(surface->flags & QEMU_ALLOCATED_FLAG));
00144 }
00145
00146 static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
00147 {
00148 dcl->next = ds->listeners;
00149 ds->listeners = dcl;
00150 }
00151
00152 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
00153 {
00154 struct DisplayChangeListener *dcl = s->listeners;
00155 while (dcl != NULL) {
00156 dcl->dpy_update(s, x, y, w, h);
00157 dcl = dcl->next;
00158 }
00159 }
00160
00161 static inline void dpy_resize(DisplayState *s)
00162 {
00163 struct DisplayChangeListener *dcl = s->listeners;
00164 while (dcl != NULL) {
00165 dcl->dpy_resize(s);
00166 dcl = dcl->next;
00167 }
00168 }
00169
00170 static inline void dpy_setdata(DisplayState *s)
00171 {
00172 struct DisplayChangeListener *dcl = s->listeners;
00173 while (dcl != NULL) {
00174 if (dcl->dpy_setdata) dcl->dpy_setdata(s);
00175 dcl = dcl->next;
00176 }
00177 }
00178
00179 static inline void dpy_refresh(DisplayState *s)
00180 {
00181 struct DisplayChangeListener *dcl = s->listeners;
00182 while (dcl != NULL) {
00183 if (dcl->dpy_refresh) dcl->dpy_refresh(s);
00184 dcl = dcl->next;
00185 }
00186 }
00187
00188 static inline void dpy_copy(struct DisplayState *s, int src_x, int src_y,
00189 int dst_x, int dst_y, int w, int h) {
00190 struct DisplayChangeListener *dcl = s->listeners;
00191 while (dcl != NULL) {
00192 if (dcl->dpy_copy)
00193 dcl->dpy_copy(s, src_x, src_y, dst_x, dst_y, w, h);
00194 else
00195 dcl->dpy_update(s, dst_x, dst_y, w, h);
00196 dcl = dcl->next;
00197 }
00198 }
00199
00200 static inline void dpy_fill(struct DisplayState *s, int x, int y,
00201 int w, int h, uint32_t c) {
00202 struct DisplayChangeListener *dcl = s->listeners;
00203 while (dcl != NULL) {
00204 if (dcl->dpy_fill) dcl->dpy_fill(s, x, y, w, h, c);
00205 dcl = dcl->next;
00206 }
00207 }
00208
00209 static inline void dpy_cursor(struct DisplayState *s, int x, int y) {
00210 struct DisplayChangeListener *dcl = s->listeners;
00211 while (dcl != NULL) {
00212 if (dcl->dpy_text_cursor) dcl->dpy_text_cursor(s, x, y);
00213 dcl = dcl->next;
00214 }
00215 }
00216
00217 static inline int ds_get_linesize(DisplayState *ds)
00218 {
00219 return ds->surface->linesize;
00220 }
00221
00222 static inline uint8_t* ds_get_data(DisplayState *ds)
00223 {
00224 return ds->surface->data;
00225 }
00226
00227 static inline int ds_get_width(DisplayState *ds)
00228 {
00229 return ds->surface->width;
00230 }
00231
00232 static inline int ds_get_height(DisplayState *ds)
00233 {
00234 return ds->surface->height;
00235 }
00236
00237 static inline int ds_get_bits_per_pixel(DisplayState *ds)
00238 {
00239 return ds->surface->pf.bits_per_pixel;
00240 }
00241
00242 static inline int ds_get_bytes_per_pixel(DisplayState *ds)
00243 {
00244 return ds->surface->pf.bytes_per_pixel;
00245 }
00246
00247 typedef unsigned long console_ch_t;
00248 static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
00249 {
00250 cpu_to_le32wu((uint32_t *) dest, ch);
00251 }
00252
00253 typedef void (*vga_hw_update_ptr)(void *);
00254 typedef void (*vga_hw_invalidate_ptr)(void *);
00255 typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
00256 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
00257
00258 DisplayState *graphic_console_init(vga_hw_update_ptr update,
00259 vga_hw_invalidate_ptr invalidate,
00260 vga_hw_screen_dump_ptr screen_dump,
00261 vga_hw_text_update_ptr text_update,
00262 void *opaque);
00263
00264 void vga_hw_update(void);
00265 void vga_hw_invalidate(void);
00266 void vga_hw_screen_dump(const char *filename);
00267 void vga_hw_text_update(console_ch_t *chardata);
00268
00269 int is_graphic_console(void);
00270 int is_fixedsize_console(void);
00271 CharDriverState *text_console_init(const char *p);
00272 void text_consoles_set_display(DisplayState *ds);
00273 void console_select(unsigned int index);
00274 void console_color_init(DisplayState *ds);
00275 void qemu_console_resize(DisplayState *ds, int width, int height);
00276 void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
00277 int dst_x, int dst_y, int w, int h);
00278
00279
00280 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
00281
00282
00283 void cocoa_display_init(DisplayState *ds, int full_screen);
00284
00285
00286 void vnc_display_init(DisplayState *ds);
00287 void vnc_display_close(DisplayState *ds);
00288 int vnc_display_open(DisplayState *ds, const char *display);
00289 int vnc_display_password(DisplayState *ds, const char *password);
00290 void do_info_vnc(void);
00291
00292
00293 void curses_display_init(DisplayState *ds, int full_screen);
00294
00295
00296
00297
00298 void monitor_init(CharDriverState *hd, int show_banner);
00299 void term_puts(const char *str);
00300 void term_vprintf(const char *fmt, va_list ap);
00301 void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
00302 void term_print_filename(const char *filename);
00303 void term_flush(void);
00304 void term_print_help(void);
00305 void monitor_suspend(void);
00306 void monitor_resume(void);
00307 int monitor_read_bdrv_key(BlockDriverState *bs);
00308
00309
00310 typedef void ReadLineFunc(void *opaque, const char *str);
00311
00312 extern int completion_index;
00313 void add_completion(const char *str);
00314 void readline_handle_byte(int ch);
00315 void readline_find_completion(const char *cmdline);
00316 const char *readline_get_history(unsigned int index);
00317 void readline_start(const char *prompt, int is_password,
00318 ReadLineFunc *readline_func, void *opaque);
00319
00320 #endif