The modifier keys listed above are defined by macOS and are unaffected
by user changes to the modifiers in Emacs.
-@item ns-change-font
-This event occurs when the user selects a font in a Nextstep font
-panel (which can be opened with @kbd{Cmd-t}). The default behavior is
-to adjust the font of the selected frame
-(@code{ns-respond-to-changefont}). The name and size of the selected
-font are stored in the variables @code{ns-input-font} and
-@code{ns-input-fontsize}, respectively.
-
@item ns-power-off
This event occurs when the user logs out and Emacs is still running, or when
``Quit Emacs'' is chosen from the application menu.
(cons 4 'ns-drag-file)
(cons 5 'ns-drag-color)
(cons 6 'ns-drag-text)
- (cons 7 'ns-change-font)
(cons 8 'ns-open-file-line)
;;; (cons 9 'ns-insert-working-text)
;;; (cons 10 'ns-delete-working-text)
(define-key global-map [ns-power-off] 'save-buffers-kill-emacs)
(define-key global-map [ns-open-file] 'ns-find-file)
(define-key global-map [ns-open-temp-file] [ns-open-file])
-(define-key global-map [ns-change-font] 'ns-respond-to-change-font)
(define-key global-map [ns-open-file-line] 'ns-open-file-select-line)
(define-key global-map [ns-spi-service-call] 'ns-spi-service-call)
(define-key global-map [ns-new-frame] 'make-frame)
;; Needed for font listing functions under both backend and normal
(setq scalable-fonts-allowed t)
-;; Set to use font panel instead
-(declare-function ns-popup-font-panel "nsfns.m" (&optional frame))
-(defalias 'x-select-font 'ns-popup-font-panel "Pop up the font panel.
-This function has been overloaded in Nextstep.")
-(defalias 'mouse-set-font 'ns-popup-font-panel "Pop up the font panel.
-This function has been overloaded in Nextstep.")
-
-;; nsterm.m
-(defvar ns-input-font)
-(defvar ns-input-fontsize)
-
-(defun ns-respond-to-change-font ()
- "Set the font chosen in the font-picker panel.
-Respond to changeFont: event, expecting ns-input-font and
-ns-input-fontsize of new font."
- (interactive)
- (let ((face 'default))
- (set-face-attribute face t
- :family ns-input-font
- :height (* 10 ns-input-fontsize))
- (set-face-attribute face (selected-frame)
- :family ns-input-font
- :height (* 10 ns-input-fontsize))
- (let ((spec (list (list t (face-attr-construct 'default)))))
- (put face 'customized-face spec)
- (custom-push-theme 'theme-face face 'user 'set spec)
- (put face 'face-modified nil))))
-
;; Default fontset for macOS. This is mainly here to show how a fontset
;; can be set up manually. Ordinarily, fontsets are auto-created whenever
;; a font is chosen by
}
}
-DEFUN ("ns-popup-font-panel", Fns_popup_font_panel, Sns_popup_font_panel,
- 0, 1, "",
- doc: /* Pop up the font panel. */)
- (Lisp_Object frame)
+DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0,
+ doc: /* Read a font using a Nextstep dialog.
+Return a string describing the selected font.
+
+FRAME is the frame on which to pop up the font chooser. If omitted or
+nil, it defaults to the selected frame. */)
+ (Lisp_Object frame, Lisp_Object ignored)
{
struct frame *f = decode_window_system_frame (frame);
- id fm = [NSFontManager sharedFontManager];
- struct font *font = f->output_data.ns->font;
- NSFont *nsfont;
-#ifdef NS_IMPL_GNUSTEP
- nsfont = ((struct nsfont_info *)font)->nsfont;
-#endif
-#ifdef NS_IMPL_COCOA
- nsfont = (NSFont *) macfont_get_nsctfont (font);
-#endif
- [fm setSelectedFont: nsfont isMultiple: NO];
- [fm orderFrontFontPanel: NSApp];
- return Qnil;
-}
+ Lisp_Object font = [FRAME_NS_VIEW (f) showFontPanel];
+ if (NILP (font))
+ quit ();
+
+ return font;
+}
DEFUN ("ns-popup-color-panel", Fns_popup_color_panel, Sns_popup_color_panel,
0, 1, "",
defsubr (&Sns_emacs_info_panel);
defsubr (&Sns_list_services);
defsubr (&Sns_perform_service);
- defsubr (&Sns_popup_font_panel);
+ defsubr (&Sx_select_font);
defsubr (&Sns_popup_color_panel);
defsubr (&Sx_show_tip);
#else
@interface EmacsView : NSView <NSTextInput>
#endif
- {
+{
#ifdef NS_IMPL_COCOA
- char *old_title;
- BOOL maximizing_resize;
+ char *old_title;
+ BOOL maximizing_resize;
#endif
- BOOL windowClosing;
- NSString *workingText;
- BOOL processingCompose;
- int fs_state, fs_before_fs, next_maximized;
- int maximized_width, maximized_height;
- EmacsWindow *nonfs_window;
- BOOL fs_is_native;
+ BOOL font_panel_active;
+ NSFont *font_panel_result;
+ BOOL windowClosing;
+ NSString *workingText;
+ BOOL processingCompose;
+ int fs_state, fs_before_fs, next_maximized;
+ int maximized_width, maximized_height;
+ EmacsWindow *nonfs_window;
+ BOOL fs_is_native;
@public
- struct frame *emacsframe;
- int scrollbarsNeedingUpdate;
- NSRect ns_userRect;
- }
+ struct frame *emacsframe;
+ int scrollbarsNeedingUpdate;
+ NSRect ns_userRect;
+}
/* AppKit-side interface */
- (instancetype)menuDown: (id)sender;
#ifdef NS_IMPL_GNUSTEP
- (void)windowDidMove: (id)sender;
#endif
+- (Lisp_Object) showFontPanel;
- (int)fullscreenState;
#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
}
-int
-ns_select (int nfds, fd_set *readfds, fd_set *writefds,
- fd_set *exceptfds, struct timespec *timeout,
- sigset_t *sigmask)
+static int
+ns_select_1 (int nfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timespec *timeout,
+ sigset_t *sigmask, BOOL run_loop_only)
/* --------------------------------------------------------------------------
Replacement for select, checking for events
-------------------------------------------------------------------------- */
check_native_fs ();
#endif
- if (hold_event_q.nr > 0)
+ if (hold_event_q.nr > 0 && !run_loop_only)
{
/* We already have events pending. */
raise (SIGIO);
if (NSApp == nil
|| ![NSThread isMainThread]
|| (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0))
- return thread_select(pselect, nfds, readfds, writefds,
- exceptfds, timeout, sigmask);
+ return thread_select (pselect, nfds, readfds, writefds,
+ exceptfds, timeout, sigmask);
else
{
struct timespec t = {0, 0};
- thread_select(pselect, 0, NULL, NULL, NULL, &t, sigmask);
+ thread_select (pselect, 0, NULL, NULL, NULL, &t, sigmask);
}
/* FIXME: This draining of outerpool causes a crash when a buffer
return result;
}
+int
+ns_select (int nfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timespec *timeout,
+ sigset_t *sigmask)
+{
+ return ns_select_1 (nfds, readfds, writefds, exceptfds,
+ timeout, sigmask, NO);
+}
+
#ifdef HAVE_PTHREAD
void
ns_run_loop_break (void)
/* Called on font panel selection. */
-- (void)changeFont: (id)sender
+- (void) changeFont: (id) sender
{
- struct face *face = FACE_FROM_ID (emacsframe, DEFAULT_FACE_ID);
- struct font *font = face->font;
- id newFont;
- CGFloat size;
+ struct font *font = FRAME_OUTPUT_DATA (emacsframe)->font;
NSFont *nsfont;
- struct input_event ie;
-
- NSTRACE ("[EmacsView changeFont:]");
- EVENT_INIT (ie);
#ifdef NS_IMPL_GNUSTEP
- nsfont = ((struct nsfont_info *)font)->nsfont;
-#endif
-#ifdef NS_IMPL_COCOA
+ nsfont = ((struct nsfont_info *) font)->nsfont;
+#else
nsfont = (NSFont *) macfont_get_nsctfont (font);
#endif
- if ((newFont = [sender convertFont: nsfont]))
- {
- ie.kind = NS_NONKEY_EVENT;
- ie.modifiers = 0;
- ie.code = KEY_NS_CHANGE_FONT;
- XSETFRAME (ie.frame_or_window, emacsframe);
+ if (!font_panel_active)
+ return;
- size = [newFont pointSize];
- ns_input_fontsize = make_fixnum (lrint (size));
- ns_input_font = [[newFont familyName] lispString];
+ if (font_panel_result)
+ [font_panel_result release];
- kbd_buffer_store_event (&ie);
- }
+ font_panel_result = (NSFont *) [sender convertFont: nsfont];
+
+ if (font_panel_result)
+ [font_panel_result retain];
+
+ font_panel_active = NO;
+ [NSApp stop: self];
}
+- (Lisp_Object) showFontPanel
+{
+ id fm = [NSFontManager sharedFontManager];
+ struct font *font = FRAME_OUTPUT_DATA (emacsframe)->font;
+ NSFont *nsfont, *result;
+ struct timespec timeout;
+
+#ifdef NS_IMPL_GNUSTEP
+ nsfont = ((struct nsfont_info *) font)->nsfont;
+#else
+ nsfont = (NSFont *) macfont_get_nsctfont (font);
+#endif
+
+ [fm setSelectedFont: nsfont isMultiple: NO];
+ [fm orderFrontFontPanel: NSApp];
+
+ font_panel_active = YES;
+ timeout = make_timespec (0, 100000000);
+
+ block_input ();
+ while (font_panel_active
+ && [[fm fontPanel: YES] isVisible])
+ ns_select_1 (0, NULL, NULL, NULL, &timeout, NULL, YES);
+ unblock_input ();
+
+ if (font_panel_result)
+ [font_panel_result autorelease];
+
+ result = font_panel_result;
+ font_panel_result = nil;
+
+ [[fm fontPanel: YES] setIsVisible: NO];
+ font_panel_active = NO;
+
+ /* TODO: return a font spec instead of a string. */
+ if (result)
+ return [[result familyName] lispString];
+
+ return Qnil;
+}
- (BOOL)acceptsFirstResponder
{
return YES;
}
-
- (void)resetCursorRects
{
NSRect visible = [self visibleRect];