1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "mozilla/Logging.h"
7 #include "nsCocoaUtils.h"
9 #include "DesktopBackgroundImage.h"
11 #import <Foundation/Foundation.h>
13 extern mozilla::LazyLogModule gCocoaUtilsLog;
15 #define LOG(...) MOZ_LOG(gCocoaUtilsLog, LogLevel::Debug, (__VA_ARGS__))
20 void SetDesktopImage(nsIFile* aImage) {
21 nsAutoCString imagePath;
22 nsresult rv = aImage->GetNativePath(imagePath);
24 LOG("%s ERROR: failed to get image path", __func__);
29 rv = aImage->Exists(&exists);
30 if (NS_FAILED(rv) || !exists) {
31 LOG("%s ERROR: file \"%s\" does not exist", __func__, imagePath.get());
35 NSString* urlString = [NSString stringWithUTF8String:imagePath.get()];
37 LOG("%s ERROR: null image path \"%s\"", __func__, imagePath.get());
41 NSURL* url = [NSURL fileURLWithPath:urlString];
43 LOG("%s ERROR: null image path URL \"%s\"", __func__, imagePath.get());
47 // Only apply the background to the screen with focus
48 NSScreen* currentScreen = [NSScreen mainScreen];
50 LOG("%s ERROR: got null NSScreen", __func__);
54 // Use existing options for this screen
55 NSDictionary* screenOptions = [[NSWorkspace sharedWorkspace]
56 desktopImageOptionsForScreen:currentScreen];
59 if (![[NSWorkspace sharedWorkspace] setDesktopImageURL:url
60 forScreen:currentScreen
63 LOG("%s ERROR: setDesktopImageURL failed (%ld)", __func__,
69 } // namespace mozilla