TroikaTronix / NSCustomAlert

BigSur NSAlert replacement for alerts with longer texts
MIT License
5 stars 3 forks source link

Solution to make the alert moveable #1

Open zevrix opened 3 years ago

zevrix commented 3 years ago

Like I mentioned in a reply to you on Apple's forum, it's a great and truly useful project.

One issue in its current state is that the alert cannot be moved around by the user.

The solution I found is the following:

In the init method: • Remove the NSWindowStyleMaskDocModalWindow mask • add _panel.movableByWindowBackground = YES

WBIGitHub commented 2 years ago

@zevrix -- thanks for posting these suggestions. I tried to apply these two changes to the NSCustomAlert process, but couldn't get the alert to be movable on Monterey. Is that your experience?

Here's what I changed:

#if NON_MOVEABLE
        _panel = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
        styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskDocModalWindow
        backing:NSBackingStoreBuffered
        defer:YES];
#else
        _panel = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
        styleMask:NSWindowStyleMaskTitled
        backing:NSBackingStoreBuffered
        defer:YES];

        _panel.movableByWindowBackground = YES;
#endif
zevrix commented 2 years ago

This works for me on Monterey (and other systems) - which looks like what you posted::

_panel = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
                                             styleMask:NSWindowStyleMaskTitled
                                               backing:NSBackingStoreBuffered
                                                 defer:YES];

        _panel.movableByWindowBackground = YES; 

Maybe your NON_MOVEABLE gets in the way and is being called when not needed?

WBIGitHub commented 2 years ago

No, NON_MOVEABLE is not even defined. I just put it there to preserve the "original" code before placing your suggestions in the #else section.

Very odd.

FYI -- In MacOS Ventura, Apple has changed the behavior of NSAlert to essentially do what NSCustomAlert does: it will revert to the horizontal format if the text is beyond a specific threshold.

zevrix commented 2 years ago

thanks for the info on the changes in Ventura - i didn't know that. well hopefully it's a start and Apple will finally revert the NSAlert look to its normal horizontal layout for all situations. the change in the NSAlert layout was easily the DUMBEST UI change Apple ever made.

still strange that NSCustomAlert isn't moveable for you...

i posted the files I'm using here - maybe i made more changes that i didn't notice by now:

https://zevrix.com/guest/NSCustomAlert.zip

it's only two.h and .mm files - I don't use anything else.

also i didn't clean up my own personal comments there... plus my code is non-ARC so change accordingly if needed.

also just in case - that's how I create the alert if it makes any difference:

alert = [[NSCustomAlert new] autorelease];
// set alert properties
[alert runModal]

it's all wrapped in my own category.