1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-22 18:35:09 +00:00

Replace NS code that implemented font panels in a different way

* doc/emacs/macos.texi (Mac / GNUstep Events): Document removal
of `ns-change-font' event.  The font panels are now implemented
normally, via `x-select-font'.

* lisp/term/common-win.el (x-setup-function-keys): Likewise.

* lisp/term/ns-win.el (global-map, ns-popup-font-panel): Remove.
(x-select-font, mouse-set-font, ns-input-font):
(ns-input-fontsize): Remove.
(ns-respond-to-change-font): Delete function.

* src/nsfns.m (Fns_popup_font_panel): Delete function.
(Fx_select_font): New function.
(syms_of_nsfns): Update subrs.
* src/nsterm.h (@interface EmacsView):
* src/nsterm.m (ns_select_1): New function.
(ns_select): Wrap around that instead.
([EmacsView changeFont:]): Exit nested event loop
([EmacsView showFontPanel:]): New function.
This commit is contained in:
Po Lu 2022-05-01 21:39:33 +08:00
parent 7c8bec9e1f
commit 9370a4763a
6 changed files with 103 additions and 102 deletions

View File

@ -273,14 +273,6 @@ application is overriding the default behavior.
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.

View File

@ -65,7 +65,6 @@
(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)

View File

@ -176,7 +176,6 @@ The properties returned may include `top', `left', `height', and `width'."
(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)
@ -623,34 +622,6 @@ If FRAME is nil, the change applies to the selected 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

View File

@ -1593,26 +1593,22 @@ Frames are listed from topmost (first) to bottommost (last). */)
}
}
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, "",
@ -3299,7 +3295,7 @@ - (Lisp_Object)lispString
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);

View File

@ -442,23 +442,25 @@ typedef id instancetype;
#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;
@ -485,6 +487,7 @@ typedef id instancetype;
#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

View File

@ -4442,10 +4442,10 @@ in certain situations (rapid incoming events).
}
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
-------------------------------------------------------------------------- */
@ -4461,7 +4461,7 @@ in certain situations (rapid incoming 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);
@ -4479,12 +4479,12 @@ in certain situations (rapid incoming events).
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
@ -4602,6 +4602,15 @@ in certain situations (rapid incoming events).
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)
@ -6082,40 +6091,72 @@ - (void)dealloc
/* 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
{
@ -6123,7 +6164,6 @@ - (BOOL)acceptsFirstResponder
return YES;
}
- (void)resetCursorRects
{
NSRect visible = [self visibleRect];