1 #ifndef UI_GTK_H 2 #define UI_GTK_H 3 4 /* Work around an -Wstrict-prototypes warning in GTK headers */ 5 #pragma GCC diagnostic push 6 #pragma GCC diagnostic ignored "-Wstrict-prototypes" 7 #include <gtk/gtk.h> 8 #pragma GCC diagnostic pop 9 10 #include <gdk/gdkkeysyms.h> 11 12 #ifdef GDK_WINDOWING_X11 13 #include <gdk/gdkx.h> 14 #include <X11/XKBlib.h> 15 #endif 16 17 #ifdef GDK_WINDOWING_WAYLAND 18 #include <gdk/gdkwayland.h> 19 #endif 20 21 #include "ui/clipboard.h" 22 #include "ui/console.h" 23 #include "ui/kbd-state.h" 24 #if defined(CONFIG_OPENGL) 25 #include "ui/egl-helpers.h" 26 #include "ui/egl-context.h" 27 #endif 28 #ifdef CONFIG_VTE 29 #include "qemu/fifo8.h" 30 #endif 31 32 #define MAX_VCS 10 33 34 typedef struct GtkDisplayState GtkDisplayState; 35 36 typedef struct VirtualGfxConsole { 37 GtkWidget *drawing_area; 38 DisplayGLCtx dgc; 39 DisplayChangeListener dcl; 40 QKbdState *kbd; 41 DisplaySurface *ds; 42 pixman_image_t *convert; 43 cairo_surface_t *surface; 44 double scale_x; 45 double scale_y; 46 #if defined(CONFIG_OPENGL) 47 QemuGLShader *gls; 48 EGLContext ectx; 49 EGLSurface esurface; 50 int glupdates; 51 int x, y, w, h; 52 egl_fb guest_fb; 53 egl_fb win_fb; 54 egl_fb cursor_fb; 55 int cursor_x; 56 int cursor_y; 57 bool y0_top; 58 bool scanout_mode; 59 bool has_dmabuf; 60 #endif 61 } VirtualGfxConsole; 62 63 #if defined(CONFIG_VTE) 64 typedef struct VirtualVteConsole { 65 GtkWidget *box; 66 GtkWidget *scrollbar; 67 GtkWidget *terminal; 68 Chardev *chr; 69 Fifo8 out_fifo; 70 bool echo; 71 } VirtualVteConsole; 72 #endif 73 74 typedef enum VirtualConsoleType { 75 GD_VC_GFX, 76 GD_VC_VTE, 77 } VirtualConsoleType; 78 79 typedef struct VirtualConsole { 80 GtkDisplayState *s; 81 char *label; 82 GtkWidget *window; 83 GtkWidget *menu_item; 84 GtkWidget *tab_item; 85 GtkWidget *focus; 86 VirtualConsoleType type; 87 union { 88 VirtualGfxConsole gfx; 89 #if defined(CONFIG_VTE) 90 VirtualVteConsole vte; 91 #endif 92 }; 93 } VirtualConsole; 94 95 struct GtkDisplayState { 96 GtkWidget *window; 97 98 GtkWidget *menu_bar; 99 100 GtkAccelGroup *accel_group; 101 102 GtkWidget *machine_menu_item; 103 GtkWidget *machine_menu; 104 GtkWidget *pause_item; 105 GtkWidget *reset_item; 106 GtkWidget *powerdown_item; 107 GtkWidget *quit_item; 108 109 GtkWidget *view_menu_item; 110 GtkWidget *view_menu; 111 GtkWidget *full_screen_item; 112 GtkWidget *copy_item; 113 GtkWidget *zoom_in_item; 114 GtkWidget *zoom_out_item; 115 GtkWidget *zoom_fixed_item; 116 GtkWidget *zoom_fit_item; 117 GtkWidget *grab_item; 118 GtkWidget *grab_on_hover_item; 119 120 int nb_vcs; 121 VirtualConsole vc[MAX_VCS]; 122 123 GtkWidget *show_tabs_item; 124 GtkWidget *untabify_item; 125 GtkWidget *show_menubar_item; 126 127 GtkWidget *vbox; 128 GtkWidget *notebook; 129 int button_mask; 130 gboolean last_set; 131 int last_x; 132 int last_y; 133 int grab_x_root; 134 int grab_y_root; 135 VirtualConsole *kbd_owner; 136 VirtualConsole *ptr_owner; 137 138 gboolean full_screen; 139 140 GdkCursor *null_cursor; 141 Notifier mouse_mode_notifier; 142 gboolean free_scale; 143 144 bool external_pause_update; 145 146 QemuClipboardPeer cbpeer; 147 uint32_t cbpending[QEMU_CLIPBOARD_SELECTION__COUNT]; 148 GtkClipboard *gtkcb[QEMU_CLIPBOARD_SELECTION__COUNT]; 149 bool cbowner[QEMU_CLIPBOARD_SELECTION__COUNT]; 150 151 DisplayOptions *opts; 152 }; 153 154 extern bool gtk_use_gl_area; 155 156 /* ui/gtk.c */ 157 void gd_update_windowsize(VirtualConsole *vc); 158 int gd_monitor_update_interval(GtkWidget *widget); 159 void gd_hw_gl_flushed(void *vc); 160 161 /* ui/gtk-egl.c */ 162 void gd_egl_init(VirtualConsole *vc); 163 void gd_egl_draw(VirtualConsole *vc); 164 void gd_egl_update(DisplayChangeListener *dcl, 165 int x, int y, int w, int h); 166 void gd_egl_refresh(DisplayChangeListener *dcl); 167 void gd_egl_switch(DisplayChangeListener *dcl, 168 DisplaySurface *surface); 169 QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc, 170 QEMUGLParams *params); 171 void gd_egl_scanout_disable(DisplayChangeListener *dcl); 172 void gd_egl_scanout_texture(DisplayChangeListener *dcl, 173 uint32_t backing_id, 174 bool backing_y_0_top, 175 uint32_t backing_width, 176 uint32_t backing_height, 177 uint32_t x, uint32_t y, 178 uint32_t w, uint32_t h); 179 void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl, 180 QemuDmaBuf *dmabuf); 181 void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl, 182 QemuDmaBuf *dmabuf, bool have_hot, 183 uint32_t hot_x, uint32_t hot_y); 184 void gd_egl_cursor_position(DisplayChangeListener *dcl, 185 uint32_t pos_x, uint32_t pos_y); 186 void gd_egl_flush(DisplayChangeListener *dcl, 187 uint32_t x, uint32_t y, uint32_t w, uint32_t h); 188 void gd_egl_scanout_flush(DisplayChangeListener *dcl, 189 uint32_t x, uint32_t y, uint32_t w, uint32_t h); 190 void gtk_egl_init(DisplayGLMode mode); 191 int gd_egl_make_current(DisplayGLCtx *dgc, 192 QEMUGLContext ctx); 193 194 /* ui/gtk-gl-area.c */ 195 void gd_gl_area_init(VirtualConsole *vc); 196 void gd_gl_area_draw(VirtualConsole *vc); 197 void gd_gl_area_update(DisplayChangeListener *dcl, 198 int x, int y, int w, int h); 199 void gd_gl_area_refresh(DisplayChangeListener *dcl); 200 void gd_gl_area_switch(DisplayChangeListener *dcl, 201 DisplaySurface *surface); 202 QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc, 203 QEMUGLParams *params); 204 void gd_gl_area_destroy_context(DisplayGLCtx *dgc, 205 QEMUGLContext ctx); 206 void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl, 207 QemuDmaBuf *dmabuf); 208 void gd_gl_area_scanout_texture(DisplayChangeListener *dcl, 209 uint32_t backing_id, 210 bool backing_y_0_top, 211 uint32_t backing_width, 212 uint32_t backing_height, 213 uint32_t x, uint32_t y, 214 uint32_t w, uint32_t h); 215 void gd_gl_area_scanout_disable(DisplayChangeListener *dcl); 216 void gd_gl_area_scanout_flush(DisplayChangeListener *dcl, 217 uint32_t x, uint32_t y, uint32_t w, uint32_t h); 218 void gtk_gl_area_init(void); 219 int gd_gl_area_make_current(DisplayGLCtx *dgc, 220 QEMUGLContext ctx); 221 222 /* gtk-clipboard.c */ 223 void gd_clipboard_init(GtkDisplayState *gd); 224 225 #endif /* UI_GTK_H */ 226