From c427f037ceae283d2ac0c15e50d6162eb82de62c Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Fri, 4 Aug 2023 19:14:13 +0200 Subject: Improve procedure to close decorated Wayland window Libdecor complicates what should be simple, to close a decorated window, because it uses the titlebar after return from the closing callback function. Thus, FLTK delays the sending of the FL_CLOSE event to the window, only when libdecor runs in CSD mode. --- src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx index e6fa514ce..28001ff4f 100644 --- a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx @@ -885,19 +885,28 @@ void Fl_Wayland_Window_Driver::wait_for_expose() } } + static void delayed_close(void *data) { Fl::remove_check(delayed_close, data); Fl::handle(FL_CLOSE, (Fl_Window*)data); } + static void handle_close(struct libdecor_frame *frame, void *user_data) { // runs when the close button of a window titlebar is pushed // or after "Quit" of the application menu // or after the Kill command of Sway struct wld_window* wl_win = (struct wld_window*)user_data; - // the close window attempt is delayed because libdecor - // uses the frame after return from this function - Fl::add_check(delayed_close, wl_win->fl_win); + int X, Y = 0; + if (wl_win->kind == Fl_Wayland_Window_Driver::DECORATED) { + libdecor_frame_translate_coordinate(wl_win->frame, 0, 0, &X, &Y); + } + if (Y == 0) Fl::handle(FL_CLOSE, wl_win->fl_win); + else { + // the close window attempt is delayed because libdecor + // uses the frame after return from this function + Fl::add_check(delayed_close, wl_win->fl_win); + } } -- cgit v1.2.3