xref: /openbmc/qemu/include/ui/gtk.h (revision 6c1ebe75)
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 
159 /* ui/gtk-egl.c */
160 void gd_egl_init(VirtualConsole *vc);
161 void gd_egl_draw(VirtualConsole *vc);
162 void gd_egl_update(DisplayChangeListener *dcl,
163                    int x, int y, int w, int h);
164 void gd_egl_refresh(DisplayChangeListener *dcl);
165 void gd_egl_switch(DisplayChangeListener *dcl,
166                    DisplaySurface *surface);
167 QEMUGLContext gd_egl_create_context(DisplayChangeListener *dcl,
168                                     QEMUGLParams *params);
169 void gd_egl_scanout_disable(DisplayChangeListener *dcl);
170 void gd_egl_scanout_texture(DisplayChangeListener *dcl,
171                             uint32_t backing_id,
172                             bool backing_y_0_top,
173                             uint32_t backing_width,
174                             uint32_t backing_height,
175                             uint32_t x, uint32_t y,
176                             uint32_t w, uint32_t h);
177 void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
178                            QemuDmaBuf *dmabuf);
179 void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
180                           QemuDmaBuf *dmabuf, bool have_hot,
181                           uint32_t hot_x, uint32_t hot_y);
182 void gd_egl_cursor_position(DisplayChangeListener *dcl,
183                             uint32_t pos_x, uint32_t pos_y);
184 void gd_egl_release_dmabuf(DisplayChangeListener *dcl,
185                            QemuDmaBuf *dmabuf);
186 void gd_egl_scanout_flush(DisplayChangeListener *dcl,
187                           uint32_t x, uint32_t y, uint32_t w, uint32_t h);
188 void gtk_egl_init(DisplayGLMode mode);
189 int gd_egl_make_current(DisplayChangeListener *dcl,
190                         QEMUGLContext ctx);
191 
192 /* ui/gtk-gl-area.c */
193 void gd_gl_area_init(VirtualConsole *vc);
194 void gd_gl_area_draw(VirtualConsole *vc);
195 void gd_gl_area_update(DisplayChangeListener *dcl,
196                        int x, int y, int w, int h);
197 void gd_gl_area_refresh(DisplayChangeListener *dcl);
198 void gd_gl_area_switch(DisplayChangeListener *dcl,
199                        DisplaySurface *surface);
200 QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
201                                         QEMUGLParams *params);
202 void gd_gl_area_destroy_context(DisplayChangeListener *dcl,
203                                 QEMUGLContext ctx);
204 void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
205                                QemuDmaBuf *dmabuf);
206 void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
207                                 uint32_t backing_id,
208                                 bool backing_y_0_top,
209                                 uint32_t backing_width,
210                                 uint32_t backing_height,
211                                 uint32_t x, uint32_t y,
212                                 uint32_t w, uint32_t h);
213 void gd_gl_area_scanout_disable(DisplayChangeListener *dcl);
214 void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
215                               uint32_t x, uint32_t y, uint32_t w, uint32_t h);
216 void gtk_gl_area_init(void);
217 int gd_gl_area_make_current(DisplayChangeListener *dcl,
218                             QEMUGLContext ctx);
219 
220 /* gtk-clipboard.c */
221 void gd_clipboard_init(GtkDisplayState *gd);
222 
223 #endif /* UI_GTK_H */
224