I'm having this problem on OSX Lion when entering/exiting fullscreen. I tried to reapply the style mask without success:
NSUInteger styleMask = NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask;
styleMask |= NSTexturedBackgroundWindowMask;
window = [[NSWindow alloc] initWithContentRect:windowFrame
styleMask: styleMask
backing:NSBackingStoreBuffered
defer:NO];
and the fullscreen notification
(void)didExitFull:(NSNotification *)notification {
NSUInteger styleMask=[window styleMask];
[window setStyleMask:styleMask|NSMiniaturizableWindowMask];
}
It seems that the miniaturize button is not getting enable again.
I also found this UI Usability problems on MacOSX 10.6 here
Please override the following function
- (NSApplicationPresentationOptions) window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
{
return (proposedOptions| NSApplicationPresentationAutoHideToolbar);
}
And do not set styleMask after exitFullscreen. Let the system do it.
Related
I need to maximize compatibility for a program that I want it to works from 10.6 to Big Sur. That's why I use XCode 3.2.2.
It seems to work on Big Sur but the function [nswind displayIfNeeded];
it doesn't do anything.
displayIfNeeded instance method still available I see on apple.com but do nothing.
I need this function to redraw portions of the window that become dirty by use.
Before displayIfNeeded I invalidate rect with: setNeedsDisplayInRect
Minimal code:
# window init
NSWindow *NSWind=[super initWithContentRect:NSMakeRect(0, 0, g_winw, g_winh) styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable | NSWindowStyleMaskClosable backing:NSBackingStoreBuffered defer:NO];
NSView *GPview = [[GRAPH alloc]initWithFrame: NSMakeRect(0, 0, s_winw, s_winh-g_menuh)];
[GPview setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[[self contentView] addSubview:GPview];
# User action
[GPview setNeedsDisplayInRect: NSMakeRect(r->left,g_winh-(r->bottom-r->top)-r->top,r->right-r->left,r->bottom-r->top)];
[NSWind displayIfNeeded];
I have a very simple MacOS window, single compilation file, compiled with the clang compiler (e.g. clang -framework AppKit -o simple-mac-window osx_main.mm). It can be run from the command line.
//OSX Main - Entry point for the OSX platform.
#include <stdio.h>
#include <AppKit/AppKit.h>
static float GlobalRenderWidth = 1024;
static float GlobalRenderHeight = 768;
static bool Running = true;
//Declare an interface that inherits from NSObject and implements NSWindowDelegate.
#interface SimpleMainWindowDelegate: NSObject<NSWindowDelegate>
#end
#implementation SimpleMainWindowDelegate
- (void)windowWillClose:(id)sender {
Running = false;
}
#end
int main(int argc, const char * argv[]) {
SimpleMainWindowDelegate *mainWindowDelegate = [[SimpleMainWindowDelegate alloc] init];
NSRect screenRect = [[NSScreen mainScreen] frame];
NSRect initialFrame = NSMakeRect((screenRect.size.width - GlobalRenderWidth) * 0.5,
(screenRect.size.height - GlobalRenderHeight) * 0.5,
GlobalRenderWidth,
GlobalRenderHeight);
NSWindow *window = [[NSWindow alloc] initWithContentRect: initialFrame
styleMask: NSWindowStyleMaskTitled |
NSWindowStyleMaskClosable |
NSWindowStyleMaskMiniaturizable |
NSWindowStyleMaskResizable
backing:NSBackingStoreBuffered
defer:NO];
[window setBackgroundColor: NSColor.redColor];
[window setTitle:#"simple-mac-window"];
[window makeKeyAndOrderFront: nil];
[window setDelegate: mainWindowDelegate];
while(Running) {
NSEvent* event;
do {
event = [NSApp nextEventMatchingMask: NSEventMaskAny
untilDate: nil
inMode: NSDefaultRunLoopMode
dequeue: YES];
switch([event type]) {
default:
[NSApp sendEvent: event];
}
} while (event != nil);
}
printf("Finished running simple-mac-window.");
}
I have set the NSWindowStyleMaskResizable flag on the styleMask when initialising the window. This allows me to drag and resize the window when selecting the edges of the screen. However I do not get the handles to resize the window when I move my cursor to edge of the window. What are the minimum code elements I need to add in order to support this?
I have tried checking out the NSWindow Apple documentation but it seems that all is required is the flag. Perhaps I need to set some values on the window object or update the window delegate to include something? Or is this because of the minimal approach taken to get a window running?
There are two issues (at least). First, passing nil for the untilDate: parameter means your event loop spins, handling a nil event all the time. You should pass [NSDate distantFuture].
Second, standalone executables — that is, those that are not in an app bundle — start life with an activation policy of NSApplicationActivationPolicyProhibited. You need to do [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular] before your event loop.
I create a new macOS app in XCode.
I add the entitlement com.apple.security.files.user-selected.read-write with value YES (to allow usage of NSSavePanel)
In AppDelegate.m, I implement applicationDidFinishLaunching as follows:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSSavePanel* nssavepanel = [NSSavePanel savePanel];
NSButton* nsbutton = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 50, 20)];
[nsbutton setTitle:#"Button title"];
[nssavepanel setAccessoryView:[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 200, 80)]];
[[nssavepanel accessoryView] addSubview:nsbutton];
[nssavepanel beginWithCompletionHandler:^(NSModalResponse result) {}];
}
When I start the application, I see a panel with a button.
On macOS 10.15.3, I can click the button in the acceessory view.
On macOS 11.0 Beta (20A4300b), I cannot click the button -- the whole accessory view seems to be disabled. (If I use runModal or beginSheetModalForWindow instead of beginWithCompletionHandler, the accessory view works as expected.) Is this a bug? Am I doing something wrong here?
I'm writing some glue GUI code for a scripting language implementation, and need to be able to programmatically create windows and intercept the key and mouse commands on their views. I've subclassed both NSWindow and NSView.
When I open a window for the first time, I get a window with a title bar and controls. If I close this window and open another, the controls and title don't appear in the new window. However, if I click where the controls should be, the new window (with invisible controls) still closes.
Is there something I'm doing in my window initialization that could cause this?
+ (HMSLWindow*)hmslWindowWithTitle:(NSString *)title frame:(NSRect)frame {
HMSLWindow* hmslWindow = [[HMSLWindow alloc]
initWithContentRect: frame
styleMask: NSMiniaturizableWindowMask | NSTitledWindowMask | NSClosableWindowMask
backing: NSBackingStoreBuffered
defer: YES];
hmslWindow.title = [title retain];
[hmslWindow setContentView:[[HMSLView alloc] initWithFrame:frame]];
hmslWindow.delegate = [[HMSLWindowDelegate alloc] init];
[hmslWindow cascadeTopLeftFromPoint:NSZeroPoint];
[hmslWindow makeKeyAndOrderFront:self];
[[HMSLWindow windowDictionary] setObject:hmslWindow forKey:[NSNumber numberWithInteger:hmslWindow.windowNumber]];
return hmslWindow;
}
- (void)close {
[[HMSLWindow windowDictionary]
removeObjectForKey:[NSNumber numberWithInteger:self.windowNumber]];
[self.contentView autorelease];
[self.delegate autorelease];
[self.title autorelease];
[super close];
}
First window:
Second window (contentView with white background is correct, but the titlebar is now empty):
I've created the app which sometimes shows up an overlay with label and textbox. It works nice, but I need it to work even with other apps are in full-screen mode and active.
For overlay, I've create custom window class and overridden canBecomeKeyWindow method to let borderless window become the key window (simply returns YES).
So it works, but when I run e.g. Minecraft, and then make it full screen, my overlay can override it. But I can't type in NSTextField in the overlay. How to fix it?
I'm creating an overlay like this:
[[NSWorkspace sharedWorkspace] hideOtherApplications];
NSRect frame = [[NSScreen mainScreen] frame];
_fadedWindow = [[CustonWindow alloc] initWithContentRect:frame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[_fadedWindow setAcceptsMouseMovedEvents:YES];
[_fadedWindow setOpaque:NO];
[_fadedWindow setLevel:CGShieldingWindowLevel()];
[_fadedWindow setBackgroundColor:[NSColor colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:0.8]];
NSApplicationPresentationOptions options = NSApplicationPresentationDisableProcessSwitching + NSApplicationPresentationHideDock + NSApplicationPresentationDisableForceQuit + NSApplicationPresentationDisableSessionTermination + NSApplicationPresentationDisableHideApplication;
[NSApp setPresentationOptions:options];
_fadedWindow.alphaValue = 0;
[_fadedWindow orderFrontRegardless];
[[_fadedWindow animator] setAlphaValue:1];
[_fadedWindow toggleFullScreen:self];
[_fadedWindow makeKeyAndOrderFront:self];
[NSApp activateIgnoringOtherApps:YES];
[_fadedWindow orderFront:self];
But still, I can't seem to populate overlay's NSTextField with keyboard input.
Try this. Create a subclass for _fadedWindow. Then put this in:
-(BOOL)canBecomeKeyWindow {
return YES;
}