xref: /qemu/include/ui/gtk.h (revision dfeb8679db358e1f8e0ee4dd84f903d71f000378)
1 #ifndef UI_GTK_H
2 #define UI_GTK_H
3 
4 #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
5 /* Work around an -Wstrict-prototypes warning in GTK headers */
6 #pragma GCC diagnostic push
7 #pragma GCC diagnostic ignored "-Wstrict-prototypes"
8 #endif
9 #include <gtk/gtk.h>
10 #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
11 #pragma GCC diagnostic pop
12 #endif
13 
14 #include <gdk/gdkkeysyms.h>
15 
16 #ifdef GDK_WINDOWING_X11
17 #include <gdk/gdkx.h>
18 #include <X11/XKBlib.h>
19 #endif
20 
21 #if defined(CONFIG_OPENGL)
22 #include "ui/egl-helpers.h"
23 #endif
24 
25 /* Compatibility define to let us build on both Gtk2 and Gtk3 */
26 #if GTK_CHECK_VERSION(3, 0, 0)
27 static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
28 {
29     *ww = gdk_window_get_width(w);
30     *wh = gdk_window_get_height(w);
31 }
32 #endif
33 
34 typedef struct GtkDisplayState GtkDisplayState;
35 
36 typedef struct VirtualGfxConsole {
37     GtkWidget *drawing_area;
38     DisplayChangeListener dcl;
39     DisplaySurface *ds;
40     pixman_image_t *convert;
41     cairo_surface_t *surface;
42     double scale_x;
43     double scale_y;
44 #if defined(CONFIG_OPENGL)
45     ConsoleGLState *gls;
46     EGLContext ectx;
47     EGLSurface esurface;
48     int glupdates;
49 #endif
50 } VirtualGfxConsole;
51 
52 #if defined(CONFIG_VTE)
53 typedef struct VirtualVteConsole {
54     GtkWidget *box;
55     GtkWidget *scrollbar;
56     GtkWidget *terminal;
57     CharDriverState *chr;
58 } VirtualVteConsole;
59 #endif
60 
61 typedef enum VirtualConsoleType {
62     GD_VC_GFX,
63     GD_VC_VTE,
64 } VirtualConsoleType;
65 
66 typedef struct VirtualConsole {
67     GtkDisplayState *s;
68     char *label;
69     GtkWidget *window;
70     GtkWidget *menu_item;
71     GtkWidget *tab_item;
72     GtkWidget *focus;
73     VirtualConsoleType type;
74     union {
75         VirtualGfxConsole gfx;
76 #if defined(CONFIG_VTE)
77         VirtualVteConsole vte;
78 #endif
79     };
80 } VirtualConsole;
81 
82 /* ui/gtk.c */
83 void gd_update_windowsize(VirtualConsole *vc);
84 
85 /* ui/gtk-egl.c */
86 void gd_egl_init(VirtualConsole *vc);
87 void gd_egl_draw(VirtualConsole *vc);
88 void gd_egl_update(DisplayChangeListener *dcl,
89                    int x, int y, int w, int h);
90 void gd_egl_refresh(DisplayChangeListener *dcl);
91 void gd_egl_switch(DisplayChangeListener *dcl,
92                    DisplaySurface *surface);
93 void gtk_egl_init(void);
94 
95 #endif /* UI_GTK_H */
96