From 45422a7d1952eb4094c287373afc7f7a1a23ae4a Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:52:35 +0100 Subject: [PATCH] Add popup_window() virtual member functions to Fl_Window_Driver --- src/Fl_Menu.cxx | 12 ++----- src/Fl_Tooltip.cxx | 2 +- src/Fl_Window_Driver.H | 5 ++- src/Fl_Window_Driver.cxx | 2 -- .../Wayland/Fl_Wayland_Window_Driver.H | 3 ++ .../Wayland/Fl_Wayland_Window_Driver.cxx | 34 +++++++++++++------ 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx index 312d908e6..4aae40ecf 100644 --- a/src/Fl_Menu.cxx +++ b/src/Fl_Menu.cxx @@ -115,7 +115,7 @@ protected: Fl_Menu_Window(X, Y, W, H, 0) { menu = m; set_menu_window(); - Fl_Window_Driver::driver(this)->fltk_menu_window = true; + Fl_Window_Driver::driver(this)->popup_window(true); end(); set_modal(); clear_border(); @@ -184,16 +184,10 @@ Fl_Window *Fl_Window_Driver::menu_parent(int *display_height) { } static menuwindow *to_menuwindow(Fl_Window *win) { - if (!Fl_Window_Driver::driver(win)->fltk_menu_window) return NULL; + if (!Fl_Window_Driver::driver(win)->popup_window() || !win->menu_window()) return NULL; return ((window_with_items*)win)->as_menuwindow(); } -/** Returns whether win is a menutitle window */ -bool Fl_Window_Driver::is_menutitle(Fl_Window *win) { - if (!Fl_Window_Driver::driver(win)->fltk_menu_window) return false; - return (((window_with_items*)win)->as_menuwindow() == NULL); -} - /** Accessor to the "origin" member variable of class menuwindow. Variable origin is not NULL when 2 menuwindow's occur, one being a submenu of the other; it links the menuwindow at right to the one at left. */ @@ -234,7 +228,7 @@ int *Fl_Window_Driver::menu_offset_y(Fl_Window *win) { /** Returns whether win is a non-menubar menutitle */ bool Fl_Window_Driver::is_floating_title(Fl_Window *win) { - if (!Fl_Window_Driver::driver(win)->fltk_menu_window) return false; + if (!Fl_Window_Driver::driver(win)->popup_window() || !win->menu_window()) return false; Fl_Window *mwin = ((window_with_items*)win)->as_menuwindow(); return !mwin && !((menutitle*)win)->in_menubar; } diff --git a/src/Fl_Tooltip.cxx b/src/Fl_Tooltip.cxx index 1be2078bf..992ac3f2c 100644 --- a/src/Fl_Tooltip.cxx +++ b/src/Fl_Tooltip.cxx @@ -51,7 +51,7 @@ public: Fl_TooltipBox() : Fl_Menu_Window(0, 0) { set_override(); set_tooltip_window(); - Fl_Window_Driver::driver(this)->fltk_tooltip_window = true; + Fl_Window_Driver::driver(this)->popup_window(true); end(); } void draw() FL_OVERRIDE; diff --git a/src/Fl_Window_Driver.H b/src/Fl_Window_Driver.H index 5892a3a31..c85cc84d8 100644 --- a/src/Fl_Window_Driver.H +++ b/src/Fl_Window_Driver.H @@ -65,8 +65,6 @@ public: static fl_uintptr_t xid(const Fl_Window *win); static Fl_Window *find(fl_uintptr_t xid); int wait_for_expose_value; - bool fltk_menu_window; // true for FLTK menu window - bool fltk_tooltip_window; // true for FLTK tooltip window Fl_Image_Surface *other_xid; // offscreen bitmap (overlay and double-buffered windows) int screen_num(); void screen_num(int n) { screen_num_ = n; } @@ -213,9 +211,10 @@ public: static int *menu_offset_y(Fl_Window*); static bool is_floating_title(Fl_Window *); static void scroll_to_selected_item(Fl_Window *); - static bool is_menutitle(Fl_Window *); virtual fl_uintptr_t os_id() { return 0; } + virtual void popup_window(bool v) {} + virtual bool popup_window() { return false; } }; #endif // FL_WINDOW_DRIVER_H diff --git a/src/Fl_Window_Driver.cxx b/src/Fl_Window_Driver.cxx index d4ca4647d..c09581625 100644 --- a/src/Fl_Window_Driver.cxx +++ b/src/Fl_Window_Driver.cxx @@ -43,8 +43,6 @@ Fl_Window_Driver::Fl_Window_Driver(Fl_Window *win) wait_for_expose_value = 0; other_xid = 0; screen_num_ = 0; - fltk_menu_window = false; - fltk_tooltip_window = false; } diff --git a/src/drivers/Wayland/Fl_Wayland_Window_Driver.H b/src/drivers/Wayland/Fl_Wayland_Window_Driver.H index 8bc1a10f8..bde5b8559 100644 --- a/src/drivers/Wayland/Fl_Wayland_Window_Driver.H +++ b/src/drivers/Wayland/Fl_Wayland_Window_Driver.H @@ -61,6 +61,7 @@ private: Fl_Cursor standard_cursor_; // window's standard custom kind void delete_cursor_(struct wld_window *, bool delete_rgb = true); struct gl_start_support *gl_start_support_; // for support of gl_start/gl_finish + bool is_popup_window_; public: inline Fl_Cursor standard_cursor() { return standard_cursor_; }; bool in_handle_configure; // distinguish OS and user window resize @@ -131,6 +132,8 @@ public: int scroll(int src_x, int src_y, int src_w, int src_h, int dest_x, int dest_y, void (*draw_area)(void*, int,int,int,int), void* data) FL_OVERRIDE; void wait_for_expose() FL_OVERRIDE; + void popup_window(bool v) FL_OVERRIDE; + bool popup_window() FL_OVERRIDE; // menu-related stuff void reposition_menu_window(int x, int y) FL_OVERRIDE; void menu_window_area(int &X, int &Y, int &W, int &H, int nscreen = -1) FL_OVERRIDE; diff --git a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx index 5e3876f70..1c565fa53 100644 --- a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx @@ -68,6 +68,7 @@ Fl_Wayland_Window_Driver::Fl_Wayland_Window_Driver(Fl_Window *win) : Fl_Window_D screen_num_ = -1; gl_start_support_ = NULL; subRect_ = NULL; + is_popup_window_ = false; } @@ -1279,12 +1280,12 @@ bool Fl_Wayland_Window_Driver::process_menu_or_tooltip(struct wld_window *new_wi xdg_surface_add_listener(new_window->xdg_surface, &xdg_surface_listener, new_window); Fl_Wayland_Window_Driver::new_popup = true; Fl_Window *menu_origin = NULL; - if (fltk_menu_window) { + if (pWindow->menu_window()) { menu_origin = Fl_Window_Driver::menu_leftorigin(pWindow); if (!menu_origin && !previous_floatingtitle) menu_origin = Fl_Window_Driver::menu_title(pWindow); } - Fl_Widget *target = (fltk_tooltip_window ? Fl_Tooltip::current() : NULL); + Fl_Widget *target = (pWindow->tooltip_window() ? Fl_Tooltip::current() : NULL); if (pWindow->user_data() == &Fl_Screen_Driver::transient_scale_display && Fl_Screen_Driver::transient_scale_parent) { target = Fl_Screen_Driver::transient_scale_parent; @@ -1293,7 +1294,9 @@ bool Fl_Wayland_Window_Driver::process_menu_or_tooltip(struct wld_window *new_wi if (!target) target = Fl::belowmouse(); if (!target) target = Fl::first_window(); Fl_Window *parent_win = target->top_window(); - while (parent_win && Fl_Window_Driver::driver(parent_win)->fltk_menu_window) parent_win = Fl::next_window(parent_win); + while (parent_win && parent_win->menu_window() && driver(parent_win)->popup_window()) { + parent_win = Fl::next_window(parent_win); + } Fl_Window *origin_win = (menu_origin ? menu_origin : parent_win); struct wld_window * parent_xid = fl_wl_xid(origin_win); struct xdg_surface *parent_xdg = parent_xid->xdg_surface; @@ -1394,13 +1397,13 @@ void Fl_Wayland_Window_Driver::makeWindow() // put transient scale win at center of top window by making it a tooltip of top Fl_Screen_Driver::transient_scale_parent = Fl::first_window(); pWindow->set_tooltip_window(); - fltk_tooltip_window = true; + popup_window(true); pWindow->position( (Fl_Screen_Driver::transient_scale_parent->w() - pWindow->w())/2 , (Fl_Screen_Driver::transient_scale_parent->h() - pWindow->h())/2); } - if (fltk_menu_window || fltk_tooltip_window) { // a menu window or tooltip + if (popup_window()) { // a menu window or tooltip is_floatingtitle = process_menu_or_tooltip(new_window); } else if (pWindow->border() && !pWindow->parent() ) { // a decorated window @@ -1494,7 +1497,7 @@ void Fl_Wayland_Window_Driver::makeWindow() pWindow->redraw(); pWindow->handle(Fl::e_number = FL_SHOW); // get child windows to appear Fl::e_number = old_event; - if (fltk_menu_window && !is_floatingtitle) { + if (pWindow->menu_window() && popup_window() && !is_floatingtitle) { // make sure each menu window is mapped with its constraints before mapping next popup pWindow->wait_for_expose(); if (previous_floatingtitle) { // a menuwindow with a menutitle @@ -1840,13 +1843,12 @@ void Fl_Wayland_Window_Driver::resize(int X, int Y, int W, int H) { if (H < 1) H = 1; } // toplevel, non-popup windows must have origin at 0,0 - if (!pWindow->parent() && - !(fltk_menu_window || fltk_tooltip_window)) X = Y = 0; + if (!pWindow->parent() && !popup_window()) X = Y = 0; pWindow->Fl_Group::resize(X,Y,W,H); //fprintf(stderr, "resize: win=%p to %dx%d\n", pWindow, W, H); if (shown()) {pWindow->redraw();} } else { - if (pWindow->parent() || fltk_menu_window || fltk_tooltip_window) { + if (pWindow->parent() || popup_window()) { x(X); y(Y); //fprintf(stderr, "move menuwin=%p x()=%d\n", pWindow, X); } else { @@ -2022,7 +2024,7 @@ void Fl_Wayland_Window_Driver::reposition_menu_window(int x, int y) { struct wld_window * parent_xid = fl_wl_xid(menu_origin); float f = Fl::screen_scale(Fl_Window_Driver::menu_parent()->screen_num()); int popup_x = x * f, popup_y = y * f + xid_menu->state; - if (Fl_Window_Driver::driver(menu_origin)->fltk_menu_window) { + if (menu_origin->menu_window() && driver(menu_origin)->popup_window()) { popup_x -= menu_origin->x() * f; popup_y -= menu_origin->y() * f; } @@ -2064,7 +2066,7 @@ void Fl_Wayland_Window_Driver::menu_window_area(int &X, int &Y, int &W, int &H, int HH; Fl_Window *parent = Fl_Window_Driver::menu_parent(&HH); if (parent) { - if (fltk_menu_window && pWindow->h() > HH) { + if (pWindow->menu_window() && popup_window() && pWindow->h() > HH) { // tall menu: set top (Y) and bottom (Y+H) bounds relatively to reference window int ih = Fl_Window_Driver::menu_itemheight(pWindow); X = -50000; @@ -2158,3 +2160,13 @@ void Fl_Wayland_Window_Driver::un_maximize() { struct wld_window *xid = (struct wld_window *)Fl_X::flx(pWindow)->xid; if (xid->kind == DECORATED) libdecor_frame_unset_maximized(xid->frame); } + + +void Fl_Wayland_Window_Driver::popup_window(bool v) { + is_popup_window_ = v; +} + + +bool Fl_Wayland_Window_Driver::popup_window() { + return is_popup_window_; +}