Skip to content

Commit

Permalink
Fix GLFW runtime platform detection (#3863)
Browse files Browse the repository at this point in the history
* Fix GLFW runtime platform detection

* Add libwayland-dev package to workflows

* Add libxkbcommon-dev package to workflows

* Add libwayland-bin package to codeql.yml

* Add libwayland-client0 and libwayland-cursor0 packages to codeql.yml

* Use libwayland-dev in codeql.yml

* Add libxkbcommon-dev to codeql.yml

* Remove libwayland-bin from linux.yml and linux_examples.yml (libwayland-dev includes it as a dependency)

---------

Co-authored-by: Ray <raysan5@gmail.com>
  • Loading branch information
M374LX and raysan5 authored Mar 14, 2024
1 parent 42db6ba commit 9a8d73e
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 559 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: |
sudo apt-get update -qq
sudo apt-get install gcc-multilib
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-dev libwayland-bin libxkbcommon-dev
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-dev libxkbcommon-dev
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
run: |
sudo apt-get update -qq
sudo apt-get install gcc-multilib
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-bin
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-dev libxkbcommon-dev
mkdir build
cd build
mkdir ${{ env.RELEASE_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup Environment
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-bin
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-dev libxkbcommon-dev
- name: Build Library
run: |
Expand Down
16 changes: 10 additions & 6 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ RAYLIB_MODULE_RAYGUI_PATH ?= $(RAYLIB_SRC_PATH)/../../raygui/src
# Use external GLFW library instead of rglfw module
USE_EXTERNAL_GLFW ?= FALSE

# Enable support for both Wayland and X11 by default on Linux when using GLFW
GLFW_LINUX_ENABLE_WAYLAND ?= TRUE
GLFW_LINUX_ENABLE_X11 ?= TRUE

# PLATFORM_DESKTOP_SDL: It requires SDL library to be provided externally
# WARNING: Library is not included in raylib, it MUST be configured by users
SDL_INCLUDE_PATH ?= $(RAYLIB_SRC_PATH)/external/SDL2/include
SDL_LIBRARY_PATH ?= $(RAYLIB_SRC_PATH)/external/SDL2/lib

# Use Wayland display server protocol on Linux desktop (by default it uses X11 windowing system)
# NOTE: This variable is only used for PLATFORM_OS: LINUX
USE_WAYLAND_DISPLAY ?= FALSE

# Determine if the file has root access (only required to install raylib)
# "whoami" prints the name of the user that calls him (so, if it is the root user, "whoami" prints "root")
ROOT = $(shell whoami)
Expand Down Expand Up @@ -407,7 +407,11 @@ endif
# Use Wayland display on Linux desktop
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(PLATFORM_OS), LINUX)
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
ifeq ($(GLFW_LINUX_ENABLE_X11),TRUE)
CFLAGS += -D_GLFW_X11
endif

ifeq ($(GLFW_LINUX_ENABLE_WAYLAND),TRUE)
CFLAGS += -D_GLFW_WAYLAND
LDFLAGS += $(shell pkg-config wayland-client wayland-cursor wayland-egl xkbcommon --libs)

Expand Down Expand Up @@ -533,7 +537,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
endif
ifeq ($(PLATFORM_OS),LINUX)
LDLIBS = -lGL -lc -lm -lpthread -ldl -lrt
ifeq ($(USE_WAYLAND_DISPLAY),FALSE)
ifeq ($(GLFW_LINUX_ENABLE_X11),TRUE)
LDLIBS += -lX11
endif
# TODO: On ARM 32bit arch, miniaudio requires atomics library
Expand Down
474 changes: 17 additions & 457 deletions src/external/glfw/README.md

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/external/glfw/src/cocoa_init.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//========================================================================
// GLFW 3.4 macOS - www.glfw.org
// GLFW 3.4 macOS (modified for raylib) - www.glfw.org; www.raylib.com
//------------------------------------------------------------------------
// Copyright (c) 2009-2019 Camilla Löwy <elmindreda@glfw.org>
// Copyright (c) 2024 M374LX <wilsalx@gmail.com>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -175,7 +176,7 @@ static void createMenuBar(void)

// Create key code translation tables
//
static void createKeyTables(void)
static void createKeyTablesCocoa(void)
{
memset(_glfw.ns.keycodes, -1, sizeof(_glfw.ns.keycodes));
memset(_glfw.ns.scancodes, -1, sizeof(_glfw.ns.scancodes));
Expand Down Expand Up @@ -618,7 +619,7 @@ int _glfwInitCocoa(void)
name:NSTextInputContextKeyboardSelectionDidChangeNotification
object:nil];

createKeyTables();
createKeyTablesCocoa();

_glfw.ns.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
if (!_glfw.ns.eventSource)
Expand Down
3 changes: 2 additions & 1 deletion src/external/glfw/src/cocoa_monitor.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//========================================================================
// GLFW 3.4 macOS - www.glfw.org
// GLFW 3.4 macOS (modified for raylib) - www.glfw.org; www.raylib.com
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
// Copyright (c) 2024 M374LX <wilsalx@gmail.com>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down
28 changes: 14 additions & 14 deletions src/external/glfw/src/cocoa_window.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void updateCursorMode(_GLFWwindow* window)

// Make the specified window and its video mode active on its monitor
//
static void acquireMonitor(_GLFWwindow* window)
static void acquireMonitorCocoa(_GLFWwindow* window)
{
_glfwSetVideoModeCocoa(window->monitor, &window->videoMode);
const CGRect bounds = CGDisplayBounds(window->monitor->ns.displayID);
Expand All @@ -127,7 +127,7 @@ static void acquireMonitor(_GLFWwindow* window)

// Remove the window and restore the original video mode
//
static void releaseMonitor(_GLFWwindow* window)
static void releaseMonitorCocoa(_GLFWwindow* window)
{
if (window->monitor->window != window)
return;
Expand Down Expand Up @@ -158,7 +158,7 @@ static int translateFlags(NSUInteger flags)

// Translates a macOS keycode to a GLFW keycode
//
static int translateKey(unsigned int key)
static int translateKeyCocoa(unsigned int key)
{
if (key >= sizeof(_glfw.ns.keycodes) / sizeof(_glfw.ns.keycodes[0]))
return GLFW_KEY_UNKNOWN;
Expand Down Expand Up @@ -277,15 +277,15 @@ - (void)windowDidMove:(NSNotification *)notification
- (void)windowDidMiniaturize:(NSNotification *)notification
{
if (window->monitor)
releaseMonitor(window);
releaseMonitorCocoa(window);

_glfwInputWindowIconify(window, GLFW_TRUE);
}

- (void)windowDidDeminiaturize:(NSNotification *)notification
{
if (window->monitor)
acquireMonitor(window);
acquireMonitorCocoa(window);

_glfwInputWindowIconify(window, GLFW_FALSE);
}
Expand Down Expand Up @@ -561,7 +561,7 @@ - (void)updateTrackingAreas

- (void)keyDown:(NSEvent *)event
{
const int key = translateKey([event keyCode]);
const int key = translateKeyCocoa([event keyCode]);
const int mods = translateFlags([event modifierFlags]);

_glfwInputKey(window, key, [event keyCode], GLFW_PRESS, mods);
Expand All @@ -574,7 +574,7 @@ - (void)flagsChanged:(NSEvent *)event
int action;
const unsigned int modifierFlags =
[event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask;
const int key = translateKey([event keyCode]);
const int key = translateKeyCocoa([event keyCode]);
const int mods = translateFlags(modifierFlags);
const NSUInteger keyFlag = translateKeyToModifierFlag(key);

Expand All @@ -593,7 +593,7 @@ - (void)flagsChanged:(NSEvent *)event

- (void)keyUp:(NSEvent *)event
{
const int key = translateKey([event keyCode]);
const int key = translateKeyCocoa([event keyCode]);
const int mods = translateFlags([event modifierFlags]);
_glfwInputKey(window, key, [event keyCode], GLFW_RELEASE, mods);
}
Expand Down Expand Up @@ -966,7 +966,7 @@ GLFWbool _glfwCreateWindowCocoa(_GLFWwindow* window,
{
_glfwShowWindowCocoa(window);
_glfwFocusWindowCocoa(window);
acquireMonitor(window);
acquireMonitorCocoa(window);

if (wndconfig->centerCursor)
_glfwCenterCursorInContentArea(window);
Expand Down Expand Up @@ -996,7 +996,7 @@ void _glfwDestroyWindowCocoa(_GLFWwindow* window)
[window->ns.object orderOut:nil];

if (window->monitor)
releaseMonitor(window);
releaseMonitorCocoa(window);

if (window->context.destroy)
window->context.destroy(window);
Expand Down Expand Up @@ -1083,7 +1083,7 @@ void _glfwSetWindowSizeCocoa(_GLFWwindow* window, int width, int height)
if (window->monitor)
{
if (window->monitor->window == window)
acquireMonitor(window);
acquireMonitorCocoa(window);
}
else
{
Expand Down Expand Up @@ -1252,7 +1252,7 @@ void _glfwSetWindowMonitorCocoa(_GLFWwindow* window,
if (monitor)
{
if (monitor->window == window)
acquireMonitor(window);
acquireMonitorCocoa(window);
}
else
{
Expand All @@ -1270,7 +1270,7 @@ void _glfwSetWindowMonitorCocoa(_GLFWwindow* window,
}

if (window->monitor)
releaseMonitor(window);
releaseMonitorCocoa(window);

_glfwInputWindowMonitor(window, monitor);

Expand Down Expand Up @@ -1308,7 +1308,7 @@ void _glfwSetWindowMonitorCocoa(_GLFWwindow* window,
[window->ns.object setLevel:NSMainMenuWindowLevel + 1];
[window->ns.object setHasShadow:NO];

acquireMonitor(window);
acquireMonitorCocoa(window);
}
else
{
Expand Down
19 changes: 10 additions & 9 deletions src/external/glfw/src/null_window.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//========================================================================
// GLFW 3.4 - www.glfw.org
// GLFW 3.4 (modified for raylib) - www.glfw.org; www.raylib.com
//------------------------------------------------------------------------
// Copyright (c) 2016 Google Inc.
// Copyright (c) 2016-2019 Camilla Löwy <elmindreda@glfw.org>
// Copyright (c) 2024 M374LX <wilsalx@gmail.com>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -59,12 +60,12 @@ static void fitToMonitor(_GLFWwindow* window)
window->null.height = mode.height;
}

static void acquireMonitor(_GLFWwindow* window)
static void acquireMonitorNull(_GLFWwindow* window)
{
_glfwInputMonitorWindow(window->monitor, window);
}

static void releaseMonitor(_GLFWwindow* window)
static void releaseMonitorNull(_GLFWwindow* window)
{
if (window->monitor->window != window)
return;
Expand Down Expand Up @@ -147,7 +148,7 @@ GLFWbool _glfwCreateWindowNull(_GLFWwindow* window,
{
_glfwShowWindowNull(window);
_glfwFocusWindowNull(window);
acquireMonitor(window);
acquireMonitorNull(window);

if (wndconfig->centerCursor)
_glfwCenterCursorInContentArea(window);
Expand All @@ -168,7 +169,7 @@ GLFWbool _glfwCreateWindowNull(_GLFWwindow* window,
void _glfwDestroyWindowNull(_GLFWwindow* window)
{
if (window->monitor)
releaseMonitor(window);
releaseMonitorNull(window);

if (_glfw.null.focusedWindow == window)
_glfw.null.focusedWindow = NULL;
Expand Down Expand Up @@ -203,14 +204,14 @@ void _glfwSetWindowMonitorNull(_GLFWwindow* window,
}

if (window->monitor)
releaseMonitor(window);
releaseMonitorNull(window);

_glfwInputWindowMonitor(window, monitor);

if (window->monitor)
{
window->null.visible = GLFW_TRUE;
acquireMonitor(window);
acquireMonitorNull(window);
fitToMonitor(window);
}
else
Expand Down Expand Up @@ -340,7 +341,7 @@ void _glfwIconifyWindowNull(_GLFWwindow* window)
_glfwInputWindowIconify(window, GLFW_TRUE);

if (window->monitor)
releaseMonitor(window);
releaseMonitorNull(window);
}
}

Expand All @@ -352,7 +353,7 @@ void _glfwRestoreWindowNull(_GLFWwindow* window)
_glfwInputWindowIconify(window, GLFW_FALSE);

if (window->monitor)
acquireMonitor(window);
acquireMonitorNull(window);
}
else if (window->null.maximized)
{
Expand Down
12 changes: 2 additions & 10 deletions src/external/glfw/src/platform.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//========================================================================
// GLFW 3.4 - www.glfw.org
// GLFW 3.4 (modified for raylib) - www.glfw.org; www.raylib.com
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2018 Camilla Löwy <elmindreda@glfw.org>
// Copyright (c) 2024 M374LX <wilsalx@gmail.com>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -74,15 +75,6 @@ GLFWbool _glfwSelectPlatform(int desiredID, _GLFWplatform* platform)
return GLFW_FALSE;
}

// Only allow the Null platform if specifically requested
if (desiredID == GLFW_PLATFORM_NULL)
return _glfwConnectNull(desiredID, platform);
else if (count == 0)
{
_glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "This binary only supports the Null platform");
return GLFW_FALSE;
}

#if defined(_GLFW_WAYLAND) && defined(_GLFW_X11)
if (desiredID == GLFW_ANY_PLATFORM)
{
Expand Down
7 changes: 4 additions & 3 deletions src/external/glfw/src/win32_init.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//========================================================================
// GLFW 3.4 Win32 - www.glfw.org
// GLFW 3.4 Win32 (modified for raylib) - www.glfw.org; www.raylib.com
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
// Copyright (c) 2024 M374LX <wilsalx@gmail.com>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -195,7 +196,7 @@ static void freeLibraries(void)

// Create key code translation tables
//
static void createKeyTables(void)
static void createKeyTablesWin32(void)
{
int scancode;

Expand Down Expand Up @@ -685,7 +686,7 @@ int _glfwInitWin32(void)
if (!loadLibraries())
return GLFW_FALSE;

createKeyTables();
createKeyTablesWin32();
_glfwUpdateKeyNamesWin32();

if (_glfwIsWindows10Version1703OrGreaterWin32())
Expand Down
Loading

0 comments on commit 9a8d73e

Please sign in to comment.