summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nsfns.m32
-rw-r--r--src/nsterm.h31
-rw-r--r--src/nsterm.m104
3 files changed, 103 insertions, 64 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 00d4a7d2bd2..b71a3d7376d 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -1593,26 +1593,22 @@ Some window managers may refuse to restack windows. */)
}
}
-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 @@ Default is t. */);
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);
diff --git a/src/nsterm.h b/src/nsterm.h
index 5b121ede98f..9d8a6f486fc 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -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
diff --git a/src/nsterm.m b/src/nsterm.m
index 5d2e74ad56e..5e70e0d5665 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4442,10 +4442,10 @@ ns_read_socket (struct terminal *terminal, struct input_event *hold_quit)
}
-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 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
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 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
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 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
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 @@ not_in_argv (NSString *arg)
/* 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 @@ not_in_argv (NSString *arg)
return YES;
}
-
- (void)resetCursorRects
{
NSRect visible = [self visibleRect];