Create wallpaper caching and add namespace

This commit is contained in:
Vinyl Darkscratch 2018-03-01 15:48:42 -08:00
parent 3b386259b1
commit fe1381243b
2 changed files with 20 additions and 8 deletions

View file

@ -8,5 +8,8 @@
#include <string>
bool ChangeBackground(std::string imageURL);
bool ResetBackground();
namespace MacDesktop {
void CacheCurrentBackground();
bool ChangeBackground(std::string imageURL);
bool ResetBackground();
}

View file

@ -10,16 +10,25 @@
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
bool ChangeBackground(std::string imageURL) {
NSURL *originalBackground;
NSDictionary<NSWorkspaceDesktopImageOptionKey, id> *originalOptions;
NSScreen *mainscreen = [NSScreen mainScreen];
NSWorkspace *sharedworkspace = [NSWorkspace sharedWorkspace];
void MacDesktop::CacheCurrentBackground() {
originalBackground = [sharedworkspace desktopImageURLForScreen:mainscreen];
originalOptions = [sharedworkspace desktopImageOptionsForScreen:mainscreen];
}
bool MacDesktop::ChangeBackground(std::string imageURL) {
NSURL *URL = [NSURL fileURLWithPath:@(imageURL.c_str())];
NSScreen *mainscreen = [NSScreen mainScreen];
NSWorkspace *sharedworkspace = [NSWorkspace sharedWorkspace];
BOOL success = [sharedworkspace setDesktopImageURL:[URL absoluteURL] forScreen:mainscreen options:[sharedworkspace desktopImageOptionsForScreen:mainscreen] error:nil];
return (bool)success;
}
bool ResetBackground() {
// XXX Implement me!
return false;
bool MacDesktop::ResetBackground() {
BOOL success = [sharedworkspace setDesktopImageURL:originalBackground forScreen:mainscreen options:originalOptions error:nil];
return (bool)success;
}