Created
March 29, 2012 15:03
-
-
Save ecarnevale/2238260 to your computer and use it in GitHub Desktop.
Add ns-toggle-fullscreen to Emacs 24
This file contains hidden or 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 084b62f..b7ed1a2 100644 | |
--- a/lisp/term/ns-win.el | |
+++ b/lisp/term/ns-win.el | |
@@ -1267,6 +1267,10 @@ the operating system.") | |
(add-to-list 'window-system-initialization-alist '(ns . ns-initialize-window-system)) | |
+(declare-function ns-toggle-fullscreen-internal "nsfns.m" ()) | |
+(defun ns-toggle-fullscreen () | |
+ (interactive) | |
+ (ns-toggle-fullscreen-internal)) | |
(provide 'ns-win) | |
;; arch-tag: eb138a45-4e2e-4d68-b1c9-a39665731644 | |
diff --git a/src/nsfns.m b/src/nsfns.m | |
index bcf81ab..a727724 100644 | |
--- a/src/nsfns.m | |
+++ b/src/nsfns.m | |
@@ -2568,6 +2568,23 @@ Value is t if tooltip was open, nil otherwise. */) | |
[NSApp stop: self]; | |
} | |
#endif | |
+ | |
+DEFUN ("ns-toggle-fullscreen-internal", Fns_toggle_fullscreen_internal, Sns_toggle_fullscreen_internal, | |
+ 0, 0, 0, | |
+ doc: /* Toggle fulscreen mode */) | |
+() | |
+{ | |
+ struct frame *f = SELECTED_FRAME(); | |
+ EmacsWindow *window = ns_get_window(f); | |
+ | |
+#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | |
+ [window toggleFullScreen:nil]; | |
+#endif | |
+ | |
+ return Qnil; | |
+} | |
+ | |
+ | |
@end | |
@@ -2677,6 +2694,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/nsmenu.m b/src/nsmenu.m | |
index c34d787..c3a3371 100644 | |
--- a/src/nsmenu.m | |
+++ b/src/nsmenu.m | |
@@ -999,7 +999,7 @@ free_frame_tool_bar (FRAME_PTR f) | |
Under NS we just hide the toolbar until it might be needed again. | |
-------------------------------------------------------------------------- */ | |
{ | |
- [[FRAME_NS_VIEW (f) toolbar] setVisible: NO]; | |
+ [[FRAME_NS_VIEW (f) window] setToolbar: nil]; | |
} | |
void | |
@@ -1011,6 +1011,7 @@ update_frame_tool_bar (FRAME_PTR f) | |
int i; | |
EmacsToolbar *toolbar = [FRAME_NS_VIEW (f) toolbar]; | |
+ [window setToolbar: toolbar]; | |
[toolbar clearActive]; | |
/* update EmacsToolbar as in GtkUtils, build items list */ | |
diff --git a/src/nsterm.h b/src/nsterm.h | |
index 88fb2f4..0d4cc14 100644 | |
--- a/src/nsterm.h | |
+++ b/src/nsterm.h | |
@@ -315,6 +315,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |
- initWithCapacity: (unsigned long) c; | |
- (void) setString: (NSString *)str font: (NSFont *)font; | |
@end | |
+#ifndef MAC_OS_X_VERSION_10_7 | |
+#define MAC_OS_X_VERSION_10_7 1070 | |
+#endif | |
#endif /* NS_IMPL_COCOA */ | |
extern NSArray *ns_send_types, *ns_return_types; | |
diff --git a/src/nsterm.m b/src/nsterm.m | |
index cfe82b6..2c1b734 100644 | |
--- a/src/nsterm.m | |
+++ b/src/nsterm.m | |
@@ -4935,39 +4935,7 @@ ns_term_shutdown (int sig) | |
frameSize.height = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (emacsframe, rows) | |
+ FRAME_NS_TITLEBAR_HEIGHT (emacsframe) | |
+ FRAME_TOOLBAR_HEIGHT (emacsframe); | |
-#ifdef NS_IMPL_COCOA | |
- { | |
- /* this sets window title to have size in it; the wm does this under GS */ | |
- NSRect r = [[self window] frame]; | |
- if (r.size.height == frameSize.height && r.size.width == frameSize.width) | |
- { | |
- if (old_title != 0) | |
- { | |
- xfree (old_title); | |
- old_title = 0; | |
- } | |
- } | |
- else | |
- { | |
- char *size_title; | |
- NSWindow *window = [self window]; | |
- if (old_title == 0) | |
- { | |
- const char *t = [[[self window] title] UTF8String]; | |
- char *pos = strstr (t, " — "); | |
- if (pos) | |
- *pos = '\0'; | |
- old_title = (char *) xmalloc (strlen (t) + 1); | |
- strcpy (old_title, t); | |
- } | |
- size_title = xmalloc (strlen (old_title) + 40); | |
- sprintf (size_title, "%s — (%d x %d)", old_title, cols, rows); | |
- [window setTitle: [NSString stringWithUTF8String: size_title]]; | |
- [window display]; | |
- xfree (size_title); | |
- } | |
- } | |
-#endif /* NS_IMPL_COCOA */ | |
+ | |
/*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */ | |
return frameSize; | |
@@ -4989,14 +4957,6 @@ ns_term_shutdown (int sig) | |
NSTRACE (windowDidResize); | |
/*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */ | |
-#ifdef NS_IMPL_COCOA | |
- if (old_title != 0) | |
- { | |
- xfree (old_title); | |
- old_title = 0; | |
- } | |
-#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). */ | |
@@ -5172,6 +5132,14 @@ ns_term_shutdown (int sig) | |
[self allocateGState]; | |
+#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | |
+ if (NSApp != nil && [NSApp isActive]) | |
+ { | |
+ [NSApp setPresentationOptions: NSApplicationPresentationFullScreen | [NSApp presentationOptions] ]; | |
+ [win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary | [win collectionBehavior] ]; | |
+ } | |
+#endif | |
+ | |
ns_window_num++; | |
return self; | |
} | |
@@ -5542,6 +5510,60 @@ ns_term_shutdown (int sig) | |
} | |
} | |
+#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | |
+- (void)windowDidEnterFullScreen:(NSNotification *)notification | |
+{ | |
+ NSTRACE (windowDidEnterFullScreen); | |
+ /* NSLog(@"Calling windowDidEnterFullScreen"); */ | |
+ | |
+ NSWindow *window = [self window]; | |
+ NSRect wr = [window frame]; | |
+ int w = (int)wr.size.width - emacsframe->border_width; | |
+ int h = (int)wr.size.height; | |
+ cols = FRAME_PIXEL_WIDTH_TO_TEXT_COLS(emacsframe, w); | |
+ rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES(emacsframe, h); | |
+ /* NSLog(@"window_size=%dx%d (%dx%d)", w, h, cols, rows); */ | |
+ FRAME_PIXEL_WIDTH (emacsframe) = w; | |
+ FRAME_PIXEL_HEIGHT (emacsframe) = h; | |
+ change_frame_size (emacsframe, rows, cols, 0, 1, 0); | |
+ SET_FRAME_GARBAGED (emacsframe); | |
+ cancel_mouse_face (emacsframe); | |
+ ns_send_appdefined (-1); | |
+} | |
+#endif | |
+ | |
+#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | |
+- (void)windowDidExitFullScreen:(NSNotification *)notification | |
+{ | |
+ NSTRACE (windowDidExitFullScreen); | |
+ /* NSLog(@"Calling windowDidExitFullScreen"); */ | |
+ | |
+ NSWindow *window = [self window]; | |
+ NSRect wr = [window frame]; | |
+ int w = (int)wr.size.width - emacsframe->border_width; | |
+ int h = (int)wr.size.height | |
+ - FRAME_NS_TITLEBAR_HEIGHT (emacsframe) | |
+ - FRAME_TOOLBAR_HEIGHT (emacsframe); | |
+ cols = FRAME_PIXEL_WIDTH_TO_TEXT_COLS(emacsframe, w); | |
+ rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES(emacsframe, h); | |
+ /* NSLog(@"window_size=%dx%d (%dx%d)", w, h, cols, rows); */ | |
+ FRAME_PIXEL_WIDTH (emacsframe) = w; | |
+ FRAME_PIXEL_HEIGHT (emacsframe) = h; | |
+ change_frame_size (emacsframe, rows, cols, 0, 1, 0); | |
+ SET_FRAME_GARBAGED (emacsframe); | |
+ cancel_mouse_face (emacsframe); | |
+ ns_send_appdefined (-1); | |
+} | |
+#endif | |
+ | |
+#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | |
+- (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions | |
+{ | |
+ /* NSLog(@"Calling window:willUseFullScreenPresentationOptions: %d", proposedOptions); */ | |
+ return proposedOptions | NSApplicationPresentationAutoHideToolbar; | |
+} | |
+#endif | |
+ | |
- validRequestorForSendType: (NSString *)typeSent | |
returnType: (NSString *)typeReturned |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment