wmww / gtk-layer-shell

A library to create panels and other desktop components for Wayland using the Layer Shell protocol
GNU General Public License v3.0
318 stars 16 forks source link

It creates a bigger buffer than it should #106

Closed wb9688 closed 3 years ago

wb9688 commented 3 years ago

I made a GtkWindow with the default set_exclusive_zone(0) and the compositor says that it should be 3840x2114, but GTK Layer Shell somehow creates a buffer that's 3840x2160 (my monitor's resolution) and e.g. gtk_window_get_size() also says that the GtkWindow is 3840x2160, which is obviously incorrect. I could not reproduce this with other apps, so I'm probably doing a call to some GTK API that I shouldn't, but GTK Layer Shell should still obey the compositor as far as I know. For what it's worth, you could find my code here, but it's about 6000 lines, so not really close to a minimal example.

Log with `WAYLAND_DEBUG=1` ``` [4107954.774] -> wl_display@1.get_registry(new id wl_registry@2) [4107954.805] -> wl_display@1.sync(new id wl_callback@3) [4107954.998] wl_display@1.delete_id(3) [4107955.034] wl_registry@2.global(1, "wl_shm", 1) [4107955.046] -> wl_registry@2.bind(1, "wl_shm", 1, new id [unknown]@4) [4107955.122] -> wl_shm@4.create_pool(new id wl_shm_pool@5, fd 11, 2304) [4107955.285] -> wl_shm_pool@5.resize(6912) [4107955.389] -> wl_shm_pool@5.resize(16128) [4107955.504] -> wl_shm_pool@5.resize(34560) [4107955.700] -> wl_shm_pool@5.resize(71424) [4107956.819] -> wl_shm_pool@5.resize(145152) [4107956.904] -> wl_shm_pool@5.resize(292608) [4107958.598] -> wl_shm_pool@5.resize(587520) [4107960.435] -> wl_shm_pool@5.resize(1177344) [4107968.524] wl_registry@2.global(2, "wl_drm", 2) [4107968.538] wl_registry@2.global(3, "zwp_linux_dmabuf_v1", 3) [4107968.545] wl_registry@2.global(4, "wl_compositor", 4) [4107968.550] -> wl_registry@2.bind(4, "wl_compositor", 3, new id [unknown]@6) [4107968.556] wl_registry@2.global(5, "wl_subcompositor", 1) [4107968.561] -> wl_registry@2.bind(5, "wl_subcompositor", 1, new id [unknown]@7) [4107968.568] wl_registry@2.global(6, "wl_data_device_manager", 3) [4107968.574] -> wl_registry@2.bind(6, "wl_data_device_manager", 3, new id [unknown]@8) [4107968.580] wl_registry@2.global(7, "gtk_primary_selection_device_manager", 1) [4107968.587] -> wl_registry@2.bind(7, "gtk_primary_selection_device_manager", 1, new id [unknown]@9) [4107968.592] wl_registry@2.global(8, "zwp_primary_selection_device_manager_v1", 1) [4107968.599] wl_registry@2.global(9, "zwlr_data_control_manager_v1", 2) [4107968.605] wl_registry@2.global(10, "zwlr_output_manager_v1", 2) [4107968.613] wl_registry@2.global(11, "zwlr_output_power_manager_v1", 1) [4107968.621] wl_registry@2.global(12, "xdg_wm_base", 2) [4107968.626] wl_registry@2.global(13, "zwlr_layer_shell_v1", 4) [4107968.634] wl_registry@2.global(14, "zwp_tablet_manager_v2", 1) [4107968.639] -> wl_registry@2.bind(14, "zwp_tablet_manager_v2", 1, new id [unknown]@10) [4107968.648] wl_registry@2.global(15, "wl_seat", 7) [4107968.653] -> wl_registry@2.bind(15, "wl_seat", 5, new id [unknown]@11) [4107970.305] -> wl_compositor@6.create_surface(new id wl_surface@12) [4107970.319] -> gtk_primary_selection_device_manager@9.get_device(new id gtk_primary_selection_device@13, wl_seat@11) [4107970.324] -> wl_data_device_manager@8.get_data_device(new id wl_data_device@14, wl_seat@11) [4107970.390] -> wl_compositor@6.create_surface(new id wl_surface@15) [4107970.395] -> zwp_tablet_manager_v2@10.get_tablet_seat(new id zwp_tablet_seat_v2@16, wl_seat@11) [4107970.401] -> wl_display@1.sync(new id wl_callback@17) [4107970.405] wl_registry@2.global(16, "zwlr_screencopy_manager_v1", 3) [4107970.415] wl_registry@2.global(17, "zwlr_gamma_control_manager_v1", 1) [4107970.420] wl_registry@2.global(18, "zwlr_export_dmabuf_manager_v1", 1) [4107970.425] wl_registry@2.global(19, "zxdg_output_manager_v1", 3) [4107970.430] -> wl_registry@2.bind(19, "zxdg_output_manager_v1", 3, new id [unknown]@18) [4107970.438] -> wl_display@1.sync(new id wl_callback@19) [4107970.441] wl_registry@2.global(20, "zwlr_input_inhibit_manager_v1", 1) [4107970.446] wl_registry@2.global(21, "org_kde_kwin_server_decoration_manager", 1) [4107970.453] -> wl_registry@2.bind(21, "org_kde_kwin_server_decoration_manager", 1, new id [unknown]@20) [4107970.462] wl_registry@2.global(22, "zxdg_decoration_manager_v1", 1) [4107970.469] wl_registry@2.global(23, "zwp_virtual_keyboard_manager_v1", 1) [4107970.475] wl_registry@2.global(24, "zwlr_virtual_pointer_manager_v1", 2) [4107970.480] wl_registry@2.global(25, "zwp_idle_inhibit_manager_v1", 1) [4107970.487] wl_registry@2.global(26, "org_kde_kwin_idle", 1) [4107970.495] wl_registry@2.global(27, "zwlr_foreign_toplevel_manager_v1", 3) [4107970.500] wl_registry@2.global(28, "zwp_pointer_gestures_v1", 1) [4107970.508] -> wl_registry@2.bind(28, "zwp_pointer_gestures_v1", 1, new id [unknown]@21) [4107970.516] wl_registry@2.global(29, "zwp_relative_pointer_manager_v1", 1) [4107970.523] wl_registry@2.global(30, "zwp_pointer_constraints_v1", 1) [4107970.528] wl_registry@2.global(31, "zwp_input_method_manager_v2", 1) [4107970.537] wl_registry@2.global(32, "zwp_text_input_manager_v3", 1) [4107970.541] wl_registry@2.global(33, "wp_presentation", 1) [4107970.547] wl_registry@2.global(34, "wp_viewporter", 1) [4107970.553] wl_registry@2.global(35, "zxdg_exporter_v1", 1) [4107970.560] -> wl_registry@2.bind(35, "zxdg_exporter_v1", 1, new id [unknown]@22) [4107970.569] wl_registry@2.global(36, "zxdg_importer_v1", 1) [4107970.576] -> wl_registry@2.bind(36, "zxdg_importer_v1", 1, new id [unknown]@23) [4107970.584] wl_registry@2.global(37, "zxdg_exporter_v2", 1) [4107970.589] wl_registry@2.global(38, "zxdg_importer_v2", 1) [4107970.597] wl_registry@2.global(39, "zwf_shell_manager_v2", 1) [4107970.602] wl_registry@2.global(40, "gtk_shell1", 3) [4107970.613] -> wl_registry@2.bind(40, "gtk_shell1", 3, new id [unknown]@24) [4107970.624] wl_registry@2.global(43, "wl_output", 3) [4107970.629] -> wl_registry@2.bind(43, "wl_output", 2, new id [unknown]@25) [4107970.657] -> zxdg_output_manager_v1@18.get_xdg_output(new id zxdg_output_v1@26, wl_output@25) [4107970.662] -> wl_display@1.sync(new id wl_callback@27) [4107970.666] wl_callback@3.done(17825) [4107995.451] wl_display@1.delete_id(17) [4107995.457] wl_display@1.delete_id(19) [4107995.459] wl_display@1.delete_id(27) [4107995.460] wl_shm@4.format(0) [4107995.463] wl_shm@4.format(1) [4107995.466] wl_shm@4.format(875709016) [4107995.469] wl_shm@4.format(875708993) [4107995.472] wl_seat@11.name("default") [4107995.475] wl_seat@11.capabilities(7) [4107995.478] -> wl_seat@11.get_pointer(new id wl_pointer@3) [4107995.496] -> zwp_pointer_gestures_v1@21.get_swipe_gesture(new id zwp_pointer_gesture_swipe_v1@28, wl_pointer@3) [4107995.501] -> zwp_pointer_gestures_v1@21.get_pinch_gesture(new id zwp_pointer_gesture_pinch_v1@29, wl_pointer@3) [4107995.506] -> wl_seat@11.get_keyboard(new id wl_keyboard@30) [4107995.515] -> wl_seat@11.get_touch(new id wl_touch@31) [4107995.527] wl_callback@17.done(17825) [4107995.530] wl_callback@19.done(17825) [4107995.532] org_kde_kwin_server_decoration_manager@20.default_mode(1) [4107995.538] wl_output@25.geometry(0, 0, 950, 540, 0, "Philips Consumer Electronics Company", "PHL BDM4350", 0) [4107995.551] wl_output@25.mode(1, 3840, 2160, 59997) [4107995.557] wl_output@25.scale(1) [4107995.559] wl_output@25.done() [4107995.567] zxdg_output_v1@26.name("DP-2") [4107995.570] zxdg_output_v1@26.description("Philips Consumer Electronics Company PHL BDM4350 0x00000CE0 (DP-2)") [4107995.574] zxdg_output_v1@26.logical_position(0, 0) [4107995.579] zxdg_output_v1@26.logical_size(3840, 2160) [4107995.582] wl_output@25.done() [4107995.585] wl_callback@27.done(17825) [4107995.588] -> wl_registry@2.bind(12, "xdg_wm_base", 1, new id [unknown]@27) [4108048.007] -> wl_display@1.get_registry(new id wl_registry@19) [4108048.028] -> wl_display@1.sync(new id wl_callback@17) [4108048.225] wl_display@1.delete_id(17) [4108048.244] wl_keyboard@30.keymap(1, fd 20, 47424) [4108050.604] wl_keyboard@30.repeat_info(40, 400) [4108050.615] wl_registry@19.global(1, "wl_shm", 1) [4108050.632] wl_registry@19.global(2, "wl_drm", 2) [4108050.641] wl_registry@19.global(3, "zwp_linux_dmabuf_v1", 3) [4108050.651] wl_registry@19.global(4, "wl_compositor", 4) [4108050.661] wl_registry@19.global(5, "wl_subcompositor", 1) [4108050.675] wl_registry@19.global(6, "wl_data_device_manager", 3) [4108050.684] wl_registry@19.global(7, "gtk_primary_selection_device_manager", 1) [4108050.694] wl_registry@19.global(8, "zwp_primary_selection_device_manager_v1", 1) [4108050.703] wl_registry@19.global(9, "zwlr_data_control_manager_v1", 2) [4108050.715] wl_registry@19.global(10, "zwlr_output_manager_v1", 2) [4108050.724] wl_registry@19.global(11, "zwlr_output_power_manager_v1", 1) [4108050.737] wl_registry@19.global(12, "xdg_wm_base", 2) [4108050.758] -> wl_registry@19.bind(12, "xdg_wm_base", 2, new id [unknown]@32) [4108050.780] wl_registry@19.global(13, "zwlr_layer_shell_v1", 4) [4108050.794] -> wl_registry@19.bind(13, "zwlr_layer_shell_v1", 4, new id [unknown]@33) [4108050.811] wl_registry@19.global(14, "zwp_tablet_manager_v2", 1) [4108050.821] wl_registry@19.global(15, "wl_seat", 7) [4108050.828] wl_registry@19.global(16, "zwlr_screencopy_manager_v1", 3) [4108050.838] wl_registry@19.global(17, "zwlr_gamma_control_manager_v1", 1) [4108050.848] wl_registry@19.global(18, "zwlr_export_dmabuf_manager_v1", 1) [4108050.858] wl_registry@19.global(19, "zxdg_output_manager_v1", 3) [4108050.865] wl_registry@19.global(20, "zwlr_input_inhibit_manager_v1", 1) [4108050.874] wl_registry@19.global(21, "org_kde_kwin_server_decoration_manager", 1) [4108050.883] wl_registry@19.global(22, "zxdg_decoration_manager_v1", 1) [4108050.891] wl_registry@19.global(23, "zwp_virtual_keyboard_manager_v1", 1) [4108050.898] wl_registry@19.global(24, "zwlr_virtual_pointer_manager_v1", 2) [4108050.907] wl_registry@19.global(25, "zwp_idle_inhibit_manager_v1", 1) [4108050.917] wl_registry@19.global(26, "org_kde_kwin_idle", 1) [4108050.928] wl_registry@19.global(27, "zwlr_foreign_toplevel_manager_v1", 3) [4108050.938] wl_registry@19.global(28, "zwp_pointer_gestures_v1", 1) [4108050.951] wl_registry@19.global(29, "zwp_relative_pointer_manager_v1", 1) [4108050.962] wl_registry@19.global(30, "zwp_pointer_constraints_v1", 1) [4108050.974] wl_registry@19.global(31, "zwp_input_method_manager_v2", 1) [4108050.985] wl_registry@19.global(32, "zwp_text_input_manager_v3", 1) [4108050.994] wl_registry@19.global(33, "wp_presentation", 1) [4108051.003] wl_registry@19.global(34, "wp_viewporter", 1) [4108051.015] wl_registry@19.global(35, "zxdg_exporter_v1", 1) [4108051.023] wl_registry@19.global(36, "zxdg_importer_v1", 1) [4108051.032] wl_registry@19.global(37, "zxdg_exporter_v2", 1) [4108051.039] wl_registry@19.global(38, "zxdg_importer_v2", 1) [4108051.053] wl_registry@19.global(39, "zwf_shell_manager_v2", 1) [4108051.061] wl_registry@19.global(40, "gtk_shell1", 3) [4108051.070] wl_registry@19.global(43, "wl_output", 3) [4108051.077] wl_callback@17.done(17829) [4108059.865] -> wl_compositor@6.create_surface(new id wl_surface@17) [4108343.569] -> wl_surface@17.attach(nil, 0, 0) [4108343.593] -> zwlr_layer_shell_v1@33.get_layer_surface(new id zwlr_layer_surface_v1@34, wl_surface@17, wl_output@25, 1, "gtk-layer-shell") [4108343.604] -> zwlr_layer_surface_v1@34.set_keyboard_interactivity(0) [4108343.607] -> zwlr_layer_surface_v1@34.set_exclusive_zone(0) [4108343.610] -> zwlr_layer_surface_v1@34.set_anchor(15) [4108343.612] -> zwlr_layer_surface_v1@34.set_margin(0, 0, 0, 0) [4108343.617] -> zwlr_layer_surface_v1@34.set_size(0, 0) [4108343.624] -> wl_surface@17.commit() [4108343.627] -> wl_display@1.sync(new id wl_callback@35) [4108343.875] wl_display@1.delete_id(35) [4108343.878] zwlr_layer_surface_v1@34.configure(17830, 3840, 2114) [4108343.882] -> zwlr_layer_surface_v1@34.ack_configure(17830) [4108343.890] wl_callback@35.done(17830) [4108488.126] -> wl_shm@4.create_pool(new id wl_shm_pool@35, fd 24, 33177600) [4108488.151] -> wl_shm_pool@35.create_buffer(new id wl_buffer@36, 0, 3840, 2160, 15360, 0) [4108497.660] -> wl_surface@17.attach(wl_buffer@36, 0, 0) [4108497.679] -> wl_surface@17.set_buffer_scale(1) [4108497.682] -> wl_surface@17.damage(0, 0, 3840, 2160) [4108497.686] -> wl_surface@17.set_input_region(nil) [4108497.694] -> wl_surface@17.frame(new id wl_callback@37) [4108497.697] -> wl_surface@17.commit() [4108510.162] wl_display@1.delete_id(37) [4108510.182] wl_buffer@36.release() [4108510.185] wl_surface@17.enter(wl_output@25) [4108510.192] wl_callback@37.done(19630450) [4108516.307] -> wl_surface@17.attach(wl_buffer@36, 0, 0) [4108516.328] -> wl_surface@17.set_buffer_scale(1) [4108516.331] -> wl_surface@17.damage(0, 0, 3840, 2160) [4108516.342] -> wl_surface@17.frame(new id wl_callback@37) [4108516.347] -> wl_surface@17.commit() [4108518.606] wl_buffer@36.release() [4108527.840] wl_display@1.delete_id(37) [4108527.856] wl_callback@37.done(19630471) [4108534.065] -> wl_surface@17.attach(wl_buffer@36, 0, 0) [4108534.098] -> wl_surface@17.set_buffer_scale(1) [4108534.103] -> wl_surface@17.damage(0, 0, 3840, 2160) [4108534.122] -> wl_surface@17.frame(new id wl_callback@37) [4108534.128] -> wl_surface@17.commit() [4108537.673] wl_buffer@36.release() [4108545.457] wl_display@1.delete_id(37) [4108545.465] wl_callback@37.done(19630489) ```
wmww commented 3 years ago

Nice to see a file manager with a traditional desktop background architecture attempting Wayland support with Layer shell. I've been hoping someone would do that for MATE for a while. Wasn't expecting it from PCManFM.

I'm not exactly sure what's going on, but here are the factors at play:

wb9688 commented 3 years ago

I found out that it works when I remove either https://github.com/wb9688/pcmanfm/blob/b5ca2683d5724d3e51789640de907658735bcb03/src/desktop.c#L4357 (gtk_window_set_resizable) or https://github.com/wb9688/pcmanfm/blob/b5ca2683d5724d3e51789640de907658735bcb03/src/desktop.c#L5042 (gtk_window_set_default_size). I could reproduce it with the following minimal example:

#include <gtk/gtk.h>
#include <gtk-layer-shell/gtk-layer-shell.h>

#define MONITOR_WIDTH 3840
#define MONITOR_HEIGHT 2160

int main(int argc, char *argv[]) {
    gtk_init(&argc, &argv);

    GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_container_set_border_width(GTK_CONTAINER(window), 12);

    gtk_window_set_default_size(GTK_WINDOW(window), MONITOR_WIDTH, MONITOR_HEIGHT);
    gtk_window_set_resizable(GTK_WINDOW(window), FALSE);

    gtk_layer_init_for_window(GTK_WINDOW(window));
    gtk_layer_set_layer(GTK_WINDOW(window), GTK_LAYER_SHELL_LAYER_BOTTOM);
    gtk_layer_set_anchor(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_LEFT, TRUE);
    gtk_layer_set_anchor(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_RIGHT, TRUE);
    gtk_layer_set_anchor(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_TOP, TRUE);
    gtk_layer_set_anchor(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE);
    gtk_layer_set_exclusive_zone(GTK_WINDOW(window), 0);

    gtk_widget_show(window);

    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_main();

    return 0;
}

I think that at least a log message (g_critical?) would be appropriate for such situations.

wmww commented 3 years ago

Thanks for the minimal example, but I don't think this needs to be addressed. Fixing, or detecting and warning about every possible unexpected way an app could use GTK in conjunction with gtk-layer-shell is out of scope.

It does seem like this would always be the result of an app bug and thus a warning could be appropriate, but I'm not convinced there is no situation that would trigger such a warning for a valid app. Then I get another but report of "gtk-layer-shell spits out dumb warnings on my app that works fine" and then I have to hunt down what's going on there, make a more complicated check, etc. What I'm trying to say is that it's not an unreasonable request, but I don't think it's worth it unless someone can show that it is a common case and a warning would help many developers.

wb9688 commented 3 years ago

Based on https://github.com/swaywm/wlr-protocols/blob/d1598e82240d6e8ca57729495a94d4e11d222033/unstable/wlr-layer-shell-unstable-v1.xml#L341 it seems like it's not actually incorrect to disobey the compositor, so I'd be fine with that. Thanks for your help!