Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu shortcuts should be disabled while a dialog is open #5235

Open
2 tasks done
ErikKalkoken opened this issue Nov 3, 2024 · 7 comments
Open
2 tasks done

Menu shortcuts should be disabled while a dialog is open #5235

ErikKalkoken opened this issue Nov 3, 2024 · 7 comments

Comments

@ErikKalkoken
Copy link
Contributor

Checklist

  • I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
  • This issue only relates to a single feature. I will open new issues for any other features.

Is your feature request related to a problem?

In a desktop app with a menu the menu shortcuts are still active while a dialog is open. This can be a problem, because if there are shortcut that opens a dialog (e.g. a settings dialog), this allows the user to open multiple instances of the same dialog, one on top of each other. It may also be weird for users to be able to open menu items through shortcuts while a supposedly modal dialog is open. In general this behavior breaks the expectation of modality for dialogs in desktop apps.

Is it possible to construct a solution with the existing API?

As a workaround one could manually remove all menu shortcuts before a dialog is open and re-add them again when it is closed. This would have to be done for each and every dialog in the app and would result in a lot of additional boilerplate code.

Describe the solution you'd like to see.

Menu shortcuts should be automatically disabled when a dialog opens and re-enabled when it is closed. Any other shortcuts should not be affected.

@ErikKalkoken
Copy link
Contributor Author

For reference our related discussion on Discord

@ErikKalkoken ErikKalkoken changed the title Shortcuts should be disabled while a dialog is open Menu shortcuts should be disabled while a dialog is open Nov 3, 2024
@andydotxyz
Copy link
Member

I've just realised there is some challenge here because modality means different things on different platforms. For example on macOS the menus remain visible and usable when a dialog is up iirc.
I wonder if global menus on Gnome work that way too?

@ErikKalkoken
Copy link
Contributor Author

Do you mean with Fyne apps specifically or apps in general on macOS?

No, on Gnome the menus are greyed out and inactive while a modal dialog is open. That is how Fyne apps work currently (tested with the Fyne demo app) and native apps too (tested with Libre Office Calc).

Same on Windows btw (tested with a one of my Fyne apps).

@andydotxyz
Copy link
Member

I was meaning apps in general.

Perhaps the original issue was missing some info about OS, because I'm a little confused now - if the menu items are being disabled as you expect then what is it that isn't right?

@ErikKalkoken
Copy link
Contributor Author

What isn't right is that the menu shortcuts still work despite the menu being greyed out.

This creates problems: For example if you have a menu shortcut that opens a modal dialog, this allows you to re-open the same modal multiple times, which are then shown on top of each other. And the user needs to close the same dialog multiple times to get back to the app.

Here is how this looks to the user:

  1. I am first opening an about dialog via menu,
  2. Opening it 3 more times via shortcut
  3. Closing all 4 modals.
Screencast.from.19.01.2025.17.35.21.webm

Here is the code that produces above behavior:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/dialog"
	"fyne.io/fyne/v2/driver/desktop"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Fyne Playground")
	mi := fyne.NewMenuItem("About...", func() {
		d := dialog.NewInformation("About", "A modal dialog", w)
		d.Show()
	})
	mi.Shortcut = &desktop.CustomShortcut{KeyName: fyne.KeyA, Modifier: fyne.KeyModifierAlt}
	w.Canvas().AddShortcut(mi.Shortcut, func(shortcut fyne.Shortcut) {
		mi.Action()
	})
	menu := fyne.NewMainMenu(fyne.NewMenu("File", mi))
	w.SetMainMenu(menu)
	w.SetContent(container.NewCenter(widget.NewLabel("Welcome")))
	w.Resize(fyne.NewSize(600, 300))
	w.ShowAndRun()
}

@andydotxyz
Copy link
Member

andydotxyz commented Jan 19, 2025

Ah right, so not when there are global menus. I was asking about when they are outside of the window in apps that are not Fyne - sorry for the confusion.

On macOS it applies to all apps (because we use the global menu) whereas Linux Global is not something we support so there is a grey area there for sure.

@andydotxyz
Copy link
Member

andydotxyz commented Jan 19, 2025

In my testing the apps on macOS do not universally get disabled but it seems that the app decides which menu items to disable when a modal dialog is up...
Perhaps what we should do is not disable the menu bar (to be consistent)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants