target-ppc: Use NARROW_MODE macro for tlbie
[qemu/agraf.git] / ui / gtk.c
blob305940d0ba0fe3cb7550c8b19675bb85aae43cd0
1 /*
2 * GTK UI
4 * Copyright IBM, Corp. 2012
6 * Authors:
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:
14 * GTK VNC Widget
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"
37 #include "qemu-common.h"
39 #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
40 /* Work around an -Wstrict-prototypes warning in GTK headers */
41 #pragma GCC diagnostic ignored "-Wstrict-prototypes"
42 #endif
43 #include <gtk/gtk.h>
44 #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
45 #pragma GCC diagnostic error "-Wstrict-prototypes"
46 #endif
49 #include <gdk/gdkkeysyms.h>
50 #include <glib/gi18n.h>
51 #include <locale.h>
52 #include <vte/vte.h>
53 #include <sys/types.h>
54 #include <sys/socket.h>
55 #include <sys/un.h>
56 #include <sys/wait.h>
57 #include <pty.h>
58 #include <math.h>
60 #include "ui/console.h"
61 #include "sysemu/sysemu.h"
62 #include "qmp-commands.h"
63 #include "x_keymap.h"
64 #include "keymaps.h"
65 #include "char/char.h"
67 //#define DEBUG_GTK
69 #ifdef DEBUG_GTK
70 #define DPRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
71 #else
72 #define DPRINTF(fmt, ...) do { } while (0)
73 #endif
75 #define MAX_VCS 10
78 /* Compatibility define to let us build on both Gtk2 and Gtk3 */
79 #if GTK_CHECK_VERSION(3, 0, 0)
80 static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
82 *ww = gdk_window_get_width(w);
83 *wh = gdk_window_get_height(w);
85 #endif
87 #if !GTK_CHECK_VERSION(2, 20, 0)
88 #define gtk_widget_get_realized(widget) GTK_WIDGET_REALIZED(widget)
89 #endif
91 #ifndef GDK_KEY_0
92 #define GDK_KEY_0 GDK_0
93 #define GDK_KEY_1 GDK_1
94 #define GDK_KEY_2 GDK_2
95 #define GDK_KEY_f GDK_f
96 #define GDK_KEY_g GDK_g
97 #define GDK_KEY_plus GDK_plus
98 #define GDK_KEY_minus GDK_minus
99 #endif
101 typedef struct VirtualConsole
103 GtkWidget *menu_item;
104 GtkWidget *terminal;
105 GtkWidget *scrolled_window;
106 CharDriverState *chr;
107 int fd;
108 } VirtualConsole;
110 typedef struct GtkDisplayState
112 GtkWidget *window;
114 GtkWidget *menu_bar;
116 GtkAccelGroup *accel_group;
118 GtkWidget *machine_menu_item;
119 GtkWidget *machine_menu;
120 GtkWidget *pause_item;
121 GtkWidget *reset_item;
122 GtkWidget *powerdown_item;
123 GtkWidget *quit_item;
125 GtkWidget *view_menu_item;
126 GtkWidget *view_menu;
127 GtkWidget *full_screen_item;
128 GtkWidget *zoom_in_item;
129 GtkWidget *zoom_out_item;
130 GtkWidget *zoom_fixed_item;
131 GtkWidget *zoom_fit_item;
132 GtkWidget *grab_item;
133 GtkWidget *grab_on_hover_item;
134 GtkWidget *vga_item;
136 int nb_vcs;
137 VirtualConsole vc[MAX_VCS];
139 GtkWidget *show_tabs_item;
141 GtkWidget *vbox;
142 GtkWidget *notebook;
143 GtkWidget *drawing_area;
144 cairo_surface_t *surface;
145 DisplayChangeListener dcl;
146 DisplaySurface *ds;
147 int button_mask;
148 int last_x;
149 int last_y;
151 double scale_x;
152 double scale_y;
153 gboolean full_screen;
155 GdkCursor *null_cursor;
156 Notifier mouse_mode_notifier;
157 gboolean free_scale;
159 bool external_pause_update;
160 } GtkDisplayState;
162 static GtkDisplayState *global_state;
164 /** Utility Functions **/
166 static bool gd_is_grab_active(GtkDisplayState *s)
168 return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->grab_item));
171 static bool gd_grab_on_hover(GtkDisplayState *s)
173 return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->grab_on_hover_item));
176 static bool gd_on_vga(GtkDisplayState *s)
178 return gtk_notebook_get_current_page(GTK_NOTEBOOK(s->notebook)) == 0;
181 static void gd_update_cursor(GtkDisplayState *s, gboolean override)
183 GdkWindow *window;
184 bool on_vga;
186 window = gtk_widget_get_window(GTK_WIDGET(s->drawing_area));
188 on_vga = gd_on_vga(s);
190 if ((override || on_vga) &&
191 (s->full_screen || kbd_mouse_is_absolute() || gd_is_grab_active(s))) {
192 gdk_window_set_cursor(window, s->null_cursor);
193 } else {
194 gdk_window_set_cursor(window, NULL);
198 static void gd_update_caption(GtkDisplayState *s)
200 const char *status = "";
201 gchar *title;
202 const char *grab = "";
203 bool is_paused = !runstate_is_running();
205 if (gd_is_grab_active(s)) {
206 grab = " - Press Ctrl+Alt+G to release grab";
209 if (is_paused) {
210 status = " [Paused]";
212 s->external_pause_update = true;
213 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->pause_item),
214 is_paused);
215 s->external_pause_update = false;
217 if (qemu_name) {
218 title = g_strdup_printf("QEMU (%s)%s%s", qemu_name, status, grab);
219 } else {
220 title = g_strdup_printf("QEMU%s%s", status, grab);
223 gtk_window_set_title(GTK_WINDOW(s->window), title);
225 g_free(title);
228 static void gd_update_windowsize(GtkDisplayState *s)
230 if (!s->full_screen) {
231 GtkRequisition req;
232 double sx, sy;
234 if (s->free_scale) {
235 sx = s->scale_x;
236 sy = s->scale_y;
238 s->scale_y = 1.0;
239 s->scale_x = 1.0;
240 } else {
241 sx = 1.0;
242 sy = 1.0;
245 gtk_widget_set_size_request(s->drawing_area,
246 surface_width(s->ds) * s->scale_x,
247 surface_height(s->ds) * s->scale_y);
248 #if GTK_CHECK_VERSION(3, 0, 0)
249 gtk_widget_get_preferred_size(s->vbox, NULL, &req);
250 #else
251 gtk_widget_size_request(s->vbox, &req);
252 #endif
254 gtk_window_resize(GTK_WINDOW(s->window),
255 req.width * sx, req.height * sy);
259 static void gd_update_full_redraw(GtkDisplayState *s)
261 int ww, wh;
262 gdk_drawable_get_size(gtk_widget_get_window(s->drawing_area), &ww, &wh);
263 gtk_widget_queue_draw_area(s->drawing_area, 0, 0, ww, wh);
266 /** DisplayState Callbacks **/
268 static void gd_update(DisplayChangeListener *dcl,
269 int x, int y, int w, int h)
271 GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
272 int x1, x2, y1, y2;
273 int mx, my;
274 int fbw, fbh;
275 int ww, wh;
277 DPRINTF("update(x=%d, y=%d, w=%d, h=%d)\n", x, y, w, h);
279 x1 = floor(x * s->scale_x);
280 y1 = floor(y * s->scale_y);
282 x2 = ceil(x * s->scale_x + w * s->scale_x);
283 y2 = ceil(y * s->scale_y + h * s->scale_y);
285 fbw = surface_width(s->ds) * s->scale_x;
286 fbh = surface_height(s->ds) * s->scale_y;
288 gdk_drawable_get_size(gtk_widget_get_window(s->drawing_area), &ww, &wh);
290 mx = my = 0;
291 if (ww > fbw) {
292 mx = (ww - fbw) / 2;
294 if (wh > fbh) {
295 my = (wh - fbh) / 2;
298 gtk_widget_queue_draw_area(s->drawing_area, mx + x1, my + y1, (x2 - x1), (y2 - y1));
301 static void gd_refresh(DisplayChangeListener *dcl)
303 vga_hw_update();
306 static void gd_switch(DisplayChangeListener *dcl,
307 DisplaySurface *surface)
309 GtkDisplayState *s = container_of(dcl, GtkDisplayState, dcl);
310 cairo_format_t kind;
311 bool resized = true;
312 int stride;
314 DPRINTF("resize(width=%d, height=%d)\n",
315 surface_width(surface), surface_height(surface));
317 if (s->surface) {
318 cairo_surface_destroy(s->surface);
321 if (s->ds &&
322 surface_width(s->ds) == surface_width(surface) &&
323 surface_height(s->ds) == surface_height(surface)) {
324 resized = false;
326 s->ds = surface;
327 switch (surface_bits_per_pixel(surface)) {
328 case 8:
329 kind = CAIRO_FORMAT_A8;
330 break;
331 case 16:
332 kind = CAIRO_FORMAT_RGB16_565;
333 break;
334 case 32:
335 kind = CAIRO_FORMAT_RGB24;
336 break;
337 default:
338 g_assert_not_reached();
339 break;
342 stride = cairo_format_stride_for_width(kind, surface_width(surface));
343 g_assert(surface_stride(surface) == stride);
345 s->surface = cairo_image_surface_create_for_data(surface_data(surface),
346 kind,
347 surface_width(surface),
348 surface_height(surface),
349 surface_stride(surface));
351 if (resized) {
352 gd_update_windowsize(s);
353 } else {
354 gd_update_full_redraw(s);
358 /** QEMU Events **/
360 static void gd_change_runstate(void *opaque, int running, RunState state)
362 GtkDisplayState *s = opaque;
364 gd_update_caption(s);
367 static void gd_mouse_mode_change(Notifier *notify, void *data)
369 gd_update_cursor(container_of(notify, GtkDisplayState, mouse_mode_notifier),
370 FALSE);
373 /** GTK Events **/
375 static gboolean gd_window_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
377 GtkDisplayState *s = opaque;
378 GtkAccelGroupEntry *entries;
379 guint n_entries = 0;
380 gboolean propagate_accel = TRUE;
381 gboolean handled = FALSE;
383 entries = gtk_accel_group_query(s->accel_group, key->keyval,
384 key->state, &n_entries);
385 if (n_entries) {
386 const char *quark = g_quark_to_string(entries[0].accel_path_quark);
388 if (gd_is_grab_active(s) && strstart(quark, "<QEMU>/File/", NULL)) {
389 propagate_accel = FALSE;
393 if (!handled && propagate_accel) {
394 handled = gtk_window_activate_key(GTK_WINDOW(widget), key);
397 if (!handled) {
398 handled = gtk_window_propagate_key_event(GTK_WINDOW(widget), key);
401 return handled;
404 static gboolean gd_window_close(GtkWidget *widget, GdkEvent *event,
405 void *opaque)
407 GtkDisplayState *s = opaque;
409 if (!no_quit) {
410 unregister_displaychangelistener(&s->dcl);
411 qmp_quit(NULL);
412 return FALSE;
415 return TRUE;
418 static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
420 GtkDisplayState *s = opaque;
421 int mx, my;
422 int ww, wh;
423 int fbw, fbh;
425 if (!gtk_widget_get_realized(widget)) {
426 return FALSE;
429 fbw = surface_width(s->ds);
430 fbh = surface_height(s->ds);
432 gdk_drawable_get_size(gtk_widget_get_window(widget), &ww, &wh);
434 if (s->full_screen) {
435 s->scale_x = (double)ww / fbw;
436 s->scale_y = (double)wh / fbh;
437 } else if (s->free_scale) {
438 double sx, sy;
440 sx = (double)ww / fbw;
441 sy = (double)wh / fbh;
443 s->scale_x = s->scale_y = MIN(sx, sy);
446 fbw *= s->scale_x;
447 fbh *= s->scale_y;
449 mx = my = 0;
450 if (ww > fbw) {
451 mx = (ww - fbw) / 2;
453 if (wh > fbh) {
454 my = (wh - fbh) / 2;
457 cairo_rectangle(cr, 0, 0, ww, wh);
459 /* Optionally cut out the inner area where the pixmap
460 will be drawn. This avoids 'flashing' since we're
461 not double-buffering. Note we're using the undocumented
462 behaviour of drawing the rectangle from right to left
463 to cut out the whole */
464 cairo_rectangle(cr, mx + fbw, my,
465 -1 * fbw, fbh);
466 cairo_fill(cr);
468 cairo_scale(cr, s->scale_x, s->scale_y);
469 cairo_set_source_surface(cr, s->surface, mx / s->scale_x, my / s->scale_y);
470 cairo_paint(cr);
472 return TRUE;
475 #if !GTK_CHECK_VERSION(3, 0, 0)
476 static gboolean gd_expose_event(GtkWidget *widget, GdkEventExpose *expose,
477 void *opaque)
479 cairo_t *cr;
480 gboolean ret;
482 cr = gdk_cairo_create(gtk_widget_get_window(widget));
483 cairo_rectangle(cr,
484 expose->area.x,
485 expose->area.y,
486 expose->area.width,
487 expose->area.height);
488 cairo_clip(cr);
490 ret = gd_draw_event(widget, cr, opaque);
492 cairo_destroy(cr);
494 return ret;
496 #endif
498 static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
499 void *opaque)
501 GtkDisplayState *s = opaque;
502 int dx, dy;
503 int x, y;
504 int mx, my;
505 int fbh, fbw;
506 int ww, wh;
508 fbw = surface_width(s->ds) * s->scale_x;
509 fbh = surface_height(s->ds) * s->scale_y;
511 gdk_drawable_get_size(gtk_widget_get_window(s->drawing_area), &ww, &wh);
513 mx = my = 0;
514 if (ww > fbw) {
515 mx = (ww - fbw) / 2;
517 if (wh > fbh) {
518 my = (wh - fbh) / 2;
521 x = (motion->x - mx) / s->scale_x;
522 y = (motion->y - my) / s->scale_y;
524 if (x < 0 || y < 0 ||
525 x >= surface_width(s->ds) ||
526 y >= surface_height(s->ds)) {
527 return TRUE;
530 if (kbd_mouse_is_absolute()) {
531 dx = x * 0x7FFF / (surface_width(s->ds) - 1);
532 dy = y * 0x7FFF / (surface_height(s->ds) - 1);
533 } else if (s->last_x == -1 || s->last_y == -1) {
534 dx = 0;
535 dy = 0;
536 } else {
537 dx = x - s->last_x;
538 dy = y - s->last_y;
541 s->last_x = x;
542 s->last_y = y;
544 if (kbd_mouse_is_absolute() || gd_is_grab_active(s)) {
545 kbd_mouse_event(dx, dy, 0, s->button_mask);
548 if (!kbd_mouse_is_absolute() && gd_is_grab_active(s)) {
549 GdkScreen *screen = gtk_widget_get_screen(s->drawing_area);
550 int x = (int)motion->x_root;
551 int y = (int)motion->y_root;
553 /* In relative mode check to see if client pointer hit
554 * one of the screen edges, and if so move it back by
555 * 200 pixels. This is important because the pointer
556 * in the server doesn't correspond 1-for-1, and so
557 * may still be only half way across the screen. Without
558 * this warp, the server pointer would thus appear to hit
559 * an invisible wall */
560 if (x == 0) {
561 x += 200;
563 if (y == 0) {
564 y += 200;
566 if (x == (gdk_screen_get_width(screen) - 1)) {
567 x -= 200;
569 if (y == (gdk_screen_get_height(screen) - 1)) {
570 y -= 200;
573 if (x != (int)motion->x_root || y != (int)motion->y_root) {
574 #if GTK_CHECK_VERSION(3, 0, 0)
575 GdkDevice *dev = gdk_event_get_device((GdkEvent *)motion);
576 gdk_device_warp(dev, screen, x, y);
577 #else
578 GdkDisplay *display = gtk_widget_get_display(widget);
579 gdk_display_warp_pointer(display, screen, x, y);
580 #endif
581 s->last_x = -1;
582 s->last_y = -1;
583 return FALSE;
586 return TRUE;
589 static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,
590 void *opaque)
592 GtkDisplayState *s = opaque;
593 int dx, dy;
594 int n;
596 if (button->button == 1) {
597 n = 0x01;
598 } else if (button->button == 2) {
599 n = 0x04;
600 } else if (button->button == 3) {
601 n = 0x02;
602 } else {
603 n = 0x00;
606 if (button->type == GDK_BUTTON_PRESS) {
607 s->button_mask |= n;
608 } else if (button->type == GDK_BUTTON_RELEASE) {
609 s->button_mask &= ~n;
612 if (kbd_mouse_is_absolute()) {
613 dx = s->last_x * 0x7FFF / (surface_width(s->ds) - 1);
614 dy = s->last_y * 0x7FFF / (surface_height(s->ds) - 1);
615 } else {
616 dx = 0;
617 dy = 0;
620 kbd_mouse_event(dx, dy, 0, s->button_mask);
622 return TRUE;
625 static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
627 int gdk_keycode;
628 int qemu_keycode;
630 gdk_keycode = key->hardware_keycode;
632 if (gdk_keycode < 9) {
633 qemu_keycode = 0;
634 } else if (gdk_keycode < 97) {
635 qemu_keycode = gdk_keycode - 8;
636 } else if (gdk_keycode < 158) {
637 qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
638 } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
639 qemu_keycode = 0x70;
640 } else if (gdk_keycode == 211) { /* backslash */
641 qemu_keycode = 0x73;
642 } else {
643 qemu_keycode = 0;
646 DPRINTF("translated GDK keycode %d to QEMU keycode %d (%s)\n",
647 gdk_keycode, qemu_keycode,
648 (key->type == GDK_KEY_PRESS) ? "down" : "up");
650 if (qemu_keycode & SCANCODE_GREY) {
651 kbd_put_keycode(SCANCODE_EMUL0);
654 if (key->type == GDK_KEY_PRESS) {
655 kbd_put_keycode(qemu_keycode & SCANCODE_KEYCODEMASK);
656 } else if (key->type == GDK_KEY_RELEASE) {
657 kbd_put_keycode(qemu_keycode | SCANCODE_UP);
658 } else {
659 g_assert_not_reached();
662 return TRUE;
665 /** Window Menu Actions **/
667 static void gd_menu_pause(GtkMenuItem *item, void *opaque)
669 GtkDisplayState *s = opaque;
671 if (s->external_pause_update) {
672 return;
674 if (runstate_is_running()) {
675 qmp_stop(NULL);
676 } else {
677 qmp_cont(NULL);
681 static void gd_menu_reset(GtkMenuItem *item, void *opaque)
683 qmp_system_reset(NULL);
686 static void gd_menu_powerdown(GtkMenuItem *item, void *opaque)
688 qmp_system_powerdown(NULL);
691 static void gd_menu_quit(GtkMenuItem *item, void *opaque)
693 qmp_quit(NULL);
696 static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
698 GtkDisplayState *s = opaque;
700 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->vga_item))) {
701 gtk_notebook_set_current_page(GTK_NOTEBOOK(s->notebook), 0);
702 } else {
703 int i;
705 for (i = 0; i < s->nb_vcs; i++) {
706 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->vc[i].menu_item))) {
707 gtk_notebook_set_current_page(GTK_NOTEBOOK(s->notebook), i + 1);
708 break;
714 static void gd_menu_show_tabs(GtkMenuItem *item, void *opaque)
716 GtkDisplayState *s = opaque;
718 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->show_tabs_item))) {
719 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), TRUE);
720 } else {
721 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE);
725 static void gd_menu_full_screen(GtkMenuItem *item, void *opaque)
727 GtkDisplayState *s = opaque;
729 if (!s->full_screen) {
730 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE);
731 gtk_widget_set_size_request(s->menu_bar, 0, 0);
732 gtk_widget_set_size_request(s->drawing_area, -1, -1);
733 gtk_window_fullscreen(GTK_WINDOW(s->window));
734 if (gd_on_vga(s)) {
735 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), TRUE);
737 s->full_screen = TRUE;
738 } else {
739 gtk_window_unfullscreen(GTK_WINDOW(s->window));
740 gd_menu_show_tabs(GTK_MENU_ITEM(s->show_tabs_item), s);
741 gtk_widget_set_size_request(s->menu_bar, -1, -1);
742 gtk_widget_set_size_request(s->drawing_area,
743 surface_width(s->ds),
744 surface_height(s->ds));
745 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), FALSE);
746 s->full_screen = FALSE;
747 s->scale_x = 1.0;
748 s->scale_y = 1.0;
751 gd_update_cursor(s, FALSE);
754 static void gd_menu_zoom_in(GtkMenuItem *item, void *opaque)
756 GtkDisplayState *s = opaque;
758 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item),
759 FALSE);
761 s->scale_x += .25;
762 s->scale_y += .25;
764 gd_update_windowsize(s);
767 static void gd_menu_zoom_out(GtkMenuItem *item, void *opaque)
769 GtkDisplayState *s = opaque;
771 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item),
772 FALSE);
774 s->scale_x -= .25;
775 s->scale_y -= .25;
777 s->scale_x = MAX(s->scale_x, .25);
778 s->scale_y = MAX(s->scale_y, .25);
780 gd_update_windowsize(s);
783 static void gd_menu_zoom_fixed(GtkMenuItem *item, void *opaque)
785 GtkDisplayState *s = opaque;
787 s->scale_x = 1.0;
788 s->scale_y = 1.0;
790 gd_update_windowsize(s);
793 static void gd_menu_zoom_fit(GtkMenuItem *item, void *opaque)
795 GtkDisplayState *s = opaque;
797 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->zoom_fit_item))) {
798 s->free_scale = TRUE;
799 } else {
800 s->free_scale = FALSE;
803 gd_update_windowsize(s);
804 gd_update_full_redraw(s);
807 static void gd_grab_keyboard(GtkDisplayState *s)
809 #if GTK_CHECK_VERSION(3, 0, 0)
810 GdkDisplay *display = gtk_widget_get_display(s->drawing_area);
811 GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
812 GList *devices = gdk_device_manager_list_devices(mgr,
813 GDK_DEVICE_TYPE_MASTER);
814 GList *tmp = devices;
815 while (tmp) {
816 GdkDevice *dev = tmp->data;
817 if (gdk_device_get_source(dev) == GDK_SOURCE_KEYBOARD) {
818 gdk_device_grab(dev,
819 gtk_widget_get_window(s->drawing_area),
820 GDK_OWNERSHIP_NONE,
821 FALSE,
822 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
823 NULL,
824 GDK_CURRENT_TIME);
826 tmp = tmp->next;
828 g_list_free(devices);
829 #else
830 gdk_keyboard_grab(gtk_widget_get_window(s->drawing_area),
831 FALSE,
832 GDK_CURRENT_TIME);
833 #endif
836 static void gd_ungrab_keyboard(GtkDisplayState *s)
838 #if GTK_CHECK_VERSION(3, 0, 0)
839 GdkDisplay *display = gtk_widget_get_display(s->drawing_area);
840 GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
841 GList *devices = gdk_device_manager_list_devices(mgr,
842 GDK_DEVICE_TYPE_MASTER);
843 GList *tmp = devices;
844 while (tmp) {
845 GdkDevice *dev = tmp->data;
846 if (gdk_device_get_source(dev) == GDK_SOURCE_KEYBOARD) {
847 gdk_device_ungrab(dev,
848 GDK_CURRENT_TIME);
850 tmp = tmp->next;
852 g_list_free(devices);
853 #else
854 gdk_keyboard_ungrab(GDK_CURRENT_TIME);
855 #endif
858 static void gd_grab_pointer(GtkDisplayState *s)
860 #if GTK_CHECK_VERSION(3, 0, 0)
861 GdkDisplay *display = gtk_widget_get_display(s->drawing_area);
862 GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
863 GList *devices = gdk_device_manager_list_devices(mgr,
864 GDK_DEVICE_TYPE_MASTER);
865 GList *tmp = devices;
866 while (tmp) {
867 GdkDevice *dev = tmp->data;
868 if (gdk_device_get_source(dev) == GDK_SOURCE_MOUSE) {
869 gdk_device_grab(dev,
870 gtk_widget_get_window(s->drawing_area),
871 GDK_OWNERSHIP_NONE,
872 FALSE, /* All events to come to our
873 window directly */
874 GDK_POINTER_MOTION_MASK |
875 GDK_BUTTON_PRESS_MASK |
876 GDK_BUTTON_RELEASE_MASK |
877 GDK_BUTTON_MOTION_MASK |
878 GDK_SCROLL_MASK,
879 s->null_cursor,
880 GDK_CURRENT_TIME);
882 tmp = tmp->next;
884 g_list_free(devices);
885 #else
886 gdk_pointer_grab(gtk_widget_get_window(s->drawing_area),
887 FALSE, /* All events to come to our window directly */
888 GDK_POINTER_MOTION_MASK |
889 GDK_BUTTON_PRESS_MASK |
890 GDK_BUTTON_RELEASE_MASK |
891 GDK_BUTTON_MOTION_MASK |
892 GDK_SCROLL_MASK,
893 NULL, /* Allow cursor to move over entire desktop */
894 s->null_cursor,
895 GDK_CURRENT_TIME);
896 #endif
899 static void gd_ungrab_pointer(GtkDisplayState *s)
901 #if GTK_CHECK_VERSION(3, 0, 0)
902 GdkDisplay *display = gtk_widget_get_display(s->drawing_area);
903 GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
904 GList *devices = gdk_device_manager_list_devices(mgr,
905 GDK_DEVICE_TYPE_MASTER);
906 GList *tmp = devices;
907 while (tmp) {
908 GdkDevice *dev = tmp->data;
909 if (gdk_device_get_source(dev) == GDK_SOURCE_MOUSE) {
910 gdk_device_ungrab(dev,
911 GDK_CURRENT_TIME);
913 tmp = tmp->next;
915 g_list_free(devices);
916 #else
917 gdk_pointer_ungrab(GDK_CURRENT_TIME);
918 #endif
921 static void gd_menu_grab_input(GtkMenuItem *item, void *opaque)
923 GtkDisplayState *s = opaque;
925 if (gd_is_grab_active(s)) {
926 gd_grab_keyboard(s);
927 gd_grab_pointer(s);
928 } else {
929 gd_ungrab_keyboard(s);
930 gd_ungrab_pointer(s);
933 gd_update_caption(s);
934 gd_update_cursor(s, FALSE);
937 static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
938 gpointer data)
940 GtkDisplayState *s = data;
941 guint last_page;
942 gboolean on_vga;
944 if (!gtk_widget_get_realized(s->notebook)) {
945 return;
948 last_page = gtk_notebook_get_current_page(nb);
950 if (last_page) {
951 gtk_widget_set_size_request(s->vc[last_page - 1].terminal, -1, -1);
954 on_vga = arg2 == 0;
956 if (!on_vga) {
957 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
958 FALSE);
959 } else if (s->full_screen) {
960 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
961 TRUE);
964 if (arg2 == 0) {
965 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->vga_item), TRUE);
966 } else {
967 VirtualConsole *vc = &s->vc[arg2 - 1];
968 VteTerminal *term = VTE_TERMINAL(vc->terminal);
969 int width, height;
971 width = 80 * vte_terminal_get_char_width(term);
972 height = 25 * vte_terminal_get_char_height(term);
974 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item), TRUE);
975 gtk_widget_set_size_request(vc->terminal, width, height);
978 gtk_widget_set_sensitive(s->grab_item, on_vga);
980 gd_update_cursor(s, TRUE);
983 static gboolean gd_enter_event(GtkWidget *widget, GdkEventCrossing *crossing, gpointer data)
985 GtkDisplayState *s = data;
987 if (!gd_is_grab_active(s) && gd_grab_on_hover(s)) {
988 gd_grab_keyboard(s);
991 return TRUE;
994 static gboolean gd_leave_event(GtkWidget *widget, GdkEventCrossing *crossing, gpointer data)
996 GtkDisplayState *s = data;
998 if (!gd_is_grab_active(s) && gd_grab_on_hover(s)) {
999 gd_ungrab_keyboard(s);
1002 return TRUE;
1005 /** Virtual Console Callbacks **/
1007 static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
1009 VirtualConsole *vc = chr->opaque;
1011 return write(vc->fd, buf, len);
1014 static int nb_vcs;
1015 static CharDriverState *vcs[MAX_VCS];
1017 static CharDriverState *gd_vc_handler(ChardevVC *unused)
1019 CharDriverState *chr;
1021 chr = g_malloc0(sizeof(*chr));
1022 chr->chr_write = gd_vc_chr_write;
1024 vcs[nb_vcs++] = chr;
1026 return chr;
1029 void early_gtk_display_init(void)
1031 register_vc_handler(gd_vc_handler);
1034 static gboolean gd_vc_in(GIOChannel *chan, GIOCondition cond, void *opaque)
1036 VirtualConsole *vc = opaque;
1037 uint8_t buffer[1024];
1038 ssize_t len;
1040 len = read(vc->fd, buffer, sizeof(buffer));
1041 if (len <= 0) {
1042 return FALSE;
1045 qemu_chr_be_write(vc->chr, buffer, len);
1047 return TRUE;
1050 static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSList *group)
1052 const char *label;
1053 char buffer[32];
1054 char path[32];
1055 #if VTE_CHECK_VERSION(0, 26, 0)
1056 VtePty *pty;
1057 #endif
1058 GIOChannel *chan;
1059 GtkWidget *scrolled_window;
1060 GtkAdjustment *vadjustment;
1061 int master_fd, slave_fd, ret;
1062 struct termios tty;
1064 snprintf(buffer, sizeof(buffer), "vc%d", index);
1065 snprintf(path, sizeof(path), "<QEMU>/View/VC%d", index);
1067 vc->chr = vcs[index];
1069 if (vc->chr->label) {
1070 label = vc->chr->label;
1071 } else {
1072 label = buffer;
1075 vc->menu_item = gtk_radio_menu_item_new_with_mnemonic(group, label);
1076 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));
1077 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(vc->menu_item), path);
1078 gtk_accel_map_add_entry(path, GDK_KEY_2 + index, GDK_CONTROL_MASK | GDK_MOD1_MASK);
1080 vc->terminal = vte_terminal_new();
1082 ret = openpty(&master_fd, &slave_fd, NULL, NULL, NULL);
1083 g_assert(ret != -1);
1085 /* Set raw attributes on the pty. */
1086 tcgetattr(slave_fd, &tty);
1087 cfmakeraw(&tty);
1088 tcsetattr(slave_fd, TCSAFLUSH, &tty);
1090 #if VTE_CHECK_VERSION(0, 26, 0)
1091 pty = vte_pty_new_foreign(master_fd, NULL);
1092 vte_terminal_set_pty_object(VTE_TERMINAL(vc->terminal), pty);
1093 #else
1094 vte_terminal_set_pty(VTE_TERMINAL(vc->terminal), master_fd);
1095 #endif
1097 vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc->terminal), -1);
1099 vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc->terminal));
1101 scrolled_window = gtk_scrolled_window_new(NULL, vadjustment);
1102 gtk_container_add(GTK_CONTAINER(scrolled_window), vc->terminal);
1104 vte_terminal_set_size(VTE_TERMINAL(vc->terminal), 80, 25);
1106 vc->fd = slave_fd;
1107 vc->chr->opaque = vc;
1108 vc->scrolled_window = scrolled_window;
1110 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vc->scrolled_window),
1111 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1113 gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), scrolled_window, gtk_label_new(label));
1114 g_signal_connect(vc->menu_item, "activate",
1115 G_CALLBACK(gd_menu_switch_vc), s);
1117 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), vc->menu_item);
1119 qemu_chr_generic_open(vc->chr);
1120 if (vc->chr->init) {
1121 vc->chr->init(vc->chr);
1124 chan = g_io_channel_unix_new(vc->fd);
1125 g_io_add_watch(chan, G_IO_IN, gd_vc_in, vc);
1127 return group;
1130 /** Window Creation **/
1132 static void gd_connect_signals(GtkDisplayState *s)
1134 g_signal_connect(s->show_tabs_item, "activate",
1135 G_CALLBACK(gd_menu_show_tabs), s);
1137 g_signal_connect(s->window, "key-press-event",
1138 G_CALLBACK(gd_window_key_event), s);
1139 g_signal_connect(s->window, "delete-event",
1140 G_CALLBACK(gd_window_close), s);
1142 #if GTK_CHECK_VERSION(3, 0, 0)
1143 g_signal_connect(s->drawing_area, "draw",
1144 G_CALLBACK(gd_draw_event), s);
1145 #else
1146 g_signal_connect(s->drawing_area, "expose-event",
1147 G_CALLBACK(gd_expose_event), s);
1148 #endif
1149 g_signal_connect(s->drawing_area, "motion-notify-event",
1150 G_CALLBACK(gd_motion_event), s);
1151 g_signal_connect(s->drawing_area, "button-press-event",
1152 G_CALLBACK(gd_button_event), s);
1153 g_signal_connect(s->drawing_area, "button-release-event",
1154 G_CALLBACK(gd_button_event), s);
1155 g_signal_connect(s->drawing_area, "key-press-event",
1156 G_CALLBACK(gd_key_event), s);
1157 g_signal_connect(s->drawing_area, "key-release-event",
1158 G_CALLBACK(gd_key_event), s);
1160 g_signal_connect(s->pause_item, "activate",
1161 G_CALLBACK(gd_menu_pause), s);
1162 g_signal_connect(s->reset_item, "activate",
1163 G_CALLBACK(gd_menu_reset), s);
1164 g_signal_connect(s->powerdown_item, "activate",
1165 G_CALLBACK(gd_menu_powerdown), s);
1166 g_signal_connect(s->quit_item, "activate",
1167 G_CALLBACK(gd_menu_quit), s);
1168 g_signal_connect(s->full_screen_item, "activate",
1169 G_CALLBACK(gd_menu_full_screen), s);
1170 g_signal_connect(s->zoom_in_item, "activate",
1171 G_CALLBACK(gd_menu_zoom_in), s);
1172 g_signal_connect(s->zoom_out_item, "activate",
1173 G_CALLBACK(gd_menu_zoom_out), s);
1174 g_signal_connect(s->zoom_fixed_item, "activate",
1175 G_CALLBACK(gd_menu_zoom_fixed), s);
1176 g_signal_connect(s->zoom_fit_item, "activate",
1177 G_CALLBACK(gd_menu_zoom_fit), s);
1178 g_signal_connect(s->vga_item, "activate",
1179 G_CALLBACK(gd_menu_switch_vc), s);
1180 g_signal_connect(s->grab_item, "activate",
1181 G_CALLBACK(gd_menu_grab_input), s);
1182 g_signal_connect(s->notebook, "switch-page",
1183 G_CALLBACK(gd_change_page), s);
1184 g_signal_connect(s->drawing_area, "enter-notify-event",
1185 G_CALLBACK(gd_enter_event), s);
1186 g_signal_connect(s->drawing_area, "leave-notify-event",
1187 G_CALLBACK(gd_leave_event), s);
1190 static void gd_create_menus(GtkDisplayState *s)
1192 GtkStockItem item;
1193 GtkAccelGroup *accel_group;
1194 GSList *group = NULL;
1195 GtkWidget *separator;
1196 int i;
1198 accel_group = gtk_accel_group_new();
1199 s->machine_menu = gtk_menu_new();
1200 gtk_menu_set_accel_group(GTK_MENU(s->machine_menu), accel_group);
1201 s->machine_menu_item = gtk_menu_item_new_with_mnemonic(_("_Machine"));
1203 s->pause_item = gtk_check_menu_item_new_with_mnemonic(_("_Pause"));
1204 gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), s->pause_item);
1206 separator = gtk_separator_menu_item_new();
1207 gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), separator);
1209 s->reset_item = gtk_image_menu_item_new_with_mnemonic(_("_Reset"));
1210 gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), s->reset_item);
1212 s->powerdown_item = gtk_image_menu_item_new_with_mnemonic(_("Power _Down"));
1213 gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), s->powerdown_item);
1215 separator = gtk_separator_menu_item_new();
1216 gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), separator);
1218 s->quit_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
1219 gtk_stock_lookup(GTK_STOCK_QUIT, &item);
1220 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->quit_item),
1221 "<QEMU>/Machine/Quit");
1222 gtk_accel_map_add_entry("<QEMU>/Machine/Quit", item.keyval, item.modifier);
1223 gtk_menu_shell_append(GTK_MENU_SHELL(s->machine_menu), s->quit_item);
1225 s->view_menu = gtk_menu_new();
1226 gtk_menu_set_accel_group(GTK_MENU(s->view_menu), accel_group);
1227 s->view_menu_item = gtk_menu_item_new_with_mnemonic(_("_View"));
1229 s->full_screen_item =
1230 gtk_image_menu_item_new_from_stock(GTK_STOCK_FULLSCREEN, NULL);
1231 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->full_screen_item),
1232 "<QEMU>/View/Full Screen");
1233 gtk_accel_map_add_entry("<QEMU>/View/Full Screen", GDK_KEY_f, GDK_CONTROL_MASK | GDK_MOD1_MASK);
1234 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->full_screen_item);
1236 separator = gtk_separator_menu_item_new();
1237 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), separator);
1239 s->zoom_in_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_IN, NULL);
1240 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_in_item),
1241 "<QEMU>/View/Zoom In");
1242 gtk_accel_map_add_entry("<QEMU>/View/Zoom In", GDK_KEY_plus, GDK_CONTROL_MASK | GDK_MOD1_MASK);
1243 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->zoom_in_item);
1245 s->zoom_out_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_OUT, NULL);
1246 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_out_item),
1247 "<QEMU>/View/Zoom Out");
1248 gtk_accel_map_add_entry("<QEMU>/View/Zoom Out", GDK_KEY_minus, GDK_CONTROL_MASK | GDK_MOD1_MASK);
1249 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->zoom_out_item);
1251 s->zoom_fixed_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_100, NULL);
1252 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_fixed_item),
1253 "<QEMU>/View/Zoom Fixed");
1254 gtk_accel_map_add_entry("<QEMU>/View/Zoom Fixed", GDK_KEY_0, GDK_CONTROL_MASK | GDK_MOD1_MASK);
1255 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->zoom_fixed_item);
1257 s->zoom_fit_item = gtk_check_menu_item_new_with_mnemonic(_("Zoom To _Fit"));
1258 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->zoom_fit_item);
1260 separator = gtk_separator_menu_item_new();
1261 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), separator);
1263 s->grab_on_hover_item = gtk_check_menu_item_new_with_mnemonic(_("Grab On _Hover"));
1264 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->grab_on_hover_item);
1266 s->grab_item = gtk_check_menu_item_new_with_mnemonic(_("_Grab Input"));
1267 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),
1268 "<QEMU>/View/Grab Input");
1269 gtk_accel_map_add_entry("<QEMU>/View/Grab Input", GDK_KEY_g, GDK_CONTROL_MASK | GDK_MOD1_MASK);
1270 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->grab_item);
1272 separator = gtk_separator_menu_item_new();
1273 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), separator);
1275 s->vga_item = gtk_radio_menu_item_new_with_mnemonic(group, "_VGA");
1276 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(s->vga_item));
1277 gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->vga_item),
1278 "<QEMU>/View/VGA");
1279 gtk_accel_map_add_entry("<QEMU>/View/VGA", GDK_KEY_1, GDK_CONTROL_MASK | GDK_MOD1_MASK);
1280 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->vga_item);
1282 for (i = 0; i < nb_vcs; i++) {
1283 VirtualConsole *vc = &s->vc[i];
1285 group = gd_vc_init(s, vc, i, group);
1286 s->nb_vcs++;
1289 separator = gtk_separator_menu_item_new();
1290 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), separator);
1292 s->show_tabs_item = gtk_check_menu_item_new_with_mnemonic(_("Show _Tabs"));
1293 gtk_menu_shell_append(GTK_MENU_SHELL(s->view_menu), s->show_tabs_item);
1295 g_object_set_data(G_OBJECT(s->window), "accel_group", accel_group);
1296 gtk_window_add_accel_group(GTK_WINDOW(s->window), accel_group);
1297 s->accel_group = accel_group;
1299 gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->machine_menu_item),
1300 s->machine_menu);
1301 gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->machine_menu_item);
1303 gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->view_menu_item), s->view_menu);
1304 gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->view_menu_item);
1307 static const DisplayChangeListenerOps dcl_ops = {
1308 .dpy_name = "gtk",
1309 .dpy_gfx_update = gd_update,
1310 .dpy_gfx_switch = gd_switch,
1311 .dpy_refresh = gd_refresh,
1314 void gtk_display_init(DisplayState *ds)
1316 GtkDisplayState *s = g_malloc0(sizeof(*s));
1318 gtk_init(NULL, NULL);
1320 s->dcl.ops = &dcl_ops;
1322 s->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1323 #if GTK_CHECK_VERSION(3, 2, 0)
1324 s->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1325 #else
1326 s->vbox = gtk_vbox_new(FALSE, 0);
1327 #endif
1328 s->notebook = gtk_notebook_new();
1329 s->drawing_area = gtk_drawing_area_new();
1330 s->menu_bar = gtk_menu_bar_new();
1332 s->scale_x = 1.0;
1333 s->scale_y = 1.0;
1334 s->free_scale = FALSE;
1336 setlocale(LC_ALL, "");
1337 bindtextdomain("qemu", CONFIG_QEMU_LOCALEDIR);
1338 textdomain("qemu");
1340 s->null_cursor = gdk_cursor_new(GDK_BLANK_CURSOR);
1342 s->mouse_mode_notifier.notify = gd_mouse_mode_change;
1343 qemu_add_mouse_mode_change_notifier(&s->mouse_mode_notifier);
1344 qemu_add_vm_change_state_handler(gd_change_runstate, s);
1346 gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), s->drawing_area, gtk_label_new("VGA"));
1348 gd_create_menus(s);
1350 gd_connect_signals(s);
1352 gtk_widget_add_events(s->drawing_area,
1353 GDK_POINTER_MOTION_MASK |
1354 GDK_BUTTON_PRESS_MASK |
1355 GDK_BUTTON_RELEASE_MASK |
1356 GDK_BUTTON_MOTION_MASK |
1357 GDK_ENTER_NOTIFY_MASK |
1358 GDK_LEAVE_NOTIFY_MASK |
1359 GDK_SCROLL_MASK |
1360 GDK_KEY_PRESS_MASK);
1361 gtk_widget_set_double_buffered(s->drawing_area, FALSE);
1362 gtk_widget_set_can_focus(s->drawing_area, TRUE);
1364 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE);
1365 gtk_notebook_set_show_border(GTK_NOTEBOOK(s->notebook), FALSE);
1367 gd_update_caption(s);
1369 gtk_box_pack_start(GTK_BOX(s->vbox), s->menu_bar, FALSE, TRUE, 0);
1370 gtk_box_pack_start(GTK_BOX(s->vbox), s->notebook, TRUE, TRUE, 0);
1372 gtk_container_add(GTK_CONTAINER(s->window), s->vbox);
1374 gtk_widget_show_all(s->window);
1376 register_displaychangelistener(ds, &s->dcl);
1378 global_state = s;