4 * Copyright IBM, Corp. 2012
7 * Anthony Liguori <aliguori@us.ibm.com>
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.
12 * Portions from gtk-vnc:
16 * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
17 * Copyright (C) 2009-2010 Daniel P. Berrange <dan@berrange.com>
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.
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.
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
34 #define GETTEXT_PACKAGE "qemu"
35 #define LOCALEDIR "po"
38 # define _WIN32_WINNT 0x0601 /* needed to get definition of MAPVK_VK_TO_VSC */
41 #include "qemu-common.h"
43 #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
44 /* Work around an -Wstrict-prototypes warning in GTK headers */
45 #pragma GCC diagnostic push
46 #pragma GCC diagnostic ignored "-Wstrict-prototypes"
49 #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
50 #pragma GCC diagnostic pop
54 #include <gdk/gdkkeysyms.h>
55 #include <glib/gi18n.h>
57 #if defined(CONFIG_VTE)
63 #include "ui/console.h"
65 #include "sysemu/sysemu.h"
66 #include "qmp-commands.h"
69 #include "sysemu/char.h"
73 #if !defined(CONFIG_VTE)
74 # define VTE_CHECK_VERSION(a, b, c) 0
77 /* Compatibility define to let us build on both Gtk2 and Gtk3 */
78 #if GTK_CHECK_VERSION(3, 0, 0)
79 static inline void gdk_drawable_get_size(GdkWindow
*w
, gint
*ww
, gint
*wh
)
81 *ww
= gdk_window_get_width(w
);
82 *wh
= gdk_window_get_height(w
);
86 #if !GTK_CHECK_VERSION(2, 20, 0)
87 #define gtk_widget_get_realized(widget) GTK_WIDGET_REALIZED(widget)
91 #define GDK_KEY_0 GDK_0
92 #define GDK_KEY_1 GDK_1
93 #define GDK_KEY_2 GDK_2
94 #define GDK_KEY_f GDK_f
95 #define GDK_KEY_g GDK_g
96 #define GDK_KEY_plus GDK_plus
97 #define GDK_KEY_minus GDK_minus
100 #define HOTKEY_MODIFIERS (GDK_CONTROL_MASK | GDK_MOD1_MASK)
101 #define IGNORE_MODIFIER_MASK \
102 (GDK_MODIFIER_MASK & ~(GDK_LOCK_MASK | GDK_MOD2_MASK))
104 static const int modifier_keycode
[] = {
105 /* shift, control, alt keys, meta keys, both left & right */
106 0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xdb, 0xdd,
109 typedef struct VirtualConsole
111 GtkWidget
*menu_item
;
113 #if defined(CONFIG_VTE)
114 GtkWidget
*scrolled_window
;
115 CharDriverState
*chr
;
120 typedef struct GtkDisplayState
126 GtkAccelGroup
*accel_group
;
128 GtkWidget
*machine_menu_item
;
129 GtkWidget
*machine_menu
;
130 GtkWidget
*pause_item
;
131 GtkWidget
*reset_item
;
132 GtkWidget
*powerdown_item
;
133 GtkWidget
*quit_item
;
135 GtkWidget
*view_menu_item
;
136 GtkWidget
*view_menu
;
137 GtkWidget
*full_screen_item
;
138 GtkWidget
*zoom_in_item
;
139 GtkWidget
*zoom_out_item
;
140 GtkWidget
*zoom_fixed_item
;
141 GtkWidget
*zoom_fit_item
;
142 GtkWidget
*grab_item
;
143 GtkWidget
*grab_on_hover_item
;
147 VirtualConsole vc
[MAX_VCS
];
149 GtkWidget
*show_tabs_item
;
153 GtkWidget
*drawing_area
;
154 cairo_surface_t
*surface
;
155 pixman_image_t
*convert
;
156 DisplayChangeListener dcl
;
167 gboolean full_screen
;
169 GdkCursor
*null_cursor
;
170 Notifier mouse_mode_notifier
;
173 bool external_pause_update
;
175 bool modifier_pressed
[ARRAY_SIZE(modifier_keycode
)];
178 static GtkDisplayState
*global_state
;
180 /** Utility Functions **/
182 static bool gd_is_grab_active(GtkDisplayState
*s
)
184 return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s
->grab_item
));
187 static bool gd_grab_on_hover(GtkDisplayState
*s
)
189 return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s
->grab_on_hover_item
));
192 static bool gd_on_vga(GtkDisplayState
*s
)
194 return gtk_notebook_get_current_page(GTK_NOTEBOOK(s
->notebook
)) == 0;
197 static void gd_update_cursor(GtkDisplayState
*s
, gboolean override
)
202 window
= gtk_widget_get_window(GTK_WIDGET(s
->drawing_area
));
204 on_vga
= gd_on_vga(s
);
206 if ((override
|| on_vga
) &&
207 (s
->full_screen
|| qemu_input_is_absolute() || gd_is_grab_active(s
))) {
208 gdk_window_set_cursor(window
, s
->null_cursor
);
210 gdk_window_set_cursor(window
, NULL
);
214 static void gd_update_caption(GtkDisplayState
*s
)
216 const char *status
= "";
218 const char *grab
= "";
219 bool is_paused
= !runstate_is_running();
221 if (gd_is_grab_active(s
)) {
222 grab
= _(" - Press Ctrl+Alt+G to release grab");
226 status
= _(" [Paused]");
228 s
->external_pause_update
= true;
229 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s
->pause_item
),
231 s
->external_pause_update
= false;
234 title
= g_strdup_printf("QEMU (%s)%s%s", qemu_name
, status
, grab
);
236 title
= g_strdup_printf("QEMU%s%s", status
, grab
);
239 gtk_window_set_title(GTK_WINDOW(s
->window
), title
);
244 static void gd_update_windowsize(GtkDisplayState
*s
)
246 if (!s
->full_screen
) {
261 gtk_widget_set_size_request(s
->drawing_area
,
262 surface_width(s
->ds
) * s
->scale_x
,
263 surface_height(s
->ds
) * s
->scale_y
);
264 #if GTK_CHECK_VERSION(3, 0, 0)
265 gtk_widget_get_preferred_size(s
->vbox
, NULL
, &req
);
267 gtk_widget_size_request(s
->vbox
, &req
);
270 gtk_window_resize(GTK_WINDOW(s
->window
),
271 req
.width
* sx
, req
.height
* sy
);
275 static void gd_update_full_redraw(GtkDisplayState
*s
)
278 gdk_drawable_get_size(gtk_widget_get_window(s
->drawing_area
), &ww
, &wh
);
279 gtk_widget_queue_draw_area(s
->drawing_area
, 0, 0, ww
, wh
);
282 static void gtk_release_modifiers(GtkDisplayState
*s
)
289 for (i
= 0; i
< ARRAY_SIZE(modifier_keycode
); i
++) {
290 keycode
= modifier_keycode
[i
];
291 if (!s
->modifier_pressed
[i
]) {
294 qemu_input_event_send_key_number(s
->dcl
.con
, keycode
, false);
295 s
->modifier_pressed
[i
] = false;
299 /** DisplayState Callbacks **/
301 static void gd_update(DisplayChangeListener
*dcl
,
302 int x
, int y
, int w
, int h
)
304 GtkDisplayState
*s
= container_of(dcl
, GtkDisplayState
, dcl
);
310 trace_gd_update(x
, y
, w
, h
);
313 pixman_image_composite(PIXMAN_OP_SRC
, s
->ds
->image
, NULL
, s
->convert
,
314 x
, y
, 0, 0, x
, y
, w
, h
);
317 x1
= floor(x
* s
->scale_x
);
318 y1
= floor(y
* s
->scale_y
);
320 x2
= ceil(x
* s
->scale_x
+ w
* s
->scale_x
);
321 y2
= ceil(y
* s
->scale_y
+ h
* s
->scale_y
);
323 fbw
= surface_width(s
->ds
) * s
->scale_x
;
324 fbh
= surface_height(s
->ds
) * s
->scale_y
;
326 gdk_drawable_get_size(gtk_widget_get_window(s
->drawing_area
), &ww
, &wh
);
336 gtk_widget_queue_draw_area(s
->drawing_area
, mx
+ x1
, my
+ y1
, (x2
- x1
), (y2
- y1
));
339 static void gd_refresh(DisplayChangeListener
*dcl
)
341 graphic_hw_update(dcl
->con
);
344 #if GTK_CHECK_VERSION(3, 0, 0)
345 static void gd_mouse_set(DisplayChangeListener
*dcl
,
346 int x
, int y
, int visible
)
348 GtkDisplayState
*s
= container_of(dcl
, GtkDisplayState
, dcl
);
350 GdkDeviceManager
*mgr
;
353 if (qemu_input_is_absolute()) {
357 dpy
= gtk_widget_get_display(s
->drawing_area
);
358 mgr
= gdk_display_get_device_manager(dpy
);
359 gdk_window_get_root_coords(gtk_widget_get_window(s
->drawing_area
),
360 x
, y
, &x_root
, &y_root
);
361 gdk_device_warp(gdk_device_manager_get_client_pointer(mgr
),
362 gtk_widget_get_screen(s
->drawing_area
),
366 static void gd_mouse_set(DisplayChangeListener
*dcl
,
367 int x
, int y
, int visible
)
369 GtkDisplayState
*s
= container_of(dcl
, GtkDisplayState
, dcl
);
372 if (qemu_input_is_absolute()) {
376 gdk_window_get_root_coords(gtk_widget_get_window(s
->drawing_area
),
377 x
, y
, &x_root
, &y_root
);
378 gdk_display_warp_pointer(gtk_widget_get_display(s
->drawing_area
),
379 gtk_widget_get_screen(s
->drawing_area
),
384 static void gd_cursor_define(DisplayChangeListener
*dcl
,
387 GtkDisplayState
*s
= container_of(dcl
, GtkDisplayState
, dcl
);
391 pixbuf
= gdk_pixbuf_new_from_data((guchar
*)(c
->data
),
392 GDK_COLORSPACE_RGB
, true, 8,
393 c
->width
, c
->height
, c
->width
* 4,
395 cursor
= gdk_cursor_new_from_pixbuf(gtk_widget_get_display(s
->drawing_area
),
396 pixbuf
, c
->hot_x
, c
->hot_y
);
397 gdk_window_set_cursor(gtk_widget_get_window(s
->drawing_area
), cursor
);
398 g_object_unref(pixbuf
);
399 #if !GTK_CHECK_VERSION(3, 0, 0)
400 gdk_cursor_unref(cursor
);
402 g_object_unref(cursor
);
406 static void gd_switch(DisplayChangeListener
*dcl
,
407 DisplaySurface
*surface
)
409 GtkDisplayState
*s
= container_of(dcl
, GtkDisplayState
, dcl
);
412 trace_gd_switch(surface_width(surface
), surface_height(surface
));
415 cairo_surface_destroy(s
->surface
);
419 surface_width(s
->ds
) == surface_width(surface
) &&
420 surface_height(s
->ds
) == surface_height(surface
)) {
426 pixman_image_unref(s
->convert
);
430 if (surface
->format
== PIXMAN_x8r8g8b8
) {
432 * PIXMAN_x8r8g8b8 == CAIRO_FORMAT_RGB24
434 * No need to convert, use surface directly. Should be the
435 * common case as this is qemu_default_pixelformat(32) too.
437 s
->surface
= cairo_image_surface_create_for_data
438 (surface_data(surface
),
440 surface_width(surface
),
441 surface_height(surface
),
442 surface_stride(surface
));
444 /* Must convert surface, use pixman to do it. */
445 s
->convert
= pixman_image_create_bits(PIXMAN_x8r8g8b8
,
446 surface_width(surface
),
447 surface_height(surface
),
449 s
->surface
= cairo_image_surface_create_for_data
450 ((void *)pixman_image_get_data(s
->convert
),
452 pixman_image_get_width(s
->convert
),
453 pixman_image_get_height(s
->convert
),
454 pixman_image_get_stride(s
->convert
));
455 pixman_image_composite(PIXMAN_OP_SRC
, s
->ds
->image
, NULL
, s
->convert
,
457 pixman_image_get_width(s
->convert
),
458 pixman_image_get_height(s
->convert
));
462 gd_update_windowsize(s
);
464 gd_update_full_redraw(s
);
470 static void gd_change_runstate(void *opaque
, int running
, RunState state
)
472 GtkDisplayState
*s
= opaque
;
474 gd_update_caption(s
);
477 static void gd_mouse_mode_change(Notifier
*notify
, void *data
)
479 gd_update_cursor(container_of(notify
, GtkDisplayState
, mouse_mode_notifier
),
485 static gboolean
gd_window_key_event(GtkWidget
*widget
, GdkEventKey
*key
, void *opaque
)
487 GtkDisplayState
*s
= opaque
;
488 gboolean handled
= FALSE
;
490 if (!gd_is_grab_active(s
) ||
491 (key
->state
& IGNORE_MODIFIER_MASK
) == HOTKEY_MODIFIERS
) {
492 handled
= gtk_window_activate_key(GTK_WINDOW(widget
), key
);
495 gtk_release_modifiers(s
);
497 handled
= gtk_window_propagate_key_event(GTK_WINDOW(widget
), key
);
503 static gboolean
gd_window_close(GtkWidget
*widget
, GdkEvent
*event
,
506 GtkDisplayState
*s
= opaque
;
509 unregister_displaychangelistener(&s
->dcl
);
517 static gboolean
gd_draw_event(GtkWidget
*widget
, cairo_t
*cr
, void *opaque
)
519 GtkDisplayState
*s
= opaque
;
524 if (!gtk_widget_get_realized(widget
)) {
528 fbw
= surface_width(s
->ds
);
529 fbh
= surface_height(s
->ds
);
531 gdk_drawable_get_size(gtk_widget_get_window(widget
), &ww
, &wh
);
533 if (s
->full_screen
) {
534 s
->scale_x
= (double)ww
/ fbw
;
535 s
->scale_y
= (double)wh
/ fbh
;
536 } else if (s
->free_scale
) {
539 sx
= (double)ww
/ fbw
;
540 sy
= (double)wh
/ fbh
;
542 s
->scale_x
= s
->scale_y
= MIN(sx
, sy
);
556 cairo_rectangle(cr
, 0, 0, ww
, wh
);
558 /* Optionally cut out the inner area where the pixmap
559 will be drawn. This avoids 'flashing' since we're
560 not double-buffering. Note we're using the undocumented
561 behaviour of drawing the rectangle from right to left
562 to cut out the whole */
563 cairo_rectangle(cr
, mx
+ fbw
, my
,
567 cairo_scale(cr
, s
->scale_x
, s
->scale_y
);
568 cairo_set_source_surface(cr
, s
->surface
, mx
/ s
->scale_x
, my
/ s
->scale_y
);
574 #if !GTK_CHECK_VERSION(3, 0, 0)
575 static gboolean
gd_expose_event(GtkWidget
*widget
, GdkEventExpose
*expose
,
581 cr
= gdk_cairo_create(gtk_widget_get_window(widget
));
586 expose
->area
.height
);
589 ret
= gd_draw_event(widget
, cr
, opaque
);
597 static gboolean
gd_motion_event(GtkWidget
*widget
, GdkEventMotion
*motion
,
600 GtkDisplayState
*s
= opaque
;
606 fbw
= surface_width(s
->ds
) * s
->scale_x
;
607 fbh
= surface_height(s
->ds
) * s
->scale_y
;
609 gdk_drawable_get_size(gtk_widget_get_window(s
->drawing_area
), &ww
, &wh
);
619 x
= (motion
->x
- mx
) / s
->scale_x
;
620 y
= (motion
->y
- my
) / s
->scale_y
;
622 if (qemu_input_is_absolute()) {
623 if (x
< 0 || y
< 0 ||
624 x
>= surface_width(s
->ds
) ||
625 y
>= surface_height(s
->ds
)) {
628 qemu_input_queue_abs(s
->dcl
.con
, INPUT_AXIS_X
, x
,
629 surface_width(s
->ds
));
630 qemu_input_queue_abs(s
->dcl
.con
, INPUT_AXIS_Y
, y
,
631 surface_height(s
->ds
));
632 qemu_input_event_sync();
633 } else if (s
->last_set
&& gd_is_grab_active(s
)) {
634 qemu_input_queue_rel(s
->dcl
.con
, INPUT_AXIS_X
, x
- s
->last_x
);
635 qemu_input_queue_rel(s
->dcl
.con
, INPUT_AXIS_Y
, y
- s
->last_y
);
636 qemu_input_event_sync();
642 if (!qemu_input_is_absolute() && gd_is_grab_active(s
)) {
643 GdkScreen
*screen
= gtk_widget_get_screen(s
->drawing_area
);
644 int x
= (int)motion
->x_root
;
645 int y
= (int)motion
->y_root
;
647 /* In relative mode check to see if client pointer hit
648 * one of the screen edges, and if so move it back by
649 * 200 pixels. This is important because the pointer
650 * in the server doesn't correspond 1-for-1, and so
651 * may still be only half way across the screen. Without
652 * this warp, the server pointer would thus appear to hit
653 * an invisible wall */
660 if (x
== (gdk_screen_get_width(screen
) - 1)) {
663 if (y
== (gdk_screen_get_height(screen
) - 1)) {
667 if (x
!= (int)motion
->x_root
|| y
!= (int)motion
->y_root
) {
668 #if GTK_CHECK_VERSION(3, 0, 0)
669 GdkDevice
*dev
= gdk_event_get_device((GdkEvent
*)motion
);
670 gdk_device_warp(dev
, screen
, x
, y
);
672 GdkDisplay
*display
= gtk_widget_get_display(widget
);
673 gdk_display_warp_pointer(display
, screen
, x
, y
);
682 static gboolean
gd_button_event(GtkWidget
*widget
, GdkEventButton
*button
,
685 GtkDisplayState
*s
= opaque
;
688 if (button
->button
== 1) {
689 btn
= INPUT_BUTTON_LEFT
;
690 } else if (button
->button
== 2) {
691 btn
= INPUT_BUTTON_MIDDLE
;
692 } else if (button
->button
== 3) {
693 btn
= INPUT_BUTTON_RIGHT
;
698 qemu_input_queue_btn(s
->dcl
.con
, btn
, button
->type
== GDK_BUTTON_PRESS
);
699 qemu_input_event_sync();
703 static gboolean
gd_scroll_event(GtkWidget
*widget
, GdkEventScroll
*scroll
,
706 GtkDisplayState
*s
= opaque
;
709 if (scroll
->direction
== GDK_SCROLL_UP
) {
710 btn
= INPUT_BUTTON_WHEEL_UP
;
711 } else if (scroll
->direction
== GDK_SCROLL_DOWN
) {
712 btn
= INPUT_BUTTON_WHEEL_DOWN
;
717 qemu_input_queue_btn(s
->dcl
.con
, btn
, true);
718 qemu_input_event_sync();
719 qemu_input_queue_btn(s
->dcl
.con
, btn
, false);
720 qemu_input_event_sync();
724 static gboolean
gd_key_event(GtkWidget
*widget
, GdkEventKey
*key
, void *opaque
)
726 GtkDisplayState
*s
= opaque
;
727 int gdk_keycode
= key
->hardware_keycode
;
731 UINT qemu_keycode
= MapVirtualKey(gdk_keycode
, MAPVK_VK_TO_VSC
);
732 switch (qemu_keycode
) {
733 case 103: /* alt gr */
734 qemu_keycode
= 56 | SCANCODE_GREY
;
740 if (gdk_keycode
< 9) {
742 } else if (gdk_keycode
< 97) {
743 qemu_keycode
= gdk_keycode
- 8;
744 } else if (gdk_keycode
< 158) {
745 qemu_keycode
= translate_evdev_keycode(gdk_keycode
- 97);
746 } else if (gdk_keycode
== 208) { /* Hiragana_Katakana */
748 } else if (gdk_keycode
== 211) { /* backslash */
755 trace_gd_key_event(gdk_keycode
, qemu_keycode
,
756 (key
->type
== GDK_KEY_PRESS
) ? "down" : "up");
758 for (i
= 0; i
< ARRAY_SIZE(modifier_keycode
); i
++) {
759 if (qemu_keycode
== modifier_keycode
[i
]) {
760 s
->modifier_pressed
[i
] = (key
->type
== GDK_KEY_PRESS
);
764 qemu_input_event_send_key_number(s
->dcl
.con
, qemu_keycode
,
765 key
->type
== GDK_KEY_PRESS
);
770 static gboolean
gd_event(GtkWidget
*widget
, GdkEvent
*event
, void *opaque
)
772 if (event
->type
== GDK_MOTION_NOTIFY
) {
773 return gd_motion_event(widget
, &event
->motion
, opaque
);
778 /** Window Menu Actions **/
780 static void gd_menu_pause(GtkMenuItem
*item
, void *opaque
)
782 GtkDisplayState
*s
= opaque
;
784 if (s
->external_pause_update
) {
787 if (runstate_is_running()) {
794 static void gd_menu_reset(GtkMenuItem
*item
, void *opaque
)
796 qmp_system_reset(NULL
);
799 static void gd_menu_powerdown(GtkMenuItem
*item
, void *opaque
)
801 qmp_system_powerdown(NULL
);
804 static void gd_menu_quit(GtkMenuItem
*item
, void *opaque
)
809 static void gd_menu_switch_vc(GtkMenuItem
*item
, void *opaque
)
811 GtkDisplayState
*s
= opaque
;
813 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s
->vga_item
))) {
814 gtk_notebook_set_current_page(GTK_NOTEBOOK(s
->notebook
), 0);
818 gtk_release_modifiers(s
);
819 for (i
= 0; i
< s
->nb_vcs
; i
++) {
820 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s
->vc
[i
].menu_item
))) {
821 gtk_notebook_set_current_page(GTK_NOTEBOOK(s
->notebook
), i
+ 1);
828 static void gd_menu_show_tabs(GtkMenuItem
*item
, void *opaque
)
830 GtkDisplayState
*s
= opaque
;
832 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s
->show_tabs_item
))) {
833 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s
->notebook
), TRUE
);
835 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s
->notebook
), FALSE
);
839 static void gd_menu_full_screen(GtkMenuItem
*item
, void *opaque
)
841 GtkDisplayState
*s
= opaque
;
843 if (!s
->full_screen
) {
844 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s
->notebook
), FALSE
);
845 gtk_widget_set_size_request(s
->menu_bar
, 0, 0);
846 gtk_widget_set_size_request(s
->drawing_area
, -1, -1);
847 gtk_window_fullscreen(GTK_WINDOW(s
->window
));
849 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s
->grab_item
), TRUE
);
851 s
->full_screen
= TRUE
;
853 gtk_window_unfullscreen(GTK_WINDOW(s
->window
));
854 gd_menu_show_tabs(GTK_MENU_ITEM(s
->show_tabs_item
), s
);
855 gtk_widget_set_size_request(s
->menu_bar
, -1, -1);
856 gtk_widget_set_size_request(s
->drawing_area
,
857 surface_width(s
->ds
),
858 surface_height(s
->ds
));
859 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s
->grab_item
), FALSE
);
860 s
->full_screen
= FALSE
;
865 gd_update_cursor(s
, FALSE
);
868 static void gd_menu_zoom_in(GtkMenuItem
*item
, void *opaque
)
870 GtkDisplayState
*s
= opaque
;
872 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s
->zoom_fit_item
),
878 gd_update_windowsize(s
);
881 static void gd_menu_zoom_out(GtkMenuItem
*item
, void *opaque
)
883 GtkDisplayState
*s
= opaque
;
885 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s
->zoom_fit_item
),
891 s
->scale_x
= MAX(s
->scale_x
, .25);
892 s
->scale_y
= MAX(s
->scale_y
, .25);
894 gd_update_windowsize(s
);
897 static void gd_menu_zoom_fixed(GtkMenuItem
*item
, void *opaque
)
899 GtkDisplayState
*s
= opaque
;
904 gd_update_windowsize(s
);
907 static void gd_menu_zoom_fit(GtkMenuItem
*item
, void *opaque
)
909 GtkDisplayState
*s
= opaque
;
911 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s
->zoom_fit_item
))) {
912 s
->free_scale
= TRUE
;
914 s
->free_scale
= FALSE
;
917 gd_update_windowsize(s
);
920 gd_update_full_redraw(s
);
923 static void gd_grab_keyboard(GtkDisplayState
*s
)
925 #if GTK_CHECK_VERSION(3, 0, 0)
926 GdkDisplay
*display
= gtk_widget_get_display(s
->drawing_area
);
927 GdkDeviceManager
*mgr
= gdk_display_get_device_manager(display
);
928 GList
*devices
= gdk_device_manager_list_devices(mgr
,
929 GDK_DEVICE_TYPE_MASTER
);
930 GList
*tmp
= devices
;
932 GdkDevice
*dev
= tmp
->data
;
933 if (gdk_device_get_source(dev
) == GDK_SOURCE_KEYBOARD
) {
935 gtk_widget_get_window(s
->drawing_area
),
938 GDK_KEY_PRESS_MASK
| GDK_KEY_RELEASE_MASK
,
944 g_list_free(devices
);
946 gdk_keyboard_grab(gtk_widget_get_window(s
->drawing_area
),
952 static void gd_ungrab_keyboard(GtkDisplayState
*s
)
954 #if GTK_CHECK_VERSION(3, 0, 0)
955 GdkDisplay
*display
= gtk_widget_get_display(s
->drawing_area
);
956 GdkDeviceManager
*mgr
= gdk_display_get_device_manager(display
);
957 GList
*devices
= gdk_device_manager_list_devices(mgr
,
958 GDK_DEVICE_TYPE_MASTER
);
959 GList
*tmp
= devices
;
961 GdkDevice
*dev
= tmp
->data
;
962 if (gdk_device_get_source(dev
) == GDK_SOURCE_KEYBOARD
) {
963 gdk_device_ungrab(dev
,
968 g_list_free(devices
);
970 gdk_keyboard_ungrab(GDK_CURRENT_TIME
);
974 static void gd_grab_pointer(GtkDisplayState
*s
)
976 GdkDisplay
*display
= gtk_widget_get_display(s
->drawing_area
);
977 #if GTK_CHECK_VERSION(3, 0, 0)
978 GdkDeviceManager
*mgr
= gdk_display_get_device_manager(display
);
979 GList
*devices
= gdk_device_manager_list_devices(mgr
,
980 GDK_DEVICE_TYPE_MASTER
);
981 GList
*tmp
= devices
;
983 GdkDevice
*dev
= tmp
->data
;
984 if (gdk_device_get_source(dev
) == GDK_SOURCE_MOUSE
) {
986 gtk_widget_get_window(s
->drawing_area
),
988 FALSE
, /* All events to come to our
990 GDK_POINTER_MOTION_MASK
|
991 GDK_BUTTON_PRESS_MASK
|
992 GDK_BUTTON_RELEASE_MASK
|
993 GDK_BUTTON_MOTION_MASK
|
1000 g_list_free(devices
);
1001 gdk_device_get_position(gdk_device_manager_get_client_pointer(mgr
),
1002 NULL
, &s
->grab_x_root
, &s
->grab_y_root
);
1004 gdk_pointer_grab(gtk_widget_get_window(s
->drawing_area
),
1005 FALSE
, /* All events to come to our window directly */
1006 GDK_POINTER_MOTION_MASK
|
1007 GDK_BUTTON_PRESS_MASK
|
1008 GDK_BUTTON_RELEASE_MASK
|
1009 GDK_BUTTON_MOTION_MASK
|
1011 NULL
, /* Allow cursor to move over entire desktop */
1014 gdk_display_get_pointer(display
, NULL
,
1015 &s
->grab_x_root
, &s
->grab_y_root
, NULL
);
1019 static void gd_ungrab_pointer(GtkDisplayState
*s
)
1021 GdkDisplay
*display
= gtk_widget_get_display(s
->drawing_area
);
1022 #if GTK_CHECK_VERSION(3, 0, 0)
1023 GdkDeviceManager
*mgr
= gdk_display_get_device_manager(display
);
1024 GList
*devices
= gdk_device_manager_list_devices(mgr
,
1025 GDK_DEVICE_TYPE_MASTER
);
1026 GList
*tmp
= devices
;
1028 GdkDevice
*dev
= tmp
->data
;
1029 if (gdk_device_get_source(dev
) == GDK_SOURCE_MOUSE
) {
1030 gdk_device_ungrab(dev
,
1035 g_list_free(devices
);
1036 gdk_device_warp(gdk_device_manager_get_client_pointer(mgr
),
1037 gtk_widget_get_screen(s
->drawing_area
),
1038 s
->grab_x_root
, s
->grab_y_root
);
1040 gdk_pointer_ungrab(GDK_CURRENT_TIME
);
1041 gdk_display_warp_pointer(display
,
1042 gtk_widget_get_screen(s
->drawing_area
),
1043 s
->grab_x_root
, s
->grab_y_root
);
1047 static void gd_menu_grab_input(GtkMenuItem
*item
, void *opaque
)
1049 GtkDisplayState
*s
= opaque
;
1051 if (gd_is_grab_active(s
)) {
1052 gd_grab_keyboard(s
);
1055 gd_ungrab_keyboard(s
);
1056 gd_ungrab_pointer(s
);
1059 gd_update_caption(s
);
1060 gd_update_cursor(s
, FALSE
);
1063 static void gd_change_page(GtkNotebook
*nb
, gpointer arg1
, guint arg2
,
1066 GtkDisplayState
*s
= data
;
1070 if (!gtk_widget_get_realized(s
->notebook
)) {
1074 last_page
= gtk_notebook_get_current_page(nb
);
1077 gtk_widget_set_size_request(s
->vc
[last_page
- 1].terminal
, -1, -1);
1083 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s
->grab_item
),
1085 } else if (s
->full_screen
) {
1086 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s
->grab_item
),
1091 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s
->vga_item
), TRUE
);
1093 #if defined(CONFIG_VTE)
1094 VirtualConsole
*vc
= &s
->vc
[arg2
- 1];
1095 VteTerminal
*term
= VTE_TERMINAL(vc
->terminal
);
1098 width
= 80 * vte_terminal_get_char_width(term
);
1099 height
= 25 * vte_terminal_get_char_height(term
);
1101 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc
->menu_item
), TRUE
);
1102 gtk_widget_set_size_request(vc
->terminal
, width
, height
);
1104 g_assert_not_reached();
1108 gtk_widget_set_sensitive(s
->grab_item
, on_vga
);
1110 gd_update_cursor(s
, TRUE
);
1113 static gboolean
gd_enter_event(GtkWidget
*widget
, GdkEventCrossing
*crossing
, gpointer data
)
1115 GtkDisplayState
*s
= data
;
1117 if (!gd_is_grab_active(s
) && gd_grab_on_hover(s
)) {
1118 gd_grab_keyboard(s
);
1124 static gboolean
gd_leave_event(GtkWidget
*widget
, GdkEventCrossing
*crossing
, gpointer data
)
1126 GtkDisplayState
*s
= data
;
1128 if (!gd_is_grab_active(s
) && gd_grab_on_hover(s
)) {
1129 gd_ungrab_keyboard(s
);
1135 static gboolean
gd_focus_out_event(GtkWidget
*widget
,
1136 GdkEventCrossing
*crossing
, gpointer data
)
1138 GtkDisplayState
*s
= data
;
1140 gtk_release_modifiers(s
);
1145 /** Virtual Console Callbacks **/
1147 static int gd_vc_chr_write(CharDriverState
*chr
, const uint8_t *buf
, int len
)
1149 VirtualConsole
*vc
= chr
->opaque
;
1151 return vc
? write(vc
->fd
, buf
, len
) : len
;
1155 static CharDriverState
*vcs
[MAX_VCS
];
1157 static CharDriverState
*gd_vc_handler(ChardevVC
*unused
)
1159 CharDriverState
*chr
;
1161 chr
= g_malloc0(sizeof(*chr
));
1162 chr
->chr_write
= gd_vc_chr_write
;
1163 /* defer OPENED events until our vc is fully initialized */
1164 chr
->explicit_be_open
= true;
1166 vcs
[nb_vcs
++] = chr
;
1171 void early_gtk_display_init(void)
1173 register_vc_handler(gd_vc_handler
);
1176 #if defined(CONFIG_VTE)
1177 static gboolean
gd_vc_in(GIOChannel
*chan
, GIOCondition cond
, void *opaque
)
1179 VirtualConsole
*vc
= opaque
;
1180 uint8_t buffer
[1024];
1183 len
= read(vc
->fd
, buffer
, sizeof(buffer
));
1188 qemu_chr_be_write(vc
->chr
, buffer
, len
);
1194 static GSList
*gd_vc_init(GtkDisplayState
*s
, VirtualConsole
*vc
, int index
, GSList
*group
,
1195 GtkWidget
*view_menu
)
1197 #if defined(CONFIG_VTE)
1201 #if VTE_CHECK_VERSION(0, 26, 0)
1205 GtkWidget
*scrolled_window
;
1206 GtkAdjustment
*vadjustment
;
1207 int master_fd
, slave_fd
;
1209 snprintf(buffer
, sizeof(buffer
), "vc%d", index
);
1210 snprintf(path
, sizeof(path
), "<QEMU>/View/VC%d", index
);
1212 vc
->chr
= vcs
[index
];
1214 if (vc
->chr
->label
) {
1215 label
= vc
->chr
->label
;
1220 vc
->menu_item
= gtk_radio_menu_item_new_with_mnemonic(group
, label
);
1221 group
= gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc
->menu_item
));
1222 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(vc
->menu_item
), path
);
1223 gtk_accel_map_add_entry(path
, GDK_KEY_2
+ index
, HOTKEY_MODIFIERS
);
1225 vc
->terminal
= vte_terminal_new();
1227 master_fd
= qemu_openpty_raw(&slave_fd
, NULL
);
1228 g_assert(master_fd
!= -1);
1230 #if VTE_CHECK_VERSION(0, 26, 0)
1231 pty
= vte_pty_new_foreign(master_fd
, NULL
);
1232 vte_terminal_set_pty_object(VTE_TERMINAL(vc
->terminal
), pty
);
1234 vte_terminal_set_pty(VTE_TERMINAL(vc
->terminal
), master_fd
);
1237 vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc
->terminal
), -1);
1239 vadjustment
= vte_terminal_get_adjustment(VTE_TERMINAL(vc
->terminal
));
1241 scrolled_window
= gtk_scrolled_window_new(NULL
, vadjustment
);
1242 gtk_container_add(GTK_CONTAINER(scrolled_window
), vc
->terminal
);
1244 vte_terminal_set_size(VTE_TERMINAL(vc
->terminal
), 80, 25);
1247 vc
->chr
->opaque
= vc
;
1248 vc
->scrolled_window
= scrolled_window
;
1250 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vc
->scrolled_window
),
1251 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
1253 gtk_notebook_append_page(GTK_NOTEBOOK(s
->notebook
), scrolled_window
, gtk_label_new(label
));
1254 g_signal_connect(vc
->menu_item
, "activate",
1255 G_CALLBACK(gd_menu_switch_vc
), s
);
1257 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), vc
->menu_item
);
1259 qemu_chr_be_generic_open(vc
->chr
);
1260 if (vc
->chr
->init
) {
1261 vc
->chr
->init(vc
->chr
);
1264 chan
= g_io_channel_unix_new(vc
->fd
);
1265 g_io_add_watch(chan
, G_IO_IN
, gd_vc_in
, vc
);
1267 #endif /* CONFIG_VTE */
1271 /** Window Creation **/
1273 static void gd_connect_signals(GtkDisplayState
*s
)
1275 g_signal_connect(s
->show_tabs_item
, "activate",
1276 G_CALLBACK(gd_menu_show_tabs
), s
);
1278 g_signal_connect(s
->window
, "key-press-event",
1279 G_CALLBACK(gd_window_key_event
), s
);
1280 g_signal_connect(s
->window
, "delete-event",
1281 G_CALLBACK(gd_window_close
), s
);
1283 #if GTK_CHECK_VERSION(3, 0, 0)
1284 g_signal_connect(s
->drawing_area
, "draw",
1285 G_CALLBACK(gd_draw_event
), s
);
1287 g_signal_connect(s
->drawing_area
, "expose-event",
1288 G_CALLBACK(gd_expose_event
), s
);
1290 g_signal_connect(s
->drawing_area
, "event",
1291 G_CALLBACK(gd_event
), s
);
1292 g_signal_connect(s
->drawing_area
, "button-press-event",
1293 G_CALLBACK(gd_button_event
), s
);
1294 g_signal_connect(s
->drawing_area
, "button-release-event",
1295 G_CALLBACK(gd_button_event
), s
);
1296 g_signal_connect(s
->drawing_area
, "scroll-event",
1297 G_CALLBACK(gd_scroll_event
), s
);
1298 g_signal_connect(s
->drawing_area
, "key-press-event",
1299 G_CALLBACK(gd_key_event
), s
);
1300 g_signal_connect(s
->drawing_area
, "key-release-event",
1301 G_CALLBACK(gd_key_event
), s
);
1303 g_signal_connect(s
->pause_item
, "activate",
1304 G_CALLBACK(gd_menu_pause
), s
);
1305 g_signal_connect(s
->reset_item
, "activate",
1306 G_CALLBACK(gd_menu_reset
), s
);
1307 g_signal_connect(s
->powerdown_item
, "activate",
1308 G_CALLBACK(gd_menu_powerdown
), s
);
1309 g_signal_connect(s
->quit_item
, "activate",
1310 G_CALLBACK(gd_menu_quit
), s
);
1311 g_signal_connect(s
->full_screen_item
, "activate",
1312 G_CALLBACK(gd_menu_full_screen
), s
);
1313 g_signal_connect(s
->zoom_in_item
, "activate",
1314 G_CALLBACK(gd_menu_zoom_in
), s
);
1315 g_signal_connect(s
->zoom_out_item
, "activate",
1316 G_CALLBACK(gd_menu_zoom_out
), s
);
1317 g_signal_connect(s
->zoom_fixed_item
, "activate",
1318 G_CALLBACK(gd_menu_zoom_fixed
), s
);
1319 g_signal_connect(s
->zoom_fit_item
, "activate",
1320 G_CALLBACK(gd_menu_zoom_fit
), s
);
1321 g_signal_connect(s
->vga_item
, "activate",
1322 G_CALLBACK(gd_menu_switch_vc
), s
);
1323 g_signal_connect(s
->grab_item
, "activate",
1324 G_CALLBACK(gd_menu_grab_input
), s
);
1325 g_signal_connect(s
->notebook
, "switch-page",
1326 G_CALLBACK(gd_change_page
), s
);
1327 g_signal_connect(s
->drawing_area
, "enter-notify-event",
1328 G_CALLBACK(gd_enter_event
), s
);
1329 g_signal_connect(s
->drawing_area
, "leave-notify-event",
1330 G_CALLBACK(gd_leave_event
), s
);
1331 g_signal_connect(s
->drawing_area
, "focus-out-event",
1332 G_CALLBACK(gd_focus_out_event
), s
);
1335 static GtkWidget
*gd_create_menu_machine(GtkDisplayState
*s
, GtkAccelGroup
*accel_group
)
1337 GtkWidget
*machine_menu
;
1338 GtkWidget
*separator
;
1341 machine_menu
= gtk_menu_new();
1342 gtk_menu_set_accel_group(GTK_MENU(machine_menu
), accel_group
);
1344 s
->pause_item
= gtk_check_menu_item_new_with_mnemonic(_("_Pause"));
1345 gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu
), s
->pause_item
);
1347 separator
= gtk_separator_menu_item_new();
1348 gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu
), separator
);
1350 s
->reset_item
= gtk_image_menu_item_new_with_mnemonic(_("_Reset"));
1351 gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu
), s
->reset_item
);
1353 s
->powerdown_item
= gtk_image_menu_item_new_with_mnemonic(_("Power _Down"));
1354 gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu
), s
->powerdown_item
);
1356 separator
= gtk_separator_menu_item_new();
1357 gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu
), separator
);
1359 s
->quit_item
= gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT
, NULL
);
1360 gtk_stock_lookup(GTK_STOCK_QUIT
, &item
);
1361 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s
->quit_item
),
1362 "<QEMU>/Machine/Quit");
1363 gtk_accel_map_add_entry("<QEMU>/Machine/Quit", item
.keyval
, item
.modifier
);
1364 gtk_menu_shell_append(GTK_MENU_SHELL(machine_menu
), s
->quit_item
);
1366 return machine_menu
;
1369 static GtkWidget
*gd_create_menu_view(GtkDisplayState
*s
, GtkAccelGroup
*accel_group
)
1371 GSList
*group
= NULL
;
1372 GtkWidget
*view_menu
;
1373 GtkWidget
*separator
;
1376 view_menu
= gtk_menu_new();
1377 gtk_menu_set_accel_group(GTK_MENU(view_menu
), accel_group
);
1379 s
->full_screen_item
=
1380 gtk_image_menu_item_new_from_stock(GTK_STOCK_FULLSCREEN
, NULL
);
1381 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s
->full_screen_item
),
1382 "<QEMU>/View/Full Screen");
1383 gtk_accel_map_add_entry("<QEMU>/View/Full Screen", GDK_KEY_f
,
1385 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), s
->full_screen_item
);
1387 separator
= gtk_separator_menu_item_new();
1388 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), separator
);
1390 s
->zoom_in_item
= gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_IN
, NULL
);
1391 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s
->zoom_in_item
),
1392 "<QEMU>/View/Zoom In");
1393 gtk_accel_map_add_entry("<QEMU>/View/Zoom In", GDK_KEY_plus
,
1395 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), s
->zoom_in_item
);
1397 s
->zoom_out_item
= gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_OUT
, NULL
);
1398 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s
->zoom_out_item
),
1399 "<QEMU>/View/Zoom Out");
1400 gtk_accel_map_add_entry("<QEMU>/View/Zoom Out", GDK_KEY_minus
,
1402 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), s
->zoom_out_item
);
1404 s
->zoom_fixed_item
= gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_100
, NULL
);
1405 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s
->zoom_fixed_item
),
1406 "<QEMU>/View/Zoom Fixed");
1407 gtk_accel_map_add_entry("<QEMU>/View/Zoom Fixed", GDK_KEY_0
,
1409 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), s
->zoom_fixed_item
);
1411 s
->zoom_fit_item
= gtk_check_menu_item_new_with_mnemonic(_("Zoom To _Fit"));
1412 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), s
->zoom_fit_item
);
1414 separator
= gtk_separator_menu_item_new();
1415 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), separator
);
1417 s
->grab_on_hover_item
= gtk_check_menu_item_new_with_mnemonic(_("Grab On _Hover"));
1418 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), s
->grab_on_hover_item
);
1420 s
->grab_item
= gtk_check_menu_item_new_with_mnemonic(_("_Grab Input"));
1421 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s
->grab_item
),
1422 "<QEMU>/View/Grab Input");
1423 gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g
,
1425 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), s
->grab_item
);
1427 separator
= gtk_separator_menu_item_new();
1428 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), separator
);
1430 s
->vga_item
= gtk_radio_menu_item_new_with_mnemonic(group
, "_VGA");
1431 group
= gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(s
->vga_item
));
1432 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s
->vga_item
),
1434 gtk_accel_map_add_entry("<QEMU>/View/VGA", GDK_KEY_1
, HOTKEY_MODIFIERS
);
1435 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), s
->vga_item
);
1437 for (i
= 0; i
< nb_vcs
; i
++) {
1438 VirtualConsole
*vc
= &s
->vc
[i
];
1440 group
= gd_vc_init(s
, vc
, i
, group
, view_menu
);
1444 separator
= gtk_separator_menu_item_new();
1445 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), separator
);
1447 s
->show_tabs_item
= gtk_check_menu_item_new_with_mnemonic(_("Show _Tabs"));
1448 gtk_menu_shell_append(GTK_MENU_SHELL(view_menu
), s
->show_tabs_item
);
1453 static void gd_create_menus(GtkDisplayState
*s
)
1455 GtkAccelGroup
*accel_group
;
1457 accel_group
= gtk_accel_group_new();
1458 s
->machine_menu
= gd_create_menu_machine(s
, accel_group
);
1459 s
->view_menu
= gd_create_menu_view(s
, accel_group
);
1461 s
->machine_menu_item
= gtk_menu_item_new_with_mnemonic(_("_Machine"));
1462 gtk_menu_item_set_submenu(GTK_MENU_ITEM(s
->machine_menu_item
),
1464 gtk_menu_shell_append(GTK_MENU_SHELL(s
->menu_bar
), s
->machine_menu_item
);
1466 s
->view_menu_item
= gtk_menu_item_new_with_mnemonic(_("_View"));
1467 gtk_menu_item_set_submenu(GTK_MENU_ITEM(s
->view_menu_item
), s
->view_menu
);
1468 gtk_menu_shell_append(GTK_MENU_SHELL(s
->menu_bar
), s
->view_menu_item
);
1470 g_object_set_data(G_OBJECT(s
->window
), "accel_group", accel_group
);
1471 gtk_window_add_accel_group(GTK_WINDOW(s
->window
), accel_group
);
1472 s
->accel_group
= accel_group
;
1475 static const DisplayChangeListenerOps dcl_ops
= {
1477 .dpy_gfx_update
= gd_update
,
1478 .dpy_gfx_switch
= gd_switch
,
1479 .dpy_refresh
= gd_refresh
,
1480 .dpy_mouse_set
= gd_mouse_set
,
1481 .dpy_cursor_define
= gd_cursor_define
,
1484 void gtk_display_init(DisplayState
*ds
, bool full_screen
, bool grab_on_hover
)
1486 GtkDisplayState
*s
= g_malloc0(sizeof(*s
));
1489 gtk_init(NULL
, NULL
);
1491 s
->dcl
.ops
= &dcl_ops
;
1492 s
->dcl
.con
= qemu_console_lookup_by_index(0);
1494 s
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
1495 #if GTK_CHECK_VERSION(3, 2, 0)
1496 s
->vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
1498 s
->vbox
= gtk_vbox_new(FALSE
, 0);
1500 s
->notebook
= gtk_notebook_new();
1501 s
->drawing_area
= gtk_drawing_area_new();
1502 s
->menu_bar
= gtk_menu_bar_new();
1506 s
->free_scale
= FALSE
;
1508 setlocale(LC_ALL
, "");
1509 bindtextdomain("qemu", CONFIG_QEMU_LOCALEDIR
);
1512 s
->null_cursor
= gdk_cursor_new(GDK_BLANK_CURSOR
);
1514 s
->mouse_mode_notifier
.notify
= gd_mouse_mode_change
;
1515 qemu_add_mouse_mode_change_notifier(&s
->mouse_mode_notifier
);
1516 qemu_add_vm_change_state_handler(gd_change_runstate
, s
);
1518 gtk_notebook_append_page(GTK_NOTEBOOK(s
->notebook
), s
->drawing_area
, gtk_label_new("VGA"));
1520 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, "qemu_logo_no_text.svg");
1522 GError
*error
= NULL
;
1523 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_file(filename
, &error
);
1525 gtk_window_set_icon(GTK_WINDOW(s
->window
), pixbuf
);
1527 g_error_free(error
);
1534 gd_connect_signals(s
);
1536 gtk_widget_add_events(s
->drawing_area
,
1537 GDK_POINTER_MOTION_MASK
|
1538 GDK_BUTTON_PRESS_MASK
|
1539 GDK_BUTTON_RELEASE_MASK
|
1540 GDK_BUTTON_MOTION_MASK
|
1541 GDK_ENTER_NOTIFY_MASK
|
1542 GDK_LEAVE_NOTIFY_MASK
|
1544 GDK_KEY_PRESS_MASK
);
1545 gtk_widget_set_double_buffered(s
->drawing_area
, FALSE
);
1546 gtk_widget_set_can_focus(s
->drawing_area
, TRUE
);
1548 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s
->notebook
), FALSE
);
1549 gtk_notebook_set_show_border(GTK_NOTEBOOK(s
->notebook
), FALSE
);
1551 gd_update_caption(s
);
1553 gtk_box_pack_start(GTK_BOX(s
->vbox
), s
->menu_bar
, FALSE
, TRUE
, 0);
1554 gtk_box_pack_start(GTK_BOX(s
->vbox
), s
->notebook
, TRUE
, TRUE
, 0);
1556 gtk_container_add(GTK_CONTAINER(s
->window
), s
->vbox
);
1558 gtk_widget_show_all(s
->window
);
1561 gtk_menu_item_activate(GTK_MENU_ITEM(s
->full_screen_item
));
1563 if (grab_on_hover
) {
1564 gtk_menu_item_activate(GTK_MENU_ITEM(s
->grab_on_hover_item
));
1567 register_displaychangelistener(&s
->dcl
);