Use SDL to detect screen dimensions
Supports macOS, remove dependency on X11
This commit is contained in:
parent
d77166b3fe
commit
6896308451
|
@ -19,11 +19,6 @@ include(cmake/FindSDL2_mixer.cmake)
|
|||
include(cmake/FindCCache.cmake)
|
||||
include(cmake/Findcppcheck.cmake)
|
||||
|
||||
if (NOT WIN32)
|
||||
include(FindX11)
|
||||
include(cmake/FindCheck.cmake)
|
||||
endif (NOT WIN32)
|
||||
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/src/config.h.in"
|
||||
"${PROJECT_BINARY_DIR}/config.h"
|
||||
|
@ -73,11 +68,6 @@ include_directories(
|
|||
${SDL2_MIXER_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
if (NOT WIN32)
|
||||
include_directories(
|
||||
${X11_INCLUDE_DIR}
|
||||
)
|
||||
endif (NOT WIN32)
|
||||
if (CHECK_FOUND)
|
||||
include_directories(
|
||||
${CHECK_INCLUDE_DIR}
|
||||
|
@ -163,12 +153,6 @@ else (NOT PHYSFS_FOUND)
|
|||
)
|
||||
endif (NOT PHYSFS_FOUND)
|
||||
|
||||
if (NOT WIN32)
|
||||
target_link_libraries(breakhack
|
||||
${X11_LIBRARIES}
|
||||
)
|
||||
endif (NOT WIN32)
|
||||
|
||||
if (MSVC)
|
||||
set_target_properties(breakhack PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
|
||||
set_target_properties(breakhack PROPERTIES COMPILE_DEFINITIONS_DEBUG "_CONSOLE")
|
||||
|
|
13
src/main.c
13
src/main.c
|
@ -92,6 +92,13 @@ static
|
|||
bool initSDL(void)
|
||||
{
|
||||
int imgFlags = IMG_INIT_PNG;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
|
||||
{
|
||||
error("Could not initiate SDL2: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
Dimension dim = getScreenDimensions();
|
||||
|
||||
if (dim.height > 1080) {
|
||||
|
@ -104,12 +111,6 @@ bool initSDL(void)
|
|||
info("Scaling by %f", renderScale);
|
||||
}
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
|
||||
{
|
||||
error("Could not initiate SDL2: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( (IMG_Init(imgFlags) & imgFlags) == 0 ) {
|
||||
error("Unable to initiate img loading: %s",
|
||||
IMG_GetError());
|
||||
|
|
|
@ -17,28 +17,20 @@
|
|||
*/
|
||||
|
||||
#include "defines.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <X11/Xlib.h>
|
||||
#else // _WIN32
|
||||
#include <windows.h>
|
||||
#endif // _WIN32
|
||||
#include <stdlib.h>
|
||||
#include <SDL_video.h>
|
||||
|
||||
#include "screenresolution.h"
|
||||
|
||||
Dimension getScreenDimensions(void)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
Display *d = XOpenDisplay(NULL);
|
||||
Screen *s = DefaultScreenOfDisplay(d);
|
||||
Dimension dim = (Dimension) { s->width, s->height };
|
||||
|
||||
free(d);
|
||||
free(s);
|
||||
#else // _WIN32
|
||||
Dimension dim = (Dimension) { GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) };
|
||||
#endif // _WIN32
|
||||
SDL_DisplayMode dm;
|
||||
if (SDL_GetCurrentDisplayMode(0, &dm) != 0)
|
||||
{
|
||||
error("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError());
|
||||
}
|
||||
Dimension dim = (Dimension) { dm.w, dm.h };
|
||||
|
||||
return dim;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue