Skip to content

Instantly share code, notes, and snippets.

@balibali
Created March 6, 2011 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balibali/857132 to your computer and use it in GitHub Desktop.
Save balibali/857132 to your computer and use it in GitHub Desktop.
Homebrew の Emacs 23.3 用パッチ。typester さんのパッチ (https://github.com/typester/emacs/downloads) をベースにフルスクリーン時にメニューバーを表示するように変更
#!/bin/sh
git --git-dir=$(brew --repository)/.git --work-tree=$(brew --repository) checkout Library/Formula/emacs.rb
brew update
brew uninstall emacs
curl "https://gist.github.com/raw/857132/emacs.rb.patch" | patch -p1 -d $(brew --repository)
brew install emacs --cocoa
ln -sf $(brew --prefix emacs)/Emacs.app /Applications
git --git-dir=$(brew --repository)/.git --work-tree=$(brew --repository) checkout Library/Formula/emacs.rb
#!/bin/bash
if [ -e ~/.emacs.d ]; then
echo "Error: \`~/.emacs.d' already exists" >&2
exit 1
fi
mkdir ~/.emacs.d
cd ~/.emacs.d
curl -O "https://gist.github.com/raw/846942/init.el"
mkdir lisp
cd lisp
# auto-install.el
curl -O "http://www.emacswiki.org/emacs/download/auto-install.el"
emacs --batch -Q -f batch-byte-compile auto-install.el
# color-theme.el
curl -L "http://download.savannah.gnu.org/releases/color-theme/color-theme-6.6.0.tar.gz" | tar xzv
cd color-theme-6.6.0
echo "OPTIONCOMPILE = -q --no-site-file --batch --eval '(setq load-path (cons \"..\" load-path))'" >> Makefile.defs
make clean
make
diff --git a/Library/Formula/emacs.rb b/Library/Formula/emacs.rb
index 30dae4d..84471a5 100644
--- a/Library/Formula/emacs.rb
+++ b/Library/Formula/emacs.rb
@@ -21,7 +21,10 @@ class Emacs <Formula
def patches
if ARGV.include? "--cocoa" and not ARGV.build_head?
- "https://github.com/downloads/typester/emacs/feature-fullscreen.patch"
+ [
+ "https://gist.github.com/raw/857132/fix-shiftmodifier-with-ime.patch",
+ "https://gist.github.com/raw/857132/feature-fullscreen.patch"
+ ]
end
end
diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el
index 6880fdb..7dae8ac 100644
--- a/lisp/term/ns-win.el
+++ b/lisp/term/ns-win.el
@@ -1267,6 +1267,11 @@ 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 10ce80d..407e1c4 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -2591,6 +2591,32 @@ Value is t if tooltip was open, nil otherwise. */)
#endif
+DEFUN ("ns-toggle-fullscreen-internal", Fns_toggle_fullscreen_internal, Sns_toggle_fullscreen_internal,
+ 0, 0, 0,
+ doc: /* Toggle fullscreen mode */)
+ ()
+{
+ struct frame *f = SELECTED_FRAME();
+ 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;
+
+ [[new_window delegate] windowDidMove:nil];
+
+ return Qnil;
+}
+
/* ==========================================================================
@@ -2676,6 +2702,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 00784a3..b8ab3c1 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -95,6 +95,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
{
NSPoint grabOffset;
}
+- (EmacsWindow *)toggleFullscreen;
+@end
+
+/* 10.5 or below is not supported [NSWindow setStyleMask:], so require content swap hack */
+@interface EmacsFullWindow : EmacsWindow
+{
+ EmacsWindow *normalWindow;
+}
+- (id)initWithNormalWindow:(EmacsWindow *)window;
+- (EmacsWindow *)getNormalWindow;
@end
diff --git a/src/nsterm.m b/src/nsterm.m
index 30b73c2..1642c07 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -696,6 +696,13 @@ ns_focus (struct frame *f, NSRect *r, int n)
}
if (view)
+ {
+ EmacsFullWindow *win = [view window];
+ if ([win isKindOfClass:[EmacsFullWindow class]])
+ [[win getNormalWindow] orderOut:nil];
+ }
+
+ if (view)
#ifdef NS_IMPL_GNUSTEP
r ? [view lockFocusInRect: u] : [view lockFocus];
#else
@@ -1155,8 +1162,16 @@ 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:[EmacsFullWindow class]])
+ {
+ pixelwidth = [[window screen] visibleFrame].size.width;
+ pixelheight = [[window screen] visibleFrame].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)
@@ -1174,7 +1189,7 @@ x_set_window_size (struct frame *f, int change_grav, int cols, int rows)
+ FRAME_TOOLBAR_HEIGHT (f);
/* constrain to screen if we can */
- if (screen)
+ if (screen && ![window isKindOfClass:[EmacsFullWindow class]])
{
NSSize sz = [screen visibleFrame].size;
NSSize ez = { wr.size.width - sz.width, wr.size.height - sz.height };
@@ -5620,6 +5635,43 @@ ns_term_shutdown (int sig)
@implementation EmacsWindow
+- (NSWindow *)toggleFullscreen
+{
+ BOOL isFullscreen = [[self className] isEqualToString:@"EmacsFullWindow"];
+ NSWindow *win;
+
+ if (isFullscreen)
+ {
+ EmacsFullWindow *f = (EmacsFullWindow *)self;
+ EmacsWindow *w = [f getNormalWindow];
+
+ [w setContentView:[f contentView]];
+ [w makeKeyAndOrderFront:nil];
+
+ [f close];
+
+ win = w;
+ }
+ else
+ {
+ [self deminiaturize:nil];
+ [self orderOut:nil];
+
+ EmacsFullWindow *f = [[EmacsFullWindow alloc] initWithNormalWindow:self];
+ EmacsView *view = (EmacsView *)[self delegate];
+ [f setDelegate:view];
+ [f makeFirstResponder:view];
+ [f setContentView:[self contentView]];
+ [f setContentSize:[[self screen] visibleFrame].size];
+ [f setTitle:[self title]];
+ [f makeKeyAndOrderFront:nil];
+
+ win = f;
+ }
+
+ return win;
+}
+
/* called only on resize clicks by special case in EmacsApp-sendEvent */
- (void)mouseDown: (NSEvent *)theEvent
{
@@ -5678,6 +5730,36 @@ ns_term_shutdown (int sig)
@end /* EmacsWindow */
+@implementation EmacsFullWindow
+
+- (BOOL)canBecomeKeyWindow
+{
+ return YES;
+}
+
+- (id)initWithNormalWindow:(EmacsWindow *)window
+{
+ self = [super initWithContentRect:[window contentRectForFrameRect:[[window screen] visibleFrame]]
+ styleMask:NSBorderlessWindowMask
+ backing:NSBackingStoreBuffered
+ defer:YES];
+ if (self)
+ {
+ normalWindow = window;
+ [self setAcceptsMouseMovedEvents: YES];
+ [self useOptimizedDrawing: YES];
+ }
+
+ return self;
+}
+
+- (EmacsWindow *)getNormalWindow
+{
+ return normalWindow;
+}
+
+@end /* EmacsFullWindow */
+
/* ==========================================================================
diff --git a/src/nsterm.m b/src/nsterm.m
index 30b73c2..56f9464 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4488,7 +4488,7 @@ ns_term_shutdown (int sig)
code, fnKeysym, flags, emacs_event->modifiers);
/* if it was a function key or had modifiers, pass it directly to emacs */
- if (fnKeysym || (emacs_event->modifiers
+ if (fnKeysym || (emacs_event->modifiers && (emacs_event->modifiers != shift_modifier)
&& [[theEvent charactersIgnoringModifiers] length] > 0))
/*[[theEvent characters] length] */
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment