aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsterm.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/nsterm.m')
-rw-r--r--src/nsterm.m232
1 files changed, 75 insertions, 157 deletions
diff --git a/src/nsterm.m b/src/nsterm.m
index 2df0e1a1ad5..6b739befeeb 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -183,7 +183,6 @@ static int ns_window_num = 0;
183static NSRect uRect; 183static NSRect uRect;
184#endif 184#endif
185static BOOL gsaved = NO; 185static BOOL gsaved = NO;
186BOOL ns_in_resize = NO;
187static BOOL ns_fake_keydown = NO; 186static BOOL ns_fake_keydown = NO;
188int ns_tmp_flags; /* FIXME */ 187int ns_tmp_flags; /* FIXME */
189struct nsfont_info *ns_tmp_font; /* FIXME */ 188struct nsfont_info *ns_tmp_font; /* FIXME */
@@ -493,17 +492,6 @@ ns_release_autorelease_pool (void *pool)
493 492
494 ========================================================================== */ 493 ========================================================================== */
495 494
496static NSRect
497ns_resize_handle_rect (NSWindow *window)
498{
499 NSRect r = [window frame];
500 r.origin.x = r.size.width - RESIZE_HANDLE_SIZE;
501 r.origin.y = 0;
502 r.size.width = r.size.height = RESIZE_HANDLE_SIZE;
503 return r;
504}
505
506
507// 495//
508// Window constraining 496// Window constraining
509// ------------------- 497// -------------------
@@ -581,9 +569,6 @@ ns_menu_bar_should_be_hidden (void)
581static void 569static void
582ns_update_auto_hide_menu_bar (void) 570ns_update_auto_hide_menu_bar (void)
583{ 571{
584#ifndef MAC_OS_X_VERSION_10_6
585#define MAC_OS_X_VERSION_10_6 1060
586#endif
587#ifdef NS_IMPL_COCOA 572#ifdef NS_IMPL_COCOA
588#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 573#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
589 block_input (); 574 block_input ();
@@ -1068,8 +1053,23 @@ x_make_frame_visible (struct frame *f)
1068 if this ends up the case again, comment this out again. */ 1053 if this ends up the case again, comment this out again. */
1069 if (!FRAME_VISIBLE_P (f)) 1054 if (!FRAME_VISIBLE_P (f))
1070 { 1055 {
1056 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
1071 f->async_visible = 1; 1057 f->async_visible = 1;
1072 ns_raise_frame (f); 1058 ns_raise_frame (f);
1059
1060#ifdef NEW_STYLE_FS
1061 /* Making a new frame from a fullscreen frame will make the new frame
1062 fullscreen also. So skip handleFS as this will print an error. */
1063 if (f->want_fullscreen == FULLSCREEN_BOTH
1064 && ([[view window] styleMask] & NSFullScreenWindowMask) != 0)
1065 return;
1066#endif
1067 if (f->want_fullscreen != FULLSCREEN_NONE)
1068 {
1069 block_input ();
1070 [view handleFS];
1071 unblock_input ();
1072 }
1073 } 1073 }
1074} 1074}
1075 1075
@@ -1317,6 +1317,18 @@ ns_fullscreen_hook (FRAME_PTR f)
1317 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); 1317 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
1318 1318
1319 if (! f->async_visible) return; 1319 if (! f->async_visible) return;
1320#ifndef NEW_STYLE_FS
1321 if (f->want_fullscreen == FULLSCREEN_BOTH)
1322 {
1323 /* Old style fs don't initiate correctly if created from
1324 init/default-frame alist, so use a timer (not nice...).
1325 */
1326 [NSTimer scheduledTimerWithTimeInterval: 0.5 target: view
1327 selector: @selector (handleFS)
1328 userInfo: nil repeats: NO];
1329 return;
1330 }
1331#endif
1320 1332
1321 block_input (); 1333 block_input ();
1322 [view handleFS]; 1334 [view handleFS];
@@ -1956,8 +1968,6 @@ ns_clear_frame (struct frame *f)
1956 NSRect r; 1968 NSRect r;
1957 1969
1958 NSTRACE (ns_clear_frame); 1970 NSTRACE (ns_clear_frame);
1959 if (ns_in_resize)
1960 return;
1961 1971
1962 /* comes on initial frame because we have 1972 /* comes on initial frame because we have
1963 after-make-frame-functions = select-frame */ 1973 after-make-frame-functions = select-frame */
@@ -1977,10 +1987,6 @@ ns_clear_frame (struct frame *f)
1977 NSRectFill (r); 1987 NSRectFill (r);
1978 ns_unfocus (f); 1988 ns_unfocus (f);
1979 1989
1980#ifdef NS_IMPL_COCOA
1981 [[view window] display]; /* redraw resize handle */
1982#endif
1983
1984 /* as of 2006/11 or so this is now needed */ 1990 /* as of 2006/11 or so this is now needed */
1985 ns_redraw_scroll_bars (f); 1991 ns_redraw_scroll_bars (f);
1986 unblock_input (); 1992 unblock_input ();
@@ -2006,35 +2012,8 @@ ns_clear_frame_area (struct frame *f, int x, int y, int width, int height)
2006 ns_focus (f, &r, 1); 2012 ns_focus (f, &r, 1);
2007 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f) set]; 2013 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f) set];
2008 2014
2009#ifdef NS_IMPL_COCOA
2010 {
2011 /* clip out the resize handle */
2012 NSWindow *window = [FRAME_NS_VIEW (f) window];
2013 NSRect ir
2014 = [view convertRect: ns_resize_handle_rect (window) fromView: nil];
2015
2016 ir = NSIntersectionRect (r, ir);
2017 if (NSIsEmptyRect (ir))
2018 {
2019#endif
2020
2021 NSRectFill (r); 2015 NSRectFill (r);
2022 2016
2023#ifdef NS_IMPL_COCOA
2024 }
2025 else
2026 {
2027 NSRect r1 = r, r2 = r; /* upper and lower non-intersecting */
2028 r1.size.height -= ir.size.height;
2029 r2.origin.y += r1.size.height;
2030 r2.size.width -= ir.size.width;
2031 r2.size.height = ir.size.height;
2032 NSRectFill (r1);
2033 NSRectFill (r2);
2034 }
2035 }
2036#endif
2037
2038 ns_unfocus (f); 2017 ns_unfocus (f);
2039 return; 2018 return;
2040} 2019}
@@ -2996,8 +2975,10 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
2996 { 2975 {
2997#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 2976#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2998 NSRect dr = NSMakeRect (x, y, s->slice.width, s->slice.height); 2977 NSRect dr = NSMakeRect (x, y, s->slice.width, s->slice.height);
2978 NSRect ir = NSMakeRect (s->slice.x, s->slice.y,
2979 s->slice.width, s->slice.height);
2999 [img drawInRect: dr 2980 [img drawInRect: dr
3000 fromRect: NSZeroRect 2981 fromRect: ir
3001 operation: NSCompositeSourceOver 2982 operation: NSCompositeSourceOver
3002 fraction: 1.0 2983 fraction: 1.0
3003 respectFlipped: YES 2984 respectFlipped: YES
@@ -4210,6 +4191,11 @@ ns_term_init (Lisp_Object display_name)
4210 NSColorPboardType, 4191 NSColorPboardType,
4211 NSFontPboardType, nil] retain]; 4192 NSFontPboardType, nil] retain];
4212 4193
4194#ifndef NEW_STYLE_FS
4195 /* If fullscreen is in init/default-frame-alist, focus isn't set
4196 right for fullscreen windows, so set this. */
4197 [NSApp activateIgnoringOtherApps:YES];
4198#endif
4213 4199
4214 [NSApp run]; 4200 [NSApp run];
4215 ns_do_open_file = YES; 4201 ns_do_open_file = YES;
@@ -4282,34 +4268,6 @@ ns_term_shutdown (int sig)
4282 return; 4268 return;
4283 } 4269 }
4284 4270
4285#ifdef NS_IMPL_COCOA
4286 /* pass mouse down in resize handle and subsequent drags directly to
4287 EmacsWindow so we can generate continuous redisplays */
4288 if (ns_in_resize)
4289 {
4290 if (type == NSLeftMouseDragged)
4291 {
4292 [window mouseDragged: theEvent];
4293 return;
4294 }
4295 else if (type == NSLeftMouseUp)
4296 {
4297 [window mouseUp: theEvent];
4298 return;
4299 }
4300 }
4301 else if (type == NSLeftMouseDown)
4302 {
4303 NSRect r = ns_resize_handle_rect (window);
4304 if (NSPointInRect ([theEvent locationInWindow], r))
4305 {
4306 ns_in_resize = YES;
4307 [window mouseDown: theEvent];
4308 return;
4309 }
4310 }
4311#endif
4312
4313 if (type == NSApplicationDefined) 4271 if (type == NSApplicationDefined)
4314 { 4272 {
4315 /* Events posted by ns_send_appdefined interrupt the run loop here. 4273 /* Events posted by ns_send_appdefined interrupt the run loop here.
@@ -5505,10 +5463,17 @@ not_in_argv (NSString *arg)
5505 5463
5506- (void)windowDidResize: (NSNotification *)notification 5464- (void)windowDidResize: (NSNotification *)notification
5507{ 5465{
5466
5467#if !defined (NEW_STYLE_FS) && ! defined (NS_IMPL_GNUSTEP)
5468 NSWindow *theWindow = [notification object];
5469 /* We can get notification on the non-FS window when in fullscreen mode. */
5470 if ([self window] != theWindow) return;
5471#endif
5472
5508#ifdef NS_IMPL_GNUSTEP 5473#ifdef NS_IMPL_GNUSTEP
5509 NSWindow *theWindow = [notification object]; 5474 NSWindow *theWindow = [notification object];
5510 5475
5511 /* in GNUstep, at least currently, it's possible to get a didResize 5476 /* In GNUstep, at least currently, it's possible to get a didResize
5512 without getting a willResize.. therefore we need to act as if we got 5477 without getting a willResize.. therefore we need to act as if we got
5513 the willResize now */ 5478 the willResize now */
5514 NSSize sz = [theWindow frame].size; 5479 NSSize sz = [theWindow frame].size;
@@ -5526,20 +5491,10 @@ not_in_argv (NSString *arg)
5526 } 5491 }
5527#endif /* NS_IMPL_COCOA */ 5492#endif /* NS_IMPL_COCOA */
5528 5493
5529 /* Avoid loop under GNUstep due to call at beginning of this function.
5530 (x_set_window_size causes a resize which causes
5531 a "windowDidResize" which calls x_set_window_size). */
5532#ifndef NS_IMPL_GNUSTEP
5533 if (cols > 0 && rows > 0) 5494 if (cols > 0 && rows > 0)
5534 { 5495 {
5535 if (ns_in_resize) 5496 [self updateFrameSize: YES];
5536 x_set_window_size (emacsframe, 0, cols, rows);
5537 else
5538 {
5539 [self updateFrameSize: YES];
5540 }
5541 } 5497 }
5542#endif
5543 5498
5544 ns_send_appdefined (-1); 5499 ns_send_appdefined (-1);
5545} 5500}
@@ -5661,7 +5616,7 @@ not_in_argv (NSString *arg)
5661 5616
5662 wr = [win frame]; 5617 wr = [win frame];
5663 bwidth = f->border_width = wr.size.width - r.size.width; 5618 bwidth = f->border_width = wr.size.width - r.size.width;
5664 tbar_height = FRAME_NS_TITLEBAR_HEIGHT (f) = wr.size.height - r.size.height; 5619 tibar_height = FRAME_NS_TITLEBAR_HEIGHT (f) = wr.size.height - r.size.height;
5665 5620
5666 [win setAcceptsMouseMovedEvents: YES]; 5621 [win setAcceptsMouseMovedEvents: YES];
5667 [win setDelegate: self]; 5622 [win setDelegate: self];
@@ -5870,8 +5825,16 @@ not_in_argv (NSString *arg)
5870- (void)windowDidEnterFullScreen:(NSNotification *)notification 5825- (void)windowDidEnterFullScreen:(NSNotification *)notification
5871{ 5826{
5872 [self setFSValue: FULLSCREEN_BOTH]; 5827 [self setFSValue: FULLSCREEN_BOTH];
5873#ifndef NEW_STYLE_FS 5828#ifdef NEW_STYLE_FS
5829 // Fix bad background.
5830 if ([toolbar isVisible])
5831 {
5832 [toolbar setVisible:NO];
5833 [toolbar setVisible:YES];
5834 }
5835#else
5874 [self windowDidBecomeKey:notification]; 5836 [self windowDidBecomeKey:notification];
5837 [nonfs_window orderOut:self];
5875#endif 5838#endif
5876} 5839}
5877 5840
@@ -5891,11 +5854,6 @@ not_in_argv (NSString *arg)
5891 5854
5892- (void)toggleFullScreen: (id)sender 5855- (void)toggleFullScreen: (id)sender
5893{ 5856{
5894 /* Bugs remain:
5895 1) Having fullscreen in initial/default frame alist.
5896 2) Fullscreen in default frame alist only applied to first frame.
5897 */
5898
5899#ifdef NEW_STYLE_FS 5857#ifdef NEW_STYLE_FS
5900 [[self window] toggleFullScreen:sender]; 5858 [[self window] toggleFullScreen:sender];
5901#else 5859#else
@@ -5904,7 +5862,7 @@ not_in_argv (NSString *arg)
5904 isEqual:[[NSScreen screens] objectAtIndex:0]]; 5862 isEqual:[[NSScreen screens] objectAtIndex:0]];
5905 struct frame *f = emacsframe; 5863 struct frame *f = emacsframe;
5906 NSSize sz; 5864 NSSize sz;
5907 NSRect r; 5865 NSRect r, wr = [w frame];
5908 NSColor *col = ns_lookup_indexed_color (NS_FACE_BACKGROUND 5866 NSColor *col = ns_lookup_indexed_color (NS_FACE_BACKGROUND
5909 (FRAME_DEFAULT_FACE (f)), 5867 (FRAME_DEFAULT_FACE (f)),
5910 f); 5868 f);
@@ -5930,7 +5888,7 @@ not_in_argv (NSString *arg)
5930 } 5888 }
5931 5889
5932 fw = [[EmacsFSWindow alloc] 5890 fw = [[EmacsFSWindow alloc]
5933 initWithContentRect:[w contentRectForFrameRect:[w frame]] 5891 initWithContentRect:[w contentRectForFrameRect:wr]
5934 styleMask:NSBorderlessWindowMask 5892 styleMask:NSBorderlessWindowMask
5935 backing:NSBackingStoreBuffered 5893 backing:NSBackingStoreBuffered
5936 defer:YES 5894 defer:YES
@@ -5938,9 +5896,7 @@ not_in_argv (NSString *arg)
5938 5896
5939 [fw setContentView:[w contentView]]; 5897 [fw setContentView:[w contentView]];
5940 [fw setTitle:[w title]]; 5898 [fw setTitle:[w title]];
5941 [fw makeKeyAndOrderFront:NSApp];
5942 [fw setDelegate:self]; 5899 [fw setDelegate:self];
5943 [fw makeFirstResponder:self];
5944 [fw setAcceptsMouseMovedEvents: YES]; 5900 [fw setAcceptsMouseMovedEvents: YES];
5945 [fw useOptimizedDrawing: YES]; 5901 [fw useOptimizedDrawing: YES];
5946 [fw setResizeIncrements: sz]; 5902 [fw setResizeIncrements: sz];
@@ -5950,18 +5906,26 @@ not_in_argv (NSString *arg)
5950 5906
5951 f->border_width = 0; 5907 f->border_width = 0;
5952 FRAME_NS_TITLEBAR_HEIGHT (f) = 0; 5908 FRAME_NS_TITLEBAR_HEIGHT (f) = 0;
5909 tobar_height = FRAME_TOOLBAR_HEIGHT (f);
5910 FRAME_TOOLBAR_HEIGHT (f) = 0;
5911 FRAME_EXTERNAL_TOOL_BAR (f) = 0;
5953 5912
5954 nonfs_window = w; 5913 nonfs_window = w;
5914
5955 [self windowWillEnterFullScreen:nil]; 5915 [self windowWillEnterFullScreen:nil];
5916 [fw makeKeyAndOrderFront:NSApp];
5917 [fw makeFirstResponder:self];
5956 [w orderOut:self]; 5918 [w orderOut:self];
5957 r = [fw frameRectForContentRect:[[fw screen] frame]]; 5919 r = [fw frameRectForContentRect:[[fw screen] frame]];
5958 [fw setFrame: r display:YES animate:YES]; 5920 [fw setFrame: r display:YES animate:YES];
5959 [self windowDidEnterFullScreen:nil]; 5921 [self windowDidEnterFullScreen:nil];
5922 [fw display];
5960 } 5923 }
5961 else 5924 else
5962 { 5925 {
5963 fw = w; 5926 fw = w;
5964 w = nonfs_window; 5927 w = nonfs_window;
5928 nonfs_window = nil;
5965 5929
5966 if (onFirstScreen) 5930 if (onFirstScreen)
5967 { 5931 {
@@ -5980,7 +5944,10 @@ not_in_argv (NSString *arg)
5980 [w setOpaque: NO]; 5944 [w setOpaque: NO];
5981 5945
5982 f->border_width = bwidth; 5946 f->border_width = bwidth;
5983 FRAME_NS_TITLEBAR_HEIGHT (f) = tbar_height; 5947 FRAME_NS_TITLEBAR_HEIGHT (f) = tibar_height;
5948 FRAME_TOOLBAR_HEIGHT (f) = tobar_height;
5949 if (tobar_height)
5950 FRAME_EXTERNAL_TOOL_BAR (f) = 1;
5984 5951
5985 [self windowWillExitFullScreen:nil]; 5952 [self windowWillExitFullScreen:nil];
5986 [fw setFrame: [w frame] display:YES animate:YES]; 5953 [fw setFrame: [w frame] display:YES animate:YES];
@@ -6152,7 +6119,7 @@ not_in_argv (NSString *arg)
6152 6119
6153 NSTRACE (drawRect); 6120 NSTRACE (drawRect);
6154 6121
6155 if (!emacsframe || !emacsframe->output_data.ns || ns_in_resize) 6122 if (!emacsframe || !emacsframe->output_data.ns)
6156 return; 6123 return;
6157 6124
6158 ns_clear_frame_area (emacsframe, x, y, width, height); 6125 ns_clear_frame_area (emacsframe, x, y, width, height);
@@ -6489,60 +6456,6 @@ not_in_argv (NSString *arg)
6489 return [super constrainFrameRect:frameRect toScreen:screen]; 6456 return [super constrainFrameRect:frameRect toScreen:screen];
6490} 6457}
6491 6458
6492
6493/* called only on resize clicks by special case in EmacsApp-sendEvent */
6494- (void)mouseDown: (NSEvent *)theEvent
6495{
6496 if (ns_in_resize)
6497 {
6498 NSSize size = [[theEvent window] frame].size;
6499 grabOffset = [theEvent locationInWindow];
6500 grabOffset.x = size.width - grabOffset.x;
6501 }
6502 else
6503 [super mouseDown: theEvent];
6504}
6505
6506
6507/* stop resizing */
6508- (void)mouseUp: (NSEvent *)theEvent
6509{
6510 if (ns_in_resize)
6511 {
6512 struct frame *f = ((EmacsView *)[self delegate])->emacsframe;
6513 ns_in_resize = NO;
6514 ns_set_name_as_filename (f);
6515 [self display];
6516 ns_send_appdefined (-1);
6517 }
6518 else
6519 [super mouseUp: theEvent];
6520}
6521
6522
6523/* send resize events */
6524- (void)mouseDragged: (NSEvent *)theEvent
6525{
6526 if (ns_in_resize)
6527 {
6528 NSPoint p = [theEvent locationInWindow];
6529 NSSize size, vettedSize, origSize = [self frame].size;
6530
6531 size.width = p.x + grabOffset.x;
6532 size.height = origSize.height - p.y + grabOffset.y;
6533
6534 if (size.width == origSize.width && size.height == origSize.height)
6535 return;
6536
6537 vettedSize = [[self delegate] windowWillResize: self toSize: size];
6538 [[NSNotificationCenter defaultCenter]
6539 postNotificationName: NSWindowDidResizeNotification
6540 object: self];
6541 }
6542 else
6543 [super mouseDragged: theEvent];
6544}
6545
6546@end /* EmacsWindow */ 6459@end /* EmacsWindow */
6547 6460
6548 6461
@@ -6553,6 +6466,11 @@ not_in_argv (NSString *arg)
6553 return YES; 6466 return YES;
6554} 6467}
6555 6468
6469- (BOOL)canBecomeMainWindow
6470{
6471 return YES;
6472}
6473
6556@end 6474@end
6557 6475
6558/* ========================================================================== 6476/* ==========================================================================
@@ -7168,7 +7086,7 @@ allowing it to be used at a lower level for accented character entry.");
7168 ns_function_modifier = Qnone; 7086 ns_function_modifier = Qnone;
7169 7087
7170 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text, 7088 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
7171 "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above."); 7089 "Non-nil (the default) means to render text antialiased.");
7172 ns_antialias_text = Qt; 7090 ns_antialias_text = Qt;
7173 7091
7174 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit, 7092 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,