choc icon indicating copy to clipboard operation
choc copied to clipboard

Disable the window close button?

Open daveboulden opened this issue 2 years ago • 11 comments

Is there a way to disable the window close button of choc_DesktopWindow?

I have a situation where I need to be able to disable or intercept it for compatibility within the host program that my software runs within. Currently, using the OS-level close button crashes the host program.

daveboulden avatar Jan 03 '24 13:01 daveboulden

I've not attempted to add that functionality, but there are ways on each platform to implement it. I'm too busy to look into it, but if you wanted to have a shot, I could review the code. It's not difficult to do, just requires a bit of time for research and testing.

julianstorer avatar Jan 04 '24 09:01 julianstorer

That's a very kind offer, thank you. I'll give that a go.

daveboulden avatar Jan 05 '24 12:01 daveboulden

I have implemented this in a clone of the repo here:

https://github.com/daveboulden/choc

I have implemented an extra function setClosable (bool b) to disable the Close button after the instantiation of the window. The changes are in /gui/choc_DesktopWindow.h.

Under MacOS the Close button is disabled and appears as an empty grey button. There is one caveat, though: the setResizable() function specifically enables the Close button and so could possibly be changed to get the styleMask first and then set the NSWindowStyleMaskClosable flag accordingly as I have done in setClosable() so that it ndoesn't overwrite any changes made using setClosable() but that may possibly require a default styleMask to be set initially.

Windows doesn't support removing just the Close button (you either have the three Min/Max/Close buttons or none at all), so instead I set a Boolean variable and use that to effectively intercept the close message in wndProc().

I do not have an environment to easily test the implementation of setClosable() under Linux, but it seems GTK has some very specific and easily identifiable code for manipulating the window, so I am pretty sure the code should be right for this.

@julianstorer It would be great if you could review this when you have a spare moment.

daveboulden avatar Mar 04 '24 19:03 daveboulden

Thanks, I've added a couple of comments..

julianstorer avatar Mar 06 '24 09:03 julianstorer

Thanks Julian... where do I find those comments? (I have looked but can't work out where they are)

daveboulden avatar Mar 06 '24 13:03 daveboulden

I added them to the commit in your repo

julianstorer avatar Mar 06 '24 13:03 julianstorer

I've solved the issue on Windows. The Close button has to be disabled via the underlying system menu rather than the window style. I've done a new commit with those changes in place.

daveboulden avatar Mar 06 '24 14:03 daveboulden

great, I'll take a look asap

julianstorer avatar Mar 06 '24 14:03 julianstorer

Did you get a chance to take a look? Would it be easier if I created a Pull Request?

daveboulden avatar Mar 18 '24 17:03 daveboulden

Sorry, have been busy, but yes, either a PR or just a diff that shows your changes against the latest version would be helpful

julianstorer avatar Mar 24 '24 14:03 julianstorer

No problem. I have synced all latest changes into my fork and issued a Pull Request. All changes are in choc_DesktopWindow.h.

daveboulden avatar Mar 24 '24 15:03 daveboulden

Don't know if you spotted it, but I added this last week - will close this issue now

julianstorer avatar Apr 12 '24 15:04 julianstorer