Last active
December 11, 2015 01:38
-
-
Save RyanKung/4524519 to your computer and use it in GitHub Desktop.
no-lion-style fullscreen implementation for emacs 24.2, base on typester's patch. The title-height will be set zero while 'ns-toggle-fullscreen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el | |
index 1aad645..51e41df 100644 | |
--- a/lisp/term/ns-win.el | |
+++ b/lisp/term/ns-win.el | |
@@ -942,6 +942,12 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") | |
(add-to-list 'frame-creation-function-alist '(ns . x-create-frame-with-faces)) | |
(add-to-list 'window-system-initialization-alist '(ns . ns-initialize-window-system)) | |
+;; for fullscreen | |
+(declare-function ns-toggle-fullscreen-internal "nsfns.m" ()) | |
+(defun ns-toggle-fullscreen () | |
+ (interactive) | |
+ (ns-toggle-fullscreen-internal)) | |
+ | |
(provide 'ns-win) | |
diff --git a/src/nsfns.m b/src/nsfns.m | |
index 9e89737..13496ce 100644 | |
--- a/src/nsfns.m | |
+++ b/src/nsfns.m | |
@@ -1605,6 +1605,36 @@ If VALUE is nil, the default is removed. */) | |
return Qnil; | |
} | |
+DEFUN ("ns-toggle-fullscreen-internal", Fns_toggle_fullscreen_internal, Sns_toggle_fullscreen_internal, | |
+ 0, 0, 0, | |
+ doc: /* Toggle fulscreen mode */) | |
+ () | |
+{ | |
+ NSLog(@"ENTER FULLSCREEN"); | |
+ struct frame *f = SELECTED_FRAME(); | |
+ FRAME_NS_TITLEBAR_HEIGHT (f) = 0; | |
+ EmacsWindow *window = ns_get_window(f); | |
+ EmacsWindow *new_window = [window toggleFullscreen]; | |
+ FRAME_NS_WINDOW(f) = new_window; | |
+ | |
+ | |
+ NSRect r = [new_window contentRectForFrameRect:[new_window frame]]; | |
+ int cols = FRAME_PIXEL_WIDTH_TO_TEXT_COLS(f, r.size.width); | |
+ int rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES(f, r.size.height); | |
+ | |
+ change_frame_size (f, rows, cols, 0, 1, 0); /* pretend, delay, safe */ | |
+ FRAME_PIXEL_WIDTH (f) = (int)r.size.width; | |
+ FRAME_PIXEL_HEIGHT (f) = (int)r.size.height; | |
+ | |
+ f->border_width = [new_window frame].size.width - r.size.width; | |
+ FRAME_NS_TITLEBAR_HEIGHT (f) = 0; | |
+ | |
+ [[new_window delegate] windowDidMove:nil]; | |
+ | |
+ return Qnil; | |
+} | |
+ | |
+ | |
DEFUN ("x-server-max-request-size", Fx_server_max_request_size, | |
Sx_server_max_request_size, | |
@@ -2746,6 +2776,8 @@ be used as the image of the icon representing the frame. */); | |
defsubr (&Sx_show_tip); | |
defsubr (&Sx_hide_tip); | |
+ defsubr (&Sns_toggle_fullscreen_internal); | |
+ | |
/* used only in fontset.c */ | |
check_window_system_func = check_ns; | |
diff --git a/src/nsterm.h b/src/nsterm.h | |
index 806cfcc..9a79b6a 100644 | |
--- a/src/nsterm.h | |
+++ b/src/nsterm.h | |
@@ -128,14 +128,28 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |
{ | |
NSPoint grabOffset; | |
} | |
-@end | |
+-(EmacsWindow *)toggleFullscreen; | |
+ | |
+@end | |
+/* 10.5 or below is not supported [NSWindow setStyleMask:], so require content swap hack */ | |
/* Fullscreen version of the above. */ | |
@interface EmacsFSWindow : EmacsWindow | |
{ | |
+ EmacsWindow *normalWindow; | |
} | |
+ | |
+-(id)initWithNormalWindow:(EmacsWindow *)window; | |
+-(EmacsWindow *)getNormalWindow; | |
+ | |
@end | |
+ | |
+// dummy for 10.5- | |
+#define NSApplicationPresentationDefault 0 | |
+#define NSApplicationPresentationAutoHideDock (1 << 0) | |
+#define NSApplicationPresentationAutoHideMenuBar (1 << 2) | |
+ | |
/* ========================================================================== | |
diff --git a/src/nsterm.m b/src/nsterm.m | |
index a57e744..e36de0f 100644 | |
--- a/src/nsterm.m | |
+++ b/src/nsterm.m | |
@@ -809,6 +809,12 @@ ns_focus (struct frame *f, NSRect *r, int n) | |
[focus_view unlockFocus]; | |
[[focus_view window] flushWindow]; | |
/*debug_lock--; */ | |
+ if (view) { | |
+ EmacsFSWindow *win = [view window]; | |
+ if ([win isKindOfClass:[EmacsFSWindow class]]) { | |
+ [[win getNormalWindow] orderOut:nil]; | |
+ } | |
+ } | |
} | |
if (view) | |
@@ -1275,8 +1281,15 @@ x_set_window_size (struct frame *f, int change_grav, int cols, int rows) | |
f->scroll_bar_actual_width = NS_SCROLL_BAR_WIDTH (f); | |
compute_fringe_widths (f, 0); | |
- pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, cols); | |
- pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows); | |
+ if ([window isKindOfClass:[EmacsFSWindow class]]) { | |
+ pixelwidth = [[window screen] frame].size.width; | |
+ pixelheight = [[window screen] frame].size.height; | |
+ } | |
+ else { | |
+ pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, cols); | |
+ pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows); | |
+ } | |
+ | |
/* If we have a toolbar, take its height into account. */ | |
if (tb) | |
@@ -5857,6 +5870,7 @@ not_in_argv (NSString *arg) | |
- (void)windowWillEnterFullScreen:(NSNotification *)notification | |
{ | |
+ NSLog(@"Enter with lion API"); | |
fs_before_fs = fs_state; | |
} | |
@@ -6413,6 +6427,59 @@ not_in_argv (NSString *arg) | |
@implementation EmacsWindow | |
+-(NSWindow *)toggleFullscreen { | |
+ BOOL isFullscreen = [[self className] isEqualToString:@"EmacsFSWindow"]; | |
+ NSWindow *win; | |
+ if (isFullscreen) { | |
+ EmacsFSWindow *f = (EmacsFSWindow *)self; | |
+ EmacsWindow *w = [f getNormalWindow]; | |
+ | |
+ [w setContentView:[f contentView]]; | |
+ [w makeKeyAndOrderFront:nil]; | |
+ | |
+ [f close]; | |
+ | |
+ win = w; | |
+ | |
+ if ([[self screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) { | |
+ if ([NSApp respondsToSelector:@selector(setPresentationOptions:)]) { | |
+ [NSApp setPresentationOptions:NSApplicationPresentationDefault]; | |
+ } | |
+ else { | |
+ [NSMenu setMenuBarVisible:YES]; | |
+ } | |
+ } | |
+ } | |
+ else { | |
+ [self deminiaturize:nil]; | |
+ | |
+ if ([[self screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) { | |
+ if ([NSApp respondsToSelector:@selector(setPresentationOptions:)]) { | |
+ [NSApp setPresentationOptions:NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar]; | |
+ } | |
+ else { | |
+ [NSMenu setMenuBarVisible:NO]; | |
+ } | |
+ } | |
+ | |
+ [self orderOut:nil]; | |
+ | |
+ EmacsFSWindow *f = [[EmacsFSWindow alloc] initWithNormalWindow:self]; | |
+ EmacsView *view = (EmacsView *)[self delegate]; | |
+ [f setDelegate:view]; | |
+ [f makeFirstResponder:view]; | |
+ [f setContentView:[self contentView]]; | |
+ [f setContentSize:[[self screen] frame].size]; | |
+ [f setTitle:[self title]]; | |
+ [f makeKeyAndOrderFront:nil]; | |
+ | |
+ win = f; | |
+ } | |
+ | |
+ return win; | |
+} | |
+ | |
+ | |
#ifdef NS_IMPL_COCOA | |
- (id)accessibilityAttributeValue:(NSString *)attribute | |
{ | |
@@ -6499,17 +6566,35 @@ not_in_argv (NSString *arg) | |
@implementation EmacsFSWindow | |
-- (BOOL)canBecomeKeyWindow | |
+- (BOOL)canBecomeMainWindow | |
{ | |
return YES; | |
} | |
-- (BOOL)canBecomeMainWindow | |
-{ | |
- return YES; | |
+-(BOOL)canBecomeKeyWindow { | |
+ return YES; | |
} | |
-@end | |
+-(id)initWithNormalWindow:(EmacsWindow *)window { | |
+ self = [super initWithContentRect:[window contentRectForFrameRect:[[window screen] frame]] | |
+ styleMask:NSBorderlessWindowMask | |
+ backing:NSBackingStoreBuffered | |
+ defer:YES]; | |
+ if (self) { | |
+ normalWindow = window; | |
+ [self setAcceptsMouseMovedEvents: YES]; | |
+ [self useOptimizedDrawing: YES]; | |
+ } | |
+ | |
+ return self; | |
+} | |
+ | |
+-(EmacsWindow *)getNormalWindow { | |
+ return normalWindow; | |
+} | |
+ | |
+@end /* EmacsFullWindow */ | |
+ | |
/* ========================================================================== | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment