comparison mac/dw.m @ 2127:663467f6eee4

Code cleanup: Add constants to header for dark mode, buffer sizes and Unicode support. Windows and OS/2 can both be built without Unicode support for legacy platforms and apps. Some new Windows features require Unicode (notifications, edge) and Unicode is buggy on OS/2. Can now check if Unicode is supported with the DW_FEATURE_UTF8_UNICODE feature test. Dark mode constants added DW_DARK_MODE_DISABLED/BASIC/FULL/FORCED. Win: Include dw.h in the WinToast glue for the constants, and improve safety in Edge glue.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 28 Jun 2020 20:34:25 +0000
parents 7ba8c8ff548f
children fc29c4c2d386
comparison
equal deleted inserted replaced
2126:97839ff3c985 2127:663467f6eee4
441 #endif 441 #endif
442 pthread_key_t _dw_fg_color_key; 442 pthread_key_t _dw_fg_color_key;
443 pthread_key_t _dw_bg_color_key; 443 pthread_key_t _dw_bg_color_key;
444 int DWOSMajor, DWOSMinor, DWOSBuild; 444 int DWOSMajor, DWOSMinor, DWOSBuild;
445 static char _dw_bundle_path[PATH_MAX+1] = { 0 }; 445 static char _dw_bundle_path[PATH_MAX+1] = { 0 };
446 static char _dw_app_id[101]= {0}; 446 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
447 447
448 /* Create a default colors for a thread */ 448 /* Create a default colors for a thread */
449 void _init_colors(void) 449 void _init_colors(void)
450 { 450 {
451 NSColor *fgcolor = [[NSColor grayColor] retain]; 451 NSColor *fgcolor = [[NSColor grayColor] retain];
4040 * The appname is only required on Windows. If NULL is passed the detected 4040 * The appname is only required on Windows. If NULL is passed the detected
4041 * application name will be used, but a prettier name may be desired. 4041 * application name will be used, but a prettier name may be desired.
4042 */ 4042 */
4043 int dw_app_id_set(const char *appid, const char *appname) 4043 int dw_app_id_set(const char *appid, const char *appname)
4044 { 4044 {
4045 strncpy(_dw_app_id, appid, 100); 4045 strncpy(_dw_app_id, appid, _DW_APP_ID_SIZE);
4046 return DW_ERROR_NONE; 4046 return DW_ERROR_NONE;
4047 } 4047 }
4048 4048
4049 /* 4049 /*
4050 * Displays a debug message on the console... 4050 * Displays a debug message on the console...
12137 char *binname = strrchr(pathcopy, '/'); 12137 char *binname = strrchr(pathcopy, '/');
12138 12138
12139 if(binname && (binname++) && !_dw_app_id[0]) 12139 if(binname && (binname++) && !_dw_app_id[0])
12140 { 12140 {
12141 /* If we have a binary name, use that for the Application ID instead. */ 12141 /* If we have a binary name, use that for the Application ID instead. */
12142 snprintf(_dw_app_id, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname); 12142 snprintf(_dw_app_id, _DW_APP_ID_SIZE, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname);
12143 } 12143 }
12144 if(app) 12144 if(app)
12145 { 12145 {
12146 char pathbuf[PATH_MAX+1] = { 0 }; 12146 char pathbuf[PATH_MAX+1] = { 0 };
12147 size_t len = (size_t)(app - pathcopy); 12147 size_t len = (size_t)(app - pathcopy);
12237 [thread release]; 12237 [thread release];
12238 [NSTextField setCellClass:[DWTextFieldCell class]]; 12238 [NSTextField setCellClass:[DWTextFieldCell class]];
12239 if(!_dw_app_id[0]) 12239 if(!_dw_app_id[0])
12240 { 12240 {
12241 /* Generate an Application ID based on the PID if all else fails. */ 12241 /* Generate an Application ID based on the PID if all else fails. */
12242 snprintf(_dw_app_id, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid()); 12242 snprintf(_dw_app_id, _DW_APP_ID_SIZE, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
12243 } 12243 }
12244 return 0; 12244 return 0;
12245 } 12245 }
12246 12246
12247 /* 12247 /*
12709 case DW_FEATURE_HTML: 12709 case DW_FEATURE_HTML:
12710 case DW_FEATURE_HTML_RESULT: 12710 case DW_FEATURE_HTML_RESULT:
12711 case DW_FEATURE_CONTAINER_STRIPE: 12711 case DW_FEATURE_CONTAINER_STRIPE:
12712 case DW_FEATURE_MLE_WORD_WRAP: 12712 case DW_FEATURE_MLE_WORD_WRAP:
12713 case DW_FEATURE_MLE_AUTO_COMPLETE: 12713 case DW_FEATURE_MLE_AUTO_COMPLETE:
12714 case DW_FEATURE_UTF8_UNICODE:
12714 return DW_FEATURE_ENABLED; 12715 return DW_FEATURE_ENABLED;
12715 #ifdef BUILDING_FOR_MOJAVE 12716 #ifdef BUILDING_FOR_MOJAVE
12716 case DW_FEATURE_DARK_MODE: 12717 case DW_FEATURE_DARK_MODE:
12717 { 12718 {
12718 if(@available(macOS 10.14, *)) 12719 if(@available(macOS 10.14, *))
12725 if(appearance) 12726 if(appearance)
12726 { 12727 {
12727 NSAppearanceName basicAppearance = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; 12728 NSAppearanceName basicAppearance = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
12728 12729
12729 if([basicAppearance isEqualToString:NSAppearanceNameDarkAqua]) 12730 if([basicAppearance isEqualToString:NSAppearanceNameDarkAqua])
12730 return 3; 12731 return DW_DARK_MODE_FORCED;
12731 if([basicAppearance isEqualToString:NSAppearanceNameAqua]) 12732 if([basicAppearance isEqualToString:NSAppearanceNameAqua])
12732 return DW_FEATURE_DISABLED; 12733 return DW_FEATURE_DISABLED;
12733 } 12734 }
12734 return DW_FEATURE_ENABLED; 12735 return DW_FEATURE_ENABLED;
12735 } 12736 }
12765 case DW_FEATURE_HTML: 12766 case DW_FEATURE_HTML:
12766 case DW_FEATURE_HTML_RESULT: 12767 case DW_FEATURE_HTML_RESULT:
12767 case DW_FEATURE_CONTAINER_STRIPE: 12768 case DW_FEATURE_CONTAINER_STRIPE:
12768 case DW_FEATURE_MLE_WORD_WRAP: 12769 case DW_FEATURE_MLE_WORD_WRAP:
12769 case DW_FEATURE_MLE_AUTO_COMPLETE: 12770 case DW_FEATURE_MLE_AUTO_COMPLETE:
12771 case DW_FEATURE_UTF8_UNICODE:
12770 return DW_ERROR_GENERAL; 12772 return DW_ERROR_GENERAL;
12771 /* These features are supported and configurable */ 12773 /* These features are supported and configurable */
12772 #ifdef BUILDING_FOR_MOJAVE 12774 #ifdef BUILDING_FOR_MOJAVE
12773 case DW_FEATURE_DARK_MODE: 12775 case DW_FEATURE_DARK_MODE:
12774 { 12776 {
12778 _dw_app_init(); 12780 _dw_app_init();
12779 /* Disabled forces the non-dark aqua theme */ 12781 /* Disabled forces the non-dark aqua theme */
12780 if(state == DW_FEATURE_DISABLED) 12782 if(state == DW_FEATURE_DISABLED)
12781 [DWApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]]; 12783 [DWApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
12782 /* Enabled lets the OS decide the mode */ 12784 /* Enabled lets the OS decide the mode */
12783 else if(state == DW_FEATURE_ENABLED || state == 2) 12785 else if(state == DW_FEATURE_ENABLED || state == DW_DARK_MODE_FULL)
12784 [DWApp setAppearance:nil]; 12786 [DWApp setAppearance:nil];
12785 /* 2 forces dark mode aqua appearance */ 12787 /* 2 forces dark mode aqua appearance */
12786 else if(state == 3) 12788 else if(state == DW_DARK_MODE_FORCED)
12787 [DWApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]]; 12789 [DWApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
12788 else 12790 else
12789 return DW_ERROR_GENERAL; 12791 return DW_ERROR_GENERAL;
12790 return DW_ERROR_NONE; 12792 return DW_ERROR_NONE;
12791 } 12793 }