Wayland: implement scale factor windows as popups - cont'd

This commit is contained in:
ManoloFLTK 2023-10-24 09:43:23 +02:00
parent 434e6a09ed
commit 3868ea90bd
3 changed files with 29 additions and 14 deletions

View File

@ -79,6 +79,8 @@ public:
static const int fl_YValue;
static const int fl_XNegative;
static const int fl_YNegative;
// Used when transient scale windows are implemented as popups
static Fl_Window *transient_scale_parent;
// key_table and key_table_size are used in fl_shortcut to translate key names
struct Keyname {
unsigned int key;

View File

@ -384,9 +384,15 @@ void Fl_Screen_Driver::rescale_all_windows_from_screen(int screen, float f)
}
static void del_transient_window(Fl_Window **pwin) {
delete *pwin;
*pwin = NULL;
static Fl_Window *transient_scale_window = NULL;
Fl_Window *Fl_Screen_Driver::transient_scale_parent = NULL;
static void del_transient_window(void *) {
Fl_Screen_Driver::transient_scale_parent = NULL;
delete (Fl_Image*)transient_scale_window->shape();
delete transient_scale_window;
transient_scale_window = NULL;
}
@ -430,15 +436,14 @@ void Fl_Screen_Driver::transient_scale_display(float f, int nscreen)
win->set_non_modal();
Fl_Window_Driver::driver(win)->screen_num(nscreen);
Fl_Window_Driver::driver(win)->force_position(1);
static Fl_Window *transient = NULL;
if (transient) {
Fl::remove_timeout((Fl_Timeout_Handler)del_transient_window);
delete transient;
if (transient_scale_window) {
Fl::remove_timeout(del_transient_window);
del_transient_window(NULL);
}
transient = win;
transient_scale_window = win;
win->show();
// delete transient win after 1 sec
Fl::add_timeout(1, (Fl_Timeout_Handler)del_transient_window, &transient);
Fl::add_timeout(1, del_transient_window, NULL);
}
// respond to Ctrl-'+' and Ctrl-'-' and Ctrl-'0' (Ctrl-'=' is same as Ctrl-'+') by rescaling all windows

View File

@ -434,6 +434,11 @@ static void destroy_surface_caution_pointer_focus(struct wl_surface *surface,
void Fl_Wayland_Window_Driver::hide() {
if (pWindow == Fl_Screen_Driver::transient_scale_parent) {
// Don't hide the parent of a running transient scale window
// because the transient is a popup and MUST be deleted first.
return;
}
Fl_X* ip = Fl_X::flx(pWindow);
if (hide_common()) return;
if (ip->region) {
@ -1244,7 +1249,6 @@ static const char *get_prog_name() {
item, when there's one, is visible immediately after the tall popup is mapped on display.
*/
static Fl_Window *transient_parent = NULL; // used for transient scale windows
bool Fl_Wayland_Window_Driver::process_menu_or_tooltip(struct wld_window *new_window) {
// a menu window or tooltip
@ -1266,7 +1270,9 @@ bool Fl_Wayland_Window_Driver::process_menu_or_tooltip(struct wld_window *new_wi
}
Fl_Widget *target = (pWindow->tooltip_window() ? Fl_Tooltip::current() : NULL);
if (pWindow->user_data() == &Fl_Screen_Driver::transient_scale_display &&
transient_parent) target = transient_parent;
Fl_Screen_Driver::transient_scale_parent) {
target = Fl_Screen_Driver::transient_scale_parent;
}
if (!target) target = Fl_Window_Driver::menu_parent();
if (!target) target = Fl::belowmouse();
if (!target) target = Fl::first_window();
@ -1343,6 +1349,7 @@ bool Fl_Wayland_Window_Driver::process_menu_or_tooltip(struct wld_window *new_wi
void Fl_Wayland_Window_Driver::makeWindow()
{
Fl_Group::current(0); // get rid of very common user bug: forgot end()
struct wld_window *new_window;
bool is_floatingtitle = false;
wait_for_expose_value = 1;
@ -1369,10 +1376,11 @@ void Fl_Wayland_Window_Driver::makeWindow()
if (pWindow->user_data() == &Fl_Screen_Driver::transient_scale_display &&
Fl::first_window()) {
// put transient scale win at center of top window by making it a tooltip of top
transient_parent = Fl::first_window();
Fl_Screen_Driver::transient_scale_parent = Fl::first_window();
pWindow->set_tooltip_window();
pWindow->position((transient_parent->w() - pWindow->w())/2 ,
(transient_parent->h() - pWindow->h())/2);
pWindow->position(
(Fl_Screen_Driver::transient_scale_parent->w() - pWindow->w())/2 ,
(Fl_Screen_Driver::transient_scale_parent->h() - pWindow->h())/2);
}
if (pWindow->menu_window() || pWindow->tooltip_window()) { // a menu window or tooltip