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