aboutsummaryrefslogtreecommitdiff
path: root/ui/gtk.c
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2018-08-22 14:15:52 +0100
committerGerd Hoffmann <kraxel@redhat.com>2018-10-12 15:22:18 +0200
commit89d85cde75143325205e332dd97bf1bb8402d7c1 (patch)
tree6b7eec2dc32791ab4f5b3ffc5c6ec3b7383700d0 /ui/gtk.c
parent69ac8c4cb93f2685839ff7b857cef306b388ff3c (diff)
ui: remove support for GTK2 in favour of GTK3
GTK2 was deprecated in the 2.12.0 release with: commit b7715af2b31f47060cc5b4be930d16c13be93fa9 Author: Daniel P. Berrange <berrange@redhat.com> Date: Tue Dec 12 11:34:40 2017 +0000 ui: deprecate use of GTK 2.x in favour of 3.x series The GTK 3.0 release was made in Feb, 2011: https://blog.gtk.org/2011/02/10/gtk-3-0-released/ That will soon be 7 years ago, which is enough time to consider the 3.x series widely supported. Thus we deprecate the GTK 2.x support, which will allow us to delete it in the last release of 2018. By this time, GTK 3.x will be almost 8 years old. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Message-id: 20171212113440.16483-1-berrange@redhat.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> It is thus able to be removed in the 3.1.0 release. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-id: 20180822131554.3398-2-berrange@redhat.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'ui/gtk.c')
-rw-r--r--ui/gtk.c192
1 files changed, 14 insertions, 178 deletions
diff --git a/ui/gtk.c b/ui/gtk.c
index 3ddb5fe162..de8efadec3 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -111,49 +111,6 @@
# define VTE_CHECK_VERSION(a, b, c) 0
#endif
-#if defined(CONFIG_VTE) && !GTK_CHECK_VERSION(3, 0, 0)
-/*
- * The gtk2 vte terminal widget seriously messes up the window resize
- * for some reason. You basically can't make the qemu window smaller
- * any more because the toplevel window geoemtry hints are overridden.
- *
- * Workaround that by hiding all vte widgets, except the one in the
- * current tab.
- *
- * Luckily everything works smooth in gtk3.
- */
-# define VTE_RESIZE_HACK 1
-#endif
-
-#if !GTK_CHECK_VERSION(2, 20, 0)
-#define gtk_widget_get_realized(widget) GTK_WIDGET_REALIZED(widget)
-#endif
-
-#ifndef GDK_IS_X11_DISPLAY
-#define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
-#endif
-#ifndef GDK_IS_WAYLAND_DISPLAY
-#define GDK_IS_WAYLAND_DISPLAY(dpy) (dpy == dpy)
-#endif
-#ifndef GDK_IS_WIN32_DISPLAY
-#define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
-#endif
-
-#if !GTK_CHECK_VERSION(2, 22, 0)
-#define GDK_KEY_0 GDK_0
-#define GDK_KEY_1 GDK_1
-#define GDK_KEY_2 GDK_2
-#define GDK_KEY_f GDK_f
-#define GDK_KEY_g GDK_g
-#define GDK_KEY_m GDK_m
-#define GDK_KEY_q GDK_q
-#define GDK_KEY_plus GDK_plus
-#define GDK_KEY_equal GDK_equal
-#define GDK_KEY_minus GDK_minus
-#define GDK_KEY_Pause GDK_Pause
-#define GDK_KEY_Delete GDK_Delete
-#endif
-
/* Some older mingw versions lack this constant or have
* it conditionally defined */
#ifdef _WIN32
@@ -455,7 +412,8 @@ static void gd_update_full_redraw(VirtualConsole *vc)
{
GtkWidget *area = vc->gfx.drawing_area;
int ww, wh;
- gdk_drawable_get_size(gtk_widget_get_window(area), &ww, &wh);
+ ww = gdk_window_get_width(gtk_widget_get_window(area));
+ wh = gdk_window_get_height(gtk_widget_get_window(area));
#if defined(CONFIG_GTK_GL)
if (vc->gfx.gls && gtk_use_gl_area) {
gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
@@ -530,7 +488,8 @@ static void gd_update(DisplayChangeListener *dcl,
if (!win) {
return;
}
- gdk_drawable_get_size(win, &ww, &wh);
+ ww = gdk_window_get_width(win);
+ wh = gdk_window_get_height(win);
mx = my = 0;
if (ww > fbw) {
@@ -549,7 +508,6 @@ static void gd_refresh(DisplayChangeListener *dcl)
graphic_hw_update(dcl->con);
}
-#if GTK_CHECK_VERSION(3, 0, 0)
static GdkDevice *gd_get_pointer(GdkDisplay *dpy)
{
#if GTK_CHECK_VERSION(3, 20, 0)
@@ -580,24 +538,6 @@ static void gd_mouse_set(DisplayChangeListener *dcl,
vc->s->last_x = x;
vc->s->last_y = y;
}
-#else
-static void gd_mouse_set(DisplayChangeListener *dcl,
- int x, int y, int visible)
-{
- VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
- gint x_root, y_root;
-
- if (qemu_input_is_absolute()) {
- return;
- }
-
- gdk_window_get_root_coords(gtk_widget_get_window(vc->gfx.drawing_area),
- x, y, &x_root, &y_root);
- gdk_display_warp_pointer(gtk_widget_get_display(vc->gfx.drawing_area),
- gtk_widget_get_screen(vc->gfx.drawing_area),
- x_root, y_root);
-}
-#endif
static void gd_cursor_define(DisplayChangeListener *dcl,
QEMUCursor *c)
@@ -619,11 +559,7 @@ static void gd_cursor_define(DisplayChangeListener *dcl,
pixbuf, c->hot_x, c->hot_y);
gdk_window_set_cursor(gtk_widget_get_window(vc->gfx.drawing_area), cursor);
g_object_unref(pixbuf);
-#if !GTK_CHECK_VERSION(3, 0, 0)
- gdk_cursor_unref(cursor);
-#else
g_object_unref(cursor);
-#endif
}
static void gd_switch(DisplayChangeListener *dcl,
@@ -863,7 +799,8 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
fbw = surface_width(vc->gfx.ds);
fbh = surface_height(vc->gfx.ds);
- gdk_drawable_get_size(gtk_widget_get_window(widget), &ww, &wh);
+ ww = gdk_window_get_width(gtk_widget_get_window(widget));
+ wh = gdk_window_get_height(gtk_widget_get_window(widget));
if (s->full_screen) {
vc->gfx.scale_x = (double)ww / fbw;
@@ -907,29 +844,6 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
return TRUE;
}
-#if !GTK_CHECK_VERSION(3, 0, 0)
-static gboolean gd_expose_event(GtkWidget *widget, GdkEventExpose *expose,
- void *opaque)
-{
- cairo_t *cr;
- gboolean ret;
-
- cr = gdk_cairo_create(gtk_widget_get_window(widget));
- cairo_rectangle(cr,
- expose->area.x,
- expose->area.y,
- expose->area.width,
- expose->area.height);
- cairo_clip(cr);
-
- ret = gd_draw_event(widget, cr, opaque);
-
- cairo_destroy(cr);
-
- return ret;
-}
-#endif
-
static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
void *opaque)
{
@@ -947,8 +861,8 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
- gdk_drawable_get_size(gtk_widget_get_window(vc->gfx.drawing_area),
- &ww, &wh);
+ ww = gdk_window_get_width(gtk_widget_get_window(vc->gfx.drawing_area));
+ wh = gdk_window_get_height(gtk_widget_get_window(vc->gfx.drawing_area));
mx = my = 0;
if (ww > fbw) {
@@ -1026,13 +940,8 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
}
if (x != (int)motion->x_root || y != (int)motion->y_root) {
-#if GTK_CHECK_VERSION(3, 0, 0)
GdkDevice *dev = gdk_event_get_device((GdkEvent *)motion);
gdk_device_warp(dev, screen, x, y);
-#else
- GdkDisplay *display = gtk_widget_get_display(widget);
- gdk_display_warp_pointer(display, screen, x, y);
-#endif
s->last_set = FALSE;
return FALSE;
}
@@ -1309,10 +1218,6 @@ static void gd_accel_switch_vc(void *opaque)
VirtualConsole *vc = opaque;
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item), TRUE);
-#if !GTK_CHECK_VERSION(3, 0, 0)
- /* GTK2 sends the accel key to the target console - ignore this until */
- vc->s->ignore_keys = true;
-#endif
}
static void gd_menu_show_tabs(GtkMenuItem *item, void *opaque)
@@ -1539,7 +1444,7 @@ static void gd_grab_update(VirtualConsole *vc, bool kbd, bool ptr)
gdk_seat_ungrab(seat);
}
}
-#elif GTK_CHECK_VERSION(3, 0, 0)
+#else
static void gd_grab_devices(VirtualConsole *vc, bool grab,
GdkInputSource source, GdkEventMask mask,
GdkCursor *cursor)
@@ -1578,14 +1483,10 @@ static void gd_grab_keyboard(VirtualConsole *vc, const char *reason)
#if GTK_CHECK_VERSION(3, 20, 0)
gd_grab_update(vc, true, vc->s->ptr_owner == vc);
-#elif GTK_CHECK_VERSION(3, 0, 0)
+#else
gd_grab_devices(vc, true, GDK_SOURCE_KEYBOARD,
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
NULL);
-#else
- gdk_keyboard_grab(gtk_widget_get_window(vc->gfx.drawing_area),
- FALSE,
- GDK_CURRENT_TIME);
#endif
vc->s->kbd_owner = vc;
gd_update_caption(vc->s);
@@ -1603,10 +1504,8 @@ static void gd_ungrab_keyboard(GtkDisplayState *s)
#if GTK_CHECK_VERSION(3, 20, 0)
gd_grab_update(vc, false, vc->s->ptr_owner == vc);
-#elif GTK_CHECK_VERSION(3, 0, 0)
- gd_grab_devices(vc, false, GDK_SOURCE_KEYBOARD, 0, NULL);
#else
- gdk_keyboard_ungrab(GDK_CURRENT_TIME);
+ gd_grab_devices(vc, false, GDK_SOURCE_KEYBOARD, 0, NULL);
#endif
gd_update_caption(s);
trace_gd_ungrab(vc->label, "kbd");
@@ -1628,7 +1527,7 @@ static void gd_grab_pointer(VirtualConsole *vc, const char *reason)
gd_grab_update(vc, vc->s->kbd_owner == vc, true);
gdk_device_get_position(gd_get_pointer(display),
NULL, &vc->s->grab_x_root, &vc->s->grab_y_root);
-#elif GTK_CHECK_VERSION(3, 0, 0)
+#else
gd_grab_devices(vc, true, GDK_SOURCE_MOUSE,
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_PRESS_MASK |
@@ -1638,19 +1537,6 @@ static void gd_grab_pointer(VirtualConsole *vc, const char *reason)
vc->s->null_cursor);
gdk_device_get_position(gd_get_pointer(display),
NULL, &vc->s->grab_x_root, &vc->s->grab_y_root);
-#else
- gdk_pointer_grab(gtk_widget_get_window(vc->gfx.drawing_area),
- FALSE, /* All events to come to our window directly */
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_MOTION_MASK |
- GDK_SCROLL_MASK,
- NULL, /* Allow cursor to move over entire desktop */
- vc->s->null_cursor,
- GDK_CURRENT_TIME);
- gdk_display_get_pointer(display, NULL,
- &vc->s->grab_x_root, &vc->s->grab_y_root, NULL);
#endif
vc->s->ptr_owner = vc;
gd_update_caption(vc->s);
@@ -1673,16 +1559,11 @@ static void gd_ungrab_pointer(GtkDisplayState *s)
gdk_device_warp(gd_get_pointer(display),
gtk_widget_get_screen(vc->gfx.drawing_area),
vc->s->grab_x_root, vc->s->grab_y_root);
-#elif GTK_CHECK_VERSION(3, 0, 0)
+#else
gd_grab_devices(vc, false, GDK_SOURCE_MOUSE, 0, NULL);
gdk_device_warp(gd_get_pointer(display),
gtk_widget_get_screen(vc->gfx.drawing_area),
vc->s->grab_x_root, vc->s->grab_y_root);
-#else
- gdk_pointer_ungrab(GDK_CURRENT_TIME);
- gdk_display_warp_pointer(display,
- gtk_widget_get_screen(vc->gfx.drawing_area),
- vc->s->grab_x_root, vc->s->grab_y_root);
#endif
gd_update_caption(s);
trace_gd_ungrab(vc->label, "ptr");
@@ -1715,21 +1596,10 @@ static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
return;
}
-#ifdef VTE_RESIZE_HACK
- vc = gd_vc_find_current(s);
- if (vc && vc->type == GD_VC_VTE) {
- gtk_widget_hide(vc->vte.terminal);
- }
-#endif
vc = gd_vc_find_by_page(s, arg2);
if (!vc) {
return;
}
-#ifdef VTE_RESIZE_HACK
- if (vc->type == GD_VC_VTE) {
- gtk_widget_show(vc->vte.terminal);
- }
-#endif
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item),
TRUE);
on_vga = (vc->type == GD_VC_GFX &&
@@ -1963,20 +1833,15 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,
vte_terminal_set_size(VTE_TERMINAL(vc->vte.terminal),
VC_TERM_X_MIN, VC_TERM_Y_MIN);
-#if VTE_CHECK_VERSION(0, 28, 0) && GTK_CHECK_VERSION(3, 0, 0)
+#if VTE_CHECK_VERSION(0, 28, 0)
vadjustment = gtk_scrollable_get_vadjustment
(GTK_SCROLLABLE(vc->vte.terminal));
#else
vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc->vte.terminal));
#endif
-#if GTK_CHECK_VERSION(3, 0, 0)
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
scrollbar = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, vadjustment);
-#else
- box = gtk_hbox_new(false, 2);
- scrollbar = gtk_vscrollbar_new(vadjustment);
-#endif
gtk_box_pack_end(GTK_BOX(box), scrollbar, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(box), vc->vte.terminal, TRUE, TRUE, 0);
@@ -2015,7 +1880,6 @@ static void gd_vcs_init(GtkDisplayState *s, GSList *group,
static void gd_connect_vc_gfx_signals(VirtualConsole *vc)
{
-#if GTK_CHECK_VERSION(3, 0, 0)
g_signal_connect(vc->gfx.drawing_area, "draw",
G_CALLBACK(gd_draw_event), vc);
#if defined(CONFIG_GTK_GL)
@@ -2027,10 +1891,6 @@ static void gd_connect_vc_gfx_signals(VirtualConsole *vc)
G_CALLBACK(gd_resize_event), vc);
}
#endif
-#else
- g_signal_connect(vc->gfx.drawing_area, "expose-event",
- G_CALLBACK(gd_expose_event), vc);
-#endif
if (qemu_console_is_graphic(vc->gfx.dcl.con)) {
g_signal_connect(vc->gfx.drawing_area, "event",
G_CALLBACK(gd_event), vc);
@@ -2234,11 +2094,9 @@ static GtkWidget *gd_create_menu_view(GtkDisplayState *s)
gtk_accel_group_connect(s->accel_group, GDK_KEY_f, HOTKEY_MODIFIERS, 0,
g_cclosure_new_swap(G_CALLBACK(gd_accel_full_screen), s, NULL));
-#if GTK_CHECK_VERSION(3, 8, 0)
gtk_accel_label_set_accel(
GTK_ACCEL_LABEL(gtk_bin_get_child(GTK_BIN(s->full_screen_item))),
GDK_KEY_f, HOTKEY_MODIFIERS);
-#endif
gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->full_screen_item);
separator = gtk_separator_menu_item_new();
@@ -2370,11 +2228,6 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
assert(opts->type == DISPLAY_TYPE_GTK);
s->opts = opts;
-#if !GTK_CHECK_VERSION(3, 0, 0)
- g_printerr("Running QEMU with GTK 2.x is deprecated, and will be removed\n"
- "in a future release. Please switch to GTK 3.x instead\n");
-#endif
-
s->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
#if GTK_CHECK_VERSION(3, 2, 0)
s->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
@@ -2431,23 +2284,6 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
gtk_widget_show_all(s->window);
-#ifdef VTE_RESIZE_HACK
- {
- VirtualConsole *cur = gd_vc_find_current(s);
- if (cur) {
- int i;
-
- for (i = 0; i < s->nb_vcs; i++) {
- VirtualConsole *vc = &s->vc[i];
- if (vc && vc->type == GD_VC_VTE && vc != cur) {
- gtk_widget_hide(vc->vte.terminal);
- }
- }
- gd_update_windowsize(cur);
- }
- }
-#endif
-
vc = gd_vc_find_current(s);
gtk_widget_set_sensitive(s->view_menu, vc != NULL);
#ifdef CONFIG_VTE