Bug 1544739 - Part 9: Update GNOME shell service - Sync Get/SetDesktopBackgroundColor. r=frg a=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Wed, 24 Apr 2019 18:54:00 +0200
changeset 32188 a441444f65f14b5a24b71ea2465469e8c2f5e06e
parent 32187 92feee89deec2b67c46a4b83dfef9819e6c94cdd
child 32189 33e9c7be67682a74b1558f4fc474f64ad003de7c
push id187
push userfrgrahl@gmx.net
push dateWed, 24 Apr 2019 16:55:18 +0000
treeherdercomm-esr60@33e9c7be6768 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1544739
Bug 1544739 - Part 9: Update GNOME shell service - Sync Get/SetDesktopBackgroundColor. r=frg a=frg
suite/components/shell/nsGNOMEShellService.cpp
--- a/suite/components/shell/nsGNOMEShellService.cpp
+++ b/suite/components/shell/nsGNOMEShellService.cpp
@@ -376,59 +376,62 @@ nsGNOMEShellService::SetDesktopBackgroun
       return rv;
     }
   }
 
   return NS_ERROR_FAILURE;
 }
 
 #define COLOR_16_TO_8_BIT(_c) ((_c) >> 8)
+#define COLOR_8_TO_16_BIT(_c) ((_c) << 8 | (_c))
 
 NS_IMETHODIMP
 nsGNOMEShellService::GetDesktopBackgroundColor(uint32_t *aColor)
 {
-  nsCOMPtr<nsIGSettingsService> gsettings(do_GetService(NS_GSETTINGSSERVICE_CONTRACTID));
+  nsCOMPtr<nsIGSettingsService> gsettings =
+      do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
   nsCOMPtr<nsIGSettingsCollection> background_settings;
+  nsAutoCString background;
 
-  if (gsettings)
+  if (gsettings) {
     gsettings->GetCollectionForSchema(NS_LITERAL_CSTRING(kDesktopBGSchema),
                                       getter_AddRefs(background_settings));
+    if (background_settings) {
+      background_settings->GetString(NS_LITERAL_CSTRING(kDesktopColorGSKey),
+                                     background);
+    }
+  }
 
-  nsCString background;
-  if (background_settings)
-    background_settings->GetString(NS_LITERAL_CSTRING(kDesktopColorGSKey),
-                                   background);
-
-  if (background.IsEmpty())
-    return NS_ERROR_FAILURE;
+  if (background.IsEmpty()) {
+    *aColor = 0;
+    return NS_OK;
+  }
 
   GdkColor color;
   NS_ENSURE_TRUE(gdk_color_parse(background.get(), &color), NS_ERROR_FAILURE);
 
   *aColor = COLOR_16_TO_8_BIT(color.red) << 16 |
             COLOR_16_TO_8_BIT(color.green) << 8 |
             COLOR_16_TO_8_BIT(color.blue);
   return NS_OK;
 }
 
-#define COLOR_8_TO_16_BIT(_c) ((_c) << 8 | (_c))
-
 NS_IMETHODIMP
 nsGNOMEShellService::SetDesktopBackgroundColor(uint32_t aColor)
 {
   NS_ENSURE_ARG_MAX(aColor, 0xFFFFFF);
 
-  uint8_t red = aColor >> 16;
-  uint8_t green = aColor >> 8;
-  uint8_t blue = aColor;
+  uint16_t red = COLOR_8_TO_16_BIT((aColor >> 16) & 0xff);
+  uint16_t green = COLOR_8_TO_16_BIT((aColor >> 8) & 0xff);
+  uint16_t blue = COLOR_8_TO_16_BIT(aColor & 0xff);
   char colorString[14];
-  sprintf(colorString, "#%04x%04x%04x", COLOR_8_TO_16_BIT(red),
-          COLOR_8_TO_16_BIT(green), COLOR_8_TO_16_BIT(blue));
+  sprintf(colorString, "#%04x%04x%04x", red, green, blue);
 
-  nsCOMPtr<nsIGSettingsService> gsettings(do_GetService(NS_GSETTINGSSERVICE_CONTRACTID));
+  nsCOMPtr<nsIGSettingsService> gsettings =
+      do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
   if (gsettings) {
     nsCOMPtr<nsIGSettingsCollection> background_settings;
     gsettings->GetCollectionForSchema(NS_LITERAL_CSTRING(kDesktopBGSchema),
                                       getter_AddRefs(background_settings));
     if (background_settings) {
       background_settings->SetString(NS_LITERAL_CSTRING(kDesktopColorGSKey),
                                      nsDependentCString(colorString));
       return NS_OK;