Feature - Implemented Add Close Accelerator key cmd-W/Alt-W

MCroft

Developer
Staff member
There's a nice, small patch here: View attachment Close_Hot_Key.patch, but it needs testing on Windows and Linux.

I would like to be able to use cmd-W (on windows Alt-W) to act the same as the red close box for windows.

I added a few lines to genericFrame.java and it works like a champ. Hooray!

But I want to understand if it's doing the right thing when a user closes the last open window.

Right now it does what hitting all the red close boxes does, which is log the user out. Should it ask ("are you sure?" or "quit, logout, close and stay logged in"? ). If the relay browser is running, is that correct/expected behavior?

tl;dr -- it does exactly what the close box does, but should we revisit what that is?
 
Last edited:

MCroft

Developer
Staff member
What is "the red close box for windows". What does it do for non-KoLmafia applications?

This is what I mean. It's technically only sometimes red, but it is the standard decoration usually in the upper left or right of the window that closes the window

close_apps_8.png
 

fronobulax

Developer
Staff member
This is what I mean. It's technically only sometimes red, but it is the standard decoration usually in the upper left or right of the window that closes the window

View attachment 9911

Weird. My professional Windows experience goes back to 3.1 and I have NEVER seen that X outlined in red. For the record when I press it I expect it to close a window. If the window being closed is the last window opened/created by the app then it also shuts down the app. I have no clue what the keyboard shortcut is but either way I would expect the last window to logout mafia and shut down. I do something different if I only want to log out, but not shut down.
 

MCroft

Developer
Staff member
Weird. My professional Windows experience goes back to 3.1 and I have NEVER seen that X outlined in red. For the record when I press it I expect it to close a window. If the window being closed is the last window opened/created by the app then it also shuts down the app. I have no clue what the keyboard shortcut is but either way I would expect the last window to logout mafia and shut down. I do something different if I only want to log out, but not shut down.

On current MacOS, it's a red circle that becomes a red circle with a dark red X in it when you hover over it. Sorry my description wasn't clear. I haven't had a Windows machine for home or work in for a while now.

I saw Windows 2.1, but we never used it. I recall how MS made a huge freaking deal about upgrading from 3.0 to 3.1, because you'd never get another UAE (Unexpected Application Error). And they were telling the truth. 3.1 was where they changed them all to General Protection Faults. It was still a good upgrade (or 3.11 was, since it had networking), but it wasn't what they tried to tell me it would be...

