From f01216f167bad1ad2efff1c351c9d310ef1104a2 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Tue, 17 May 2022 10:40:09 +0200 Subject: [PATCH] Weston support: handle click on titlebar. --- src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx | 10 ++++++---- src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx | 11 +++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx index 7b4b34116..27512a43e 100644 --- a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx @@ -227,10 +227,12 @@ struct wl_display *Fl_Wayland_Screen_Driver::wl_display = NULL; Fl_Window *Fl_Wayland_Screen_Driver::surface_to_window(struct wl_surface *surface) { - Fl_X *xp = Fl_X::first; - while (xp) { - if (xp->xid->wl_surface == surface) return xp->w; - xp = xp->next; + if (surface) { + Fl_X *xp = Fl_X::first; + while (xp) { + if (xp->xid->wl_surface == surface) return xp->w; + xp = xp->next; + } } return NULL; } diff --git a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx index 587b15668..934cb4de6 100644 --- a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx @@ -790,10 +790,12 @@ static void handle_configure(struct libdecor_frame *frame, "There is no way to know if the surface is currently minimized, nor is there any way to unset minimization on this surface. If you are looking to throttle redrawing when minimized, please instead use the wl_surface.frame event" */ - if (window_state == LIBDECOR_WINDOW_STATE_NONE) { - Fl::handle(FL_UNFOCUS, window->fl_win); - } - else if (window_state & LIBDECOR_WINDOW_STATE_ACTIVE) { + if (window_state & LIBDECOR_WINDOW_STATE_ACTIVE) { + if (Fl_Wayland_Screen_Driver::compositor == Fl_Wayland_Screen_Driver::WESTON) { + // After click on titlebar, weston calls wl_keyboard_enter() for a + // titlebar-related surface that FLTK can't identify, so we send FL_FOCUS here. + Fl::handle(FL_FOCUS, window->fl_win); + } if (!window->fl_win->border()) libdecor_frame_set_visibility(window->frame, false); else if (!libdecor_frame_is_visible(window->frame)) libdecor_frame_set_visibility(window->frame, true); } @@ -833,6 +835,7 @@ void Fl_Wayland_Window_Driver::wait_for_expose() wl_display_roundtrip(Fl_Wayland_Screen_Driver::wl_display); } } else if (xid->kind == DECORATED) { + // necessary for the windowfocus demo program with recent Wayland versions if (!(xid->state & LIBDECOR_WINDOW_STATE_ACTIVE)) { wl_display_dispatch(Fl_Wayland_Screen_Driver::wl_display); }