Ticket #27046: emacs-app-fullscreen.patch

File emacs-app-fullscreen.patch, 8.8 KB (added by mike.mclean@…, 14 years ago)
  • files/fullscreen.patch

     
     1diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el
     2index 157b2dd..f3807b7 100644
     3--- a/lisp/term/ns-win.el
     4+++ b/lisp/term/ns-win.el
     5@@ -1263,6 +1263,11 @@ the operating system.")
     6 (add-to-list 'window-system-initialization-alist '(ns . ns-initialize-window-system))
     7 
     8 
     9+(declare-function ns-toggle-fullscreen-internal "nsfns.m" ())
     10+(defun ns-toggle-fullscreen ()
     11+  (interactive)
     12+  (ns-toggle-fullscreen-internal))
     13+
     14 (provide 'ns-win)
     15 
     16 ;; arch-tag: eb138a45-4e2e-4d68-b1c9-a39665731644
     17diff --git a/src/nsfns.m b/src/nsfns.m
     18index 642ff79..03ffcf7 100644
     19--- a/src/nsfns.m
     20+++ b/src/nsfns.m
     21@@ -2589,6 +2589,34 @@ Value is t if tooltip was open, nil otherwise.  */)
     22 
     23 #endif
     24 
     25+DEFUN ("ns-toggle-fullscreen-internal", Fns_toggle_fullscreen_internal, Sns_toggle_fullscreen_internal,
     26+       0, 0, 0,
     27+       doc: /* Toggle fulscreen mode */)
     28+    ()
     29+{
     30+    struct frame *f = SELECTED_FRAME();
     31+    EmacsWindow *window = ns_get_window(f);
     32+
     33+    EmacsWindow *new_window = [window toggleFullscreen];
     34+    FRAME_NS_WINDOW(f) = new_window;
     35+
     36+    NSRect r = [new_window contentRectForFrameRect:[new_window frame]];
     37+    int cols = FRAME_PIXEL_WIDTH_TO_TEXT_COLS(f, r.size.width);
     38+    int rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES(f, r.size.height);
     39+
     40+    change_frame_size (f, rows, cols, 0, 1, 0); /* pretend, delay, safe */
     41+    FRAME_PIXEL_WIDTH (f) = (int)r.size.width;
     42+    FRAME_PIXEL_HEIGHT (f) = (int)r.size.height;
     43+
     44+    f->border_width = [new_window frame].size.width - r.size.width;
     45+    FRAME_NS_TITLEBAR_HEIGHT (f) =
     46+        [new_window frame].size.height - r.size.height;
     47+
     48+    [[new_window delegate] windowDidMove:nil];
     49+
     50+    return Qnil;
     51+}
     52+
     53 
     54 /* ==========================================================================
     55 
     56@@ -2676,6 +2704,8 @@ be used as the image of the icon representing the frame.  */);
     57   defsubr (&Sx_show_tip);
     58   defsubr (&Sx_hide_tip);
     59 
     60+  defsubr (&Sns_toggle_fullscreen_internal);
     61+
     62   /* used only in fontset.c */
     63   check_window_system_func = check_ns;
     64 
     65diff --git a/src/nsterm.h b/src/nsterm.h
     66index 29d312a..17b19e4 100644
     67--- a/src/nsterm.h
     68+++ b/src/nsterm.h
     69@@ -95,8 +95,25 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
     70 {
     71   NSPoint grabOffset;
     72 }
     73+
     74+-(EmacsWindow *)toggleFullscreen;
     75+
     76+@end
     77+
     78+/* 10.5 or below is not supported [NSWindow setStyleMask:], so require content swap hack */
     79+@interface EmacsFullWindow : EmacsWindow {
     80+    EmacsWindow *normalWindow;
     81+}
     82+
     83+-(id)initWithNormalWindow:(EmacsWindow *)window;
     84+-(EmacsWindow *)getNormalWindow;
     85+
     86 @end
     87 
     88+// dummy for 10.5-
     89+#define NSApplicationPresentationDefault 0
     90+#define NSApplicationPresentationAutoHideDock (1 <<  0)
     91+#define NSApplicationPresentationAutoHideMenuBar (1 <<  2)
     92 
     93 /* ==========================================================================
     94 
     95diff --git a/src/nsterm.m b/src/nsterm.m
     96index 9256c08..8bbb575 100644
     97--- a/src/nsterm.m
     98+++ b/src/nsterm.m
     99@@ -686,6 +686,13 @@ ns_focus (struct frame *f, NSRect *r, int n)
     100 /*debug_lock--; */
     101             }
     102 
     103+          if (view) {
     104+              EmacsFullWindow *win = [view window];
     105+              if ([win isKindOfClass:[EmacsFullWindow class]]) {
     106+                  [[win getNormalWindow] orderOut:nil];
     107+              }
     108+          }
     109+
     110           if (view)
     111 #ifdef NS_IMPL_GNUSTEP
     112             r ? [view lockFocusInRect: u] : [view lockFocus];
     113@@ -1131,8 +1138,14 @@ x_set_window_size (struct frame *f, int change_grav, int cols, int rows)
     114   f->scroll_bar_actual_width = NS_SCROLL_BAR_WIDTH (f);
     115   compute_fringe_widths (f, 0);
     116 
     117-  pixelwidth =  FRAME_TEXT_COLS_TO_PIXEL_WIDTH   (f, cols);
     118-  pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows);
     119+  if ([window isKindOfClass:[EmacsFullWindow class]]) {
     120+      pixelwidth = [[window screen] frame].size.width;
     121+      pixelheight = [[window screen] frame].size.height;
     122+  }
     123+  else {
     124+      pixelwidth =  FRAME_TEXT_COLS_TO_PIXEL_WIDTH   (f, cols);
     125+      pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows);
     126+  }
     127 
     128   /* If we have a toolbar, take its height into account. */
     129   if (tb)
     130@@ -1150,7 +1163,7 @@ x_set_window_size (struct frame *f, int change_grav, int cols, int rows)
     131                   + FRAME_NS_TOOLBAR_HEIGHT (f);
     132 
     133   /* constrain to screen if we can */
     134-  if (screen)
     135+  if (screen && ![window isKindOfClass:[EmacsFullWindow class]])
     136     {
     137       NSSize sz = [screen visibleFrame].size;
     138       NSSize ez = { wr.size.width - sz.width, wr.size.height - sz.height };
     139@@ -1197,7 +1210,7 @@ x_set_window_size (struct frame *f, int change_grav, int cols, int rows)
     140   change_frame_size (f, rows, cols, 0, 1, 0); /* pretend, delay, safe */
     141   FRAME_PIXEL_WIDTH (f) = pixelwidth;
     142   FRAME_PIXEL_HEIGHT (f) = pixelheight;
     143-/*  SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
     144+  /*  SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
     145 
     146   mark_window_cursors_off (XWINDOW (f->root_window));
     147   cancel_mouse_face (f);
     148@@ -5609,6 +5622,59 @@ extern void update_window_cursor (struct window *w, int on);
     149 
     150 @implementation EmacsWindow
     151 
     152+-(NSWindow *)toggleFullscreen {
     153+    BOOL isFullscreen = [[self className] isEqualToString:@"EmacsFullWindow"];
     154+    NSWindow *win;
     155+
     156+    if (isFullscreen) {
     157+        EmacsFullWindow *f = (EmacsFullWindow *)self;
     158+        EmacsWindow *w = [f getNormalWindow];
     159+
     160+        [w setContentView:[f contentView]];
     161+        [w makeKeyAndOrderFront:nil];
     162+
     163+        [f close];
     164+
     165+        win = w;
     166+
     167+        if ([[self screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) {
     168+            if ([NSApp respondsToSelector:@selector(setPresentationOptions:)]) {
     169+                [NSApp setPresentationOptions:NSApplicationPresentationDefault];
     170+            }
     171+            else {
     172+                [NSMenu setMenuBarVisible:YES];
     173+            }
     174+        }
     175+    }
     176+    else {
     177+        [self deminiaturize:nil];
     178+
     179+        if ([[self screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) {
     180+            if ([NSApp respondsToSelector:@selector(setPresentationOptions:)]) {
     181+                [NSApp setPresentationOptions:NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar];
     182+            }
     183+            else {
     184+                [NSMenu setMenuBarVisible:NO];
     185+            }
     186+        }
     187+
     188+        [self orderOut:nil];
     189+
     190+        EmacsFullWindow *f = [[EmacsFullWindow alloc] initWithNormalWindow:self];
     191+        EmacsView *view = (EmacsView *)[self delegate];
     192+        [f setDelegate:view];
     193+        [f makeFirstResponder:view];
     194+        [f setContentView:[self contentView]];
     195+        [f setContentSize:[[self screen] frame].size];
     196+        [f setTitle:[self title]];
     197+        [f makeKeyAndOrderFront:nil];
     198+
     199+        win = f;
     200+    }
     201+
     202+    return win;
     203+}
     204+
     205 /* called only on resize clicks by special case in EmacsApp-sendEvent */
     206 - (void)mouseDown: (NSEvent *)theEvent
     207 {
     208@@ -5667,6 +5733,32 @@ extern void update_window_cursor (struct window *w, int on);
     209 
     210 @end /* EmacsWindow */
     211 
     212+@implementation EmacsFullWindow
     213+
     214+-(BOOL)canBecomeKeyWindow {
     215+    return YES;
     216+}
     217+
     218+-(id)initWithNormalWindow:(EmacsWindow *)window {
     219+    self = [super initWithContentRect:[window contentRectForFrameRect:[[window screen] frame]]
     220+                            styleMask:NSBorderlessWindowMask
     221+                              backing:NSBackingStoreBuffered
     222+                                defer:YES];
     223+    if (self) {
     224+        normalWindow = window;
     225+        [self setAcceptsMouseMovedEvents: YES];
     226+        [self useOptimizedDrawing: YES];
     227+    }
     228+
     229+    return self;
     230+}
     231+
     232+-(EmacsWindow *)getNormalWindow {
     233+    return normalWindow;
     234+}
     235+
     236+@end /* EmacsFullWindow */
     237+
     238 
     239 /* ==========================================================================
     240 
  • Portfile

     
     1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
    12# $Id$
    23
    34PortSystem 1.0
     
    34name            emacs-app
    45version         23.2
     6revision    1
     7
    58categories      aqua editors
    69maintainers     css
     
    3134
    3235configure.args  --with-ns --without-x --without-dbus
    3336
     37variant fullscreen description {Add fullscreen patch from http://gist.github.com/291150 as mentioned in http://www.sanityinc.com/full-screen-support-for-cocoa-emacs-on-osx} {
     38    patchfiles fullscreen.patch
     39    patch.args -p1
     40}
     41
    3442destroot {
    3543        system "cd ${worksrcpath} && make install"
    3644        xinstall -m 755 -d ${destroot}${applications_dir}