Fix: Wayland backend draws everything two or three times (#708)

This commit is contained in:
ManoloFLTK 2023-03-24 15:34:35 +01:00
parent dcb4c39956
commit e918d94b67

View File

@ -641,8 +641,9 @@ static void surface_enter(void *data, struct wl_surface *wl_surface, struct wl_o
return;
//printf("surface_enter win=%p wl_output=%p wld_scale=%d\n", window->fl_win, wl_output, output->wld_scale);
window->output = output;
Fl_Wayland_Window_Driver *win_driver = Fl_Wayland_Window_Driver::driver(window->fl_win);
float pre_scale = Fl::screen_scale(win_driver->screen_num()) * win_driver->wld_scale();
window->output = output;
if (!window->fl_win->parent()) { // for top-level, set its screen number
Fl_Wayland_Screen_Driver::output *running_output;
Fl_Wayland_Screen_Driver *scr_dr = (Fl_Wayland_Screen_Driver*)Fl::screen_driver();
@ -660,9 +661,13 @@ static void surface_enter(void *data, struct wl_surface *wl_surface, struct wl_o
Fl_Wayland_Graphics_Driver::buffer_release(window);
window->fl_win->redraw();
} else {
win_driver->is_a_rescale(true);
window->fl_win->size(window->fl_win->w(), window->fl_win->h());
win_driver->is_a_rescale(false);
float post_scale = Fl::screen_scale(win_driver->screen_num()) * output->wld_scale;
//printf("pre_scale=%.1f post_scale=%.1f\n", pre_scale, post_scale);
if (window->fl_win->as_gl_window() || post_scale != pre_scale) {
win_driver->is_a_rescale(true);
window->fl_win->size(window->fl_win->w(), window->fl_win->h());
win_driver->is_a_rescale(false);
}
if (window->fl_win->as_gl_window())
wl_surface_set_buffer_scale(window->wl_surface, output->wld_scale);
}
@ -690,6 +695,8 @@ static void handle_configure(struct libdecor_frame *frame,
enum libdecor_window_state window_state;
struct libdecor_state *state;
Fl_Wayland_Window_Driver *driver = Fl_Wayland_Window_Driver::driver(window->fl_win);
// true exactly for the 1st run of handle_configure() for this window
bool is_1st_run = (window->xdg_surface == 0);
// true exactly for the 2nd run of handle_configure() for this window
bool is_2nd_run = (window->xdg_surface != 0 && driver->wait_for_expose_value);
float f = Fl::screen_scale(window->fl_win->screen_num());
@ -766,7 +773,6 @@ static void handle_configure(struct libdecor_frame *frame,
}
libdecor_state_free(state);
window->fl_win->redraw();
// necessary with SSD
driver->in_handle_configure = true;
if (!window->fl_win->as_gl_window()) {
@ -775,6 +781,9 @@ static void handle_configure(struct libdecor_frame *frame,
driver->Fl_Window_Driver::flush(); // GL window
}
driver->in_handle_configure = false;
if (Fl_Wayland_Screen_Driver::compositor != Fl_Wayland_Screen_Driver::WESTON || !is_1st_run) {
window->fl_win->clear_damage();
}
}
@ -841,8 +850,8 @@ static void xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, u
}
window->configured_width = window->fl_win->w();
window->configured_height = window->fl_win->h();
window->fl_win->redraw();
Fl_Window_Driver::driver(window->fl_win)->flush();
window->fl_win->clear_damage();
}
static const struct xdg_surface_listener xdg_surface_listener = {