Skip to content

Commit

Permalink
Merge pull request #2 from Astrabit-ST/hat_kid/sdl3-windows-fixes
Browse files Browse the repository at this point in the history
Hat kid/sdl3 windows fixes
  • Loading branch information
Speak2Erase authored Aug 15, 2024
2 parents 2c32a59 + 5321ba3 commit 08290b9
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 124 deletions.
12 changes: 6 additions & 6 deletions binding/binding-mri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern "C" {
#endif
}

#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
#include "binding-mri-win32.h"
#endif

Expand Down Expand Up @@ -113,7 +113,7 @@ void oneshotSteamBindingInit();
void oneshotJournalBindingInit();
void oneshotNikoBindingInit();
void oneshotWallpaperBindingInit();
#ifdef SDL_PLATFORM_LINUX
#ifdef __LINUX__
void oneshotWallpaperBindingTerminate();
#endif

Expand Down Expand Up @@ -335,7 +335,7 @@ static void mriBindingInit() {

// Set $stdout and its ilk accordingly on Windows
// I regret teaching you that word
#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
if (shState->config().winConsole)
configureWindowsStreams();
#endif
Expand Down Expand Up @@ -521,7 +521,7 @@ RB_METHOD(mkxpUserName) {

// Using the Windows API isn't working with usernames that involve Unicode
// characters for some dumb reason
#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
VALUE env = rb_const_get(rb_mKernel, rb_intern("ENV"));
return rb_funcall(env, rb_intern("[]"), 1, rb_str_new_cstr("USERNAME"));
#else
Expand Down Expand Up @@ -677,7 +677,7 @@ RB_METHOD(mkxpStringToUTF8Bang) {
return self;
}

#ifdef SDL_PLATFORM_APPLE
#ifdef __APPLE__
#define OPENCMD "open "
#define OPENARGS "--args"
#elif defined(__linux__)
Expand Down Expand Up @@ -1234,7 +1234,7 @@ static void mriBindingExecute() {
#else
ruby_init();
rb_eval_string("$KCODE='U'");
#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
if (!conf.winConsole) {
VALUE iostr = rb_str_new2("NUL");
// Sysinit isn't a thing yet, so send io to /dev/null instead
Expand Down
2 changes: 1 addition & 1 deletion binding/miniffi.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "miniffi.h"
#include <assert.h>

#if defined(__MINGW64__) || defined(__linux__) || defined(SDL_PLATFORM_APPLE)
#if defined(__MINGW64__) || defined(__linux__) || defined(__APPLE__)
mffi_value miniffi_call_intern(MINIFFI_FUNC target, MiniFFIFuncArgs *p, int nparams) {
assert(nparams <= MINIFFI_MAX_ARGS);
// Be sure to add more args to the below line if MINIFFI_MAX_ARGS is bumped
Expand Down
2 changes: 1 addition & 1 deletion binding/miniffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define MINIFFI_MAX_ARGS 16l

#if defined(__linux__) || defined(SDL_PLATFORM_APPLE)
#if defined(__linux__) || defined(__APPLE__)
typedef unsigned long mffi_value;
// Be sure to add more args to the below line if MINIFFI_MAX_ARGS is bumped
// in the future.
Expand Down
1 change: 0 additions & 1 deletion binding/modshot-window-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <SDL3/SDL.h>
#include <SDL3_image/SDL_image.h>
//#include <SDL3/SDL_syswm.h>

#ifdef _WIN32
#include <windows.h>
Expand Down
8 changes: 4 additions & 4 deletions binding/oneshot-niko-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define NIKO_Y ((13 * 16) * 2)

#include <filesystem>
#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
#include <process.h>
#else
#include <unistd.h>
Expand Down Expand Up @@ -40,10 +40,10 @@ RB_METHOD(nikoStart) {
auto pwd = std::filesystem::current_path();
std::string dir = pwd.string();

#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
dir += "\\_______.exe";
#endif
#ifdef SDL_PLATFORM_LINUX
#ifdef __LINUX__
dir += "/_______";
#endif

Expand All @@ -53,7 +53,7 @@ RB_METHOD(nikoStart) {
const_cast<char*>(dir.c_str()), const_cast<char*>(window_x.c_str()),
const_cast<char*>(window_y.c_str())};

#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
spawnv(_P_DETACH, dir.c_str(), args);
#else
pid_t pid = fork();
Expand Down
6 changes: 3 additions & 3 deletions binding/oneshot-wallpaper-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
static bool setTile = false;
static bool isCached = false;
#else
#ifdef SDL_PLATFORM_APPLE
#ifdef __APPLE__
#include "mac-desktop.h"
static bool isCached = false;
#else
Expand Down Expand Up @@ -253,7 +253,7 @@ RB_METHOD(wallpaperSet)

Debug() << "Setting wallpaper to " << path;

#ifdef SDL_PLATFORM_APPLE
#ifdef __APPLE__
if (!isCached) {
MacDesktop::CacheCurrentBackground();
isCached = true;
Expand Down Expand Up @@ -391,7 +391,7 @@ RB_METHOD(wallpaperReset)
RegCloseKey(hKey);
}
#else
#ifdef SDL_PLATFORM_APPLE
#ifdef __APPLE__
MacDesktop::ResetBackground();
#else
desktopEnvironmentInit();
Expand Down
1 change: 0 additions & 1 deletion macos/views/TouchBar.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

#import <AppKit/AppKit.h>
#import <SDL_syswm.h>
#import <SDL_events.h>
#import <SDL_timer.h>
#import <SDL_scancode.h>
Expand Down
8 changes: 4 additions & 4 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ void Config::read(int argc, char *argv[]) {
{"frameSkip", false},
{"syncToRefreshrate", false},
{"solidFonts", json::array({})},
#if defined(SDL_PLATFORM_APPLE) && defined(__aarch64__)
#if defined(__APPLE__) && defined(__aarch64__)
{"preferMetalRenderer", true},
#else
{"preferMetalRenderer", false},
#endif
{"subImageFix", false},
#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
{"enableBlitting", false},
#else
{"enableBlitting", true},
Expand Down Expand Up @@ -295,7 +295,7 @@ try { exp } catch (...) {}
for (std::string & solidFont : solidFonts)
std::transform(solidFont.begin(), solidFont.end(), solidFont.begin(),
[](unsigned char c) { return std::tolower(c); });
#ifdef SDL_PLATFORM_APPLE
#ifdef __APPLE__
SET_OPT(preferMetalRenderer, boolean);
#endif
SET_OPT(subImageFix, boolean);
Expand Down Expand Up @@ -342,7 +342,7 @@ try { exp } catch (...) {}
// Determine whether to open a console window on... Windows
winConsole = getEnvironmentBool("MKXPZ_WINDOWS_CONSOLE", editor.debug);

#ifdef SDL_PLATFORM_APPLE
#ifdef __APPLE__
// Determine whether to use the Metal renderer on macOS
// Environment variable takes priority over the json setting
preferMetalRenderer = isMetalSupported() && getEnvironmentBool("MKXPZ_MACOS_METAL", preferMetalRenderer);
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem/filesystemImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ std::string filesystemImpl::normalizePath(const char *path, bool preferred, bool
for (size_t i = 0; i < ret.length(); i++) {
char sep;
char sep_alt;
#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
if (preferred) {
sep = '\\';
sep_alt = '/';
Expand Down
1 change: 0 additions & 1 deletion src/filesystem/filesystemImplApple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

#import <AppKit/AppKit.h>
#import <SDL3/SDL_syswm.h>

#import <SDL3/SDL_filesystem.h>

Expand Down
8 changes: 4 additions & 4 deletions src/net/httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ using socket_t = int;
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "cryptui.lib")
#endif
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(SDL_PLATFORM_APPLE)
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__)
#include <TargetConditionals.h>
#if TARGET_OS_OSX
#include <CoreFoundation/CoreFoundation.h>
Expand Down Expand Up @@ -3281,7 +3281,7 @@ inline void get_remote_ip_and_port(socket_t sock, std::string &ip, int &port) {
if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == 0) {
port = ucred.pid;
}
#elif defined(SOL_LOCAL) && defined(SO_PEERPID) // SDL_PLATFORM_APPLE
#elif defined(SOL_LOCAL) && defined(SO_PEERPID) // __APPLE__
pid_t pid;
socklen_t len = sizeof(pid);
if (getsockopt(sock, SOL_LOCAL, SO_PEERPID, &pid, &len) == 0) {
Expand Down Expand Up @@ -4804,7 +4804,7 @@ inline bool load_system_certs_on_windows(X509_STORE *store) {

return result;
}
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(SDL_PLATFORM_APPLE)
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__)
#if TARGET_OS_OSX
template <typename T>
using CFObjectPtr =
Expand Down Expand Up @@ -8524,7 +8524,7 @@ inline bool SSLClient::load_certs() {
#ifdef _WIN32
loaded =
detail::load_system_certs_on_windows(SSL_CTX_get_cert_store(ctx_));
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(SDL_PLATFORM_APPLE)
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__)
#if TARGET_OS_OSX
loaded = detail::load_system_certs_on_macos(SSL_CTX_get_cert_store(ctx_));
#endif // TARGET_OS_OSX
Expand Down
5 changes: 2 additions & 3 deletions src/oneshot/oneshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
#include <mmsystem.h>
#include <security.h>
#include <shlobj.h>
#include <SDL3/SDL_syswm.h>
#elif defined SDL_PLATFORM_APPLE || __linux__
#elif defined __APPLE__ || __linux__
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
#include <dlfcn.h>

#ifdef SDL_PLATFORM_APPLE
#ifdef __APPLE__
#define OS_OSX
#include <dispatch/dispatch.h>
#else
Expand Down
4 changes: 2 additions & 2 deletions src/system/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#define MKXPZ_PLATFORM_MACOS 1
#define MKXPZ_PLATFORM_LINUX 2

#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
#define MKXPZ_PLATFORM MKXPZ_PLATFORM_WINDOWS
#elif defined SDL_PLATFORM_APPLE
#elif defined __APPLE__
#define MKXPZ_PLATFORM MKXPZ_PLATFORM_MACOS
#elif defined __linux__
#define MKXPZ_PLATFORM MKXPZ_PLATFORM_LINUX
Expand Down
8 changes: 4 additions & 4 deletions src/system/systemImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "system.h"

#if defined(SDL_PLATFORM_WIN32)
#if defined(__WIN32__)
#include <stdlib.h>
#include <windows.h>
#else
Expand All @@ -20,7 +20,7 @@

std::string systemImpl::getSystemLanguage() {
static char buf[50] = {0};
#if defined(SDL_PLATFORM_WIN32)
#if defined(__WIN32__)
wchar_t wbuf[50] = {0};
LANGID lid = GetUserDefaultLangID();
LCIDToLocaleName(lid, wbuf, sizeof(wbuf), 0);
Expand All @@ -30,7 +30,7 @@ std::string systemImpl::getSystemLanguage() {
#endif

for (int i = 0; (size_t)i < strlen(buf); i++) {
#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
if (buf[i] == '-') {
buf[i] = '_';
#else
Expand All @@ -45,7 +45,7 @@ std::string systemImpl::getSystemLanguage() {

std::string systemImpl::getUserName() {

#ifdef SDL_PLATFORM_WIN32
#ifdef __WIN32__
// The Ruby binding gets the username from the environment loaded
// with Ruby instead, should fix getting it from WinAPI at some point
return std::string("unused");
Expand Down
2 changes: 1 addition & 1 deletion src/util/string-util.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef STRING_UTIL_H
#define STRING_UTIL_H

#ifndef SDL_PLATFORM_APPLE
#ifndef __APPLE__

#include <string>

Expand Down
4 changes: 2 additions & 2 deletions src/util/win-consoleutils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if SDL_PLATFORM_WIN32
#if __WIN32__

#include "win-consoleutils.h"

Expand Down Expand Up @@ -67,4 +67,4 @@ static int openStdHandle(const DWORD &nStdHandle)
return _open_osfhandle((intptr_t)handle, _O_TEXT);
}

#endif // SDL_PLATFORM_WIN32
#endif // __WIN32__
Loading

0 comments on commit 08290b9

Please sign in to comment.