aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsfns.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/nsfns.m')
-rw-r--r--src/nsfns.m146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 6992eaa74ce..c8de5583bf3 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -2210,6 +2210,62 @@ font descriptor. If string contains `fontset' and not
2210 return build_string (ns_xlfd_to_fontname (SSDATA (name))); 2210 return build_string (ns_xlfd_to_fontname (SSDATA (name)));
2211} 2211}
2212 2212
2213static void
2214ns_init_colors (void)
2215{
2216 NSTRACE ("ns_init_colors");
2217
2218 NSColorList *cl = [NSColorList colorListNamed: @"Emacs"];
2219
2220 /* There are 752 colors defined in rgb.txt. */
2221 if ( cl == nil || [[cl allKeys] count] < 752)
2222 {
2223 Lisp_Object color_file, color_map, color, name;
2224 unsigned long c;
2225
2226 color_file = Fexpand_file_name (build_string ("rgb.txt"),
2227 Fsymbol_value (intern ("data-directory")));
2228
2229 color_map = Fx_load_color_file (color_file);
2230 if (NILP (color_map))
2231 fatal ("Could not read %s.\n", SDATA (color_file));
2232
2233 cl = [[NSColorList alloc] initWithName: @"Emacs"];
2234 for ( ; CONSP (color_map); color_map = XCDR (color_map))
2235 {
2236 color = XCAR (color_map);
2237 name = XCAR (color);
2238 c = XFIXNUM (XCDR (color));
2239 c |= 0xFF000000;
2240 [cl setColor:
2241 [NSColor colorWithUnsignedLong:c]
2242 forKey: [NSString stringWithLispString: name]];
2243 }
2244 @try
2245 {
2246#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
2247#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
2248 if ([cl respondsToSelector:@selector(writeToURL:error:)])
2249#endif
2250 if ([cl writeToURL:nil error:nil] == false)
2251 fprintf (stderr, "ns_init_colors: could not write Emacs.clr\n");
2252#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
2253 else
2254#endif
2255#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 */
2256#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100 || defined (NS_IMPL_GNUSTEP)
2257 if ([cl writeToFile: nil] == false)
2258 fprintf (stderr, "ns_init_colors: could not write Emacs.clr\n");
2259#endif
2260 }
2261 @catch (NSException *e)
2262 {
2263 NSLog(@"ns_init_colors: could not write Emacs.clr: %@", e.reason);
2264 }
2265 }
2266}
2267
2268static BOOL ns_init_colors_done = NO;
2213 2269
2214DEFUN ("ns-list-colors", Fns_list_colors, Sns_list_colors, 0, 1, 0, 2270DEFUN ("ns-list-colors", Fns_list_colors, Sns_list_colors, 0, 1, 0,
2215 doc: /* Return a list of all available colors. 2271 doc: /* Return a list of all available colors.
@@ -2221,6 +2277,12 @@ The optional argument FRAME is currently ignored. */)
2221 NSColorList *clist; 2277 NSColorList *clist;
2222 NSAutoreleasePool *pool; 2278 NSAutoreleasePool *pool;
2223 2279
2280 if (ns_init_colors_done == NO)
2281 {
2282 ns_init_colors ();
2283 ns_init_colors_done = YES;
2284 }
2285
2224 if (!NILP (frame)) 2286 if (!NILP (frame))
2225 { 2287 {
2226 CHECK_FRAME (frame); 2288 CHECK_FRAME (frame);
@@ -3806,6 +3868,88 @@ If PROGRESS is nil, remove the progress indicator. */)
3806 return Qnil; 3868 return Qnil;
3807} 3869}
3808 3870
3871/* A unique integer sleep block id and a hash map of its id to opaque
3872 NSObject sleep block activity tokens. */
3873static unsigned int sleep_block_id = 0;
3874static NSMutableDictionary *sleep_block_map = NULL;
3875
3876DEFUN ("ns-block-system-sleep",
3877 Fns_block_system_sleep,
3878 Sns_block_system_sleep,
3879 2, 2, 0,
3880 doc: /* Block system idle sleep.
3881WHY is a string reason for the block.
3882If ALLOW-DISPLAY-SLEEP is non-nil, block the screen from sleeping.
3883Return a token to unblock this block using `ns-unblock-system-sleep',
3884or nil if the block fails. */)
3885 (Lisp_Object why, Lisp_Object allow_display_sleep)
3886{
3887 block_input ();
3888
3889 NSString *reason = @"Emacs";
3890 if (!NILP (why))
3891 {
3892 CHECK_STRING (why);
3893 reason = [NSString stringWithLispString: why];
3894 }
3895
3896 unsigned long activity_options =
3897 NSActivityUserInitiated | NSActivityIdleSystemSleepDisabled;
3898 if (NILP (allow_display_sleep))
3899 activity_options |= NSActivityIdleDisplaySleepDisabled;
3900
3901 NSProcessInfo *processInfo = [NSProcessInfo processInfo];
3902 NSObject *activity_id = nil;
3903 if ([processInfo respondsToSelector:@selector(beginActivityWithOptions:reason:)])
3904 activity_id = [[NSProcessInfo processInfo]
3905 beginActivityWithOptions: activity_options
3906 reason: reason];
3907 unblock_input ();
3908
3909 if (!sleep_block_map)
3910 sleep_block_map = [[NSMutableDictionary alloc] initWithCapacity: 25];
3911
3912 if (activity_id)
3913 {
3914 [sleep_block_map setObject: activity_id
3915 forKey: [NSNumber numberWithInt: ++sleep_block_id]];
3916 return make_fixnum (sleep_block_id);
3917 }
3918 else
3919 return Qnil;
3920}
3921
3922DEFUN ("ns-unblock-system-sleep",
3923 Fns_unblock_system_sleep,
3924 Sns_unblock_system_sleep,
3925 1, 1, 0,
3926 doc: /* Unblock system idle sleep.
3927TOKEN is an object returned by `ns-block-system-sleep'.
3928Return non-nil if the TOKEN block was unblocked. */)
3929 (Lisp_Object token)
3930{
3931 block_input ();
3932 Lisp_Object res = Qnil;
3933 CHECK_FIXNAT (token);
3934 if (sleep_block_map)
3935 {
3936 NSNumber *key = [NSNumber numberWithInt: XFIXNAT (token)];
3937 NSObject *activity_id = [sleep_block_map objectForKey: key];
3938 if (activity_id)
3939 {
3940 NSProcessInfo *processInfo = [NSProcessInfo processInfo];
3941 if ([processInfo respondsToSelector:@selector(endActivity:)])
3942 {
3943 [[NSProcessInfo processInfo] endActivity: activity_id];
3944 res = Qt;
3945 }
3946 [sleep_block_map removeObjectForKey: key];
3947 }
3948 }
3949 unblock_input ();
3950 return res;
3951}
3952
3809#ifdef NS_IMPL_COCOA 3953#ifdef NS_IMPL_COCOA
3810 3954
3811DEFUN ("ns-send-items", 3955DEFUN ("ns-send-items",
@@ -4092,6 +4236,8 @@ The default value is t. */);
4092 defsubr (&Sns_badge); 4236 defsubr (&Sns_badge);
4093 defsubr (&Sns_request_user_attention); 4237 defsubr (&Sns_request_user_attention);
4094 defsubr (&Sns_progress_indicator); 4238 defsubr (&Sns_progress_indicator);
4239 defsubr (&Sns_block_system_sleep);
4240 defsubr (&Sns_unblock_system_sleep);
4095#ifdef NS_IMPL_COCOA 4241#ifdef NS_IMPL_COCOA
4096 defsubr (&Sns_send_items); 4242 defsubr (&Sns_send_items);
4097#endif 4243#endif