diff options
| author | Alan Third | 2021-06-05 12:39:46 +0100 |
|---|---|---|
| committer | Alan Third | 2021-07-24 16:35:46 +0100 |
| commit | d9fd86c24726599c4c4564ee6bcb8454c0d5065b (patch) | |
| tree | 21101431b65f0702955b5897e2e97e5bb4f28ffe | |
| parent | db055f95a1a171314601c0218a0cae22c9b30db1 (diff) | |
| download | emacs-d9fd86c24726599c4c4564ee6bcb8454c0d5065b.tar.gz emacs-d9fd86c24726599c4c4564ee6bcb8454c0d5065b.zip | |
Tidy up NS port OS window handling
* src/nsterm.h (EmacsWindow): Move above EmacsView definition and add
new method definitions.
(EmacsView): Remove redundant bwidth variable, and change NSWindow to
EmacsWindow.
(EmacsFSWindow): Delete definition.
* src/nsterm.m (ns_set_undecorated): Rewrite to work in GNUstep using
the new OS window creating methods.
([EmacsView initFrameFromEmacs:]): Move all NSWindow related code to
new init method in EmacsWindow, and use said method.
([EmacsView toggleFullScreen:]): Use EmacsWindow instead of NSWindow.
([EmacsWindow initWithEmacsFrame:]):
([EmacsWindow initWithEmacsFrame:fullscreen:screen:]):
([EmacsWindow borderWidth]): New methods.
(EmacsFSWindow): Remove implementation.
| -rw-r--r-- | src/nsfns.m | 4 | ||||
| -rw-r--r-- | src/nsterm.h | 42 | ||||
| -rw-r--r-- | src/nsterm.m | 319 |
3 files changed, 175 insertions, 190 deletions
diff --git a/src/nsfns.m b/src/nsfns.m index 454a6fdab62..c40367703db 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -947,11 +947,7 @@ frame_parm_handler ns_frame_parm_handlers[] = | |||
| 947 | 0, /* x_set_sticky */ | 947 | 0, /* x_set_sticky */ |
| 948 | 0, /* x_set_tool_bar_position */ | 948 | 0, /* x_set_tool_bar_position */ |
| 949 | 0, /* x_set_inhibit_double_buffering */ | 949 | 0, /* x_set_inhibit_double_buffering */ |
| 950 | #ifdef NS_IMPL_COCOA | ||
| 951 | ns_set_undecorated, | 950 | ns_set_undecorated, |
| 952 | #else | ||
| 953 | 0, /* ns_set_undecorated */ | ||
| 954 | #endif | ||
| 955 | ns_set_parent_frame, | 951 | ns_set_parent_frame, |
| 956 | 0, /* x_set_skip_taskbar */ | 952 | 0, /* x_set_skip_taskbar */ |
| 957 | ns_set_no_focus_on_map, | 953 | ns_set_no_focus_on_map, |
diff --git a/src/nsterm.h b/src/nsterm.h index 40fd543e479..b99bea7567a 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -406,6 +406,24 @@ typedef id instancetype; | |||
| 406 | @end | 406 | @end |
| 407 | #endif | 407 | #endif |
| 408 | 408 | ||
| 409 | /* EmacsWindow */ | ||
| 410 | @interface EmacsWindow : NSWindow | ||
| 411 | { | ||
| 412 | NSPoint grabOffset; | ||
| 413 | } | ||
| 414 | |||
| 415 | #ifdef NS_IMPL_GNUSTEP | ||
| 416 | - (NSInteger) orderedIndex; | ||
| 417 | #endif | ||
| 418 | |||
| 419 | - (instancetype)initWithEmacsFrame:(struct frame *)f; | ||
| 420 | - (instancetype)initWithEmacsFrame:(struct frame *)f fullscreen:(BOOL)fullscreen screen:(NSScreen *)screen; | ||
| 421 | - (NSInteger)borderWidth; | ||
| 422 | - (BOOL)restackWindow:(NSWindow *)win above:(BOOL)above; | ||
| 423 | - (void)setAppearance; | ||
| 424 | @end | ||
| 425 | |||
| 426 | |||
| 409 | /* ========================================================================== | 427 | /* ========================================================================== |
| 410 | 428 | ||
| 411 | The main Emacs view | 429 | The main Emacs view |
| @@ -429,9 +447,8 @@ typedef id instancetype; | |||
| 429 | NSString *workingText; | 447 | NSString *workingText; |
| 430 | BOOL processingCompose; | 448 | BOOL processingCompose; |
| 431 | int fs_state, fs_before_fs, next_maximized; | 449 | int fs_state, fs_before_fs, next_maximized; |
| 432 | int bwidth; | ||
| 433 | int maximized_width, maximized_height; | 450 | int maximized_width, maximized_height; |
| 434 | NSWindow *nonfs_window; | 451 | EmacsWindow *nonfs_window; |
| 435 | BOOL fs_is_native; | 452 | BOOL fs_is_native; |
| 436 | @public | 453 | @public |
| 437 | struct frame *emacsframe; | 454 | struct frame *emacsframe; |
| @@ -485,27 +502,6 @@ typedef id instancetype; | |||
| 485 | @end | 502 | @end |
| 486 | 503 | ||
| 487 | 504 | ||
| 488 | /* Small utility used for processing resize events under Cocoa. */ | ||
| 489 | @interface EmacsWindow : NSWindow | ||
| 490 | { | ||
| 491 | NSPoint grabOffset; | ||
| 492 | } | ||
| 493 | |||
| 494 | #ifdef NS_IMPL_GNUSTEP | ||
| 495 | - (NSInteger) orderedIndex; | ||
| 496 | #endif | ||
| 497 | |||
| 498 | - (BOOL)restackWindow:(NSWindow *)win above:(BOOL)above; | ||
| 499 | - (void)setAppearance; | ||
| 500 | @end | ||
| 501 | |||
| 502 | |||
| 503 | /* Fullscreen version of the above. */ | ||
| 504 | @interface EmacsFSWindow : EmacsWindow | ||
| 505 | { | ||
| 506 | } | ||
| 507 | @end | ||
| 508 | |||
| 509 | /* ========================================================================== | 505 | /* ========================================================================== |
| 510 | 506 | ||
| 511 | The main menu implementation | 507 | The main menu implementation |
diff --git a/src/nsterm.m b/src/nsterm.m index 0a7cd8c9ffa..16004608a1f 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -1743,7 +1743,6 @@ ns_set_window_size (struct frame *f, | |||
| 1743 | unblock_input (); | 1743 | unblock_input (); |
| 1744 | } | 1744 | } |
| 1745 | 1745 | ||
| 1746 | #ifdef NS_IMPL_COCOA | ||
| 1747 | void | 1746 | void |
| 1748 | ns_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) | 1747 | ns_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) |
| 1749 | /* -------------------------------------------------------------------------- | 1748 | /* -------------------------------------------------------------------------- |
| @@ -1753,45 +1752,37 @@ ns_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu | |||
| 1753 | dragged, resized, iconified, maximized or deleted with the mouse. If | 1752 | dragged, resized, iconified, maximized or deleted with the mouse. If |
| 1754 | nil, draw the frame with all the elements listed above unless these | 1753 | nil, draw the frame with all the elements listed above unless these |
| 1755 | have been suspended via window manager settings. | 1754 | have been suspended via window manager settings. |
| 1756 | |||
| 1757 | GNUStep cannot change an existing window's style. | ||
| 1758 | -------------------------------------------------------------------------- */ | 1755 | -------------------------------------------------------------------------- */ |
| 1759 | { | 1756 | { |
| 1760 | EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); | ||
| 1761 | NSWindow *window = [view window]; | ||
| 1762 | |||
| 1763 | NSTRACE ("ns_set_undecorated"); | 1757 | NSTRACE ("ns_set_undecorated"); |
| 1764 | 1758 | ||
| 1765 | if (!EQ (new_value, old_value)) | 1759 | if (!EQ (new_value, old_value)) |
| 1766 | { | 1760 | { |
| 1761 | EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); | ||
| 1762 | NSWindow *oldWindow = [view window]; | ||
| 1763 | NSWindow *newWindow; | ||
| 1764 | |||
| 1767 | block_input (); | 1765 | block_input (); |
| 1768 | 1766 | ||
| 1769 | if (NILP (new_value)) | 1767 | FRAME_UNDECORATED (f) = !NILP (new_value); |
| 1770 | { | ||
| 1771 | FRAME_UNDECORATED (f) = false; | ||
| 1772 | [window setStyleMask: ((window.styleMask | FRAME_DECORATED_FLAGS) | ||
| 1773 | ^ FRAME_UNDECORATED_FLAGS)]; | ||
| 1774 | 1768 | ||
| 1775 | [view createToolbar: f]; | 1769 | newWindow = [[EmacsWindow alloc] initWithEmacsFrame:f]; |
| 1776 | } | ||
| 1777 | else | ||
| 1778 | { | ||
| 1779 | [window setToolbar: nil]; | ||
| 1780 | /* Do I need to release the toolbar here? */ | ||
| 1781 | 1770 | ||
| 1782 | FRAME_UNDECORATED (f) = true; | 1771 | if (!FRAME_UNDECORATED (f)) |
| 1783 | [window setStyleMask: ((window.styleMask | FRAME_UNDECORATED_FLAGS) | 1772 | [view createToolbar: f]; |
| 1784 | ^ FRAME_DECORATED_FLAGS)]; | 1773 | |
| 1785 | } | 1774 | if ([oldWindow isKeyWindow]) |
| 1775 | [newWindow makeKeyAndOrderFront:NSApp]; | ||
| 1786 | 1776 | ||
| 1787 | /* At this point it seems we don't have an active NSResponder, | 1777 | [newWindow setIsVisible:[oldWindow isVisible]]; |
| 1788 | so some key presses (TAB) are swallowed by the system. */ | 1778 | if ([oldWindow isMiniaturized]) |
| 1789 | [window makeFirstResponder: view]; | 1779 | [newWindow miniaturize:NSApp]; |
| 1780 | |||
| 1781 | [oldWindow close]; | ||
| 1790 | 1782 | ||
| 1791 | unblock_input (); | 1783 | unblock_input (); |
| 1792 | } | 1784 | } |
| 1793 | } | 1785 | } |
| 1794 | #endif /* NS_IMPL_COCOA */ | ||
| 1795 | 1786 | ||
| 1796 | void | 1787 | void |
| 1797 | ns_set_parent_frame (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) | 1788 | ns_set_parent_frame (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) |
| @@ -7259,12 +7250,6 @@ not_in_argv (NSString *arg) | |||
| 7259 | 7250 | ||
| 7260 | - (instancetype) initFrameFromEmacs: (struct frame *)f | 7251 | - (instancetype) initFrameFromEmacs: (struct frame *)f |
| 7261 | { | 7252 | { |
| 7262 | NSRect r, wr; | ||
| 7263 | Lisp_Object tem; | ||
| 7264 | EmacsWindow *win; | ||
| 7265 | NSColor *col; | ||
| 7266 | NSString *name; | ||
| 7267 | |||
| 7268 | NSTRACE ("[EmacsView initFrameFromEmacs:]"); | 7253 | NSTRACE ("[EmacsView initFrameFromEmacs:]"); |
| 7269 | NSTRACE_MSG ("cols:%d lines:%d", f->text_cols, f->text_lines); | 7254 | NSTRACE_MSG ("cols:%d lines:%d", f->text_cols, f->text_lines); |
| 7270 | 7255 | ||
| @@ -7286,9 +7271,9 @@ not_in_argv (NSString *arg) | |||
| 7286 | nonfs_window = nil; | 7271 | nonfs_window = nil; |
| 7287 | 7272 | ||
| 7288 | ns_userRect = NSMakeRect (0, 0, 0, 0); | 7273 | ns_userRect = NSMakeRect (0, 0, 0, 0); |
| 7289 | r = NSMakeRect (0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, f->text_cols), | 7274 | [self initWithFrame: |
| 7290 | FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, f->text_lines)); | 7275 | NSMakeRect (0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, f->text_cols), |
| 7291 | [self initWithFrame: r]; | 7276 | FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, f->text_lines))]; |
| 7292 | [self setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; | 7277 | [self setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; |
| 7293 | 7278 | ||
| 7294 | FRAME_NS_VIEW (f) = self; | 7279 | FRAME_NS_VIEW (f) = self; |
| @@ -7298,37 +7283,7 @@ not_in_argv (NSString *arg) | |||
| 7298 | maximizing_resize = NO; | 7283 | maximizing_resize = NO; |
| 7299 | #endif | 7284 | #endif |
| 7300 | 7285 | ||
| 7301 | win = [[EmacsWindow alloc] | 7286 | [[EmacsWindow alloc] initWithEmacsFrame:f]; |
| 7302 | initWithContentRect: r | ||
| 7303 | styleMask: (FRAME_UNDECORATED (f) | ||
| 7304 | ? FRAME_UNDECORATED_FLAGS | ||
| 7305 | : FRAME_DECORATED_FLAGS) | ||
| 7306 | backing: NSBackingStoreBuffered | ||
| 7307 | defer: YES]; | ||
| 7308 | |||
| 7309 | #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 | ||
| 7310 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 | ||
| 7311 | if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) | ||
| 7312 | #endif | ||
| 7313 | if (FRAME_PARENT_FRAME (f)) | ||
| 7314 | [win setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary]; | ||
| 7315 | else | ||
| 7316 | [win setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; | ||
| 7317 | #endif | ||
| 7318 | |||
| 7319 | wr = [win frame]; | ||
| 7320 | bwidth = f->border_width = wr.size.width - r.size.width; | ||
| 7321 | |||
| 7322 | [win setAcceptsMouseMovedEvents: YES]; | ||
| 7323 | [win setDelegate: self]; | ||
| 7324 | #if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 | ||
| 7325 | #if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 | ||
| 7326 | if ([win respondsToSelector: @selector(useOptimizedDrawing:)]) | ||
| 7327 | #endif | ||
| 7328 | [win useOptimizedDrawing: YES]; | ||
| 7329 | #endif | ||
| 7330 | |||
| 7331 | [[win contentView] addSubview: self]; | ||
| 7332 | 7287 | ||
| 7333 | #ifdef NS_IMPL_COCOA | 7288 | #ifdef NS_IMPL_COCOA |
| 7334 | /* These settings mean AppKit will retain the contents of the frame | 7289 | /* These settings mean AppKit will retain the contents of the frame |
| @@ -7344,65 +7299,10 @@ not_in_argv (NSString *arg) | |||
| 7344 | if (ns_drag_types) | 7299 | if (ns_drag_types) |
| 7345 | [self registerForDraggedTypes: ns_drag_types]; | 7300 | [self registerForDraggedTypes: ns_drag_types]; |
| 7346 | 7301 | ||
| 7347 | tem = f->name; | ||
| 7348 | name = NILP (tem) ? @"Emacs" : [NSString stringWithLispString:tem]; | ||
| 7349 | [win setTitle: name]; | ||
| 7350 | |||
| 7351 | /* toolbar support */ | 7302 | /* toolbar support */ |
| 7352 | if (! FRAME_UNDECORATED (f)) | 7303 | if (! FRAME_UNDECORATED (f)) |
| 7353 | [self createToolbar: f]; | 7304 | [self createToolbar: f]; |
| 7354 | 7305 | ||
| 7355 | |||
| 7356 | [win setAppearance]; | ||
| 7357 | |||
| 7358 | #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 | ||
| 7359 | if ([win respondsToSelector: @selector(titlebarAppearsTransparent)]) | ||
| 7360 | win.titlebarAppearsTransparent = FRAME_NS_TRANSPARENT_TITLEBAR (f); | ||
| 7361 | #endif | ||
| 7362 | |||
| 7363 | tem = f->icon_name; | ||
| 7364 | if (!NILP (tem)) | ||
| 7365 | [win setMiniwindowTitle: | ||
| 7366 | [NSString stringWithLispString:tem]]; | ||
| 7367 | |||
| 7368 | if (FRAME_PARENT_FRAME (f) != NULL) | ||
| 7369 | { | ||
| 7370 | NSWindow *parent = [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window]; | ||
| 7371 | [parent addChildWindow: win | ||
| 7372 | ordered: NSWindowAbove]; | ||
| 7373 | } | ||
| 7374 | |||
| 7375 | if (FRAME_Z_GROUP (f) != z_group_none) | ||
| 7376 | win.level = NSNormalWindowLevel | ||
| 7377 | + (FRAME_Z_GROUP_BELOW (f) ? -1 : 1); | ||
| 7378 | |||
| 7379 | { | ||
| 7380 | NSScreen *screen = [win screen]; | ||
| 7381 | |||
| 7382 | if (screen != 0) | ||
| 7383 | { | ||
| 7384 | NSPoint pt = NSMakePoint | ||
| 7385 | (IN_BOUND (-SCREENMAX, f->left_pos | ||
| 7386 | + NS_PARENT_WINDOW_LEFT_POS (f), SCREENMAX), | ||
| 7387 | IN_BOUND (-SCREENMAX, | ||
| 7388 | NS_PARENT_WINDOW_TOP_POS (f) - f->top_pos, | ||
| 7389 | SCREENMAX)); | ||
| 7390 | |||
| 7391 | [win setFrameTopLeftPoint: pt]; | ||
| 7392 | |||
| 7393 | NSTRACE_RECT ("new frame", [win frame]); | ||
| 7394 | } | ||
| 7395 | } | ||
| 7396 | |||
| 7397 | [win makeFirstResponder: self]; | ||
| 7398 | |||
| 7399 | col = ns_lookup_indexed_color (NS_FACE_BACKGROUND | ||
| 7400 | (FACE_FROM_ID (emacsframe, DEFAULT_FACE_ID)), | ||
| 7401 | emacsframe); | ||
| 7402 | [win setBackgroundColor: col]; | ||
| 7403 | if ([col alphaComponent] != (EmacsCGFloat) 1.0) | ||
| 7404 | [win setOpaque: NO]; | ||
| 7405 | |||
| 7406 | #if !defined (NS_IMPL_COCOA) \ | 7306 | #if !defined (NS_IMPL_COCOA) \ |
| 7407 | || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 | 7307 | || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 |
| 7408 | #if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 | 7308 | #if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 |
| @@ -7420,14 +7320,6 @@ not_in_argv (NSString *arg) | |||
| 7420 | selector:@selector (viewDidResize:) | 7320 | selector:@selector (viewDidResize:) |
| 7421 | name:NSViewFrameDidChangeNotification object:nil]; | 7321 | name:NSViewFrameDidChangeNotification object:nil]; |
| 7422 | 7322 | ||
| 7423 | /* macOS Sierra automatically enables tabbed windows. We can't | ||
| 7424 | allow this to be enabled until it's available on a Free system. | ||
| 7425 | Currently it only happens by accident and is buggy anyway. */ | ||
| 7426 | #ifdef NS_IMPL_COCOA | ||
| 7427 | if ([win respondsToSelector: @selector(setTabbingMode:)]) | ||
| 7428 | [win setTabbingMode: NSWindowTabbingModeDisallowed]; | ||
| 7429 | #endif | ||
| 7430 | |||
| 7431 | ns_window_num++; | 7323 | ns_window_num++; |
| 7432 | return self; | 7324 | return self; |
| 7433 | } | 7325 | } |
| @@ -7817,7 +7709,7 @@ not_in_argv (NSString *arg) | |||
| 7817 | 7709 | ||
| 7818 | - (void)toggleFullScreen: (id)sender | 7710 | - (void)toggleFullScreen: (id)sender |
| 7819 | { | 7711 | { |
| 7820 | NSWindow *w, *fw; | 7712 | EmacsWindow *w, *fw; |
| 7821 | BOOL onFirstScreen; | 7713 | BOOL onFirstScreen; |
| 7822 | struct frame *f; | 7714 | struct frame *f; |
| 7823 | NSRect r, wr; | 7715 | NSRect r, wr; |
| @@ -7836,7 +7728,7 @@ not_in_argv (NSString *arg) | |||
| 7836 | return; | 7728 | return; |
| 7837 | } | 7729 | } |
| 7838 | 7730 | ||
| 7839 | w = [self window]; | 7731 | w = (EmacsWindow *)[self window]; |
| 7840 | onFirstScreen = [[w screen] isEqual:[[NSScreen screens] objectAtIndex:0]]; | 7732 | onFirstScreen = [[w screen] isEqual:[[NSScreen screens] objectAtIndex:0]]; |
| 7841 | f = emacsframe; | 7733 | f = emacsframe; |
| 7842 | wr = [w frame]; | 7734 | wr = [w frame]; |
| @@ -7871,27 +7763,9 @@ not_in_argv (NSString *arg) | |||
| 7871 | #endif | 7763 | #endif |
| 7872 | } | 7764 | } |
| 7873 | 7765 | ||
| 7874 | fw = [[EmacsFSWindow alloc] | 7766 | fw = [[EmacsWindow alloc] initWithEmacsFrame:emacsframe |
| 7875 | initWithContentRect:[w contentRectForFrameRect:wr] | 7767 | fullscreen:YES |
| 7876 | styleMask:NSWindowStyleMaskBorderless | 7768 | screen:screen]; |
| 7877 | backing:NSBackingStoreBuffered | ||
| 7878 | defer:YES | ||
| 7879 | screen:screen]; | ||
| 7880 | |||
| 7881 | [fw setContentView:[w contentView]]; | ||
| 7882 | [fw setTitle:[w title]]; | ||
| 7883 | [fw setDelegate:self]; | ||
| 7884 | [fw setAcceptsMouseMovedEvents: YES]; | ||
| 7885 | #if !defined (NS_IMPL_COCOA) \ | ||
| 7886 | || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 | ||
| 7887 | #if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 | ||
| 7888 | if ([fw respondsToSelector: @selector(useOptimizedDrawing:)]) | ||
| 7889 | #endif | ||
| 7890 | [fw useOptimizedDrawing: YES]; | ||
| 7891 | #endif | ||
| 7892 | [fw setBackgroundColor: col]; | ||
| 7893 | if ([col alphaComponent] != (EmacsCGFloat) 1.0) | ||
| 7894 | [fw setOpaque: NO]; | ||
| 7895 | 7769 | ||
| 7896 | f->border_width = 0; | 7770 | f->border_width = 0; |
| 7897 | 7771 | ||
| @@ -7899,7 +7773,6 @@ not_in_argv (NSString *arg) | |||
| 7899 | 7773 | ||
| 7900 | [self windowWillEnterFullScreen]; | 7774 | [self windowWillEnterFullScreen]; |
| 7901 | [fw makeKeyAndOrderFront:NSApp]; | 7775 | [fw makeKeyAndOrderFront:NSApp]; |
| 7902 | [fw makeFirstResponder:self]; | ||
| 7903 | [w orderOut:self]; | 7776 | [w orderOut:self]; |
| 7904 | r = [fw frameRectForContentRect:[screen frame]]; | 7777 | r = [fw frameRectForContentRect:[screen frame]]; |
| 7905 | [fw setFrame: r display:YES animate:ns_use_fullscreen_animation]; | 7778 | [fw setFrame: r display:YES animate:ns_use_fullscreen_animation]; |
| @@ -7926,7 +7799,7 @@ not_in_argv (NSString *arg) | |||
| 7926 | if ([col alphaComponent] != (EmacsCGFloat) 1.0) | 7799 | if ([col alphaComponent] != (EmacsCGFloat) 1.0) |
| 7927 | [w setOpaque: NO]; | 7800 | [w setOpaque: NO]; |
| 7928 | 7801 | ||
| 7929 | f->border_width = bwidth; | 7802 | f->border_width = [w borderWidth]; |
| 7930 | 7803 | ||
| 7931 | // To do: consider using [NSNotificationCenter postNotificationName:] to | 7804 | // To do: consider using [NSNotificationCenter postNotificationName:] to |
| 7932 | // send notifications. | 7805 | // send notifications. |
| @@ -8503,6 +8376,133 @@ not_in_argv (NSString *arg) | |||
| 8503 | 8376 | ||
| 8504 | @implementation EmacsWindow | 8377 | @implementation EmacsWindow |
| 8505 | 8378 | ||
| 8379 | |||
| 8380 | - (instancetype) initWithEmacsFrame:(struct frame *)f | ||
| 8381 | { | ||
| 8382 | return [self initWithEmacsFrame:f fullscreen:NO screen:nil]; | ||
| 8383 | } | ||
| 8384 | |||
| 8385 | |||
| 8386 | - (instancetype) initWithEmacsFrame:(struct frame *)f | ||
| 8387 | fullscreen:(BOOL)fullscreen | ||
| 8388 | screen:(NSScreen *)screen | ||
| 8389 | { | ||
| 8390 | NSWindowStyleMask styleMask; | ||
| 8391 | |||
| 8392 | NSTRACE ("[EmacsWindow initWithEmacsFrame:fullscreen:screen:]"); | ||
| 8393 | |||
| 8394 | if (fullscreen) | ||
| 8395 | styleMask = NSWindowStyleMaskBorderless; | ||
| 8396 | else if (FRAME_UNDECORATED (f)) | ||
| 8397 | styleMask = FRAME_UNDECORATED_FLAGS; | ||
| 8398 | else | ||
| 8399 | styleMask = FRAME_DECORATED_FLAGS; | ||
| 8400 | |||
| 8401 | |||
| 8402 | self = [super initWithContentRect: | ||
| 8403 | NSMakeRect (0, 0, | ||
| 8404 | FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, f->text_cols), | ||
| 8405 | FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, f->text_lines)) | ||
| 8406 | styleMask:styleMask | ||
| 8407 | backing:NSBackingStoreBuffered | ||
| 8408 | defer:YES | ||
| 8409 | screen:screen]; | ||
| 8410 | if (self) | ||
| 8411 | { | ||
| 8412 | NSString *name; | ||
| 8413 | NSColor *col; | ||
| 8414 | NSScreen *screen = [self screen]; | ||
| 8415 | EmacsView *view = FRAME_NS_VIEW (f); | ||
| 8416 | |||
| 8417 | [self setDelegate:view]; | ||
| 8418 | [[self contentView] addSubview:view]; | ||
| 8419 | [self makeFirstResponder:view]; | ||
| 8420 | |||
| 8421 | #if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 | ||
| 8422 | #if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 | ||
| 8423 | if ([self respondsToSelector: @selector(useOptimizedDrawing:)]) | ||
| 8424 | #endif | ||
| 8425 | [self useOptimizedDrawing:YES]; | ||
| 8426 | #endif | ||
| 8427 | |||
| 8428 | [self setAcceptsMouseMovedEvents:YES]; | ||
| 8429 | |||
| 8430 | name = NILP (f->name) ? @"Emacs" : [NSString stringWithLispString:f->name]; | ||
| 8431 | [self setTitle:name]; | ||
| 8432 | |||
| 8433 | if (!NILP (f->icon_name)) | ||
| 8434 | [self setMiniwindowTitle: | ||
| 8435 | [NSString stringWithLispString:f->icon_name]]; | ||
| 8436 | |||
| 8437 | [self setAppearance]; | ||
| 8438 | |||
| 8439 | #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 | ||
| 8440 | if ([self respondsToSelector:@selector(titlebarAppearsTransparent)]) | ||
| 8441 | [self setTitlebarAppearsTransparent:FRAME_NS_TRANSPARENT_TITLEBAR (f)]; | ||
| 8442 | #endif | ||
| 8443 | |||
| 8444 | #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 | ||
| 8445 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 | ||
| 8446 | if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) | ||
| 8447 | #endif | ||
| 8448 | if (FRAME_PARENT_FRAME (f)) | ||
| 8449 | [self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary]; | ||
| 8450 | else | ||
| 8451 | [self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; | ||
| 8452 | #endif | ||
| 8453 | |||
| 8454 | if (FRAME_PARENT_FRAME (f) != NULL) | ||
| 8455 | { | ||
| 8456 | NSWindow *parent = [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window]; | ||
| 8457 | [parent addChildWindow:self | ||
| 8458 | ordered:NSWindowAbove]; | ||
| 8459 | } | ||
| 8460 | |||
| 8461 | if (FRAME_Z_GROUP (f) != z_group_none) | ||
| 8462 | [self setLevel:NSNormalWindowLevel + (FRAME_Z_GROUP_BELOW (f) ? -1 : 1)]; | ||
| 8463 | |||
| 8464 | if (screen != 0) | ||
| 8465 | { | ||
| 8466 | NSPoint pt = NSMakePoint | ||
| 8467 | (IN_BOUND (-SCREENMAX, f->left_pos | ||
| 8468 | + NS_PARENT_WINDOW_LEFT_POS (f), SCREENMAX), | ||
| 8469 | IN_BOUND (-SCREENMAX, | ||
| 8470 | NS_PARENT_WINDOW_TOP_POS (f) - f->top_pos, | ||
| 8471 | SCREENMAX)); | ||
| 8472 | |||
| 8473 | [self setFrameTopLeftPoint:pt]; | ||
| 8474 | |||
| 8475 | NSTRACE_RECT ("new frame", [self frame]); | ||
| 8476 | } | ||
| 8477 | |||
| 8478 | f->border_width = [self borderWidth]; | ||
| 8479 | |||
| 8480 | col = ns_lookup_indexed_color (NS_FACE_BACKGROUND | ||
| 8481 | (FACE_FROM_ID (f, DEFAULT_FACE_ID)), | ||
| 8482 | f); | ||
| 8483 | [self setBackgroundColor:col]; | ||
| 8484 | if ([col alphaComponent] != (EmacsCGFloat) 1.0) | ||
| 8485 | [self setOpaque:NO]; | ||
| 8486 | |||
| 8487 | /* macOS Sierra automatically enables tabbed windows. We can't | ||
| 8488 | allow this to be enabled until it's available on a Free system. | ||
| 8489 | Currently it only happens by accident and is buggy anyway. */ | ||
| 8490 | #ifdef NS_IMPL_COCOA | ||
| 8491 | if ([self respondsToSelector:@selector(setTabbingMode:)]) | ||
| 8492 | [self setTabbingMode:NSWindowTabbingModeDisallowed]; | ||
| 8493 | #endif | ||
| 8494 | } | ||
| 8495 | |||
| 8496 | return self; | ||
| 8497 | } | ||
| 8498 | |||
| 8499 | |||
| 8500 | - (NSInteger) borderWidth | ||
| 8501 | { | ||
| 8502 | return NSWidth ([self frame]) - NSWidth ([[self contentView] frame]); | ||
| 8503 | } | ||
| 8504 | |||
| 8505 | |||
| 8506 | /* It seems the only way to reorder child frames is by removing them | 8506 | /* It seems the only way to reorder child frames is by removing them |
| 8507 | from the parent and then reattaching them in the correct order. */ | 8507 | from the parent and then reattaching them in the correct order. */ |
| 8508 | 8508 | ||
| @@ -8912,22 +8912,15 @@ nswindow_orderedIndex_sort (id w1, id w2, void *c) | |||
| 8912 | { | 8912 | { |
| 8913 | return !FRAME_NO_ACCEPT_FOCUS (((EmacsView *)[self delegate])->emacsframe); | 8913 | return !FRAME_NO_ACCEPT_FOCUS (((EmacsView *)[self delegate])->emacsframe); |
| 8914 | } | 8914 | } |
| 8915 | @end /* EmacsWindow */ | ||
| 8916 | |||
| 8917 | |||
| 8918 | @implementation EmacsFSWindow | ||
| 8919 | |||
| 8920 | - (BOOL)canBecomeKeyWindow | ||
| 8921 | { | ||
| 8922 | return YES; | ||
| 8923 | } | ||
| 8924 | 8915 | ||
| 8925 | - (BOOL)canBecomeMainWindow | 8916 | - (BOOL)canBecomeMainWindow |
| 8917 | /* Required for fullscreen and undecorated windows. */ | ||
| 8926 | { | 8918 | { |
| 8927 | return YES; | 8919 | return YES; |
| 8928 | } | 8920 | } |
| 8929 | 8921 | ||
| 8930 | @end | 8922 | @end /* EmacsWindow */ |
| 8923 | |||
| 8931 | 8924 | ||
| 8932 | /* ========================================================================== | 8925 | /* ========================================================================== |
| 8933 | 8926 | ||