When you close the last window, it logs out and I see the login window. I'm OK with that as long as it's expected behavior (it's not a change).
 

MCroft

Developer
Staff member
Do we have any kind of UX standard for Linux? Are we trying to be more like KDE or more like GNOME? They have different accelerator keys, according to this online shortcut DB which I have no reason to trust (or not to trust).
 

fronobulax

Developer
Staff member
When you close the last window, it logs out and I see the login window. I'm OK with that as long as it's expected behavior (it's not a change).

I've never liked that behavior but... I have a vague recollection there are some inconsistencies. If I press X and it retirns to Login what happens when I press the same X again?

That said, we might stay focused. If all you are trying to do is implement a keyboard shortcut that does the same thing isn't it possible to listen for the sequence and then invoke the existing and unchanged code that is invoked when pressing X?
 

MCroft

Developer
Staff member
I've never liked that behavior but... I have a vague recollection there are some inconsistencies. If I press X and it retirns to Login what happens when I press the same X again?

That said, we might stay focused. If all you are trying to do is implement a keyboard shortcut that does the same thing isn't it possible to listen for the sequence and then invoke the existing and unchanged code that is invoked when pressing X?

This is exactly my dilemma and why I wanted to discuss it.
 

fronobulax

Developer
Staff member
Do we have any kind of UX standard for Linux? Are we trying to be more like KDE or more like GNOME? They have different accelerator keys, according to this online shortcut DB which I have no reason to trust (or not to trust).

Don't think so. Explicit Linux support has always been an afterthought. KoLmafia is expected to work on Linux but not much effort has been expended to make it work nicely and optimally.

Again, perhaps we should step back and philosophize? There are two approaches I have found and used to support multiple OSs. One is the least common denominator. The other is a collection of specialized OS "features" that can be loaded (or swapped) at runtime.

The former is easiest to write, maintain and debug. Application features drive it. If it is decided that the app must minimize itself and appear in the system tray then the implementation must be OS specific if necessary. But if that is not a required feature then nothing is done.

So at what point are keyboard shortcuts a mandatory feature for KoLmafia and not just a convenience for a small subset of users? If we do something now will it be extendable when the demand for Android support is great enough to act?

I learned about design patterns too late in my career to effectively use them but there is a part of me that expects keyboard support for multiple OS conventions is easily supported by a pattern. Factory?
 

MCroft

Developer
Staff member
Don't think so. Explicit Linux support has always been an afterthought. KoLmafia is expected to work on Linux but not much effort has been expended to make it work nicely and optimally.

Again, perhaps we should step back and philosophize? There are two approaches I have found and used to support multiple OSs. One is the least common denominator. The other is a collection of specialized OS "features" that can be loaded (or swapped) at runtime.

The former is easiest to write, maintain and debug. Application features drive it. If it is decided that the app must minimize itself and appear in the system tray then the implementation must be OS specific if necessary. But if that is not a required feature then nothing is done.

So at what point are keyboard shortcuts a mandatory feature for KoLmafia and not just a convenience for a small subset of users? If we do something now will it be extendable when the demand for Android support is great enough to act?

I learned about design patterns too late in my career to effectively use them but there is a part of me that expects keyboard support for multiple OS conventions is easily supported by a pattern. Factory?

I’m always happy to dine with philosophers. If there’s a goal of my recent changes, it’s “follow expected app behavior”, which means things like “use the best compromise between Apple HIG and MS design best practices I can manage”. Gausie told me elsewhere that the guide page I found is wrong and Ctrl-w works for Linux, so we can probably get away with setting a platform-specific command key and using the common items here.

Or it can be part of the menu bar, in a hypothetical revamp of menu bars in line with design goals...

MS design best practices call for an accelerator key for every menu item. I’m not sure I’m ready for that, but it would make keyboard-only KoLmafia possible.

I don’t know if we need a class and a factory for this, but the more places we use if ( System.getProperty( “os.name” ).startsWith( “Mac” ) ), the less right I am about that...
 

MCroft

Developer
Staff member
So, since Preferences has a "isUsingMac" boolean and Mac seems to be the only platform not using CTRL-W for close, here's today's working code, for comments.

Code:
int platform_META_DOWN = ( Preferences.getBoolean( "isUsingMac" ) )
		? KeyEvent.META_DOWN_MASK
		: KeyEvent.CTRL_DOWN_MASK;
JComponentUtilities.addGlobalHotKey(
		this.getRootPane(),
		KeyEvent.VK_W,
		platform_META_DOWN, // CMD on MacOS, CTRL on others...
		new CloseWindowListener() );

and CloseWindowListener is just an ActionListener that calls dispose() in the generic frame (unless it's overridden)...
 
Last edited:

fronobulax

Developer
Staff member
For me “follow expected app behavior” means I never have to touch the keyboard :)

I never worked on an app that needed to change OS related behaviour when running because the OS changed, so an object that encapsulates the OS specific details could be created once at startup. Defining an abstract object that handled the behaviour and then making one call to the factory to get the right one punches my buttons for encapsulation, isolation, object oriented design etc. That said they are all goals that have a cost when retrofitted to a codebase as diverse as KoLmafia and that cost is not always worth paying.

Not sure what "Or it can be part of the menu bar, in a hypothetical revamp of menu bars in line with design goals..." means.

Some of the X functionality is already in menus. Seems to me to be a bad idea to expose any OS related choices to the user. You are probably talking about neither but...
 

MCroft

Developer
Staff member
For me “follow expected app behavior” means I never have to touch the keyboard :)

I never worked on an app that needed to change OS related behaviour when running because the OS changed, so an object that encapsulates the OS specific details could be created once at startup. Defining an abstract object that handled the behaviour and then making one call to the factory to get the right one punches my buttons for encapsulation, isolation, object oriented design etc. That said they are all goals that have a cost when retrofitted to a codebase as diverse as KoLmafia and that cost is not always worth paying.

Not sure what "Or it can be part of the menu bar, in a hypothetical revamp of menu bars in line with design goals..." means.

Some of the X functionality is already in menus. Seems to me to be a bad idea to expose any OS related choices to the user. You are probably talking about neither but...

Exactly on the same page wrt cost. If we have to do a ternary operator like the one I mention once, it's different than if it's in lots of places across the entire system. There are maybe a dozen places where KoLmafia branches based on os.name or isUsingMac, which seems like it may be right on the edge of the cost/benefit analysis line.

What I mean is that if you added "Close Window" into a (currently nonexistent) File Menu and assigned a platform-driven but standard accelerator key to it, you wouldn't need to implement it as a global hotkey in GenericFrame. Menu bars already understand accelerator keys, so it's somewhat easier to add there. Also a slippery slope case of "one isn't hard..."
 

MCroft

Developer
Staff member
Please review

This is the working, tested hotkey for closing windows. As we discussed, all it does is call dispose, same as clicking the window close widget in the titlebar (or equivalent). Change is in GenericFrame, same place other hotkeys are assigned.

View attachment Close_Hot_Key_v3.patch
 
Top