Under Wayland window position is not recalculated when application initiates resizing causing part of window to go off screen.
Affected version
Ubuntu 20.04.3 mutter 3.36.9-0ubuntu0.20.04.1 Gnome Wayland
Bug summary
When application requests resizing of top level window its position is not recalculated so part of window may go off screen after resizing. I noticed it using QEMU Gtk UI under Wayland when VM changes screen resolution.
Steps to reproduce
The following program demonstrates it (it is more or less what QEMU does):
$ cat gtk.c
#include <gtk/gtk.h>
static GtkWidget *window;
static void cb_resize(GtkMenuItem *item, void *opaque)
{
GtkWidget *drawing_area = opaque;
// gtk_widget_hide(window);
gtk_widget_set_size_request(drawing_area, 1280, 960);
// gtk_widget_show(window);
}
int main(int argc, char *argv[]) {
GtkWidget *vbox;
GtkWidget *notebook;
GtkWidget *menu_bar;
GtkWidget *drawing_area;
GtkWidget *menu_resize;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
notebook = gtk_notebook_new();
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
drawing_area = gtk_drawing_area_new();
gtk_widget_set_size_request(drawing_area, 640, 480);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
drawing_area, gtk_label_new("some label"));
menu_bar = gtk_menu_bar_new();
menu_resize = gtk_menu_item_new_with_mnemonic("_Resize");
g_signal_connect(menu_resize, "activate",
G_CALLBACK(cb_resize), drawing_area);
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), menu_resize);
gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(window);
g_signal_connect(window, "destroy",
G_CALLBACK(gtk_main_quit), NULL);
gtk_main();
return 0;
}
$ cc -o gtk $(pkg-config --cflags gtk+-3.0) gtk.c $(pkg-config --libs gtk+-3.0)
Run ./gtk
, move window to the bottom of the screen, double click Resize. Window size is increased, but window position remains the same so bottom part goes off screen
If I run the same program under Xwayland:
WAYLAND_DISPLAY= ./gtk
and do the same, window position is recalculated so that it fully visible after resizing.
What happened
Window size was increased and part of window went off screen.
What did you expect to happen
Window position should have been recalculated and window moved so it is fully visible with new size.