]>
Commit | Line | Data |
---|---|---|
a4ccabcf AL |
1 | /* |
2 | * GTK UI | |
3 | * | |
4 | * Copyright IBM, Corp. 2012 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <aliguori@us.ibm.com> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
10 | * See the COPYING file in the top-level directory. | |
11 | * | |
12 | * Portions from gtk-vnc: | |
13 | * | |
14 | * GTK VNC Widget | |
15 | * | |
16 | * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws> | |
17 | * Copyright (C) 2009-2010 Daniel P. Berrange <dan@berrange.com> | |
18 | * | |
19 | * This library is free software; you can redistribute it and/or | |
20 | * modify it under the terms of the GNU Lesser General Public | |
21 | * License as published by the Free Software Foundation; either | |
22 | * version 2.0 of the License, or (at your option) any later version. | |
23 | * | |
24 | * This library is distributed in the hope that it will be useful, | |
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 | * Lesser General Public License for more details. | |
28 | * | |
29 | * You should have received a copy of the GNU Lesser General Public | |
30 | * License along with this library; if not, write to the Free Software | |
31 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
32 | */ | |
33 | ||
834574ea AL |
34 | #define GETTEXT_PACKAGE "qemu" |
35 | #define LOCALEDIR "po" | |
36 | ||
e16f4c87 | 37 | #include "qemu/osdep.h" |
c95e3080 | 38 | #include "qemu-common.h" |
f348b6d1 | 39 | #include "qemu/cutils.h" |
c95e3080 | 40 | |
dc7ff344 GH |
41 | #include "ui/console.h" |
42 | #include "ui/gtk.h" | |
c95e3080 | 43 | |
834574ea | 44 | #include <glib/gi18n.h> |
3f58eade | 45 | #include <locale.h> |
bbbf9bfb | 46 | #if defined(CONFIG_VTE) |
a4ccabcf | 47 | #include <vte/vte.h> |
bbbf9bfb | 48 | #endif |
a4ccabcf AL |
49 | #include <math.h> |
50 | ||
ef0dd982 | 51 | #include "trace.h" |
af98ba92 | 52 | #include "ui/input.h" |
a4ccabcf AL |
53 | #include "sysemu/sysemu.h" |
54 | #include "qmp-commands.h" | |
55 | #include "x_keymap.h" | |
56 | #include "keymaps.h" | |
dccfcd0e | 57 | #include "sysemu/char.h" |
6a24ced5 | 58 | #include "qom/object.h" |
a4ccabcf | 59 | |
d861def3 | 60 | #define MAX_VCS 10 |
82fc1809 GH |
61 | #define VC_WINDOW_X_MIN 320 |
62 | #define VC_WINDOW_Y_MIN 240 | |
63 | #define VC_TERM_X_MIN 80 | |
64 | #define VC_TERM_Y_MIN 25 | |
65 | #define VC_SCALE_MIN 0.25 | |
66 | #define VC_SCALE_STEP 0.25 | |
d861def3 | 67 | |
bbbf9bfb SW |
68 | #if !defined(CONFIG_VTE) |
69 | # define VTE_CHECK_VERSION(a, b, c) 0 | |
70 | #endif | |
cba68834 | 71 | |
6fa27697 GH |
72 | #if defined(CONFIG_VTE) && !GTK_CHECK_VERSION(3, 0, 0) |
73 | /* | |
74 | * The gtk2 vte terminal widget seriously messes up the window resize | |
75 | * for some reason. You basically can't make the qemu window smaller | |
76 | * any more because the toplevel window geoemtry hints are overridden. | |
77 | * | |
78 | * Workaround that by hiding all vte widgets, except the one in the | |
79 | * current tab. | |
80 | * | |
81 | * Luckily everything works smooth in gtk3. | |
82 | */ | |
83 | # define VTE_RESIZE_HACK 1 | |
84 | #endif | |
85 | ||
ef6413a2 DB |
86 | #if !GTK_CHECK_VERSION(2, 20, 0) |
87 | #define gtk_widget_get_realized(widget) GTK_WIDGET_REALIZED(widget) | |
88 | #endif | |
89 | ||
0a337ed0 GH |
90 | #ifndef GDK_IS_X11_DISPLAY |
91 | #define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy) | |
92 | #endif | |
93 | #ifndef GDK_IS_WIN32_DISPLAY | |
94 | #define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy) | |
95 | #endif | |
96 | ||
204af15b | 97 | #if !GTK_CHECK_VERSION(2, 22, 0) |
bc0477c7 DB |
98 | #define GDK_KEY_0 GDK_0 |
99 | #define GDK_KEY_1 GDK_1 | |
100 | #define GDK_KEY_2 GDK_2 | |
101 | #define GDK_KEY_f GDK_f | |
102 | #define GDK_KEY_g GDK_g | |
db1da1f2 | 103 | #define GDK_KEY_q GDK_q |
bc0477c7 DB |
104 | #define GDK_KEY_plus GDK_plus |
105 | #define GDK_KEY_minus GDK_minus | |
dc520171 | 106 | #define GDK_KEY_Pause GDK_Pause |
204af15b | 107 | #define GDK_KEY_Delete GDK_Delete |
bc0477c7 | 108 | #endif |
ef6413a2 | 109 | |
c8f3f17c DB |
110 | /* Some older mingw versions lack this constant or have |
111 | * it conditionally defined */ | |
112 | #ifdef _WIN32 | |
113 | # ifndef MAPVK_VK_TO_VSC | |
114 | # define MAPVK_VK_TO_VSC 0 | |
115 | # endif | |
116 | #endif | |
117 | ||
118 | ||
b1e749c0 | 119 | #define HOTKEY_MODIFIERS (GDK_CONTROL_MASK | GDK_MOD1_MASK) |
b1e749c0 | 120 | |
6db253ca JK |
121 | static const int modifier_keycode[] = { |
122 | /* shift, control, alt keys, meta keys, both left & right */ | |
123 | 0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xdb, 0xdd, | |
124 | }; | |
125 | ||
e3500d1f | 126 | struct GtkDisplayState { |
a4ccabcf AL |
127 | GtkWidget *window; |
128 | ||
129 | GtkWidget *menu_bar; | |
130 | ||
73d4dc71 AL |
131 | GtkAccelGroup *accel_group; |
132 | ||
30e8f22b JK |
133 | GtkWidget *machine_menu_item; |
134 | GtkWidget *machine_menu; | |
135 | GtkWidget *pause_item; | |
136 | GtkWidget *reset_item; | |
137 | GtkWidget *powerdown_item; | |
a4ccabcf AL |
138 | GtkWidget *quit_item; |
139 | ||
140 | GtkWidget *view_menu_item; | |
141 | GtkWidget *view_menu; | |
c6158483 | 142 | GtkWidget *full_screen_item; |
44b31e0b | 143 | GtkWidget *copy_item; |
c6158483 AL |
144 | GtkWidget *zoom_in_item; |
145 | GtkWidget *zoom_out_item; | |
146 | GtkWidget *zoom_fixed_item; | |
147 | GtkWidget *zoom_fit_item; | |
5104a1f6 AL |
148 | GtkWidget *grab_item; |
149 | GtkWidget *grab_on_hover_item; | |
a4ccabcf | 150 | |
d861def3 AL |
151 | int nb_vcs; |
152 | VirtualConsole vc[MAX_VCS]; | |
153 | ||
a4ccabcf | 154 | GtkWidget *show_tabs_item; |
cdeb7090 | 155 | GtkWidget *untabify_item; |
a4ccabcf AL |
156 | |
157 | GtkWidget *vbox; | |
158 | GtkWidget *notebook; | |
a4ccabcf | 159 | int button_mask; |
e61031cd | 160 | gboolean last_set; |
a4ccabcf AL |
161 | int last_x; |
162 | int last_y; | |
ecce1929 TI |
163 | int grab_x_root; |
164 | int grab_y_root; | |
4c638e2e GH |
165 | VirtualConsole *kbd_owner; |
166 | VirtualConsole *ptr_owner; | |
a4ccabcf | 167 | |
c6158483 | 168 | gboolean full_screen; |
a4ccabcf AL |
169 | |
170 | GdkCursor *null_cursor; | |
171 | Notifier mouse_mode_notifier; | |
c6158483 | 172 | gboolean free_scale; |
30e8f22b JK |
173 | |
174 | bool external_pause_update; | |
6db253ca JK |
175 | |
176 | bool modifier_pressed[ARRAY_SIZE(modifier_keycode)]; | |
3158a348 | 177 | bool has_evdev; |
1a01716a | 178 | bool ignore_keys; |
e3500d1f | 179 | }; |
a4ccabcf | 180 | |
d531deef | 181 | static void gd_grab_pointer(VirtualConsole *vc, const char *reason); |
2884cf5b | 182 | static void gd_ungrab_pointer(GtkDisplayState *s); |
d531deef | 183 | static void gd_grab_keyboard(VirtualConsole *vc, const char *reason); |
aa4f4058 | 184 | static void gd_ungrab_keyboard(GtkDisplayState *s); |
2884cf5b | 185 | |
a4ccabcf AL |
186 | /** Utility Functions **/ |
187 | ||
271a25c0 GH |
188 | static VirtualConsole *gd_vc_find_by_menu(GtkDisplayState *s) |
189 | { | |
190 | VirtualConsole *vc; | |
191 | gint i; | |
192 | ||
193 | for (i = 0; i < s->nb_vcs; i++) { | |
194 | vc = &s->vc[i]; | |
195 | if (gtk_check_menu_item_get_active | |
196 | (GTK_CHECK_MENU_ITEM(vc->menu_item))) { | |
197 | return vc; | |
198 | } | |
199 | } | |
200 | return NULL; | |
201 | } | |
202 | ||
203 | static VirtualConsole *gd_vc_find_by_page(GtkDisplayState *s, gint page) | |
204 | { | |
205 | VirtualConsole *vc; | |
206 | gint i, p; | |
207 | ||
208 | for (i = 0; i < s->nb_vcs; i++) { | |
209 | vc = &s->vc[i]; | |
210 | p = gtk_notebook_page_num(GTK_NOTEBOOK(s->notebook), vc->tab_item); | |
211 | if (p == page) { | |
212 | return vc; | |
213 | } | |
214 | } | |
215 | return NULL; | |
216 | } | |
217 | ||
e3500d1f GH |
218 | static VirtualConsole *gd_vc_find_current(GtkDisplayState *s) |
219 | { | |
220 | gint page; | |
221 | ||
222 | page = gtk_notebook_get_current_page(GTK_NOTEBOOK(s->notebook)); | |
223 | return gd_vc_find_by_page(s, page); | |
224 | } | |
225 | ||
5104a1f6 AL |
226 | static bool gd_is_grab_active(GtkDisplayState *s) |
227 | { | |
228 | return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->grab_item)); | |
229 | } | |
230 | ||
231 | static bool gd_grab_on_hover(GtkDisplayState *s) | |
232 | { | |
233 | return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->grab_on_hover_item)); | |
234 | } | |
235 | ||
e3500d1f | 236 | static void gd_update_cursor(VirtualConsole *vc) |
a4ccabcf | 237 | { |
e3500d1f | 238 | GtkDisplayState *s = vc->s; |
a4ccabcf | 239 | GdkWindow *window; |
a4ccabcf | 240 | |
f8c223f6 GH |
241 | if (vc->type != GD_VC_GFX || |
242 | !qemu_console_is_graphic(vc->gfx.dcl.con)) { | |
e3500d1f GH |
243 | return; |
244 | } | |
a4ccabcf | 245 | |
4cdfc935 HP |
246 | if (!gtk_widget_get_realized(vc->gfx.drawing_area)) { |
247 | return; | |
248 | } | |
249 | ||
e3500d1f | 250 | window = gtk_widget_get_window(GTK_WIDGET(vc->gfx.drawing_area)); |
2884cf5b | 251 | if (s->full_screen || qemu_input_is_absolute() || s->ptr_owner == vc) { |
a4ccabcf AL |
252 | gdk_window_set_cursor(window, s->null_cursor); |
253 | } else { | |
254 | gdk_window_set_cursor(window, NULL); | |
255 | } | |
256 | } | |
257 | ||
258 | static void gd_update_caption(GtkDisplayState *s) | |
259 | { | |
260 | const char *status = ""; | |
4eeaa3a8 | 261 | gchar *prefix; |
a4ccabcf | 262 | gchar *title; |
5104a1f6 | 263 | const char *grab = ""; |
30e8f22b | 264 | bool is_paused = !runstate_is_running(); |
4eeaa3a8 GH |
265 | int i; |
266 | ||
267 | if (qemu_name) { | |
268 | prefix = g_strdup_printf("QEMU (%s)", qemu_name); | |
269 | } else { | |
270 | prefix = g_strdup_printf("QEMU"); | |
271 | } | |
5104a1f6 | 272 | |
4eeaa3a8 GH |
273 | if (s->ptr_owner != NULL && |
274 | s->ptr_owner->window == NULL) { | |
d8da9ee8 | 275 | grab = _(" - Press Ctrl+Alt+G to release grab"); |
5104a1f6 | 276 | } |
a4ccabcf | 277 | |
30e8f22b | 278 | if (is_paused) { |
d8da9ee8 | 279 | status = _(" [Paused]"); |
a4ccabcf | 280 | } |
30e8f22b JK |
281 | s->external_pause_update = true; |
282 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->pause_item), | |
283 | is_paused); | |
284 | s->external_pause_update = false; | |
a4ccabcf | 285 | |
4eeaa3a8 | 286 | title = g_strdup_printf("%s%s%s", prefix, status, grab); |
a4ccabcf | 287 | gtk_window_set_title(GTK_WINDOW(s->window), title); |
a4ccabcf | 288 | g_free(title); |
4eeaa3a8 GH |
289 | |
290 | for (i = 0; i < s->nb_vcs; i++) { | |
291 | VirtualConsole *vc = &s->vc[i]; | |
292 | ||
293 | if (!vc->window) { | |
294 | continue; | |
295 | } | |
296 | title = g_strdup_printf("%s: %s%s%s", prefix, vc->label, | |
297 | vc == s->kbd_owner ? " +kbd" : "", | |
298 | vc == s->ptr_owner ? " +ptr" : ""); | |
299 | gtk_window_set_title(GTK_WINDOW(vc->window), title); | |
300 | g_free(title); | |
301 | } | |
302 | ||
303 | g_free(prefix); | |
a4ccabcf AL |
304 | } |
305 | ||
82fc1809 | 306 | static void gd_update_geometry_hints(VirtualConsole *vc) |
9d9801cf | 307 | { |
e3500d1f | 308 | GtkDisplayState *s = vc->s; |
82fc1809 GH |
309 | GdkWindowHints mask = 0; |
310 | GdkGeometry geo = {}; | |
311 | GtkWidget *geo_widget = NULL; | |
312 | GtkWindow *geo_window; | |
e3500d1f | 313 | |
82fc1809 | 314 | if (vc->type == GD_VC_GFX) { |
f98f43ea GH |
315 | if (!vc->gfx.ds) { |
316 | return; | |
317 | } | |
82fc1809 GH |
318 | if (s->free_scale) { |
319 | geo.min_width = surface_width(vc->gfx.ds) * VC_SCALE_MIN; | |
320 | geo.min_height = surface_height(vc->gfx.ds) * VC_SCALE_MIN; | |
321 | mask |= GDK_HINT_MIN_SIZE; | |
322 | } else { | |
323 | geo.min_width = surface_width(vc->gfx.ds) * vc->gfx.scale_x; | |
324 | geo.min_height = surface_height(vc->gfx.ds) * vc->gfx.scale_y; | |
325 | mask |= GDK_HINT_MIN_SIZE; | |
326 | } | |
327 | geo_widget = vc->gfx.drawing_area; | |
328 | gtk_widget_set_size_request(geo_widget, geo.min_width, geo.min_height); | |
9d9801cf | 329 | |
82fc1809 GH |
330 | #if defined(CONFIG_VTE) |
331 | } else if (vc->type == GD_VC_VTE) { | |
332 | VteTerminal *term = VTE_TERMINAL(vc->vte.terminal); | |
6978dc4a | 333 | GtkBorder padding = { 0 }; |
82fc1809 | 334 | |
84e2dc4b | 335 | #if VTE_CHECK_VERSION(0, 37, 0) |
84e2dc4b CR |
336 | gtk_style_context_get_padding( |
337 | gtk_widget_get_style_context(vc->vte.terminal), | |
338 | gtk_widget_get_state_flags(vc->vte.terminal), | |
339 | &padding); | |
84e2dc4b | 340 | #else |
6978dc4a AG |
341 | { |
342 | GtkBorder *ib = NULL; | |
343 | gtk_widget_style_get(vc->vte.terminal, "inner-border", &ib, NULL); | |
344 | if (ib) { | |
345 | padding = *ib; | |
346 | gtk_border_free(ib); | |
347 | } | |
348 | } | |
84e2dc4b CR |
349 | #endif |
350 | ||
82fc1809 GH |
351 | geo.width_inc = vte_terminal_get_char_width(term); |
352 | geo.height_inc = vte_terminal_get_char_height(term); | |
353 | mask |= GDK_HINT_RESIZE_INC; | |
354 | geo.base_width = geo.width_inc; | |
355 | geo.base_height = geo.height_inc; | |
356 | mask |= GDK_HINT_BASE_SIZE; | |
357 | geo.min_width = geo.width_inc * VC_TERM_X_MIN; | |
358 | geo.min_height = geo.height_inc * VC_TERM_Y_MIN; | |
359 | mask |= GDK_HINT_MIN_SIZE; | |
84e2dc4b | 360 | |
6978dc4a AG |
361 | geo.base_width += padding.left + padding.right; |
362 | geo.base_height += padding.top + padding.bottom; | |
363 | geo.min_width += padding.left + padding.right; | |
364 | geo.min_height += padding.top + padding.bottom; | |
82fc1809 GH |
365 | geo_widget = vc->vte.terminal; |
366 | #endif | |
9d9801cf | 367 | } |
82fc1809 GH |
368 | |
369 | geo_window = GTK_WINDOW(vc->window ? vc->window : s->window); | |
370 | gtk_window_set_geometry_hints(geo_window, geo_widget, &geo, mask); | |
371 | } | |
372 | ||
97edf3bd | 373 | void gd_update_windowsize(VirtualConsole *vc) |
82fc1809 GH |
374 | { |
375 | GtkDisplayState *s = vc->s; | |
376 | ||
377 | gd_update_geometry_hints(vc); | |
378 | ||
379 | if (vc->type == GD_VC_GFX && !s->full_screen && !s->free_scale) { | |
380 | gtk_window_resize(GTK_WINDOW(vc->window ? vc->window : s->window), | |
381 | VC_WINDOW_X_MIN, VC_WINDOW_Y_MIN); | |
aa0a55d4 | 382 | } |
9d9801cf GH |
383 | } |
384 | ||
e3500d1f | 385 | static void gd_update_full_redraw(VirtualConsole *vc) |
9d9801cf | 386 | { |
e3500d1f | 387 | GtkWidget *area = vc->gfx.drawing_area; |
9d9801cf | 388 | int ww, wh; |
e3500d1f | 389 | gdk_drawable_get_size(gtk_widget_get_window(area), &ww, &wh); |
925a0400 GH |
390 | #if defined(CONFIG_GTK_GL) |
391 | if (vc->gfx.gls) { | |
392 | gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area)); | |
393 | return; | |
394 | } | |
395 | #endif | |
e3500d1f | 396 | gtk_widget_queue_draw_area(area, 0, 0, ww, wh); |
9d9801cf GH |
397 | } |
398 | ||
6db253ca JK |
399 | static void gtk_release_modifiers(GtkDisplayState *s) |
400 | { | |
e3500d1f | 401 | VirtualConsole *vc = gd_vc_find_current(s); |
6db253ca JK |
402 | int i, keycode; |
403 | ||
f8c223f6 GH |
404 | if (vc->type != GD_VC_GFX || |
405 | !qemu_console_is_graphic(vc->gfx.dcl.con)) { | |
6db253ca JK |
406 | return; |
407 | } | |
408 | for (i = 0; i < ARRAY_SIZE(modifier_keycode); i++) { | |
409 | keycode = modifier_keycode[i]; | |
410 | if (!s->modifier_pressed[i]) { | |
411 | continue; | |
412 | } | |
e3500d1f | 413 | qemu_input_event_send_key_number(vc->gfx.dcl.con, keycode, false); |
6db253ca JK |
414 | s->modifier_pressed[i] = false; |
415 | } | |
416 | } | |
417 | ||
316cb068 GH |
418 | static void gd_widget_reparent(GtkWidget *from, GtkWidget *to, |
419 | GtkWidget *widget) | |
420 | { | |
421 | g_object_ref(G_OBJECT(widget)); | |
422 | gtk_container_remove(GTK_CONTAINER(from), widget); | |
423 | gtk_container_add(GTK_CONTAINER(to), widget); | |
424 | g_object_unref(G_OBJECT(widget)); | |
425 | } | |
426 | ||
a4ccabcf AL |
427 | /** DisplayState Callbacks **/ |
428 | ||
7c20b4a3 | 429 | static void gd_update(DisplayChangeListener *dcl, |
bc2ed970 | 430 | int x, int y, int w, int h) |
a4ccabcf | 431 | { |
e3500d1f | 432 | VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); |
f8c223f6 | 433 | GdkWindow *win; |
a4ccabcf | 434 | int x1, x2, y1, y2; |
c6158483 AL |
435 | int mx, my; |
436 | int fbw, fbh; | |
437 | int ww, wh; | |
a4ccabcf | 438 | |
74444bc1 | 439 | trace_gd_update(vc->label, x, y, w, h); |
a4ccabcf | 440 | |
4cdfc935 HP |
441 | if (!gtk_widget_get_realized(vc->gfx.drawing_area)) { |
442 | return; | |
443 | } | |
444 | ||
e3500d1f GH |
445 | if (vc->gfx.convert) { |
446 | pixman_image_composite(PIXMAN_OP_SRC, vc->gfx.ds->image, | |
447 | NULL, vc->gfx.convert, | |
f0875536 GH |
448 | x, y, 0, 0, x, y, w, h); |
449 | } | |
450 | ||
e3500d1f GH |
451 | x1 = floor(x * vc->gfx.scale_x); |
452 | y1 = floor(y * vc->gfx.scale_y); | |
a4ccabcf | 453 | |
e3500d1f GH |
454 | x2 = ceil(x * vc->gfx.scale_x + w * vc->gfx.scale_x); |
455 | y2 = ceil(y * vc->gfx.scale_y + h * vc->gfx.scale_y); | |
a4ccabcf | 456 | |
e3500d1f GH |
457 | fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x; |
458 | fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y; | |
c6158483 | 459 | |
f8c223f6 GH |
460 | win = gtk_widget_get_window(vc->gfx.drawing_area); |
461 | if (!win) { | |
462 | return; | |
463 | } | |
464 | gdk_drawable_get_size(win, &ww, &wh); | |
c6158483 AL |
465 | |
466 | mx = my = 0; | |
467 | if (ww > fbw) { | |
468 | mx = (ww - fbw) / 2; | |
469 | } | |
470 | if (wh > fbh) { | |
471 | my = (wh - fbh) / 2; | |
472 | } | |
473 | ||
e3500d1f GH |
474 | gtk_widget_queue_draw_area(vc->gfx.drawing_area, |
475 | mx + x1, my + y1, (x2 - x1), (y2 - y1)); | |
a4ccabcf AL |
476 | } |
477 | ||
bc2ed970 | 478 | static void gd_refresh(DisplayChangeListener *dcl) |
a4ccabcf | 479 | { |
284d1c6b | 480 | graphic_hw_update(dcl->con); |
a4ccabcf AL |
481 | } |
482 | ||
b087143b | 483 | #if GTK_CHECK_VERSION(3, 0, 0) |
bb732ee7 CR |
484 | static GdkDevice *gd_get_pointer(GdkDisplay *dpy) |
485 | { | |
486 | #if GTK_CHECK_VERSION(3, 20, 0) | |
487 | return gdk_seat_get_pointer(gdk_display_get_default_seat(dpy)); | |
488 | #else | |
489 | return gdk_device_manager_get_client_pointer( | |
490 | gdk_display_get_device_manager(dpy)); | |
491 | #endif | |
492 | } | |
493 | ||
b087143b IM |
494 | static void gd_mouse_set(DisplayChangeListener *dcl, |
495 | int x, int y, int visible) | |
496 | { | |
e3500d1f | 497 | VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); |
b087143b | 498 | GdkDisplay *dpy; |
b087143b IM |
499 | gint x_root, y_root; |
500 | ||
2bda6602 CR |
501 | if (qemu_input_is_absolute()) { |
502 | return; | |
503 | } | |
504 | ||
e3500d1f | 505 | dpy = gtk_widget_get_display(vc->gfx.drawing_area); |
e3500d1f | 506 | gdk_window_get_root_coords(gtk_widget_get_window(vc->gfx.drawing_area), |
b087143b | 507 | x, y, &x_root, &y_root); |
bb732ee7 | 508 | gdk_device_warp(gd_get_pointer(dpy), |
e3500d1f | 509 | gtk_widget_get_screen(vc->gfx.drawing_area), |
298526fe | 510 | x_root, y_root); |
1271f7f7 GH |
511 | vc->s->last_x = x; |
512 | vc->s->last_y = y; | |
b087143b IM |
513 | } |
514 | #else | |
9697f5d2 GH |
515 | static void gd_mouse_set(DisplayChangeListener *dcl, |
516 | int x, int y, int visible) | |
517 | { | |
e3500d1f | 518 | VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); |
9697f5d2 GH |
519 | gint x_root, y_root; |
520 | ||
2bda6602 CR |
521 | if (qemu_input_is_absolute()) { |
522 | return; | |
523 | } | |
524 | ||
e3500d1f | 525 | gdk_window_get_root_coords(gtk_widget_get_window(vc->gfx.drawing_area), |
9697f5d2 | 526 | x, y, &x_root, &y_root); |
e3500d1f GH |
527 | gdk_display_warp_pointer(gtk_widget_get_display(vc->gfx.drawing_area), |
528 | gtk_widget_get_screen(vc->gfx.drawing_area), | |
9697f5d2 GH |
529 | x_root, y_root); |
530 | } | |
b087143b | 531 | #endif |
9697f5d2 GH |
532 | |
533 | static void gd_cursor_define(DisplayChangeListener *dcl, | |
534 | QEMUCursor *c) | |
535 | { | |
e3500d1f | 536 | VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); |
9697f5d2 GH |
537 | GdkPixbuf *pixbuf; |
538 | GdkCursor *cursor; | |
539 | ||
4cdfc935 HP |
540 | if (!gtk_widget_get_realized(vc->gfx.drawing_area)) { |
541 | return; | |
542 | } | |
543 | ||
9697f5d2 GH |
544 | pixbuf = gdk_pixbuf_new_from_data((guchar *)(c->data), |
545 | GDK_COLORSPACE_RGB, true, 8, | |
546 | c->width, c->height, c->width * 4, | |
547 | NULL, NULL); | |
e3500d1f GH |
548 | cursor = gdk_cursor_new_from_pixbuf |
549 | (gtk_widget_get_display(vc->gfx.drawing_area), | |
550 | pixbuf, c->hot_x, c->hot_y); | |
551 | gdk_window_set_cursor(gtk_widget_get_window(vc->gfx.drawing_area), cursor); | |
9697f5d2 | 552 | g_object_unref(pixbuf); |
030b4b7d | 553 | #if !GTK_CHECK_VERSION(3, 0, 0) |
17139240 | 554 | gdk_cursor_unref(cursor); |
030b4b7d SW |
555 | #else |
556 | g_object_unref(cursor); | |
557 | #endif | |
9697f5d2 GH |
558 | } |
559 | ||
c12aeb86 | 560 | static void gd_switch(DisplayChangeListener *dcl, |
c12aeb86 | 561 | DisplaySurface *surface) |
a4ccabcf | 562 | { |
e3500d1f | 563 | VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl); |
9d9801cf | 564 | bool resized = true; |
a4ccabcf | 565 | |
f98f43ea GH |
566 | trace_gd_switch(vc->label, |
567 | surface ? surface_width(surface) : 0, | |
568 | surface ? surface_height(surface) : 0); | |
a4ccabcf | 569 | |
e3500d1f GH |
570 | if (vc->gfx.surface) { |
571 | cairo_surface_destroy(vc->gfx.surface); | |
f98f43ea GH |
572 | vc->gfx.surface = NULL; |
573 | } | |
574 | if (vc->gfx.convert) { | |
575 | pixman_image_unref(vc->gfx.convert); | |
576 | vc->gfx.convert = NULL; | |
a4ccabcf AL |
577 | } |
578 | ||
f98f43ea | 579 | if (vc->gfx.ds && surface && |
e3500d1f GH |
580 | surface_width(vc->gfx.ds) == surface_width(surface) && |
581 | surface_height(vc->gfx.ds) == surface_height(surface)) { | |
9d9801cf GH |
582 | resized = false; |
583 | } | |
e3500d1f | 584 | vc->gfx.ds = surface; |
a4ccabcf | 585 | |
f98f43ea GH |
586 | if (!surface) { |
587 | return; | |
f0875536 | 588 | } |
a4ccabcf | 589 | |
f0875536 GH |
590 | if (surface->format == PIXMAN_x8r8g8b8) { |
591 | /* | |
592 | * PIXMAN_x8r8g8b8 == CAIRO_FORMAT_RGB24 | |
593 | * | |
594 | * No need to convert, use surface directly. Should be the | |
595 | * common case as this is qemu_default_pixelformat(32) too. | |
596 | */ | |
e3500d1f | 597 | vc->gfx.surface = cairo_image_surface_create_for_data |
f0875536 GH |
598 | (surface_data(surface), |
599 | CAIRO_FORMAT_RGB24, | |
600 | surface_width(surface), | |
601 | surface_height(surface), | |
602 | surface_stride(surface)); | |
603 | } else { | |
604 | /* Must convert surface, use pixman to do it. */ | |
e3500d1f GH |
605 | vc->gfx.convert = pixman_image_create_bits(PIXMAN_x8r8g8b8, |
606 | surface_width(surface), | |
607 | surface_height(surface), | |
608 | NULL, 0); | |
609 | vc->gfx.surface = cairo_image_surface_create_for_data | |
610 | ((void *)pixman_image_get_data(vc->gfx.convert), | |
f0875536 | 611 | CAIRO_FORMAT_RGB24, |
e3500d1f GH |
612 | pixman_image_get_width(vc->gfx.convert), |
613 | pixman_image_get_height(vc->gfx.convert), | |
614 | pixman_image_get_stride(vc->gfx.convert)); | |
615 | pixman_image_composite(PIXMAN_OP_SRC, vc->gfx.ds->image, | |
616 | NULL, vc->gfx.convert, | |
f0875536 | 617 | 0, 0, 0, 0, 0, 0, |
e3500d1f GH |
618 | pixman_image_get_width(vc->gfx.convert), |
619 | pixman_image_get_height(vc->gfx.convert)); | |
f0875536 | 620 | } |
c6158483 | 621 | |
9d9801cf | 622 | if (resized) { |
e3500d1f | 623 | gd_update_windowsize(vc); |
9d9801cf | 624 | } else { |
e3500d1f | 625 | gd_update_full_redraw(vc); |
c6158483 | 626 | } |
a4ccabcf AL |
627 | } |
628 | ||
97edf3bd GH |
629 | static const DisplayChangeListenerOps dcl_ops = { |
630 | .dpy_name = "gtk", | |
631 | .dpy_gfx_update = gd_update, | |
632 | .dpy_gfx_switch = gd_switch, | |
633 | .dpy_gfx_check_format = qemu_pixman_check_format, | |
634 | .dpy_refresh = gd_refresh, | |
635 | .dpy_mouse_set = gd_mouse_set, | |
636 | .dpy_cursor_define = gd_cursor_define, | |
637 | }; | |
638 | ||
639 | ||
640 | #if defined(CONFIG_OPENGL) | |
641 | ||
642 | /** DisplayState Callbacks (opengl version) **/ | |
643 | ||
925a0400 GH |
644 | #if defined(CONFIG_GTK_GL) |
645 | ||
646 | static const DisplayChangeListenerOps dcl_gl_area_ops = { | |
647 | .dpy_name = "gtk-egl", | |
648 | .dpy_gfx_update = gd_gl_area_update, | |
649 | .dpy_gfx_switch = gd_gl_area_switch, | |
650 | .dpy_gfx_check_format = console_gl_check_format, | |
651 | .dpy_refresh = gd_gl_area_refresh, | |
652 | .dpy_mouse_set = gd_mouse_set, | |
653 | .dpy_cursor_define = gd_cursor_define, | |
654 | ||
655 | .dpy_gl_ctx_create = gd_gl_area_create_context, | |
656 | .dpy_gl_ctx_destroy = gd_gl_area_destroy_context, | |
657 | .dpy_gl_ctx_make_current = gd_gl_area_make_current, | |
658 | .dpy_gl_ctx_get_current = gd_gl_area_get_current_context, | |
659 | .dpy_gl_scanout = gd_gl_area_scanout, | |
660 | .dpy_gl_update = gd_gl_area_scanout_flush, | |
661 | }; | |
662 | ||
663 | #else | |
664 | ||
97edf3bd GH |
665 | static const DisplayChangeListenerOps dcl_egl_ops = { |
666 | .dpy_name = "gtk-egl", | |
667 | .dpy_gfx_update = gd_egl_update, | |
668 | .dpy_gfx_switch = gd_egl_switch, | |
669 | .dpy_gfx_check_format = console_gl_check_format, | |
670 | .dpy_refresh = gd_egl_refresh, | |
671 | .dpy_mouse_set = gd_mouse_set, | |
672 | .dpy_cursor_define = gd_cursor_define, | |
4782aeb7 GH |
673 | |
674 | .dpy_gl_ctx_create = gd_egl_create_context, | |
675 | .dpy_gl_ctx_destroy = qemu_egl_destroy_context, | |
676 | .dpy_gl_ctx_make_current = gd_egl_make_current, | |
677 | .dpy_gl_ctx_get_current = qemu_egl_get_current_context, | |
678 | .dpy_gl_scanout = gd_egl_scanout, | |
679 | .dpy_gl_update = gd_egl_scanout_flush, | |
97edf3bd GH |
680 | }; |
681 | ||
925a0400 GH |
682 | #endif /* CONFIG_GTK_GL */ |
683 | #endif /* CONFIG_OPENGL */ | |
97edf3bd | 684 | |
a4ccabcf AL |
685 | /** QEMU Events **/ |
686 | ||
687 | static void gd_change_runstate(void *opaque, int running, RunState state) | |
688 | { | |
689 | GtkDisplayState *s = opaque; | |
690 | ||
691 | gd_update_caption(s); | |
692 | } | |
693 | ||
694 | static void gd_mouse_mode_change(Notifier *notify, void *data) | |
695 | { | |
800b0e81 | 696 | GtkDisplayState *s; |
99623c90 | 697 | int i; |
800b0e81 TI |
698 | |
699 | s = container_of(notify, GtkDisplayState, mouse_mode_notifier); | |
700 | /* release the grab at switching to absolute mode */ | |
701 | if (qemu_input_is_absolute() && gd_is_grab_active(s)) { | |
702 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), | |
703 | FALSE); | |
704 | } | |
99623c90 GH |
705 | for (i = 0; i < s->nb_vcs; i++) { |
706 | VirtualConsole *vc = &s->vc[i]; | |
707 | gd_update_cursor(vc); | |
708 | } | |
a4ccabcf AL |
709 | } |
710 | ||
711 | /** GTK Events **/ | |
712 | ||
713 | static gboolean gd_window_close(GtkWidget *widget, GdkEvent *event, | |
714 | void *opaque) | |
715 | { | |
716 | GtkDisplayState *s = opaque; | |
e3500d1f | 717 | int i; |
a4ccabcf AL |
718 | |
719 | if (!no_quit) { | |
e3500d1f GH |
720 | for (i = 0; i < s->nb_vcs; i++) { |
721 | if (s->vc[i].type != GD_VC_GFX) { | |
722 | continue; | |
723 | } | |
724 | unregister_displaychangelistener(&s->vc[i].gfx.dcl); | |
725 | } | |
a4ccabcf AL |
726 | qmp_quit(NULL); |
727 | return FALSE; | |
728 | } | |
729 | ||
730 | return TRUE; | |
731 | } | |
732 | ||
925a0400 GH |
733 | static void gd_set_ui_info(VirtualConsole *vc, gint width, gint height) |
734 | { | |
735 | QemuUIInfo info; | |
736 | ||
737 | memset(&info, 0, sizeof(info)); | |
738 | info.width = width; | |
739 | info.height = height; | |
740 | dpy_set_ui_info(vc->gfx.dcl.con, &info); | |
741 | } | |
742 | ||
743 | #if defined(CONFIG_GTK_GL) | |
744 | ||
745 | static gboolean gd_render_event(GtkGLArea *area, GdkGLContext *context, | |
746 | void *opaque) | |
747 | { | |
748 | VirtualConsole *vc = opaque; | |
749 | ||
750 | if (vc->gfx.gls) { | |
751 | gd_gl_area_draw(vc); | |
752 | } | |
753 | return TRUE; | |
754 | } | |
755 | ||
756 | static void gd_resize_event(GtkGLArea *area, | |
757 | gint width, gint height, gpointer *opaque) | |
758 | { | |
759 | VirtualConsole *vc = (void *)opaque; | |
760 | ||
761 | gd_set_ui_info(vc, width, height); | |
762 | } | |
763 | ||
764 | #endif | |
765 | ||
a4ccabcf AL |
766 | static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque) |
767 | { | |
e3500d1f GH |
768 | VirtualConsole *vc = opaque; |
769 | GtkDisplayState *s = vc->s; | |
c6158483 | 770 | int mx, my; |
a4ccabcf AL |
771 | int ww, wh; |
772 | int fbw, fbh; | |
773 | ||
97edf3bd GH |
774 | #if defined(CONFIG_OPENGL) |
775 | if (vc->gfx.gls) { | |
925a0400 GH |
776 | #if defined(CONFIG_GTK_GL) |
777 | /* invoke render callback please */ | |
778 | return FALSE; | |
779 | #else | |
97edf3bd GH |
780 | gd_egl_draw(vc); |
781 | return TRUE; | |
925a0400 | 782 | #endif |
97edf3bd GH |
783 | } |
784 | #endif | |
785 | ||
c6158483 AL |
786 | if (!gtk_widget_get_realized(widget)) { |
787 | return FALSE; | |
788 | } | |
f98f43ea GH |
789 | if (!vc->gfx.ds) { |
790 | return FALSE; | |
791 | } | |
c6158483 | 792 | |
e3500d1f GH |
793 | fbw = surface_width(vc->gfx.ds); |
794 | fbh = surface_height(vc->gfx.ds); | |
a4ccabcf AL |
795 | |
796 | gdk_drawable_get_size(gtk_widget_get_window(widget), &ww, &wh); | |
797 | ||
c6158483 | 798 | if (s->full_screen) { |
e3500d1f GH |
799 | vc->gfx.scale_x = (double)ww / fbw; |
800 | vc->gfx.scale_y = (double)wh / fbh; | |
c6158483 AL |
801 | } else if (s->free_scale) { |
802 | double sx, sy; | |
803 | ||
804 | sx = (double)ww / fbw; | |
805 | sy = (double)wh / fbh; | |
806 | ||
e3500d1f | 807 | vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy); |
a4ccabcf AL |
808 | } |
809 | ||
e3500d1f GH |
810 | fbw *= vc->gfx.scale_x; |
811 | fbh *= vc->gfx.scale_y; | |
5104a1f6 | 812 | |
c6158483 AL |
813 | mx = my = 0; |
814 | if (ww > fbw) { | |
815 | mx = (ww - fbw) / 2; | |
816 | } | |
817 | if (wh > fbh) { | |
818 | my = (wh - fbh) / 2; | |
819 | } | |
820 | ||
821 | cairo_rectangle(cr, 0, 0, ww, wh); | |
822 | ||
823 | /* Optionally cut out the inner area where the pixmap | |
824 | will be drawn. This avoids 'flashing' since we're | |
825 | not double-buffering. Note we're using the undocumented | |
826 | behaviour of drawing the rectangle from right to left | |
827 | to cut out the whole */ | |
828 | cairo_rectangle(cr, mx + fbw, my, | |
829 | -1 * fbw, fbh); | |
830 | cairo_fill(cr); | |
831 | ||
e3500d1f GH |
832 | cairo_scale(cr, vc->gfx.scale_x, vc->gfx.scale_y); |
833 | cairo_set_source_surface(cr, vc->gfx.surface, | |
834 | mx / vc->gfx.scale_x, my / vc->gfx.scale_y); | |
a4ccabcf AL |
835 | cairo_paint(cr); |
836 | ||
837 | return TRUE; | |
838 | } | |
839 | ||
fe43bca8 | 840 | #if !GTK_CHECK_VERSION(3, 0, 0) |
a4ccabcf AL |
841 | static gboolean gd_expose_event(GtkWidget *widget, GdkEventExpose *expose, |
842 | void *opaque) | |
843 | { | |
844 | cairo_t *cr; | |
845 | gboolean ret; | |
846 | ||
847 | cr = gdk_cairo_create(gtk_widget_get_window(widget)); | |
848 | cairo_rectangle(cr, | |
849 | expose->area.x, | |
850 | expose->area.y, | |
851 | expose->area.width, | |
852 | expose->area.height); | |
853 | cairo_clip(cr); | |
854 | ||
855 | ret = gd_draw_event(widget, cr, opaque); | |
856 | ||
857 | cairo_destroy(cr); | |
858 | ||
859 | return ret; | |
860 | } | |
fe43bca8 | 861 | #endif |
a4ccabcf AL |
862 | |
863 | static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion, | |
864 | void *opaque) | |
865 | { | |
e3500d1f GH |
866 | VirtualConsole *vc = opaque; |
867 | GtkDisplayState *s = vc->s; | |
a4ccabcf | 868 | int x, y; |
c6158483 AL |
869 | int mx, my; |
870 | int fbh, fbw; | |
871 | int ww, wh; | |
872 | ||
f98f43ea GH |
873 | if (!vc->gfx.ds) { |
874 | return TRUE; | |
875 | } | |
876 | ||
e3500d1f GH |
877 | fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x; |
878 | fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y; | |
a4ccabcf | 879 | |
e3500d1f GH |
880 | gdk_drawable_get_size(gtk_widget_get_window(vc->gfx.drawing_area), |
881 | &ww, &wh); | |
c6158483 AL |
882 | |
883 | mx = my = 0; | |
884 | if (ww > fbw) { | |
885 | mx = (ww - fbw) / 2; | |
886 | } | |
887 | if (wh > fbh) { | |
888 | my = (wh - fbh) / 2; | |
889 | } | |
890 | ||
e3500d1f GH |
891 | x = (motion->x - mx) / vc->gfx.scale_x; |
892 | y = (motion->y - my) / vc->gfx.scale_y; | |
c6158483 | 893 | |
192f81bf | 894 | if (qemu_input_is_absolute()) { |
e61031cd | 895 | if (x < 0 || y < 0 || |
e3500d1f GH |
896 | x >= surface_width(vc->gfx.ds) || |
897 | y >= surface_height(vc->gfx.ds)) { | |
e61031cd TI |
898 | return TRUE; |
899 | } | |
e3500d1f GH |
900 | qemu_input_queue_abs(vc->gfx.dcl.con, INPUT_AXIS_X, x, |
901 | surface_width(vc->gfx.ds)); | |
902 | qemu_input_queue_abs(vc->gfx.dcl.con, INPUT_AXIS_Y, y, | |
903 | surface_height(vc->gfx.ds)); | |
192f81bf | 904 | qemu_input_event_sync(); |
2884cf5b | 905 | } else if (s->last_set && s->ptr_owner == vc) { |
e3500d1f GH |
906 | qemu_input_queue_rel(vc->gfx.dcl.con, INPUT_AXIS_X, x - s->last_x); |
907 | qemu_input_queue_rel(vc->gfx.dcl.con, INPUT_AXIS_Y, y - s->last_y); | |
192f81bf | 908 | qemu_input_event_sync(); |
a4ccabcf | 909 | } |
a4ccabcf AL |
910 | s->last_x = x; |
911 | s->last_y = y; | |
e61031cd | 912 | s->last_set = TRUE; |
a4ccabcf | 913 | |
2884cf5b | 914 | if (!qemu_input_is_absolute() && s->ptr_owner == vc) { |
e3500d1f | 915 | GdkScreen *screen = gtk_widget_get_screen(vc->gfx.drawing_area); |
76d8f93b AG |
916 | int screen_width, screen_height; |
917 | ||
5104a1f6 AL |
918 | int x = (int)motion->x_root; |
919 | int y = (int)motion->y_root; | |
920 | ||
76d8f93b AG |
921 | #if GTK_CHECK_VERSION(3, 22, 0) |
922 | { | |
923 | GdkDisplay *dpy = gtk_widget_get_display(widget); | |
924 | GdkWindow *win = gtk_widget_get_window(widget); | |
925 | GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); | |
926 | GdkRectangle geometry; | |
927 | gdk_monitor_get_geometry(monitor, &geometry); | |
928 | screen_width = geometry.width; | |
929 | screen_height = geometry.height; | |
930 | } | |
931 | #else | |
932 | { | |
933 | screen_width = gdk_screen_get_width(screen); | |
934 | screen_height = gdk_screen_get_height(screen); | |
935 | } | |
936 | #endif | |
937 | ||
5104a1f6 AL |
938 | /* In relative mode check to see if client pointer hit |
939 | * one of the screen edges, and if so move it back by | |
940 | * 200 pixels. This is important because the pointer | |
941 | * in the server doesn't correspond 1-for-1, and so | |
942 | * may still be only half way across the screen. Without | |
943 | * this warp, the server pointer would thus appear to hit | |
944 | * an invisible wall */ | |
945 | if (x == 0) { | |
946 | x += 200; | |
947 | } | |
948 | if (y == 0) { | |
949 | y += 200; | |
950 | } | |
76d8f93b | 951 | if (x == (screen_width - 1)) { |
5104a1f6 AL |
952 | x -= 200; |
953 | } | |
76d8f93b | 954 | if (y == (screen_height - 1)) { |
5104a1f6 AL |
955 | y -= 200; |
956 | } | |
957 | ||
958 | if (x != (int)motion->x_root || y != (int)motion->y_root) { | |
8906de76 DB |
959 | #if GTK_CHECK_VERSION(3, 0, 0) |
960 | GdkDevice *dev = gdk_event_get_device((GdkEvent *)motion); | |
961 | gdk_device_warp(dev, screen, x, y); | |
962 | #else | |
963 | GdkDisplay *display = gtk_widget_get_display(widget); | |
5104a1f6 | 964 | gdk_display_warp_pointer(display, screen, x, y); |
8906de76 | 965 | #endif |
e61031cd | 966 | s->last_set = FALSE; |
5104a1f6 AL |
967 | return FALSE; |
968 | } | |
969 | } | |
a4ccabcf AL |
970 | return TRUE; |
971 | } | |
972 | ||
973 | static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button, | |
974 | void *opaque) | |
975 | { | |
e3500d1f GH |
976 | VirtualConsole *vc = opaque; |
977 | GtkDisplayState *s = vc->s; | |
192f81bf | 978 | InputButton btn; |
a4ccabcf | 979 | |
800b0e81 TI |
980 | /* implicitly grab the input at the first click in the relative mode */ |
981 | if (button->button == 1 && button->type == GDK_BUTTON_PRESS && | |
2884cf5b | 982 | !qemu_input_is_absolute() && s->ptr_owner != vc) { |
2884cf5b GH |
983 | if (!vc->window) { |
984 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), | |
985 | TRUE); | |
986 | } else { | |
d531deef | 987 | gd_grab_pointer(vc, "relative-mode-click"); |
2884cf5b | 988 | } |
800b0e81 TI |
989 | return TRUE; |
990 | } | |
991 | ||
a4ccabcf | 992 | if (button->button == 1) { |
192f81bf | 993 | btn = INPUT_BUTTON_LEFT; |
a4ccabcf | 994 | } else if (button->button == 2) { |
192f81bf | 995 | btn = INPUT_BUTTON_MIDDLE; |
a4ccabcf | 996 | } else if (button->button == 3) { |
192f81bf | 997 | btn = INPUT_BUTTON_RIGHT; |
a4ccabcf | 998 | } else { |
192f81bf | 999 | return TRUE; |
a4ccabcf AL |
1000 | } |
1001 | ||
e3500d1f GH |
1002 | qemu_input_queue_btn(vc->gfx.dcl.con, btn, |
1003 | button->type == GDK_BUTTON_PRESS); | |
192f81bf | 1004 | qemu_input_event_sync(); |
a4ccabcf AL |
1005 | return TRUE; |
1006 | } | |
1007 | ||
d58b9122 JK |
1008 | static gboolean gd_scroll_event(GtkWidget *widget, GdkEventScroll *scroll, |
1009 | void *opaque) | |
1010 | { | |
e3500d1f | 1011 | VirtualConsole *vc = opaque; |
d58b9122 JK |
1012 | InputButton btn; |
1013 | ||
1014 | if (scroll->direction == GDK_SCROLL_UP) { | |
f22d0af0 | 1015 | btn = INPUT_BUTTON_WHEEL_UP; |
d58b9122 | 1016 | } else if (scroll->direction == GDK_SCROLL_DOWN) { |
f22d0af0 | 1017 | btn = INPUT_BUTTON_WHEEL_DOWN; |
d58b9122 JK |
1018 | } else { |
1019 | return TRUE; | |
1020 | } | |
1021 | ||
e3500d1f | 1022 | qemu_input_queue_btn(vc->gfx.dcl.con, btn, true); |
d58b9122 | 1023 | qemu_input_event_sync(); |
e3500d1f | 1024 | qemu_input_queue_btn(vc->gfx.dcl.con, btn, false); |
d58b9122 JK |
1025 | qemu_input_event_sync(); |
1026 | return TRUE; | |
1027 | } | |
1028 | ||
0a337ed0 | 1029 | static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode) |
a4ccabcf | 1030 | { |
932f2d7e | 1031 | int qemu_keycode; |
a4ccabcf | 1032 | |
0a337ed0 GH |
1033 | #ifdef GDK_WINDOWING_WIN32 |
1034 | if (GDK_IS_WIN32_DISPLAY(dpy)) { | |
1035 | qemu_keycode = MapVirtualKey(gdk_keycode, MAPVK_VK_TO_VSC); | |
1036 | switch (qemu_keycode) { | |
1037 | case 103: /* alt gr */ | |
1038 | qemu_keycode = 56 | SCANCODE_GREY; | |
1039 | break; | |
1040 | } | |
1041 | return qemu_keycode; | |
2777ccc5 | 1042 | } |
0a337ed0 | 1043 | #endif |
a4ccabcf AL |
1044 | |
1045 | if (gdk_keycode < 9) { | |
1046 | qemu_keycode = 0; | |
1047 | } else if (gdk_keycode < 97) { | |
1048 | qemu_keycode = gdk_keycode - 8; | |
0a337ed0 GH |
1049 | #ifdef GDK_WINDOWING_X11 |
1050 | } else if (GDK_IS_X11_DISPLAY(dpy) && gdk_keycode < 158) { | |
3158a348 BR |
1051 | if (s->has_evdev) { |
1052 | qemu_keycode = translate_evdev_keycode(gdk_keycode - 97); | |
1053 | } else { | |
1054 | qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97); | |
1055 | } | |
0a337ed0 | 1056 | #endif |
a4ccabcf AL |
1057 | } else if (gdk_keycode == 208) { /* Hiragana_Katakana */ |
1058 | qemu_keycode = 0x70; | |
1059 | } else if (gdk_keycode == 211) { /* backslash */ | |
1060 | qemu_keycode = 0x73; | |
1061 | } else { | |
1062 | qemu_keycode = 0; | |
1063 | } | |
1064 | ||
932f2d7e GH |
1065 | return qemu_keycode; |
1066 | } | |
1067 | ||
f8c223f6 GH |
1068 | static gboolean gd_text_key_down(GtkWidget *widget, |
1069 | GdkEventKey *key, void *opaque) | |
1070 | { | |
1071 | VirtualConsole *vc = opaque; | |
1072 | QemuConsole *con = vc->gfx.dcl.con; | |
1073 | ||
85617885 TH |
1074 | if (key->keyval == GDK_KEY_Delete) { |
1075 | kbd_put_qcode_console(con, Q_KEY_CODE_DELETE); | |
1076 | } else if (key->length) { | |
f8c223f6 GH |
1077 | kbd_put_string_console(con, key->string, key->length); |
1078 | } else { | |
1079 | int num = gd_map_keycode(vc->s, gtk_widget_get_display(widget), | |
1080 | key->hardware_keycode); | |
1081 | int qcode = qemu_input_key_number_to_qcode(num); | |
1082 | kbd_put_qcode_console(con, qcode); | |
1083 | } | |
1084 | return TRUE; | |
1085 | } | |
1086 | ||
932f2d7e GH |
1087 | static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) |
1088 | { | |
1089 | VirtualConsole *vc = opaque; | |
1090 | GtkDisplayState *s = vc->s; | |
1091 | int gdk_keycode = key->hardware_keycode; | |
1092 | int qemu_keycode; | |
1093 | int i; | |
1094 | ||
1a01716a JK |
1095 | if (s->ignore_keys) { |
1096 | s->ignore_keys = (key->type == GDK_KEY_PRESS); | |
1097 | return TRUE; | |
1098 | } | |
1099 | ||
5c960521 MD |
1100 | if (key->keyval == GDK_KEY_Pause) { |
1101 | qemu_input_event_send_key_qcode(vc->gfx.dcl.con, Q_KEY_CODE_PAUSE, | |
1102 | key->type == GDK_KEY_PRESS); | |
1103 | return TRUE; | |
1104 | } | |
1105 | ||
0a337ed0 GH |
1106 | qemu_keycode = gd_map_keycode(s, gtk_widget_get_display(widget), |
1107 | gdk_keycode); | |
932f2d7e | 1108 | |
74444bc1 | 1109 | trace_gd_key_event(vc->label, gdk_keycode, qemu_keycode, |
ef0dd982 | 1110 | (key->type == GDK_KEY_PRESS) ? "down" : "up"); |
a4ccabcf | 1111 | |
6db253ca JK |
1112 | for (i = 0; i < ARRAY_SIZE(modifier_keycode); i++) { |
1113 | if (qemu_keycode == modifier_keycode[i]) { | |
1114 | s->modifier_pressed[i] = (key->type == GDK_KEY_PRESS); | |
1115 | } | |
1116 | } | |
1117 | ||
e3500d1f | 1118 | qemu_input_event_send_key_number(vc->gfx.dcl.con, qemu_keycode, |
af98ba92 | 1119 | key->type == GDK_KEY_PRESS); |
a4ccabcf AL |
1120 | |
1121 | return TRUE; | |
1122 | } | |
1123 | ||
0d0e044d TI |
1124 | static gboolean gd_event(GtkWidget *widget, GdkEvent *event, void *opaque) |
1125 | { | |
1126 | if (event->type == GDK_MOTION_NOTIFY) { | |
1127 | return gd_motion_event(widget, &event->motion, opaque); | |
1128 | } | |
1129 | return FALSE; | |
1130 | } | |
1131 | ||
a4ccabcf AL |
1132 | /** Window Menu Actions **/ |
1133 | ||
30e8f22b JK |
1134 | static void gd_menu_pause(GtkMenuItem *item, void *opaque) |
1135 | { | |
1136 | GtkDisplayState *s = opaque; | |
1137 | ||
1138 | if (s->external_pause_update) { | |
1139 | return; | |
1140 | } | |
1141 | if (runstate_is_running()) { | |
1142 | qmp_stop(NULL); | |
1143 | } else { | |
1144 | qmp_cont(NULL); | |
1145 | } | |
1146 | } | |
1147 | ||
1148 | static void gd_menu_reset(GtkMenuItem *item, void *opaque) | |
1149 | { | |
1150 | qmp_system_reset(NULL); | |
1151 | } | |
1152 | ||
1153 | static void gd_menu_powerdown(GtkMenuItem *item, void *opaque) | |
1154 | { | |
1155 | qmp_system_powerdown(NULL); | |
1156 | } | |
1157 | ||
a4ccabcf AL |
1158 | static void gd_menu_quit(GtkMenuItem *item, void *opaque) |
1159 | { | |
1160 | qmp_quit(NULL); | |
1161 | } | |
1162 | ||
1163 | static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque) | |
1164 | { | |
1165 | GtkDisplayState *s = opaque; | |
e3500d1f | 1166 | VirtualConsole *vc = gd_vc_find_by_menu(s); |
e72b59fa | 1167 | GtkNotebook *nb = GTK_NOTEBOOK(s->notebook); |
832189c9 | 1168 | gint page; |
a4ccabcf | 1169 | |
e3500d1f GH |
1170 | gtk_release_modifiers(s); |
1171 | if (vc) { | |
e72b59fa JS |
1172 | page = gtk_notebook_page_num(nb, vc->tab_item); |
1173 | gtk_notebook_set_current_page(nb, page); | |
9d677e1c | 1174 | gtk_widget_grab_focus(vc->focus); |
a4ccabcf | 1175 | } |
1a01716a | 1176 | s->ignore_keys = false; |
a4ccabcf AL |
1177 | } |
1178 | ||
277836c8 CR |
1179 | static void gd_accel_switch_vc(void *opaque) |
1180 | { | |
1181 | VirtualConsole *vc = opaque; | |
1a01716a | 1182 | |
277836c8 | 1183 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item), TRUE); |
1a01716a JK |
1184 | #if !GTK_CHECK_VERSION(3, 0, 0) |
1185 | /* GTK2 sends the accel key to the target console - ignore this until */ | |
1186 | vc->s->ignore_keys = true; | |
1187 | #endif | |
277836c8 CR |
1188 | } |
1189 | ||
a4ccabcf AL |
1190 | static void gd_menu_show_tabs(GtkMenuItem *item, void *opaque) |
1191 | { | |
1192 | GtkDisplayState *s = opaque; | |
fa7a1e52 | 1193 | VirtualConsole *vc = gd_vc_find_current(s); |
a4ccabcf AL |
1194 | |
1195 | if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->show_tabs_item))) { | |
1196 | gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), TRUE); | |
1197 | } else { | |
1198 | gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE); | |
1199 | } | |
fa7a1e52 | 1200 | gd_update_windowsize(vc); |
a4ccabcf AL |
1201 | } |
1202 | ||
cdeb7090 GH |
1203 | static gboolean gd_tab_window_close(GtkWidget *widget, GdkEvent *event, |
1204 | void *opaque) | |
1205 | { | |
1206 | VirtualConsole *vc = opaque; | |
1207 | GtkDisplayState *s = vc->s; | |
1208 | ||
1209 | gtk_widget_set_sensitive(vc->menu_item, true); | |
316cb068 | 1210 | gd_widget_reparent(vc->window, s->notebook, vc->tab_item); |
cdeb7090 GH |
1211 | gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(s->notebook), |
1212 | vc->tab_item, vc->label); | |
1213 | gtk_widget_destroy(vc->window); | |
1214 | vc->window = NULL; | |
1215 | return TRUE; | |
1216 | } | |
1217 | ||
0c77a37f GH |
1218 | static gboolean gd_win_grab(void *opaque) |
1219 | { | |
1220 | VirtualConsole *vc = opaque; | |
1221 | ||
1222 | fprintf(stderr, "%s: %s\n", __func__, vc->label); | |
1223 | if (vc->s->ptr_owner) { | |
1224 | gd_ungrab_pointer(vc->s); | |
1225 | } else { | |
d531deef | 1226 | gd_grab_pointer(vc, "user-request-detached-tab"); |
0c77a37f | 1227 | } |
0c77a37f GH |
1228 | return TRUE; |
1229 | } | |
1230 | ||
cdeb7090 GH |
1231 | static void gd_menu_untabify(GtkMenuItem *item, void *opaque) |
1232 | { | |
1233 | GtkDisplayState *s = opaque; | |
1234 | VirtualConsole *vc = gd_vc_find_current(s); | |
cdeb7090 | 1235 | |
f8c223f6 GH |
1236 | if (vc->type == GD_VC_GFX && |
1237 | qemu_console_is_graphic(vc->gfx.dcl.con)) { | |
aa0a55d4 GH |
1238 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), |
1239 | FALSE); | |
cdeb7090 GH |
1240 | } |
1241 | if (!vc->window) { | |
1242 | gtk_widget_set_sensitive(vc->menu_item, false); | |
1243 | vc->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
316cb068 | 1244 | gd_widget_reparent(s->notebook, vc->window, vc->tab_item); |
cdeb7090 | 1245 | |
cdeb7090 GH |
1246 | g_signal_connect(vc->window, "delete-event", |
1247 | G_CALLBACK(gd_tab_window_close), vc); | |
1248 | gtk_widget_show_all(vc->window); | |
4eeaa3a8 | 1249 | |
f8c223f6 GH |
1250 | if (qemu_console_is_graphic(vc->gfx.dcl.con)) { |
1251 | GtkAccelGroup *ag = gtk_accel_group_new(); | |
1252 | gtk_window_add_accel_group(GTK_WINDOW(vc->window), ag); | |
0c77a37f | 1253 | |
f8c223f6 GH |
1254 | GClosure *cb = g_cclosure_new_swap(G_CALLBACK(gd_win_grab), |
1255 | vc, NULL); | |
1256 | gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0, cb); | |
1257 | } | |
0c77a37f | 1258 | |
82fc1809 | 1259 | gd_update_geometry_hints(vc); |
4eeaa3a8 | 1260 | gd_update_caption(s); |
cdeb7090 GH |
1261 | } |
1262 | } | |
1263 | ||
c6158483 AL |
1264 | static void gd_menu_full_screen(GtkMenuItem *item, void *opaque) |
1265 | { | |
1266 | GtkDisplayState *s = opaque; | |
e3500d1f | 1267 | VirtualConsole *vc = gd_vc_find_current(s); |
c6158483 | 1268 | |
10409282 | 1269 | if (!s->full_screen) { |
c6158483 | 1270 | gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE); |
b0f31820 | 1271 | gtk_widget_hide(s->menu_bar); |
e3500d1f GH |
1272 | if (vc->type == GD_VC_GFX) { |
1273 | gtk_widget_set_size_request(vc->gfx.drawing_area, -1, -1); | |
c6158483 | 1274 | } |
e3500d1f | 1275 | gtk_window_fullscreen(GTK_WINDOW(s->window)); |
c6158483 AL |
1276 | s->full_screen = TRUE; |
1277 | } else { | |
1278 | gtk_window_unfullscreen(GTK_WINDOW(s->window)); | |
1279 | gd_menu_show_tabs(GTK_MENU_ITEM(s->show_tabs_item), s); | |
b0f31820 | 1280 | gtk_widget_show(s->menu_bar); |
c6158483 | 1281 | s->full_screen = FALSE; |
e3500d1f GH |
1282 | if (vc->type == GD_VC_GFX) { |
1283 | vc->gfx.scale_x = 1.0; | |
1284 | vc->gfx.scale_y = 1.0; | |
82fc1809 | 1285 | gd_update_windowsize(vc); |
e3500d1f | 1286 | } |
c6158483 AL |
1287 | } |
1288 | ||
e3500d1f | 1289 | gd_update_cursor(vc); |
c6158483 AL |
1290 | } |
1291 | ||
95414914 CR |
1292 | static void gd_accel_full_screen(void *opaque) |
1293 | { | |
1294 | GtkDisplayState *s = opaque; | |
1295 | gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item)); | |
1296 | } | |
1297 | ||
c6158483 AL |
1298 | static void gd_menu_zoom_in(GtkMenuItem *item, void *opaque) |
1299 | { | |
1300 | GtkDisplayState *s = opaque; | |
e3500d1f | 1301 | VirtualConsole *vc = gd_vc_find_current(s); |
c6158483 AL |
1302 | |
1303 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item), | |
1304 | FALSE); | |
1305 | ||
82fc1809 GH |
1306 | vc->gfx.scale_x += VC_SCALE_STEP; |
1307 | vc->gfx.scale_y += VC_SCALE_STEP; | |
c6158483 | 1308 | |
e3500d1f | 1309 | gd_update_windowsize(vc); |
c6158483 AL |
1310 | } |
1311 | ||
1312 | static void gd_menu_zoom_out(GtkMenuItem *item, void *opaque) | |
1313 | { | |
1314 | GtkDisplayState *s = opaque; | |
e3500d1f | 1315 | VirtualConsole *vc = gd_vc_find_current(s); |
c6158483 AL |
1316 | |
1317 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item), | |
1318 | FALSE); | |
1319 | ||
82fc1809 GH |
1320 | vc->gfx.scale_x -= VC_SCALE_STEP; |
1321 | vc->gfx.scale_y -= VC_SCALE_STEP; | |
c6158483 | 1322 | |
82fc1809 GH |
1323 | vc->gfx.scale_x = MAX(vc->gfx.scale_x, VC_SCALE_MIN); |
1324 | vc->gfx.scale_y = MAX(vc->gfx.scale_y, VC_SCALE_MIN); | |
c6158483 | 1325 | |
e3500d1f | 1326 | gd_update_windowsize(vc); |
c6158483 AL |
1327 | } |
1328 | ||
1329 | static void gd_menu_zoom_fixed(GtkMenuItem *item, void *opaque) | |
1330 | { | |
1331 | GtkDisplayState *s = opaque; | |
e3500d1f | 1332 | VirtualConsole *vc = gd_vc_find_current(s); |
c6158483 | 1333 | |
e3500d1f GH |
1334 | vc->gfx.scale_x = 1.0; |
1335 | vc->gfx.scale_y = 1.0; | |
c6158483 | 1336 | |
e3500d1f | 1337 | gd_update_windowsize(vc); |
c6158483 AL |
1338 | } |
1339 | ||
1340 | static void gd_menu_zoom_fit(GtkMenuItem *item, void *opaque) | |
1341 | { | |
1342 | GtkDisplayState *s = opaque; | |
e3500d1f | 1343 | VirtualConsole *vc = gd_vc_find_current(s); |
c6158483 AL |
1344 | |
1345 | if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item))) { | |
1346 | s->free_scale = TRUE; | |
1347 | } else { | |
1348 | s->free_scale = FALSE; | |
e3500d1f GH |
1349 | vc->gfx.scale_x = 1.0; |
1350 | vc->gfx.scale_y = 1.0; | |
c6158483 AL |
1351 | } |
1352 | ||
82fc1809 | 1353 | gd_update_windowsize(vc); |
e3500d1f | 1354 | gd_update_full_redraw(vc); |
c6158483 AL |
1355 | } |
1356 | ||
a69fc693 GH |
1357 | #if GTK_CHECK_VERSION(3, 20, 0) |
1358 | static void gd_grab_update(VirtualConsole *vc, bool kbd, bool ptr) | |
1359 | { | |
1360 | GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area); | |
1361 | GdkSeat *seat = gdk_display_get_default_seat(display); | |
1362 | GdkWindow *window = gtk_widget_get_window(vc->gfx.drawing_area); | |
1363 | GdkSeatCapabilities caps = 0; | |
1364 | GdkCursor *cursor = NULL; | |
1365 | ||
1366 | if (kbd) { | |
1367 | caps |= GDK_SEAT_CAPABILITY_KEYBOARD; | |
1368 | } | |
1369 | if (ptr) { | |
1370 | caps |= GDK_SEAT_CAPABILITY_ALL_POINTING; | |
1371 | cursor = vc->s->null_cursor; | |
1372 | } | |
1373 | ||
1374 | if (caps) { | |
1375 | gdk_seat_grab(seat, window, caps, false, cursor, | |
1376 | NULL, NULL, NULL); | |
1377 | } else { | |
1378 | gdk_seat_ungrab(seat); | |
1379 | } | |
1380 | } | |
1381 | #elif GTK_CHECK_VERSION(3, 0, 0) | |
f50def91 GH |
1382 | static void gd_grab_devices(VirtualConsole *vc, bool grab, |
1383 | GdkInputSource source, GdkEventMask mask, | |
1384 | GdkCursor *cursor) | |
1385 | { | |
e3500d1f | 1386 | GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area); |
655199da | 1387 | GdkDeviceManager *mgr = gdk_display_get_device_manager(display); |
f50def91 GH |
1388 | GList *devs = gdk_device_manager_list_devices(mgr, GDK_DEVICE_TYPE_MASTER); |
1389 | GList *tmp = devs; | |
1390 | ||
1391 | for (tmp = devs; tmp; tmp = tmp->next) { | |
655199da | 1392 | GdkDevice *dev = tmp->data; |
f50def91 GH |
1393 | if (gdk_device_get_source(dev) != source) { |
1394 | continue; | |
1395 | } | |
1396 | if (grab) { | |
1397 | GdkWindow *win = gtk_widget_get_window(vc->gfx.drawing_area); | |
1398 | gdk_device_grab(dev, win, GDK_OWNERSHIP_NONE, FALSE, | |
1399 | mask, cursor, GDK_CURRENT_TIME); | |
1400 | } else { | |
1401 | gdk_device_ungrab(dev, GDK_CURRENT_TIME); | |
655199da | 1402 | } |
655199da | 1403 | } |
f50def91 GH |
1404 | g_list_free(devs); |
1405 | } | |
1406 | #endif | |
1407 | ||
d531deef | 1408 | static void gd_grab_keyboard(VirtualConsole *vc, const char *reason) |
f50def91 | 1409 | { |
aa4f4058 GH |
1410 | if (vc->s->kbd_owner) { |
1411 | if (vc->s->kbd_owner == vc) { | |
1412 | return; | |
1413 | } else { | |
1414 | gd_ungrab_keyboard(vc->s); | |
1415 | } | |
1416 | } | |
1417 | ||
a69fc693 GH |
1418 | #if GTK_CHECK_VERSION(3, 20, 0) |
1419 | gd_grab_update(vc, true, vc->s->ptr_owner == vc); | |
1420 | #elif GTK_CHECK_VERSION(3, 0, 0) | |
f50def91 GH |
1421 | gd_grab_devices(vc, true, GDK_SOURCE_KEYBOARD, |
1422 | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK, | |
1423 | NULL); | |
655199da | 1424 | #else |
e3500d1f | 1425 | gdk_keyboard_grab(gtk_widget_get_window(vc->gfx.drawing_area), |
5104a1f6 AL |
1426 | FALSE, |
1427 | GDK_CURRENT_TIME); | |
655199da | 1428 | #endif |
4c638e2e | 1429 | vc->s->kbd_owner = vc; |
695cc59d | 1430 | gd_update_caption(vc->s); |
d531deef | 1431 | trace_gd_grab(vc->label, "kbd", reason); |
5104a1f6 AL |
1432 | } |
1433 | ||
4c638e2e | 1434 | static void gd_ungrab_keyboard(GtkDisplayState *s) |
5104a1f6 | 1435 | { |
4c638e2e GH |
1436 | VirtualConsole *vc = s->kbd_owner; |
1437 | ||
1438 | if (vc == NULL) { | |
1439 | return; | |
1440 | } | |
1441 | s->kbd_owner = NULL; | |
1442 | ||
a69fc693 GH |
1443 | #if GTK_CHECK_VERSION(3, 20, 0) |
1444 | gd_grab_update(vc, false, vc->s->ptr_owner == vc); | |
1445 | #elif GTK_CHECK_VERSION(3, 0, 0) | |
f50def91 | 1446 | gd_grab_devices(vc, false, GDK_SOURCE_KEYBOARD, 0, NULL); |
655199da | 1447 | #else |
5104a1f6 | 1448 | gdk_keyboard_ungrab(GDK_CURRENT_TIME); |
655199da | 1449 | #endif |
695cc59d | 1450 | gd_update_caption(s); |
d531deef | 1451 | trace_gd_ungrab(vc->label, "kbd"); |
5104a1f6 AL |
1452 | } |
1453 | ||
d531deef | 1454 | static void gd_grab_pointer(VirtualConsole *vc, const char *reason) |
2a05485d | 1455 | { |
e3500d1f | 1456 | GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area); |
aa4f4058 GH |
1457 | |
1458 | if (vc->s->ptr_owner) { | |
1459 | if (vc->s->ptr_owner == vc) { | |
1460 | return; | |
1461 | } else { | |
1462 | gd_ungrab_pointer(vc->s); | |
1463 | } | |
1464 | } | |
1465 | ||
a69fc693 GH |
1466 | #if GTK_CHECK_VERSION(3, 20, 0) |
1467 | gd_grab_update(vc, vc->s->kbd_owner == vc, true); | |
1468 | gdk_device_get_position(gd_get_pointer(display), | |
1469 | NULL, &vc->s->grab_x_root, &vc->s->grab_y_root); | |
1470 | #elif GTK_CHECK_VERSION(3, 0, 0) | |
f50def91 GH |
1471 | gd_grab_devices(vc, true, GDK_SOURCE_MOUSE, |
1472 | GDK_POINTER_MOTION_MASK | | |
1473 | GDK_BUTTON_PRESS_MASK | | |
1474 | GDK_BUTTON_RELEASE_MASK | | |
1475 | GDK_BUTTON_MOTION_MASK | | |
1476 | GDK_SCROLL_MASK, | |
1477 | vc->s->null_cursor); | |
bb732ee7 | 1478 | gdk_device_get_position(gd_get_pointer(display), |
e3500d1f | 1479 | NULL, &vc->s->grab_x_root, &vc->s->grab_y_root); |
2a05485d | 1480 | #else |
e3500d1f | 1481 | gdk_pointer_grab(gtk_widget_get_window(vc->gfx.drawing_area), |
2a05485d DB |
1482 | FALSE, /* All events to come to our window directly */ |
1483 | GDK_POINTER_MOTION_MASK | | |
1484 | GDK_BUTTON_PRESS_MASK | | |
1485 | GDK_BUTTON_RELEASE_MASK | | |
1486 | GDK_BUTTON_MOTION_MASK | | |
1487 | GDK_SCROLL_MASK, | |
1488 | NULL, /* Allow cursor to move over entire desktop */ | |
e3500d1f | 1489 | vc->s->null_cursor, |
2a05485d | 1490 | GDK_CURRENT_TIME); |
ecce1929 | 1491 | gdk_display_get_pointer(display, NULL, |
e3500d1f | 1492 | &vc->s->grab_x_root, &vc->s->grab_y_root, NULL); |
2a05485d | 1493 | #endif |
4c638e2e | 1494 | vc->s->ptr_owner = vc; |
695cc59d | 1495 | gd_update_caption(vc->s); |
d531deef | 1496 | trace_gd_grab(vc->label, "ptr", reason); |
2a05485d DB |
1497 | } |
1498 | ||
4c638e2e | 1499 | static void gd_ungrab_pointer(GtkDisplayState *s) |
2a05485d | 1500 | { |
4c638e2e | 1501 | VirtualConsole *vc = s->ptr_owner; |
41cc5239 | 1502 | GdkDisplay *display; |
4c638e2e GH |
1503 | |
1504 | if (vc == NULL) { | |
1505 | return; | |
1506 | } | |
1507 | s->ptr_owner = NULL; | |
1508 | ||
41cc5239 | 1509 | display = gtk_widget_get_display(vc->gfx.drawing_area); |
a69fc693 GH |
1510 | #if GTK_CHECK_VERSION(3, 20, 0) |
1511 | gd_grab_update(vc, vc->s->kbd_owner == vc, false); | |
1512 | gdk_device_warp(gd_get_pointer(display), | |
1513 | gtk_widget_get_screen(vc->gfx.drawing_area), | |
1514 | vc->s->grab_x_root, vc->s->grab_y_root); | |
1515 | #elif GTK_CHECK_VERSION(3, 0, 0) | |
f50def91 | 1516 | gd_grab_devices(vc, false, GDK_SOURCE_MOUSE, 0, NULL); |
bb732ee7 | 1517 | gdk_device_warp(gd_get_pointer(display), |
e3500d1f GH |
1518 | gtk_widget_get_screen(vc->gfx.drawing_area), |
1519 | vc->s->grab_x_root, vc->s->grab_y_root); | |
2a05485d DB |
1520 | #else |
1521 | gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
ecce1929 | 1522 | gdk_display_warp_pointer(display, |
e3500d1f GH |
1523 | gtk_widget_get_screen(vc->gfx.drawing_area), |
1524 | vc->s->grab_x_root, vc->s->grab_y_root); | |
2a05485d | 1525 | #endif |
695cc59d | 1526 | gd_update_caption(s); |
d531deef | 1527 | trace_gd_ungrab(vc->label, "ptr"); |
2a05485d DB |
1528 | } |
1529 | ||
5104a1f6 AL |
1530 | static void gd_menu_grab_input(GtkMenuItem *item, void *opaque) |
1531 | { | |
1532 | GtkDisplayState *s = opaque; | |
e3500d1f | 1533 | VirtualConsole *vc = gd_vc_find_current(s); |
5104a1f6 AL |
1534 | |
1535 | if (gd_is_grab_active(s)) { | |
d531deef GH |
1536 | gd_grab_keyboard(vc, "user-request-main-window"); |
1537 | gd_grab_pointer(vc, "user-request-main-window"); | |
5104a1f6 | 1538 | } else { |
4c638e2e GH |
1539 | gd_ungrab_keyboard(s); |
1540 | gd_ungrab_pointer(s); | |
5104a1f6 AL |
1541 | } |
1542 | ||
e3500d1f | 1543 | gd_update_cursor(vc); |
5104a1f6 AL |
1544 | } |
1545 | ||
a4ccabcf AL |
1546 | static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2, |
1547 | gpointer data) | |
1548 | { | |
1549 | GtkDisplayState *s = data; | |
e3500d1f | 1550 | VirtualConsole *vc; |
5104a1f6 | 1551 | gboolean on_vga; |
a4ccabcf AL |
1552 | |
1553 | if (!gtk_widget_get_realized(s->notebook)) { | |
1554 | return; | |
1555 | } | |
1556 | ||
6fa27697 GH |
1557 | #ifdef VTE_RESIZE_HACK |
1558 | vc = gd_vc_find_current(s); | |
1559 | if (vc && vc->type == GD_VC_VTE) { | |
1560 | gtk_widget_hide(vc->vte.terminal); | |
1561 | } | |
1562 | #endif | |
e3500d1f GH |
1563 | vc = gd_vc_find_by_page(s, arg2); |
1564 | if (!vc) { | |
1565 | return; | |
1566 | } | |
6fa27697 GH |
1567 | #ifdef VTE_RESIZE_HACK |
1568 | if (vc->type == GD_VC_VTE) { | |
1569 | gtk_widget_show(vc->vte.terminal); | |
1570 | } | |
1571 | #endif | |
e3500d1f GH |
1572 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item), |
1573 | TRUE); | |
f8c223f6 GH |
1574 | on_vga = (vc->type == GD_VC_GFX && |
1575 | qemu_console_is_graphic(vc->gfx.dcl.con)); | |
5104a1f6 AL |
1576 | if (!on_vga) { |
1577 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), | |
1578 | FALSE); | |
c6158483 AL |
1579 | } else if (s->full_screen) { |
1580 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), | |
1581 | TRUE); | |
5104a1f6 | 1582 | } |
5104a1f6 | 1583 | gtk_widget_set_sensitive(s->grab_item, on_vga); |
a0815632 SH |
1584 | #ifdef CONFIG_VTE |
1585 | gtk_widget_set_sensitive(s->copy_item, vc->type == GD_VC_VTE); | |
1586 | #endif | |
5104a1f6 | 1587 | |
82fc1809 | 1588 | gd_update_windowsize(vc); |
e3500d1f | 1589 | gd_update_cursor(vc); |
a4ccabcf AL |
1590 | } |
1591 | ||
e3500d1f GH |
1592 | static gboolean gd_enter_event(GtkWidget *widget, GdkEventCrossing *crossing, |
1593 | gpointer opaque) | |
5104a1f6 | 1594 | { |
e3500d1f GH |
1595 | VirtualConsole *vc = opaque; |
1596 | GtkDisplayState *s = vc->s; | |
5104a1f6 | 1597 | |
2884cf5b | 1598 | if (gd_grab_on_hover(s)) { |
d531deef | 1599 | gd_grab_keyboard(vc, "grab-on-hover"); |
5104a1f6 | 1600 | } |
5104a1f6 AL |
1601 | return TRUE; |
1602 | } | |
1603 | ||
e3500d1f GH |
1604 | static gboolean gd_leave_event(GtkWidget *widget, GdkEventCrossing *crossing, |
1605 | gpointer opaque) | |
5104a1f6 | 1606 | { |
e3500d1f GH |
1607 | VirtualConsole *vc = opaque; |
1608 | GtkDisplayState *s = vc->s; | |
5104a1f6 | 1609 | |
2884cf5b | 1610 | if (gd_grab_on_hover(s)) { |
4c638e2e | 1611 | gd_ungrab_keyboard(s); |
5104a1f6 | 1612 | } |
5104a1f6 AL |
1613 | return TRUE; |
1614 | } | |
1615 | ||
6db253ca | 1616 | static gboolean gd_focus_out_event(GtkWidget *widget, |
e3500d1f | 1617 | GdkEventCrossing *crossing, gpointer opaque) |
6db253ca | 1618 | { |
e3500d1f GH |
1619 | VirtualConsole *vc = opaque; |
1620 | GtkDisplayState *s = vc->s; | |
6db253ca JK |
1621 | |
1622 | gtk_release_modifiers(s); | |
6db253ca JK |
1623 | return TRUE; |
1624 | } | |
1625 | ||
1301e515 GH |
1626 | static gboolean gd_configure(GtkWidget *widget, |
1627 | GdkEventConfigure *cfg, gpointer opaque) | |
1628 | { | |
1629 | VirtualConsole *vc = opaque; | |
1301e515 | 1630 | |
925a0400 | 1631 | gd_set_ui_info(vc, cfg->width, cfg->height); |
1301e515 GH |
1632 | return FALSE; |
1633 | } | |
1634 | ||
d861def3 AL |
1635 | /** Virtual Console Callbacks **/ |
1636 | ||
ed1132e4 | 1637 | static GSList *gd_vc_menu_init(GtkDisplayState *s, VirtualConsole *vc, |
cdeb7090 | 1638 | int idx, GSList *group, GtkWidget *view_menu) |
ed1132e4 | 1639 | { |
cdeb7090 | 1640 | vc->menu_item = gtk_radio_menu_item_new_with_mnemonic(group, vc->label); |
277836c8 CR |
1641 | gtk_accel_group_connect(s->accel_group, GDK_KEY_1 + idx, |
1642 | HOTKEY_MODIFIERS, 0, | |
1643 | g_cclosure_new_swap(G_CALLBACK(gd_accel_switch_vc), vc, NULL)); | |
1644 | #if GTK_CHECK_VERSION(3, 8, 0) | |
1645 | gtk_accel_label_set_accel( | |
1646 | GTK_ACCEL_LABEL(gtk_bin_get_child(GTK_BIN(vc->menu_item))), | |
1647 | GDK_KEY_1 + idx, HOTKEY_MODIFIERS); | |
1648 | #endif | |
ed1132e4 GH |
1649 | |
1650 | g_signal_connect(vc->menu_item, "activate", | |
1651 | G_CALLBACK(gd_menu_switch_vc), s); | |
1652 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc->menu_item); | |
1653 | ||
277836c8 | 1654 | group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item)); |
ed1132e4 GH |
1655 | return group; |
1656 | } | |
1657 | ||
ee5f31e4 | 1658 | #if defined(CONFIG_VTE) |
44b31e0b MT |
1659 | static void gd_menu_copy(GtkMenuItem *item, void *opaque) |
1660 | { | |
1661 | GtkDisplayState *s = opaque; | |
1662 | VirtualConsole *vc = gd_vc_find_current(s); | |
1663 | ||
1664 | vte_terminal_copy_clipboard(VTE_TERMINAL(vc->vte.terminal)); | |
1665 | } | |
1666 | ||
0fb20d1c CR |
1667 | static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque) |
1668 | { | |
1669 | VirtualConsole *vc = opaque; | |
1670 | ||
1671 | if (gtk_adjustment_get_upper(adjustment) > | |
1672 | gtk_adjustment_get_page_size(adjustment)) { | |
271a25c0 | 1673 | gtk_widget_show(vc->vte.scrollbar); |
0fb20d1c | 1674 | } else { |
271a25c0 | 1675 | gtk_widget_hide(vc->vte.scrollbar); |
0fb20d1c CR |
1676 | } |
1677 | } | |
1678 | ||
d861def3 AL |
1679 | static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len) |
1680 | { | |
1681 | VirtualConsole *vc = chr->opaque; | |
1682 | ||
271a25c0 | 1683 | vte_terminal_feed(VTE_TERMINAL(vc->vte.terminal), (const char *)buf, len); |
d4370741 | 1684 | return len; |
d861def3 AL |
1685 | } |
1686 | ||
fba958c6 PB |
1687 | static void gd_vc_chr_set_echo(CharDriverState *chr, bool echo) |
1688 | { | |
1689 | VirtualConsole *vc = chr->opaque; | |
1690 | ||
1691 | vc->vte.echo = echo; | |
1692 | } | |
1693 | ||
d861def3 AL |
1694 | static int nb_vcs; |
1695 | static CharDriverState *vcs[MAX_VCS]; | |
1696 | ||
919e11f3 | 1697 | static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp) |
d861def3 | 1698 | { |
919e11f3 | 1699 | ChardevCommon *common = qapi_ChardevVC_base(vc); |
d861def3 AL |
1700 | CharDriverState *chr; |
1701 | ||
919e11f3 DB |
1702 | chr = qemu_chr_alloc(common, errp); |
1703 | if (!chr) { | |
1704 | return NULL; | |
1705 | } | |
1706 | ||
d861def3 | 1707 | chr->chr_write = gd_vc_chr_write; |
fba958c6 PB |
1708 | chr->chr_set_echo = gd_vc_chr_set_echo; |
1709 | ||
1710 | /* Temporary, until gd_vc_vte_init runs. */ | |
327d83ba | 1711 | chr->opaque = g_new0(VirtualConsole, 1); |
fba958c6 | 1712 | |
d861def3 AL |
1713 | vcs[nb_vcs++] = chr; |
1714 | ||
1715 | return chr; | |
1716 | } | |
1717 | ||
d4370741 CR |
1718 | static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size, |
1719 | gpointer user_data) | |
d861def3 | 1720 | { |
d4370741 | 1721 | VirtualConsole *vc = user_data; |
d861def3 | 1722 | |
fba958c6 PB |
1723 | if (vc->vte.echo) { |
1724 | VteTerminal *term = VTE_TERMINAL(vc->vte.terminal); | |
1725 | int i; | |
1726 | for (i = 0; i < size; i++) { | |
1727 | uint8_t c = text[i]; | |
1728 | if (c >= 128 || isprint(c)) { | |
1729 | /* 8-bit characters are considered printable. */ | |
1730 | vte_terminal_feed(term, &text[i], 1); | |
1731 | } else if (c == '\r' || c == '\n') { | |
1732 | vte_terminal_feed(term, "\r\n", 2); | |
1733 | } else { | |
1734 | char ctrl[2] = { '^', 0}; | |
1735 | ctrl[1] = text[i] ^ 64; | |
1736 | vte_terminal_feed(term, ctrl, 2); | |
1737 | } | |
1738 | } | |
1739 | } | |
1740 | ||
271a25c0 | 1741 | qemu_chr_be_write(vc->vte.chr, (uint8_t *)text, (unsigned int)size); |
d861def3 AL |
1742 | return TRUE; |
1743 | } | |
1744 | ||
ed1132e4 GH |
1745 | static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc, |
1746 | CharDriverState *chr, int idx, | |
e3500d1f | 1747 | GSList *group, GtkWidget *view_menu) |
d861def3 | 1748 | { |
d861def3 | 1749 | char buffer[32]; |
0fb20d1c CR |
1750 | GtkWidget *box; |
1751 | GtkWidget *scrollbar; | |
1752 | GtkAdjustment *vadjustment; | |
fba958c6 | 1753 | VirtualConsole *tmp_vc = chr->opaque; |
d861def3 | 1754 | |
e3500d1f | 1755 | vc->s = s; |
fba958c6 PB |
1756 | vc->vte.echo = tmp_vc->vte.echo; |
1757 | ||
ed1132e4 | 1758 | vc->vte.chr = chr; |
fba958c6 PB |
1759 | chr->opaque = vc; |
1760 | g_free(tmp_vc); | |
d861def3 | 1761 | |
ed1132e4 | 1762 | snprintf(buffer, sizeof(buffer), "vc%d", idx); |
cdeb7090 GH |
1763 | vc->label = g_strdup_printf("%s", vc->vte.chr->label |
1764 | ? vc->vte.chr->label : buffer); | |
1765 | group = gd_vc_menu_init(s, vc, idx, group, view_menu); | |
d861def3 | 1766 | |
271a25c0 GH |
1767 | vc->vte.terminal = vte_terminal_new(); |
1768 | g_signal_connect(vc->vte.terminal, "commit", G_CALLBACK(gd_vc_in), vc); | |
d861def3 | 1769 | |
fba958c6 PB |
1770 | /* The documentation says that the default is UTF-8, but actually it is |
1771 | * 7-bit ASCII at least in VTE 0.38. | |
1772 | */ | |
4d594233 | 1773 | #if VTE_CHECK_VERSION(0, 38, 0) |
fba958c6 PB |
1774 | vte_terminal_set_encoding(VTE_TERMINAL(vc->vte.terminal), "UTF-8", NULL); |
1775 | #else | |
1776 | vte_terminal_set_encoding(VTE_TERMINAL(vc->vte.terminal), "UTF-8"); | |
1777 | #endif | |
1778 | ||
271a25c0 | 1779 | vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc->vte.terminal), -1); |
82fc1809 GH |
1780 | vte_terminal_set_size(VTE_TERMINAL(vc->vte.terminal), |
1781 | VC_TERM_X_MIN, VC_TERM_Y_MIN); | |
d861def3 | 1782 | |
0fb20d1c | 1783 | #if VTE_CHECK_VERSION(0, 28, 0) && GTK_CHECK_VERSION(3, 0, 0) |
271a25c0 GH |
1784 | vadjustment = gtk_scrollable_get_vadjustment |
1785 | (GTK_SCROLLABLE(vc->vte.terminal)); | |
0fb20d1c | 1786 | #else |
271a25c0 | 1787 | vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc->vte.terminal)); |
0fb20d1c CR |
1788 | #endif |
1789 | ||
1790 | #if GTK_CHECK_VERSION(3, 0, 0) | |
1791 | box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2); | |
1792 | scrollbar = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, vadjustment); | |
1793 | #else | |
1794 | box = gtk_hbox_new(false, 2); | |
1795 | scrollbar = gtk_vscrollbar_new(vadjustment); | |
1796 | #endif | |
1797 | ||
271a25c0 | 1798 | gtk_box_pack_start(GTK_BOX(box), vc->vte.terminal, TRUE, TRUE, 0); |
0fb20d1c CR |
1799 | gtk_box_pack_start(GTK_BOX(box), scrollbar, FALSE, FALSE, 0); |
1800 | ||
271a25c0 GH |
1801 | vc->vte.box = box; |
1802 | vc->vte.scrollbar = scrollbar; | |
0fb20d1c CR |
1803 | |
1804 | g_signal_connect(vadjustment, "changed", | |
1805 | G_CALLBACK(gd_vc_adjustment_changed), vc); | |
d861def3 | 1806 | |
e3500d1f | 1807 | vc->type = GD_VC_VTE; |
271a25c0 | 1808 | vc->tab_item = box; |
9d677e1c | 1809 | vc->focus = vc->vte.terminal; |
271a25c0 | 1810 | gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), vc->tab_item, |
cdeb7090 | 1811 | gtk_label_new(vc->label)); |
d861def3 | 1812 | |
271a25c0 | 1813 | qemu_chr_be_generic_open(vc->vte.chr); |
d861def3 | 1814 | |
d861def3 | 1815 | return group; |
a4ccabcf AL |
1816 | } |
1817 | ||
ed1132e4 | 1818 | static void gd_vcs_init(GtkDisplayState *s, GSList *group, |
ee5f31e4 GH |
1819 | GtkWidget *view_menu) |
1820 | { | |
1821 | int i; | |
1822 | ||
1823 | for (i = 0; i < nb_vcs; i++) { | |
ed1132e4 GH |
1824 | VirtualConsole *vc = &s->vc[s->nb_vcs]; |
1825 | group = gd_vc_vte_init(s, vc, vcs[i], s->nb_vcs, group, view_menu); | |
ee5f31e4 GH |
1826 | s->nb_vcs++; |
1827 | } | |
1828 | } | |
1829 | #endif /* CONFIG_VTE */ | |
1830 | ||
a4ccabcf AL |
1831 | /** Window Creation **/ |
1832 | ||
e3500d1f GH |
1833 | static void gd_connect_vc_gfx_signals(VirtualConsole *vc) |
1834 | { | |
1835 | #if GTK_CHECK_VERSION(3, 0, 0) | |
1836 | g_signal_connect(vc->gfx.drawing_area, "draw", | |
1837 | G_CALLBACK(gd_draw_event), vc); | |
925a0400 GH |
1838 | #if defined(CONFIG_GTK_GL) |
1839 | if (display_opengl) { | |
1840 | /* wire up GtkGlArea events */ | |
1841 | g_signal_connect(vc->gfx.drawing_area, "render", | |
1842 | G_CALLBACK(gd_render_event), vc); | |
1843 | g_signal_connect(vc->gfx.drawing_area, "resize", | |
1844 | G_CALLBACK(gd_resize_event), vc); | |
1845 | } | |
1846 | #endif | |
e3500d1f GH |
1847 | #else |
1848 | g_signal_connect(vc->gfx.drawing_area, "expose-event", | |
1849 | G_CALLBACK(gd_expose_event), vc); | |
1850 | #endif | |
f8c223f6 GH |
1851 | if (qemu_console_is_graphic(vc->gfx.dcl.con)) { |
1852 | g_signal_connect(vc->gfx.drawing_area, "event", | |
1853 | G_CALLBACK(gd_event), vc); | |
1854 | g_signal_connect(vc->gfx.drawing_area, "button-press-event", | |
1855 | G_CALLBACK(gd_button_event), vc); | |
1856 | g_signal_connect(vc->gfx.drawing_area, "button-release-event", | |
1857 | G_CALLBACK(gd_button_event), vc); | |
1858 | g_signal_connect(vc->gfx.drawing_area, "scroll-event", | |
1859 | G_CALLBACK(gd_scroll_event), vc); | |
1860 | g_signal_connect(vc->gfx.drawing_area, "key-press-event", | |
1861 | G_CALLBACK(gd_key_event), vc); | |
1862 | g_signal_connect(vc->gfx.drawing_area, "key-release-event", | |
1863 | G_CALLBACK(gd_key_event), vc); | |
1864 | ||
1865 | g_signal_connect(vc->gfx.drawing_area, "enter-notify-event", | |
1866 | G_CALLBACK(gd_enter_event), vc); | |
1867 | g_signal_connect(vc->gfx.drawing_area, "leave-notify-event", | |
1868 | G_CALLBACK(gd_leave_event), vc); | |
1869 | g_signal_connect(vc->gfx.drawing_area, "focus-out-event", | |
1870 | G_CALLBACK(gd_focus_out_event), vc); | |
1301e515 GH |
1871 | g_signal_connect(vc->gfx.drawing_area, "configure-event", |
1872 | G_CALLBACK(gd_configure), vc); | |
f8c223f6 GH |
1873 | } else { |
1874 | g_signal_connect(vc->gfx.drawing_area, "key-press-event", | |
1875 | G_CALLBACK(gd_text_key_down), vc); | |
1876 | } | |
e3500d1f GH |
1877 | } |
1878 | ||
a4ccabcf AL |
1879 | static void gd_connect_signals(GtkDisplayState *s) |
1880 | { | |
1881 | g_signal_connect(s->show_tabs_item, "activate", | |
1882 | G_CALLBACK(gd_menu_show_tabs), s); | |
cdeb7090 GH |
1883 | g_signal_connect(s->untabify_item, "activate", |
1884 | G_CALLBACK(gd_menu_untabify), s); | |
a4ccabcf AL |
1885 | |
1886 | g_signal_connect(s->window, "delete-event", | |
1887 | G_CALLBACK(gd_window_close), s); | |
1888 | ||
30e8f22b JK |
1889 | g_signal_connect(s->pause_item, "activate", |
1890 | G_CALLBACK(gd_menu_pause), s); | |
1891 | g_signal_connect(s->reset_item, "activate", | |
1892 | G_CALLBACK(gd_menu_reset), s); | |
1893 | g_signal_connect(s->powerdown_item, "activate", | |
1894 | G_CALLBACK(gd_menu_powerdown), s); | |
a4ccabcf AL |
1895 | g_signal_connect(s->quit_item, "activate", |
1896 | G_CALLBACK(gd_menu_quit), s); | |
44b31e0b MT |
1897 | #if defined(CONFIG_VTE) |
1898 | g_signal_connect(s->copy_item, "activate", | |
1899 | G_CALLBACK(gd_menu_copy), s); | |
1900 | #endif | |
c6158483 AL |
1901 | g_signal_connect(s->full_screen_item, "activate", |
1902 | G_CALLBACK(gd_menu_full_screen), s); | |
1903 | g_signal_connect(s->zoom_in_item, "activate", | |
1904 | G_CALLBACK(gd_menu_zoom_in), s); | |
1905 | g_signal_connect(s->zoom_out_item, "activate", | |
1906 | G_CALLBACK(gd_menu_zoom_out), s); | |
1907 | g_signal_connect(s->zoom_fixed_item, "activate", | |
1908 | G_CALLBACK(gd_menu_zoom_fixed), s); | |
1909 | g_signal_connect(s->zoom_fit_item, "activate", | |
1910 | G_CALLBACK(gd_menu_zoom_fit), s); | |
5104a1f6 AL |
1911 | g_signal_connect(s->grab_item, "activate", |
1912 | G_CALLBACK(gd_menu_grab_input), s); | |
a4ccabcf AL |
1913 | g_signal_connect(s->notebook, "switch-page", |
1914 | G_CALLBACK(gd_change_page), s); | |
1915 | } | |
1916 | ||
400519d2 | 1917 | static GtkWidget *gd_create_menu_machine(GtkDisplayState *s) |
a4ccabcf | 1918 | { |
bf9b255f | 1919 | GtkWidget *machine_menu; |
a4ccabcf AL |
1920 | GtkWidget *separator; |
1921 | ||
bf9b255f | 1922 | machine_menu = gtk_menu_new(); |
400519d2 | 1923 | gtk_menu_set_accel_group(GTK_MENU(machine_menu), s->accel_group); |
30e8f22b JK |
1924 | |
1925 | s->pause_item = gtk_check_menu_item_new_with_mnemonic(_("_Pause")); | |
bf9b255f | 1926 | gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->pause_item); |
30e8f22b JK |
1927 | |
1928 | separator = gtk_separator_menu_item_new(); | |
bf9b255f | 1929 | gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), separator); |
30e8f22b | 1930 | |
9068f20d | 1931 | s->reset_item = gtk_menu_item_new_with_mnemonic(_("_Reset")); |
bf9b255f | 1932 | gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->reset_item); |
30e8f22b | 1933 | |
9068f20d | 1934 | s->powerdown_item = gtk_menu_item_new_with_mnemonic(_("Power _Down")); |
bf9b255f | 1935 | gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->powerdown_item); |
30e8f22b JK |
1936 | |
1937 | separator = gtk_separator_menu_item_new(); | |
bf9b255f | 1938 | gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), separator); |
a4ccabcf | 1939 | |
3d914488 | 1940 | s->quit_item = gtk_menu_item_new_with_mnemonic(_("_Quit")); |
a4ccabcf | 1941 | gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->quit_item), |
30e8f22b | 1942 | "<QEMU>/Machine/Quit"); |
3d914488 | 1943 | gtk_accel_map_add_entry("<QEMU>/Machine/Quit", |
db1da1f2 | 1944 | GDK_KEY_q, HOTKEY_MODIFIERS); |
bf9b255f | 1945 | gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu), s->quit_item); |
a4ccabcf | 1946 | |
bf9b255f AL |
1947 | return machine_menu; |
1948 | } | |
1949 | ||
e3500d1f | 1950 | static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, |
ed1132e4 | 1951 | QemuConsole *con, int idx, |
e3500d1f GH |
1952 | GSList *group, GtkWidget *view_menu) |
1953 | { | |
779ce88f | 1954 | vc->label = qemu_console_get_label(con); |
e3500d1f GH |
1955 | vc->s = s; |
1956 | vc->gfx.scale_x = 1.0; | |
1957 | vc->gfx.scale_y = 1.0; | |
1958 | ||
97edf3bd GH |
1959 | #if defined(CONFIG_OPENGL) |
1960 | if (display_opengl) { | |
925a0400 GH |
1961 | #if defined(CONFIG_GTK_GL) |
1962 | vc->gfx.drawing_area = gtk_gl_area_new(); | |
1963 | vc->gfx.dcl.ops = &dcl_gl_area_ops; | |
1964 | #else | |
1965 | vc->gfx.drawing_area = gtk_drawing_area_new(); | |
97edf3bd GH |
1966 | /* |
1967 | * gtk_widget_set_double_buffered() was deprecated in 3.14. | |
1968 | * It is required for opengl rendering on X11 though. A | |
1969 | * proper replacement (native opengl support) is only | |
1970 | * available in 3.16+. Silence the warning if possible. | |
1971 | */ | |
1972 | #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE | |
1973 | #pragma GCC diagnostic push | |
1974 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
1975 | #endif | |
1976 | gtk_widget_set_double_buffered(vc->gfx.drawing_area, FALSE); | |
1977 | #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE | |
1978 | #pragma GCC diagnostic pop | |
1979 | #endif | |
1980 | vc->gfx.dcl.ops = &dcl_egl_ops; | |
925a0400 | 1981 | #endif /* CONFIG_GTK_GL */ |
97edf3bd GH |
1982 | } else |
1983 | #endif | |
1984 | { | |
925a0400 | 1985 | vc->gfx.drawing_area = gtk_drawing_area_new(); |
97edf3bd GH |
1986 | vc->gfx.dcl.ops = &dcl_ops; |
1987 | } | |
1988 | ||
925a0400 GH |
1989 | |
1990 | gtk_widget_add_events(vc->gfx.drawing_area, | |
1991 | GDK_POINTER_MOTION_MASK | | |
1992 | GDK_BUTTON_PRESS_MASK | | |
1993 | GDK_BUTTON_RELEASE_MASK | | |
1994 | GDK_BUTTON_MOTION_MASK | | |
1995 | GDK_ENTER_NOTIFY_MASK | | |
1996 | GDK_LEAVE_NOTIFY_MASK | | |
1997 | GDK_SCROLL_MASK | | |
1998 | GDK_KEY_PRESS_MASK); | |
1999 | gtk_widget_set_can_focus(vc->gfx.drawing_area, TRUE); | |
2000 | ||
2001 | vc->type = GD_VC_GFX; | |
2002 | vc->tab_item = vc->gfx.drawing_area; | |
2003 | vc->focus = vc->gfx.drawing_area; | |
2004 | gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), | |
2005 | vc->tab_item, gtk_label_new(vc->label)); | |
2006 | ||
e3500d1f GH |
2007 | vc->gfx.dcl.con = con; |
2008 | register_displaychangelistener(&vc->gfx.dcl); | |
2009 | ||
f8c223f6 GH |
2010 | gd_connect_vc_gfx_signals(vc); |
2011 | group = gd_vc_menu_init(s, vc, idx, group, view_menu); | |
2012 | ||
1301e515 GH |
2013 | if (dpy_ui_info_supported(vc->gfx.dcl.con)) { |
2014 | gtk_menu_item_activate(GTK_MENU_ITEM(s->zoom_fit_item)); | |
1d73cd78 | 2015 | s->free_scale = true; |
1301e515 GH |
2016 | } |
2017 | ||
e3500d1f GH |
2018 | return group; |
2019 | } | |
2020 | ||
400519d2 | 2021 | static GtkWidget *gd_create_menu_view(GtkDisplayState *s) |
bf9b255f AL |
2022 | { |
2023 | GSList *group = NULL; | |
2024 | GtkWidget *view_menu; | |
2025 | GtkWidget *separator; | |
ed1132e4 GH |
2026 | QemuConsole *con; |
2027 | int vc; | |
bf9b255f AL |
2028 | |
2029 | view_menu = gtk_menu_new(); | |
400519d2 | 2030 | gtk_menu_set_accel_group(GTK_MENU(view_menu), s->accel_group); |
a4ccabcf | 2031 | |
3d914488 | 2032 | s->full_screen_item = gtk_menu_item_new_with_mnemonic(_("_Fullscreen")); |
95414914 | 2033 | |
44b31e0b MT |
2034 | #if defined(CONFIG_VTE) |
2035 | s->copy_item = gtk_menu_item_new_with_mnemonic(_("_Copy")); | |
2036 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->copy_item); | |
2037 | #endif | |
2038 | ||
95414914 CR |
2039 | gtk_accel_group_connect(s->accel_group, GDK_KEY_f, HOTKEY_MODIFIERS, 0, |
2040 | g_cclosure_new_swap(G_CALLBACK(gd_accel_full_screen), s, NULL)); | |
2041 | #if GTK_CHECK_VERSION(3, 8, 0) | |
2042 | gtk_accel_label_set_accel( | |
2043 | GTK_ACCEL_LABEL(gtk_bin_get_child(GTK_BIN(s->full_screen_item))), | |
2044 | GDK_KEY_f, HOTKEY_MODIFIERS); | |
2045 | #endif | |
bf9b255f | 2046 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->full_screen_item); |
c6158483 AL |
2047 | |
2048 | separator = gtk_separator_menu_item_new(); | |
bf9b255f | 2049 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator); |
c6158483 | 2050 | |
3d914488 | 2051 | s->zoom_in_item = gtk_menu_item_new_with_mnemonic(_("Zoom _In")); |
c6158483 AL |
2052 | gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_in_item), |
2053 | "<QEMU>/View/Zoom In"); | |
b1e749c0 JK |
2054 | gtk_accel_map_add_entry("<QEMU>/View/Zoom In", GDK_KEY_plus, |
2055 | HOTKEY_MODIFIERS); | |
bf9b255f | 2056 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_in_item); |
c6158483 | 2057 | |
3d914488 | 2058 | s->zoom_out_item = gtk_menu_item_new_with_mnemonic(_("Zoom _Out")); |
c6158483 AL |
2059 | gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_out_item), |
2060 | "<QEMU>/View/Zoom Out"); | |
b1e749c0 JK |
2061 | gtk_accel_map_add_entry("<QEMU>/View/Zoom Out", GDK_KEY_minus, |
2062 | HOTKEY_MODIFIERS); | |
bf9b255f | 2063 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_out_item); |
c6158483 | 2064 | |
3d914488 | 2065 | s->zoom_fixed_item = gtk_menu_item_new_with_mnemonic(_("Best _Fit")); |
c6158483 AL |
2066 | gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_fixed_item), |
2067 | "<QEMU>/View/Zoom Fixed"); | |
b1e749c0 JK |
2068 | gtk_accel_map_add_entry("<QEMU>/View/Zoom Fixed", GDK_KEY_0, |
2069 | HOTKEY_MODIFIERS); | |
bf9b255f | 2070 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_fixed_item); |
c6158483 | 2071 | |
834574ea | 2072 | s->zoom_fit_item = gtk_check_menu_item_new_with_mnemonic(_("Zoom To _Fit")); |
bf9b255f | 2073 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_fit_item); |
c6158483 AL |
2074 | |
2075 | separator = gtk_separator_menu_item_new(); | |
bf9b255f | 2076 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator); |
c6158483 | 2077 | |
834574ea | 2078 | s->grab_on_hover_item = gtk_check_menu_item_new_with_mnemonic(_("Grab On _Hover")); |
bf9b255f | 2079 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_on_hover_item); |
5104a1f6 | 2080 | |
834574ea | 2081 | s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab Input")); |
5104a1f6 AL |
2082 | gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item), |
2083 | "<QEMU>/View/Grab Input"); | |
b1e749c0 JK |
2084 | gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g, |
2085 | HOTKEY_MODIFIERS); | |
bf9b255f | 2086 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_item); |
5104a1f6 | 2087 | |
a4ccabcf | 2088 | separator = gtk_separator_menu_item_new(); |
bf9b255f | 2089 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator); |
a4ccabcf | 2090 | |
e3500d1f | 2091 | /* gfx */ |
ed1132e4 GH |
2092 | for (vc = 0;; vc++) { |
2093 | con = qemu_console_lookup_by_index(vc); | |
f8c223f6 | 2094 | if (!con) { |
ed1132e4 GH |
2095 | break; |
2096 | } | |
2097 | group = gd_vc_gfx_init(s, &s->vc[vc], con, | |
2098 | vc, group, view_menu); | |
2099 | s->nb_vcs++; | |
2100 | } | |
a4ccabcf | 2101 | |
ee5f31e4 | 2102 | #if defined(CONFIG_VTE) |
e3500d1f | 2103 | /* vte */ |
ed1132e4 | 2104 | gd_vcs_init(s, group, view_menu); |
ee5f31e4 | 2105 | #endif |
d861def3 | 2106 | |
a4ccabcf | 2107 | separator = gtk_separator_menu_item_new(); |
bf9b255f | 2108 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator); |
a4ccabcf | 2109 | |
834574ea | 2110 | s->show_tabs_item = gtk_check_menu_item_new_with_mnemonic(_("Show _Tabs")); |
bf9b255f | 2111 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->show_tabs_item); |
a4ccabcf | 2112 | |
cdeb7090 GH |
2113 | s->untabify_item = gtk_menu_item_new_with_mnemonic(_("Detach Tab")); |
2114 | gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->untabify_item); | |
2115 | ||
bf9b255f AL |
2116 | return view_menu; |
2117 | } | |
2118 | ||
2119 | static void gd_create_menus(GtkDisplayState *s) | |
2120 | { | |
400519d2 CR |
2121 | s->accel_group = gtk_accel_group_new(); |
2122 | s->machine_menu = gd_create_menu_machine(s); | |
2123 | s->view_menu = gd_create_menu_view(s); | |
bf9b255f AL |
2124 | |
2125 | s->machine_menu_item = gtk_menu_item_new_with_mnemonic(_("_Machine")); | |
30e8f22b JK |
2126 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->machine_menu_item), |
2127 | s->machine_menu); | |
2128 | gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->machine_menu_item); | |
a4ccabcf | 2129 | |
bf9b255f | 2130 | s->view_menu_item = gtk_menu_item_new_with_mnemonic(_("_View")); |
a4ccabcf AL |
2131 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->view_menu_item), s->view_menu); |
2132 | gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->view_menu_item); | |
bf9b255f | 2133 | |
400519d2 CR |
2134 | g_object_set_data(G_OBJECT(s->window), "accel_group", s->accel_group); |
2135 | gtk_window_add_accel_group(GTK_WINDOW(s->window), s->accel_group); | |
a4ccabcf AL |
2136 | } |
2137 | ||
3158a348 BR |
2138 | static void gd_set_keycode_type(GtkDisplayState *s) |
2139 | { | |
0a337ed0 | 2140 | #ifdef GDK_WINDOWING_X11 |
3158a348 | 2141 | GdkDisplay *display = gtk_widget_get_display(s->window); |
0a337ed0 GH |
2142 | if (GDK_IS_X11_DISPLAY(display)) { |
2143 | Display *x11_display = gdk_x11_display_get_xdisplay(display); | |
2144 | XkbDescPtr desc = XkbGetKeyboard(x11_display, XkbGBN_AllComponentsMask, | |
2145 | XkbUseCoreKbd); | |
2146 | char *keycodes = NULL; | |
2147 | ||
2148 | if (desc && desc->names) { | |
2149 | keycodes = XGetAtomName(x11_display, desc->names->keycodes); | |
2150 | } | |
2151 | if (keycodes == NULL) { | |
2152 | fprintf(stderr, "could not lookup keycode name\n"); | |
2153 | } else if (strstart(keycodes, "evdev", NULL)) { | |
2154 | s->has_evdev = true; | |
2155 | } else if (!strstart(keycodes, "xfree86", NULL)) { | |
2156 | fprintf(stderr, "unknown keycodes `%s', please report to " | |
2157 | "qemu-devel@nongnu.org\n", keycodes); | |
2158 | } | |
84961407 CF |
2159 | |
2160 | if (desc) { | |
2161 | XkbFreeKeyboard(desc, XkbGBN_AllComponentsMask, True); | |
2162 | } | |
2163 | if (keycodes) { | |
2164 | XFree(keycodes); | |
2165 | } | |
3158a348 BR |
2166 | } |
2167 | #endif | |
2168 | } | |
2169 | ||
060ab763 GH |
2170 | static gboolean gtkinit; |
2171 | ||
881249c7 | 2172 | void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover) |
a4ccabcf | 2173 | { |
3d4da9d6 HP |
2174 | VirtualConsole *vc; |
2175 | ||
a4ccabcf | 2176 | GtkDisplayState *s = g_malloc0(sizeof(*s)); |
d819cdcc | 2177 | char *filename; |
63c67b6d | 2178 | GdkDisplay *window_display; |
a4ccabcf | 2179 | |
060ab763 GH |
2180 | if (!gtkinit) { |
2181 | fprintf(stderr, "gtk initialization failed\n"); | |
2182 | exit(1); | |
2183 | } | |
2184 | ||
a4ccabcf | 2185 | s->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
51572ab0 DB |
2186 | #if GTK_CHECK_VERSION(3, 2, 0) |
2187 | s->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); | |
2188 | #else | |
a4ccabcf | 2189 | s->vbox = gtk_vbox_new(FALSE, 0); |
51572ab0 | 2190 | #endif |
a4ccabcf | 2191 | s->notebook = gtk_notebook_new(); |
a4ccabcf AL |
2192 | s->menu_bar = gtk_menu_bar_new(); |
2193 | ||
c6158483 | 2194 | s->free_scale = FALSE; |
a4ccabcf | 2195 | |
2cb5d2a4 AG |
2196 | /* LC_MESSAGES only. See early_gtk_display_init() for details */ |
2197 | setlocale(LC_MESSAGES, ""); | |
834574ea AL |
2198 | bindtextdomain("qemu", CONFIG_QEMU_LOCALEDIR); |
2199 | textdomain("qemu"); | |
2200 | ||
63c67b6d HR |
2201 | window_display = gtk_widget_get_display(s->window); |
2202 | s->null_cursor = gdk_cursor_new_for_display(window_display, | |
2203 | GDK_BLANK_CURSOR); | |
a4ccabcf AL |
2204 | |
2205 | s->mouse_mode_notifier.notify = gd_mouse_mode_change; | |
2206 | qemu_add_mouse_mode_change_notifier(&s->mouse_mode_notifier); | |
2207 | qemu_add_vm_change_state_handler(gd_change_runstate, s); | |
2208 | ||
f7da9c17 | 2209 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "qemu_logo_no_text.svg"); |
d819cdcc SW |
2210 | if (filename) { |
2211 | GError *error = NULL; | |
2212 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename, &error); | |
2213 | if (pixbuf) { | |
2214 | gtk_window_set_icon(GTK_WINDOW(s->window), pixbuf); | |
2215 | } else { | |
2216 | g_error_free(error); | |
2217 | } | |
2218 | g_free(filename); | |
2219 | } | |
2220 | ||
a4ccabcf AL |
2221 | gd_create_menus(s); |
2222 | ||
2223 | gd_connect_signals(s); | |
2224 | ||
a4ccabcf AL |
2225 | gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE); |
2226 | gtk_notebook_set_show_border(GTK_NOTEBOOK(s->notebook), FALSE); | |
2227 | ||
a4ccabcf AL |
2228 | gd_update_caption(s); |
2229 | ||
2230 | gtk_box_pack_start(GTK_BOX(s->vbox), s->menu_bar, FALSE, TRUE, 0); | |
2231 | gtk_box_pack_start(GTK_BOX(s->vbox), s->notebook, TRUE, TRUE, 0); | |
2232 | ||
2233 | gtk_container_add(GTK_CONTAINER(s->window), s->vbox); | |
2234 | ||
2235 | gtk_widget_show_all(s->window); | |
2236 | ||
6fa27697 GH |
2237 | #ifdef VTE_RESIZE_HACK |
2238 | { | |
2239 | VirtualConsole *cur = gd_vc_find_current(s); | |
b310a2a6 FZ |
2240 | if (cur) { |
2241 | int i; | |
2242 | ||
2243 | for (i = 0; i < s->nb_vcs; i++) { | |
2244 | VirtualConsole *vc = &s->vc[i]; | |
2245 | if (vc && vc->type == GD_VC_VTE && vc != cur) { | |
2246 | gtk_widget_hide(vc->vte.terminal); | |
2247 | } | |
6fa27697 | 2248 | } |
b310a2a6 | 2249 | gd_update_windowsize(cur); |
6fa27697 | 2250 | } |
6fa27697 GH |
2251 | } |
2252 | #endif | |
2253 | ||
3d4da9d6 HP |
2254 | vc = gd_vc_find_current(s); |
2255 | gtk_widget_set_sensitive(s->view_menu, vc != NULL); | |
a0815632 SH |
2256 | #ifdef CONFIG_VTE |
2257 | gtk_widget_set_sensitive(s->copy_item, | |
3d4da9d6 | 2258 | vc && vc->type == GD_VC_VTE); |
a0815632 SH |
2259 | #endif |
2260 | ||
787ba4f0 PW |
2261 | if (full_screen) { |
2262 | gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item)); | |
2263 | } | |
881249c7 JK |
2264 | if (grab_on_hover) { |
2265 | gtk_menu_item_activate(GTK_MENU_ITEM(s->grab_on_hover_item)); | |
2266 | } | |
787ba4f0 | 2267 | |
3158a348 | 2268 | gd_set_keycode_type(s); |
a4ccabcf | 2269 | } |
ee5f31e4 | 2270 | |
97edf3bd | 2271 | void early_gtk_display_init(int opengl) |
ee5f31e4 | 2272 | { |
2cb5d2a4 AG |
2273 | /* The QEMU code relies on the assumption that it's always run in |
2274 | * the C locale. Therefore it is not prepared to deal with | |
2275 | * operations that produce different results depending on the | |
2276 | * locale, such as printf's formatting of decimal numbers, and | |
2277 | * possibly others. | |
2278 | * | |
2279 | * Since GTK+ calls setlocale() by default -importing the locale | |
2280 | * settings from the environment- we must prevent it from doing so | |
2281 | * using gtk_disable_setlocale(). | |
2282 | * | |
2283 | * QEMU's GTK+ UI, however, _does_ have translations for some of | |
2284 | * the menu items. As a trade-off between a functionally correct | |
2285 | * QEMU and a fully internationalized UI we support importing | |
2286 | * LC_MESSAGES from the environment (see the setlocale() call | |
2287 | * earlier in this file). This allows us to display translated | |
2288 | * messages leaving everything else untouched. | |
2289 | */ | |
2290 | gtk_disable_setlocale(); | |
060ab763 GH |
2291 | gtkinit = gtk_init_check(NULL, NULL); |
2292 | if (!gtkinit) { | |
2293 | /* don't exit yet, that'll break -help */ | |
2294 | return; | |
2295 | } | |
97edf3bd GH |
2296 | |
2297 | switch (opengl) { | |
2298 | case -1: /* default */ | |
2299 | case 0: /* off */ | |
2300 | break; | |
2301 | case 1: /* on */ | |
2302 | #if defined(CONFIG_OPENGL) | |
925a0400 GH |
2303 | #if defined(CONFIG_GTK_GL) |
2304 | gtk_gl_area_init(); | |
2305 | #else | |
97edf3bd | 2306 | gtk_egl_init(); |
925a0400 | 2307 | #endif |
97edf3bd GH |
2308 | #endif |
2309 | break; | |
2310 | default: | |
2311 | g_assert_not_reached(); | |
2312 | break; | |
2313 | } | |
2314 | ||
ee5f31e4 GH |
2315 | #if defined(CONFIG_VTE) |
2316 | register_vc_handler(gd_vc_handler); | |
2317 | #endif | |
2318 | } |