diff options
| author | Jan Djärv | 2013-12-21 17:11:55 +0100 |
|---|---|---|
| committer | Jan Djärv | 2013-12-21 17:11:55 +0100 |
| commit | 41cf3d118e142b15468951e3c8670a7d83fdfe66 (patch) | |
| tree | 2aec095fad311bfb0bbb84a9d8081eeb31f05d10 /src | |
| parent | aac2b673c3083ab612bcd57fbcd9d370078bd8da (diff) | |
| download | emacs-41cf3d118e142b15468951e3c8670a7d83fdfe66.tar.gz emacs-41cf3d118e142b15468951e3c8670a7d83fdfe66.zip | |
Customize ns-use-srgb-colorspace on OSX >= 10.7 to use sRGB.
* etc/NEWS: Mention ns-use-srgb-colorspace.
* lisp/cus-start.el (all): Add ns-use-srgb-colorspace.
* src/nsfns.m (Fxw_color_values): Use colorUsingDefaultColorSpace.
* src/nsterm.h: Declare EmacsColor category.
* src/nsterm.m (NSColor): Implement EmacsColor category.
(ns_get_color): Use colorUsingDefaultColorSpace.
(ns_get_color, ns_term_init): Use colorForEmacsRed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/nsfns.m | 2 | ||||
| -rw-r--r-- | src/nsterm.h | 12 | ||||
| -rw-r--r-- | src/nsterm.m | 63 |
3 files changed, 66 insertions, 11 deletions
diff --git a/src/nsfns.m b/src/nsfns.m index 8f14915ea65..e90e01b12fb 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -2289,7 +2289,7 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0, | |||
| 2289 | if (ns_lisp_to_color (color, &col)) | 2289 | if (ns_lisp_to_color (color, &col)) |
| 2290 | return Qnil; | 2290 | return Qnil; |
| 2291 | 2291 | ||
| 2292 | [[col colorUsingColorSpaceName: NSCalibratedRGBColorSpace] | 2292 | [[col colorUsingDefaultColorSpace] |
| 2293 | getRed: &red green: &green blue: &blue alpha: &alpha]; | 2293 | getRed: &red green: &green blue: &blue alpha: &alpha]; |
| 2294 | return list3i (lrint (red * 65280), lrint (green * 65280), | 2294 | return list3i (lrint (red * 65280), lrint (green * 65280), |
| 2295 | lrint (blue * 65280)); | 2295 | lrint (blue * 65280)); |
diff --git a/src/nsterm.h b/src/nsterm.h index b86122417e5..2ca8385f7e9 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -78,6 +78,18 @@ typedef float EmacsCGFloat; | |||
| 78 | 78 | ||
| 79 | /* ========================================================================== | 79 | /* ========================================================================== |
| 80 | 80 | ||
| 81 | NSColor, EmacsColor category. | ||
| 82 | |||
| 83 | ========================================================================== */ | ||
| 84 | @interface NSColor (EmacsColor) | ||
| 85 | + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green | ||
| 86 | blue:(CGFloat)blue alpha:(CGFloat)alpha; | ||
| 87 | - (NSColor *)colorUsingDefaultColorSpace; | ||
| 88 | |||
| 89 | @end | ||
| 90 | |||
| 91 | /* ========================================================================== | ||
| 92 | |||
| 81 | The Emacs application | 93 | The Emacs application |
| 82 | 94 | ||
| 83 | ========================================================================== */ | 95 | ========================================================================== */ |
diff --git a/src/nsterm.m b/src/nsterm.m index 10780b054d9..f2aef422db4 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -105,6 +105,43 @@ extern NSString *NSMenuDidBeginTrackingNotification; | |||
| 105 | 105 | ||
| 106 | /* ========================================================================== | 106 | /* ========================================================================== |
| 107 | 107 | ||
| 108 | NSColor, EmacsColor category. | ||
| 109 | |||
| 110 | ========================================================================== */ | ||
| 111 | @implementation NSColor (EmacsColor) | ||
| 112 | + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green | ||
| 113 | blue:(CGFloat)blue alpha:(CGFloat)alpha | ||
| 114 | { | ||
| 115 | #ifdef NS_IMPL_COCOA | ||
| 116 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | ||
| 117 | if (ns_use_srgb_colorspace) | ||
| 118 | return [NSColor colorWithSRGBRed: red | ||
| 119 | green: green | ||
| 120 | blue: blue | ||
| 121 | alpha: alpha]; | ||
| 122 | #endif | ||
| 123 | #endif | ||
| 124 | return [NSColor colorWithCalibratedRed: red | ||
| 125 | green: green | ||
| 126 | blue: blue | ||
| 127 | alpha: alpha]; | ||
| 128 | } | ||
| 129 | |||
| 130 | - (NSColor *)colorUsingDefaultColorSpace | ||
| 131 | { | ||
| 132 | #ifdef NS_IMPL_COCOA | ||
| 133 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | ||
| 134 | if (ns_use_srgb_colorspace) | ||
| 135 | return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]]; | ||
| 136 | #endif | ||
| 137 | #endif | ||
| 138 | return [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; | ||
| 139 | } | ||
| 140 | |||
| 141 | @end | ||
| 142 | |||
| 143 | /* ========================================================================== | ||
| 144 | |||
| 108 | Local declarations | 145 | Local declarations |
| 109 | 146 | ||
| 110 | ========================================================================== */ | 147 | ========================================================================== */ |
| @@ -1509,7 +1546,7 @@ ns_get_color (const char *name, NSColor **col) | |||
| 1509 | #endif | 1546 | #endif |
| 1510 | if ((new = [NSColor selectedTextBackgroundColor]) != nil) | 1547 | if ((new = [NSColor selectedTextBackgroundColor]) != nil) |
| 1511 | { | 1548 | { |
| 1512 | *col = [new colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; | 1549 | *col = [new colorUsingDefaultColorSpace]; |
| 1513 | unblock_input (); | 1550 | unblock_input (); |
| 1514 | return 0; | 1551 | return 0; |
| 1515 | } | 1552 | } |
| @@ -1525,7 +1562,7 @@ ns_get_color (const char *name, NSColor **col) | |||
| 1525 | */ | 1562 | */ |
| 1526 | if ((new = [NSColor selectedTextColor]) != nil) | 1563 | if ((new = [NSColor selectedTextColor]) != nil) |
| 1527 | { | 1564 | { |
| 1528 | *col = [new colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; | 1565 | *col = [new colorUsingDefaultColorSpace]; |
| 1529 | unblock_input (); | 1566 | unblock_input (); |
| 1530 | return 0; | 1567 | return 0; |
| 1531 | } | 1568 | } |
| @@ -1572,7 +1609,7 @@ ns_get_color (const char *name, NSColor **col) | |||
| 1572 | 1609 | ||
| 1573 | if (r >= 0.0F) | 1610 | if (r >= 0.0F) |
| 1574 | { | 1611 | { |
| 1575 | *col = [NSColor colorWithCalibratedRed: r green: g blue: b alpha: 1.0]; | 1612 | *col = [NSColor colorForEmacsRed: r green: g blue: b alpha: 1.0]; |
| 1576 | unblock_input (); | 1613 | unblock_input (); |
| 1577 | return 0; | 1614 | return 0; |
| 1578 | } | 1615 | } |
| @@ -1604,7 +1641,7 @@ ns_get_color (const char *name, NSColor **col) | |||
| 1604 | } | 1641 | } |
| 1605 | 1642 | ||
| 1606 | if (new) | 1643 | if (new) |
| 1607 | *col = [new colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; | 1644 | *col = [new colorUsingDefaultColorSpace]; |
| 1608 | unblock_input (); | 1645 | unblock_input (); |
| 1609 | return new ? 0 : 1; | 1646 | return new ? 0 : 1; |
| 1610 | } | 1647 | } |
| @@ -1645,9 +1682,9 @@ ns_color_to_lisp (NSColor *col) | |||
| 1645 | return build_string ((char *)str); | 1682 | return build_string ((char *)str); |
| 1646 | } | 1683 | } |
| 1647 | 1684 | ||
| 1648 | [[col colorUsingColorSpaceName: NSCalibratedRGBColorSpace] | 1685 | [[col colorUsingDefaultColorSpace] |
| 1649 | getRed: &red green: &green blue: &blue alpha: &alpha]; | 1686 | getRed: &red green: &green blue: &blue alpha: &alpha]; |
| 1650 | if (red ==green && red ==blue) | 1687 | if (red == green && red == blue) |
| 1651 | { | 1688 | { |
| 1652 | [[col colorUsingColorSpaceName: NSCalibratedWhiteColorSpace] | 1689 | [[col colorUsingColorSpaceName: NSCalibratedWhiteColorSpace] |
| 1653 | getWhite: &gray alpha: &alpha]; | 1690 | getWhite: &gray alpha: &alpha]; |
| @@ -4273,10 +4310,10 @@ ns_term_init (Lisp_Object display_name) | |||
| 4273 | name = SSDATA (XCAR (color)); | 4310 | name = SSDATA (XCAR (color)); |
| 4274 | c = XINT (XCDR (color)); | 4311 | c = XINT (XCDR (color)); |
| 4275 | [cl setColor: | 4312 | [cl setColor: |
| 4276 | [NSColor colorWithCalibratedRed: RED_FROM_ULONG (c) / 255.0 | 4313 | [NSColor colorForEmacsRed: RED_FROM_ULONG (c) / 255.0 |
| 4277 | green: GREEN_FROM_ULONG (c) / 255.0 | 4314 | green: GREEN_FROM_ULONG (c) / 255.0 |
| 4278 | blue: BLUE_FROM_ULONG (c) / 255.0 | 4315 | blue: BLUE_FROM_ULONG (c) / 255.0 |
| 4279 | alpha: 1.0] | 4316 | alpha: 1.0] |
| 4280 | forKey: [NSString stringWithUTF8String: name]]; | 4317 | forKey: [NSString stringWithUTF8String: name]]; |
| 4281 | } | 4318 | } |
| 4282 | [cl writeToFile: nil]; | 4319 | [cl writeToFile: nil]; |
| @@ -7607,6 +7644,12 @@ Default is t for OSX >= 10.7, nil otherwise. */); | |||
| 7607 | #endif | 7644 | #endif |
| 7608 | ns_last_use_native_fullscreen = ns_use_native_fullscreen; | 7645 | ns_last_use_native_fullscreen = ns_use_native_fullscreen; |
| 7609 | 7646 | ||
| 7647 | DEFVAR_BOOL ("ns-use-srgb-colorspace", ns_use_srgb_colorspace, | ||
| 7648 | doc: /*Non-nil means to use sRGB colorspace on OSX >= 10.7. | ||
| 7649 | Note that this does not apply to images. | ||
| 7650 | This variable is ignored on OSX < 10.7 and GNUStep. Default is nil. */); | ||
| 7651 | ns_use_srgb_colorspace = NO; | ||
| 7652 | |||
| 7610 | /* TODO: move to common code */ | 7653 | /* TODO: move to common code */ |
| 7611 | DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars, | 7654 | DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars, |
| 7612 | doc: /* Which toolkit scroll bars Emacs uses, if any. | 7655 | doc: /* Which toolkit scroll bars Emacs uses, if any. |