moveable modal dialog

14 views
Skip to first unread message

Klaus

unread,
May 3, 2026, 7:37:14 AM (2 days ago) May 3
to fltk.general
Hi!

I want to create a dialog window which is modal, means it is the only
window which reacts on any kind of input. But this window should be
moveable.

All my experiments result in 2 kinds of behavior:

1. ) The window is the only one which reacts on inputs, but it can't be
moved ( without also moving the main application window )

2. ) The window is moveable, but the main window still reacts on all
kind of input which enables me to generate multiple dialog windows.

Non of both is what I need :-)




#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <iostream>

void open_dialog(Fl_Widget*, void* v) {
Fl_Window* mainwin = (Fl_Window*)v;

Fl_Window* dlg = new Fl_Window(300, 200, "Dialog");

mainwin->deactivate(); // did not deactivate the main window. It
still reacts on inputs

dlg->callback([](Fl_Widget* w, void* data) {
Fl_Window* mainwin = (Fl_Window*)data;
mainwin->activate();
w->hide();
}, mainwin);

dlg->end();
dlg->show();
}

#if 0

void open_dialog(Fl_Widget*, void*) {
Fl_Window* dlg = new Fl_Window(300, 200, "Dialog");
dlg->set_modal(); // it is now modal, but not longer moveable

new Fl_Button(100, 120, 100, 30, "OK");

dlg->end();
dlg->show();
}

#endif

int main() {
Fl_Window win(400, 300, "Mainwin");

Fl_Button btn(150, 130, 100, 30, "Dialog open");
btn.callback(open_dialog, &win);

win.end();
win.show();

return Fl::run();
}




#if 0

class CustomDialog : public Fl_Window {
int selected_value;


static void button_cb(Fl_Widget* w, void* data) {
CustomDialog* dialog = (CustomDialog*)w->parent();
dialog->selected_value = (int)(long)data;
dialog->hide(); //
}

public:
CustomDialog() : Fl_Window(300, 150, "Wahl treffen"),
selected_value(-1) {

//this->set_non_modal(); // main window still reacts on inputs
but win is moveable
this->set_modal(); // main win did not react n inputs (fine)
but dialog can't be moved anymore
this->border(1);

// Drei Knöpfe mit unterschiedlichen Rückgabewerten
Fl_Button* b1 = new Fl_Button(20, 50, 80, 40, "Wert 10");
Fl_Button* b2 = new Fl_Button(110, 50, 80, 40, "Wert 20");
Fl_Button* b3 = new Fl_Button(200, 50, 80, 40, "Wert 30");

b1->callback(button_cb, (void*)10);
b2->callback(button_cb, (void*)20);
b3->callback(button_cb, (void*)30);

this->end();
}


int show_and_wait() {
this->show();
while (this->shown()) {
Fl::wait();
}
return selected_value;
}
};

void open_dialog_cb(Fl_Widget*, void*) {
Fl_Group::current(0);
CustomDialog* diag = new CustomDialog();


diag->parent(NULL);


diag->border(1);
diag->position(500, 400);


int result = diag->show_and_wait(); // Blockiert hier

if (result != -1) {
std::cout << "Coice " << result << std::endl;
} else {
std::cout << "Np choice" << std::endl;
}

delete diag;
}

int main() {
Fl_Window* main_win = new Fl_Window(400, 300, "FLTK 1.5 App");
Fl_Button* btn = new Fl_Button(150, 130, 100, 40, "Dialog");
btn->callback(open_dialog_cb);
main_win->end();
main_win->show();
return Fl::run();
}

#endif

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <iostream>

#if 0

class CustomDialog : public Fl_Window {
int result;
public:

CustomDialog() : Fl_Window(300, 150, "Völlig Frei"), result(-1) {
this->set_non_modal();

Fl_Button* b = new Fl_Button(100, 50, 100, 40, "Wert 20");
b->callback(btn_cb, (void*)20);
this->end();
}

static void btn_cb(Fl_Widget* w, void* data) {
CustomDialog* d = (CustomDialog*)w->parent();
d->result = (int)(long)data;
d->hide();
}

int run() {
Fl_Window* main_win = Fl::first_window();
if (main_win) main_win->deactivate();

this->position(100, 100);
this->show();

while (this->shown()) Fl::wait();

if (main_win) main_win->activate();
return result;
}
};

void open_cb(Fl_Widget* w, void*) {
//w->deactivate();
Fl_Window* main_win = Fl::first_window();
if (main_win) main_win->deactivate();


Fl_Group::current(0);
CustomDialog diag;
diag.run();
main_win->activate();

//w->activate();
}

int main() {
Fl_Window* win = new Fl_Window(400, 300, "Main win");
Fl_Button* btn = new Fl_Button(140, 130, 120, 40, "Dialog");
Fl_Button* btn2 = new Fl_Button(140, 160, 120, 40, "Dialog");
btn->callback(open_cb);
btn2->callback(open_cb);
win->end();
win->show();
return Fl::run();
}

#endif

imm

unread,
May 3, 2026, 9:00:10 AM (2 days ago) May 3
to General FLTK
On Sun, 3 May 2026, 12:37 'Klaus' wrote:
Hi!

I want to create a dialog window which is modal, means it is the only
window which reacts on any kind of input. But this window should be
moveable.

All my experiments result in 2 kinds of behavior:

1. ) The window is the only one which reacts on inputs, but it can't be
moved ( without also moving the main application window )

What OS and window manager are you using?

This sounds like a window management issue rather than any specific window issue.
One of the Wayland WMs I use (can't remember which one!) does this (and I don't much like it, TBH) whilst the same binary run on another machine doesn't.

It may well be that what you are seeing is caused by that, rather than any issues with the code.
--
Ian
From my Fairphone FP6

Klaus

unread,
May 3, 2026, 9:15:01 AM (2 days ago) May 3
to fltkg...@googlegroups.com
> What OS and window manager are you using?

It is a fedora 42 which runs gnome desktop with mutter/x11 window manager.


>
> This sounds like a window management issue rather than any specific
> window issue.
> One of the Wayland WMs I use (can't remember which one!) does this (and
> I don't much like it, TBH) whilst the same binary run on another machine
> doesn't.
>
> It may well be that what you are seeing is caused by that, rather than
> any issues with the code.


If it is a related to the used WM, is there a chance to modify this
behavior from the application? Or is there a chance to simulate the
desired behavior in any way?

Regards
Klaus

Manolo

unread,
May 3, 2026, 3:18:39 PM (2 days ago) May 3
to fltk.general
You have to use the "Tweaks" application, select "Windows" in its left panel,
go to the "Click Actions" section and unset the ""Attach Modal Dialogs"
option.
Reply all
Reply to author
Forward
0 new messages