diff 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
line wrap: on
line diff
--- a/mac/dw.m	Sun Jun 28 05:39:08 2020 +0000
+++ b/mac/dw.m	Sun Jun 28 20:34:25 2020 +0000
@@ -443,7 +443,7 @@
 pthread_key_t _dw_bg_color_key;
 int DWOSMajor, DWOSMinor, DWOSBuild;
 static char _dw_bundle_path[PATH_MAX+1] = { 0 };
-static char _dw_app_id[101]= {0};
+static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
 
 /* Create a default colors for a thread */
 void _init_colors(void)
@@ -4042,7 +4042,7 @@
  */
 int dw_app_id_set(const char *appid, const char *appname)
 {
-    strncpy(_dw_app_id, appid, 100);
+    strncpy(_dw_app_id, appid, _DW_APP_ID_SIZE);
     return DW_ERROR_NONE;
 }
 
@@ -12139,7 +12139,7 @@
         if(binname && (binname++) && !_dw_app_id[0])
         {
             /* If we have a binary name, use that for the Application ID instead. */
-            snprintf(_dw_app_id, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname);
+            snprintf(_dw_app_id, _DW_APP_ID_SIZE, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname);
         }
         if(app)
         {
@@ -12239,7 +12239,7 @@
     if(!_dw_app_id[0])
     {
         /* Generate an Application ID based on the PID if all else fails. */
-        snprintf(_dw_app_id, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
+        snprintf(_dw_app_id, _DW_APP_ID_SIZE, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
     }
     return 0;
 }
@@ -12711,6 +12711,7 @@
         case DW_FEATURE_CONTAINER_STRIPE:
         case DW_FEATURE_MLE_WORD_WRAP:
         case DW_FEATURE_MLE_AUTO_COMPLETE:
+        case DW_FEATURE_UTF8_UNICODE:
             return DW_FEATURE_ENABLED;
 #ifdef BUILDING_FOR_MOJAVE
         case DW_FEATURE_DARK_MODE:
@@ -12727,7 +12728,7 @@
                     NSAppearanceName basicAppearance = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
                     
                     if([basicAppearance isEqualToString:NSAppearanceNameDarkAqua])
-                        return 3;
+                        return DW_DARK_MODE_FORCED;
                     if([basicAppearance isEqualToString:NSAppearanceNameAqua])
                         return DW_FEATURE_DISABLED;
                 }
@@ -12767,6 +12768,7 @@
         case DW_FEATURE_CONTAINER_STRIPE:
         case DW_FEATURE_MLE_WORD_WRAP:
         case DW_FEATURE_MLE_AUTO_COMPLETE:
+        case DW_FEATURE_UTF8_UNICODE:
             return DW_ERROR_GENERAL;
         /* These features are supported and configurable */
 #ifdef BUILDING_FOR_MOJAVE
@@ -12780,10 +12782,10 @@
                 if(state == DW_FEATURE_DISABLED)
                    [DWApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
                 /* Enabled lets the OS decide the mode */
-                else if(state == DW_FEATURE_ENABLED || state == 2)
+                else if(state == DW_FEATURE_ENABLED || state == DW_DARK_MODE_FULL)
                    [DWApp setAppearance:nil];
                 /* 2 forces dark mode aqua appearance */
-                else if(state == 3)
+                else if(state == DW_DARK_MODE_FORCED)
                     [DWApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
                 else
                     return DW_ERROR_GENERAL;