Bug Prevent swing popups from stealing focus

Irrat

Member
I'm on Windows 10, and I'm not sure if this is an issue elsewhere but sometimes mafia has a popup box appear for one reason or another.
This is normally fine, but sometimes I'm typing in CLI or mafia's chat or sometimes I'm not even using mafia as my active window and I'm typing in another program.
Sometimes I might be playing a game.

This is a bit unreliable but sometimes the popup steals focus, sometimes it doesn't.
But when it does steal focus, chances are fairly high that I was typing something.. And when that happens, I normally press the spacebar before I even realize that the popup has stolen focus.

And now, I've suddenly picked a choice in the popup without knowing what the popup said, or what choice I just picked.

I'm aware that this isn't something mafia itself decided to do and that it's due to the swing implementation in Java itself.
I'm not even sure if it has an easy solution. But it's still an issue at times. Especially when your looping script was asking "You are about to overdrink but have more than 400 adventures remaining. This seems extreme, do you want to do it anyways?"

I'd say this can be separated into two problems.
  • The first is that it steals focus, we should never be stealing focus. Even if we have mafia active, if the window that wants to create a popup is not the active window, it shouldn't steal focus.
  • The second is that it should only be accepting "Enter" as a selector. Not spacebar. Or some other measure to ensure we don't accidentally press a button before we are aware of what just happened. Even if you have the main window open, you don't want to be typing in CLI and accidentally pick a surprise option.
 

fronobulax

Developer
Staff member
I remember things that didn't happen. I remember a long time ago there were complaints because mafia popped up a window and it was hidden by other windows and the community was very vocal in saying that was a Bad Thing. My recollection is that the fix was to give the window focus which would allow/force the operating system to put it where it was noticeable.

So mafia is behaving as intended and this is perhaps a Feature Request and not a Bug :)

I spent much of my Java career successfully getting someone else to work on the UI in general and Swing in particular. I do not know whether is is possible to put a window forward or on top but not give it focus but I suspect that would be an acceptable solution if it is feasible.

I do not multi-task significantly when running mafia and when I am I want to know ASAP that mafia needs my attention. So I like a pop up with focus. Since I am not a touch typist I do not run into the situation where the change in focus captures keyboard input intended for elsewhere.

Most mafia popups that I can think of present buttons and expect the user to choose one. Keeping in mind my ignorance of Swing it does seem to me to be wrong that a possibly arbitrary keyboard entry can be the equivalent of a button press, That may be by design in which case it would be helpful to document which keys map to which buttons. It may also be that a button is designated as the default and keyboard input selects the default.

I think there is an opportunity here but I am not personally prepared to dive into the rabbit hole that is Swing, at least at this moment.
 

xKiv

Active member
I think there are two other things that can be done to alleviate this:

1) after such popup is created, do not let it accept regular input for some (configurable?) amount of time. Like a second or two. Long enough that we will notice we are suddenly typing/clicking into something that didn't exist when the "command" to do that typing/clicking was issued.
Things that I think such popup should probably have:
- some indication that it is in this mode, so that we know when we *can* use it regularly
- indication that it is receiving (and ingoring) input - so that it grabs the user's focus too, not just the computer's focus
- a way to quickly end this "input ignoring" mode - something that 1) doesn't trigger anything else in mafia's GUI and 2) users are unlikely to do otherwise

2) in reaction to "... without knowing what the popup said, or what choice I just picked." - a (brief) history of popups and choices taken in them (or inputs, if there's an input box?)
 

Irrat

Member
I think there are two other things that can be done to alleviate this:

1) after such popup is created, do not let it accept regular input for some (configurable?) amount of time. Like a second or two. Long enough that we will notice we are suddenly typing/clicking into something that didn't exist when the "command" to do that typing/clicking was issued.
Things that I think such popup should probably have:
- some indication that it is in this mode, so that we know when we *can* use it regularly
- indication that it is receiving (and ingoring) input - so that it grabs the user's focus too, not just the computer's focus
- a way to quickly end this "input ignoring" mode - something that 1) doesn't trigger anything else in mafia's GUI and 2) users are unlikely to do otherwise

2) in reaction to "... without knowing what the popup said, or what choice I just picked." - a (brief) history of popups and choices taken in them (or inputs, if there's an input box?)
I think declining input for a second or two would be best, and the easiest to implement. Worst comes to it, just make it an opt-out/in.

A history of inputs, it sounds good? But at the same time, it sounds meaningless. It'd be up to the script themselves to say what was done, which is generally the case. I'm talking in this case that I realize I picked an option. And I'm not sure if I should spam "esc" or let the script continue as its something I'm fine with. Which this wouldn't really help too much with, since its just the few seconds after that I think its particularly relevant..

I remember things that didn't happen. I remember a long time ago there were complaints because mafia popped up a window and it was hidden by other windows and the community was very vocal in saying that was a Bad Thing. My recollection is that the fix was to give the window focus which would allow/force the operating system to put it where it was noticeable.

So mafia is behaving as intended and this is perhaps a Feature Request and not a Bug :)

I spent much of my Java career successfully getting someone else to work on the UI in general and Swing in particular. I do not know whether is is possible to put a window forward or on top but not give it focus but I suspect that would be an acceptable solution if it is feasible.

I do not multi-task significantly when running mafia and when I am I want to know ASAP that mafia needs my attention. So I like a pop up with focus. Since I am not a touch typist I do not run into the situation where the change in focus captures keyboard input intended for elsewhere.

Most mafia popups that I can think of present buttons and expect the user to choose one. Keeping in mind my ignorance of Swing it does seem to me to be wrong that a possibly arbitrary keyboard entry can be the equivalent of a button press, That may be by design in which case it would be helpful to document which keys map to which buttons. It may also be that a button is designated as the default and keyboard input selects the default.

I think there is an opportunity here but I am not personally prepared to dive into the rabbit hole that is Swing, at least at this moment.

Yeah, it's hard. I think there's always going to be someone that's surprised if we disabled some key inputs on the option buttons, so as xKiv said it may be the best idea is to just disable all buttons for a second or two when the popup appears.
 

MCroft

Developer
Staff member
I think the relay browser coving a window with focus was a concern at one point,

@Irrat , can you give specific examples of the dialogs that are popping up?

There was some work done earlier this year on the case of the popup that appeared when using the seal tooth, but I think it didn't have any choices.

Are you having trouble when timing in with the accept /reject the ping time dialog coming up in the background?
 

Irrat

Member
I think the relay browser coving a window with focus was a concern at one point,

@Irrat , can you give specific examples of the dialogs that are popping up?

There was some work done earlier this year on the case of the popup that appeared when using the seal tooth, but I think it didn't have any choices.

Are you having trouble when timing in with the accept /reject the ping time dialog coming up in the background?
Popups from scripts, sorry.

User_confirm()
 
Top