Prepare wallpaper changing on macOS

This commit is contained in:
Vinyl Darkscratch 2018-03-01 14:50:22 -08:00
parent 87fcbbb494
commit 74de315eda
4 changed files with 65 additions and 10 deletions

View file

@ -7,15 +7,21 @@
static bool isCached = false;
#ifdef _WIN32
#include <windows.h>
static WCHAR szStyle[8] = {0};
static WCHAR szTile[8] = {0};
static WCHAR szFile[MAX_PATH+1] = {0};
static DWORD oldcolor = 0;
static DWORD szStyleSize = sizeof(szStyle) - 1;
static DWORD szTileSize = sizeof(szTile) - 1;
static bool setStyle = false;
static bool setTile = false;
#include <windows.h>
static WCHAR szStyle[8] = {0};
static WCHAR szTile[8] = {0};
static WCHAR szFile[MAX_PATH+1] = {0};
static DWORD oldcolor = 0;
static DWORD szStyleSize = sizeof(szStyle) - 1;
static DWORD szTileSize = sizeof(szTile) - 1;
static bool setStyle = false;
static bool setTile = false;
#else
#ifdef __APPLE__
#include "mac-desktop.h"
#else
// XXX Implement me!
#endif
#endif
RB_METHOD(wallpaperSet)
@ -93,6 +99,11 @@ end:
if (hKey)
RegCloseKey(hKey);
#else
#ifdef __APPLE__
// XXX Implement me!
#else
// XXX Implement me!
#endif
#endif
return Qnil;
}
@ -126,6 +137,11 @@ RB_METHOD(wallpaperReset)
RegCloseKey(hKey);
}
#else
#ifdef __APPLE__
// XXX Implement me!
#else
// XXX Implement me!
#endif
#endif
return Qnil;
}

View file

@ -41,8 +41,10 @@ unix {
LIBS += -ldl
macx: {
INCLUDEPATH += $$QMAKE_MAC_SDK_PATH/System/Library/Frameworks/OpenAL.framework/Versions/A/Headers
LIBS += -framework OpenAL
LIBS += -framework OpenAL -framework AppKit
QMAKE_LFLAGS += -L/usr/local/opt/ruby@2.3/lib -L/usr/local/opt/openal-soft/lib
HEADERS += src/mac-desktop.h
SOURCES += src/mac-desktop.mm
}
!macx: {
# PKGCONFIG += openal zlib

12
src/mac-desktop.h Normal file
View file

@ -0,0 +1,12 @@
//
// SyngleChance Engine - mac-desktop.h
// ©2018 Vinyl Darkscratch. You may use this code for anything you'd like.
// https://www.queengoob.org
//
#pragma once
#include <string>
bool ChangeBackground(std::string imageURL);
bool ResetBackground();

25
src/mac-desktop.mm Normal file
View file

@ -0,0 +1,25 @@
//
// SyngleChance Engine - mac-desktop.mm
// ©2018 Vinyl Darkscratch. You may use this code for anything you'd like.
// https://www.queengoob.org
//
#include "mac-desktop.h"
#include <string>
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
bool 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;
}