From 04fafa467506fe9ca9b77d9cdc3f8e25cb8fd5d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Dj=C3=A4rv?= Date: Sat, 6 Oct 2012 19:31:11 +0200 Subject: [PATCH] Handle fullscreen parameter in initial/defult-frame-alist for NS. * nsfns.m (Fx_create_frame): Call x_default_parameter with fullscreen/Fullscreen. * nsterm.h (EmacsView): Rename tbar_height to tibar_height. tobar_height is new. * nsterm.m (x_make_frame_visible): Check for fullscreen. (ns_fullscreen_hook): Activate old style fullscreen with a timer. (ns_term_init): Set activateIgnoringOtherApps if old style fullscreen. (windowDidResize:): Check for correct window if old style fullscreen. Capitalize word in comment. Remove incorrect comment. (initFrameFromEmacs:): tbar_height renamed tibar_height. (windowDidEnterFullScreen:): Toggle toolbar for fullscreen to fix error in drawing background. (toggleFullScreen:): Remove comment. Rearrange calls. Set toolbar values to zero, save old height in tobar_height. Restore tool bar height when leaving fullscreen. (canBecomeMainWindow): New function. --- src/ChangeLog | 21 +++++++++++++ src/nsfns.m | 2 ++ src/nsterm.h | 3 +- src/nsterm.m | 87 ++++++++++++++++++++++++++++++++++++++++----------- 4 files changed, 94 insertions(+), 19 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 956e78e6c7e..b960837eaab 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,24 @@ +2012-10-06 Jan Djärv + + * nsfns.m (Fx_create_frame): Call x_default_parameter with + fullscreen/Fullscreen. + + * nsterm.h (EmacsView): Rename tbar_height to tibar_height. + tobar_height is new. + + * nsterm.m (x_make_frame_visible): Check for fullscreen. + (ns_fullscreen_hook): Activate old style fullscreen with a timer. + (ns_term_init): Set activateIgnoringOtherApps if old style fullscreen. + (windowDidResize:): Check for correct window if old style fullscreen. + Capitalize word in comment. Remove incorrect comment. + (initFrameFromEmacs:): tbar_height renamed tibar_height. + (windowDidEnterFullScreen:): Toggle toolbar for fullscreen to fix + error in drawing background. + (toggleFullScreen:): Remove comment. Rearrange calls. + Set toolbar values to zero, save old height in tobar_height. + Restore tool bar height when leaving fullscreen. + (canBecomeMainWindow): New function. + 2012-10-06 Paul Eggert * keyboard.c (read_char): Remove unnecessary 'volatile's and label. diff --git a/src/nsfns.m b/src/nsfns.m index 1efadf0cb98..f22198401e0 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -1346,6 +1346,8 @@ This function is an internal primitive--use `make-frame' instead. */) RES_TYPE_NUMBER); x_default_parameter (f, parms, Qalpha, Qnil, "alpha", "Alpha", RES_TYPE_NUMBER); + x_default_parameter (f, parms, Qfullscreen, Qnil, + "fullscreen", "Fullscreen", RES_TYPE_SYMBOL); width = FRAME_COLS (f); height = FRAME_LINES (f); diff --git a/src/nsterm.h b/src/nsterm.h index f06e0cb0f7f..f1cd7458bdc 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -86,7 +86,8 @@ along with GNU Emacs. If not, see . */ BOOL windowClosing; NSString *workingText; BOOL processingCompose; - int fs_state, fs_before_fs, next_maximized, tbar_height, bwidth; + int fs_state, fs_before_fs, next_maximized; + int tibar_height, tobar_height, bwidth; int maximized_width, maximized_height; NSWindow *nonfs_window; @public diff --git a/src/nsterm.m b/src/nsterm.m index 2df0e1a1ad5..0d0be9281ee 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1068,8 +1068,23 @@ x_make_frame_visible (struct frame *f) if this ends up the case again, comment this out again. */ if (!FRAME_VISIBLE_P (f)) { + EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); f->async_visible = 1; ns_raise_frame (f); + +#ifdef NEW_STYLE_FS + /* Making a new frame from a fullscreen frame will make the new frame + fullscreen also. So skip handleFS as this will print an error. */ + if (f->want_fullscreen == FULLSCREEN_BOTH + && ([[view window] styleMask] & NSFullScreenWindowMask) != 0) + return; +#endif + if (f->want_fullscreen != FULLSCREEN_NONE) + { + block_input (); + [view handleFS]; + unblock_input (); + } } } @@ -1317,6 +1332,18 @@ ns_fullscreen_hook (FRAME_PTR f) EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); if (! f->async_visible) return; +#ifndef NEW_STYLE_FS + if (f->want_fullscreen == FULLSCREEN_BOTH) + { + /* Old style fs don't initiate correctly if created from + init/default-frame alist, so use a timer (not nice...). + */ + [NSTimer scheduledTimerWithTimeInterval: 0.5 target: view + selector: @selector (handleFS) + userInfo: nil repeats: NO]; + return; + } +#endif block_input (); [view handleFS]; @@ -4210,6 +4237,11 @@ ns_term_init (Lisp_Object display_name) NSColorPboardType, NSFontPboardType, nil] retain]; +#ifndef NEW_STYLE_FS + /* If fullscreen is in init/default-frame-alist, focus isn't set + right for fullscreen windows, so set this. */ + [NSApp activateIgnoringOtherApps:YES]; +#endif [NSApp run]; ns_do_open_file = YES; @@ -5505,10 +5537,17 @@ not_in_argv (NSString *arg) - (void)windowDidResize: (NSNotification *)notification { + +#if !defined (NEW_STYLE_FS) && ! defined (NS_IMPL_GNUSTEP) + NSWindow *theWindow = [notification object]; + /* We can get notification on the non-FS window when in fullscreen mode. */ + if ([self window] != theWindow) return; +#endif + #ifdef NS_IMPL_GNUSTEP NSWindow *theWindow = [notification object]; - /* in GNUstep, at least currently, it's possible to get a didResize + /* In GNUstep, at least currently, it's possible to get a didResize without getting a willResize.. therefore we need to act as if we got the willResize now */ NSSize sz = [theWindow frame].size; @@ -5526,10 +5565,6 @@ not_in_argv (NSString *arg) } #endif /* NS_IMPL_COCOA */ - /* Avoid loop under GNUstep due to call at beginning of this function. - (x_set_window_size causes a resize which causes - a "windowDidResize" which calls x_set_window_size). */ -#ifndef NS_IMPL_GNUSTEP if (cols > 0 && rows > 0) { if (ns_in_resize) @@ -5539,7 +5574,6 @@ not_in_argv (NSString *arg) [self updateFrameSize: YES]; } } -#endif ns_send_appdefined (-1); } @@ -5661,7 +5695,7 @@ not_in_argv (NSString *arg) wr = [win frame]; bwidth = f->border_width = wr.size.width - r.size.width; - tbar_height = FRAME_NS_TITLEBAR_HEIGHT (f) = wr.size.height - r.size.height; + tibar_height = FRAME_NS_TITLEBAR_HEIGHT (f) = wr.size.height - r.size.height; [win setAcceptsMouseMovedEvents: YES]; [win setDelegate: self]; @@ -5870,8 +5904,16 @@ not_in_argv (NSString *arg) - (void)windowDidEnterFullScreen:(NSNotification *)notification { [self setFSValue: FULLSCREEN_BOTH]; -#ifndef NEW_STYLE_FS +#ifdef NEW_STYLE_FS + // Fix bad background. + if ([toolbar isVisible]) + { + [toolbar setVisible:NO]; + [toolbar setVisible:YES]; + } +#else [self windowDidBecomeKey:notification]; + [nonfs_window orderOut:self]; #endif } @@ -5891,11 +5933,6 @@ not_in_argv (NSString *arg) - (void)toggleFullScreen: (id)sender { - /* Bugs remain: - 1) Having fullscreen in initial/default frame alist. - 2) Fullscreen in default frame alist only applied to first frame. - */ - #ifdef NEW_STYLE_FS [[self window] toggleFullScreen:sender]; #else @@ -5904,7 +5941,7 @@ not_in_argv (NSString *arg) isEqual:[[NSScreen screens] objectAtIndex:0]]; struct frame *f = emacsframe; NSSize sz; - NSRect r; + NSRect r, wr = [w frame]; NSColor *col = ns_lookup_indexed_color (NS_FACE_BACKGROUND (FRAME_DEFAULT_FACE (f)), f); @@ -5930,7 +5967,7 @@ not_in_argv (NSString *arg) } fw = [[EmacsFSWindow alloc] - initWithContentRect:[w contentRectForFrameRect:[w frame]] + initWithContentRect:[w contentRectForFrameRect:wr] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES @@ -5938,9 +5975,7 @@ not_in_argv (NSString *arg) [fw setContentView:[w contentView]]; [fw setTitle:[w title]]; - [fw makeKeyAndOrderFront:NSApp]; [fw setDelegate:self]; - [fw makeFirstResponder:self]; [fw setAcceptsMouseMovedEvents: YES]; [fw useOptimizedDrawing: YES]; [fw setResizeIncrements: sz]; @@ -5950,18 +5985,26 @@ not_in_argv (NSString *arg) f->border_width = 0; FRAME_NS_TITLEBAR_HEIGHT (f) = 0; + tobar_height = FRAME_TOOLBAR_HEIGHT (f); + FRAME_TOOLBAR_HEIGHT (f) = 0; + FRAME_EXTERNAL_TOOL_BAR (f) = 0; nonfs_window = w; + [self windowWillEnterFullScreen:nil]; + [fw makeKeyAndOrderFront:NSApp]; + [fw makeFirstResponder:self]; [w orderOut:self]; r = [fw frameRectForContentRect:[[fw screen] frame]]; [fw setFrame: r display:YES animate:YES]; [self windowDidEnterFullScreen:nil]; + [fw display]; } else { fw = w; w = nonfs_window; + nonfs_window = nil; if (onFirstScreen) { @@ -5980,7 +6023,10 @@ not_in_argv (NSString *arg) [w setOpaque: NO]; f->border_width = bwidth; - FRAME_NS_TITLEBAR_HEIGHT (f) = tbar_height; + FRAME_NS_TITLEBAR_HEIGHT (f) = tibar_height; + FRAME_TOOLBAR_HEIGHT (f) = tobar_height; + if (tobar_height) + FRAME_EXTERNAL_TOOL_BAR (f) = 1; [self windowWillExitFullScreen:nil]; [fw setFrame: [w frame] display:YES animate:YES]; @@ -6553,6 +6599,11 @@ not_in_argv (NSString *arg) return YES; } +- (BOOL)canBecomeMainWindow +{ + return YES; +} + @end /* ========================================================================== -- 2.39.5