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