I have a GTK4 Adwaita application built with GJS. I'm trying to add a PreferencesDialog that pops up over the ApplicationWindow but blocks interaction with the window, similar to a lot of other Adwaita applications (such as Gnome Text Editor). I dont want it to popup up within the window, as it's then confined to the window dimensions.
From what I can see, there are two options:
- Present the dialog by passing in the window as a parameter. This sets the dialog as a child of the window, and means that the dialog is confined to the windows dimensions, which is not desired.
- Present the dialog by passing
nullas a parameter. This sets the dialog as a sibling of the window, and is completely detached from it - the user can still interact with the application while the dialog is open, and can move the dialog independently from the window. This is not desired, either.
So neither of these have the desired effect. Perhaps I'm missing some additional configuration required to match the behavior of Gnome Text Editors Preferences Dialog, or perhaps this is a limitation of GJS?
Basic example
Adw.init();
const app = new Adw.Application();
app.connect("activate", () => {
const win = new Adw.ApplicationWindow({
application: app,
defaultHeight: 200,
defaultWidth: 200,
resizable: true,
});
const showDialog = new Gtk.Button({ label: "Show dialog" });
showDialog.connect("clicked", () => {
const dialog = new Adw.PreferencesDialog({
presentationMode: Adw.DialogPresentationMode.FLOATING,
});
dialog.present(null); // becomes sibling, completely detached from win ❌
// vs dialog.present(win); // becomes child, confined to win dimensions ❌
});
win.set_content(showDialog);
win.connect("close-request", () => app.quit());
win.present();
});
app.run([imports.system.programInvocationName].concat(ARGV));
Gnome Text Editor Behavior
I've tried to include a gif demonstrating how this works in Gnome Text Editor, but it keeps failing to upload. I've posted the example on Imgur.
The main thing I notice when inspecting the widgets of Gnome Text Editor while the PreferencesDialog is open, is that the dialog is a sibling of the window, not a child of it. Again, I havent been able to upload an image to StackOverflow showing this, so an image is included on Imgur
I'm not very familiar with C code, so I havent been able to fully understand how Gnome Text Editor implements this. Some things I notice, however:
- The preferences dialog definitely appears to be a dialog, rather than a window (here)
- When creating and presenting the dialog, the window appears to be passed in as a parameter (here)
So I'd really like to understand how Gnome Text Editor (and other GTK4 Adwaita apps) manage to create a preferences dialog pop over the window, block user interaction with the window, where moving the dialog also moves the window behind it, yet is not confined to the windows dimensions. And I'd like to understand how to implement the same behavior in my GJS app.