aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStéphane Marks2026-02-11 10:10:36 -0500
committerAlan Third2026-02-12 16:55:27 +0000
commitadf6c7bcbe989871b20c794b3f528aa348bc0c60 (patch)
treec9953c7b963f170502086572d7c77fcd02e80bed /src
parentc091ff00ec45821b911a8fd83c4b672b9a6e4feb (diff)
downloademacs-adf6c7bcbe989871b20c794b3f528aa348bc0c60.tar.gz
emacs-adf6c7bcbe989871b20c794b3f528aa348bc0c60.zip
Move ns_init_colors from ns_term_init to emacs.c (bug#80377)
Accommodate NS Emacs on a headless system. Add error checking for failed calls to NSColorList writeToURL and writeToFile. * src/nsterm.m (ns_term_init): Move color initialization to nsfns.m. * src/nsfns.m (ns_init_colors): New function. (Fns_list_colors): Call ns_init_colors.
Diffstat (limited to 'src')
-rw-r--r--src/nsfns.m62
-rw-r--r--src/nsterm.m48
2 files changed, 62 insertions, 48 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 3d3d5ec1bde..dddceb8d17b 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -2209,6 +2209,62 @@ font descriptor. If string contains `fontset' and not
2209 return build_string (ns_xlfd_to_fontname (SSDATA (name))); 2209 return build_string (ns_xlfd_to_fontname (SSDATA (name)));
2210} 2210}
2211 2211
2212static void
2213ns_init_colors (void)
2214{
2215 NSTRACE ("ns_init_colors");
2216
2217 NSColorList *cl = [NSColorList colorListNamed: @"Emacs"];
2218
2219 /* There are 752 colors defined in rgb.txt. */
2220 if ( cl == nil || [[cl allKeys] count] < 752)
2221 {
2222 Lisp_Object color_file, color_map, color, name;
2223 unsigned long c;
2224
2225 color_file = Fexpand_file_name (build_string ("rgb.txt"),
2226 Fsymbol_value (intern ("data-directory")));
2227
2228 color_map = Fx_load_color_file (color_file);
2229 if (NILP (color_map))
2230 fatal ("Could not read %s.\n", SDATA (color_file));
2231
2232 cl = [[NSColorList alloc] initWithName: @"Emacs"];
2233 for ( ; CONSP (color_map); color_map = XCDR (color_map))
2234 {
2235 color = XCAR (color_map);
2236 name = XCAR (color);
2237 c = XFIXNUM (XCDR (color));
2238 c |= 0xFF000000;
2239 [cl setColor:
2240 [NSColor colorWithUnsignedLong:c]
2241 forKey: [NSString stringWithLispString: name]];
2242 }
2243 @try
2244 {
2245#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
2246#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
2247 if ([cl respondsToSelector:@selector(writeToURL:error:)])
2248#endif
2249 if ([cl writeToURL:nil error:nil] == false)
2250 fprintf (stderr, "ns_init_colors: could not write Emacs.clr\n");
2251#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
2252 else
2253#endif
2254#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 */
2255#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100 || defined (NS_IMPL_GNUSTEP)
2256 if ([cl writeToFile: nil] == false)
2257 fprintf (stderr, "ns_init_colors: could not write Emacs.clr\n");
2258#endif
2259 }
2260 @catch (NSException *e)
2261 {
2262 NSLog(@"ns_init_colors: could not write Emacs.clr: %@", e.reason);
2263 }
2264 }
2265}
2266
2267static BOOL ns_init_colors_done = NO;
2212 2268
2213DEFUN ("ns-list-colors", Fns_list_colors, Sns_list_colors, 0, 1, 0, 2269DEFUN ("ns-list-colors", Fns_list_colors, Sns_list_colors, 0, 1, 0,
2214 doc: /* Return a list of all available colors. 2270 doc: /* Return a list of all available colors.
@@ -2220,6 +2276,12 @@ The optional argument FRAME is currently ignored. */)
2220 NSColorList *clist; 2276 NSColorList *clist;
2221 NSAutoreleasePool *pool; 2277 NSAutoreleasePool *pool;
2222 2278
2279 if (ns_init_colors_done == NO)
2280 {
2281 ns_init_colors ();
2282 ns_init_colors_done = YES;
2283 }
2284
2223 if (!NILP (frame)) 2285 if (!NILP (frame))
2224 { 2286 {
2225 CHECK_FRAME (frame); 2287 CHECK_FRAME (frame);
diff --git a/src/nsterm.m b/src/nsterm.m
index d0bbd1b4660..932d209f56b 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -591,7 +591,6 @@ ns_init_locale (void)
591 setenv ("LANG", lang, 1); 591 setenv ("LANG", lang, 1);
592} 592}
593 593
594
595void 594void
596ns_release_object (void *obj) 595ns_release_object (void *obj)
597/* -------------------------------------------------------------------------- 596/* --------------------------------------------------------------------------
@@ -5891,53 +5890,6 @@ ns_term_init (Lisp_Object display_name)
5891 ns_antialias_threshold = NILP (tmp) ? 10.0 : extract_float (tmp); 5890 ns_antialias_threshold = NILP (tmp) ? 10.0 : extract_float (tmp);
5892 } 5891 }
5893 5892
5894 NSTRACE_MSG ("Colors");
5895
5896 {
5897 NSColorList *cl = [NSColorList colorListNamed: @"Emacs"];
5898
5899 /* There are 752 colors defined in rgb.txt. */
5900 if ( cl == nil || [[cl allKeys] count] < 752)
5901 {
5902 Lisp_Object color_file, color_map, color, name;
5903 unsigned long c;
5904
5905 color_file = Fexpand_file_name (build_string ("rgb.txt"),
5906 Fsymbol_value (intern ("data-directory")));
5907
5908 color_map = Fx_load_color_file (color_file);
5909 if (NILP (color_map))
5910 fatal ("Could not read %s.\n", SDATA (color_file));
5911
5912 cl = [[NSColorList alloc] initWithName: @"Emacs"];
5913 for ( ; CONSP (color_map); color_map = XCDR (color_map))
5914 {
5915 color = XCAR (color_map);
5916 name = XCAR (color);
5917 c = XFIXNUM (XCDR (color));
5918 c |= 0xFF000000;
5919 [cl setColor:
5920 [NSColor colorWithUnsignedLong:c]
5921 forKey: [NSString stringWithLispString: name]];
5922 }
5923
5924 /* FIXME: Report any errors writing the color file below. */
5925#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
5926#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
5927 if ([cl respondsToSelector:@selector(writeToURL:error:)])
5928#endif
5929 [cl writeToURL:nil error:nil];
5930#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
5931 else
5932#endif
5933#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 */
5934#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100 \
5935 || defined (NS_IMPL_GNUSTEP)
5936 [cl writeToFile: nil];
5937#endif
5938 }
5939 }
5940
5941 NSTRACE_MSG ("Versions"); 5893 NSTRACE_MSG ("Versions");
5942 5894
5943 delete_keyboard_wait_descriptor (0); 5895 delete_keyboard_wait_descriptor (0);