medfall

A super great game engine
Log | Files | Refs

commit d41d7cb550e2e997c41f9be10955b55e45f1d408
parent c1b8c1c2057aea2af4c65f8a4d820a073b9d7edf
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat Aug 19 10:35:29 +0300

Update GLFW to git master. Adds raw input and dynamic loading of some X libs

Diffstat:
libs/glfw.lua | 11++++++-----
libs/glfw/COPYING.txt | 4++--
libs/glfw/README.md | 222+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
libs/glfw/include/GLFW/glfw3.h | 1419++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
libs/glfw/include/GLFW/glfw3native.h | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
libs/glfw/src/cocoa_init.m | 283++++++++++++++++++++++++++++++++++++-------------------------------------------
libs/glfw/src/cocoa_joystick.h | 28+++++++++-------------------
libs/glfw/src/cocoa_joystick.m | 614++++++++++++++++++++++++++++++++++++-------------------------------------------
libs/glfw/src/cocoa_monitor.m | 206+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
libs/glfw/src/cocoa_platform.h | 47++++++++++++++++++++++++++++++-----------------
libs/glfw/src/cocoa_time.cc | 8++++----
libs/glfw/src/cocoa_window.m | 384+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
libs/glfw/src/context.cc | 30+++++++++++++++---------------
libs/glfw/src/egl_context.cc | 123++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
libs/glfw/src/egl_context.h | 81++++++++++++++++++++++++++++++++++++++++++-------------------------------------
libs/glfw/src/glx_context.cc | 59+++++++++++++++++++++++++++++++++--------------------------
libs/glfw/src/glx_context.h | 17++++++++---------
libs/glfw/src/init.cc | 241+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
libs/glfw/src/input.cc | 567++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
libs/glfw/src/internal.h | 543++++++++++++++++++++++++++++++++++++-------------------------------------------
libs/glfw/src/linux_joystick.cc | 431++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
libs/glfw/src/linux_joystick.h | 44+++++++++++++++++++-------------------------
libs/glfw/src/mappings.h | 230+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
libs/glfw/src/mir_init.cc | 272++++++++++++++++++++++++++++++++++++++++---------------------------------------
libs/glfw/src/mir_monitor.cc | 127+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
libs/glfw/src/mir_platform.h | 51+++++++++++++++++++++++++++------------------------
libs/glfw/src/mir_window.cc | 430++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
libs/glfw/src/monitor.cc | 112+++++++++++++++++++++++++++----------------------------------------------------
libs/glfw/src/nsgl_context.h | 8++------
libs/glfw/src/nsgl_context.m | 111+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
libs/glfw/src/osmesa_context.cc | 368+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
libs/glfw/src/osmesa_context.h | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
libs/glfw/src/posix_thread.cc | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
libs/glfw/src/posix_thread.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
libs/glfw/src/posix_time.cc | 16++++++++--------
libs/glfw/src/posix_time.h | 14+++++---------
libs/glfw/src/posix_tls.cc | 68--------------------------------------------------------------------
libs/glfw/src/posix_tls.h | 49-------------------------------------------------
libs/glfw/src/vulkan.cc | 118+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
libs/glfw/src/wgl_context.cc | 152+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
libs/glfw/src/wgl_context.h | 39++++++++++++++++++++-------------------
libs/glfw/src/win32_init.cc | 351++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
libs/glfw/src/win32_joystick.cc | 541++++++++++++++++++++++++++++++++++++++-----------------------------------------
libs/glfw/src/win32_joystick.h | 18+++++-------------
libs/glfw/src/win32_monitor.cc | 237+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
libs/glfw/src/win32_platform.h | 106+++++++++++++++++++++++++++++++++++++++++++------------------------------------
libs/glfw/src/win32_thread.cc | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
libs/glfw/src/win32_time.cc | 18+++++++++---------
libs/glfw/src/win32_tls.cc | 69---------------------------------------------------------------------
libs/glfw/src/win32_window.cc | 409+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
libs/glfw/src/window.cc | 161++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
libs/glfw/src/wl_init.cc | 434+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
libs/glfw/src/wl_monitor.cc | 137++++++++++++++++++-------------------------------------------------------------
libs/glfw/src/wl_platform.h | 41+++++++++++++++--------------------------
libs/glfw/src/wl_window.cc | 122++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
libs/glfw/src/x11_init.cc | 318++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
libs/glfw/src/x11_monitor.cc | 260+++++++++++++++++++++++++++++++++++++++++--------------------------------------
libs/glfw/src/x11_platform.h | 166++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
libs/glfw/src/x11_window.cc | 925++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
libs/glfw/src/xkb_unicode.cc | 61++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
libs/glfw/src/xkb_unicode.h | 7+------
make.lua | 2+-
62 files changed, 8153 insertions(+), 4227 deletions(-)
diff --git a/libs/glfw.lua b/libs/glfw.lua @@ -6,8 +6,8 @@ lib( "glfw", { if OS == "windows" then lib( "glfw", { "libs/glfw/src/win32_init", "libs/glfw/src/win32_monitor", "libs/glfw/src/win32_window", - "libs/glfw/src/win32_joystick", "libs/glfw/src/win32_time", "libs/glfw/src/win32_tls", - "libs/glfw/src/wgl_context", "libs/glfw/src/egl_context", + "libs/glfw/src/win32_joystick", "libs/glfw/src/win32_time", "libs/glfw/src/win32_thread", + "libs/glfw/src/wgl_context", "libs/glfw/src/egl_context", "libs/glfw/src/osmesa_context", } ) obj_cxxflags( "libs/glfw/src/%", "/c /O2 /TC /D_GLFW_WIN32 /wd4152 /wd4204 /wd4244" ) -- compile as c @@ -15,15 +15,16 @@ elseif OS == "linux" then lib( "glfw", { "libs/glfw/src/x11_init", "libs/glfw/src/x11_monitor", "libs/glfw/src/x11_window", "libs/glfw/src/xkb_unicode", "libs/glfw/src/linux_joystick", "libs/glfw/src/posix_time", - "libs/glfw/src/posix_tls", "libs/glfw/src/glx_context", "libs/glfw/src/egl_context", + "libs/glfw/src/posix_thread", "libs/glfw/src/glx_context", "libs/glfw/src/egl_context", + "libs/glfw/src/osmesa_context", } ) obj_replace_cxxflags( "libs/glfw/src/%", "-c -x c -O2 -D_GLFW_X11" ) elseif OS == "macos" then lib( "glfw", { "libs/glfw/src/cocoa_init", "libs/glfw/src/cocoa_monitor", "libs/glfw/src/cocoa_window", - "libs/glfw/src/cocoa_joystick", "libs/glfw/src/cocoa_time", "libs/glfw/src/posix_tls", - "libs/glfw/src/nsgl_context", + "libs/glfw/src/cocoa_joystick", "libs/glfw/src/cocoa_time", "libs/glfw/src/posix_thread", + "libs/glfw/src/nsgl_context", "libs/glfw/src/osmesa_context", } ) obj_replace_cxxflags( "libs/glfw/src/%", "-c -x c -O2 -D_GLFW_COCOA -mmacosx-version-min=10.9" ) diff --git a/libs/glfw/COPYING.txt b/libs/glfw/COPYING.txt @@ -1,5 +1,5 @@ -Copyright (c) 2002-2006 Marcus Geelnard -Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +Copyright (c) 2002-2006 Marcus Geelnard +Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/libs/glfw/README.md b/libs/glfw/README.md @@ -10,23 +10,36 @@ GLFW is an Open Source, multi-platform library for OpenGL, OpenGL ES and Vulkan application development. It provides a simple, platform-independent API for creating windows, contexts and surfaces, reading input, handling events, etc. +GLFW natively supports Windows, macOS and Linux and other Unix-like systems. +Experimental implementations for the Wayland protocol and the Mir display server +are available but not yet officially supported. + GLFW is licensed under the [zlib/libpng -license](https://opensource.org/licenses/Zlib). +license](http://www.glfw.org/license.html). -This is version 3.2.1, which adds support for statically linking the Vulkan -loader and fixes for a number of bugs that together affect all supported -platforms. +The latest stable release is version 3.2.1. See the [downloads](http://www.glfw.org/download.html) page for details and files, or fetch the `latest` branch, which always points to the latest stable release. Each release starting with 3.0 also has a corresponding [annotated tag](https://github.com/glfw/glfw/releases) with source and binary archives. +The [version history](http://www.glfw.org/changelog.html) lists all user-visible +changes for every release. + +This is a development branch for version 3.3, which is _not yet described_. +Pre-release documentation is available [here](http://www.glfw.org/docs/3.3/). + +The `master` branch is the stable integration branch and _should_ always compile +and run on all supported platforms, although details of newly added features may +change until they have been included in a release. New features and many bug +fixes live in [other branches](https://github.com/glfw/glfw/branches/all) until +they are stable enough to merge. If you are new to GLFW, you may find the -[tutorial](http://www.glfw.org/docs/latest/quick.html) for GLFW -3 useful. If you have used GLFW 2 in the past, there is a -[transition guide](http://www.glfw.org/docs/latest/moving.html) for moving to -the GLFW 3 API. +[tutorial](http://www.glfw.org/docs/latest/quick.html) for GLFW 3 useful. If +you have used GLFW 2 in the past, there is a [transition +guide](http://www.glfw.org/docs/latest/moving.html) for moving to the GLFW +3 API. ## Compiling GLFW @@ -36,30 +49,36 @@ does not need the headers for any context creation API (WGL, GLX, EGL, NSGL) or rendering API (OpenGL, OpenGL ES, Vulkan) to enable support for them. GLFW supports compilation on Windows with Visual C++ 2010 and later, MinGW and -MinGW-w64, on OS X with Clang and on Linux and other Unix-like systems with GCC +MinGW-w64, on macOS with Clang and on Linux and other Unix-like systems with GCC and Clang. It will likely compile in other environments as well, but this is not regularly tested. -There are also [pre-compiled Windows -binaries](http://www.glfw.org/download.html) available for all compilers -supported on that platform. +There are [pre-compiled Windows binaries](http://www.glfw.org/download.html) +available for all supported compilers. -See the [compilation guide](http://www.glfw.org/docs/latest/compile.html) in the -documentation for more information. +See the [compilation guide](http://www.glfw.org/docs/latest/compile.html) for +more information about how to compile GLFW yourself. ## Using GLFW -See the [building application guide](http://www.glfw.org/docs/latest/build.html) -guide in the documentation for more information. +See the [documentation](http://www.glfw.org/docs/latest/) for tutorials, guides +and the API reference. + + +## Contributing to GLFW + +See the [contribution +guide](https://github.com/glfw/glfw/blob/master/.github/CONTRIBUTING.md) for +more information. ## System requirements -GLFW supports Windows XP and later, OS X 10.7 Lion and later, and Linux and -other Unix-like systems with the X Window System. Experimental implementations -for the Wayland protocol and the Mir display server are available but not yet -officially supported. +GLFW supports Windows XP and later and macOS 10.7 and later. Linux and other +Unix-like systems running the X Window System are supported even without +a desktop environment or modern extensions, although some features require +a running window or clipboard manager. The OSMesa backend requires Mesa 6.3. See the [compatibility guide](http://www.glfw.org/docs/latest/compat.html) in the documentation for more information. @@ -69,6 +88,9 @@ in the documentation for more information. GLFW itself depends only on the headers and libraries for your window system. +The (experimental) Wayland backend also depends on the `extra-cmake-modules` +package, which is used to generated Wayland protocol headers. + The examples and test programs depend on a number of tiny libraries. These are located in the `deps/` directory. @@ -80,13 +102,16 @@ located in the `deps/` directory. [glad](https://github.com/Dav1dde/glad) for examples using modern OpenGL - [linmath.h](https://github.com/datenwolf/linmath.h) for linear algebra in examples + - [Nuklear](https://github.com/vurtun/nuklear) for test and example UI + - [stb\_image\_write](https://github.com/nothings/stb) for writing images to disk - [Vulkan headers](https://www.khronos.org/registry/vulkan/) for Vulkan tests The Vulkan example additionally requires the Vulkan SDK to be installed, or it -will not be included in the build. +will not be included in the build. On macOS you need to provide the path to the +MoltenVK SDK manually as it has no standard installation location. -The documentation is generated with [Doxygen](http://doxygen.org/). If CMake -does not find Doxygen, the documentation will not be generated when you build. +The documentation is generated with [Doxygen](http://doxygen.org/) if CMake can +find that tool. ## Reporting bugs @@ -99,34 +124,113 @@ information on what to include when reporting a bug. ## Changelog - - Added on-demand loading of Vulkan and context creation API libraries - - Added `_GLFW_VULKAN_STATIC` build macro to make the library use the Vulkan - loader linked statically into the application (#820) - - Bugfix: Single compilation unit builds failed due to naming conflicts (#783) - - Bugfix: The range checks for `glfwSetCursorPos` used the wrong minimum (#773) - - Bugfix: Defining `GLFW_INCLUDE_VULKAN` when compiling the library did not - fail with the expected error message (#823) - - Bugfix: Inherited value of `CMAKE_MODULE_PATH` was clobbered (#822) - - [Win32] Bugfix: `glfwSetClipboardString` created an unnecessary intermediate - copy of the string - - [Win32] Bugfix: Examples failed to build on Visual C++ 2010 due to C99 in - `linmath.h` (#785) - - [Win32] Bugfix: The first shown window ignored the `GLFW_MAXIMIZED` hint - when the process was provided a `STARTUPINFO` (#780) - - [Cocoa] Bugfix: Event processing would segfault on some machines due to - a previous distributed notification listener not being fully - removed (#817,#826) - - [Cocoa] Bugfix: Some include statements were duplicated (#838) - - [X11] Bugfix: Window size limits were ignored if the minimum or maximum size - was set to `GLFW_DONT_CARE` (#805) - - [X11] Bugfix: Input focus was set before window was visible, causing - `BadMatch` on some non-reparenting WMs (#789,#798) - - [X11] Bugfix: `glfwGetWindowPos` and `glfwSetWindowPos` operated on the - window frame instead of the client area (#800) - - [WGL] Added reporting of errors from `WGL_ARB_create_context` extension - - [GLX] Bugfix: Dynamically loaded entry points were not verified - - [EGL] Added `lib` prefix matching between EGL and OpenGL ES library binaries - - [EGL] Bugfix: Dynamically loaded entry points were not verified +- Added `glfwGetError` function for querying the last error code and its + description (#970) +- Added `glfwUpdateGamepadMappings` function for importing gamepad mappings in + SDL\_GameControllerDB format (#900) +- Added `glfwJoystickIsGamepad` function for querying whether a joystick has + a gamepad mapping (#900) +- Added `glfwGetJoystickGUID` function for querying the SDL compatible GUID of + a joystick (#900) +- Added `glfwGetGamepadName` function for querying the name provided by the + gamepad mapping (#900) +- Added `glfwGetGamepadState` function, `GLFW_GAMEPAD_*` and `GLFWgamepadstate` + for retrieving gamepad input state (#900) +- Added `glfwRequestWindowAttention` function for requesting attention from the + user (#732,#988) +- Added `glfwGetKeyScancode` function that allows retrieving platform dependent + scancodes for keys (#830) +- Added `glfwSetWindowMaximizeCallback` and `GLFWwindowmaximizefun` for + receiving window maximization events (#778) +- Added `glfwSetWindowAttrib` function for changing window attributes (#537) +- Added `glfwGetJoystickHats` function for querying joystick hats + (#889,#906,#934) +- Added `glfwInitHint` and `glfwInitHintString` for setting initialization hints +- Added `glfwGetX11SelectionString` and `glfwSetX11SelectionString` + functions for accessing X11 primary selection (#894,#1056) +- Added headless [OSMesa](http://mesa3d.org/osmesa.html) backend (#850) +- Added definition of `GLAPIENTRY` to public header +- Added `GLFW_CENTER_CURSOR` window hint for controlling cursor centering + (#749,#842) +- Added `GLFW_JOYSTICK_HAT_BUTTONS` init hint (#889) +- Added macOS specific `GLFW_COCOA_RETINA_FRAMEBUFFER` window hint +- Added macOS specific `GLFW_COCOA_FRAME_AUTOSAVE` window hint (#195) +- Added macOS specific `GLFW_COCOA_GRAPHICS_SWITCHING` window hint (#377,#935) +- Added macOS specific `GLFW_COCOA_CHDIR_RESOURCES` init hint +- Added macOS specific `GLFW_COCOA_MENUBAR` init hint +- Added X11 specific `GLFW_X11_WM_CLASS_NAME` and `GLFW_X11_WM_CLASS_CLASS` init + hints (#893) +- Added `GLFW_INCLUDE_ES32` for including the OpenGL ES 3.2 header +- Added `GLFW_OSMESA_CONTEXT_API` for creating OpenGL contexts with + [OSMesa](https://www.mesa3d.org/osmesa.html) (#281) +- Removed `GLFW_USE_RETINA` compile-time option +- Removed `GLFW_USE_CHDIR` compile-time option +- Removed `GLFW_USE_MENUBAR` compile-time option +- Bugfix: Calling `glfwMaximizeWindow` on a full screen window was not ignored +- Bugfix: `GLFW_INCLUDE_VULKAN` could not be combined with the corresponding + OpenGL and OpenGL ES header macros +- Bugfix: `glfwGetInstanceProcAddress` returned `NULL` for + `vkGetInstanceProcAddr` when `_GLFW_VULKAN_STATIC` was enabled +- Bugfix: Invalid library paths were used in test and example CMake files (#930) +- Bugfix: The scancode for synthetic key release events was always zero +- [Win32] Added system error strings to relevant GLFW error descriptions (#733) +- [Win32] Moved to `WM_INPUT` for disabled cursor mode motion input (#125) +- [Win32] Removed XInput circular deadzone from joystick axis data (#1045) +- [Win32] Bugfix: Undecorated windows could not be iconified by the user (#861) +- [Win32] Bugfix: Deadzone logic could underflow with some controllers (#910) +- [Win32] Bugfix: Bitness test in `FindVulkan.cmake` was VS specific (#928) +- [Win32] Bugfix: `glfwVulkanSupported` emitted an error on systems with + a loader but no ICD (#916) +- [Win32] Bugfix: Non-iconified full sreeen windows did not prevent screen + blanking or password enabled screensavers (#851) +- [Win32] Bugfix: Mouse capture logic lost secondary release messages (#954) +- [Win32] Bugfix: The 32-bit Vulkan loader library static was not searched for +- [Win32] Bugfix: Vulkan libraries have a new path as of SDK 1.0.42.0 (#956) +- [Win32] Bugfix: Monitors with no display devices were not enumerated (#960) +- [Win32] Bugfix: Monitor events were not emitted (#784) +- [Win32] Bugfix: The Cygwin DLL was installed to the wrong directory (#1035) +- [Win32] Bugfix: Normalization of axis data via XInput was incorrect (#1045) +- [X11] Moved to XI2 `XI_RawMotion` for disable cursor mode motion input (#125) +- [X11] Replaced `_GLFW_HAS_XF86VM` compile-time option with dynamic loading +- [X11] Bugfix: `glfwGetVideoMode` would segfault on Cygwin/X +- [X11] Bugfix: Dynamic X11 library loading did not use full sonames (#941) +- [X11] Bugfix: Window creation on 64-bit would read past top of stack (#951) +- [X11] Bugfix: XDND support had multiple non-conformance issues (#968) +- [X11] Bugfix: The RandR monitor path was disabled despite working RandR (#972) +- [X11] Bugfix: IM-duplicated key events would leak at low polling rates (#747) +- [X11] Bugfix: Gamma ramp setting via RandR did not validate ramp size +- [X11] Bugfix: Key name string encoding depended on current locale (#981,#983) +- [Linux] Moved to evdev for joystick input (#906,#1005) +- [Linux] Bugfix: Event processing did not detect joystick disconnection (#932) +- [Linux] Bugfix: The joystick device path could be truncated (#1025) +- [Linux] Bugfix: `glfwInit` would fail if inotify creation failed (#833) +- [Linux] Bugfix: `strdup` was used without any required feature macro (#1055) +- [Cocoa] Added support for Vulkan window surface creation via + [MoltenVK](https://moltengl.com/moltenvk/) (#870) +- [Cocoa] Added support for loading a `MainMenu.nib` when available +- [Cocoa] Bugfix: Disabling window aspect ratio would assert (#852) +- [Cocoa] Bugfix: Window creation failed to set first responder (#876,#883) +- [Cocoa] Bugfix: Removed use of deprecated `CGDisplayIOServicePort` function + (#165,#192,#508,#511) +- [Cocoa] Bugfix: Disabled use of deprecated `CGDisplayModeCopyPixelEncoding` + function on macOS 10.12+ +- [Cocoa] Bugfix: Running in AppSandbox would emit warnings (#816,#882) +- [Cocoa] Bugfix: Windows created after the first were not cascaded (#195) +- [Cocoa] Bugfix: Leaving video mode with `glfwSetWindowMonitor` would set + incorrect position and size (#748) +- [Cocoa] Bugfix: Iconified full screen windows could not be restored (#848) +- [Cocoa] Bugfix: Value range was ignored for joystick hats and buttons (#888) +- [Cocoa] Bugfix: Full screen framebuffer was incorrectly sized for some video + modes (#682) +- [Cocoa] Bugfix: A string object for IME was updated non-idiomatically (#1050) +- [WGL] Added support for `WGL_EXT_colorspace` for OpenGL ES contexts +- [WGL] Added support for `WGL_ARB_create_context_no_error` +- [GLX] Added support for `GLX_ARB_create_context_no_error` +- [GLX] Bugfix: Context creation could segfault if no GLXFBConfigs were + available (#1040) +- [EGL] Added support for `EGL_KHR_get_all_proc_addresses` (#871) +- [EGL] Added support for `EGL_KHR_context_flush_control` +- [EGL] Bugfix: The test for `EGL_RGB_BUFFER` was invalid ## Contact @@ -159,13 +263,18 @@ skills. - John Bartholomew - Niklas Behrens - Niklas Bergström + - Denis Bernard - Doug Binks - blanco + - Kyle Brenneman - Martin Capitanio + - David Carlier - Chi-kwan Chan + - Michał Cichoń - Lambert Clara - Andrew Corrigan - Noel Cower + - Jason Daly - Jarrod Davis - Olivier Delannoy - Paul R. Deppe @@ -175,8 +284,10 @@ skills. - Jonathan Dummer - Ralph Eastwood - Siavash Eliasi + - Felipe Ferreira - Michael Fogleman - Gerald Franz + - Mário Freitas - GeO4d - Marcus Geelnard - Eloi Marín Gratacós @@ -196,6 +307,7 @@ skills. - Cameron King - Peter Knut - Christoph Kubisch + - Konstantin Käfer - Eric Larson - Robin Leffmann - Glenn Lewis @@ -211,6 +323,7 @@ skills. - Bryce Mehring - Jonathan Mercier - Marcel Metz + - Liam Middlebrook - Jonathan Miller - Kenneth Miller - Bruce Mitchener @@ -219,12 +332,14 @@ skills. - Jon Morton - Pierre Moulon - Julian Møller + - Kristian Nielsen - Kamil Nowakowski - Ozzy - Andri Pálsson - Peoro - Braden Pellett - Arturo J. Pérez + - Anthony Pesch - Orson Peters - Emmanuel Gil Peyrot - Cyril Pichard @@ -247,6 +362,7 @@ skills. - Patrick Snape - Julian Squires - Johannes Stein + - Michael Stocker - Justin Stoecker - Elviss Strazdins - Nathan Sweet @@ -255,7 +371,9 @@ skills. - Arthur Tombs - Ioannis Tsakpinis - Samuli Tuomola + - Matthew Turner - urraka + - Elias Vanderstuyft - Jari Vetoniemi - Ricardo Vieira - Nicholas Vitovitch @@ -266,6 +384,8 @@ skills. - Jay Weisskopf - Frank Wille - yuriks + - Ryogo Yoshimura + - Andrey Zholos - Santi Zupancic - Jonas Ådahl - Lasse Öörni diff --git a/libs/glfw/include/GLFW/glfw3.h b/libs/glfw/include/GLFW/glfw3.h @@ -1,9 +1,9 @@ /************************************************************************* - * GLFW 3.2 - www.glfw.org + * GLFW 3.3 - www.glfw.org * A library for OpenGL, window and input *------------------------------------------------------------------------ * Copyright (c) 2002-2006 Marcus Geelnard - * Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> + * Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -47,32 +47,38 @@ extern "C" { * For more information about how to use this file, see @ref build_include. */ /*! @defgroup context Context reference + * @brief Functions and types related to OpenGL and OpenGL ES contexts. * * This is the reference documentation for OpenGL and OpenGL ES context related * functions. For more task-oriented information, see the @ref context_guide. */ /*! @defgroup vulkan Vulkan reference + * @brief Functions and types related to Vulkan. * * This is the reference documentation for Vulkan related functions and types. * For more task-oriented information, see the @ref vulkan_guide. */ /*! @defgroup init Initialization, version and error reference + * @brief Functions and types related to initialization and error handling. * * This is the reference documentation for initialization and termination of * the library, version management and error handling. For more task-oriented * information, see the @ref intro_guide. */ /*! @defgroup input Input reference + * @brief Functions and types related to input handling. * * This is the reference documentation for input related functions and types. * For more task-oriented information, see the @ref input_guide. */ /*! @defgroup monitor Monitor reference + * @brief Functions and types related to monitors. * * This is the reference documentation for monitor related functions and types. * For more task-oriented information, see the @ref monitor_guide. */ /*! @defgroup window Window reference + * @brief Functions and types related to windows. * * This is the reference documentation for window related functions and types, * including creation, deletion and event polling. For more task-oriented @@ -116,67 +122,97 @@ extern "C" { #endif /* CALLBACK */ /* Include because most Windows GLU headers need wchar_t and - * the OS X OpenGL header blocks the definition of ptrdiff_t by glext.h. + * the macOS OpenGL header blocks the definition of ptrdiff_t by glext.h. * Include it unconditionally to avoid surprising side-effects. */ #include <stddef.h> /* Include because it is needed by Vulkan and related functions. + * Include it unconditionally to avoid surprising side-effects. */ #include <stdint.h> -/* Include the chosen client API headers. +/* Include the chosen OpenGL or OpenGL ES headers. */ -#if defined(__APPLE__) - #if defined(GLFW_INCLUDE_GLCOREARB) +#if defined(GLFW_INCLUDE_ES1) + + #include <GLES/gl.h> + #if defined(GLFW_INCLUDE_GLEXT) + #include <GLES/glext.h> + #endif + +#elif defined(GLFW_INCLUDE_ES2) + + #include <GLES2/gl2.h> + #if defined(GLFW_INCLUDE_GLEXT) + #include <GLES2/gl2ext.h> + #endif + +#elif defined(GLFW_INCLUDE_ES3) + + #include <GLES3/gl3.h> + #if defined(GLFW_INCLUDE_GLEXT) + #include <GLES2/gl2ext.h> + #endif + +#elif defined(GLFW_INCLUDE_ES31) + + #include <GLES3/gl31.h> + #if defined(GLFW_INCLUDE_GLEXT) + #include <GLES2/gl2ext.h> + #endif + +#elif defined(GLFW_INCLUDE_ES32) + + #include <GLES3/gl32.h> + #if defined(GLFW_INCLUDE_GLEXT) + #include <GLES2/gl2ext.h> + #endif + +#elif defined(GLFW_INCLUDE_GLCOREARB) + + #if defined(__APPLE__) + #include <OpenGL/gl3.h> #if defined(GLFW_INCLUDE_GLEXT) #include <OpenGL/gl3ext.h> - #endif - #elif !defined(GLFW_INCLUDE_NONE) + #endif /*GLFW_INCLUDE_GLEXT*/ + + #else /*__APPLE__*/ + + #include <GL/glcorearb.h> + + #endif /*__APPLE__*/ + +#elif !defined(GLFW_INCLUDE_NONE) + + #if defined(__APPLE__) + #if !defined(GLFW_INCLUDE_GLEXT) #define GL_GLEXT_LEGACY #endif #include <OpenGL/gl.h> - #endif - #if defined(GLFW_INCLUDE_GLU) - #include <OpenGL/glu.h> - #endif -#else - #if defined(GLFW_INCLUDE_GLCOREARB) - #include <GL/glcorearb.h> - #elif defined(GLFW_INCLUDE_ES1) - #include <GLES/gl.h> - #if defined(GLFW_INCLUDE_GLEXT) - #include <GLES/glext.h> - #endif - #elif defined(GLFW_INCLUDE_ES2) - #include <GLES2/gl2.h> - #if defined(GLFW_INCLUDE_GLEXT) - #include <GLES2/gl2ext.h> - #endif - #elif defined(GLFW_INCLUDE_ES3) - #include <GLES3/gl3.h> - #if defined(GLFW_INCLUDE_GLEXT) - #include <GLES2/gl2ext.h> - #endif - #elif defined(GLFW_INCLUDE_ES31) - #include <GLES3/gl31.h> - #if defined(GLFW_INCLUDE_GLEXT) - #include <GLES2/gl2ext.h> + #if defined(GLFW_INCLUDE_GLU) + #include <OpenGL/glu.h> #endif - #elif defined(GLFW_INCLUDE_VULKAN) - #include <vulkan/vulkan.h> - #elif !defined(GLFW_INCLUDE_NONE) + + #else /*__APPLE__*/ + #include <GL/gl.h> #if defined(GLFW_INCLUDE_GLEXT) #include <GL/glext.h> #endif - #endif - #if defined(GLFW_INCLUDE_GLU) - #include <GL/glu.h> - #endif -#endif + #if defined(GLFW_INCLUDE_GLU) + #include <GL/glu.h> + #endif + + #endif /*__APPLE__*/ + +#endif /* OpenGL and OpenGL ES headers */ + +#if defined(GLFW_INCLUDE_VULKAN) + #include <vulkan/vulkan.h> +#endif /* Vulkan header */ #if defined(GLFW_DLL) && defined(_GLFW_BUILD_DLL) /* GLFW_DLL must be defined by applications that are linking against the DLL @@ -222,14 +258,14 @@ extern "C" { * backward-compatible. * @ingroup init */ -#define GLFW_VERSION_MINOR 2 +#define GLFW_VERSION_MINOR 3 /*! @brief The revision number of the GLFW library. * * This is incremented when a bug fix release is made that does not contain any * API changes. * @ingroup init */ -#define GLFW_VERSION_REVISION 1 +#define GLFW_VERSION_REVISION 0 /*! @} */ /*! @name Boolean values @@ -275,7 +311,25 @@ extern "C" { #define GLFW_REPEAT 2 /*! @} */ +/*! @defgroup hat_state Joystick hat states + * + * See [joystick hat input](@ref joystick_hat) for how these are used. + * + * @ingroup input + * @{ */ +#define GLFW_HAT_CENTERED 0 +#define GLFW_HAT_UP 1 +#define GLFW_HAT_RIGHT 2 +#define GLFW_HAT_DOWN 4 +#define GLFW_HAT_LEFT 8 +#define GLFW_HAT_RIGHT_UP (GLFW_HAT_RIGHT | GLFW_HAT_UP) +#define GLFW_HAT_RIGHT_DOWN (GLFW_HAT_RIGHT | GLFW_HAT_DOWN) +#define GLFW_HAT_LEFT_UP (GLFW_HAT_LEFT | GLFW_HAT_UP) +#define GLFW_HAT_LEFT_DOWN (GLFW_HAT_LEFT | GLFW_HAT_DOWN) +/*! @} */ + /*! @defgroup keys Keyboard keys + * @brief Keyboard key IDs. * * See [key input](@ref input_key) for how these are used. * @@ -430,6 +484,7 @@ extern "C" { /*! @} */ /*! @defgroup mods Modifier key flags + * @brief Modifier key flags. * * See [key input](@ref input_key) for how these are used. * @@ -452,6 +507,7 @@ extern "C" { /*! @} */ /*! @defgroup buttons Mouse buttons + * @brief Mouse button IDs. * * See [mouse button input](@ref input_mouse_button) for how these are used. * @@ -472,6 +528,7 @@ extern "C" { /*! @} */ /*! @defgroup joysticks Joysticks + * @brief Joystick IDs. * * See [joystick input](@ref joystick) for how these are used. * @@ -496,12 +553,66 @@ extern "C" { #define GLFW_JOYSTICK_LAST GLFW_JOYSTICK_16 /*! @} */ +/*! @defgroup gamepad_buttons Gamepad buttons + * @brief Gamepad buttons. + * + * See @ref gamepad for how these are used. + * + * @ingroup input + * @{ */ +#define GLFW_GAMEPAD_BUTTON_A 0 +#define GLFW_GAMEPAD_BUTTON_B 1 +#define GLFW_GAMEPAD_BUTTON_X 2 +#define GLFW_GAMEPAD_BUTTON_Y 3 +#define GLFW_GAMEPAD_BUTTON_LEFT_BUMPER 4 +#define GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER 5 +#define GLFW_GAMEPAD_BUTTON_BACK 6 +#define GLFW_GAMEPAD_BUTTON_START 7 +#define GLFW_GAMEPAD_BUTTON_GUIDE 8 +#define GLFW_GAMEPAD_BUTTON_LEFT_THUMB 9 +#define GLFW_GAMEPAD_BUTTON_RIGHT_THUMB 10 +#define GLFW_GAMEPAD_BUTTON_DPAD_UP 11 +#define GLFW_GAMEPAD_BUTTON_DPAD_RIGHT 12 +#define GLFW_GAMEPAD_BUTTON_DPAD_DOWN 13 +#define GLFW_GAMEPAD_BUTTON_DPAD_LEFT 14 +#define GLFW_GAMEPAD_BUTTON_LAST GLFW_GAMEPAD_BUTTON_DPAD_LEFT + +#define GLFW_GAMEPAD_BUTTON_CROSS GLFW_GAMEPAD_BUTTON_A +#define GLFW_GAMEPAD_BUTTON_CIRCLE GLFW_GAMEPAD_BUTTON_B +#define GLFW_GAMEPAD_BUTTON_SQUARE GLFW_GAMEPAD_BUTTON_X +#define GLFW_GAMEPAD_BUTTON_TRIANGLE GLFW_GAMEPAD_BUTTON_Y +/*! @} */ + +/*! @defgroup gamepad_axes Gamepad axes + * @brief Gamepad axes. + * + * See @ref gamepad for how these are used. + * + * @ingroup input + * @{ */ +#define GLFW_GAMEPAD_AXIS_LEFT_X 0 +#define GLFW_GAMEPAD_AXIS_LEFT_Y 1 +#define GLFW_GAMEPAD_AXIS_RIGHT_X 2 +#define GLFW_GAMEPAD_AXIS_RIGHT_Y 3 +#define GLFW_GAMEPAD_AXIS_LEFT_TRIGGER 4 +#define GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER 5 +#define GLFW_GAMEPAD_AXIS_LAST GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER +/*! @} */ + /*! @defgroup errors Error codes + * @brief Error codes. * * See [error handling](@ref error_handling) for how these are used. * * @ingroup init * @{ */ +/*! @brief No error has occurred. + * + * No error has occurred. + * + * @analysis Yay. + */ +#define GLFW_NO_ERROR 0 /*! @brief GLFW has not been initialized. * * This occurs if a GLFW function was called that must not be called unless the @@ -524,8 +635,7 @@ extern "C" { /*! @brief One of the arguments to the function was an invalid enum value. * * One of the arguments to the function was an invalid enum value, for example - * requesting [GLFW_RED_BITS](@ref window_hints_fb) with @ref - * glfwGetWindowAttrib. + * requesting @ref GLFW_RED_BITS with @ref glfwGetWindowAttrib. * * @analysis Application programmer error. Fix the offending call. */ @@ -560,7 +670,7 @@ extern "C" { * @par * Some pre-installed Windows graphics drivers do not support OpenGL. AMD only * supports OpenGL ES via EGL, while Nvidia and Intel only support it via - * a WGL or GLX extension. OS X does not provide OpenGL ES at all. The Mesa + * a WGL or GLX extension. macOS does not provide OpenGL ES at all. The Mesa * EGL, OpenGL and OpenGL ES libraries do not interface with the Nvidia binary * driver. Older graphics drivers do not support Vulkan. */ @@ -622,44 +732,213 @@ extern "C" { #define GLFW_NO_WINDOW_CONTEXT 0x0001000A /*! @} */ +/*! @addtogroup window + * @{ */ +/*! @brief Input focus window hint and attribute + * + * Input focus [window hint](@ref GLFW_FOCUSED_hint) or + * [window attribute](@ref GLFW_FOCUSED_attrib). + */ #define GLFW_FOCUSED 0x00020001 +/*! @brief Window iconification window attribute + * + * Window iconification [window attribute](@ref GLFW_ICONIFIED_attrib). + */ #define GLFW_ICONIFIED 0x00020002 +/*! @brief Window resize-ability window hint and attribute + * + * Window resize-ability [window hint](@ref GLFW_RESIZABLE_hint) and + * [window attribute](@ref GLFW_RESIZABLE_attrib). + */ #define GLFW_RESIZABLE 0x00020003 +/*! @brief Window visibility window hint and attribute + * + * Window visibility [window hint](@ref GLFW_VISIBLE_hint) and + * [window attribute](@ref GLFW_VISIBLE_attrib). + */ #define GLFW_VISIBLE 0x00020004 +/*! @brief Window decoration window hint and attribute + * + * Window decoration [window hint](@ref GLFW_DECORATED_hint) and + * [window attribute](@ref GLFW_DECORATED_attrib). + */ #define GLFW_DECORATED 0x00020005 +/*! @brief Window auto-iconification window hint and attribute + * + * Window auto-iconification [window hint](@ref GLFW_AUTO_ICONIFY_hint) and + * [window attribute](@ref GLFW_AUTO_ICONIFY_attrib). + */ #define GLFW_AUTO_ICONIFY 0x00020006 +/*! @brief Window decoration window hint and attribute + * + * Window decoration [window hint](@ref GLFW_FLOATING_hint) and + * [window attribute](@ref GLFW_FLOATING_attrib). + */ #define GLFW_FLOATING 0x00020007 +/*! @brief Window maximization window hint and attribute + * + * Window maximization [window hint](@ref GLFW_MAXIMIZED_hint) and + * [window attribute](@ref GLFW_MAXIMIZED_attrib). + */ #define GLFW_MAXIMIZED 0x00020008 +/*! @brief Cursor centering window hint + * + * Cursor centering [window hint](@ref GLFW_CENTER_CURSOR_hint). + */ +#define GLFW_CENTER_CURSOR 0x00020009 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_RED_BITS). + */ #define GLFW_RED_BITS 0x00021001 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_GREEN_BITS). + */ #define GLFW_GREEN_BITS 0x00021002 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_BLUE_BITS). + */ #define GLFW_BLUE_BITS 0x00021003 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_ALPHA_BITS). + */ #define GLFW_ALPHA_BITS 0x00021004 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_DEPTH_BITS). + */ #define GLFW_DEPTH_BITS 0x00021005 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_STENCIL_BITS). + */ #define GLFW_STENCIL_BITS 0x00021006 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_ACCUM_RED_BITS). + */ #define GLFW_ACCUM_RED_BITS 0x00021007 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_ACCUM_GREEN_BITS). + */ #define GLFW_ACCUM_GREEN_BITS 0x00021008 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_ACCUM_BLUE_BITS). + */ #define GLFW_ACCUM_BLUE_BITS 0x00021009 +/*! @brief Framebuffer bit depth hint. + * + * Framebuffer bit depth [hint](@ref GLFW_ACCUM_ALPHA_BITS). + */ #define GLFW_ACCUM_ALPHA_BITS 0x0002100A +/*! @brief Framebuffer auxiliary buffer hint. + * + * Framebuffer auxiliary buffer [hint](@ref GLFW_AUX_BUFFERS). + */ #define GLFW_AUX_BUFFERS 0x0002100B +/*! @brief OpenGL stereoscopic rendering hint. + * + * OpenGL stereoscopic rendering [hint](@ref GLFW_STEREO). + */ #define GLFW_STEREO 0x0002100C +/*! @brief Framebuffer MSAA samples hint. + * + * Framebuffer MSAA samples [hint](@ref GLFW_SAMPLES). + */ #define GLFW_SAMPLES 0x0002100D +/*! @brief Framebuffer sRGB hint. + * + * Framebuffer sRGB [hint](@ref GLFW_SRGB_CAPABLE). + */ #define GLFW_SRGB_CAPABLE 0x0002100E +/*! @brief Monitor refresh rate hint. + * + * Monitor refresh rate [hint](@ref GLFW_REFRESH_RATE). + */ #define GLFW_REFRESH_RATE 0x0002100F +/*! @brief Framebuffer double buffering hint. + * + * Framebuffer double buffering [hint](@ref GLFW_DOUBLEBUFFER). + */ #define GLFW_DOUBLEBUFFER 0x00021010 - +/*! @brief Context client API hint and attribute. + * + * Context client API [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_CLIENT_API 0x00022001 +/*! @brief Context client API major version hint and attribute. + * + * Context client API major version [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_CONTEXT_VERSION_MAJOR 0x00022002 +/*! @brief Context client API minor version hint and attribute. + * + * Context client API minor version [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_CONTEXT_VERSION_MINOR 0x00022003 +/*! @brief Context client API revision number hint and attribute. + * + * Context client API revision number [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_CONTEXT_REVISION 0x00022004 +/*! @brief Context robustness hint and attribute. + * + * Context client API revision number [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_CONTEXT_ROBUSTNESS 0x00022005 +/*! @brief OpenGL forward-compatibility hint and attribute. + * + * OpenGL forward-compatibility [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_OPENGL_FORWARD_COMPAT 0x00022006 +/*! @brief OpenGL debug context hint and attribute. + * + * OpenGL debug context [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_OPENGL_DEBUG_CONTEXT 0x00022007 +/*! @brief OpenGL profile hint and attribute. + * + * OpenGL profile [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_OPENGL_PROFILE 0x00022008 +/*! @brief Context flush-on-release hint and attribute. + * + * Context flush-on-release [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_CONTEXT_RELEASE_BEHAVIOR 0x00022009 +/*! @brief Context error suppression hint and attribute. + * + * Context error suppression [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_CONTEXT_NO_ERROR 0x0002200A +/*! @brief Context creation API hint and attribute. + * + * Context creation API [hint](@ref GLFW_CLIENT_API_hint) and + * [attribute](@ref GLFW_CLIENT_API_attrib). + */ #define GLFW_CONTEXT_CREATION_API 0x0002200B +#define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001 +#define GLFW_COCOA_FRAME_AUTOSAVE 0x00023002 +#define GLFW_COCOA_GRAPHICS_SWITCHING 0x00023003 +/*! @} */ + #define GLFW_NO_API 0 #define GLFW_OPENGL_API 0x00030001 #define GLFW_OPENGL_ES_API 0x00030002 @@ -686,8 +965,10 @@ extern "C" { #define GLFW_NATIVE_CONTEXT_API 0x00036001 #define GLFW_EGL_CONTEXT_API 0x00036002 +#define GLFW_OSMESA_CONTEXT_API 0x00036003 /*! @defgroup shapes Standard cursor shapes + * @brief Standard system cursor shapes. * * See [standard cursor creation](@ref cursor_standard) for how these are used. * @@ -729,6 +1010,17 @@ extern "C" { #define GLFW_CONNECTED 0x00040001 #define GLFW_DISCONNECTED 0x00040002 +/*! @addtogroup init + * @{ */ +#define GLFW_JOYSTICK_HAT_BUTTONS 0x00050001 + +#define GLFW_COCOA_CHDIR_RESOURCES 0x00051001 +#define GLFW_COCOA_MENUBAR 0x00051002 + +#define GLFW_X11_WM_CLASS_NAME 0x00052001 +#define GLFW_X11_WM_CLASS_CLASS 0x00052002 +/*! @} */ + #define GLFW_DONT_CARE -1 @@ -742,7 +1034,7 @@ extern "C" { * without forcing a cast from a regular pointer. * * @sa @ref context_glext - * @sa glfwGetProcAddress + * @sa @ref glfwGetProcAddress * * @since Added in version 3.0. @@ -756,7 +1048,7 @@ typedef void (*GLFWglproc)(void); * without forcing a cast from a regular pointer. * * @sa @ref vulkan_proc - * @sa glfwGetInstanceProcAddress + * @sa @ref glfwGetInstanceProcAddress * * @since Added in version 3.2. * @@ -808,7 +1100,7 @@ typedef struct GLFWcursor GLFWcursor; * @param[in] description A UTF-8 encoded string describing the error. * * @sa @ref error_handling - * @sa glfwSetErrorCallback + * @sa @ref glfwSetErrorCallback * * @since Added in version 3.0. * @@ -827,7 +1119,7 @@ typedef void (* GLFWerrorfun)(int,const char*); * upper-left corner of the client area of the window. * * @sa @ref window_pos - * @sa glfwSetWindowPosCallback + * @sa @ref glfwSetWindowPosCallback * * @since Added in version 3.0. * @@ -844,7 +1136,7 @@ typedef void (* GLFWwindowposfun)(GLFWwindow*,int,int); * @param[in] height The new height, in screen coordinates, of the window. * * @sa @ref window_size - * @sa glfwSetWindowSizeCallback + * @sa @ref glfwSetWindowSizeCallback * * @since Added in version 1.0. * @glfw3 Added window handle parameter. @@ -860,7 +1152,7 @@ typedef void (* GLFWwindowsizefun)(GLFWwindow*,int,int); * @param[in] window The window that the user attempted to close. * * @sa @ref window_close - * @sa glfwSetWindowCloseCallback + * @sa @ref glfwSetWindowCloseCallback * * @since Added in version 2.5. * @glfw3 Added window handle parameter. @@ -876,7 +1168,7 @@ typedef void (* GLFWwindowclosefun)(GLFWwindow*); * @param[in] window The window whose content needs to be refreshed. * * @sa @ref window_refresh - * @sa glfwSetWindowRefreshCallback + * @sa @ref glfwSetWindowRefreshCallback * * @since Added in version 2.5. * @glfw3 Added window handle parameter. @@ -894,7 +1186,7 @@ typedef void (* GLFWwindowrefreshfun)(GLFWwindow*); * `GLFW_FALSE` if it lost it. * * @sa @ref window_focus - * @sa glfwSetWindowFocusCallback + * @sa @ref glfwSetWindowFocusCallback * * @since Added in version 3.0. * @@ -912,7 +1204,7 @@ typedef void (* GLFWwindowfocusfun)(GLFWwindow*,int); * `GLFW_FALSE` if it was restored. * * @sa @ref window_iconify - * @sa glfwSetWindowIconifyCallback + * @sa @ref glfwSetWindowIconifyCallback * * @since Added in version 3.0. * @@ -920,6 +1212,24 @@ typedef void (* GLFWwindowfocusfun)(GLFWwindow*,int); */ typedef void (* GLFWwindowiconifyfun)(GLFWwindow*,int); +/*! @brief The function signature for window maximize/restore callbacks. + * + * This is the function signature for window maximize/restore callback + * functions. + * + * @param[in] window The window that was maximized or restored. + * @param[in] iconified `GLFW_TRUE` if the window was maximized, or + * `GLFW_FALSE` if it was restored. + * + * @sa @ref window_maximize + * @sa glfwSetWindowMaximizeCallback + * + * @since Added in version 3.3. + * + * @ingroup window + */ +typedef void (* GLFWwindowmaximizefun)(GLFWwindow*,int); + /*! @brief The function signature for framebuffer resize callbacks. * * This is the function signature for framebuffer resize callback @@ -930,7 +1240,7 @@ typedef void (* GLFWwindowiconifyfun)(GLFWwindow*,int); * @param[in] height The new height, in pixels, of the framebuffer. * * @sa @ref window_fbsize - * @sa glfwSetFramebufferSizeCallback + * @sa @ref glfwSetFramebufferSizeCallback * * @since Added in version 3.0. * @@ -950,7 +1260,7 @@ typedef void (* GLFWframebuffersizefun)(GLFWwindow*,int,int); * held down. * * @sa @ref input_mouse_button - * @sa glfwSetMouseButtonCallback + * @sa @ref glfwSetMouseButtonCallback * * @since Added in version 1.0. * @glfw3 Added window handle and modifier mask parameters. @@ -970,7 +1280,7 @@ typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int,int); * client area. * * @sa @ref cursor_pos - * @sa glfwSetCursorPosCallback + * @sa @ref glfwSetCursorPosCallback * * @since Added in version 3.0. Replaces `GLFWmouseposfun`. * @@ -987,7 +1297,7 @@ typedef void (* GLFWcursorposfun)(GLFWwindow*,double,double); * area, or `GLFW_FALSE` if it left it. * * @sa @ref cursor_enter - * @sa glfwSetCursorEnterCallback + * @sa @ref glfwSetCursorEnterCallback * * @since Added in version 3.0. * @@ -1004,7 +1314,7 @@ typedef void (* GLFWcursorenterfun)(GLFWwindow*,int); * @param[in] yoffset The scroll offset along the y-axis. * * @sa @ref scrolling - * @sa glfwSetScrollCallback + * @sa @ref glfwSetScrollCallback * * @since Added in version 3.0. Replaces `GLFWmousewheelfun`. * @@ -1024,7 +1334,7 @@ typedef void (* GLFWscrollfun)(GLFWwindow*,double,double); * held down. * * @sa @ref input_key - * @sa glfwSetKeyCallback + * @sa @ref glfwSetKeyCallback * * @since Added in version 1.0. * @glfw3 Added window handle, scancode and modifier mask parameters. @@ -1041,7 +1351,7 @@ typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int); * @param[in] codepoint The Unicode code point of the character. * * @sa @ref input_char - * @sa glfwSetCharCallback + * @sa @ref glfwSetCharCallback * * @since Added in version 2.4. * @glfw3 Added window handle parameter. @@ -1063,7 +1373,7 @@ typedef void (* GLFWcharfun)(GLFWwindow*,unsigned int); * held down. * * @sa @ref input_char - * @sa glfwSetCharModsCallback + * @sa @ref glfwSetCharModsCallback * * @since Added in version 3.1. * @@ -1080,7 +1390,7 @@ typedef void (* GLFWcharmodsfun)(GLFWwindow*,unsigned int,int); * @param[in] paths The UTF-8 encoded file and/or directory path names. * * @sa @ref path_drop - * @sa glfwSetDropCallback + * @sa @ref glfwSetDropCallback * * @since Added in version 3.1. * @@ -1096,7 +1406,7 @@ typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**); * @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. * * @sa @ref monitor_event - * @sa glfwSetMonitorCallback + * @sa @ref glfwSetMonitorCallback * * @since Added in version 3.0. * @@ -1109,11 +1419,11 @@ typedef void (* GLFWmonitorfun)(GLFWmonitor*,int); * This is the function signature for joystick configuration callback * functions. * - * @param[in] joy The joystick that was connected or disconnected. + * @param[in] jid The joystick that was connected or disconnected. * @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. * * @sa @ref joystick_event - * @sa glfwSetJoystickCallback + * @sa @ref glfwSetJoystickCallback * * @since Added in version 3.2. * @@ -1126,7 +1436,8 @@ typedef void (* GLFWjoystickfun)(int,int); * This describes a single video mode. * * @sa @ref monitor_modes - * @sa glfwGetVideoMode glfwGetVideoModes + * @sa @ref glfwGetVideoMode + * @sa @ref glfwGetVideoModes * * @since Added in version 1.0. * @glfw3 Added refresh rate member. @@ -1160,7 +1471,8 @@ typedef struct GLFWvidmode * This describes the gamma ramp for a monitor. * * @sa @ref monitor_gamma - * @sa glfwGetGammaRamp glfwSetGammaRamp + * @sa @ref glfwGetGammaRamp + * @sa @ref glfwSetGammaRamp * * @since Added in version 3.0. * @@ -1184,6 +1496,9 @@ typedef struct GLFWgammaramp /*! @brief Image data. * + * This describes a single 2D image. See the documentation for each related + * function what the expected pixel format is. + * * @sa @ref cursor_custom * @sa @ref window_icon * @@ -1203,6 +1518,27 @@ typedef struct GLFWimage unsigned char* pixels; } GLFWimage; +/*! @brief Gamepad input state + * + * This describes the input state of a gamepad. + * + * @sa @ref gamepad + * @sa @ref glfwGetGamepadState + * + * @since Added in version 3.3. + */ +typedef struct GLFWgamepadstate +{ + /*! The states of each [gamepad button](@ref gamepad_buttons), `GLFW_PRESS` + * or `GLFW_RELEASE`. + */ + unsigned char buttons[15]; + /*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0 + * to 1.0 inclusive. + */ + float axes[6]; +} GLFWgamepadstate; + /************************************************************************* * GLFW API functions @@ -1226,15 +1562,15 @@ typedef struct GLFWimage * * @errors Possible errors include @ref GLFW_PLATFORM_ERROR. * - * @remark @osx This function will change the current directory of the + * @remark @macos This function will change the current directory of the * application to the `Contents/Resources` subdirectory of the application's - * bundle, if present. This can be disabled with a - * [compile-time option](@ref compile_options_osx). + * bundle, if present. This can be disabled with the @ref + * GLFW_COCOA_CHDIR_RESOURCES init hint. * * @thread_safety This function must only be called from the main thread. * * @sa @ref intro_init - * @sa glfwTerminate + * @sa @ref glfwTerminate * * @since Added in version 1.0. * @@ -1266,7 +1602,7 @@ GLFWAPI int glfwInit(void); * @thread_safety This function must only be called from the main thread. * * @sa @ref intro_init - * @sa glfwInit + * @sa @ref glfwInit * * @since Added in version 1.0. * @@ -1274,6 +1610,76 @@ GLFWAPI int glfwInit(void); */ GLFWAPI void glfwTerminate(void); +/*! @brief Sets the specified init hint to the desired value. + * + * This function sets hints for the next initialization of GLFW. Only integer + * type hints can be set with this function. + * + * The values you set hints to are never reset by GLFW, but they only take + * effect during initialization. Once GLFW has been initialized, any values + * you set will be ignored until the library is terminated and initialized + * again. + * + * Some hints are platform specific. These may be set on any platform but they + * will only affect their specific platform. Other platforms will simply + * ignore them. Setting these hints requires no platform specific headers or + * functions. + * + * @param[in] hint The [init hint](@ref init_hints) to set. + * @param[in] value The new value of the init hint. + * + * @errors Possible errors include @ref GLFW_INVALID_ENUM and @ref + * GLFW_INVALID_VALUE. + * + * @remarks This function may be called before @ref glfwInit. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa init_hints + * @sa glfwInit + * @sa glfwInitHintString + * + * @since Added in version 3.3. + * + * @ingroup init + */ +GLFWAPI void glfwInitHint(int hint, int value); + +/*! @brief Sets the specified init hint to the desired value. + * + * This function sets hints for the next initialization of GLFW. Only string + * type hints can be set with this function. + * + * The values you set hints to are never reset by GLFW, but they only take + * effect during initialization. Once GLFW has been initialized, any values + * you set will be ignored until the library is terminated and initialized + * again. + * + * Some hints are platform specific. These may be set on any platform but they + * will only affect their specific platform. Other platforms will simply + * ignore them. Setting these hints requires no platform specific headers or + * functions. + * + * @param[in] hint The [init hint](@ref init_hints) to set. + * @param[in] value The new value of the init hint. + * + * @errors Possible errors include @ref GLFW_INVALID_ENUM and @ref + * GLFW_INVALID_VALUE. + * + * @remarks This function may be called before @ref glfwInit. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa init_hints + * @sa glfwInit + * @sa glfwInitHint + * + * @since Added in version 3.3. + * + * @ingroup init + */ +GLFWAPI void glfwInitHintString(int hint, const char* value); + /*! @brief Retrieves the version of the GLFW library. * * This function retrieves the major, minor and revision numbers of the GLFW @@ -1293,7 +1699,7 @@ GLFWAPI void glfwTerminate(void); * @thread_safety This function may be called from any thread. * * @sa @ref intro_version - * @sa glfwGetVersionString + * @sa @ref glfwGetVersionString * * @since Added in version 1.0. * @@ -1324,7 +1730,7 @@ GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev); * @thread_safety This function may be called from any thread. * * @sa @ref intro_version - * @sa glfwGetVersion + * @sa @ref glfwGetVersion * * @since Added in version 3.0. * @@ -1332,11 +1738,46 @@ GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev); */ GLFWAPI const char* glfwGetVersionString(void); +/*! @brief Returns and clears the last error for the calling thread. + * + * This function returns and clears the [error code](@ref errors) of the last + * error that occurred on the calling thread, and optionally a UTF-8 encoded + * human-readable description of it. If no error has occurred since the last + * call, it returns @ref GLFW_NO_ERROR (zero) and the description pointer is + * set to `NULL`. + * + * @param[in] description Where to store the error description pointer, or `NULL`. + * @return The last error code for the calling thread, or @ref GLFW_NO_ERROR + * (zero). + * + * @errors None. + * + * @pointer_lifetime The returned string is allocated and freed by GLFW. You + * should not free it yourself. It is guaranteed to be valid only until the + * next error occurs or the library is terminated. + * + * @remark This function may be called before @ref glfwInit. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref error_handling + * @sa @ref glfwSetErrorCallback + * + * @since Added in version 3.3. + * + * @ingroup init + */ +GLFWAPI int glfwGetError(const char** description); + /*! @brief Sets the error callback. * * This function sets the error callback, which is called with an error code * and a human-readable description each time a GLFW error occurs. * + * The error code is set before the callback is called. Calling @ref + * glfwGetError from the error callback will return the same value as the error + * code argument. + * * The error callback is called on the thread where the error occurred. If you * are using GLFW from multiple threads, your error callback needs to be * written accordingly. @@ -1359,6 +1800,7 @@ GLFWAPI const char* glfwGetVersionString(void); * @thread_safety This function must only be called from the main thread. * * @sa @ref error_handling + * @sa @ref glfwGetError * * @since Added in version 3.0. * @@ -1387,7 +1829,7 @@ GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun); * * @sa @ref monitor_monitors * @sa @ref monitor_event - * @sa glfwGetPrimaryMonitor + * @sa @ref glfwGetPrimaryMonitor * * @since Added in version 3.0. * @@ -1411,7 +1853,7 @@ GLFWAPI GLFWmonitor** glfwGetMonitors(int* count); * glfwGetMonitors. * * @sa @ref monitor_monitors - * @sa glfwGetMonitors + * @sa @ref glfwGetMonitors * * @since Added in version 3.0. * @@ -1551,7 +1993,7 @@ GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun); * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_modes - * @sa glfwGetVideoMode + * @sa @ref glfwGetVideoMode * * @since Added in version 1.0. * @glfw3 Changed to return an array of modes for a specific monitor. @@ -1580,7 +2022,7 @@ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count); * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_modes - * @sa glfwGetVideoModes + * @sa @ref glfwGetVideoModes * * @since Added in version 3.0. Replaces `glfwGetDesktopMode`. * @@ -1594,12 +2036,23 @@ GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor); * and then calls @ref glfwSetGammaRamp with it. The value must be a finite * number greater than zero. * + * The software controlled gamma ramp is applied _in addition_ to the hardware + * gamma correction, which today is usually an approximation of sRGB gamma. + * This means that setting a perfectly linear ramp, or gamma 1.0, will produce + * the default (usually sRGB-like) behavior. + * + * For gamma correct rendering with OpenGL or OpenGL ES, see the @ref + * GLFW_SRGB_CAPABLE hint. + * * @param[in] monitor The monitor whose gamma ramp to set. * @param[in] gamma The desired exponent. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. * + * @remark @wayland Gamma handling is currently unavailable, this function will + * always emit @ref GLFW_PLATFORM_ERROR. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_gamma @@ -1621,6 +2074,9 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* monitor, float gamma); * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark @wayland Gamma handling is currently unavailable, this function will + * always return `NULL` and emit @ref GLFW_PLATFORM_ERROR. + * * @pointer_lifetime The returned structure and its arrays are allocated and * freed by GLFW. You should not free them yourself. They are valid until the * specified monitor is disconnected, this function is called again for that @@ -1642,6 +2098,14 @@ GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor); * original gamma ramp for that monitor is saved by GLFW the first time this * function is called and is restored by @ref glfwTerminate. * + * The software controlled gamma ramp is applied _in addition_ to the hardware + * gamma correction, which today is usually an approximation of sRGB gamma. + * This means that setting a perfectly linear ramp, or gamma 1.0, will produce + * the default (usually sRGB-like) behavior. + * + * For gamma correct rendering with OpenGL or OpenGL ES, see the @ref + * GLFW_SRGB_CAPABLE hint. + * * @param[in] monitor The monitor whose gamma ramp to set. * @param[in] ramp The gamma ramp to use. * @@ -1653,6 +2117,9 @@ GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor); * * @remark @win32 The gamma ramp size must be 256. * + * @remark @wayland Gamma handling is currently unavailable, this function will + * always emit @ref GLFW_PLATFORM_ERROR. + * * @pointer_lifetime The specified gamma ramp is copied before this function * returns. * @@ -1676,7 +2143,7 @@ GLFWAPI void glfwSetGammaRamp(GLFWmonitor* monitor, const GLFWgammaramp* ramp); * @thread_safety This function must only be called from the main thread. * * @sa @ref window_hints - * @sa glfwWindowHint + * @sa @ref glfwWindowHint * * @since Added in version 3.0. * @@ -1704,7 +2171,7 @@ GLFWAPI void glfwDefaultWindowHints(void); * @thread_safety This function must only be called from the main thread. * * @sa @ref window_hints - * @sa glfwDefaultWindowHints + * @sa @ref glfwDefaultWindowHints * * @since Added in version 3.0. Replaces `glfwOpenWindowHint`. * @@ -1744,12 +2211,12 @@ GLFWAPI void glfwWindowHint(int hint, int value); * or _borderless full screen_ windows, see @ref window_windowed_full_screen. * * Once you have created the window, you can switch it between windowed and - * full screen mode with @ref glfwSetWindowMonitor. If the window has an - * OpenGL or OpenGL ES context, it will be unaffected. + * full screen mode with @ref glfwSetWindowMonitor. This will not affect its + * OpenGL or OpenGL ES context. * * By default, newly created windows use the placement recommended by the * window system. To create the window at a specific position, make it - * initially invisible using the [GLFW_VISIBLE](@ref window_hints_wnd) window + * initially invisible using the [GLFW_VISIBLE](@ref GLFW_VISIBLE_hint) window * hint, set its [position](@ref window_pos) and then [show](@ref window_hide) * it. * @@ -1791,27 +2258,41 @@ GLFWAPI void glfwWindowHint(int hint, int value); * @remark @win32 The context to share resources with must not be current on * any other thread. * - * @remark @osx The GLFW window has no icon, as it is not a document + * @remark @macos The OS only supports forward-compatible core profile contexts + * for OpenGL versions 3.2 and later. Before creating an OpenGL context of + * version 3.2 or later you must set the + * [GLFW_OPENGL_FORWARD_COMPAT](@ref GLFW_OPENGL_FORWARD_COMPAT_hint) and + * [GLFW_OPENGL_PROFILE](@ref GLFW_OPENGL_PROFILE_hint) hints accordingly. + * OpenGL 3.0 and 3.1 contexts are not supported at all on macOS. + * + * @remark @macos The GLFW window has no icon, as it is not a document * window, but the dock icon will be the same as the application bundle's icon. * For more information on bundles, see the * [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/) * in the Mac Developer Library. * - * @remark @osx The first time a window is created the menu bar is populated - * with common commands like Hide, Quit and About. The About entry opens - * a minimal about dialog with information from the application's bundle. The - * menu bar can be disabled with a - * [compile-time option](@ref compile_options_osx). - * - * @remark @osx On OS X 10.10 and later the window frame will not be rendered - * at full resolution on Retina displays unless the `NSHighResolutionCapable` - * key is enabled in the application bundle's `Info.plist`. For more - * information, see + * @remark @macos The first time a window is created the menu bar is created. + * If GLFW finds a `MainMenu.nib` it is loaded and assumed to contain a menu + * bar. Otherwise a minimal menu bar is created manually with common commands + * like Hide, Quit and About. The About entry opens a minimal about dialog + * with information from the application's bundle. Menu bar creation can be + * disabled entirely with the @ref GLFW_COCOA_MENUBAR init hint. + * + * @remark @macos On OS X 10.10 and later the window frame will not be rendered + * at full resolution on Retina displays unless the + * [GLFW_COCOA_RETINA_FRAMEBUFFER](@ref GLFW_COCOA_RETINA_FRAMEBUFFER_hint) + * hint is `GLFW_TRUE` and the `NSHighResolutionCapable` key is enabled in the + * application bundle's `Info.plist`. For more information, see * [High Resolution Guidelines for OS X](https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html) * in the Mac Developer Library. The GLFW test and example programs use * a custom `Info.plist` template for this, which can be found as * `CMake/MacOSXBundleInfo.plist.in` in the source tree. * + * @remark @macos When activating frame autosaving with + * [GLFW_COCOA_FRAME_AUTOSAVE](@ref GLFW_COCOA_FRAME_AUTOSAVE_hint), the + * specified window size may be overriden by a previously saved size and + * position. + * * @remark @x11 Some window managers will not respect the placement of * initially hidden windows. * @@ -1820,12 +2301,29 @@ GLFWAPI void glfwWindowHint(int hint, int value); * query the final size, position or other attributes directly after window * creation. * - * @reentrancy This function must not be called from a callback. + * @remark @x11 The name and class of the `WM_CLASS` window property will by + * default be set to the window title passed to this function. Set the @ref + * GLFW_X11_WM_CLASS_NAME and @ref GLFW_X11_WM_CLASS_CLASS init hints before + * initialization to override this. + * + * @remark @wayland The window frame is currently unimplemented, as if + * [GLFW_DECORATED](@ref GLFW_DECORATED_hint) was always set to `GLFW_FALSE`. + * A compositor can still emit close, resize or maximize events, using for + * example a keybind mechanism. + * + * @remark @wayland A full screen window will not attempt to change the mode, + * no matter what the requested size or refresh rate. + * + * @remark @wayland The wl_shell protocol does not support window + * icons, the window will inherit the one defined in the application's + * desktop file, so this function emits @ref GLFW_PLATFORM_ERROR. + * + * @remark @wayland Screensaver inhibition is currently unimplemented. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_creation - * @sa glfwDestroyWindow + * @sa @ref glfwDestroyWindow * * @since Added in version 3.0. Replaces `glfwOpenWindow`. * @@ -1854,7 +2352,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, G * @thread_safety This function must only be called from the main thread. * * @sa @ref window_creation - * @sa glfwCreateWindow + * @sa @ref glfwCreateWindow * * @since Added in version 3.0. Replaces `glfwCloseWindow`. * @@ -1915,7 +2413,7 @@ GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* window, int value); * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * - * @remark @osx The window title will not be updated until the next time you + * @remark @macos The window title will not be updated until the next time you * process events. * * @thread_safety This function must only be called from the main thread. @@ -1936,6 +2434,10 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow* window, const char* title); * selected. If no images are specified, the window reverts to its default * icon. * + * The pixels are 32-bit, little-endian, non-premultiplied RGBA, i.e. eight + * bits per channel with the red channel first. They are arranged canonically + * as packed sequential rows, starting from the top-left corner. + * * The desired image sizes varies depending on platform and system settings. * The selected images will be rescaled as needed. Good sizes include 16x16, * 32x32 and 48x48. @@ -1952,12 +2454,16 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow* window, const char* title); * @pointer_lifetime The specified image data is copied before this function * returns. * - * @remark @osx The GLFW window has no icon, as it is not a document + * @remark @macos The GLFW window has no icon, as it is not a document * window, so this function does nothing. The dock icon will be the same as * the application bundle's icon. For more information on bundles, see the * [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/) * in the Mac Developer Library. * + * @remark @wayland The wl_shell protocol does not support icons, the window + * will inherit the one defined in the application's desktop file, so this + * function emits @ref GLFW_PLATFORM_ERROR. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_icon @@ -1985,10 +2491,14 @@ GLFWAPI void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* i * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark @wayland There is no way for an application to retrieve the global + * position of its windows, this function will always emit @ref + * GLFW_PLATFORM_ERROR. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_pos - * @sa glfwSetWindowPos + * @sa @ref glfwSetWindowPos * * @since Added in version 3.0. * @@ -2015,10 +2525,14 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos); * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark @wayland There is no way for an application to set the global + * position of its windows, this function will always emit @ref + * GLFW_PLATFORM_ERROR. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_pos - * @sa glfwGetWindowPos + * @sa @ref glfwGetWindowPos * * @since Added in version 1.0. * @glfw3 Added window handle parameter. @@ -2048,7 +2562,7 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow* window, int xpos, int ypos); * @thread_safety This function must only be called from the main thread. * * @sa @ref window_size - * @sa glfwSetWindowSize + * @sa @ref glfwSetWindowSize * * @since Added in version 1.0. * @glfw3 Added window handle parameter. @@ -2086,10 +2600,13 @@ GLFWAPI void glfwGetWindowSize(GLFWwindow* window, int* width, int* height); * @remark If you set size limits and an aspect ratio that conflict, the * results are undefined. * + * @remark @wayland The size limits will not be applied until the window is + * actually resized, either by the user or by the compositor. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_sizelimits - * @sa glfwSetWindowAspectRatio + * @sa @ref glfwSetWindowAspectRatio * * @since Added in version 3.2. * @@ -2126,10 +2643,13 @@ GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* window, int minwidth, int minhe * @remark If you set size limits and an aspect ratio that conflict, the * results are undefined. * + * @remark @wayland The aspect ratio will not be applied until the window is + * actually resized, either by the user or by the compositor. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_sizelimits - * @sa glfwSetWindowSizeLimits + * @sa @ref glfwSetWindowSizeLimits * * @since Added in version 3.2. * @@ -2162,11 +2682,14 @@ GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* window, int numer, int denom); * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark @wayland A full screen window will not attempt to change the mode, + * no matter what the requested size. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_size - * @sa glfwGetWindowSize - * @sa glfwSetWindowMonitor + * @sa @ref glfwGetWindowSize + * @sa @ref glfwSetWindowMonitor * * @since Added in version 1.0. * @glfw3 Added window handle parameter. @@ -2196,7 +2719,7 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow* window, int width, int height); * @thread_safety This function must only be called from the main thread. * * @sa @ref window_fbsize - * @sa glfwSetFramebufferSizeCallback + * @sa @ref glfwSetFramebufferSizeCallback * * @since Added in version 3.0. * @@ -2231,6 +2754,10 @@ GLFWAPI void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height) * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark @wayland The window frame is currently unimplemented, as if + * [GLFW_DECORATED](@ref GLFW_DECORATED_hint) was always set to `GLFW_FALSE`, + * so the returned values will always be zero. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_size @@ -2255,11 +2782,14 @@ GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark @wayland There is no concept of iconification in wl_shell, this + * function will always emit @ref GLFW_PLATFORM_ERROR. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_iconify - * @sa glfwRestoreWindow - * @sa glfwMaximizeWindow + * @sa @ref glfwRestoreWindow + * @sa @ref glfwMaximizeWindow * * @since Added in version 2.1. * @glfw3 Added window handle parameter. @@ -2285,8 +2815,8 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow* window); * @thread_safety This function must only be called from the main thread. * * @sa @ref window_iconify - * @sa glfwIconifyWindow - * @sa glfwMaximizeWindow + * @sa @ref glfwIconifyWindow + * @sa @ref glfwMaximizeWindow * * @since Added in version 2.1. * @glfw3 Added window handle parameter. @@ -2311,8 +2841,8 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow* window); * This function may only be called from the main thread. * * @sa @ref window_iconify - * @sa glfwIconifyWindow - * @sa glfwRestoreWindow + * @sa @ref glfwIconifyWindow + * @sa @ref glfwRestoreWindow * * @since Added in GLFW 3.2. * @@ -2334,7 +2864,7 @@ GLFWAPI void glfwMaximizeWindow(GLFWwindow* window); * @thread_safety This function must only be called from the main thread. * * @sa @ref window_hide - * @sa glfwHideWindow + * @sa @ref glfwHideWindow * * @since Added in version 3.0. * @@ -2356,7 +2886,7 @@ GLFWAPI void glfwShowWindow(GLFWwindow* window); * @thread_safety This function must only be called from the main thread. * * @sa @ref window_hide - * @sa glfwShowWindow + * @sa @ref glfwShowWindow * * @since Added in version 3.0. * @@ -2370,21 +2900,28 @@ GLFWAPI void glfwHideWindow(GLFWwindow* window); * The window should already be visible and not iconified. * * By default, both windowed and full screen mode windows are focused when - * initially created. Set the [GLFW_FOCUSED](@ref window_hints_wnd) to disable - * this behavior. + * initially created. Set the [GLFW_FOCUSED](@ref GLFW_FOCUSED_hint) to + * disable this behavior. * * __Do not use this function__ to steal focus from other applications unless * you are certain that is what the user wants. Focus stealing can be * extremely disruptive. * + * For a less disruptive way of getting the user's attention, see + * [attention requests](@ref window_attention). + * * @param[in] window The window to give input focus. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark @wayland It is not possible for an application to bring its windows + * to front, this function will always emit @ref GLFW_PLATFORM_ERROR. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_focus + * @sa @ref window_attention * * @since Added in version 3.2. * @@ -2392,6 +2929,33 @@ GLFWAPI void glfwHideWindow(GLFWwindow* window); */ GLFWAPI void glfwFocusWindow(GLFWwindow* window); +/*! @brief Requests user attention to the specified window. + * + * This function requests user attention to the specified window. On + * platforms where this is not supported, attention is requested to the + * application as a whole. + * + * Once the user has given attention, usually by focusing the window or + * application, the system will end the request automatically. + * + * @param[in] window The window to request attention to. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @remark @macos Attention is requested to the application as a whole, not the + * specific window. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_attention + * + * @since Added in version 3.3. + * + * @ingroup window + */ +GLFWAPI void glfwRequestWindowAttention(GLFWwindow* window); + /*! @brief Returns the monitor that the window uses for full screen mode. * * This function returns the handle of the monitor that the specified window is @@ -2406,7 +2970,7 @@ GLFWAPI void glfwFocusWindow(GLFWwindow* window); * @thread_safety This function must only be called from the main thread. * * @sa @ref window_monitor - * @sa glfwSetWindowMonitor + * @sa @ref glfwSetWindowMonitor * * @since Added in version 3.0. * @@ -2432,7 +2996,7 @@ GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window); * * When a window transitions from full screen to windowed mode, this function * restores any previous window settings such as whether it is decorated, - * floating, resizable, has size or aspect ratio limits, etc.. + * floating, resizable, has size or aspect ratio limits, etc. * * @param[in] window The window whose monitor, size or video mode to set. * @param[in] monitor The desired monitor, or `NULL` to set windowed mode. @@ -2450,12 +3014,22 @@ GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window); * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark The OpenGL or OpenGL ES context will not be destroyed or otherwise + * affected by any resizing or mode switching, although you may need to update + * your viewport if the framebuffer size has changed. + * + * @remark @wayland The desired window position is ignored, as there is no way + * for an application to set this property. + * + * @remark @wayland Setting the window to full screen will not attempt to + * change the mode, no matter what the requested size or refresh rate. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_monitor * @sa @ref window_full_screen - * @sa glfwGetWindowMonitor - * @sa glfwSetWindowSize + * @sa @ref glfwGetWindowMonitor + * @sa @ref glfwSetWindowSize * * @since Added in version 3.2. * @@ -2488,6 +3062,7 @@ GLFWAPI void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int * @thread_safety This function must only be called from the main thread. * * @sa @ref window_attribs + * @sa @ref glfwSetWindowAttrib * * @since Added in version 3.0. Replaces `glfwGetWindowParam` and * `glfwGetGLVersion`. @@ -2496,6 +3071,42 @@ GLFWAPI void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int */ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* window, int attrib); +/*! @brief Sets an attribute of the specified window. + * + * This function sets the value of an attribute of the specified window. + * + * The supported attributes are [GLFW_DECORATED](@ref GLFW_DECORATED_attrib), + * [GLFW_RESIZABLE](@ref GLFW_RESIZABLE_attrib), + * [GLFW_FLOATING](@ref GLFW_FLOATING_attrib) and + * [GLFW_AUTO_ICONIFY](@ref GLFW_AUTO_ICONIFY_attrib). + * + * Some of these attributes are ignored for full screen windows. The new + * value will take effect if the window is later made windowed. + * + * Some of these attributes are ignored for windowed mode windows. The new + * value will take effect if the window is later made full screen. + * + * @param[in] window The window to set the attribute for. + * @param[in] attrib A supported window attribute. + * @param[in] value `GLFW_TRUE` or `GLFW_FALSE`. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM, @ref GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. + * + * @remark Calling @ref glfwGetWindowAttrib will always return the latest + * value, even if that value is ignored by the current mode of the window. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_attribs + * @sa @ref glfwGetWindowAttrib + * + * @since Added in version 3.3. + * + * @ingroup window + */ +GLFWAPI void glfwSetWindowAttrib(GLFWwindow* window, int attrib, int value); + /*! @brief Sets the user pointer of the specified window. * * This function sets the user-defined pointer of the specified window. The @@ -2511,7 +3122,7 @@ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* window, int attrib); * synchronized. * * @sa @ref window_userptr - * @sa glfwGetWindowUserPointer + * @sa @ref glfwGetWindowUserPointer * * @since Added in version 3.0. * @@ -2532,7 +3143,7 @@ GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer); * synchronized. * * @sa @ref window_userptr - * @sa glfwSetWindowUserPointer + * @sa @ref glfwSetWindowUserPointer * * @since Added in version 3.0. * @@ -2554,6 +3165,9 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* window); * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * + * @remark @wayland This callback will never be called, as there is no way for + * an application to know its global position. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_pos @@ -2608,8 +3222,8 @@ GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwind * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * - * @remark @osx Selecting Quit from the application menu will trigger the close - * callback for all windows. + * @remark @macos Selecting Quit from the application menu will trigger the + * close callback for all windows. * * @thread_safety This function must only be called from the main thread. * @@ -2628,9 +3242,9 @@ GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwi * called when the client area of the window needs to be redrawn, for example * if the window has been exposed after having been covered by another window. * - * On compositing window systems such as Aero, Compiz or Aqua, where the window - * contents are saved off-screen, this callback may be called only very - * infrequently or never at all. + * On compositing window systems such as Aero, Compiz, Aqua or Wayland, where + * the window contents are saved off-screen, this callback may be called only + * very infrequently or never at all. * * @param[in] window The window whose callback to set. * @param[in] cbfun The new callback, or `NULL` to remove the currently set @@ -2692,6 +3306,9 @@ GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwi * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * + * @remark @wayland The wl_shell protocol has no concept of iconification, + * this callback will never be called. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_iconify @@ -2702,6 +3319,29 @@ GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwi */ GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun cbfun); +/*! @brief Sets the maximize callback for the specified window. + * + * This function sets the maximization callback of the specified window, which + * is called when the window is maximized or restored. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_maximize + * + * @since Added in version 3.3. + * + * @ingroup window + */ +GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun cbfun); + /*! @brief Sets the framebuffer resize callback for the specified window. * * This function sets the framebuffer resize callback of the specified window, @@ -2737,9 +3377,12 @@ GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window * [window refresh callback](@ref window_refresh) to redraw the contents of * your window when necessary during such operations. * - * On some platforms, certain events are sent directly to the application - * without going through the event queue, causing callbacks to be called - * outside of a call to one of the event processing functions. + * Do not assume that callbacks you set will _only_ be called in response to + * event processing functions like this one. While it is necessary to poll for + * events, window systems that require GLFW to register callbacks of its own + * can pass events to GLFW in response to many window system function calls. + * GLFW will pass those events on to the application callbacks before + * returning. * * Event processing is not required for joystick input to work. * @@ -2751,8 +3394,8 @@ GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window * @thread_safety This function must only be called from the main thread. * * @sa @ref events - * @sa glfwWaitEvents - * @sa glfwWaitEventsTimeout + * @sa @ref glfwWaitEvents + * @sa @ref glfwWaitEventsTimeout * * @since Added in version 1.0. * @@ -2779,8 +3422,12 @@ GLFWAPI void glfwPollEvents(void); * [window refresh callback](@ref window_refresh) to redraw the contents of * your window when necessary during such operations. * - * On some platforms, certain callbacks may be called outside of a call to one - * of the event processing functions. + * Do not assume that callbacks you set will _only_ be called in response to + * event processing functions like this one. While it is necessary to poll for + * events, window systems that require GLFW to register callbacks of its own + * can pass events to GLFW in response to many window system function calls. + * GLFW will pass those events on to the application callbacks before + * returning. * * If no windows exist, this function returns immediately. For synchronization * of threads in applications that do not create windows, use your threading @@ -2796,8 +3443,8 @@ GLFWAPI void glfwPollEvents(void); * @thread_safety This function must only be called from the main thread. * * @sa @ref events - * @sa glfwPollEvents - * @sa glfwWaitEventsTimeout + * @sa @ref glfwPollEvents + * @sa @ref glfwWaitEventsTimeout * * @since Added in version 2.5. * @@ -2826,8 +3473,12 @@ GLFWAPI void glfwWaitEvents(void); * [window refresh callback](@ref window_refresh) to redraw the contents of * your window when necessary during such operations. * - * On some platforms, certain callbacks may be called outside of a call to one - * of the event processing functions. + * Do not assume that callbacks you set will _only_ be called in response to + * event processing functions like this one. While it is necessary to poll for + * events, window systems that require GLFW to register callbacks of its own + * can pass events to GLFW in response to many window system function calls. + * GLFW will pass those events on to the application callbacks before + * returning. * * If no windows exist, this function returns immediately. For synchronization * of threads in applications that do not create windows, use your threading @@ -2842,8 +3493,8 @@ GLFWAPI void glfwWaitEvents(void); * @thread_safety This function must only be called from the main thread. * * @sa @ref events - * @sa glfwPollEvents - * @sa glfwWaitEvents + * @sa @ref glfwPollEvents + * @sa @ref glfwWaitEvents * * @since Added in version 3.2. * @@ -2866,8 +3517,8 @@ GLFWAPI void glfwWaitEventsTimeout(double timeout); * @thread_safety This function may be called from any thread. * * @sa @ref events - * @sa glfwWaitEvents - * @sa glfwWaitEventsTimeout + * @sa @ref glfwWaitEvents + * @sa @ref glfwWaitEventsTimeout * * @since Added in version 3.1. * @@ -2878,8 +3529,8 @@ GLFWAPI void glfwPostEmptyEvent(void); /*! @brief Returns the value of an input option for the specified window. * * This function returns the value of an input option for the specified window. - * The mode must be one of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or - * `GLFW_STICKY_MOUSE_BUTTONS`. + * The mode must be one of @ref GLFW_CURSOR, @ref GLFW_STICKY_KEYS or + * @ref GLFW_STICKY_MOUSE_BUTTONS. * * @param[in] window The window to query. * @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or @@ -2890,7 +3541,7 @@ GLFWAPI void glfwPostEmptyEvent(void); * * @thread_safety This function must only be called from the main thread. * - * @sa glfwSetInputMode + * @sa @ref glfwSetInputMode * * @since Added in version 3.0. * @@ -2901,8 +3552,8 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode); /*! @brief Sets an input option for the specified window. * * This function sets an input mode option for the specified window. The mode - * must be one of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or - * `GLFW_STICKY_MOUSE_BUTTONS`. + * must be one of @ref GLFW_CURSOR, @ref GLFW_STICKY_KEYS or + * @ref GLFW_STICKY_MOUSE_BUTTONS. * * If the mode is `GLFW_CURSOR`, the value must be one of the following cursor * modes: @@ -2938,7 +3589,7 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode); * * @thread_safety This function must only be called from the main thread. * - * @sa glfwGetInputMode + * @sa @ref glfwGetInputMode * * @since Added in version 3.0. Replaces `glfwEnable` and `glfwDisable`. * @@ -2946,17 +3597,22 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode); */ GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value); -/*! @brief Returns the localized name of the specified printable key. +/*! @brief Returns the layout-specific name of the specified printable key. + * + * This function returns the name of the specified printable key, encoded as + * UTF-8. This is typically the character that key would produce without any + * modifier keys, intended for displaying key bindings to the user. For dead + * keys, it is typically the diacritic it would add to a character. * - * This function returns the localized name of the specified printable key. - * This is intended for displaying key bindings to the user. + * __Do not use this function__ for [text input](@ref input_char). You will + * break text input for many languages even if it happens to work for yours. * - * If the key is `GLFW_KEY_UNKNOWN`, the scancode is used instead, otherwise - * the scancode is ignored. If a non-printable key or (if the key is - * `GLFW_KEY_UNKNOWN`) a scancode that maps to a non-printable key is - * specified, this function returns `NULL`. + * If the key is `GLFW_KEY_UNKNOWN`, the scancode is used to identify the key, + * otherwise the scancode is ignored. If you specify a non-printable key, or + * `GLFW_KEY_UNKNOWN` and a scancode that maps to a non-printable key, this + * function returns `NULL` but does not emit an error. * - * This behavior allows you to pass in the arguments passed to the + * This behavior allows you to always pass in the arguments in the * [key callback](@ref input_key) without modification. * * The printable keys are: @@ -2982,9 +3638,13 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value); * - `GLFW_KEY_KP_ADD` * - `GLFW_KEY_KP_EQUAL` * + * Names for printable keys depend on keyboard layout, while names for + * non-printable keys are the same across layouts but depend on the application + * language and should be localized along with other user interface text. + * * @param[in] key The key to query, or `GLFW_KEY_UNKNOWN`. * @param[in] scancode The scancode of the key to query. - * @return The localized name of the key, or `NULL`. + * @return The UTF-8 encoded, layout-specific name of the key, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. @@ -3003,6 +3663,30 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value); */ GLFWAPI const char* glfwGetKeyName(int key, int scancode); +/*! @brief Returns the platform-specific scancode of the specified key. + * + * This function returns the platform-specific scancode of the specified key. + * + * If the key is `GLFW_KEY_UNKNOWN` or does not exist on the keyboard this + * method will return `-1`. + * + * @param[in] key Any [named key](@ref keys). + * @return The platform-specific scancode for the key, or `-1` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref input_key + * + * @since Added in version 3.3. + * + * @ingroup input + */ +GLFWAPI int glfwGetKeyScancode(int key); + /*! @brief Returns the last reported state of a keyboard key for the specified * window. * @@ -3011,7 +3695,7 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode); * `GLFW_RELEASE`. The higher-level action `GLFW_REPEAT` is only reported to * the key callback. * - * If the `GLFW_STICKY_KEYS` input mode is enabled, this function returns + * If the @ref GLFW_STICKY_KEYS input mode is enabled, this function returns * `GLFW_PRESS` the first time you call it for a key that was pressed, even if * that key has already been released. * @@ -3050,7 +3734,7 @@ GLFWAPI int glfwGetKey(GLFWwindow* window, int key); * to the specified window. The returned state is one of `GLFW_PRESS` or * `GLFW_RELEASE`. * - * If the `GLFW_STICKY_MOUSE_BUTTONS` input mode is enabled, this function + * If the @ref GLFW_STICKY_MOUSE_BUTTONS input mode is enabled, this function * `GLFW_PRESS` the first time you call it for a mouse button that was pressed, * even if that mouse button has already been released. * @@ -3102,7 +3786,7 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* window, int button); * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_pos - * @sa glfwSetCursorPos + * @sa @ref glfwSetCursorPos * * @since Added in version 3.0. Replaces `glfwGetMousePos`. * @@ -3136,10 +3820,13 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos); * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark @wayland This function will only work when the cursor mode is + * `GLFW_CURSOR_DISABLED`, otherwise it will do nothing. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_pos - * @sa glfwGetCursorPos + * @sa @ref glfwGetCursorPos * * @since Added in version 3.0. Replaces `glfwSetMousePos`. * @@ -3154,8 +3841,8 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos); * Any remaining cursors are destroyed by @ref glfwTerminate. * * The pixels are 32-bit, little-endian, non-premultiplied RGBA, i.e. eight - * bits per channel. They are arranged canonically as packed sequential rows, - * starting from the top-left corner. + * bits per channel with the red channel first. They are arranged canonically + * as packed sequential rows, starting from the top-left corner. * * The cursor hotspot is specified in pixels, relative to the upper-left corner * of the cursor image. Like all other coordinate systems in GLFW, the X-axis @@ -3173,13 +3860,11 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos); * @pointer_lifetime The specified image data is copied before this function * returns. * - * @reentrancy This function must not be called from a callback. - * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_object - * @sa glfwDestroyCursor - * @sa glfwCreateStandardCursor + * @sa @ref glfwDestroyCursor + * @sa @ref glfwCreateStandardCursor * * @since Added in version 3.1. * @@ -3199,12 +3884,10 @@ GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot) * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. * - * @reentrancy This function must not be called from a callback. - * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_object - * @sa glfwCreateCursor + * @sa @ref glfwCreateCursor * * @since Added in version 3.1. * @@ -3218,6 +3901,9 @@ GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape); * glfwCreateCursor. Any remaining cursors will be destroyed by @ref * glfwTerminate. * + * If the specified cursor is current for any window, that window will be + * reverted to the default cursor. This does not affect the cursor mode. + * * @param[in] cursor The cursor object to destroy. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref @@ -3228,7 +3914,7 @@ GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape); * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_object - * @sa glfwCreateCursor + * @sa @ref glfwCreateCursor * * @since Added in version 3.1. * @@ -3320,7 +4006,7 @@ GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun); * * The character callback behaves as system text input normally does and will * not be called if modifier keys are held down that would prevent normal text - * input on that platform, for example a Super (Command) key on OS X or Alt key + * input on that platform, for example a Super (Command) key on macOS or Alt key * on Windows. There is a * [character with modifiers callback](@ref glfwSetCharModsCallback) that * receives these events. @@ -3501,6 +4187,8 @@ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cb * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * + * @remark @wayland File drop is currently unimplemented. + * * @thread_safety This function must only be called from the main thread. * * @sa @ref path_drop @@ -3515,7 +4203,11 @@ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun); * * This function returns whether the specified joystick is present. * - * @param[in] joy The [joystick](@ref joysticks) to query. + * There is no need to call this function before other functions that accept + * a joystick ID, as they all check for presence before performing any other + * work. + * + * @param[in] jid The [joystick](@ref joysticks) to query. * @return `GLFW_TRUE` if the joystick is present, or `GLFW_FALSE` otherwise. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref @@ -3529,18 +4221,18 @@ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun); * * @ingroup input */ -GLFWAPI int glfwJoystickPresent(int joy); +GLFWAPI int glfwJoystickPresent(int jid); /*! @brief Returns the values of all axes of the specified joystick. * * This function returns the values of all axes of the specified joystick. * Each element in the array is a value between -1.0 and 1.0. * - * Querying a joystick slot with no device present is not an error, but will - * cause this function to return `NULL`. Call @ref glfwJoystickPresent to - * check device presence. + * If the specified joystick is not present this function will return `NULL` + * but will not generate an error. This can be used instead of first calling + * @ref glfwJoystickPresent. * - * @param[in] joy The [joystick](@ref joysticks) to query. + * @param[in] jid The [joystick](@ref joysticks) to query. * @param[out] count Where to store the number of axis values in the returned * array. This is set to zero if the joystick is not present or an error * occurred. @@ -3552,8 +4244,7 @@ GLFWAPI int glfwJoystickPresent(int joy); * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified joystick is - * disconnected, this function is called again for that joystick or the library - * is terminated. + * disconnected or the library is terminated. * * @thread_safety This function must only be called from the main thread. * @@ -3563,18 +4254,25 @@ GLFWAPI int glfwJoystickPresent(int joy); * * @ingroup input */ -GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count); +GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count); /*! @brief Returns the state of all buttons of the specified joystick. * * This function returns the state of all buttons of the specified joystick. * Each element in the array is either `GLFW_PRESS` or `GLFW_RELEASE`. * - * Querying a joystick slot with no device present is not an error, but will - * cause this function to return `NULL`. Call @ref glfwJoystickPresent to - * check device presence. + * For backward compatibility with earlier versions that did not have @ref + * glfwGetJoystickHats, the button array also includes all hats, each + * represented as four buttons. The hats are in the same order as returned by + * __glfwGetJoystickHats__ and are in the order _up_, _right_, _down_ and + * _left_. To disable these extra buttons, set the @ref + * GLFW_JOYSTICK_HAT_BUTTONS init hint before initialization. * - * @param[in] joy The [joystick](@ref joysticks) to query. + * If the specified joystick is not present this function will return `NULL` + * but will not generate an error. This can be used instead of first calling + * @ref glfwJoystickPresent. + * + * @param[in] jid The [joystick](@ref joysticks) to query. * @param[out] count Where to store the number of button states in the returned * array. This is set to zero if the joystick is not present or an error * occurred. @@ -3586,8 +4284,7 @@ GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count); * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified joystick is - * disconnected, this function is called again for that joystick or the library - * is terminated. + * disconnected or the library is terminated. * * @thread_safety This function must only be called from the main thread. * @@ -3598,7 +4295,64 @@ GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count); * * @ingroup input */ -GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count); +GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count); + +/*! @brief Returns the state of all hats of the specified joystick. + * + * This function returns the state of all hats of the specified joystick. + * Each element in the array is one of the following values: + * + * Name | Value + * --------------------- | -------------------------------- + * `GLFW_HAT_CENTERED` | 0 + * `GLFW_HAT_UP` | 1 + * `GLFW_HAT_RIGHT` | 2 + * `GLFW_HAT_DOWN` | 4 + * `GLFW_HAT_LEFT` | 8 + * `GLFW_HAT_RIGHT_UP` | `GLFW_HAT_RIGHT` \| `GLFW_HAT_UP` + * `GLFW_HAT_RIGHT_DOWN` | `GLFW_HAT_RIGHT` \| `GLFW_HAT_DOWN` + * `GLFW_HAT_LEFT_UP` | `GLFW_HAT_LEFT` \| `GLFW_HAT_UP` + * `GLFW_HAT_LEFT_DOWN` | `GLFW_HAT_LEFT` \| `GLFW_HAT_DOWN` + * + * The diagonal directions are bitwise combinations of the primary (up, right, + * down and left) directions and you can test for these individually by ANDing + * it with the corresponding direction. + * + * @code + * if (hats[2] & GLFW_HAT_RIGHT) + * { + * // State of hat 2 could be right-up, right or right-down + * } + * @endcode + * + * If the specified joystick is not present this function will return `NULL` + * but will not generate an error. This can be used instead of first calling + * @ref glfwJoystickPresent. + * + * @param[in] jid The [joystick](@ref joysticks) to query. + * @param[out] count Where to store the number of hat states in the returned + * array. This is set to zero if the joystick is not present or an error + * occurred. + * @return An array of hat states, or `NULL` if the joystick is not present + * or an [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned array is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the specified joystick is + * disconnected, this function is called again for that joystick or the library + * is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref joystick_hat + * + * @since Added in version 3.3. + * + * @ingroup input + */ +GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count); /*! @brief Returns the name of the specified joystick. * @@ -3606,11 +4360,11 @@ GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count); * The returned string is allocated and freed by GLFW. You should not free it * yourself. * - * Querying a joystick slot with no device present is not an error, but will - * cause this function to return `NULL`. Call @ref glfwJoystickPresent to - * check device presence. + * If the specified joystick is not present this function will return `NULL` + * but will not generate an error. This can be used instead of first calling + * @ref glfwJoystickPresent. * - * @param[in] joy The [joystick](@ref joysticks) to query. + * @param[in] jid The [joystick](@ref joysticks) to query. * @return The UTF-8 encoded name of the joystick, or `NULL` if the joystick * is not present or an [error](@ref error_handling) occurred. * @@ -3619,8 +4373,7 @@ GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count); * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified joystick is - * disconnected, this function is called again for that joystick or the library - * is terminated. + * disconnected or the library is terminated. * * @thread_safety This function must only be called from the main thread. * @@ -3630,7 +4383,76 @@ GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count); * * @ingroup input */ -GLFWAPI const char* glfwGetJoystickName(int joy); +GLFWAPI const char* glfwGetJoystickName(int jid); + +/*! @brief Returns the SDL comaptible GUID of the specified joystick. + * + * This function returns the SDL compatible GUID, as a UTF-8 encoded + * hexadecimal string, of the specified joystick. The returned string is + * allocated and freed by GLFW. You should not free it yourself. + * + * The GUID is what connects a joystick to a gamepad mapping. A connected + * joystick will always have a GUID even if there is no gamepad mapping + * assigned to it. + * + * If the specified joystick is not present this function will return `NULL` + * but will not generate an error. This can be used instead of first calling + * @ref glfwJoystickPresent. + * + * The GUID uses the format introduced in SDL 2.0.5. This GUID tries to + * uniquely identify the make and model of a joystick but does not identify + * a specific unit, e.g. all wired Xbox 360 controllers will have the same + * GUID on that platform. The GUID for a unit may vary between platforms + * depending on what hardware information the platform specific APIs provide. + * + * @param[in] jid The [joystick](@ref joysticks) to query. + * @return The UTF-8 encoded GUID of the joystick, or `NULL` if the joystick + * is not present or an [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned string is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the specified joystick is + * disconnected or the library is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref gamepad + * + * @since Added in version 3.3. + * + * @ingroup input + */ +GLFWAPI const char* glfwGetJoystickGUID(int jid); + +/*! @brief Returns whether the specified joystick has a gamepad mapping. + * + * This function returns whether the specified joystick is both present and has + * a gamepad mapping. + * + * If the specified joystick is present but does not have a gamepad mapping + * this function will return `GLFW_FALSE` but will not generate an error. Call + * @ref glfwJoystickPresent to check if a joystick is present regardless of + * whether it has a mapping. + * + * @param[in] jid The [joystick](@ref joysticks) to query. + * @return `GLFW_TRUE` if a joystick is both present and has a gamepad mapping, + * or `GLFW_FALSE` otherwise. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_INVALID_ENUM. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref gamepad + * @sa @ref glfwGetGamepadState + * + * @since Added in version 3.3. + * + * @ingroup input + */ +GLFWAPI int glfwJoystickIsGamepad(int jid); /*! @brief Sets the joystick configuration callback. * @@ -3638,6 +4460,12 @@ GLFWAPI const char* glfwGetJoystickName(int joy); * currently set callback. This is called when a joystick is connected to or * disconnected from the system. * + * For joystick connection and disconnection events to be delivered on all + * platforms, you need to call one of the [event processing](@ref events) + * functions. Joystick disconnection may also be detected and the callback + * called by joystick functions. The function will then return whatever it + * returns if the joystick is not present. + * * @param[in] cbfun The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the @@ -3655,6 +4483,106 @@ GLFWAPI const char* glfwGetJoystickName(int joy); */ GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun); +/*! @brief Adds the specified SDL_GameControllerDB gamepad mappings. + * + * This function parses the specified ASCII encoded string and updates the + * internal list with any gamepad mappings it finds. This string may + * contain either a single gamepad mapping or many mappings separated by + * newlines. The parser supports the full format of the `gamecontrollerdb.txt` + * source file including empty lines and comments. + * + * See @ref gamepad_mapping for a description of the format. + * + * If there is already a gamepad mapping for a given GUID in the internal list, + * it will be replaced by the one passed to this function. If the library is + * terminated and re-initialized the internal list will revert to the built-in + * default. + * + * @param[in] string The string containing the gamepad mappings. + * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_INVALID_VALUE. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref gamepad + * @sa @ref glfwJoystickIsGamepad + * @sa @ref glfwGetGamepadName + * + * @since Added in version 3.3. + * + * @ingroup input + */ +GLFWAPI int glfwUpdateGamepadMappings(const char* string); + +/*! @brief Returns the human-readable gamepad name for the specified joystick. + * + * This function returns the human-readable name of the gamepad from the + * gamepad mapping assigned to the specified joystick. + * + * If the specified joystick is not present or does not have a gamepad mapping + * this function will return `NULL` but will not generate an error. Call + * @ref glfwJoystickPresent to check whether it is present regardless of + * whether it has a mapping. + * + * @param[in] jid The [joystick](@ref joysticks) to query. + * @return The UTF-8 encoded name of the gamepad, or `NULL` if the + * joystick is not present, does not have a mapping or an + * [error](@ref error_handling) occurred. + * + * @pointer_lifetime The returned string is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the specified joystick is + * disconnected, the gamepad mappings are updated or the library is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref gamepad + * @sa @ref glfwJoystickIsGamepad + * + * @since Added in version 3.3. + * + * @ingroup input + */ +GLFWAPI const char* glfwGetGamepadName(int jid); + +/*! @brief Retrieves the state of the specified joystick remapped as a gamepad. + * + * This function retrives the state of the specified joystick remapped to + * an Xbox-like gamepad. + * + * If the specified joystick is not present or does not have a gamepad mapping + * this function will return `GLFW_FALSE` but will not generate an error. Call + * @ref glfwJoystickPresent to check whether it is present regardless of + * whether it has a mapping. + * + * The Guide button may not be available for input as it is often hooked by the + * system or the Steam client. + * + * Not all devices have all the buttons or axes provided by @ref + * GLFWgamepadstate. Unavailable buttons and axes will always report + * `GLFW_RELEASE` and 1.0 respectively. + * + * @param[in] jid The [joystick](@ref joysticks) to query. + * @param[out] state The gamepad input state of the joystick. + * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if no joystick is + * connected, it has no gamepad mapping or an [error](@ref error_handling) + * occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_INVALID_ENUM. + * + * @sa @ref gamepad + * @sa @ref glfwUpdateGamepadMappings + * @sa @ref glfwJoystickIsGamepad + * + * @since Added in version 3.3. + * + * @ingroup input + */ +GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state); + /*! @brief Sets the clipboard to the specified string. * * This function sets the system clipboard to the specified, UTF-8 encoded @@ -3666,13 +4594,15 @@ GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun); * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark @wayland Clipboard is currently unimplemented. + * * @pointer_lifetime The specified string is copied before this function * returns. * * @thread_safety This function must only be called from the main thread. * * @sa @ref clipboard - * @sa glfwGetClipboardString + * @sa @ref glfwGetClipboardString * * @since Added in version 3.0. * @@ -3694,6 +4624,8 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string); * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * + * @remark @wayland Clipboard is currently unimplemented. + * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is valid until the next call to @ref * glfwGetClipboardString or @ref glfwSetClipboardString, or until the library @@ -3702,7 +4634,7 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string); * @thread_safety This function must only be called from the main thread. * * @sa @ref clipboard - * @sa glfwSetClipboardString + * @sa @ref glfwSetClipboardString * * @since Added in version 3.0. * @@ -3778,7 +4710,7 @@ GLFWAPI void glfwSetTime(double time); * @thread_safety This function may be called from any thread. * * @sa @ref time - * @sa glfwGetTimerFrequency + * @sa @ref glfwGetTimerFrequency * * @since Added in version 3.2. * @@ -3798,7 +4730,7 @@ GLFWAPI uint64_t glfwGetTimerValue(void); * @thread_safety This function may be called from any thread. * * @sa @ref time - * @sa glfwGetTimerValue + * @sa @ref glfwGetTimerValue * * @since Added in version 3.2. * @@ -3817,7 +4749,8 @@ GLFWAPI uint64_t glfwGetTimerFrequency(void); * By default, making a context non-current implicitly forces a pipeline flush. * On machines that support `GL_KHR_context_flush_control`, you can control * whether a context performs this flush by setting the - * [GLFW_CONTEXT_RELEASE_BEHAVIOR](@ref window_hints_ctx) window hint. + * [GLFW_CONTEXT_RELEASE_BEHAVIOR](@ref GLFW_CONTEXT_RELEASE_BEHAVIOR_hint) + * hint. * * The specified window must have an OpenGL or OpenGL ES context. Specifying * a window without a context will generate a @ref GLFW_NO_WINDOW_CONTEXT @@ -3832,7 +4765,7 @@ GLFWAPI uint64_t glfwGetTimerFrequency(void); * @thread_safety This function may be called from any thread. * * @sa @ref context_current - * @sa glfwGetCurrentContext + * @sa @ref glfwGetCurrentContext * * @since Added in version 3.0. * @@ -3853,7 +4786,7 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* window); * @thread_safety This function may be called from any thread. * * @sa @ref context_current - * @sa glfwMakeContextCurrent + * @sa @ref glfwMakeContextCurrent * * @since Added in version 3.0. * @@ -3886,7 +4819,7 @@ GLFWAPI GLFWwindow* glfwGetCurrentContext(void); * @thread_safety This function may be called from any thread. * * @sa @ref buffer_swap - * @sa glfwSwapInterval + * @sa @ref glfwSwapInterval * * @since Added in version 1.0. * @glfw3 Added window handle parameter. @@ -3934,7 +4867,7 @@ GLFWAPI void glfwSwapBuffers(GLFWwindow* window); * @thread_safety This function may be called from any thread. * * @sa @ref buffer_swap - * @sa glfwSwapBuffers + * @sa @ref glfwSwapBuffers * * @since Added in version 1.0. * @@ -3972,7 +4905,7 @@ GLFWAPI void glfwSwapInterval(int interval); * @thread_safety This function may be called from any thread. * * @sa @ref context_glext - * @sa glfwGetProcAddress + * @sa @ref glfwGetProcAddress * * @since Added in version 1.0. * @@ -4014,7 +4947,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension); * @thread_safety This function may be called from any thread. * * @sa @ref context_glext - * @sa glfwExtensionSupported + * @sa @ref glfwExtensionSupported * * @since Added in version 1.0. * @@ -4022,19 +4955,21 @@ GLFWAPI int glfwExtensionSupported(const char* extension); */ GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname); -/*! @brief Returns whether the Vulkan loader has been found. +/*! @brief Returns whether the Vulkan loader and an ICD have been found. * - * This function returns whether the Vulkan loader has been found. This check - * is performed by @ref glfwInit. + * This function returns whether the Vulkan loader and any minimally functional + * ICD have been found. * - * The availability of a Vulkan loader does not by itself guarantee that window - * surface creation or even device creation is possible. Call @ref - * glfwGetRequiredInstanceExtensions to check whether the extensions necessary - * for Vulkan surface creation are available and @ref - * glfwGetPhysicalDevicePresentationSupport to check whether a queue family of - * a physical device supports image presentation. + * The availability of a Vulkan loader and even an ICD does not by itself + * guarantee that surface creation or even instance creation is possible. + * For example, on Fermi systems Nvidia will install an ICD that provides no + * actual Vulkan support. Call @ref glfwGetRequiredInstanceExtensions to check + * whether the extensions necessary for Vulkan surface creation are available + * and @ref glfwGetPhysicalDevicePresentationSupport to check whether a queue + * family of a physical device supports image presentation. * - * @return `GLFW_TRUE` if Vulkan is available, or `GLFW_FALSE` otherwise. + * @return `GLFW_TRUE` if Vulkan is minimally available, or `GLFW_FALSE` + * otherwise. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @@ -4058,7 +4993,7 @@ GLFWAPI int glfwVulkanSupported(void); * * If Vulkan is not available on the machine, this function returns `NULL` and * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported - * to check whether Vulkan is available. + * to check whether Vulkan is at least minimally available. * * If Vulkan is available but no set of extensions allowing window surface * creation was found, this function returns `NULL`. You may still use Vulkan @@ -4072,11 +5007,14 @@ GLFWAPI int glfwVulkanSupported(void); * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_API_UNAVAILABLE. * - * @remarks Additional extensions may be required by future versions of GLFW. + * @remark Additional extensions may be required by future versions of GLFW. * You should check if any extensions you wish to enable are already in the * returned array, as it is an error to specify an extension more than once in * the `VkInstanceCreateInfo` struct. * + * @remark @macos This function currently only supports the + * `VK_MVK_macos_surface` extension from MoltenVK. + * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is guaranteed to be valid only until the * library is terminated. @@ -4084,7 +5022,7 @@ GLFWAPI int glfwVulkanSupported(void); * @thread_safety This function may be called from any thread. * * @sa @ref vulkan_ext - * @sa glfwCreateWindowSurface + * @sa @ref glfwCreateWindowSurface * * @since Added in version 3.2. * @@ -4108,7 +5046,7 @@ GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count); * * If Vulkan is not available on the machine, this function returns `NULL` and * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported - * to check whether Vulkan is available. + * to check whether Vulkan is at least minimally available. * * This function is equivalent to calling `vkGetInstanceProcAddr` with * a platform-specific query of the Vulkan loader as a fallback. @@ -4144,7 +5082,7 @@ GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* p * not available on the machine, or if the specified instance was not created * with the required extensions, this function returns `GLFW_FALSE` and * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported - * to check whether Vulkan is available and @ref + * to check whether Vulkan is at least minimally available and @ref * glfwGetRequiredInstanceExtensions to check what instance extensions are * required. * @@ -4157,6 +5095,10 @@ GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* p * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_API_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR. * + * @remark @macos This function currently always returns `GLFW_TRUE`, as the + * `VK_MVK_macos_surface` extension does not provide + * a `vkGetPhysicalDevice*PresentationSupport` type function. + * * @thread_safety This function may be called from any thread. For * synchronization details of Vulkan objects, see the Vulkan specification. * @@ -4172,10 +5114,10 @@ GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhys * * This function creates a Vulkan surface for the specified window. * - * If the Vulkan loader was not found at initialization, this function returns - * `VK_ERROR_INITIALIZATION_FAILED` and generates a @ref GLFW_API_UNAVAILABLE - * error. Call @ref glfwVulkanSupported to check whether the Vulkan loader was - * found. + * If the Vulkan loader or at least one minimally functional ICD were not found, + * this function returns `VK_ERROR_INITIALIZATION_FAILED` and generates a @ref + * GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported to check whether + * Vulkan is at least minimally available. * * If the required window surface creation instance extensions are not * available or if the specified instance was not created with these extensions @@ -4201,16 +5143,22 @@ GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhys * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_API_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR. * - * @remarks If an error occurs before the creation call is made, GLFW returns + * @remark If an error occurs before the creation call is made, GLFW returns * the Vulkan error code most appropriate for the error. Appropriate use of * @ref glfwVulkanSupported and @ref glfwGetRequiredInstanceExtensions should * eliminate almost all occurrences of these errors. * + * @remark @macos This function currently only supports the + * `VK_MVK_macos_surface` extension from MoltenVK. + * + * @remark @macos This function creates and sets a `CAMetalLayer` instance for + * the window content view, which is required for MoltenVK to function. + * * @thread_safety This function may be called from any thread. For * synchronization details of Vulkan objects, see the Vulkan specification. * * @sa @ref vulkan_surface - * @sa glfwGetRequiredInstanceExtensions + * @sa @ref glfwGetRequiredInstanceExtensions * * @since Added in version 3.2. * @@ -4237,6 +5185,13 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window #undef GLFW_CALLBACK_DEFINED #endif +/* Some OpenGL related headers need GLAPIENTRY, but it is unconditionally + * defined by some gl.h variants (OpenBSD) so define it after if needed. + */ +#ifndef GLAPIENTRY + #define GLAPIENTRY APIENTRY +#endif + /* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */ diff --git a/libs/glfw/include/GLFW/glfw3native.h b/libs/glfw/include/GLFW/glfw3native.h @@ -1,9 +1,9 @@ /************************************************************************* - * GLFW 3.2 - www.glfw.org + * GLFW 3.3 - www.glfw.org * A library for OpenGL, window and input *------------------------------------------------------------------------ * Copyright (c) 2002-2006 Marcus Geelnard - * Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> + * Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -45,12 +45,13 @@ extern "C" { * more information. */ /*! @defgroup native Native access + * @brief Functions related to accessing native handles. * * **By using the native access functions you assert that you know what you're * doing and how to fix problems caused by using them. If you don't, you * shouldn't be using them.** * - * Before the inclusion of @ref glfw3native.h, you may define exactly one + * Before the inclusion of @ref glfw3native.h, you may define zero or more * window system API macro and zero or more context creation API macros. * * The chosen backends must match those the library was compiled for. Failure @@ -68,6 +69,7 @@ extern "C" { * * `GLFW_EXPOSE_NATIVE_NSGL` * * `GLFW_EXPOSE_NATIVE_GLX` * * `GLFW_EXPOSE_NATIVE_EGL` + * * `GLFW_EXPOSE_NATIVE_OSMESA` * * These macros select which of the native access functions that are declared * and which platform-specific headers to include. It is then up your (by @@ -114,6 +116,9 @@ extern "C" { #if defined(GLFW_EXPOSE_NATIVE_EGL) #include <EGL/egl.h> #endif +#if defined(GLFW_EXPOSE_NATIVE_OSMESA) + #include <GL/osmesa.h> +#endif /************************************************************************* @@ -284,6 +289,56 @@ GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor); * @ingroup native */ GLFWAPI Window glfwGetX11Window(GLFWwindow* window); + +/*! @brief Sets the current primary selection to the specified string. + * + * @param[in] string A UTF-8 encoded string. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The specified string is copied before this function + * returns. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref clipboard + * @sa glfwGetX11SelectionString + * @sa glfwSetClipboardString + * + * @since Added in version 3.3. + * + * @ingroup native + */ +GLFWAPI void glfwSetX11SelectionString(const char* string); + +/*! @brief Returns the contents of the current primary selection as a string. + * + * If the selection is empty or if its contents cannot be converted, `NULL` + * is returned and a @ref GLFW_FORMAT_UNAVAILABLE error is generated. + * + * @return The contents of the selection as a UTF-8 encoded string, or `NULL` + * if an [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref + * GLFW_PLATFORM_ERROR. + * + * @pointer_lifetime The returned string is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the next call to @ref + * glfwGetX11SelectionString or @ref glfwSetX11SelectionString, or until the + * library is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref clipboard + * @sa glfwSetX11SelectionString + * @sa glfwGetClipboardString + * + * @since Added in version 3.3. + * + * @ingroup native + */ +GLFWAPI const char* glfwGetX11SelectionString(void); #endif #if defined(GLFW_EXPOSE_NATIVE_GLX) @@ -389,9 +444,9 @@ GLFWAPI MirConnection* glfwGetMirDisplay(void); */ GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor); -/*! @brief Returns the `MirSurface*` of the specified window. +/*! @brief Returns the `MirWindow*` of the specified window. * - * @return The `MirSurface*` of the specified window, or `NULL` if an + * @return The `MirWindow*` of the specified window, or `NULL` if an * [error](@ref error_handling) occurred. * * @thread_safety This function may be called from any thread. Access is not @@ -401,7 +456,7 @@ GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor); * * @ingroup native */ -GLFWAPI MirSurface* glfwGetMirWindow(GLFWwindow* window); +GLFWAPI MirWindow* glfwGetMirWindow(GLFWwindow* window); #endif #if defined(GLFW_EXPOSE_NATIVE_EGL) @@ -448,6 +503,64 @@ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window); GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window); #endif +#if defined(GLFW_EXPOSE_NATIVE_OSMESA) +/*! @brief Retrieves the color buffer associated with the specified window. + * + * @param[in] window The window whose color buffer to retrieve. + * @param[out] width Where to store the width of the color buffer, or `NULL`. + * @param[out] height Where to store the height of the color buffer, or `NULL`. + * @param[out] format Where to store the OSMesa pixel format of the color + * buffer, or `NULL`. + * @param[out] buffer Where to store the address of the color buffer, or + * `NULL`. + * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.3. + * + * @ingroup native + */ +GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* window, int* width, int* height, int* format, void** buffer); + +/*! @brief Retrieves the depth buffer associated with the specified window. + * + * @param[in] window The window whose depth buffer to retrieve. + * @param[out] width Where to store the width of the depth buffer, or `NULL`. + * @param[out] height Where to store the height of the depth buffer, or `NULL`. + * @param[out] bytesPerValue Where to store the number of bytes per depth + * buffer element, or `NULL`. + * @param[out] buffer Where to store the address of the depth buffer, or + * `NULL`. + * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.3. + * + * @ingroup native + */ +GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height, int* bytesPerValue, void** buffer); + +/*! @brief Returns the `OSMesaContext` of the specified window. + * + * @return The `OSMesaContext` of the specified window, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.3. + * + * @ingroup native + */ +GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* window); +#endif + #ifdef __cplusplus } #endif diff --git a/libs/glfw/src/cocoa_init.m b/libs/glfw/src/cocoa_init.m @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 OS X - www.glfw.org +// GLFW 3.3 macOS - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2009-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2009-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -28,8 +28,6 @@ #include <sys/param.h> // For MAXPATHLEN -#if defined(_GLFW_USE_CHDIR) - // Change to our application bundle's resources directory, if present // static void changeToResourcesDirectory(void) @@ -66,137 +64,135 @@ static void changeToResourcesDirectory(void) chdir(resourcesPath); } -#endif /* _GLFW_USE_CHDIR */ - // Create key code translation tables // static void createKeyTables(void) { int scancode; - memset(_glfw.ns.publicKeys, -1, sizeof(_glfw.ns.publicKeys)); - memset(_glfw.ns.nativeKeys, -1, sizeof(_glfw.ns.nativeKeys)); - - _glfw.ns.publicKeys[0x1D] = GLFW_KEY_0; - _glfw.ns.publicKeys[0x12] = GLFW_KEY_1; - _glfw.ns.publicKeys[0x13] = GLFW_KEY_2; - _glfw.ns.publicKeys[0x14] = GLFW_KEY_3; - _glfw.ns.publicKeys[0x15] = GLFW_KEY_4; - _glfw.ns.publicKeys[0x17] = GLFW_KEY_5; - _glfw.ns.publicKeys[0x16] = GLFW_KEY_6; - _glfw.ns.publicKeys[0x1A] = GLFW_KEY_7; - _glfw.ns.publicKeys[0x1C] = GLFW_KEY_8; - _glfw.ns.publicKeys[0x19] = GLFW_KEY_9; - _glfw.ns.publicKeys[0x00] = GLFW_KEY_A; - _glfw.ns.publicKeys[0x0B] = GLFW_KEY_B; - _glfw.ns.publicKeys[0x08] = GLFW_KEY_C; - _glfw.ns.publicKeys[0x02] = GLFW_KEY_D; - _glfw.ns.publicKeys[0x0E] = GLFW_KEY_E; - _glfw.ns.publicKeys[0x03] = GLFW_KEY_F; - _glfw.ns.publicKeys[0x05] = GLFW_KEY_G; - _glfw.ns.publicKeys[0x04] = GLFW_KEY_H; - _glfw.ns.publicKeys[0x22] = GLFW_KEY_I; - _glfw.ns.publicKeys[0x26] = GLFW_KEY_J; - _glfw.ns.publicKeys[0x28] = GLFW_KEY_K; - _glfw.ns.publicKeys[0x25] = GLFW_KEY_L; - _glfw.ns.publicKeys[0x2E] = GLFW_KEY_M; - _glfw.ns.publicKeys[0x2D] = GLFW_KEY_N; - _glfw.ns.publicKeys[0x1F] = GLFW_KEY_O; - _glfw.ns.publicKeys[0x23] = GLFW_KEY_P; - _glfw.ns.publicKeys[0x0C] = GLFW_KEY_Q; - _glfw.ns.publicKeys[0x0F] = GLFW_KEY_R; - _glfw.ns.publicKeys[0x01] = GLFW_KEY_S; - _glfw.ns.publicKeys[0x11] = GLFW_KEY_T; - _glfw.ns.publicKeys[0x20] = GLFW_KEY_U; - _glfw.ns.publicKeys[0x09] = GLFW_KEY_V; - _glfw.ns.publicKeys[0x0D] = GLFW_KEY_W; - _glfw.ns.publicKeys[0x07] = GLFW_KEY_X; - _glfw.ns.publicKeys[0x10] = GLFW_KEY_Y; - _glfw.ns.publicKeys[0x06] = GLFW_KEY_Z; - - _glfw.ns.publicKeys[0x27] = GLFW_KEY_APOSTROPHE; - _glfw.ns.publicKeys[0x2A] = GLFW_KEY_BACKSLASH; - _glfw.ns.publicKeys[0x2B] = GLFW_KEY_COMMA; - _glfw.ns.publicKeys[0x18] = GLFW_KEY_EQUAL; - _glfw.ns.publicKeys[0x32] = GLFW_KEY_GRAVE_ACCENT; - _glfw.ns.publicKeys[0x21] = GLFW_KEY_LEFT_BRACKET; - _glfw.ns.publicKeys[0x1B] = GLFW_KEY_MINUS; - _glfw.ns.publicKeys[0x2F] = GLFW_KEY_PERIOD; - _glfw.ns.publicKeys[0x1E] = GLFW_KEY_RIGHT_BRACKET; - _glfw.ns.publicKeys[0x29] = GLFW_KEY_SEMICOLON; - _glfw.ns.publicKeys[0x2C] = GLFW_KEY_SLASH; - _glfw.ns.publicKeys[0x0A] = GLFW_KEY_WORLD_1; - - _glfw.ns.publicKeys[0x33] = GLFW_KEY_BACKSPACE; - _glfw.ns.publicKeys[0x39] = GLFW_KEY_CAPS_LOCK; - _glfw.ns.publicKeys[0x75] = GLFW_KEY_DELETE; - _glfw.ns.publicKeys[0x7D] = GLFW_KEY_DOWN; - _glfw.ns.publicKeys[0x77] = GLFW_KEY_END; - _glfw.ns.publicKeys[0x24] = GLFW_KEY_ENTER; - _glfw.ns.publicKeys[0x35] = GLFW_KEY_ESCAPE; - _glfw.ns.publicKeys[0x7A] = GLFW_KEY_F1; - _glfw.ns.publicKeys[0x78] = GLFW_KEY_F2; - _glfw.ns.publicKeys[0x63] = GLFW_KEY_F3; - _glfw.ns.publicKeys[0x76] = GLFW_KEY_F4; - _glfw.ns.publicKeys[0x60] = GLFW_KEY_F5; - _glfw.ns.publicKeys[0x61] = GLFW_KEY_F6; - _glfw.ns.publicKeys[0x62] = GLFW_KEY_F7; - _glfw.ns.publicKeys[0x64] = GLFW_KEY_F8; - _glfw.ns.publicKeys[0x65] = GLFW_KEY_F9; - _glfw.ns.publicKeys[0x6D] = GLFW_KEY_F10; - _glfw.ns.publicKeys[0x67] = GLFW_KEY_F11; - _glfw.ns.publicKeys[0x6F] = GLFW_KEY_F12; - _glfw.ns.publicKeys[0x69] = GLFW_KEY_F13; - _glfw.ns.publicKeys[0x6B] = GLFW_KEY_F14; - _glfw.ns.publicKeys[0x71] = GLFW_KEY_F15; - _glfw.ns.publicKeys[0x6A] = GLFW_KEY_F16; - _glfw.ns.publicKeys[0x40] = GLFW_KEY_F17; - _glfw.ns.publicKeys[0x4F] = GLFW_KEY_F18; - _glfw.ns.publicKeys[0x50] = GLFW_KEY_F19; - _glfw.ns.publicKeys[0x5A] = GLFW_KEY_F20; - _glfw.ns.publicKeys[0x73] = GLFW_KEY_HOME; - _glfw.ns.publicKeys[0x72] = GLFW_KEY_INSERT; - _glfw.ns.publicKeys[0x7B] = GLFW_KEY_LEFT; - _glfw.ns.publicKeys[0x3A] = GLFW_KEY_LEFT_ALT; - _glfw.ns.publicKeys[0x3B] = GLFW_KEY_LEFT_CONTROL; - _glfw.ns.publicKeys[0x38] = GLFW_KEY_LEFT_SHIFT; - _glfw.ns.publicKeys[0x37] = GLFW_KEY_LEFT_SUPER; - _glfw.ns.publicKeys[0x6E] = GLFW_KEY_MENU; - _glfw.ns.publicKeys[0x47] = GLFW_KEY_NUM_LOCK; - _glfw.ns.publicKeys[0x79] = GLFW_KEY_PAGE_DOWN; - _glfw.ns.publicKeys[0x74] = GLFW_KEY_PAGE_UP; - _glfw.ns.publicKeys[0x7C] = GLFW_KEY_RIGHT; - _glfw.ns.publicKeys[0x3D] = GLFW_KEY_RIGHT_ALT; - _glfw.ns.publicKeys[0x3E] = GLFW_KEY_RIGHT_CONTROL; - _glfw.ns.publicKeys[0x3C] = GLFW_KEY_RIGHT_SHIFT; - _glfw.ns.publicKeys[0x36] = GLFW_KEY_RIGHT_SUPER; - _glfw.ns.publicKeys[0x31] = GLFW_KEY_SPACE; - _glfw.ns.publicKeys[0x30] = GLFW_KEY_TAB; - _glfw.ns.publicKeys[0x7E] = GLFW_KEY_UP; - - _glfw.ns.publicKeys[0x52] = GLFW_KEY_KP_0; - _glfw.ns.publicKeys[0x53] = GLFW_KEY_KP_1; - _glfw.ns.publicKeys[0x54] = GLFW_KEY_KP_2; - _glfw.ns.publicKeys[0x55] = GLFW_KEY_KP_3; - _glfw.ns.publicKeys[0x56] = GLFW_KEY_KP_4; - _glfw.ns.publicKeys[0x57] = GLFW_KEY_KP_5; - _glfw.ns.publicKeys[0x58] = GLFW_KEY_KP_6; - _glfw.ns.publicKeys[0x59] = GLFW_KEY_KP_7; - _glfw.ns.publicKeys[0x5B] = GLFW_KEY_KP_8; - _glfw.ns.publicKeys[0x5C] = GLFW_KEY_KP_9; - _glfw.ns.publicKeys[0x45] = GLFW_KEY_KP_ADD; - _glfw.ns.publicKeys[0x41] = GLFW_KEY_KP_DECIMAL; - _glfw.ns.publicKeys[0x4B] = GLFW_KEY_KP_DIVIDE; - _glfw.ns.publicKeys[0x4C] = GLFW_KEY_KP_ENTER; - _glfw.ns.publicKeys[0x51] = GLFW_KEY_KP_EQUAL; - _glfw.ns.publicKeys[0x43] = GLFW_KEY_KP_MULTIPLY; - _glfw.ns.publicKeys[0x4E] = GLFW_KEY_KP_SUBTRACT; + memset(_glfw.ns.keycodes, -1, sizeof(_glfw.ns.keycodes)); + memset(_glfw.ns.scancodes, -1, sizeof(_glfw.ns.scancodes)); + + _glfw.ns.keycodes[0x1D] = GLFW_KEY_0; + _glfw.ns.keycodes[0x12] = GLFW_KEY_1; + _glfw.ns.keycodes[0x13] = GLFW_KEY_2; + _glfw.ns.keycodes[0x14] = GLFW_KEY_3; + _glfw.ns.keycodes[0x15] = GLFW_KEY_4; + _glfw.ns.keycodes[0x17] = GLFW_KEY_5; + _glfw.ns.keycodes[0x16] = GLFW_KEY_6; + _glfw.ns.keycodes[0x1A] = GLFW_KEY_7; + _glfw.ns.keycodes[0x1C] = GLFW_KEY_8; + _glfw.ns.keycodes[0x19] = GLFW_KEY_9; + _glfw.ns.keycodes[0x00] = GLFW_KEY_A; + _glfw.ns.keycodes[0x0B] = GLFW_KEY_B; + _glfw.ns.keycodes[0x08] = GLFW_KEY_C; + _glfw.ns.keycodes[0x02] = GLFW_KEY_D; + _glfw.ns.keycodes[0x0E] = GLFW_KEY_E; + _glfw.ns.keycodes[0x03] = GLFW_KEY_F; + _glfw.ns.keycodes[0x05] = GLFW_KEY_G; + _glfw.ns.keycodes[0x04] = GLFW_KEY_H; + _glfw.ns.keycodes[0x22] = GLFW_KEY_I; + _glfw.ns.keycodes[0x26] = GLFW_KEY_J; + _glfw.ns.keycodes[0x28] = GLFW_KEY_K; + _glfw.ns.keycodes[0x25] = GLFW_KEY_L; + _glfw.ns.keycodes[0x2E] = GLFW_KEY_M; + _glfw.ns.keycodes[0x2D] = GLFW_KEY_N; + _glfw.ns.keycodes[0x1F] = GLFW_KEY_O; + _glfw.ns.keycodes[0x23] = GLFW_KEY_P; + _glfw.ns.keycodes[0x0C] = GLFW_KEY_Q; + _glfw.ns.keycodes[0x0F] = GLFW_KEY_R; + _glfw.ns.keycodes[0x01] = GLFW_KEY_S; + _glfw.ns.keycodes[0x11] = GLFW_KEY_T; + _glfw.ns.keycodes[0x20] = GLFW_KEY_U; + _glfw.ns.keycodes[0x09] = GLFW_KEY_V; + _glfw.ns.keycodes[0x0D] = GLFW_KEY_W; + _glfw.ns.keycodes[0x07] = GLFW_KEY_X; + _glfw.ns.keycodes[0x10] = GLFW_KEY_Y; + _glfw.ns.keycodes[0x06] = GLFW_KEY_Z; + + _glfw.ns.keycodes[0x27] = GLFW_KEY_APOSTROPHE; + _glfw.ns.keycodes[0x2A] = GLFW_KEY_BACKSLASH; + _glfw.ns.keycodes[0x2B] = GLFW_KEY_COMMA; + _glfw.ns.keycodes[0x18] = GLFW_KEY_EQUAL; + _glfw.ns.keycodes[0x32] = GLFW_KEY_GRAVE_ACCENT; + _glfw.ns.keycodes[0x21] = GLFW_KEY_LEFT_BRACKET; + _glfw.ns.keycodes[0x1B] = GLFW_KEY_MINUS; + _glfw.ns.keycodes[0x2F] = GLFW_KEY_PERIOD; + _glfw.ns.keycodes[0x1E] = GLFW_KEY_RIGHT_BRACKET; + _glfw.ns.keycodes[0x29] = GLFW_KEY_SEMICOLON; + _glfw.ns.keycodes[0x2C] = GLFW_KEY_SLASH; + _glfw.ns.keycodes[0x0A] = GLFW_KEY_WORLD_1; + + _glfw.ns.keycodes[0x33] = GLFW_KEY_BACKSPACE; + _glfw.ns.keycodes[0x39] = GLFW_KEY_CAPS_LOCK; + _glfw.ns.keycodes[0x75] = GLFW_KEY_DELETE; + _glfw.ns.keycodes[0x7D] = GLFW_KEY_DOWN; + _glfw.ns.keycodes[0x77] = GLFW_KEY_END; + _glfw.ns.keycodes[0x24] = GLFW_KEY_ENTER; + _glfw.ns.keycodes[0x35] = GLFW_KEY_ESCAPE; + _glfw.ns.keycodes[0x7A] = GLFW_KEY_F1; + _glfw.ns.keycodes[0x78] = GLFW_KEY_F2; + _glfw.ns.keycodes[0x63] = GLFW_KEY_F3; + _glfw.ns.keycodes[0x76] = GLFW_KEY_F4; + _glfw.ns.keycodes[0x60] = GLFW_KEY_F5; + _glfw.ns.keycodes[0x61] = GLFW_KEY_F6; + _glfw.ns.keycodes[0x62] = GLFW_KEY_F7; + _glfw.ns.keycodes[0x64] = GLFW_KEY_F8; + _glfw.ns.keycodes[0x65] = GLFW_KEY_F9; + _glfw.ns.keycodes[0x6D] = GLFW_KEY_F10; + _glfw.ns.keycodes[0x67] = GLFW_KEY_F11; + _glfw.ns.keycodes[0x6F] = GLFW_KEY_F12; + _glfw.ns.keycodes[0x69] = GLFW_KEY_F13; + _glfw.ns.keycodes[0x6B] = GLFW_KEY_F14; + _glfw.ns.keycodes[0x71] = GLFW_KEY_F15; + _glfw.ns.keycodes[0x6A] = GLFW_KEY_F16; + _glfw.ns.keycodes[0x40] = GLFW_KEY_F17; + _glfw.ns.keycodes[0x4F] = GLFW_KEY_F18; + _glfw.ns.keycodes[0x50] = GLFW_KEY_F19; + _glfw.ns.keycodes[0x5A] = GLFW_KEY_F20; + _glfw.ns.keycodes[0x73] = GLFW_KEY_HOME; + _glfw.ns.keycodes[0x72] = GLFW_KEY_INSERT; + _glfw.ns.keycodes[0x7B] = GLFW_KEY_LEFT; + _glfw.ns.keycodes[0x3A] = GLFW_KEY_LEFT_ALT; + _glfw.ns.keycodes[0x3B] = GLFW_KEY_LEFT_CONTROL; + _glfw.ns.keycodes[0x38] = GLFW_KEY_LEFT_SHIFT; + _glfw.ns.keycodes[0x37] = GLFW_KEY_LEFT_SUPER; + _glfw.ns.keycodes[0x6E] = GLFW_KEY_MENU; + _glfw.ns.keycodes[0x47] = GLFW_KEY_NUM_LOCK; + _glfw.ns.keycodes[0x79] = GLFW_KEY_PAGE_DOWN; + _glfw.ns.keycodes[0x74] = GLFW_KEY_PAGE_UP; + _glfw.ns.keycodes[0x7C] = GLFW_KEY_RIGHT; + _glfw.ns.keycodes[0x3D] = GLFW_KEY_RIGHT_ALT; + _glfw.ns.keycodes[0x3E] = GLFW_KEY_RIGHT_CONTROL; + _glfw.ns.keycodes[0x3C] = GLFW_KEY_RIGHT_SHIFT; + _glfw.ns.keycodes[0x36] = GLFW_KEY_RIGHT_SUPER; + _glfw.ns.keycodes[0x31] = GLFW_KEY_SPACE; + _glfw.ns.keycodes[0x30] = GLFW_KEY_TAB; + _glfw.ns.keycodes[0x7E] = GLFW_KEY_UP; + + _glfw.ns.keycodes[0x52] = GLFW_KEY_KP_0; + _glfw.ns.keycodes[0x53] = GLFW_KEY_KP_1; + _glfw.ns.keycodes[0x54] = GLFW_KEY_KP_2; + _glfw.ns.keycodes[0x55] = GLFW_KEY_KP_3; + _glfw.ns.keycodes[0x56] = GLFW_KEY_KP_4; + _glfw.ns.keycodes[0x57] = GLFW_KEY_KP_5; + _glfw.ns.keycodes[0x58] = GLFW_KEY_KP_6; + _glfw.ns.keycodes[0x59] = GLFW_KEY_KP_7; + _glfw.ns.keycodes[0x5B] = GLFW_KEY_KP_8; + _glfw.ns.keycodes[0x5C] = GLFW_KEY_KP_9; + _glfw.ns.keycodes[0x45] = GLFW_KEY_KP_ADD; + _glfw.ns.keycodes[0x41] = GLFW_KEY_KP_DECIMAL; + _glfw.ns.keycodes[0x4B] = GLFW_KEY_KP_DIVIDE; + _glfw.ns.keycodes[0x4C] = GLFW_KEY_KP_ENTER; + _glfw.ns.keycodes[0x51] = GLFW_KEY_KP_EQUAL; + _glfw.ns.keycodes[0x43] = GLFW_KEY_KP_MULTIPLY; + _glfw.ns.keycodes[0x4E] = GLFW_KEY_KP_SUBTRACT; for (scancode = 0; scancode < 256; scancode++) { // Store the reverse translation for faster key name lookup - if (_glfw.ns.publicKeys[scancode] >= 0) - _glfw.ns.nativeKeys[_glfw.ns.publicKeys[scancode]] = scancode; + if (_glfw.ns.keycodes[scancode] >= 0) + _glfw.ns.scancodes[_glfw.ns.keycodes[scancode]] = scancode; } } @@ -247,9 +243,6 @@ static GLFWbool initializeTIS(void) CFStringRef* kPropertyUnicodeKeyLayoutData = CFBundleGetDataPointerForName(_glfw.ns.tis.bundle, CFSTR("kTISPropertyUnicodeKeyLayoutData")); - CFStringRef* kNotifySelectedKeyboardInputSourceChanged = - CFBundleGetDataPointerForName(_glfw.ns.tis.bundle, - CFSTR("kTISNotifySelectedKeyboardInputSourceChanged")); _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource = CFBundleGetFunctionPointerForName(_glfw.ns.tis.bundle, CFSTR("TISCopyCurrentKeyboardLayoutInputSource")); @@ -261,7 +254,6 @@ static GLFWbool initializeTIS(void) CFSTR("LMGetKbdType")); if (!kPropertyUnicodeKeyLayoutData || - !kNotifySelectedKeyboardInputSourceChanged || !TISCopyCurrentKeyboardLayoutInputSource || !TISGetInputSourceProperty || !LMGetKbdType) @@ -273,8 +265,6 @@ static GLFWbool initializeTIS(void) _glfw.ns.tis.kPropertyUnicodeKeyLayoutData = *kPropertyUnicodeKeyLayoutData; - _glfw.ns.tis.kNotifySelectedKeyboardInputSourceChanged = - *kNotifySelectedKeyboardInputSourceChanged; return updateUnicodeDataNS(); } @@ -300,17 +290,16 @@ int _glfwPlatformInit(void) { _glfw.ns.autoreleasePool = [[NSAutoreleasePool alloc] init]; + if (_glfw.hints.init.ns.chdir) + changeToResourcesDirectory(); + _glfw.ns.listener = [[GLFWLayoutListener alloc] init]; - [[NSDistributedNotificationCenter defaultCenter] + [[NSNotificationCenter defaultCenter] addObserver:_glfw.ns.listener selector:@selector(selectedKeyboardInputSourceChanged:) - name:(__bridge NSString*)kTISNotifySelectedKeyboardInputSourceChanged + name:NSTextInputContextKeyboardSelectionDidChangeNotification object:nil]; -#if defined(_GLFW_USE_CHDIR) - changeToResourcesDirectory(); -#endif - createKeyTables(); _glfw.ns.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); @@ -322,12 +311,10 @@ int _glfwPlatformInit(void) if (!initializeTIS()) return GLFW_FALSE; - if (!_glfwInitThreadLocalStoragePOSIX()) - return GLFW_FALSE; - _glfwInitTimerNS(); _glfwInitJoysticksNS(); + _glfwPollMonitorsNS(); return GLFW_TRUE; } @@ -355,11 +342,11 @@ void _glfwPlatformTerminate(void) if (_glfw.ns.listener) { - [[NSDistributedNotificationCenter defaultCenter] + [[NSNotificationCenter defaultCenter] removeObserver:_glfw.ns.listener - name:(__bridge NSString*)kTISNotifySelectedKeyboardInputSourceChanged + name:NSTextInputContextKeyboardSelectionDidChangeNotification object:nil]; - [[NSDistributedNotificationCenter defaultCenter] + [[NSNotificationCenter defaultCenter] removeObserver:_glfw.ns.listener]; [_glfw.ns.listener release]; _glfw.ns.listener = nil; @@ -372,7 +359,6 @@ void _glfwPlatformTerminate(void) _glfwTerminateNSGL(); _glfwTerminateJoysticksNS(); - _glfwTerminateThreadLocalStoragePOSIX(); [_glfw.ns.autoreleasePool release]; _glfw.ns.autoreleasePool = nil; @@ -381,15 +367,6 @@ void _glfwPlatformTerminate(void) const char* _glfwPlatformGetVersionString(void) { return _GLFW_VERSION_NUMBER " Cocoa NSGL" -#if defined(_GLFW_USE_CHDIR) - " chdir" -#endif -#if defined(_GLFW_USE_MENUBAR) - " menubar" -#endif -#if defined(_GLFW_USE_RETINA) - " retina" -#endif #if defined(_GLFW_BUILD_DLL) " dynamic" #endif diff --git a/libs/glfw/src/cocoa_joystick.h b/libs/glfw/src/cocoa_joystick.h @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 Cocoa - www.glfw.org +// GLFW 3.3 Cocoa - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -24,37 +24,27 @@ // //======================================================================== -#ifndef _glfw3_cocoa_joystick_h_ -#define _glfw3_cocoa_joystick_h_ - #include <IOKit/IOKitLib.h> #include <IOKit/IOCFPlugIn.h> #include <IOKit/hid/IOHIDLib.h> #include <IOKit/hid/IOHIDKeys.h> -#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ - _GLFWjoystickNS ns_js[GLFW_JOYSTICK_LAST + 1] +#define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickNS ns +#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE +#define _GLFW_PLATFORM_MAPPING_NAME "Mac OS X" // Cocoa-specific per-joystick data // typedef struct _GLFWjoystickNS { - GLFWbool present; - char name[256]; - - IOHIDDeviceRef deviceRef; - - CFMutableArrayRef axisElements; - CFMutableArrayRef buttonElements; - CFMutableArrayRef hatElements; - - float* axes; - unsigned char* buttons; + IOHIDDeviceRef device; + CFMutableArrayRef axes; + CFMutableArrayRef buttons; + CFMutableArrayRef hats; } _GLFWjoystickNS; void _glfwInitJoysticksNS(void); void _glfwTerminateJoysticksNS(void); -#endif // _glfw3_cocoa_joystick_h_ diff --git a/libs/glfw/src/cocoa_joystick.m b/libs/glfw/src/cocoa_joystick.m @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 Cocoa - www.glfw.org +// GLFW 3.3 Cocoa - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2009-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2009-2016 Camilla Löwy <elmindreda@glfw.org> // Copyright (c) 2012 Torsten Walluhn <tw@mad-cad.net> // // This software is provided 'as-is', without any express or implied @@ -42,289 +42,218 @@ // typedef struct _GLFWjoyelementNS { - IOHIDElementRef elementRef; - - long min; - long max; - - long minReport; - long maxReport; + IOHIDElementRef native; + uint32_t usage; + int index; + long minimum; + long maximum; } _GLFWjoyelementNS; -static void getElementsCFArrayHandler(const void* value, void* parameter); - -// Adds an element to the specified joystick -// -static void addJoystickElement(_GLFWjoystickNS* js, - IOHIDElementRef elementRef) -{ - IOHIDElementType elementType; - long usagePage, usage; - CFMutableArrayRef elementsArray = NULL; - - elementType = IOHIDElementGetType(elementRef); - usagePage = IOHIDElementGetUsagePage(elementRef); - usage = IOHIDElementGetUsage(elementRef); - - if ((elementType != kIOHIDElementTypeInput_Axis) && - (elementType != kIOHIDElementTypeInput_Button) && - (elementType != kIOHIDElementTypeInput_Misc)) - { - return; - } - - switch (usagePage) - { - case kHIDPage_GenericDesktop: - { - switch (usage) - { - case kHIDUsage_GD_X: - case kHIDUsage_GD_Y: - case kHIDUsage_GD_Z: - case kHIDUsage_GD_Rx: - case kHIDUsage_GD_Ry: - case kHIDUsage_GD_Rz: - case kHIDUsage_GD_Slider: - case kHIDUsage_GD_Dial: - case kHIDUsage_GD_Wheel: - elementsArray = js->axisElements; - break; - case kHIDUsage_GD_Hatswitch: - elementsArray = js->hatElements; - break; - } - - break; - } - - case kHIDPage_Button: - elementsArray = js->buttonElements; - break; - default: - break; - } - - if (elementsArray) - { - _GLFWjoyelementNS* element = calloc(1, sizeof(_GLFWjoyelementNS)); - - CFArrayAppendValue(elementsArray, element); - - element->elementRef = elementRef; - - element->minReport = IOHIDElementGetLogicalMin(elementRef); - element->maxReport = IOHIDElementGetLogicalMax(elementRef); - } -} - -// Adds an element to the specified joystick -// -static void getElementsCFArrayHandler(const void* value, void* parameter) -{ - if (CFGetTypeID(value) == IOHIDElementGetTypeID()) - { - addJoystickElement((_GLFWjoystickNS*) parameter, - (IOHIDElementRef) value); - } -} - // Returns the value of the specified element of the specified joystick // -static long getElementValue(_GLFWjoystickNS* js, _GLFWjoyelementNS* element) +static long getElementValue(_GLFWjoystick* js, _GLFWjoyelementNS* element) { - IOReturn result = kIOReturnSuccess; IOHIDValueRef valueRef; long value = 0; - if (js && element && js->deviceRef) + if (js->ns.device) { - result = IOHIDDeviceGetValue(js->deviceRef, - element->elementRef, - &valueRef); - - if (kIOReturnSuccess == result) + if (IOHIDDeviceGetValue(js->ns.device, + element->native, + &valueRef) == kIOReturnSuccess) { value = IOHIDValueGetIntegerValue(valueRef); - - // Record min and max for auto calibration - if (value < element->minReport) - element->minReport = value; - if (value > element->maxReport) - element->maxReport = value; } } - // Auto user scale return value; } +// Comparison function for matching the SDL element order +// +static CFComparisonResult compareElements(const void* fp, const void* sp, void* user) +{ + const _GLFWjoyelementNS* fe = fp; + const _GLFWjoyelementNS* se = sp; + if (fe->usage < se->usage) + return kCFCompareLessThan; + if (fe->usage > se->usage) + return kCFCompareGreaterThan; + if (fe->index < se->index) + return kCFCompareLessThan; + if (fe->index > se->index) + return kCFCompareGreaterThan; + return kCFCompareEqualTo; +} + // Removes the specified joystick // -static void removeJoystick(_GLFWjoystickNS* js) +static void closeJoystick(_GLFWjoystick* js) { int i; if (!js->present) return; - for (i = 0; i < CFArrayGetCount(js->axisElements); i++) - free((void*) CFArrayGetValueAtIndex(js->axisElements, i)); - CFArrayRemoveAllValues(js->axisElements); - CFRelease(js->axisElements); - - for (i = 0; i < CFArrayGetCount(js->buttonElements); i++) - free((void*) CFArrayGetValueAtIndex(js->buttonElements, i)); - CFArrayRemoveAllValues(js->buttonElements); - CFRelease(js->buttonElements); + for (i = 0; i < CFArrayGetCount(js->ns.axes); i++) + free((void*) CFArrayGetValueAtIndex(js->ns.axes, i)); + CFRelease(js->ns.axes); - for (i = 0; i < CFArrayGetCount(js->hatElements); i++) - free((void*) CFArrayGetValueAtIndex(js->hatElements, i)); - CFArrayRemoveAllValues(js->hatElements); - CFRelease(js->hatElements); + for (i = 0; i < CFArrayGetCount(js->ns.buttons); i++) + free((void*) CFArrayGetValueAtIndex(js->ns.buttons, i)); + CFRelease(js->ns.buttons); - free(js->axes); - free(js->buttons); + for (i = 0; i < CFArrayGetCount(js->ns.hats); i++) + free((void*) CFArrayGetValueAtIndex(js->ns.hats, i)); + CFRelease(js->ns.hats); - memset(js, 0, sizeof(_GLFWjoystickNS)); - - _glfwInputJoystickChange(js - _glfw.ns_js, GLFW_DISCONNECTED); + _glfwFreeJoystick(js); + _glfwInputJoystick(js, GLFW_DISCONNECTED); } -// Polls for joystick axis events and updates GLFW state +// Callback for user-initiated joystick addition // -static GLFWbool pollJoystickAxisEvents(_GLFWjoystickNS* js) +static void matchCallback(void* context, + IOReturn result, + void* sender, + IOHIDDeviceRef device) { + int jid; + char name[256]; + char guid[33]; CFIndex i; + CFTypeRef property; + uint32_t vendor = 0, product = 0, version = 0; + _GLFWjoystick* js; + CFMutableArrayRef axes, buttons, hats; - if (!js->present) - return GLFW_FALSE; - - for (i = 0; i < CFArrayGetCount(js->axisElements); i++) + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) { - _GLFWjoyelementNS* axis = (_GLFWjoyelementNS*) - CFArrayGetValueAtIndex(js->axisElements, i); - - long value = getElementValue(js, axis); - long readScale = axis->maxReport - axis->minReport; - - if (readScale == 0) - js->axes[i] = value; - else - js->axes[i] = (2.f * (value - axis->minReport) / readScale) - 1.f; + if (_glfw.joysticks[jid].ns.device == device) + return; } - return GLFW_TRUE; -} - -// Polls for joystick button events and updates GLFW state -// -static GLFWbool pollJoystickButtonEvents(_GLFWjoystickNS* js) -{ - CFIndex i; - int buttonIndex = 0; - - if (!js->present) - return GLFW_FALSE; + axes = CFArrayCreateMutable(NULL, 0, NULL); + buttons = CFArrayCreateMutable(NULL, 0, NULL); + hats = CFArrayCreateMutable(NULL, 0, NULL); - for (i = 0; i < CFArrayGetCount(js->buttonElements); i++) + property = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey)); + if (property) { - _GLFWjoyelementNS* button = (_GLFWjoyelementNS*) - CFArrayGetValueAtIndex(js->buttonElements, i); - - if (getElementValue(js, button)) - js->buttons[buttonIndex++] = GLFW_PRESS; - else - js->buttons[buttonIndex++] = GLFW_RELEASE; + CFStringGetCString(property, + name, + sizeof(name), + kCFStringEncodingUTF8); } + else + strncpy(name, "Unknown", sizeof(name)); - for (i = 0; i < CFArrayGetCount(js->hatElements); i++) - { - _GLFWjoyelementNS* hat = (_GLFWjoyelementNS*) - CFArrayGetValueAtIndex(js->hatElements, i); + property = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)); + if (property) + CFNumberGetValue(property, kCFNumberSInt32Type, &vendor); - // Bit fields of button presses for each direction, including nil - const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; + property = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductIDKey)); + if (property) + CFNumberGetValue(property, kCFNumberSInt32Type, &product); - long j, value = getElementValue(js, hat); - if (value < 0 || value > 8) - value = 8; + property = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVersionNumberKey)); + if (property) + CFNumberGetValue(property, kCFNumberSInt32Type, &version); - for (j = 0; j < 4; j++) - { - if (directions[value] & (1 << j)) - js->buttons[buttonIndex++] = GLFW_PRESS; - else - js->buttons[buttonIndex++] = GLFW_RELEASE; - } + // Generate a joystick GUID that matches the SDL 2.0.5+ one + if (vendor && product) + { + sprintf(guid, "03000000%02x%02x0000%02x%02x0000%02x%02x0000", + (uint8_t) vendor, (uint8_t) (vendor >> 8), + (uint8_t) product, (uint8_t) (product >> 8), + (uint8_t) version, (uint8_t) (version >> 8)); } - - return GLFW_TRUE; -} - -// Callback for user-initiated joystick addition -// -static void matchCallback(void* context, - IOReturn result, - void* sender, - IOHIDDeviceRef deviceRef) -{ - _GLFWjoystickNS* js; - int joy; - - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) + else { - if (_glfw.ns_js[joy].present && _glfw.ns_js[joy].deviceRef == deviceRef) - return; + sprintf(guid, "05000000%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x00", + name[0], name[1], name[2], name[3], + name[4], name[5], name[6], name[7], + name[8], name[9], name[10]); } - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) + CFArrayRef elements = + IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone); + + for (i = 0; i < CFArrayGetCount(elements); i++) { - if (!_glfw.ns_js[joy].present) - break; - } + IOHIDElementRef native = (IOHIDElementRef) CFArrayGetValueAtIndex(elements, i); + if (CFGetTypeID(native) != IOHIDElementGetTypeID()) + continue; + + const IOHIDElementType type = IOHIDElementGetType(native); + if ((type != kIOHIDElementTypeInput_Axis) && + (type != kIOHIDElementTypeInput_Button) && + (type != kIOHIDElementTypeInput_Misc)) + { + continue; + } - if (joy > GLFW_JOYSTICK_LAST) - return; + CFMutableArrayRef target = NULL; - js = _glfw.ns_js + joy; - js->present = GLFW_TRUE; - js->deviceRef = deviceRef; + const uint32_t usage = IOHIDElementGetUsage(native); + const uint32_t page = IOHIDElementGetUsagePage(native); + if (page == kHIDPage_GenericDesktop) + { + switch (usage) + { + case kHIDUsage_GD_X: + case kHIDUsage_GD_Y: + case kHIDUsage_GD_Z: + case kHIDUsage_GD_Rx: + case kHIDUsage_GD_Ry: + case kHIDUsage_GD_Rz: + case kHIDUsage_GD_Slider: + case kHIDUsage_GD_Dial: + case kHIDUsage_GD_Wheel: + target = axes; + break; + case kHIDUsage_GD_Hatswitch: + target = hats; + break; + } + } + else if (page == kHIDPage_Button) + target = buttons; - CFStringRef name = IOHIDDeviceGetProperty(deviceRef, - CFSTR(kIOHIDProductKey)); - if (name) - { - CFStringGetCString(name, - js->name, - sizeof(js->name), - kCFStringEncodingUTF8); + if (target) + { + _GLFWjoyelementNS* element = calloc(1, sizeof(_GLFWjoyelementNS)); + element->native = native; + element->usage = usage; + element->index = (int) CFArrayGetCount(target); + element->minimum = IOHIDElementGetLogicalMin(native); + element->maximum = IOHIDElementGetLogicalMax(native); + CFArrayAppendValue(target, element); + } } - else - strncpy(js->name, "Unknown", sizeof(js->name)); - js->axisElements = CFArrayCreateMutable(NULL, 0, NULL); - js->buttonElements = CFArrayCreateMutable(NULL, 0, NULL); - js->hatElements = CFArrayCreateMutable(NULL, 0, NULL); + CFRelease(elements); - CFArrayRef arrayRef = IOHIDDeviceCopyMatchingElements(deviceRef, - NULL, - kIOHIDOptionsTypeNone); - CFRange range = { 0, CFArrayGetCount(arrayRef) }; - CFArrayApplyFunction(arrayRef, - range, - getElementsCFArrayHandler, - (void*) js); + CFArraySortValues(axes, CFRangeMake(0, CFArrayGetCount(axes)), + compareElements, NULL); + CFArraySortValues(buttons, CFRangeMake(0, CFArrayGetCount(buttons)), + compareElements, NULL); + CFArraySortValues(hats, CFRangeMake(0, CFArrayGetCount(hats)), + compareElements, NULL); - CFRelease(arrayRef); + js = _glfwAllocJoystick(name, guid, + CFArrayGetCount(axes), + CFArrayGetCount(buttons), + CFArrayGetCount(hats)); - js->axes = calloc(CFArrayGetCount(js->axisElements), sizeof(float)); - js->buttons = calloc(CFArrayGetCount(js->buttonElements) + - CFArrayGetCount(js->hatElements) * 4, 1); + js->ns.device = device; + js->ns.axes = axes; + js->ns.buttons = buttons; + js->ns.hats = hats; - _glfwInputJoystickChange(joy, GLFW_CONNECTED); + _glfwInputJoystick(js, GLFW_CONNECTED); } // Callback for user-initiated joystick removal @@ -332,60 +261,20 @@ static void matchCallback(void* context, static void removeCallback(void* context, IOReturn result, void* sender, - IOHIDDeviceRef deviceRef) + IOHIDDeviceRef device) { - int joy; + int jid; - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) { - if (_glfw.ns_js[joy].deviceRef == deviceRef) + if (_glfw.joysticks[jid].ns.device == device) { - removeJoystick(_glfw.ns_js + joy); + closeJoystick(_glfw.joysticks + jid); break; } } } -// Creates a dictionary to match against devices with the specified usage page -// and usage -// -static CFMutableDictionaryRef createMatchingDictionary(long usagePage, - long usage) -{ - CFMutableDictionaryRef result = - CFDictionaryCreateMutable(kCFAllocatorDefault, - 0, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - - if (result) - { - CFNumberRef pageRef = CFNumberCreate(kCFAllocatorDefault, - kCFNumberLongType, - &usagePage); - if (pageRef) - { - CFDictionarySetValue(result, - CFSTR(kIOHIDDeviceUsagePageKey), - pageRef); - CFRelease(pageRef); - - CFNumberRef usageRef = CFNumberCreate(kCFAllocatorDefault, - kCFNumberLongType, - &usage); - if (usageRef) - { - CFDictionarySetValue(result, - CFSTR(kIOHIDDeviceUsageKey), - usageRef); - CFRelease(usageRef); - } - } - } - - return result; -} - ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// @@ -395,56 +284,73 @@ static CFMutableDictionaryRef createMatchingDictionary(long usagePage, // void _glfwInitJoysticksNS(void) { - CFMutableArrayRef matchingCFArrayRef; + CFMutableArrayRef matching; + const long usages[] = + { + kHIDUsage_GD_Joystick, + kHIDUsage_GD_GamePad, + kHIDUsage_GD_MultiAxisController + }; _glfw.ns.hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); - matchingCFArrayRef = CFArrayCreateMutable(kCFAllocatorDefault, - 0, - &kCFTypeArrayCallBacks); - if (matchingCFArrayRef) + matching = CFArrayCreateMutable(kCFAllocatorDefault, + 0, + &kCFTypeArrayCallBacks); + if (!matching) { - CFDictionaryRef matchingCFDictRef = - createMatchingDictionary(kHIDPage_GenericDesktop, - kHIDUsage_GD_Joystick); - if (matchingCFDictRef) - { - CFArrayAppendValue(matchingCFArrayRef, matchingCFDictRef); - CFRelease(matchingCFDictRef); - } + _glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to create array"); + return; + } - matchingCFDictRef = createMatchingDictionary(kHIDPage_GenericDesktop, - kHIDUsage_GD_GamePad); - if (matchingCFDictRef) - { - CFArrayAppendValue(matchingCFArrayRef, matchingCFDictRef); - CFRelease(matchingCFDictRef); - } + for (int i = 0; i < sizeof(usages) / sizeof(long); i++) + { + const long page = kHIDPage_GenericDesktop; + + CFMutableDictionaryRef dict = + CFDictionaryCreateMutable(kCFAllocatorDefault, + 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + if (!dict) + continue; - matchingCFDictRef = - createMatchingDictionary(kHIDPage_GenericDesktop, - kHIDUsage_GD_MultiAxisController); - if (matchingCFDictRef) + CFNumberRef pageRef = CFNumberCreate(kCFAllocatorDefault, + kCFNumberLongType, + &page); + CFNumberRef usageRef = CFNumberCreate(kCFAllocatorDefault, + kCFNumberLongType, + &usages[i]); + if (pageRef && usageRef) { - CFArrayAppendValue(matchingCFArrayRef, matchingCFDictRef); - CFRelease(matchingCFDictRef); + CFDictionarySetValue(dict, + CFSTR(kIOHIDDeviceUsagePageKey), + pageRef); + CFDictionarySetValue(dict, + CFSTR(kIOHIDDeviceUsageKey), + usageRef); + CFArrayAppendValue(matching, dict); } - IOHIDManagerSetDeviceMatchingMultiple(_glfw.ns.hidManager, - matchingCFArrayRef); - CFRelease(matchingCFArrayRef); + if (pageRef) + CFRelease(pageRef); + if (usageRef) + CFRelease(usageRef); + + CFRelease(dict); } + IOHIDManagerSetDeviceMatchingMultiple(_glfw.ns.hidManager, matching); + CFRelease(matching); + IOHIDManagerRegisterDeviceMatchingCallback(_glfw.ns.hidManager, &matchCallback, NULL); IOHIDManagerRegisterDeviceRemovalCallback(_glfw.ns.hidManager, &removeCallback, NULL); - IOHIDManagerScheduleWithRunLoop(_glfw.ns.hidManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode); - IOHIDManagerOpen(_glfw.ns.hidManager, kIOHIDOptionsTypeNone); // Execute the run loop once in order to register any initially-attached @@ -456,13 +362,10 @@ void _glfwInitJoysticksNS(void) // void _glfwTerminateJoysticksNS(void) { - int joy; + int jid; - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) - { - _GLFWjoystickNS* js = _glfw.ns_js + joy; - removeJoystick(js); - } + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) + closeJoystick(_glfw.joysticks + jid); CFRelease(_glfw.ns.hidManager); _glfw.ns.hidManager = NULL; @@ -473,39 +376,84 @@ void _glfwTerminateJoysticksNS(void) ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// -int _glfwPlatformJoystickPresent(int joy) +int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode) { - _GLFWjoystickNS* js = _glfw.ns_js + joy; - return js->present; -} + if (mode & _GLFW_POLL_AXES) + { + CFIndex i; -const float* _glfwPlatformGetJoystickAxes(int joy, int* count) -{ - _GLFWjoystickNS* js = _glfw.ns_js + joy; - if (!pollJoystickAxisEvents(js)) - return NULL; + for (i = 0; i < CFArrayGetCount(js->ns.axes); i++) + { + _GLFWjoyelementNS* axis = (_GLFWjoyelementNS*) + CFArrayGetValueAtIndex(js->ns.axes, i); + + const long raw = getElementValue(js, axis); + // Perform auto calibration + if (raw < axis->minimum) + axis->minimum = raw; + if (raw > axis->maximum) + axis->maximum = raw; + + const long delta = axis->maximum - axis->minimum; + if (delta == 0) + _glfwInputJoystickAxis(js, i, 0.f); + else + { + const float value = (2.f * (raw - axis->minimum) / delta) - 1.f; + _glfwInputJoystickAxis(js, i, value); + } + } + } - *count = (int) CFArrayGetCount(js->axisElements); - return js->axes; -} + if (mode & _GLFW_POLL_BUTTONS) + { + CFIndex i; -const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) -{ - _GLFWjoystickNS* js = _glfw.ns_js + joy; - if (!pollJoystickButtonEvents(js)) - return NULL; + for (i = 0; i < CFArrayGetCount(js->ns.buttons); i++) + { + _GLFWjoyelementNS* button = (_GLFWjoyelementNS*) + CFArrayGetValueAtIndex(js->ns.buttons, i); + const char value = getElementValue(js, button) - button->minimum; + _glfwInputJoystickButton(js, i, value); + } + + for (i = 0; i < CFArrayGetCount(js->ns.hats); i++) + { + const int states[9] = + { + GLFW_HAT_UP, + GLFW_HAT_RIGHT_UP, + GLFW_HAT_RIGHT, + GLFW_HAT_RIGHT_DOWN, + GLFW_HAT_DOWN, + GLFW_HAT_LEFT_DOWN, + GLFW_HAT_LEFT, + GLFW_HAT_LEFT_UP, + GLFW_HAT_CENTERED + }; + + _GLFWjoyelementNS* hat = (_GLFWjoyelementNS*) + CFArrayGetValueAtIndex(js->ns.hats, i); + long state = getElementValue(js, hat) - hat->minimum; + if (state < 0 || state > 8) + state = 8; + + _glfwInputJoystickHat(js, i, states[state]); + } + } - *count = (int) CFArrayGetCount(js->buttonElements) + - (int) CFArrayGetCount(js->hatElements) * 4; - return js->buttons; + return js->present; } -const char* _glfwPlatformGetJoystickName(int joy) +void _glfwPlatformUpdateGamepadGUID(char* guid) { - _GLFWjoystickNS* js = _glfw.ns_js + joy; - if (!js->present) - return NULL; - - return js->name; + if ((strncmp(guid + 4, "000000000000", 12) == 0) && + (strncmp(guid + 20, "000000000000", 12) == 0)) + { + char original[33]; + strcpy(original, guid); + sprintf(guid, "03000000%.4s0000%.4s000000000000", + original, original + 16); + } } diff --git a/libs/glfw/src/cocoa_monitor.m b/libs/glfw/src/cocoa_monitor.m @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 OS X - www.glfw.org +// GLFW 3.3 macOS - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -36,39 +36,79 @@ #include <ApplicationServices/ApplicationServices.h> -// Get the name of the specified display +// Get the name of the specified display, or NULL // static char* getDisplayName(CGDirectDisplayID displayID) { - char* name; - CFDictionaryRef info, names; - CFStringRef value; - CFIndex size; + io_iterator_t it; + io_service_t service; + CFDictionaryRef info; - // NOTE: This uses a deprecated function because Apple has - // (as of January 2015) not provided any alternative - info = IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), - kIODisplayOnlyPreferredName); - names = CFDictionaryGetValue(info, CFSTR(kDisplayProductName)); - - if (!names || !CFDictionaryGetValueIfPresent(names, CFSTR("en_US"), - (const void**) &value)) + if (IOServiceGetMatchingServices(kIOMasterPortDefault, + IOServiceMatching("IODisplayConnect"), + &it) != 0) { // This may happen if a desktop Mac is running headless + return NULL; + } + + while ((service = IOIteratorNext(it)) != 0) + { + info = IODisplayCreateInfoDictionary(service, kIODisplayOnlyPreferredName); + + CFNumberRef vendorIDRef = + CFDictionaryGetValue(info, CFSTR(kDisplayVendorID)); + CFNumberRef productIDRef = + CFDictionaryGetValue(info, CFSTR(kDisplayProductID)); + if (!vendorIDRef || !productIDRef) + { + CFRelease(info); + continue; + } + + unsigned int vendorID, productID; + CFNumberGetValue(vendorIDRef, kCFNumberIntType, &vendorID); + CFNumberGetValue(productIDRef, kCFNumberIntType, &productID); + + if (CGDisplayVendorNumber(displayID) == vendorID && + CGDisplayModelNumber(displayID) == productID) + { + // Info dictionary is used and freed below + break; + } + + CFRelease(info); + } + + IOObjectRelease(it); + + if (!service) + { _glfwInputError(GLFW_PLATFORM_ERROR, - "Cocoa: Failed to retrieve display name"); + "Cocoa: Failed to find service port for display"); + return NULL; + } + + CFDictionaryRef names = + CFDictionaryGetValue(info, CFSTR(kDisplayProductName)); + + CFStringRef nameRef; + if (!names || !CFDictionaryGetValueIfPresent(names, CFSTR("en_US"), + (const void**) &nameRef)) + { + // This may happen if a desktop Mac is running headless CFRelease(info); - return strdup("Unknown"); + return NULL; } - size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(value), - kCFStringEncodingUTF8); - name = calloc(size + 1, 1); - CFStringGetCString(value, name, size, kCFStringEncodingUTF8); + const CFIndex size = + CFStringGetMaximumSizeForEncoding(CFStringGetLength(nameRef), + kCFStringEncodingUTF8); + char* name = calloc(size + 1, 1); + CFStringGetCString(nameRef, name, size, kCFStringEncodingUTF8); CFRelease(info); - return name; } @@ -77,15 +117,15 @@ static char* getDisplayName(CGDirectDisplayID displayID) static GLFWbool modeIsGood(CGDisplayModeRef mode) { uint32_t flags = CGDisplayModeGetIOFlags(mode); + if (!(flags & kDisplayModeValidFlag) || !(flags & kDisplayModeSafeFlag)) return GLFW_FALSE; - if (flags & kDisplayModeInterlacedFlag) return GLFW_FALSE; - if (flags & kDisplayModeStretchedFlag) return GLFW_FALSE; +#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101100 CFStringRef format = CGDisplayModeCopyPixelEncoding(mode); if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) && CFStringCompare(format, CFSTR(IO32BitDirectPixels), 0)) @@ -95,6 +135,7 @@ static GLFWbool modeIsGood(CGDisplayModeRef mode) } CFRelease(format); +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */ return GLFW_TRUE; } @@ -115,8 +156,8 @@ static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode, result.refreshRate = (int) (time.timeScale / (double) time.timeValue); } +#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101100 CFStringRef format = CGDisplayModeCopyPixelEncoding(mode); - if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0) { result.redBits = 5; @@ -124,13 +165,16 @@ static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode, result.blueBits = 5; } else +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */ { result.redBits = 8; result.greenBits = 8; result.blueBits = 8; } +#if MAC_OS_X_VERSION_MAX_ALLOWED <= 101100 CFRelease(format); +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */ return result; } @@ -162,6 +206,71 @@ static void endFadeReservation(CGDisplayFadeReservationToken token) ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// +// Poll for changes in the set of connected monitors +// +void _glfwPollMonitorsNS(void) +{ + uint32_t i, j, displayCount, disconnectedCount; + CGDirectDisplayID* displays; + _GLFWmonitor** disconnected = NULL; + + CGGetOnlineDisplayList(0, NULL, &displayCount); + displays = calloc(displayCount, sizeof(CGDirectDisplayID)); + CGGetOnlineDisplayList(displayCount, displays, &displayCount); + + disconnectedCount = _glfw.monitorCount; + if (disconnectedCount) + { + disconnected = calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*)); + memcpy(disconnected, + _glfw.monitors, + _glfw.monitorCount * sizeof(_GLFWmonitor*)); + } + + for (i = 0; i < displayCount; i++) + { + _GLFWmonitor* monitor; + const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]); + + if (CGDisplayIsAsleep(displays[i])) + continue; + + for (j = 0; j < disconnectedCount; j++) + { + // HACK: Compare unit numbers instead of display IDs to work around + // display replacement on machines with automatic graphics + // switching + if (disconnected[j] && disconnected[j]->ns.unitNumber == unitNumber) + { + disconnected[j] = NULL; + break; + } + } + + const CGSize size = CGDisplayScreenSize(displays[i]); + char* name = getDisplayName(displays[i]); + if (!name) + name = strdup("Unknown"); + + monitor = _glfwAllocMonitor(name, size.width, size.height); + monitor->ns.displayID = displays[i]; + monitor->ns.unitNumber = unitNumber; + + free(name); + + _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST); + } + + for (i = 0; i < disconnectedCount; i++) + { + if (disconnected[i]) + _glfwInputMonitor(disconnected[i], GLFW_DISCONNECTED, 0); + } + + free(disconnected); + free(displays); +} + // Change the current video mode // GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired) @@ -241,53 +350,6 @@ void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor) ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// -_GLFWmonitor** _glfwPlatformGetMonitors(int* count) -{ - uint32_t i, found = 0, displayCount; - _GLFWmonitor** monitors; - CGDirectDisplayID* displays; - - *count = 0; - - CGGetOnlineDisplayList(0, NULL, &displayCount); - displays = calloc(displayCount, sizeof(CGDirectDisplayID)); - monitors = calloc(displayCount, sizeof(_GLFWmonitor*)); - - CGGetOnlineDisplayList(displayCount, displays, &displayCount); - - for (i = 0; i < displayCount; i++) - { - _GLFWmonitor* monitor; - - if (CGDisplayIsAsleep(displays[i])) - continue; - - const CGSize size = CGDisplayScreenSize(displays[i]); - char* name = getDisplayName(displays[i]); - - monitor = _glfwAllocMonitor(name, size.width, size.height); - monitor->ns.displayID = displays[i]; - monitor->ns.unitNumber = CGDisplayUnitNumber(displays[i]); - - free(name); - - found++; - monitors[found - 1] = monitor; - } - - free(displays); - - *count = found; - return monitors; -} - -GLFWbool _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) -{ - // HACK: Compare unit numbers instead of display IDs to work around display - // replacement on machines with automatic graphics switching - return first->ns.unitNumber == second->ns.unitNumber; -} - void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { const CGRect bounds = CGDisplayBounds(monitor->ns.displayID); diff --git a/libs/glfw/src/cocoa_platform.h b/libs/glfw/src/cocoa_platform.h @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 OS X - www.glfw.org +// GLFW 3.3 macOS - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2009-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2009-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -24,9 +24,6 @@ // //======================================================================== -#ifndef _glfw3_cocoa_platform_h_ -#define _glfw3_cocoa_platform_h_ - #include <stdint.h> #include <dlfcn.h> @@ -39,26 +36,39 @@ typedef void* id; #endif -#include "posix_tls.h" +typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; + +typedef struct VkMacOSSurfaceCreateInfoMVK +{ + VkStructureType sType; + const void* pNext; + VkMacOSSurfaceCreateFlagsMVK flags; + const void* pView; +} VkMacOSSurfaceCreateInfoMVK; + +typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*); + +#include "posix_thread.h" #include "cocoa_joystick.h" #include "nsgl_context.h" +#include "egl_context.h" +#include "osmesa_context.h" #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) #define _glfw_dlclose(handle) dlclose(handle) #define _glfw_dlsym(handle, name) dlsym(handle, name) +#define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->ns.view) +#define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY + #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns -#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeNS ns_time +#define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerNS ns #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorNS ns -#define _GLFW_EGL_CONTEXT_STATE -#define _GLFW_EGL_LIBRARY_CONTEXT_STATE - // HIToolbox.framework pointer typedefs #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData -#define kTISNotifySelectedKeyboardInputSourceChanged _glfw.ns.tis.kNotifySelectedKeyboardInputSourceChanged typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void); #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef); @@ -74,6 +84,9 @@ typedef struct _GLFWwindowNS id object; id delegate; id view; + id layer; + + GLFWbool maximized; // The total sum of the distances the cursor has been warped // since the last cursor motion event was processed @@ -96,9 +109,10 @@ typedef struct _GLFWlibraryNS id listener; char keyName[64]; - short int publicKeys[256]; - short int nativeKeys[GLFW_KEY_LAST + 1]; + short int keycodes[256]; + short int scancodes[GLFW_KEY_LAST + 1]; char* clipboardString; + CGPoint cascadePoint; // Where to place the cursor when re-enabled double restoreCursorPosX, restoreCursorPosY; // The window whose disabled cursor mode is active @@ -110,7 +124,6 @@ typedef struct _GLFWlibraryNS PFN_TISGetInputSourceProperty GetInputSourceProperty; PFN_LMGetKbdType GetKbdType; CFStringRef kPropertyUnicodeKeyLayoutData; - CFStringRef kNotifySelectedKeyboardInputSourceChanged; } tis; } _GLFWlibraryNS; @@ -135,16 +148,16 @@ typedef struct _GLFWcursorNS // Cocoa-specific global timer data // -typedef struct _GLFWtimeNS +typedef struct _GLFWtimerNS { uint64_t frequency; -} _GLFWtimeNS; +} _GLFWtimerNS; void _glfwInitTimerNS(void); +void _glfwPollMonitorsNS(void); GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); -#endif // _glfw3_cocoa_platform_h_ diff --git a/libs/glfw/src/cocoa_time.cc b/libs/glfw/src/cocoa_time.cc @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 OS X - www.glfw.org +// GLFW 3.3 macOS - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2009-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2009-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -40,7 +40,7 @@ void _glfwInitTimerNS(void) mach_timebase_info_data_t info; mach_timebase_info(&info); - _glfw.ns_time.frequency = (info.denom * 1e9) / info.numer; + _glfw.timer.ns.frequency = (info.denom * 1e9) / info.numer; } @@ -55,6 +55,6 @@ uint64_t _glfwPlatformGetTimerValue(void) uint64_t _glfwPlatformGetTimerFrequency(void) { - return _glfw.ns_time.frequency; + return _glfw.timer.ns.frequency; } diff --git a/libs/glfw/src/cocoa_window.m b/libs/glfw/src/cocoa_window.m @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 OS X - www.glfw.org +// GLFW 3.3 macOS - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2009-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2009-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -32,29 +32,23 @@ // Needed for _NSGetProgname #include <crt_externs.h> +// HACK: The 10.12 SDK adds new symbols and immediately deprecates the old ones +#if MAC_OS_X_VERSION_MAX_ALLOWED < 101200 + #define NSWindowStyleMaskBorderless NSBorderlessWindowMask + #define NSWindowStyleMaskClosable NSClosableWindowMask + #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask + #define NSWindowStyleMaskResizable NSResizableWindowMask + #define NSWindowStyleMaskTitled NSTitledWindowMask + #define NSEventModifierFlagCommand NSCommandKeyMask + #define NSEventModifierFlagControl NSControlKeyMask + #define NSEventModifierFlagOption NSAlternateKeyMask + #define NSEventModifierFlagShift NSShiftKeyMask + #define NSEventModifierFlagDeviceIndependentFlagsMask NSDeviceIndependentModifierFlagsMask + #define NSEventMaskAny NSAnyEventMask + #define NSEventTypeApplicationDefined NSApplicationDefined + #define NSEventTypeKeyUp NSKeyUp +#endif -// Returns the specified standard cursor -// -static NSCursor* getStandardCursor(int shape) -{ - switch (shape) - { - case GLFW_ARROW_CURSOR: - return [NSCursor arrowCursor]; - case GLFW_IBEAM_CURSOR: - return [NSCursor IBeamCursor]; - case GLFW_CROSSHAIR_CURSOR: - return [NSCursor crosshairCursor]; - case GLFW_HAND_CURSOR: - return [NSCursor pointingHandCursor]; - case GLFW_HRESIZE_CURSOR: - return [NSCursor resizeLeftRightCursor]; - case GLFW_VRESIZE_CURSOR: - return [NSCursor resizeUpDownCursor]; - } - - return nil; -} // Returns the style mask corresponding to the window settings // @@ -63,14 +57,15 @@ static NSUInteger getStyleMask(_GLFWwindow* window) NSUInteger styleMask = 0; if (window->monitor || !window->decorated) - styleMask |= NSBorderlessWindowMask; + styleMask |= NSWindowStyleMaskBorderless; else { - styleMask |= NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask; + styleMask |= NSWindowStyleMaskTitled | + NSWindowStyleMaskClosable | + NSWindowStyleMaskMiniaturizable; if (window->resizable) - styleMask |= NSResizableWindowMask; + styleMask |= NSWindowStyleMaskResizable; } return styleMask; @@ -129,7 +124,7 @@ static GLFWbool acquireMonitor(_GLFWwindow* window) [window->ns.object setFrame:frame display:YES]; - _glfwInputMonitorWindowChange(window->monitor, window); + _glfwInputMonitorWindow(window->monitor, window); return status; } @@ -140,36 +135,36 @@ static void releaseMonitor(_GLFWwindow* window) if (window->monitor->window != window) return; - _glfwInputMonitorWindowChange(window->monitor, NULL); + _glfwInputMonitorWindow(window->monitor, NULL); _glfwRestoreVideoModeNS(window->monitor); } -// Translates OS X key modifiers into GLFW ones +// Translates macOS key modifiers into GLFW ones // static int translateFlags(NSUInteger flags) { int mods = 0; - if (flags & NSShiftKeyMask) + if (flags & NSEventModifierFlagShift) mods |= GLFW_MOD_SHIFT; - if (flags & NSControlKeyMask) + if (flags & NSEventModifierFlagControl) mods |= GLFW_MOD_CONTROL; - if (flags & NSAlternateKeyMask) + if (flags & NSEventModifierFlagOption) mods |= GLFW_MOD_ALT; - if (flags & NSCommandKeyMask) + if (flags & NSEventModifierFlagCommand) mods |= GLFW_MOD_SUPER; return mods; } -// Translates a OS X keycode to a GLFW keycode +// Translates a macOS keycode to a GLFW keycode // static int translateKey(unsigned int key) { - if (key >= sizeof(_glfw.ns.publicKeys) / sizeof(_glfw.ns.publicKeys[0])) + if (key >= sizeof(_glfw.ns.keycodes) / sizeof(_glfw.ns.keycodes[0])) return GLFW_KEY_UNKNOWN; - return _glfw.ns.publicKeys[key]; + return _glfw.ns.keycodes[key]; } // Translate a GLFW keycode to a Cocoa modifier flag @@ -180,16 +175,16 @@ static NSUInteger translateKeyToModifierFlag(int key) { case GLFW_KEY_LEFT_SHIFT: case GLFW_KEY_RIGHT_SHIFT: - return NSShiftKeyMask; + return NSEventModifierFlagShift; case GLFW_KEY_LEFT_CONTROL: case GLFW_KEY_RIGHT_CONTROL: - return NSControlKeyMask; + return NSEventModifierFlagControl; case GLFW_KEY_LEFT_ALT: case GLFW_KEY_RIGHT_ALT: - return NSAlternateKeyMask; + return NSEventModifierFlagOption; case GLFW_KEY_LEFT_SUPER: case GLFW_KEY_RIGHT_SUPER: - return NSCommandKeyMask; + return NSEventModifierFlagCommand; } return 0; @@ -238,6 +233,13 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; if (_glfw.ns.disabledCursorWindow == window) centerCursor(window); + const int maximized = [window->ns.object isZoomed]; + if (window->ns.maximized != maximized) + { + window->ns.maximized = maximized; + _glfwInputWindowMaximize(window, maximized); + } + const NSRect contentRect = [window->ns.view frame]; const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect]; @@ -315,7 +317,15 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (void)applicationDidChangeScreenParameters:(NSNotification *) notification { - _glfwInputMonitorChange(); + _GLFWwindow* window; + + for (window = _glfw.windowListHead; window; window = window->next) + { + if (window->context.client != GLFW_NO_API) + [window->context.nsgl.object update]; + } + + _glfwPollMonitorsNS(); } - (void)applicationDidFinishLaunching:(NSNotification *)notification @@ -406,6 +416,19 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; return YES; } +- (BOOL)wantsUpdateLayer +{ + return YES; +} + +- (id)makeBackingLayer +{ + if (window->ns.layer) + return window->ns.layer; + + return [super makeBackingLayer]; +} + - (void)cursorUpdate:(NSEvent *)event { updateCursorImage(window); @@ -558,7 +581,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; { int action; const unsigned int modifierFlags = - [event modifierFlags] & NSDeviceIndependentModifierFlagsMask; + [event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask; const int key = translateKey([event keyCode]); const int mods = translateFlags(modifierFlags); const NSUInteger keyFlag = translateKeyToModifierFlag(key); @@ -675,10 +698,11 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange { + [markedText release]; if ([string isKindOfClass:[NSAttributedString class]]) - [markedText initWithAttributedString:string]; + markedText = [[NSMutableAttributedString alloc] initWithAttributedString:string]; else - [markedText initWithString:string]; + markedText = [[NSMutableAttributedString alloc] initWithString:string]; } - (void)unmarkText @@ -753,7 +777,12 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (BOOL)canBecomeKeyWindow { - // Required for NSBorderlessWindowMask windows + // Required for NSWindowStyleMaskBorderless windows + return YES; +} + +- (BOOL)canBecomeMainWindow +{ return YES; } @@ -765,6 +794,10 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; //------------------------------------------------------------------------ @interface GLFWApplication : NSApplication +{ + NSArray* nibObjects; +} + @end @implementation GLFWApplication @@ -774,8 +807,11 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; // down the command key don't get sent to the key window. - (void)sendEvent:(NSEvent *)event { - if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) + if ([event type] == NSEventTypeKeyUp && + ([event modifierFlags] & NSEventModifierFlagCommand)) + { [[self keyWindow] sendEvent:event]; + } else [super sendEvent:event]; } @@ -786,53 +822,58 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (void)doNothing:(id)object { } -@end -#if defined(_GLFW_USE_MENUBAR) +- (void)loadMainMenu +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 100800 + [[NSBundle mainBundle] loadNibNamed:@"MainMenu" + owner:NSApp + topLevelObjects:&nibObjects]; +#else + [[NSBundle mainBundle] loadNibNamed:@"MainMenu" owner:NSApp]; +#endif +} +@end -// Try to figure out what the calling application is called +// Set up the menu bar (manually) +// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that +// could go away at any moment, lots of stuff that really should be +// localize(d|able), etc. Add a nib to save us this horror. // -static NSString* findAppName(void) +static void createMenuBar(void) { size_t i; - NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary]; - - // Keys to search for as potential application names - NSString* GLFWNameKeys[] = + NSString* appName = nil; + NSDictionary* bundleInfo = [[NSBundle mainBundle] infoDictionary]; + NSString* nameKeys[] = { @"CFBundleDisplayName", @"CFBundleName", @"CFBundleExecutable", }; - for (i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++) + // Try to figure out what the calling application is called + + for (i = 0; i < sizeof(nameKeys) / sizeof(nameKeys[0]); i++) { - id name = [infoDictionary objectForKey:GLFWNameKeys[i]]; + id name = [bundleInfo objectForKey:nameKeys[i]]; if (name && [name isKindOfClass:[NSString class]] && ![name isEqualToString:@""]) { - return name; + appName = name; + break; } } - char** progname = _NSGetProgname(); - if (progname && *progname) - return [NSString stringWithUTF8String:*progname]; - - // Really shouldn't get here - return @"GLFW Application"; -} - -// Set up the menu bar (manually) -// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that -// could go away at any moment, lots of stuff that really should be -// localize(d|able), etc. Loading a nib would save us this horror, but that -// doesn't seem like a good thing to require of GLFW users. -// -static void createMenuBar(void) -{ - NSString* appName = findAppName(); + if (!appName) + { + char** progname = _NSGetProgname(); + if (progname && *progname) + appName = [NSString stringWithUTF8String:*progname]; + else + appName = @"GLFW Application"; + } NSMenu* bar = [[NSMenu alloc] init]; [NSApp setMainMenu:bar]; @@ -859,7 +900,7 @@ static void createMenuBar(void) [[appMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"] - setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask]; + setKeyEquivalentModifierMask:NSEventModifierFlagOption | NSEventModifierFlagCommand]; [appMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; @@ -891,7 +932,7 @@ static void createMenuBar(void) [[windowMenu addItemWithTitle:@"Enter Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] - setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask]; + setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand]; // Prior to Snow Leopard, we need to use this oddly-named semi-private API // to get the application menu working properly. @@ -899,8 +940,6 @@ static void createMenuBar(void) [NSApp performSelector:setAppleMenuSelector withObject:appMenu]; } -#endif /* _GLFW_USE_MENUBAR */ - // Initialize the Cocoa Application Kit // static GLFWbool initializeAppKit(void) @@ -916,15 +955,20 @@ static GLFWbool initializeAppKit(void) toTarget:NSApp withObject:nil]; - // In case we are unbundled, make us a proper UI application - [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + if (_glfw.hints.init.ns.menubar) + { + // In case we are unbundled, make us a proper UI application + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; -#if defined(_GLFW_USE_MENUBAR) - // Menu bar setup must go between sharedApplication above and - // finishLaunching below, in order to properly emulate the behavior - // of NSApplicationMain - createMenuBar(); -#endif + // Menu bar setup must go between sharedApplication above and + // finishLaunching below, in order to properly emulate the behavior + // of NSApplicationMain + + if ([[NSBundle mainBundle] pathForResource:@"MainMenu" ofType:@"nib"]) + [NSApp loadMainMenu]; + else + createMenuBar(); + } // There can only be one application delegate, but we allocate it the // first time a window is created to keep all window code in this file @@ -987,9 +1031,17 @@ static GLFWbool createNativeWindow(_GLFWwindow* window, else { [window->ns.object center]; + _glfw.ns.cascadePoint = + NSPointToCGPoint([window->ns.object cascadeTopLeftFromPoint: + NSPointFromCGPoint(_glfw.ns.cascadePoint)]); if (wndconfig->resizable) - [window->ns.object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; + { + const NSWindowCollectionBehavior behavior = + NSWindowCollectionBehaviorFullScreenPrimary | + NSWindowCollectionBehaviorManaged; + [window->ns.object setCollectionBehavior:behavior]; + } if (wndconfig->floating) [window->ns.object setLevel:NSFloatingWindowLevel]; @@ -998,17 +1050,19 @@ static GLFWbool createNativeWindow(_GLFWwindow* window, [window->ns.object zoom:nil]; } + if (wndconfig->ns.frame) + [window->ns.object setFrameAutosaveName:[NSString stringWithUTF8String:wndconfig->title]]; + window->ns.view = [[GLFWContentView alloc] initWithGlfwWindow:window]; -#if defined(_GLFW_USE_RETINA) - [window->ns.view setWantsBestResolutionOpenGLSurface:YES]; -#endif /*_GLFW_USE_RETINA*/ + if (wndconfig->ns.retina) + [window->ns.view setWantsBestResolutionOpenGLSurface:YES]; + [window->ns.object setContentView:window->ns.view]; [window->ns.object makeFirstResponder:window->ns.view]; [window->ns.object setTitle:[NSString stringWithUTF8String:wndconfig->title]]; [window->ns.object setDelegate:window->ns.delegate]; [window->ns.object setAcceptsMouseMovedEvents:YES]; - [window->ns.object setContentView:window->ns.view]; [window->ns.object setRestorable:NO]; return GLFW_TRUE; @@ -1039,10 +1093,19 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (!_glfwCreateContextNSGL(window, ctxconfig, fbconfig)) return GLFW_FALSE; } - else + else if (ctxconfig->source == GLFW_EGL_CONTEXT_API) { - _glfwInputError(GLFW_API_UNAVAILABLE, "Cocoa: EGL not available"); - return GLFW_FALSE; + if (!_glfwInitEGL()) + return GLFW_FALSE; + if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) + return GLFW_FALSE; + } + else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API) + { + if (!_glfwInitOSMesa()) + return GLFW_FALSE; + if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) + return GLFW_FALSE; } } @@ -1053,7 +1116,8 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (!acquireMonitor(window)) return GLFW_FALSE; - centerCursor(window); + if (wndconfig->centerCursor) + centerCursor(window); } return GLFW_TRUE; @@ -1155,7 +1219,7 @@ void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window, void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom) { if (numer == GLFW_DONT_CARE || denom == GLFW_DONT_CARE) - [window->ns.object setContentAspectRatio:NSMakeSize(0, 0)]; + [window->ns.object setResizeIncrements:NSMakeSize(1.0, 1.0)]; else [window->ns.object setContentAspectRatio:NSMakeSize(numer, denom)]; } @@ -1219,6 +1283,11 @@ void _glfwPlatformHideWindow(_GLFWwindow* window) [window->ns.object orderOut:nil]; } +void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) +{ + [NSApp requestUserAttention:NSInformationalRequest]; +} + void _glfwPlatformFocusWindow(_GLFWwindow* window) { // Make us the active application @@ -1262,6 +1331,10 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _glfwInputWindowMonitorChange(window, monitor); + // HACK: Allow the state cached in Cocoa to catch up to reality + // TODO: Solve this in a less terrible way + _glfwPlatformPollEvents(); + const NSUInteger styleMask = getStyleMask(window); [window->ns.object setStyleMask:styleMask]; [window->ns.object makeFirstResponder:window->ns.view]; @@ -1347,11 +1420,30 @@ int _glfwPlatformWindowMaximized(_GLFWwindow* window) return [window->ns.object isZoomed]; } +void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled) +{ + [window->ns.object setStyleMask:getStyleMask(window)]; +} + +void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled) +{ + [window->ns.object setStyleMask:getStyleMask(window)]; + [window->ns.object makeFirstResponder:window->ns.view]; +} + +void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled) +{ + if (enabled) + [window->ns.object setLevel:NSFloatingWindowLevel]; + else + [window->ns.object setLevel:NSNormalWindowLevel]; +} + void _glfwPlatformPollEvents(void) { for (;;) { - NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask + NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; @@ -1370,7 +1462,7 @@ void _glfwPlatformWaitEvents(void) // I wanted to pass NO to dequeue:, and rely on PollEvents to // dequeue and send. For reasons not at all clear to me, passing // NO to dequeue: causes this method never to return. - NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask + NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES]; @@ -1382,7 +1474,7 @@ void _glfwPlatformWaitEvents(void) void _glfwPlatformWaitEventsTimeout(double timeout) { NSDate* date = [NSDate dateWithTimeIntervalSinceNow:timeout]; - NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask + NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:date inMode:NSDefaultRunLoopMode dequeue:YES]; @@ -1395,7 +1487,7 @@ void _glfwPlatformWaitEventsTimeout(double timeout) void _glfwPlatformPostEmptyEvent(void) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined + NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 @@ -1469,14 +1561,8 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) updateCursorImage(window); } -const char* _glfwPlatformGetKeyName(int key, int scancode) +const char* _glfwPlatformGetScancodeName(int scancode) { - if (key != GLFW_KEY_UNKNOWN) - scancode = _glfw.ns.nativeKeys[key]; - - if (!_glfwIsPrintable(_glfw.ns.publicKeys[scancode])) - return NULL; - UInt32 deadKeyState = 0; UniChar characters[8]; UniCharCount characterCount = 0; @@ -1511,6 +1597,11 @@ const char* _glfwPlatformGetKeyName(int key, int scancode) return _glfw.ns.keyName; } +int _glfwPlatformGetKeyScancode(int key) +{ + return _glfw.ns.scancodes[key]; +} + int _glfwPlatformCreateCursor(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot) @@ -1559,7 +1650,19 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape) if (!initializeAppKit()) return GLFW_FALSE; - cursor->ns.object = getStandardCursor(shape); + if (shape == GLFW_ARROW_CURSOR) + cursor->ns.object = [NSCursor arrowCursor]; + else if (shape == GLFW_IBEAM_CURSOR) + cursor->ns.object = [NSCursor IBeamCursor]; + else if (shape == GLFW_CROSSHAIR_CURSOR) + cursor->ns.object = [NSCursor crosshairCursor]; + else if (shape == GLFW_HAND_CURSOR) + cursor->ns.object = [NSCursor pointingHandCursor]; + else if (shape == GLFW_HRESIZE_CURSOR) + cursor->ns.object = [NSCursor resizeLeftRightCursor]; + else if (shape == GLFW_VRESIZE_CURSOR) + cursor->ns.object = [NSCursor resizeUpDownCursor]; + if (!cursor->ns.object) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -1618,17 +1721,20 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) return _glfw.ns.clipboardString; } -char** _glfwPlatformGetRequiredInstanceExtensions(uint32_t* count) +void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) { - *count = 0; - return NULL; + if (!_glfw.vk.KHR_surface || !_glfw.vk.MVK_macos_surface) + return; + + extensions[0] = "VK_KHR_surface"; + extensions[1] = "VK_MVK_macos_surface"; } int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily) { - return GLFW_FALSE; + return GLFW_TRUE; } VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, @@ -1636,7 +1742,57 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface) { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 + VkResult err; + VkMacOSSurfaceCreateInfoMVK sci; + PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK; + + vkCreateMacOSSurfaceMVK = (PFN_vkCreateMacOSSurfaceMVK) + vkGetInstanceProcAddr(instance, "vkCreateMacOSSurfaceMVK"); + if (!vkCreateMacOSSurfaceMVK) + { + _glfwInputError(GLFW_API_UNAVAILABLE, + "Cocoa: Vulkan instance missing VK_MVK_macos_surface extension"); + return VK_ERROR_EXTENSION_NOT_PRESENT; + } + + // HACK: Dynamically load Core Animation to avoid adding an extra + // dependency for the majority who don't use MoltenVK + NSBundle* bundle = [NSBundle bundleWithPath:@"/System/Library/Frameworks/QuartzCore.framework"]; + if (!bundle) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Cocoa: Failed to find QuartzCore.framework"); + return VK_ERROR_EXTENSION_NOT_PRESENT; + } + + // NOTE: Create the layer here as makeBackingLayer should not return nil + window->ns.layer = [[bundle classNamed:@"CAMetalLayer"] layer]; + if (!window->ns.layer) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Cocoa: Failed to create layer for view"); + return VK_ERROR_EXTENSION_NOT_PRESENT; + } + + [window->ns.view setWantsLayer:YES]; + + memset(&sci, 0, sizeof(sci)); + sci.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK; + sci.pView = window->ns.view; + + err = vkCreateMacOSSurfaceMVK(instance, &sci, allocator, surface); + if (err) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Cocoa: Failed to create Vulkan surface: %s", + _glfwGetVulkanResultString(err)); + } + + return err; +#else return VK_ERROR_EXTENSION_NOT_PRESENT; +#endif } diff --git a/libs/glfw/src/context.cc b/libs/glfw/src/context.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 - www.glfw.org +// GLFW 3.3 - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -41,10 +41,11 @@ GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig) { if (ctxconfig->source != GLFW_NATIVE_CONTEXT_API && - ctxconfig->source != GLFW_EGL_CONTEXT_API) + ctxconfig->source != GLFW_EGL_CONTEXT_API && + ctxconfig->source != GLFW_OSMESA_CONTEXT_API) { _glfwInputError(GLFW_INVALID_ENUM, - "Invalid context creation API %i", + "Invalid context creation API 0x%08X", ctxconfig->source); return GLFW_FALSE; } @@ -54,7 +55,7 @@ GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig) ctxconfig->client != GLFW_OPENGL_ES_API) { _glfwInputError(GLFW_INVALID_ENUM, - "Invalid client API %i", + "Invalid client API 0x%08X", ctxconfig->client); return GLFW_FALSE; } @@ -84,7 +85,7 @@ GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig) ctxconfig->profile != GLFW_OPENGL_COMPAT_PROFILE) { _glfwInputError(GLFW_INVALID_ENUM, - "Invalid OpenGL profile %i", + "Invalid OpenGL profile 0x%08X", ctxconfig->profile); return GLFW_FALSE; } @@ -133,7 +134,7 @@ GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig) ctxconfig->robustness != GLFW_LOSE_CONTEXT_ON_RESET) { _glfwInputError(GLFW_INVALID_ENUM, - "Invalid context robustness mode %i", + "Invalid context robustness mode 0x%08X", ctxconfig->robustness); return GLFW_FALSE; } @@ -145,7 +146,7 @@ GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig) ctxconfig->release != GLFW_RELEASE_BEHAVIOR_FLUSH) { _glfwInputError(GLFW_INVALID_ENUM, - "Invalid context release behavior %i", + "Invalid context release behavior 0x%08X", ctxconfig->release); return GLFW_FALSE; } @@ -330,7 +331,7 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig) NULL }; - window = _glfwPlatformGetCurrentContext(); + window = _glfwPlatformGetTls(&_glfw.contextSlot); window->context.source = ctxconfig->source; window->context.client = GLFW_OPENGL_API; @@ -577,7 +578,7 @@ GLFWbool _glfwStringInExtensionString(const char* string, const char* extensions GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - _GLFWwindow* previous = _glfwPlatformGetCurrentContext(); + _GLFWwindow* previous = _glfwPlatformGetTls(&_glfw.contextSlot); _GLFW_REQUIRE_INIT(); @@ -600,7 +601,7 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle) GLFWAPI GLFWwindow* glfwGetCurrentContext(void) { _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - return (GLFWwindow*) _glfwPlatformGetCurrentContext(); + return _glfwPlatformGetTls(&_glfw.contextSlot); } GLFWAPI void glfwSwapBuffers(GLFWwindow* handle) @@ -625,7 +626,7 @@ GLFWAPI void glfwSwapInterval(int interval) _GLFW_REQUIRE_INIT(); - window = _glfwPlatformGetCurrentContext(); + window = _glfwPlatformGetTls(&_glfw.contextSlot); if (!window) { _glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL); @@ -638,12 +639,11 @@ GLFWAPI void glfwSwapInterval(int interval) GLFWAPI int glfwExtensionSupported(const char* extension) { _GLFWwindow* window; - assert(extension != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); - window = _glfwPlatformGetCurrentContext(); + window = _glfwPlatformGetTls(&_glfw.contextSlot); if (!window) { _glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL); @@ -708,7 +708,7 @@ GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - window = _glfwPlatformGetCurrentContext(); + window = _glfwPlatformGetTls(&_glfw.contextSlot); if (!window) { _glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL); diff --git a/libs/glfw/src/egl_context.cc b/libs/glfw/src/egl_context.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 EGL - www.glfw.org +// GLFW 3.3 EGL - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -113,7 +113,7 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig, _GLFWfbconfig* u = usableConfigs + usableCount; // Only consider RGB(A) EGLConfigs - if (!(getEGLConfigAttrib(n, EGL_COLOR_BUFFER_TYPE) & EGL_RGB_BUFFER)) + if (getEGLConfigAttrib(n, EGL_COLOR_BUFFER_TYPE) != EGL_RGB_BUFFER) continue; // Only consider window EGLConfigs @@ -199,12 +199,12 @@ static void makeContextCurrentEGL(_GLFWwindow* window) } } - _glfwPlatformSetCurrentContext(window); + _glfwPlatformSetTls(&_glfw.contextSlot, window); } static void swapBuffersEGL(_GLFWwindow* window) { - if (window != _glfwPlatformGetCurrentContext()) + if (window != _glfwPlatformGetTls(&_glfw.contextSlot)) { _glfwInputError(GLFW_PLATFORM_ERROR, "EGL: The context must be current on the calling thread when swapping buffers"); @@ -233,7 +233,7 @@ static int extensionSupportedEGL(const char* extension) static GLFWglproc getProcAddressEGL(const char* procname) { - _GLFWwindow* window = _glfwPlatformGetCurrentContext(); + _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); if (window->context.egl.client) { @@ -291,6 +291,8 @@ GLFWbool _glfwInitEGL(void) "EGL.dll", #elif defined(_GLFW_COCOA) "libEGL.dylib", +#elif defined(__CYGWIN__) + "libEGL-1.so", #else "libEGL.so.1", #endif @@ -315,37 +317,37 @@ GLFWbool _glfwInitEGL(void) _glfw.egl.prefix = (strncmp(sonames[i], "lib", 3) == 0); - _glfw.egl.GetConfigAttrib = (PFNEGLGETCONFIGATTRIBPROC) + _glfw.egl.GetConfigAttrib = (PFN_eglGetConfigAttrib) _glfw_dlsym(_glfw.egl.handle, "eglGetConfigAttrib"); - _glfw.egl.GetConfigs = (PFNEGLGETCONFIGSPROC) + _glfw.egl.GetConfigs = (PFN_eglGetConfigs) _glfw_dlsym(_glfw.egl.handle, "eglGetConfigs"); - _glfw.egl.GetDisplay = (PFNEGLGETDISPLAYPROC) + _glfw.egl.GetDisplay = (PFN_eglGetDisplay) _glfw_dlsym(_glfw.egl.handle, "eglGetDisplay"); - _glfw.egl.GetError = (PFNEGLGETERRORPROC) + _glfw.egl.GetError = (PFN_eglGetError) _glfw_dlsym(_glfw.egl.handle, "eglGetError"); - _glfw.egl.Initialize = (PFNEGLINITIALIZEPROC) + _glfw.egl.Initialize = (PFN_eglInitialize) _glfw_dlsym(_glfw.egl.handle, "eglInitialize"); - _glfw.egl.Terminate = (PFNEGLTERMINATEPROC) + _glfw.egl.Terminate = (PFN_eglTerminate) _glfw_dlsym(_glfw.egl.handle, "eglTerminate"); - _glfw.egl.BindAPI = (PFNEGLBINDAPIPROC) + _glfw.egl.BindAPI = (PFN_eglBindAPI) _glfw_dlsym(_glfw.egl.handle, "eglBindAPI"); - _glfw.egl.CreateContext = (PFNEGLCREATECONTEXTPROC) + _glfw.egl.CreateContext = (PFN_eglCreateContext) _glfw_dlsym(_glfw.egl.handle, "eglCreateContext"); - _glfw.egl.DestroySurface = (PFNEGLDESTROYSURFACEPROC) + _glfw.egl.DestroySurface = (PFN_eglDestroySurface) _glfw_dlsym(_glfw.egl.handle, "eglDestroySurface"); - _glfw.egl.DestroyContext = (PFNEGLDESTROYCONTEXTPROC) + _glfw.egl.DestroyContext = (PFN_eglDestroyContext) _glfw_dlsym(_glfw.egl.handle, "eglDestroyContext"); - _glfw.egl.CreateWindowSurface = (PFNEGLCREATEWINDOWSURFACEPROC) + _glfw.egl.CreateWindowSurface = (PFN_eglCreateWindowSurface) _glfw_dlsym(_glfw.egl.handle, "eglCreateWindowSurface"); - _glfw.egl.MakeCurrent = (PFNEGLMAKECURRENTPROC) + _glfw.egl.MakeCurrent = (PFN_eglMakeCurrent) _glfw_dlsym(_glfw.egl.handle, "eglMakeCurrent"); - _glfw.egl.SwapBuffers = (PFNEGLSWAPBUFFERSPROC) + _glfw.egl.SwapBuffers = (PFN_eglSwapBuffers) _glfw_dlsym(_glfw.egl.handle, "eglSwapBuffers"); - _glfw.egl.SwapInterval = (PFNEGLSWAPINTERVALPROC) + _glfw.egl.SwapInterval = (PFN_eglSwapInterval) _glfw_dlsym(_glfw.egl.handle, "eglSwapInterval"); - _glfw.egl.QueryString = (PFNEGLQUERYSTRINGPROC) + _glfw.egl.QueryString = (PFN_eglQueryString) _glfw_dlsym(_glfw.egl.handle, "eglQueryString"); - _glfw.egl.GetProcAddress = (PFNEGLGETPROCADDRESSPROC) + _glfw.egl.GetProcAddress = (PFN_eglGetProcAddress) _glfw_dlsym(_glfw.egl.handle, "eglGetProcAddress"); if (!_glfw.egl.GetConfigAttrib || @@ -399,6 +401,10 @@ GLFWbool _glfwInitEGL(void) extensionSupportedEGL("EGL_KHR_create_context_no_error"); _glfw.egl.KHR_gl_colorspace = extensionSupportedEGL("EGL_KHR_gl_colorspace"); + _glfw.egl.KHR_get_all_proc_addresses = + extensionSupportedEGL("EGL_KHR_get_all_proc_addresses"); + _glfw.egl.KHR_context_flush_control = + extensionSupportedEGL("EGL_KHR_context_flush_control"); return GLFW_TRUE; } @@ -420,11 +426,11 @@ void _glfwTerminateEGL(void) } } -#define setEGLattrib(attribName, attribValue) \ +#define setAttrib(a, v) \ { \ - attribs[index++] = attribName; \ - attribs[index++] = attribValue; \ - assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \ + assert((size_t) (index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ + attribs[index++] = a; \ + attribs[index++] = v; \ } // Create the OpenGL or OpenGL ES context @@ -436,6 +442,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, EGLint attribs[40]; EGLConfig config; EGLContext share = NULL; + int index = 0; if (!_glfw.egl.display) { @@ -476,7 +483,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, if (_glfw.egl.KHR_create_context) { - int index = 0, mask = 0, flags = 0; + int mask = 0, flags = 0; if (ctxconfig->client == GLFW_OPENGL_API) { @@ -487,12 +494,6 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, mask |= EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR; else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) mask |= EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; - - if (_glfw.egl.KHR_create_context_no_error) - { - if (ctxconfig->noerror) - flags |= EGL_CONTEXT_OPENGL_NO_ERROR_KHR; - } } if (ctxconfig->debug) @@ -502,44 +503,57 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, { if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION) { - setEGLattrib(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, - EGL_NO_RESET_NOTIFICATION_KHR); + setAttrib(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, + EGL_NO_RESET_NOTIFICATION_KHR); } else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET) { - setEGLattrib(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, - EGL_LOSE_CONTEXT_ON_RESET_KHR); + setAttrib(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, + EGL_LOSE_CONTEXT_ON_RESET_KHR); } flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR; } + if (ctxconfig->noerror) + { + if (_glfw.egl.KHR_create_context_no_error) + setAttrib(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, GLFW_TRUE); + } + if (ctxconfig->major != 1 || ctxconfig->minor != 0) { - setEGLattrib(EGL_CONTEXT_MAJOR_VERSION_KHR, ctxconfig->major); - setEGLattrib(EGL_CONTEXT_MINOR_VERSION_KHR, ctxconfig->minor); + setAttrib(EGL_CONTEXT_MAJOR_VERSION_KHR, ctxconfig->major); + setAttrib(EGL_CONTEXT_MINOR_VERSION_KHR, ctxconfig->minor); } if (mask) - setEGLattrib(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, mask); + setAttrib(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, mask); if (flags) - setEGLattrib(EGL_CONTEXT_FLAGS_KHR, flags); - - setEGLattrib(EGL_NONE, EGL_NONE); + setAttrib(EGL_CONTEXT_FLAGS_KHR, flags); } else { - int index = 0; - if (ctxconfig->client == GLFW_OPENGL_ES_API) - setEGLattrib(EGL_CONTEXT_CLIENT_VERSION, ctxconfig->major); + setAttrib(EGL_CONTEXT_CLIENT_VERSION, ctxconfig->major); + } - setEGLattrib(EGL_NONE, EGL_NONE); + if (_glfw.egl.KHR_context_flush_control) + { + if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE) + { + setAttrib(EGL_CONTEXT_RELEASE_BEHAVIOR_KHR, + EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR); + } + else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH) + { + setAttrib(EGL_CONTEXT_RELEASE_BEHAVIOR_KHR, + EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR); + } } - // Context release behaviors (GL_KHR_context_flush_control) are not yet - // supported on EGL but are not a hard constraint, so ignore and continue + setAttrib(EGL_NONE, EGL_NONE); window->context.egl.handle = eglCreateContext(_glfw.egl.display, config, share, attribs); @@ -559,12 +573,10 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, if (fbconfig->sRGB) { if (_glfw.egl.KHR_gl_colorspace) - { - setEGLattrib(EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR); - } + setAttrib(EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR); } - setEGLattrib(EGL_NONE, EGL_NONE); + setAttrib(EGL_NONE, EGL_NONE); } window->context.egl.surface = @@ -583,6 +595,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, window->context.egl.config = config; // Load the appropriate client library + if (!_glfw.egl.KHR_get_all_proc_addresses) { int i; const char** sonames; @@ -606,6 +619,8 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, "libGLESv2.dll", #elif defined(_GLFW_COCOA) "libGLESv2.dylib", +#elif defined(__CYGWIN__) + "libGLESv2-2.so", #else "libGLESv2.so.2", #endif @@ -661,7 +676,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, return GLFW_TRUE; } -#undef setEGLattrib +#undef setAttrib // Returns the Visual and depth of the chosen EGLConfig // diff --git a/libs/glfw/src/egl_context.h b/libs/glfw/src/egl_context.h @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 EGL - www.glfw.org +// GLFW 3.3 EGL - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -25,15 +25,16 @@ // //======================================================================== -#ifndef _glfw3_egl_context_h_ -#define _glfw3_egl_context_h_ - #if defined(_GLFW_USE_EGLPLATFORM_H) #include <EGL/eglplatform.h> #elif defined(_GLFW_WIN32) #define EGLAPIENTRY __stdcall typedef HDC EGLNativeDisplayType; typedef HWND EGLNativeWindowType; +#elif defined(_GLFW_COCOA) + #define EGLAPIENTRY +typedef void* EGLNativeDisplayType; +typedef id EGLNativeWindowType; #elif defined(_GLFW_X11) #define EGLAPIENTRY typedef Display* EGLNativeDisplayType; @@ -106,6 +107,9 @@ typedef MirEGLNativeWindowType EGLNativeWindowType; #define EGL_CONTEXT_OPENGL_NO_ERROR_KHR 0x31b3 #define EGL_GL_COLORSPACE_KHR 0x309d #define EGL_GL_COLORSPACE_SRGB_KHR 0x3089 +#define EGL_CONTEXT_RELEASE_BEHAVIOR_KHR 0x2097 +#define EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR 0 +#define EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR 0x2098 typedef int EGLint; typedef unsigned int EGLBoolean; @@ -116,22 +120,22 @@ typedef void* EGLDisplay; typedef void* EGLSurface; // EGL function pointer typedefs -typedef EGLBoolean (EGLAPIENTRY * PFNEGLGETCONFIGATTRIBPROC)(EGLDisplay,EGLConfig,EGLint,EGLint*); -typedef EGLBoolean (EGLAPIENTRY * PFNEGLGETCONFIGSPROC)(EGLDisplay,EGLConfig*,EGLint,EGLint*); -typedef EGLDisplay (EGLAPIENTRY * PFNEGLGETDISPLAYPROC)(EGLNativeDisplayType); -typedef EGLint (EGLAPIENTRY * PFNEGLGETERRORPROC)(void); -typedef EGLBoolean (EGLAPIENTRY * PFNEGLINITIALIZEPROC)(EGLDisplay,EGLint*,EGLint*); -typedef EGLBoolean (EGLAPIENTRY * PFNEGLTERMINATEPROC)(EGLDisplay); -typedef EGLBoolean (EGLAPIENTRY * PFNEGLBINDAPIPROC)(EGLenum); -typedef EGLContext (EGLAPIENTRY * PFNEGLCREATECONTEXTPROC)(EGLDisplay,EGLConfig,EGLContext,const EGLint*); -typedef EGLBoolean (EGLAPIENTRY * PFNEGLDESTROYSURFACEPROC)(EGLDisplay,EGLSurface); -typedef EGLBoolean (EGLAPIENTRY * PFNEGLDESTROYCONTEXTPROC)(EGLDisplay,EGLContext); -typedef EGLSurface (EGLAPIENTRY * PFNEGLCREATEWINDOWSURFACEPROC)(EGLDisplay,EGLConfig,EGLNativeWindowType,const EGLint*); -typedef EGLBoolean (EGLAPIENTRY * PFNEGLMAKECURRENTPROC)(EGLDisplay,EGLSurface,EGLSurface,EGLContext); -typedef EGLBoolean (EGLAPIENTRY * PFNEGLSWAPBUFFERSPROC)(EGLDisplay,EGLSurface); -typedef EGLBoolean (EGLAPIENTRY * PFNEGLSWAPINTERVALPROC)(EGLDisplay,EGLint); -typedef const char* (EGLAPIENTRY * PFNEGLQUERYSTRINGPROC)(EGLDisplay,EGLint); -typedef GLFWglproc (EGLAPIENTRY * PFNEGLGETPROCADDRESSPROC)(const char*); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglGetConfigAttrib)(EGLDisplay,EGLConfig,EGLint,EGLint*); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglGetConfigs)(EGLDisplay,EGLConfig*,EGLint,EGLint*); +typedef EGLDisplay (EGLAPIENTRY * PFN_eglGetDisplay)(EGLNativeDisplayType); +typedef EGLint (EGLAPIENTRY * PFN_eglGetError)(void); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglInitialize)(EGLDisplay,EGLint*,EGLint*); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglTerminate)(EGLDisplay); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglBindAPI)(EGLenum); +typedef EGLContext (EGLAPIENTRY * PFN_eglCreateContext)(EGLDisplay,EGLConfig,EGLContext,const EGLint*); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglDestroySurface)(EGLDisplay,EGLSurface); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglDestroyContext)(EGLDisplay,EGLContext); +typedef EGLSurface (EGLAPIENTRY * PFN_eglCreateWindowSurface)(EGLDisplay,EGLConfig,EGLNativeWindowType,const EGLint*); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglMakeCurrent)(EGLDisplay,EGLSurface,EGLSurface,EGLContext); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglSwapBuffers)(EGLDisplay,EGLSurface); +typedef EGLBoolean (EGLAPIENTRY * PFN_eglSwapInterval)(EGLDisplay,EGLint); +typedef const char* (EGLAPIENTRY * PFN_eglQueryString)(EGLDisplay,EGLint); +typedef GLFWglproc (EGLAPIENTRY * PFN_eglGetProcAddress)(const char*); #define eglGetConfigAttrib _glfw.egl.GetConfigAttrib #define eglGetConfigs _glfw.egl.GetConfigs #define eglGetDisplay _glfw.egl.GetDisplay @@ -176,25 +180,27 @@ typedef struct _GLFWlibraryEGL GLFWbool KHR_create_context; GLFWbool KHR_create_context_no_error; GLFWbool KHR_gl_colorspace; + GLFWbool KHR_get_all_proc_addresses; + GLFWbool KHR_context_flush_control; void* handle; - PFNEGLGETCONFIGATTRIBPROC GetConfigAttrib; - PFNEGLGETCONFIGSPROC GetConfigs; - PFNEGLGETDISPLAYPROC GetDisplay; - PFNEGLGETERRORPROC GetError; - PFNEGLINITIALIZEPROC Initialize; - PFNEGLTERMINATEPROC Terminate; - PFNEGLBINDAPIPROC BindAPI; - PFNEGLCREATECONTEXTPROC CreateContext; - PFNEGLDESTROYSURFACEPROC DestroySurface; - PFNEGLDESTROYCONTEXTPROC DestroyContext; - PFNEGLCREATEWINDOWSURFACEPROC CreateWindowSurface; - PFNEGLMAKECURRENTPROC MakeCurrent; - PFNEGLSWAPBUFFERSPROC SwapBuffers; - PFNEGLSWAPINTERVALPROC SwapInterval; - PFNEGLQUERYSTRINGPROC QueryString; - PFNEGLGETPROCADDRESSPROC GetProcAddress; + PFN_eglGetConfigAttrib GetConfigAttrib; + PFN_eglGetConfigs GetConfigs; + PFN_eglGetDisplay GetDisplay; + PFN_eglGetError GetError; + PFN_eglInitialize Initialize; + PFN_eglTerminate Terminate; + PFN_eglBindAPI BindAPI; + PFN_eglCreateContext CreateContext; + PFN_eglDestroySurface DestroySurface; + PFN_eglDestroyContext DestroyContext; + PFN_eglCreateWindowSurface CreateWindowSurface; + PFN_eglMakeCurrent MakeCurrent; + PFN_eglSwapBuffers SwapBuffers; + PFN_eglSwapInterval SwapInterval; + PFN_eglQueryString QueryString; + PFN_eglGetProcAddress GetProcAddress; } _GLFWlibraryEGL; @@ -210,4 +216,3 @@ GLFWbool _glfwChooseVisualEGL(const _GLFWctxconfig* ctxconfig, Visual** visual, int* depth); #endif /*_GLFW_X11*/ -#endif // _glfw3_egl_context_h_ diff --git a/libs/glfw/src/glx_context.cc b/libs/glfw/src/glx_context.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 GLX - www.glfw.org +// GLFW 3.3 GLX - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -59,12 +59,12 @@ static GLFWbool chooseGLXFBConfig(const _GLFWfbconfig* desired, GLXFBConfig* res // HACK: This is a (hopefully temporary) workaround for Chromium // (VirtualBox GL) not setting the window bit on any GLXFBConfigs vendor = glXGetClientString(_glfw.x11.display, GLX_VENDOR); - if (strcmp(vendor, "Chromium") == 0) + if (vendor && strcmp(vendor, "Chromium") == 0) trustWindowBit = GLFW_FALSE; nativeConfigs = glXGetFBConfigs(_glfw.x11.display, _glfw.x11.screen, &nativeCount); - if (!nativeCount) + if (!nativeConfigs || !nativeCount) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: No GLXFBConfigs returned"); return GLFW_FALSE; @@ -165,7 +165,7 @@ static void makeContextCurrentGLX(_GLFWwindow* window) } } - _glfwPlatformSetCurrentContext(window); + _glfwPlatformSetTls(&_glfw.contextSlot, window); } static void swapBuffersGLX(_GLFWwindow* window) @@ -175,7 +175,7 @@ static void swapBuffersGLX(_GLFWwindow* window) static void swapIntervalGLX(int interval) { - _GLFWwindow* window = _glfwPlatformGetCurrentContext(); + _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); if (_glfw.glx.EXT_swap_control) { @@ -397,6 +397,9 @@ GLFWbool _glfwInitGLX(void) if (extensionSupportedGLX("GLX_EXT_create_context_es2_profile")) _glfw.glx.EXT_create_context_es2_profile = GLFW_TRUE; + if (extensionSupportedGLX("GLX_ARB_create_context_no_error")) + _glfw.glx.ARB_create_context_no_error = GLFW_TRUE; + if (extensionSupportedGLX("GLX_ARB_context_flush_control")) _glfw.glx.ARB_context_flush_control = GLFW_TRUE; @@ -417,11 +420,11 @@ void _glfwTerminateGLX(void) } } -#define setGLXattrib(attribName, attribValue) \ +#define setAttrib(a, v) \ { \ - attribs[index++] = attribName; \ - attribs[index++] = attribValue; \ - assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \ + assert((size_t) (index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ + attribs[index++] = a; \ + attribs[index++] = v; \ } // Create the OpenGL or OpenGL ES context @@ -498,8 +501,6 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window, if (ctxconfig->debug) flags |= GLX_CONTEXT_DEBUG_BIT_ARB; - if (ctxconfig->noerror) - flags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR; if (ctxconfig->robustness) { @@ -507,13 +508,13 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window, { if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION) { - setGLXattrib(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, - GLX_NO_RESET_NOTIFICATION_ARB); + setAttrib(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, + GLX_NO_RESET_NOTIFICATION_ARB); } else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET) { - setGLXattrib(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, - GLX_LOSE_CONTEXT_ON_RESET_ARB); + setAttrib(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, + GLX_LOSE_CONTEXT_ON_RESET_ARB); } flags |= GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB; @@ -526,33 +527,39 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window, { if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE) { - setGLXattrib(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB, - GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB); + setAttrib(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB, + GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB); } else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH) { - setGLXattrib(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB, - GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB); + setAttrib(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB, + GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB); } } } + if (ctxconfig->noerror) + { + if (_glfw.glx.ARB_create_context_no_error) + setAttrib(GLX_CONTEXT_OPENGL_NO_ERROR_ARB, GLFW_TRUE); + } + // NOTE: Only request an explicitly versioned context when necessary, as // explicitly requesting version 1.0 does not always return the // highest version supported by the driver if (ctxconfig->major != 1 || ctxconfig->minor != 0) { - setGLXattrib(GLX_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major); - setGLXattrib(GLX_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor); + setAttrib(GLX_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major); + setAttrib(GLX_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor); } if (mask) - setGLXattrib(GLX_CONTEXT_PROFILE_MASK_ARB, mask); + setAttrib(GLX_CONTEXT_PROFILE_MASK_ARB, mask); if (flags) - setGLXattrib(GLX_CONTEXT_FLAGS_ARB, flags); + setAttrib(GLX_CONTEXT_FLAGS_ARB, flags); - setGLXattrib(None, None); + setAttrib(None, None); window->context.glx.handle = _glfw.glx.CreateContextAttribsARB(_glfw.x11.display, @@ -609,7 +616,7 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window, return GLFW_TRUE; } -#undef setGLXattrib +#undef setAttrib // Returns the Visual and depth of the chosen GLXFBConfig // diff --git a/libs/glfw/src/glx_context.h b/libs/glfw/src/glx_context.h @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 GLX - www.glfw.org +// GLFW 3.3 GLX - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -25,9 +25,6 @@ // //======================================================================== -#ifndef _glfw3_glx_context_h_ -#define _glfw3_glx_context_h_ - #define GLX_VENDOR 1 #define GLX_RGBA_BIT 0x00000001 #define GLX_WINDOW_BIT 0x00000001 @@ -67,6 +64,7 @@ #define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 #define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0 #define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 +#define GLX_CONTEXT_OPENGL_NO_ERROR_ARB 0x31b3 typedef XID GLXWindow; typedef XID GLXDrawable; @@ -85,14 +83,15 @@ typedef const char* (*PFNGLXQUERYEXTENSIONSSTRINGPROC)(Display*,int); typedef GLXFBConfig* (*PFNGLXGETFBCONFIGSPROC)(Display*,int,int*); typedef GLXContext (*PFNGLXCREATENEWCONTEXTPROC)(Display*,GLXFBConfig,int,GLXContext,Bool); typedef __GLXextproc (* PFNGLXGETPROCADDRESSPROC)(const GLubyte *procName); -typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); -typedef int (*PFNGLXSWAPINTERVALSGIPROC)(int); typedef void (*PFNGLXSWAPINTERVALEXTPROC)(Display*,GLXDrawable,int); -typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display*,GLXFBConfig,GLXContext,Bool,const int*); typedef XVisualInfo* (*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display*,GLXFBConfig); typedef GLXWindow (*PFNGLXCREATEWINDOWPROC)(Display*,GLXFBConfig,Window,const int*); typedef void (*PFNGLXDESTROYWINDOWPROC)(Display*,GLXWindow); +typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); +typedef int (*PFNGLXSWAPINTERVALSGIPROC)(int); +typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display*,GLXFBConfig,GLXContext,Bool,const int*); + // libGL.so function pointer typedefs #define glXGetFBConfigs _glfw.glx.GetFBConfigs #define glXGetFBConfigAttrib _glfw.glx.GetFBConfigAttrib @@ -164,6 +163,7 @@ typedef struct _GLFWlibraryGLX GLFWbool ARB_create_context_profile; GLFWbool ARB_create_context_robustness; GLFWbool EXT_create_context_es2_profile; + GLFWbool ARB_create_context_no_error; GLFWbool ARB_context_flush_control; } _GLFWlibraryGLX; @@ -179,4 +179,3 @@ GLFWbool _glfwChooseVisualGLX(const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig, Visual** visual, int* depth); -#endif // _glfw3_glx_context_h_ diff --git a/libs/glfw/src/init.cc b/libs/glfw/src/init.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 - www.glfw.org +// GLFW 3.3 - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -26,33 +26,45 @@ //======================================================================== #include "internal.h" +#include "mappings.h" #include <string.h> #include <stdlib.h> #include <stdio.h> #include <stdarg.h> +#include <assert.h> -// The three global variables below comprise all global data in GLFW. +// The global variables below comprise all global data in GLFW. // Any other global variable is a bug. // Global state shared between compilation units of GLFW -// These are documented in internal.h // -GLFWbool _glfwInitialized = GLFW_FALSE; -_GLFWlibrary _glfw; +_GLFWlibrary _glfw = { GLFW_FALSE }; -// This is outside of _glfw so it can be initialized and usable before -// glfwInit is called, which lets that function report errors +// These are outside of _glfw so they can be used before initialization and +// after termination // -static GLFWerrorfun _glfwErrorCallback = NULL; - +static _GLFWerror _glfwMainThreadError; +static GLFWerrorfun _glfwErrorCallback; +static _GLFWinitconfig _glfwInitHints = +{ + GLFW_TRUE, // hat buttons + { + GLFW_TRUE, // macOS menu bar + GLFW_TRUE // macOS bundle chdir + }, + { + "", // X11 WM_CLASS name + "" // X11 WM_CLASS class + } +}; // Returns a generic string representation of the specified error // -static const char* getErrorString(int error) +static const char* getErrorString(int code) { - switch (error) + switch (code) { case GLFW_NOT_INITIALIZED: return "The GLFW library is not initialized"; @@ -69,7 +81,7 @@ static const char* getErrorString(int error) case GLFW_VERSION_UNAVAILABLE: return "The requested API version is unavailable"; case GLFW_PLATFORM_ERROR: - return "A platform-specific error occurred"; + return "An undocumented platform-specific error occurred"; case GLFW_FORMAT_UNAVAILABLE: return "The requested format is unavailable"; case GLFW_NO_WINDOW_CONTEXT: @@ -79,37 +91,101 @@ static const char* getErrorString(int error) } } +// Terminate the library +// +static void terminate(void) +{ + int i; + + memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks)); + + while (_glfw.windowListHead) + glfwDestroyWindow((GLFWwindow*) _glfw.windowListHead); + + while (_glfw.cursorListHead) + glfwDestroyCursor((GLFWcursor*) _glfw.cursorListHead); + + for (i = 0; i < _glfw.monitorCount; i++) + { + _GLFWmonitor* monitor = _glfw.monitors[i]; + if (monitor->originalRamp.size) + _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp); + _glfwFreeMonitor(monitor); + } + + free(_glfw.monitors); + _glfw.monitors = NULL; + _glfw.monitorCount = 0; + + free(_glfw.mappings); + _glfw.mappings = NULL; + _glfw.mappingCount = 0; + + _glfwTerminateVulkan(); + _glfwPlatformTerminate(); + + _glfw.initialized = GLFW_FALSE; + + while (_glfw.errorListHead) + { + _GLFWerror* error = _glfw.errorListHead; + _glfw.errorListHead = error->next; + free(error); + } + + _glfwPlatformDestroyTls(&_glfw.contextSlot); + _glfwPlatformDestroyTls(&_glfw.errorSlot); + _glfwPlatformDestroyMutex(&_glfw.errorLock); + + memset(&_glfw, 0, sizeof(_glfw)); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW event API ////// ////////////////////////////////////////////////////////////////////////// -void _glfwInputError(int error, const char* format, ...) +void _glfwInputError(int code, const char* format, ...) { - if (_glfwErrorCallback) - { - char buffer[8192]; - const char* description; + _GLFWerror* error; + char description[_GLFW_MESSAGE_SIZE]; - if (format) - { - int count; - va_list vl; + if (format) + { + int count; + va_list vl; - va_start(vl, format); - count = vsnprintf(buffer, sizeof(buffer), format, vl); - va_end(vl); + va_start(vl, format); + count = vsnprintf(description, sizeof(description), format, vl); + va_end(vl); - if (count < 0) - buffer[sizeof(buffer) - 1] = '\0'; + if (count < 0) + description[sizeof(description) - 1] = '\0'; + } + else + strcpy(description, getErrorString(code)); - description = buffer; + if (_glfw.initialized) + { + error = _glfwPlatformGetTls(&_glfw.errorSlot); + if (!error) + { + error = calloc(1, sizeof(_GLFWerror)); + _glfwPlatformSetTls(&_glfw.errorSlot, error); + _glfwPlatformLockMutex(&_glfw.errorLock); + error->next = _glfw.errorListHead; + _glfw.errorListHead = error; + _glfwPlatformUnlockMutex(&_glfw.errorLock); } - else - description = getErrorString(error); - - _glfwErrorCallback(error, description); } + else + error = &_glfwMainThreadError; + + error->code = code; + strcpy(error->description, description); + + if (_glfwErrorCallback) + _glfwErrorCallback(code, description); } @@ -119,70 +195,89 @@ void _glfwInputError(int error, const char* format, ...) GLFWAPI int glfwInit(void) { - if (_glfwInitialized) + if (_glfw.initialized) return GLFW_TRUE; memset(&_glfw, 0, sizeof(_glfw)); + _glfw.hints.init = _glfwInitHints; if (!_glfwPlatformInit()) { - _glfwPlatformTerminate(); + terminate(); return GLFW_FALSE; } - _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount); - _glfwInitialized = GLFW_TRUE; + if (!_glfwPlatformCreateMutex(&_glfw.errorLock)) + return GLFW_FALSE; + if (!_glfwPlatformCreateTls(&_glfw.errorSlot)) + return GLFW_FALSE; + if (!_glfwPlatformCreateTls(&_glfw.contextSlot)) + return GLFW_FALSE; + + _glfwPlatformSetTls(&_glfw.errorSlot, &_glfwMainThreadError); - _glfw.timerOffset = _glfwPlatformGetTimerValue(); + _glfw.initialized = GLFW_TRUE; + _glfw.timer.offset = _glfwPlatformGetTimerValue(); - // Not all window hints have zero as their default value glfwDefaultWindowHints(); + glfwUpdateGamepadMappings(_glfwDefaultMappings); return GLFW_TRUE; } GLFWAPI void glfwTerminate(void) { - int i; - - if (!_glfwInitialized) + if (!_glfw.initialized) return; - memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks)); - - while (_glfw.windowListHead) - glfwDestroyWindow((GLFWwindow*) _glfw.windowListHead); - - while (_glfw.cursorListHead) - glfwDestroyCursor((GLFWcursor*) _glfw.cursorListHead); + terminate(); +} - for (i = 0; i < _glfw.monitorCount; i++) +GLFWAPI void glfwInitHint(int hint, int value) +{ + switch (hint) { - _GLFWmonitor* monitor = _glfw.monitors[i]; - if (monitor->originalRamp.size) - _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp); + case GLFW_JOYSTICK_HAT_BUTTONS: + _glfwInitHints.hatButtons = value; + return; + case GLFW_COCOA_CHDIR_RESOURCES: + _glfwInitHints.ns.chdir = value; + return; + case GLFW_COCOA_MENUBAR: + _glfwInitHints.ns.menubar = value; + return; } - _glfwTerminateVulkan(); + _glfwInputError(GLFW_INVALID_ENUM, + "Invalid integer type init hint 0x%08X", hint); +} - _glfwFreeMonitors(_glfw.monitors, _glfw.monitorCount); - _glfw.monitors = NULL; - _glfw.monitorCount = 0; +GLFWAPI void glfwInitHintString(int hint, const char* value) +{ + assert(value != NULL); - _glfwPlatformTerminate(); + switch (hint) + { + case GLFW_X11_WM_CLASS_NAME: + strncpy(_glfwInitHints.x11.className, value, + sizeof(_glfwInitHints.x11.className) - 1); + break; + case GLFW_X11_WM_CLASS_CLASS: + strncpy(_glfwInitHints.x11.classClass, value, + sizeof(_glfwInitHints.x11.classClass) - 1); + break; + } - memset(&_glfw, 0, sizeof(_glfw)); - _glfwInitialized = GLFW_FALSE; + _glfwInputError(GLFW_INVALID_ENUM, + "Invalid string type init hint 0x%08X", hint); } GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev) { if (major != NULL) *major = GLFW_VERSION_MAJOR; - if (minor != NULL) *minor = GLFW_VERSION_MINOR; - if (rev != NULL) *rev = GLFW_VERSION_REVISION; } @@ -192,6 +287,30 @@ GLFWAPI const char* glfwGetVersionString(void) return _glfwPlatformGetVersionString(); } +GLFWAPI int glfwGetError(const char** description) +{ + _GLFWerror* error; + int code = GLFW_NO_ERROR; + + if (description) + *description = NULL; + + if (_glfw.initialized) + error = _glfwPlatformGetTls(&_glfw.errorSlot); + else + error = &_glfwMainThreadError; + + if (error) + { + code = error->code; + error->code = GLFW_NO_ERROR; + if (description && code) + *description = error->description; + } + + return code; +} + GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun) { _GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun); diff --git a/libs/glfw/src/input.cc b/libs/glfw/src/input.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 - www.glfw.org +// GLFW 3.3 - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -29,11 +29,144 @@ #include <assert.h> #include <float.h> +#include <math.h> #include <stdlib.h> +#include <string.h> +#include <ctype.h> // Internal key state used for sticky keys #define _GLFW_STICK 3 +// Internal constants for gamepad mapping source types +#define _GLFW_JOYSTICK_AXIS 1 +#define _GLFW_JOYSTICK_BUTTON 2 +#define _GLFW_JOYSTICK_HATBIT 3 + +// Finds a mapping based on joystick GUID +// +static _GLFWmapping* findMapping(const char* guid) +{ + int i; + + for (i = 0; i < _glfw.mappingCount; i++) + { + if (strcmp(_glfw.mappings[i].guid, guid) == 0) + return _glfw.mappings + i; + } + + return NULL; +} + +// Parses an SDL_GameControllerDB line and adds it to the mapping list +// +static GLFWbool parseMapping(_GLFWmapping* mapping, const char* string) +{ + const char* c = string; + size_t i, length; + struct + { + const char* name; + _GLFWmapelement* element; + } fields[] = + { + { "platform", NULL }, + { "a", mapping->buttons + GLFW_GAMEPAD_BUTTON_A }, + { "b", mapping->buttons + GLFW_GAMEPAD_BUTTON_B }, + { "x", mapping->buttons + GLFW_GAMEPAD_BUTTON_X }, + { "y", mapping->buttons + GLFW_GAMEPAD_BUTTON_Y }, + { "back", mapping->buttons + GLFW_GAMEPAD_BUTTON_BACK }, + { "start", mapping->buttons + GLFW_GAMEPAD_BUTTON_START }, + { "guide", mapping->buttons + GLFW_GAMEPAD_BUTTON_GUIDE }, + { "leftshoulder", mapping->buttons + GLFW_GAMEPAD_BUTTON_LEFT_BUMPER }, + { "rightshoulder", mapping->buttons + GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER }, + { "leftstick", mapping->buttons + GLFW_GAMEPAD_BUTTON_LEFT_THUMB }, + { "rightstick", mapping->buttons + GLFW_GAMEPAD_BUTTON_RIGHT_THUMB }, + { "dpup", mapping->buttons + GLFW_GAMEPAD_BUTTON_DPAD_UP }, + { "dpright", mapping->buttons + GLFW_GAMEPAD_BUTTON_DPAD_RIGHT }, + { "dpdown", mapping->buttons + GLFW_GAMEPAD_BUTTON_DPAD_DOWN }, + { "dpleft", mapping->buttons + GLFW_GAMEPAD_BUTTON_DPAD_LEFT }, + { "lefttrigger", mapping->axes + GLFW_GAMEPAD_AXIS_LEFT_TRIGGER }, + { "righttrigger", mapping->axes + GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER }, + { "leftx", mapping->axes + GLFW_GAMEPAD_AXIS_LEFT_X }, + { "lefty", mapping->axes + GLFW_GAMEPAD_AXIS_LEFT_Y }, + { "rightx", mapping->axes + GLFW_GAMEPAD_AXIS_RIGHT_X }, + { "righty", mapping->axes + GLFW_GAMEPAD_AXIS_RIGHT_Y } + }; + + length = strcspn(c, ","); + if (length != 32 || c[length] != ',') + { + _glfwInputError(GLFW_INVALID_VALUE, NULL); + return GLFW_FALSE; + } + + memcpy(mapping->guid, c, length); + c += length + 1; + + length = strcspn(c, ","); + if (length >= sizeof(mapping->name) || c[length] != ',') + { + _glfwInputError(GLFW_INVALID_VALUE, NULL); + return GLFW_FALSE; + } + + memcpy(mapping->name, c, length); + c += length + 1; + + while (*c) + { + for (i = 0; i < sizeof(fields) / sizeof(fields[0]); i++) + { + length = strlen(fields[i].name); + if (strncmp(c, fields[i].name, length) != 0 || c[length] != ':') + continue; + + c += length + 1; + + if (fields[i].element) + { + if (*c == 'a') + fields[i].element->type = _GLFW_JOYSTICK_AXIS; + else if (*c == 'b') + fields[i].element->type = _GLFW_JOYSTICK_BUTTON; + else if (*c == 'h') + fields[i].element->type = _GLFW_JOYSTICK_HATBIT; + else + break; + + if (fields[i].element->type == _GLFW_JOYSTICK_HATBIT) + { + const unsigned int hat = strtoul(c + 1, (char**) &c, 10); + const unsigned int bit = strtoul(c + 1, (char**) &c, 10); + fields[i].element->value = (hat << 4) | bit; + } + else + fields[i].element->value = (uint8_t) strtoul(c + 1, (char**) &c, 10); + } + else + { + length = strlen(_GLFW_PLATFORM_MAPPING_NAME); + if (strncmp(c, _GLFW_PLATFORM_MAPPING_NAME, length) != 0) + return GLFW_FALSE; + } + + break; + } + + c += strcspn(c, ","); + c += strspn(c, ","); + } + + for (i = 0; i < 32; i++) + { + if (mapping->guid[i] >= 'A' && mapping->guid[i] <= 'F') + mapping->guid[i] += 'a' - 'A'; + } + + _glfwPlatformUpdateGamepadGUID(mapping->guid); + return GLFW_TRUE; +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW event API ////// @@ -90,7 +223,6 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods) if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) return; - // Register mouse button action if (action == GLFW_RELEASE && window->stickyMouseButtons) window->mouseButtons[button] = _GLFW_STICK; else @@ -124,10 +256,34 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths) window->callbacks.drop((GLFWwindow*) window, count, paths); } -void _glfwInputJoystickChange(int joy, int event) +void _glfwInputJoystick(_GLFWjoystick* js, int event) { + const int jid = (int) (js - _glfw.joysticks); + if (_glfw.callbacks.joystick) - _glfw.callbacks.joystick(joy, event); + _glfw.callbacks.joystick(jid, event); +} + +void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value) +{ + js->axes[axis] = value; +} + +void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value) +{ + js->buttons[button] = value; +} + +void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value) +{ + const int base = js->buttonCount + hat * 4; + + js->buttons[base + 0] = (value & 0x01) ? GLFW_PRESS : GLFW_RELEASE; + js->buttons[base + 1] = (value & 0x02) ? GLFW_PRESS : GLFW_RELEASE; + js->buttons[base + 2] = (value & 0x04) ? GLFW_PRESS : GLFW_RELEASE; + js->buttons[base + 3] = (value & 0x08) ? GLFW_PRESS : GLFW_RELEASE; + + js->hats[hat] = value; } @@ -135,11 +291,47 @@ void _glfwInputJoystickChange(int joy, int event) ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// -GLFWbool _glfwIsPrintable(int key) +_GLFWjoystick* _glfwAllocJoystick(const char* name, + const char* guid, + int axisCount, + int buttonCount, + int hatCount) { - return (key >= GLFW_KEY_APOSTROPHE && key <= GLFW_KEY_WORLD_2) || - (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_ADD) || - key == GLFW_KEY_KP_EQUAL; + int jid; + _GLFWjoystick* js; + + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) + { + if (!_glfw.joysticks[jid].present) + break; + } + + if (jid > GLFW_JOYSTICK_LAST) + return NULL; + + js = _glfw.joysticks + jid; + js->present = GLFW_TRUE; + js->name = strdup(name); + js->axes = calloc(axisCount, sizeof(float)); + js->buttons = calloc(buttonCount + hatCount * 4, 1); + js->hats = calloc(hatCount, 1); + js->axisCount = axisCount; + js->buttonCount = buttonCount; + js->hatCount = hatCount; + js->mapping = findMapping(guid); + + strcpy(js->guid, guid); + + return js; +} + +void _glfwFreeJoystick(_GLFWjoystick* js) +{ + free(js->name); + free(js->axes); + free(js->buttons); + free(js->hats); + memset(js, 0, sizeof(_GLFWjoystick)); } @@ -163,7 +355,7 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode) case GLFW_STICKY_MOUSE_BUTTONS: return window->stickyMouseButtons; default: - _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode %i", mode); + _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode); return 0; } } @@ -184,7 +376,7 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value) value != GLFW_CURSOR_DISABLED) { _glfwInputError(GLFW_INVALID_ENUM, - "Invalid cursor mode %i", + "Invalid cursor mode 0x%08X", value); return; } @@ -247,13 +439,39 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value) } } - _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode %i", mode); + _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode); } GLFWAPI const char* glfwGetKeyName(int key, int scancode) { _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - return _glfwPlatformGetKeyName(key, scancode); + + if (key != GLFW_KEY_UNKNOWN) + { + if (key != GLFW_KEY_KP_EQUAL && + (key < GLFW_KEY_KP_0 || key > GLFW_KEY_KP_ADD) && + (key < GLFW_KEY_APOSTROPHE || key > GLFW_KEY_WORLD_2)) + { + return NULL; + } + + scancode = _glfwPlatformGetKeyScancode(key); + } + + return _glfwPlatformGetScancodeName(scancode); +} + +GLFWAPI int glfwGetKeyScancode(int key) +{ + _GLFW_REQUIRE_INIT_OR_RETURN(-1); + + if (key < GLFW_KEY_SPACE || key > GLFW_KEY_LAST) + { + _glfwInputError(GLFW_INVALID_ENUM, "Invalid key %i", key); + return GLFW_RELEASE; + } + + return _glfwPlatformGetKeyScancode(key); } GLFWAPI int glfwGetKey(GLFWwindow* handle, int key) @@ -391,7 +609,7 @@ GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape) shape != GLFW_HRESIZE_CURSOR && shape != GLFW_VRESIZE_CURSOR) { - _glfwInputError(GLFW_INVALID_ENUM, "Invalid standard cursor %i", shape); + _glfwInputError(GLFW_INVALID_ENUM, "Invalid standard cursor 0x%08X", shape); return NULL; } @@ -540,62 +758,167 @@ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* handle, GLFWdropfun cbfun) return cbfun; } -GLFWAPI int glfwJoystickPresent(int joy) +GLFWAPI int glfwJoystickPresent(int jid) { - _GLFW_REQUIRE_INIT_OR_RETURN(0); + _GLFWjoystick* js; - if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + assert(jid >= GLFW_JOYSTICK_1); + assert(jid <= GLFW_JOYSTICK_LAST); + + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); + + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) { - _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", joy); - return 0; + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); + return GLFW_FALSE; } - return _glfwPlatformJoystickPresent(joy); + js = _glfw.joysticks + jid; + if (!js->present) + return GLFW_FALSE; + + return _glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE); } -GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count) +GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count) { + _GLFWjoystick* js; + + assert(jid >= GLFW_JOYSTICK_1); + assert(jid <= GLFW_JOYSTICK_LAST); assert(count != NULL); + *count = 0; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) { - _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", joy); + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); return NULL; } - return _glfwPlatformGetJoystickAxes(joy, count); + js = _glfw.joysticks + jid; + if (!js->present) + return NULL; + + if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_AXES)) + return NULL; + + *count = js->axisCount; + return js->axes; } -GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count) +GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count) { + _GLFWjoystick* js; + + assert(jid >= GLFW_JOYSTICK_1); + assert(jid <= GLFW_JOYSTICK_LAST); assert(count != NULL); + *count = 0; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) { - _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", joy); + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); return NULL; } - return _glfwPlatformGetJoystickButtons(joy, count); + js = _glfw.joysticks + jid; + if (!js->present) + return NULL; + + if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_BUTTONS)) + return NULL; + + if (_glfw.hints.init.hatButtons) + *count = js->buttonCount + js->hatCount * 4; + else + *count = js->buttonCount; + + return js->buttons; } -GLFWAPI const char* glfwGetJoystickName(int joy) +GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count) { + _GLFWjoystick* js; + + assert(jid >= GLFW_JOYSTICK_1); + assert(jid <= GLFW_JOYSTICK_LAST); + assert(count != NULL); + + *count = 0; + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) { - _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", joy); + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); return NULL; } - return _glfwPlatformGetJoystickName(joy); + js = _glfw.joysticks + jid; + if (!js->present) + return NULL; + + if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_BUTTONS)) + return NULL; + + *count = js->hatCount; + return js->hats; +} + +GLFWAPI const char* glfwGetJoystickName(int jid) +{ + _GLFWjoystick* js; + + assert(jid >= GLFW_JOYSTICK_1); + assert(jid <= GLFW_JOYSTICK_LAST); + + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) + { + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); + return NULL; + } + + js = _glfw.joysticks + jid; + if (!js->present) + return NULL; + + if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE)) + return NULL; + + return js->name; +} + +GLFWAPI const char* glfwGetJoystickGUID(int jid) +{ + _GLFWjoystick* js; + + assert(jid >= GLFW_JOYSTICK_1); + assert(jid <= GLFW_JOYSTICK_LAST); + + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) + { + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); + return NULL; + } + + js = _glfw.joysticks + jid; + if (!js->present) + return NULL; + + if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE)) + return NULL; + + return js->guid; } GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun) @@ -605,6 +928,182 @@ GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun) return cbfun; } +GLFWAPI int glfwUpdateGamepadMappings(const char* string) +{ + int jid; + const char* c = string; + + assert(string != NULL); + + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); + + while (*c) + { + if (isxdigit(*c)) + { + char line[1024]; + + const size_t length = strcspn(c, "\r\n"); + if (length < sizeof(line)) + { + _GLFWmapping mapping = {{0}}; + + memcpy(line, c, length); + line[length] = '\0'; + + if (parseMapping(&mapping, line)) + { + _GLFWmapping* previous = findMapping(mapping.guid); + if (previous) + *previous = mapping; + else + { + _glfw.mappingCount++; + _glfw.mappings = + realloc(_glfw.mappings, + sizeof(_GLFWmapping) * _glfw.mappingCount); + _glfw.mappings[_glfw.mappingCount - 1] = mapping; + } + } + } + + c += length; + } + else + { + c += strcspn(c, "\r\n"); + c += strspn(c, "\r\n"); + } + } + + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) + { + _GLFWjoystick* js = _glfw.joysticks + jid; + if (js->present) + js->mapping = findMapping(js->guid); + } + + return GLFW_TRUE; +} + +GLFWAPI int glfwJoystickIsGamepad(int jid) +{ + _GLFWjoystick* js; + + assert(jid >= GLFW_JOYSTICK_1); + assert(jid <= GLFW_JOYSTICK_LAST); + + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); + + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) + { + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); + return GLFW_FALSE; + } + + js = _glfw.joysticks + jid; + if (!js->present) + return GLFW_FALSE; + + if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE)) + return GLFW_FALSE; + + return js->mapping != NULL; +} + +GLFWAPI const char* glfwGetGamepadName(int jid) +{ + _GLFWjoystick* js; + + assert(jid >= GLFW_JOYSTICK_1); + assert(jid <= GLFW_JOYSTICK_LAST); + + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) + { + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); + return NULL; + } + + js = _glfw.joysticks + jid; + if (!js->present) + return NULL; + + if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE)) + return NULL; + + if (!js->mapping) + return NULL; + + return js->mapping->name; +} + +GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state) +{ + int i; + _GLFWjoystick* js; + + assert(jid >= GLFW_JOYSTICK_1); + assert(jid <= GLFW_JOYSTICK_LAST); + assert(state != NULL); + + memset(state, 0, sizeof(GLFWgamepadstate)); + + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); + + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) + { + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); + return GLFW_FALSE; + } + + js = _glfw.joysticks + jid; + if (!js->present) + return GLFW_FALSE; + + if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_ALL)) + return GLFW_FALSE; + + if (!js->mapping) + return GLFW_FALSE; + + for (i = 0; i <= GLFW_GAMEPAD_BUTTON_LAST; i++) + { + if (js->mapping->buttons[i].type == _GLFW_JOYSTICK_AXIS) + { + if (fabs(js->axes[js->mapping->buttons[i].value]) > 0.5) + state->buttons[i] = GLFW_PRESS; + } + else if (js->mapping->buttons[i].type == _GLFW_JOYSTICK_HATBIT) + { + const unsigned int hat = js->mapping->buttons[i].value >> 4; + const unsigned int bit = js->mapping->buttons[i].value & 0xf; + if (js->hats[hat] & bit) + state->buttons[i] = GLFW_PRESS; + } + else if (js->mapping->buttons[i].type == _GLFW_JOYSTICK_BUTTON) + state->buttons[i] = js->buttons[js->mapping->buttons[i].value]; + } + + for (i = 0; i <= GLFW_GAMEPAD_AXIS_LAST; i++) + { + if (js->mapping->axes[i].type == _GLFW_JOYSTICK_AXIS) + state->axes[i] = js->axes[js->mapping->axes[i].value]; + else if (js->mapping->buttons[i].type == _GLFW_JOYSTICK_HATBIT) + { + const unsigned int hat = js->mapping->buttons[i].value >> 4; + const unsigned int bit = js->mapping->buttons[i].value & 0xf; + if (js->hats[hat] & bit) + state->axes[i] = 1.f; + } + else if (js->mapping->buttons[i].type == _GLFW_JOYSTICK_BUTTON) + state->axes[i] = (float) js->buttons[js->mapping->axes[i].value]; + } + + return GLFW_TRUE; +} + GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) { _GLFWwindow* window = (_GLFWwindow*) handle; @@ -627,7 +1126,7 @@ GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle) GLFWAPI double glfwGetTime(void) { _GLFW_REQUIRE_INIT_OR_RETURN(0.0); - return (double) (_glfwPlatformGetTimerValue() - _glfw.timerOffset) / + return (double) (_glfwPlatformGetTimerValue() - _glfw.timer.offset) / _glfwPlatformGetTimerFrequency(); } @@ -641,7 +1140,7 @@ GLFWAPI void glfwSetTime(double time) return; } - _glfw.timerOffset = _glfwPlatformGetTimerValue() - + _glfw.timer.offset = _glfwPlatformGetTimerValue() - (uint64_t) (time * _glfwPlatformGetTimerFrequency()); } diff --git a/libs/glfw/src/internal.h b/libs/glfw/src/internal.h @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 - www.glfw.org +// GLFW 3.3 - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -25,10 +25,6 @@ // //======================================================================== -#ifndef _glfw3_internal_h_ -#define _glfw3_internal_h_ - - #if defined(_GLFW_USE_CONFIG_H) #include "glfw_config.h" #endif @@ -37,6 +33,8 @@ defined(GLFW_INCLUDE_ES1) || \ defined(GLFW_INCLUDE_ES2) || \ defined(GLFW_INCLUDE_ES3) || \ + defined(GLFW_INCLUDE_ES31) || \ + defined(GLFW_INCLUDE_ES32) || \ defined(GLFW_INCLUDE_NONE) || \ defined(GLFW_INCLUDE_GLEXT) || \ defined(GLFW_INCLUDE_GLU) || \ @@ -48,8 +46,20 @@ #define GLFW_INCLUDE_NONE #include "../include/GLFW/glfw3.h" +#define _GLFW_INSERT_FIRST 0 +#define _GLFW_INSERT_LAST 1 + +#define _GLFW_POLL_PRESENCE 0 +#define _GLFW_POLL_AXES 1 +#define _GLFW_POLL_BUTTONS 2 +#define _GLFW_POLL_ALL (_GLFW_POLL_AXES | _GLFW_POLL_BUTTONS) + +#define _GLFW_MESSAGE_SIZE 1024 + typedef int GLFWbool; +typedef struct _GLFWerror _GLFWerror; +typedef struct _GLFWinitconfig _GLFWinitconfig; typedef struct _GLFWwndconfig _GLFWwndconfig; typedef struct _GLFWctxconfig _GLFWctxconfig; typedef struct _GLFWfbconfig _GLFWfbconfig; @@ -58,6 +68,11 @@ typedef struct _GLFWwindow _GLFWwindow; typedef struct _GLFWlibrary _GLFWlibrary; typedef struct _GLFWmonitor _GLFWmonitor; typedef struct _GLFWcursor _GLFWcursor; +typedef struct _GLFWmapelement _GLFWmapelement; +typedef struct _GLFWmapping _GLFWmapping; +typedef struct _GLFWjoystick _GLFWjoystick; +typedef struct _GLFWtls _GLFWtls; +typedef struct _GLFWmutex _GLFWmutex; typedef void (* _GLFWmakecontextcurrentfun)(_GLFWwindow*); typedef void (* _GLFWswapbuffersfun)(_GLFWwindow*); @@ -69,6 +84,7 @@ typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*); #define GL_VERSION 0x1f02 #define GL_NONE 0 #define GL_COLOR_BUFFER_BIT 0x00004000 +#define GL_UNSIGNED_BYTE 0x1401 #define GL_EXTENSIONS 0x1f03 #define GL_NUM_EXTENSIONS 0x821d #define GL_CONTEXT_FLAGS 0x821e @@ -110,6 +126,7 @@ typedef enum VkStructureType VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000, VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR = 1000007000, VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000, + VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000053000, VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF } VkStructureType; @@ -171,6 +188,8 @@ typedef void (APIENTRY * PFN_vkVoidFunction)(void); #include "wl_platform.h" #elif defined(_GLFW_MIR) #include "mir_platform.h" +#elif defined(_GLFW_OSMESA) + #include "null_platform.h" #else #error "No supported window creation API selected" #endif @@ -216,13 +235,13 @@ typedef void (APIENTRY * PFN_vkVoidFunction)(void); // Checks for whether the library has been initialized #define _GLFW_REQUIRE_INIT() \ - if (!_glfwInitialized) \ + if (!_glfw.initialized) \ { \ _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \ return; \ } #define _GLFW_REQUIRE_INIT_OR_RETURN(x) \ - if (!_glfwInitialized) \ + if (!_glfw.initialized) \ { \ _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \ return x; \ @@ -242,6 +261,30 @@ typedef void (APIENTRY * PFN_vkVoidFunction)(void); // Platform-independent structures //======================================================================== +struct _GLFWerror +{ + _GLFWerror* next; + int code; + char description[_GLFW_MESSAGE_SIZE]; +}; + +/*! @brief Initialization configuration. + * + * Parameters relating to the initialization of the library. + */ +struct _GLFWinitconfig +{ + GLFWbool hatButtons; + struct { + GLFWbool menubar; + GLFWbool chdir; + } ns; + struct { + char className[256]; + char classClass[256]; + } x11; +}; + /*! @brief Window configuration. * * Parameters relating to the creation of the window but not directly related @@ -260,6 +303,11 @@ struct _GLFWwndconfig GLFWbool autoIconify; GLFWbool floating; GLFWbool maximized; + GLFWbool centerCursor; + struct { + GLFWbool retina; + GLFWbool frame; + } ns; }; /*! @brief Context configuration. @@ -281,6 +329,9 @@ struct _GLFWctxconfig int robustness; int release; _GLFWwindow* share; + struct { + GLFWbool offline; + } nsgl; }; /*! @brief Framebuffer configuration. @@ -338,6 +389,8 @@ struct _GLFWcontext _GLFW_PLATFORM_CONTEXT_STATE; // This is defined in egl_context.h _GLFW_EGL_CONTEXT_STATE; + // This is defined in osmesa_context.h + _GLFW_OSMESA_CONTEXT_STATE; }; /*! @brief Window and context structure. @@ -351,7 +404,7 @@ struct _GLFWwindow GLFWbool decorated; GLFWbool autoIconify; GLFWbool floating; - GLFWbool closed; + GLFWbool shouldClose; void* userPointer; GLFWvidmode videoMode; _GLFWmonitor* monitor; @@ -378,6 +431,7 @@ struct _GLFWwindow GLFWwindowrefreshfun refresh; GLFWwindowfocusfun focus; GLFWwindowiconifyfun iconify; + GLFWwindowmaximizefun maximize; GLFWframebuffersizefun fbsize; GLFWmousebuttonfun mouseButton; GLFWcursorposfun cursorPos; @@ -426,41 +480,115 @@ struct _GLFWcursor _GLFW_PLATFORM_CURSOR_STATE; }; +/*! @brief Gamepad mapping element structure + */ +struct _GLFWmapelement +{ + uint8_t type; + uint8_t value; +}; + +/*! @brief Gamepad mapping structure + */ +struct _GLFWmapping +{ + char name[128]; + char guid[33]; + _GLFWmapelement buttons[15]; + _GLFWmapelement axes[6]; +}; + +/*! @brief Joystick structure + */ +struct _GLFWjoystick +{ + GLFWbool present; + float* axes; + int axisCount; + unsigned char* buttons; + int buttonCount; + unsigned char* hats; + int hatCount; + char* name; + char guid[33]; + _GLFWmapping* mapping; + + // This is defined in the joystick API's joystick.h + _GLFW_PLATFORM_JOYSTICK_STATE; +}; + +/*! @brief Thread local storage structure. + */ +struct _GLFWtls +{ + // This is defined in the platform's thread.h + _GLFW_PLATFORM_TLS_STATE; +}; + +/*! @brief Mutex structure. + */ +struct _GLFWmutex +{ + // This is defined in the platform's thread.h + _GLFW_PLATFORM_MUTEX_STATE; +}; + /*! @brief Library global data. */ struct _GLFWlibrary { + GLFWbool initialized; + struct { + _GLFWinitconfig init; _GLFWfbconfig framebuffer; _GLFWwndconfig window; _GLFWctxconfig context; int refreshRate; } hints; + _GLFWerror* errorListHead; _GLFWcursor* cursorListHead; - _GLFWwindow* windowListHead; _GLFWmonitor** monitors; int monitorCount; - uint64_t timerOffset; + _GLFWjoystick joysticks[GLFW_JOYSTICK_LAST + 1]; + _GLFWmapping* mappings; + int mappingCount; + + _GLFWtls errorSlot; + _GLFWtls contextSlot; + _GLFWmutex errorLock; + + struct { + uint64_t offset; + // This is defined in the platform's time.h + _GLFW_PLATFORM_LIBRARY_TIMER_STATE; + } timer; struct { GLFWbool available; void* handle; - char** extensions; - uint32_t extensionCount; + char* extensions[2]; #if !defined(_GLFW_VULKAN_STATIC) PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties; PFN_vkGetInstanceProcAddr GetInstanceProcAddr; #endif GLFWbool KHR_surface; +#if defined(_GLFW_WIN32) GLFWbool KHR_win32_surface; +#elif defined(_GLFW_COCOA) + GLFWbool MVK_macos_surface; +#elif defined(_GLFW_X11) GLFWbool KHR_xlib_surface; GLFWbool KHR_xcb_surface; +#elif defined(_GLFW_WAYLAND) GLFWbool KHR_wayland_surface; +#elif defined(_GLFW_MIR) GLFWbool KHR_mir_surface; +#endif } vk; struct { @@ -472,14 +600,12 @@ struct _GLFWlibrary _GLFW_PLATFORM_LIBRARY_WINDOW_STATE; // This is defined in the context API's context.h _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE; - // This is defined in the platform's time.h - _GLFW_PLATFORM_LIBRARY_TIME_STATE; // This is defined in the platform's joystick.h _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE; - // This is defined in the platform's tls.h - _GLFW_PLATFORM_LIBRARY_TLS_STATE; // This is defined in egl_context.h _GLFW_EGL_LIBRARY_CONTEXT_STATE; + // This is defined in osmesa_context.h + _GLFW_OSMESA_LIBRARY_CONTEXT_STATE; }; @@ -487,13 +613,7 @@ struct _GLFWlibrary // Global state shared between compilation units of GLFW //======================================================================== -/*! @brief Flag indicating whether GLFW has been successfully initialized. - */ -extern GLFWbool _glfwInitialized; - -/*! @brief All global data protected by @ref _glfwInitialized. - * This should only be touched after a call to @ref glfwInit that has not been - * followed by a call to @ref glfwTerminate. +/*! @brief All global data shared between compilation units. */ extern _GLFWlibrary _glfw; @@ -502,312 +622,96 @@ extern _GLFWlibrary _glfw; // Platform API functions //======================================================================== -/*! @brief Initializes the platform-specific part of the library. - * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an error occurred. - * @ingroup platform - */ -int _glfwPlatformInit(void); +/*! @addtogroup platform @{ */ -/*! @brief Terminates the platform-specific part of the library. - * @ingroup platform - */ +int _glfwPlatformInit(void); void _glfwPlatformTerminate(void); - -/*! @copydoc glfwGetVersionString - * @ingroup platform - * - * @note The returned string must be available for the duration of the program. - * - * @note The returned string must not change for the duration of the program. - */ const char* _glfwPlatformGetVersionString(void); -/*! @copydoc glfwGetCursorPos - * @ingroup platform - */ void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos); - -/*! @copydoc glfwSetCursorPos - * @ingroup platform - */ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos); - -/*! @brief Sets the specified cursor mode of the specified window. - * @param[in] window The window whose cursor mode to set. - * @ingroup platform - */ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode); +int _glfwPlatformCreateCursor(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); +int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape); +void _glfwPlatformDestroyCursor(_GLFWcursor* cursor); +void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor); -/*! @copydoc glfwGetKeyName - * @ingroup platform - */ -const char* _glfwPlatformGetKeyName(int key, int scancode); - -/*! @copydoc glfwGetMonitors - * @ingroup platform - */ -_GLFWmonitor** _glfwPlatformGetMonitors(int* count); - -/*! @brief Checks whether two monitor objects represent the same monitor. - * - * @param[in] first The first monitor. - * @param[in] second The second monitor. - * @return @c GLFW_TRUE if the monitor objects represent the same monitor, or - * @c GLFW_FALSE otherwise. - * @ingroup platform - */ -GLFWbool _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second); +const char* _glfwPlatformGetScancodeName(int scancode); +int _glfwPlatformGetKeyScancode(int key); -/*! @copydoc glfwGetMonitorPos - * @ingroup platform - */ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos); - -/*! @copydoc glfwGetVideoModes - * @ingroup platform - */ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count); - -/*! @ingroup platform - */ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode); - -/*! @copydoc glfwGetGammaRamp - * @ingroup platform - */ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp); - -/*! @copydoc glfwSetGammaRamp - * @ingroup platform - */ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp); -/*! @copydoc glfwSetClipboardString - * @ingroup platform - */ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string); - -/*! @copydoc glfwGetClipboardString - * @ingroup platform - * - * @note The returned string must be valid until the next call to @ref - * _glfwPlatformGetClipboardString or @ref _glfwPlatformSetClipboardString. - */ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window); -/*! @copydoc glfwJoystickPresent - * @ingroup platform - */ -int _glfwPlatformJoystickPresent(int joy); +int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode); +void _glfwPlatformUpdateGamepadGUID(char* guid); -/*! @copydoc glfwGetJoystickAxes - * @ingroup platform - */ -const float* _glfwPlatformGetJoystickAxes(int joy, int* count); - -/*! @copydoc glfwGetJoystickButtons - * @ingroup platform - */ -const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count); - -/*! @copydoc glfwGetJoystickName - * @ingroup platform - */ -const char* _glfwPlatformGetJoystickName(int joy); - -/*! @copydoc glfwGetTimerValue - * @ingroup platform - */ uint64_t _glfwPlatformGetTimerValue(void); - -/*! @copydoc glfwGetTimerFrequency - * @ingroup platform - */ uint64_t _glfwPlatformGetTimerFrequency(void); -/*! @ingroup platform - */ int _glfwPlatformCreateWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); - -/*! @ingroup platform - */ void _glfwPlatformDestroyWindow(_GLFWwindow* window); - -/*! @copydoc glfwSetWindowTitle - * @ingroup platform - */ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title); - -/*! @copydoc glfwSetWindowIcon - * @ingroup platform - */ void _glfwPlatformSetWindowIcon(_GLFWwindow* window, int count, const GLFWimage* images); - -/*! @copydoc glfwGetWindowPos - * @ingroup platform - */ void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos); - -/*! @copydoc glfwSetWindowPos - * @ingroup platform - */ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos); - -/*! @copydoc glfwGetWindowSize - * @ingroup platform - */ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height); - -/*! @copydoc glfwSetWindowSize - * @ingroup platform - */ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height); - -/*! @copydoc glfwSetWindowSizeLimits - * @ingroup platform - */ void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight); - -/*! @copydoc glfwSetWindowAspectRatio - * @ingroup platform - */ void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom); - -/*! @copydoc glfwGetFramebufferSize - * @ingroup platform - */ void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height); - -/*! @copydoc glfwGetWindowFrameSize - * @ingroup platform - */ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, int* left, int* top, int* right, int* bottom); - -/*! @copydoc glfwIconifyWindow - * @ingroup platform - */ void _glfwPlatformIconifyWindow(_GLFWwindow* window); - -/*! @copydoc glfwRestoreWindow - * @ingroup platform - */ void _glfwPlatformRestoreWindow(_GLFWwindow* window); - -/*! @copydoc glfwMaximizeWindow - * @ingroup platform - */ void _glfwPlatformMaximizeWindow(_GLFWwindow* window); - -/*! @copydoc glfwShowWindow - * @ingroup platform - */ void _glfwPlatformShowWindow(_GLFWwindow* window); - -/*! @copydoc glfwHideWindow - * @ingroup platform - */ void _glfwPlatformHideWindow(_GLFWwindow* window); - -/*! @copydoc glfwFocusWindow - * @ingroup platform - */ +void _glfwPlatformRequestWindowAttention(_GLFWwindow* window); void _glfwPlatformFocusWindow(_GLFWwindow* window); - -/*! @copydoc glfwSetWindowMonitor - * @ingroup platform - */ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); - -/*! @brief Returns whether the window is focused. - * @ingroup platform - */ int _glfwPlatformWindowFocused(_GLFWwindow* window); - -/*! @brief Returns whether the window is iconified. - * @ingroup platform - */ int _glfwPlatformWindowIconified(_GLFWwindow* window); - -/*! @brief Returns whether the window is visible. - * @ingroup platform - */ int _glfwPlatformWindowVisible(_GLFWwindow* window); - -/*! @brief Returns whether the window is maximized. - * @ingroup platform - */ int _glfwPlatformWindowMaximized(_GLFWwindow* window); +void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled); +void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled); +void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled); -/*! @copydoc glfwPollEvents - * @ingroup platform - */ void _glfwPlatformPollEvents(void); - -/*! @copydoc glfwWaitEvents - * @ingroup platform - */ void _glfwPlatformWaitEvents(void); - -/*! @copydoc glfwWaitEventsTimeout - * @ingroup platform - */ void _glfwPlatformWaitEventsTimeout(double timeout); - -/*! @copydoc glfwPostEmptyEvent - * @ingroup platform - */ void _glfwPlatformPostEmptyEvent(void); -/*! @ingroup platform - */ -void _glfwPlatformSetCurrentContext(_GLFWwindow* context); - -/*! @copydoc glfwGetCurrentContext - * @ingroup platform - */ -_GLFWwindow* _glfwPlatformGetCurrentContext(void); - -/*! @copydoc glfwCreateCursor - * @ingroup platform - */ -int _glfwPlatformCreateCursor(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); - -/*! @copydoc glfwCreateStandardCursor - * @ingroup platform - */ -int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape); - -/*! @copydoc glfwDestroyCursor - * @ingroup platform - */ -void _glfwPlatformDestroyCursor(_GLFWcursor* cursor); - -/*! @copydoc glfwSetCursor - * @ingroup platform - */ -void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor); +void _glfwPlatformGetRequiredInstanceExtensions(char** extensions); +int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); +VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); -/*! @ingroup platform - */ -char** _glfwPlatformGetRequiredInstanceExtensions(uint32_t* count); +GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls); +void _glfwPlatformDestroyTls(_GLFWtls* tls); +void* _glfwPlatformGetTls(_GLFWtls* tls); +void _glfwPlatformSetTls(_GLFWtls* tls, void* value); -/*! @ingroup platform - */ -int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); +GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex); +void _glfwPlatformDestroyMutex(_GLFWmutex* mutex); +void _glfwPlatformLockMutex(_GLFWmutex* mutex); +void _glfwPlatformUnlockMutex(_GLFWmutex* mutex); -/*! @ingroup platform - */ -VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); +/*! @} */ //======================================================================== // Event API functions //======================================================================== -/*! @brief Notifies shared code of a window focus event. +/*! @brief Notifies shared code that a window has lost or received input focus. * @param[in] window The window that received the event. * @param[in] focused `GLFW_TRUE` if the window received focus, or `GLFW_FALSE` * if it lost focus. @@ -815,7 +719,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, _GLFWwindow* wind */ void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused); -/*! @brief Notifies shared code of a window movement event. +/*! @brief Notifies shared code that a window has moved. * @param[in] window The window that received the event. * @param[in] xpos The new x-coordinate of the client area of the window. * @param[in] ypos The new y-coordinate of the client area of the window. @@ -823,7 +727,7 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused); */ void _glfwInputWindowPos(_GLFWwindow* window, int xpos, int ypos); -/*! @brief Notifies shared code of a window resize event. +/*! @brief Notifies shared code that a window has been resized. * @param[in] window The window that received the event. * @param[in] width The new width of the client area of the window. * @param[in] height The new height of the client area of the window. @@ -831,7 +735,7 @@ void _glfwInputWindowPos(_GLFWwindow* window, int xpos, int ypos); */ void _glfwInputWindowSize(_GLFWwindow* window, int width, int height); -/*! @brief Notifies shared code of a framebuffer resize event. +/*! @brief Notifies shared code that a window framebuffer has been resized. * @param[in] window The window that received the event. * @param[in] width The new width, in pixels, of the framebuffer. * @param[in] height The new height, in pixels, of the framebuffer. @@ -839,7 +743,7 @@ void _glfwInputWindowSize(_GLFWwindow* window, int width, int height); */ void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height); -/*! @brief Notifies shared code of a window iconification event. +/*! @brief Notifies shared code that a window has been iconified or restored. * @param[in] window The window that received the event. * @param[in] iconified `GLFW_TRUE` if the window was iconified, or * `GLFW_FALSE` if it was restored. @@ -847,17 +751,30 @@ void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height); */ void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified); -/*! @brief Notifies shared code of a window damage event. +/*! @brief Notifies shared code that a window has been maximized or restored. + * @param[in] window The window that received the event. + * @param[in] maximized `GLFW_TRUE` if the window was maximized, or + * `GLFW_FALSE` if it was restored. + * @ingroup event + */ +void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized); + +/*! @brief Notifies shared code that a window's contents needs updating. * @param[in] window The window that received the event. */ void _glfwInputWindowDamage(_GLFWwindow* window); -/*! @brief Notifies shared code of a window close request event +/*! @brief Notifies shared code that the user wishes to close a window. * @param[in] window The window that received the event. * @ingroup event */ void _glfwInputWindowCloseRequest(_GLFWwindow* window); +/*! @brief Notifies shared code that a window has changed its desired monitor. + * @param[in] window The window that received the event. + * @param[in] monitor The new desired monitor, or `NULL`. + * @ingroup event + */ void _glfwInputWindowMonitorChange(_GLFWwindow* window, _GLFWmonitor* monitor); /*! @brief Notifies shared code of a physical key event. @@ -892,6 +809,7 @@ void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset); * @param[in] window The window that received the event. * @param[in] button The button that was pressed or released. * @param[in] action @ref GLFW_PRESS or @ref GLFW_RELEASE. + * @param[in] mods The modifiers pressed when the event was generated. * @ingroup event */ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods); @@ -914,27 +832,35 @@ void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos); */ void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered); -/*! @ingroup event +/*! @brief Notifies shared code of a monitor connection or disconnection. + * @param[in] monitor The monitor that was connected or disconnected. + * @param[in] action One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. + * @param[in] placement `_GLFW_INSERT_FIRST` or `_GLFW_INSERT_LAST`. + * @ingroup event */ -void _glfwInputMonitorChange(void); +void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement); -/*! @ingroup event +/*! @brief Notifies shared code that a full screen window has acquired or + * released a monitor. + * @param[in] monitor The monitor that was acquired or released. + * @param[in] window The window that acquired the monitor, or `NULL`. + * @ingroup event */ -void _glfwInputMonitorWindowChange(_GLFWmonitor* monitor, _GLFWwindow* window); +void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window); /*! @brief Notifies shared code of an error. - * @param[in] error The error code most suitable for the error. + * @param[in] code The error code most suitable for the error. * @param[in] format The `printf` style format string of the error * description. * @ingroup event */ #if defined(__GNUC__) -void _glfwInputError(int error, const char* format, ...) __attribute__((format(printf, 2, 3))); +void _glfwInputError(int code, const char* format, ...) __attribute__((format(printf, 2, 3))); #else -void _glfwInputError(int error, const char* format, ...); +void _glfwInputError(int code, const char* format, ...); #endif -/*! @brief Notifies dropped object over window. +/*! @brief Notifies shared code of files or directories dropped on a window. * @param[in] window The window that received the event. * @param[in] count The number of dropped objects. * @param[in] names The names of the dropped objects. @@ -942,19 +868,41 @@ void _glfwInputError(int error, const char* format, ...); */ void _glfwInputDrop(_GLFWwindow* window, int count, const char** names); -/*! @brief Notifies shared code of a joystick connection/disconnection event. - * @param[in] joy The joystick that was connected or disconnected. +/*! @brief Notifies shared code of a joystick connection or disconnection. + * @param[in] js The joystick that was connected or disconnected. * @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. * @ingroup event */ -void _glfwInputJoystickChange(int joy, int event); +void _glfwInputJoystick(_GLFWjoystick* js, int event); + +/*! @brief Notifies shared code of the new value of a joystick axis. + * @param[in] js The joystick whose axis to update. + * @param[in] axis The index of the axis to update. + * @param[in] value The new value of the axis. + */ +void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value); + +/*! @brief Notifies shared code of the new value of a joystick button. + * @param[in] js The joystick whose button to update. + * @param[in] button The index of the button to update. + * @param[in] value The new value of the button. + */ +void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value); + +/*! @brief Notifies shared code of the new value of a joystick hat. + * @param[in] js The joystick whose hat to update. + * @param[in] button The index of the hat to update. + * @param[in] value The new value of the hat. + */ +void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value); //======================================================================== // Utility functions //======================================================================== -/*! @ingroup utility +/*! @brief Chooses the video mode most closely matching the desired one. + * @ingroup utility */ const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired); @@ -1009,11 +957,13 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig); */ GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig); -/*! @ingroup utility +/*! @brief Allocates red, green and blue value arrays of the specified size. + * @ingroup utility */ void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size); -/*! @ingroup utility +/*! @brief Frees the red, green and blue value arrays and clears the struct. + * @ingroup utility */ void _glfwFreeGammaArrays(GLFWgammaramp* ramp); @@ -1032,17 +982,23 @@ _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM); */ void _glfwFreeMonitor(_GLFWmonitor* monitor); -/*! @ingroup utility +/*! @brief Returns an available joystick object with arrays and name allocated. + * @ingroup utility */ -void _glfwFreeMonitors(_GLFWmonitor** monitors, int count); +_GLFWjoystick* _glfwAllocJoystick(const char* name, + const char* guid, + int axisCount, + int buttonCount, + int hatCount); -/*! @ingroup utility - */ -GLFWbool _glfwIsPrintable(int key); +/*! @brief Frees arrays and name and flags the joystick object as unused. + * @ingroup utility + */ +void _glfwFreeJoystick(_GLFWjoystick* js); /*! @ingroup utility */ -GLFWbool _glfwInitVulkan(void); +GLFWbool _glfwInitVulkan(int mode); /*! @ingroup utility */ @@ -1052,4 +1008,3 @@ void _glfwTerminateVulkan(void); */ const char* _glfwGetVulkanResultString(VkResult result); -#endif // _glfw3_internal_h_ diff --git a/libs/glfw/src/linux_joystick.cc b/libs/glfw/src/linux_joystick.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 Linux - www.glfw.org +// GLFW 3.3 Linux - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -27,9 +27,6 @@ #include "internal.h" -#if defined(__linux__) -#include <linux/joystick.h> - #include <sys/types.h> #include <sys/stat.h> #include <sys/inotify.h> @@ -40,129 +37,220 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> -#endif // __linux__ +// Apply an EV_KEY event to the specified joystick +// +static void handleKeyEvent(_GLFWjoystick* js, int code, int value) +{ + _glfwInputJoystickButton(js, + js->linjs.keyMap[code - BTN_MISC], + value ? GLFW_PRESS : GLFW_RELEASE); +} -// Attempt to open the specified joystick device +// Apply an EV_ABS event to the specified joystick // -#if defined(__linux__) -static GLFWbool openJoystickDevice(const char* path) +static void handleAbsEvent(_GLFWjoystick* js, int code, int value) { - char axisCount, buttonCount; - char name[256] = ""; - int joy, fd, version; - _GLFWjoystickLinux* js; + const int index = js->linjs.absMap[code]; + + if (code >= ABS_HAT0X && code <= ABS_HAT3Y) + { + static const char stateMap[3][3] = + { + { GLFW_HAT_CENTERED, GLFW_HAT_UP, GLFW_HAT_DOWN }, + { GLFW_HAT_LEFT, GLFW_HAT_LEFT_UP, GLFW_HAT_LEFT_DOWN }, + { GLFW_HAT_RIGHT, GLFW_HAT_RIGHT_UP, GLFW_HAT_RIGHT_DOWN }, + }; + + const int hat = (code - ABS_HAT0X) / 2; + const int axis = (code - ABS_HAT0X) % 2; + int* state = js->linjs.hats[hat]; + + // NOTE: Looking at several input drivers, it seems all hat events use + // -1 for left / up, 0 for centered and 1 for right / down + if (value == 0) + state[axis] = 0; + else if (value < 0) + state[axis] = 1; + else if (value > 0) + state[axis] = 2; + + _glfwInputJoystickHat(js, index, stateMap[state[0]][state[1]]); + } + else + { + const struct input_absinfo* info = &js->linjs.absInfo[code]; + float normalized = value; + + const int range = info->maximum - info->minimum; + if (range) + { + // Normalize to 0.0 -> 1.0 + normalized = (normalized - info->minimum) / range; + // Normalize to -1.0 -> 1.0 + normalized = normalized * 2.0f - 1.0f; + } + + _glfwInputJoystickAxis(js, index, normalized); + } +} + +// Poll state of absolute axes +// +static void pollAbsState(_GLFWjoystick* js) +{ + int code; - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) + for (code = 0; code < ABS_CNT; code++) { - if (!_glfw.linux_js.js[joy].present) + if (js->linjs.absMap[code] < 0) continue; - if (strcmp(_glfw.linux_js.js[joy].path, path) == 0) - return GLFW_FALSE; + struct input_absinfo* info = &js->linjs.absInfo[code]; + + if (ioctl(js->linjs.fd, EVIOCGABS(code), info) < 0) + continue; + + handleAbsEvent(js, code, info->value); } +} + +#define isBitSet(bit, arr) (arr[(bit) / 8] & (1 << ((bit) % 8))) - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) +// Attempt to open the specified joystick device +// +static GLFWbool openJoystickDevice(const char* path) +{ + int jid, code; + char name[256] = ""; + char guid[33] = ""; + char evBits[(EV_CNT + 7) / 8] = {0}; + char keyBits[(KEY_CNT + 7) / 8] = {0}; + char absBits[(ABS_CNT + 7) / 8] = {0}; + int axisCount = 0, buttonCount = 0, hatCount = 0; + struct input_id id; + _GLFWjoystickLinux linjs = {0}; + _GLFWjoystick* js = NULL; + + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) { - if (!_glfw.linux_js.js[joy].present) - break; + if (!_glfw.joysticks[jid].present) + continue; + if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0) + return GLFW_FALSE; } - if (joy > GLFW_JOYSTICK_LAST) + linjs.fd = open(path, O_RDONLY | O_NONBLOCK); + if (linjs.fd == -1) return GLFW_FALSE; - fd = open(path, O_RDONLY | O_NONBLOCK); - if (fd == -1) + if (ioctl(linjs.fd, EVIOCGBIT(0, sizeof(evBits)), evBits) < 0 || + ioctl(linjs.fd, EVIOCGBIT(EV_KEY, sizeof(keyBits)), keyBits) < 0 || + ioctl(linjs.fd, EVIOCGBIT(EV_ABS, sizeof(absBits)), absBits) < 0 || + ioctl(linjs.fd, EVIOCGID, &id) < 0) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Linux: Failed to query input device: %s", + strerror(errno)); + close(linjs.fd); return GLFW_FALSE; + } - // Verify that the joystick driver version is at least 1.0 - ioctl(fd, JSIOCGVERSION, &version); - if (version < 0x010000) + // Ensure this device supports the events expected of a joystick + if (!isBitSet(EV_KEY, evBits) || !isBitSet(EV_ABS, evBits)) { - // It's an old 0.x interface (we don't support it) - close(fd); + close(linjs.fd); return GLFW_FALSE; } - if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0) + if (ioctl(linjs.fd, EVIOCGNAME(sizeof(name)), name) < 0) strncpy(name, "Unknown", sizeof(name)); - js = _glfw.linux_js.js + joy; - js->present = GLFW_TRUE; - js->name = strdup(name); - js->path = strdup(path); - js->fd = fd; + // Generate a joystick GUID that matches the SDL 2.0.5+ one + if (id.vendor && id.product && id.version) + { + sprintf(guid, "%02x%02x0000%02x%02x0000%02x%02x0000%02x%02x0000", + id.bustype & 0xff, id.bustype >> 8, + id.vendor & 0xff, id.vendor >> 8, + id.product & 0xff, id.product >> 8, + id.version & 0xff, id.version >> 8); + } + else + { + sprintf(guid, "%02x%02x0000%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x00", + id.bustype & 0xff, id.bustype >> 8, + name[0], name[1], name[2], name[3], + name[4], name[5], name[6], name[7], + name[8], name[9], name[10]); + } - ioctl(fd, JSIOCGAXES, &axisCount); - js->axisCount = (int) axisCount; - js->axes = calloc(axisCount, sizeof(float)); + for (code = BTN_MISC; code < KEY_CNT; code++) + { + if (!isBitSet(code, keyBits)) + continue; - ioctl(fd, JSIOCGBUTTONS, &buttonCount); - js->buttonCount = (int) buttonCount; - js->buttons = calloc(buttonCount, 1); + linjs.keyMap[code - BTN_MISC] = buttonCount; + buttonCount++; + } - _glfwInputJoystickChange(joy, GLFW_CONNECTED); - return GLFW_TRUE; -} -#endif // __linux__ + for (code = 0; code < ABS_CNT; code++) + { + linjs.absMap[code] = -1; + if (!isBitSet(code, absBits)) + continue; -// Polls for and processes events the specified joystick -// -static GLFWbool pollJoystickEvents(_GLFWjoystickLinux* js) -{ -#if defined(__linux__) - _glfwPollJoystickEvents(); + if (code >= ABS_HAT0X && code <= ABS_HAT3Y) + { + linjs.absMap[code] = hatCount; + hatCount++; + // Skip the Y axis + code++; + } + else + { + if (ioctl(linjs.fd, EVIOCGABS(code), &linjs.absInfo[code]) < 0) + continue; - if (!js->present) - return GLFW_FALSE; + linjs.absMap[code] = axisCount; + axisCount++; + } + } - // Read all queued events (non-blocking) - for (;;) + js = _glfwAllocJoystick(name, guid, axisCount, buttonCount, hatCount); + if (!js) { - struct js_event e; - - errno = 0; - if (read(js->fd, &e, sizeof(e)) < 0) - { - // Reset the joystick slot if the device was disconnected - if (errno == ENODEV) - { - free(js->axes); - free(js->buttons); - free(js->name); - free(js->path); + close(linjs.fd); + return GLFW_FALSE; + } - memset(js, 0, sizeof(_GLFWjoystickLinux)); + strncpy(linjs.path, path, sizeof(linjs.path)); + memcpy(&js->linjs, &linjs, sizeof(linjs)); - _glfwInputJoystickChange(js - _glfw.linux_js.js, - GLFW_DISCONNECTED); - } + pollAbsState(js); - break; - } + _glfwInputJoystick(js, GLFW_CONNECTED); + return GLFW_TRUE; +} - // Clear the initial-state bit - e.type &= ~JS_EVENT_INIT; +#undef isBitSet - if (e.type == JS_EVENT_AXIS) - js->axes[e.number] = (float) e.value / 32767.0f; - else if (e.type == JS_EVENT_BUTTON) - js->buttons[e.number] = e.value ? GLFW_PRESS : GLFW_RELEASE; - } -#endif // __linux__ - return js->present; +// Frees all resources associated with the specified joystick +// +static void closeJoystick(_GLFWjoystick* js) +{ + close(js->linjs.fd); + _glfwFreeJoystick(js); + _glfwInputJoystick(js, GLFW_DISCONNECTED); } // Lexically compare joysticks by name; used by qsort // -#if defined(__linux__) static int compareJoysticks(const void* fp, const void* sp) { - const _GLFWjoystickLinux* fj = fp; - const _GLFWjoystickLinux* sj = sp; - return strcmp(fj->path, sj->path); + const _GLFWjoystick* fj = fp; + const _GLFWjoystick* sj = sp; + return strcmp(fj->linjs.path, sj->linjs.path); } -#endif // __linux__ ////////////////////////////////////////////////////////////////////////// @@ -173,36 +261,24 @@ static int compareJoysticks(const void* fp, const void* sp) // GLFWbool _glfwInitJoysticksLinux(void) { -#if defined(__linux__) DIR* dir; int count = 0; const char* dirname = "/dev/input"; - _glfw.linux_js.inotify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); - if (_glfw.linux_js.inotify == -1) + _glfw.linjs.inotify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); + if (_glfw.linjs.inotify > 0) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Linux: Failed to initialize inotify: %s", - strerror(errno)); - return GLFW_FALSE; - } + // HACK: Register for IN_ATTRIB to get notified when udev is done + // This works well in practice but the true way is libudev - // HACK: Register for IN_ATTRIB as well to get notified when udev is done - // This works well in practice but the true way is libudev - - _glfw.linux_js.watch = inotify_add_watch(_glfw.linux_js.inotify, - dirname, - IN_CREATE | IN_ATTRIB); - if (_glfw.linux_js.watch == -1) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Linux: Failed to watch for joystick connections in %s: %s", - dirname, - strerror(errno)); - // Continue without device connection notifications + _glfw.linjs.watch = inotify_add_watch(_glfw.linjs.inotify, + dirname, + IN_CREATE | IN_ATTRIB | IN_DELETE); } - if (regcomp(&_glfw.linux_js.regex, "^js[0-9]\\+$", 0) != 0) + // Continue without device connection notifications if inotify fails + + if (regcomp(&_glfw.linjs.regex, "^event[0-9]\\+$", 0) != 0) { _glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to compile regex"); return GLFW_FALSE; @@ -215,13 +291,15 @@ GLFWbool _glfwInitJoysticksLinux(void) while ((entry = readdir(dir))) { - char path[20]; regmatch_t match; - if (regexec(&_glfw.linux_js.regex, entry->d_name, 1, &match, 0) != 0) + if (regexec(&_glfw.linjs.regex, entry->d_name, 1, &match, 0) != 0) continue; + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s/%s", dirname, entry->d_name); + if (openJoystickDevice(path)) count++; } @@ -229,17 +307,10 @@ GLFWbool _glfwInitJoysticksLinux(void) closedir(dir); } else - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Linux: Failed to open joystick device directory %s: %s", - dirname, - strerror(errno)); - // Continue with no joysticks detected - } - qsort(_glfw.linux_js.js, count, sizeof(_GLFWjoystickLinux), compareJoysticks); -#endif // __linux__ + // Continue with no joysticks if enumeration fails + qsort(_glfw.joysticks, count, sizeof(_GLFWjoystick), compareJoysticks); return GLFW_TRUE; } @@ -247,56 +318,65 @@ GLFWbool _glfwInitJoysticksLinux(void) // void _glfwTerminateJoysticksLinux(void) { -#if defined(__linux__) - int i; + int jid; - for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) { - if (_glfw.linux_js.js[i].present) - { - close(_glfw.linux_js.js[i].fd); - free(_glfw.linux_js.js[i].axes); - free(_glfw.linux_js.js[i].buttons); - free(_glfw.linux_js.js[i].name); - free(_glfw.linux_js.js[i].path); - } + _GLFWjoystick* js = _glfw.joysticks + jid; + if (js->present) + closeJoystick(js); } - regfree(&_glfw.linux_js.regex); + regfree(&_glfw.linjs.regex); - if (_glfw.linux_js.inotify > 0) + if (_glfw.linjs.inotify > 0) { - if (_glfw.linux_js.watch > 0) - inotify_rm_watch(_glfw.linux_js.inotify, _glfw.linux_js.watch); + if (_glfw.linjs.watch > 0) + inotify_rm_watch(_glfw.linjs.inotify, _glfw.linjs.watch); - close(_glfw.linux_js.inotify); + close(_glfw.linjs.inotify); } -#endif // __linux__ } -void _glfwPollJoystickEvents(void) +void _glfwDetectJoystickConnectionLinux(void) { -#if defined(__linux__) ssize_t offset = 0; char buffer[16384]; - const ssize_t size = read(_glfw.linux_js.inotify, buffer, sizeof(buffer)); + if (_glfw.linjs.inotify <= 0) + return; + + const ssize_t size = read(_glfw.linjs.inotify, buffer, sizeof(buffer)); while (size > offset) { regmatch_t match; const struct inotify_event* e = (struct inotify_event*) (buffer + offset); - if (regexec(&_glfw.linux_js.regex, e->name, 1, &match, 0) == 0) - { - char path[20]; - snprintf(path, sizeof(path), "/dev/input/%s", e->name); + offset += sizeof(struct inotify_event) + e->len; + + if (regexec(&_glfw.linjs.regex, e->name, 1, &match, 0) != 0) + continue; + + char path[PATH_MAX]; + snprintf(path, sizeof(path), "/dev/input/%s", e->name); + + if (e->mask & (IN_CREATE | IN_ATTRIB)) openJoystickDevice(path); - } + else if (e->mask & IN_DELETE) + { + int jid; - offset += sizeof(struct inotify_event) + e->len; + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) + { + if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0) + { + closeJoystick(_glfw.joysticks + jid); + break; + } + } + } } -#endif } @@ -304,38 +384,47 @@ void _glfwPollJoystickEvents(void) ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// -int _glfwPlatformJoystickPresent(int joy) +int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode) { - _GLFWjoystickLinux* js = _glfw.linux_js.js + joy; - return pollJoystickEvents(js); -} + // Read all queued events (non-blocking) + for (;;) + { + struct input_event e; -const float* _glfwPlatformGetJoystickAxes(int joy, int* count) -{ - _GLFWjoystickLinux* js = _glfw.linux_js.js + joy; - if (!pollJoystickEvents(js)) - return NULL; + errno = 0; + if (read(js->linjs.fd, &e, sizeof(e)) < 0) + { + // Reset the joystick slot if the device was disconnected + if (errno == ENODEV) + closeJoystick(js); - *count = js->axisCount; - return js->axes; -} + break; + } -const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) -{ - _GLFWjoystickLinux* js = _glfw.linux_js.js + joy; - if (!pollJoystickEvents(js)) - return NULL; + if (e.type == EV_SYN) + { + if (e.code == SYN_DROPPED) + _glfw.linjs.dropped = GLFW_TRUE; + else if (e.code == SYN_REPORT) + { + _glfw.linjs.dropped = GLFW_FALSE; + pollAbsState(js); + } + } + + if (_glfw.linjs.dropped) + continue; - *count = js->buttonCount; - return js->buttons; + if (e.type == EV_KEY) + handleKeyEvent(js, e.code, e.value); + else if (e.type == EV_ABS) + handleAbsEvent(js, e.code, e.value); + } + + return js->present; } -const char* _glfwPlatformGetJoystickName(int joy) +void _glfwPlatformUpdateGamepadGUID(char* guid) { - _GLFWjoystickLinux* js = _glfw.linux_js.js + joy; - if (!pollJoystickEvents(js)) - return NULL; - - return js->name; } diff --git a/libs/glfw/src/linux_joystick.h b/libs/glfw/src/linux_joystick.h @@ -1,5 +1,5 @@ //======================================================================== -// GLFW 3.2 Linux - www.glfw.org +// GLFW 3.3 Linux - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2014 Jonas Ådahl <jadahl@gmail.com> // @@ -24,45 +24,39 @@ // //======================================================================== -#ifndef _glfw3_linux_joystick_h_ -#define _glfw3_linux_joystick_h_ - +#include <linux/input.h> +#include <linux/limits.h> #include <regex.h> -#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWjoylistLinux linux_js +#define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickLinux linjs +#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs +#define _GLFW_PLATFORM_MAPPING_NAME "Linux" // Linux-specific joystick data // typedef struct _GLFWjoystickLinux { - GLFWbool present; - int fd; - float* axes; - int axisCount; - unsigned char* buttons; - int buttonCount; - char* name; - char* path; + int fd; + char path[PATH_MAX]; + int keyMap[KEY_CNT - BTN_MISC]; + int absMap[ABS_CNT]; + struct input_absinfo absInfo[ABS_CNT]; + int hats[4][2]; } _GLFWjoystickLinux; // Linux-specific joystick API data // -typedef struct _GLFWjoylistLinux +typedef struct _GLFWlibraryLinux { - _GLFWjoystickLinux js[GLFW_JOYSTICK_LAST + 1]; - -#if defined(__linux__) - int inotify; - int watch; - regex_t regex; -#endif /*__linux__*/ -} _GLFWjoylistLinux; + int inotify; + int watch; + regex_t regex; + GLFWbool dropped; +} _GLFWlibraryLinux; GLFWbool _glfwInitJoysticksLinux(void); void _glfwTerminateJoysticksLinux(void); +void _glfwDetectJoystickConnectionLinux(void); -void _glfwPollJoystickEvents(void); - -#endif // _glfw3_linux_joystick_h_ diff --git a/libs/glfw/src/mappings.h b/libs/glfw/src/mappings.h @@ -0,0 +1,230 @@ +//======================================================================== +// GLFW 3.3 - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +// All gamepad mappings not labeled GLFW are copied from the +// SDL_GameControllerDB project under the following license: +// +// Simple DirectMedia Layer +// Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the +// use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. + +const char* _glfwDefaultMappings = +"8f0e1200000000000000504944564944,Acme,platform:Windows,x:b2,a:b0,b:b1,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,\n" +"341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows,\n" +"ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Windows,\n" +"6d0416c2000000000000504944564944,Generic DirectInput Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows,\n" +"0d0f6e00000000000000504944564944,HORIPAD 4,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Windows,\n" +"6d0419c2000000000000504944564944,Logitech F710 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows,\n" +"88880803000000000000504944564944,PS3 Controller,a:b2,b:b1,back:b8,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b9,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:b7,rightx:a3,righty:a4,start:b11,x:b0,y:b3,platform:Windows,\n" +"4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,platform:Windows,\n" +"25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,back:b9,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b0,y:b3,platform:Windows,\n" +"4c05c405000000000000504944564944,Sony DualShock 4,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b13,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Windows,\n" +"4c05cc09000000000000504944564944,Sony DualShock 4,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b13,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Windows,\n" +"4c05a00b000000000000504944564944,Sony DualShock 4 Wireless Adaptor,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b13,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Windows,\n" +"6d0418c2000000000000504944564944,Logitech RumblePad 2 USB,platform:Windows,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,\n" +"36280100000000000000504944564944,OUYA Controller,platform:Windows,a:b0,b:b3,y:b2,x:b1,start:b14,guide:b15,leftstick:b6,rightstick:b7,leftshoulder:b4,rightshoulder:b5,dpup:b8,dpleft:b10,dpdown:b9,dpright:b11,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b12,righttrigger:b13,\n" +"4f0400b3000000000000504944564944,Thrustmaster Firestorm Dual Power,a:b0,b:b2,y:b3,x:b1,start:b10,guide:b8,back:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,platform:Windows,\n" +"00f00300000000000000504944564944,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Windows,\n" +"00f0f100000000000000504944564944,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Windows,\n" +"28040140000000000000504944564944,GamePad Pro USB,platform:Windows,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,lefttrigger:b6,righttrigger:b7,\n" +"ff113133000000000000504944564944,SVEN X-PAD,platform:Windows,a:b2,b:b3,y:b1,x:b0,start:b5,back:b4,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b8,righttrigger:b9,\n" +"8f0e0300000000000000504944564944,Piranha xtreme,platform:Windows,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,\n" +"8f0e0d31000000000000504944564944,Multilaser JS071 USB,platform:Windows,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,\n" +"10080300000000000000504944564944,PS2 USB,platform:Windows,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a4,righty:a2,lefttrigger:b4,righttrigger:b5,\n" +"79000600000000000000504944564944,G-Shark GS-GP702,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b6,righttrigger:b7,platform:Windows,\n" +"4b12014d000000000000504944564944,NYKO AIRFLO,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b10,start:b9,leftstick:a0,rightstick:a2,leftshoulder:a3,rightshoulder:b5,dpup:h0.1,dpdown:h0.0,dpleft:h0.8,dpright:h0.2,leftx:h0.6,lefty:h0.12,rightx:h0.9,righty:h0.4,lefttrigger:b6,righttrigger:b7,platform:Windows,\n" +"d6206dca000000000000504944564944,PowerA Pro Ex,a:b1,b:b2,x:b0,y:b3,back:b8,guide:b12,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.0,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Windows,\n" +"a3060cff000000000000504944564944,Saitek P2500,a:b2,b:b3,y:b1,x:b0,start:b4,guide:b10,back:b5,leftstick:b8,rightstick:b9,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,platform:Windows,\n" +"4f0415b3000000000000504944564944,Thrustmaster Dual Analog 3.2,platform:Windows,x:b1,a:b0,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,\n" +"6f0e1e01000000000000504944564944,Rock Candy Gamepad for PS3,platform:Windows,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,guide:b12,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,\n" +"83056020000000000000504944564944,iBuffalo USB 2-axis 8-button Gamepad,a:b1,b:b0,y:b2,x:b3,start:b7,back:b6,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,platform:Windows,\n" +"10080100000000000000504944564944,PS1 USB,platform:Windows,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftshoulder:b6,rightshoulder:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b4,righttrigger:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,\n" +"49190204000000000000504944564944,Ipega PG-9023,a:b0,b:b1,x:b3,y:b4,back:b10,start:b11,leftstick:b13,rightstick:b14,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b8,righttrigger:b9,platform:Windows,\n" +"4f0423b3000000000000504944564944,Dual Trigger 3-in-1,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:b6,righttrigger:b7,platform:Windows,\n" +"0d0f4900000000000000504944564944,Hatsune Miku Sho Controller,a:b1,b:b2,x:b0,y:b3,back:b8,guide:b12,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Windows,\n" +"79004318000000000000504944564944,Mayflash GameCube Controller Adapter,platform:Windows,a:b1,b:b2,x:b0,y:b3,back:b0,start:b9,guide:b0,leftshoulder:b4,rightshoulder:b7,leftstick:b0,rightstick:b0,leftx:a0,lefty:a1,rightx:a5,righty:a2,lefttrigger:a3,righttrigger:a4,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,\n" +"79000018000000000000504944564944,Mayflash WiiU Pro Game Controller Adapter (DInput),a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Windows,\n" +"2509e803000000000000504944564944,Mayflash Wii Classic Controller,a:b1,b:b0,x:b3,y:b2,back:b8,guide:b10,start:b9,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:b11,dpdown:b13,dpleft:b12,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Windows,\n" +"300f1001000000000000504944564944,Saitek P480 Rumble Pad,a:b2,b:b3,x:b0,y:b1,back:b8,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b5,righttrigger:b7,platform:Windows,\n" +"10280900000000000000504944564944,8Bitdo SFC30 GamePad,a:b1,b:b0,y:b3,x:b4,start:b11,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,platform:Windows,\n" +"63252305000000000000504944564944,USB Vibration Joystick (BM),platform:Windows,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,\n" +"20380900000000000000504944564944,8Bitdo NES30 PRO Wireless,platform:Windows,a:b0,b:b1,x:b3,y:b4,leftshoulder:b6,rightshoulder:b7,lefttrigger:b8,righttrigger:b9,back:b10,start:b11,leftstick:b13,rightstick:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,\n" +"02200090000000000000504944564944,8Bitdo NES30 PRO USB,platform:Windows,a:b0,b:b1,x:b3,y:b4,leftshoulder:b6,rightshoulder:b7,lefttrigger:b8,righttrigger:b9,back:b10,start:b11,leftstick:b13,rightstick:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,\n" +"ff113133000000000000504944564944,Gembird JPD-DualForce,platform:Windows,a:b2,b:b3,x:b0,y:b1,start:b9,back:b8,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b6,righttrigger:b7,leftstick:b10,rightstick:b11,\n" +"341a0108000000000000504944564944,EXEQ RF USB Gamepad 8206,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,leftstick:b8,rightstick:b7,back:b8,start:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftx:a0,lefty:a1,rightx:a2,righty:a3,platform:Windows,\n" +"c0111352000000000000504944564944,Battalife Joystick,platform:Windows,x:b4,a:b6,b:b7,y:b5,back:b2,start:b3,leftshoulder:b0,rightshoulder:b1,leftx:a0,lefty:a1,\n" +"100801e5000000000000504944564944,NEXT Classic USB Game Controller,a:b0,b:b1,back:b8,start:b9,rightx:a2,righty:a3,leftx:a0,lefty:a1,platform:Windows,\n" +"79000600000000000000504944564944,NGS Phantom,a:b2,b:b3,y:b1,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b6,righttrigger:b7,platform:Windows,\n" +"0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Mac OS X,\n" +"6d0400000000000016c2000000000000,Logitech F310 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X,\n" +"6d0400000000000018c2000000000000,Logitech F510 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X,\n" +"6d040000000000001fc2000000000000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,platform:Mac OS X,\n" +"6d0400000000000019c2000000000000,Logitech Wireless Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X,\n" +"4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,platform:Mac OS X,\n" +"4c05000000000000c405000000000000,Sony DualShock 4,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b13,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Mac OS X,\n" +"4c05000000000000cc09000000000000,Sony DualShock 4 V2,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b13,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Mac OS X,\n" +"5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,platform:Mac OS X,\n" +"891600000000000000fd000000000000,Razer Onza Tournament,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,leftstick:b6,rightstick:b7,leftshoulder:b4,rightshoulder:b5,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Mac OS X,\n" +"4f0400000000000000b3000000000000,Thrustmaster Firestorm Dual Power,a:b0,b:b2,y:b3,x:b1,start:b10,guide:b8,back:b9,leftstick:b11,rightstick:,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,platform:Mac OS X,\n" +"8f0e0000000000000300000000000000,Piranha xtreme,platform:Mac OS X,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,\n" +"0d0f0000000000004d00000000000000,HORI Gem Pad 3,platform:Mac OS X,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,\n" +"79000000000000000600000000000000,G-Shark GP-702,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,platform:Mac OS X,\n" +"4f0400000000000015b3000000000000,Thrustmaster Dual Analog 3.2,platform:Mac OS X,x:b1,a:b0,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,\n" +"AD1B00000000000001F9000000000000,Gamestop BB-070 X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,platform:Mac OS X,\n" +"050000005769696d6f74652028303000,Wii Remote,a:b4,b:b5,y:b9,x:b10,start:b6,guide:b8,back:b7,dpup:b2,dpleft:b0,dpdown:b3,dpright:b1,leftx:a0,lefty:a1,lefttrigger:b12,righttrigger:,leftshoulder:b11,platform:Mac OS X,\n" +"83050000000000006020000000000000,iBuffalo USB 2-axis 8-button Gamepad,a:b1,b:b0,x:b3,y:b2,back:b6,start:b7,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,platform:Mac OS X,\n" +"bd1200000000000015d0000000000000,Tomee SNES USB Controller,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,platform:Mac OS X,\n" +"79000000000000001100000000000000,Retrolink Classic Controller,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,leftx:a3,lefty:a4,platform:Mac OS X,\n" +"5e04000000000000dd02000000000000,Xbox One Wired Controller,platform:Mac OS X,x:b2,a:b0,b:b1,y:b3,back:b9,guide:b10,start:b8,dpleft:b13,dpdown:b12,dpright:b14,dpup:b11,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"5e04000000000000ea02000000000000,Xbox Wireless Controller,platform:Mac OS X,x:b2,a:b0,b:b1,y:b3,back:b9,guide:b10,start:b8,dpleft:b13,dpdown:b12,dpright:b14,dpup:b11,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"5e04000000000000e002000000000000,Xbox Wireless Controller,platform:Mac OS X,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b10,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"050000005769696d6f74652028313800,Wii U Pro Controller,a:b16,b:b15,x:b18,y:b17,back:b7,guide:b8,start:b6,leftstick:b23,rightstick:b24,leftshoulder:b19,rightshoulder:b20,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b21,righttrigger:b22,platform:Mac OS X,\n" +"79000000000000000018000000000000,Mayflash WiiU Pro Game Controller Adapter (DInput),a:b4,b:b8,x:b0,y:b12,back:b32,start:b36,leftstick:b40,rightstick:b44,leftshoulder:b16,rightshoulder:b20,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a4,rightx:a8,righty:a12,lefttrigger:b24,righttrigger:b28,platform:Mac OS X,\n" +"2509000000000000e803000000000000,Mayflash Wii Classic Controller,a:b1,b:b0,x:b3,y:b2,back:b8,guide:b10,start:b9,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:b11,dpdown:b13,dpleft:b12,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Mac OS X,\n" +"351200000000000021ab000000000000,SFC30 Joystick,a:b1,b:b0,x:b4,y:b3,back:b10,start:b11,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Mac OS X,\n" +"b4040000000000000a01000000000000,Sega Saturn USB Gamepad,a:b0,b:b1,x:b3,y:b4,back:b5,guide:b2,start:b8,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Mac OS X,\n" +"81170000000000007e05000000000000,Sega Saturn,x:b0,a:b2,b:b4,y:b6,start:b13,dpleft:b15,dpdown:b16,dpright:b14,dpup:b17,leftshoulder:b8,lefttrigger:a5,lefttrigger:b10,rightshoulder:b9,righttrigger:a4,righttrigger:b11,leftx:a0,lefty:a2,platform:Mac OS X,\n" +"10280000000000000900000000000000,8Bitdo SFC30 GamePad,a:b1,b:b0,x:b4,y:b3,back:b10,start:b11,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Mac OS X,\n" +"d814000000000000cecf000000000000,MC Cthulhu,platform:Mac OS X,leftx:,lefty:,rightx:,righty:,lefttrigger:b6,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,righttrigger:b7,\n" +"0d0f0000000000006600000000000000,HORIPAD FPS PLUS 4,platform:Mac OS X,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:b6,righttrigger:a4,\n" +"0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux,\n" +"03000000ba2200002010000001010000,Jess Technology USB Game Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b3,y:b0,platform:Linux,\n" +"030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux,\n" +"030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,\n" +"030000006d04000016c2000011010000,Logitech F310 Gamepad (DInput),x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,platform:Linux,\n" +"030000006d0400001ec2000020200000,Logitech F510 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,\n" +"030000006d04000019c2000011010000,Logitech F710 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux,\n" +"030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,\n" +"030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,platform:Linux,\n" +"030000004c050000c405000011010000,Sony DualShock 4,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b13,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Linux,\n" +"050000004c050000c405000000010000,Sony DualShock 4 BT,a:b1,b:b2,back:b13,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,\n" +"030000004c050000cc09000011010000,Sony DualShock 4 V2,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b13,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Linux,\n" +"050000004c050000cc09000000010000,Sony DualShock 4 V2 BT,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b13,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Linux,\n" +"030000004c050000a00b000011010000,Sony DualShock 4 Wireless Adaptor,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b13,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:a3,righttrigger:a4,platform:Linux,\n" +"030000006f0e00003001000001010000,EA Sports PS3 Controller,platform:Linux,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,\n" +"03000000de280000ff11000001000000,Valve Streaming Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,\n" +"030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,\n" +"030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,\n" +"030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,\n" +"03000000100800000100000010010000,Twin USB PS2 Adapter,a:b2,b:b1,y:b0,x:b3,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b4,righttrigger:b5,platform:Linux,\n" +"03000000a306000023f6000011010000,Saitek Cyborg V.1 Game Pad,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b6,righttrigger:b7,platform:Linux,\n" +"030000004f04000020b3000010010000,Thrustmaster 2 in 1 DT,a:b0,b:b2,y:b3,x:b1,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,platform:Linux,\n" +"030000004f04000023b3000000010000,Thrustmaster Dual Trigger 3-in-1,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a5,\n" +"030000008f0e00000300000010010000,GreenAsia Inc. USB Joystick ,platform:Linux,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,\n" +"030000008f0e00001200000010010000,GreenAsia Inc. USB Joystick ,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,\n" +"030000005e0400009102000007010000,X360 Wireless Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Linux,\n" +"030000006d04000016c2000010010000,Logitech Logitech Dual Action,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,\n" +"03000000260900008888000000010000,GameCube {WiseGroup USB box},a:b0,b:b2,y:b3,x:b1,start:b7,leftshoulder:,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,rightstick:,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:Linux,\n" +"030000006d04000011c2000010010000,Logitech WingMan Cordless RumblePad,a:b0,b:b1,y:b4,x:b3,start:b8,guide:b5,back:b2,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b9,righttrigger:b10,platform:Linux,\n" +"030000006d04000018c2000010010000,Logitech Logitech RumblePad 2 USB,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,\n" +"05000000d6200000ad0d000001000000,Moga Pro,platform:Linux,a:b0,b:b1,y:b3,x:b2,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a5,righttrigger:a4,\n" +"030000004f04000009d0000000010000,Thrustmaster Run N Drive Wireless PS3,platform:Linux,a:b1,b:b2,x:b0,y:b3,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,\n" +"030000004f04000008d0000000010000,Thrustmaster Run N Drive Wireless,platform:Linux,a:b1,b:b2,x:b0,y:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:b6,righttrigger:b7,\n" +"0300000000f000000300000000010000,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Linux,\n" +"0300000000f00000f100000000010000,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Linux,\n" +"030000006f0e00001f01000000010000,Generic X-Box pad,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"03000000280400000140000000010000,Gravis GamePad Pro USB ,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftx:a0,lefty:a1,\n" +"030000005e0400008902000021010000,Microsoft X-Box pad v2 (US),platform:Linux,x:b3,a:b0,b:b1,y:b4,back:b6,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b5,lefttrigger:a2,rightshoulder:b2,righttrigger:a5,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"030000005e0400008502000000010000,Microsoft X-Box pad (Japan),platform:Linux,x:b3,a:b0,b:b1,y:b4,back:b6,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b5,lefttrigger:a2,rightshoulder:b2,righttrigger:a5,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"030000006f0e00001e01000011010000,Rock Candy Gamepad for PS3,platform:Linux,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,guide:b12,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,\n" +"03000000250900000500000000010000,Sony PS2 pad with SmartJoy adapter,platform:Linux,a:b2,b:b1,y:b0,x:b3,start:b8,back:b9,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5,\n" +"030000008916000000fd000024010000,Razer Onza Tournament,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Linux,\n" +"030000004f04000000b3000010010000,Thrustmaster Firestorm Dual Power,a:b0,b:b2,y:b3,x:b1,start:b10,guide:b8,back:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,platform:Linux,\n" +"03000000ad1b000001f5000033050000,Hori Pad EX Turbo 2,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Linux,\n" +"060000004c0500006802000000010000,PS3 Controller (Bluetooth),a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,platform:Linux,\n" +"050000004c0500006802000000010000,PS3 Controller (Bluetooth),a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,platform:Linux,\n" +"03000000790000000600000010010000,DragonRise Inc. Generic USB Joystick ,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a3,rightx:a1,righty:a4,\n" +"03000000666600000488000000010000,Super Joy Box 5 Pro,platform:Linux,a:b2,b:b1,x:b3,y:b0,back:b9,start:b8,leftshoulder:b6,rightshoulder:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5,dpup:b12,dpleft:b15,dpdown:b14,dpright:b13,\n" +"05000000362800000100000002010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,platform:Linux,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,\n" +"05000000362800000100000003010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,platform:Linux,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,\n" +"030000008916000001fd000024010000,Razer Onza Classic Edition,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:b11,dpdown:b14,dpright:b12,dpup:b13,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"030000005e040000d102000001010000,Microsoft X-Box One pad,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"030000005e040000dd02000003020000,Microsoft X-Box One pad v2,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,platform:Linux,\n" +"03000000790000001100000010010000,RetroLink Saturn Classic Controller,platform:Linux,x:b3,a:b0,b:b1,y:b4,back:b5,guide:b2,start:b8,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,\n" +"050000007e0500003003000001000000,Nintendo Wii U Pro Controller,platform:Linux,a:b0,b:b1,x:b3,y:b2,back:b8,start:b9,guide:b10,leftshoulder:b4,rightshoulder:b5,leftstick:b11,rightstick:b12,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:b13,dpleft:b15,dpdown:b14,dpright:b16,\n" +"030000005e0400008e02000004010000,Microsoft X-Box 360 pad,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,guide:b8,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,\n" +"030000000d0f00002200000011010000,HORI CO. LTD. REAL ARCADE Pro.V3,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,guide:b12,start:b9,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,\n" +"030000000d0f00001000000011010000,HORI CO. LTD. FIGHTING STICK 3,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,guide:b12,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7\n" +"03000000f0250000c183000010010000,Goodbetterbest Ltd USB Controller,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,guide:b12,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,\n" +"0000000058626f782047616d65706100,Xbox Gamepad (userspace driver),platform:Linux,a:b0,b:b1,x:b2,y:b3,start:b7,back:b6,guide:b8,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,lefttrigger:a5,righttrigger:a4,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a2,righty:a3,\n" +"03000000ff1100003133000010010000,PC Game Controller,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Linux,\n" +"030000005e0400008e02000020200000,SpeedLink XEOX Pro Analog Gamepad pad,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"030000006f0e00001304000000010000,Generic X-Box pad,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:a0,rightstick:a3,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"03000000a306000018f5000010010000,Saitek PLC Saitek P3200 Rumble Pad,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:a2,rightshoulder:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"03000000830500006020000010010000,iBuffalo USB 2-axis 8-button Gamepad,a:b1,b:b0,x:b3,y:b2,back:b6,start:b7,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,platform:Linux,\n" +"03000000bd12000015d0000010010000,Tomee SNES USB Controller,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,platform:Linux,\n" +"03000000790000001100000010010000,Retrolink Classic Controller,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,platform:Linux,\n" +"03000000c9110000f055000011010000,HJC Game GAMEPAD,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a3,dpleft:h0.8,lefttrigger:b6,x:b2,dpup:h0.1,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b0,dpright:h0.2,righttrigger:b7,b:b1,platform:Linux,\n" +"03000000a30600000c04000011010000,Saitek P2900 Wireless Pad,a:b1,b:b2,y:b3,x:b0,start:b12,guide:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b4,righttrigger:b5,platform:Linux,\n" +"03000000341a000005f7000010010000,GameCube {HuiJia USB box},a:b1,b:b2,y:b3,x:b0,start:b9,guide:,back:,leftstick:,rightstick:,leftshoulder:,dpleft:b15,dpdown:b14,dpright:b13,leftx:a0,lefty:a1,rightx:a5,righty:a2,lefttrigger:a3,righttrigger:a4,rightshoulder:b7,dpup:b12,platform:Linux,\n" +"030000006e0500000320000010010000,JC-U3613M - DirectInput Mode,platform:Linux,x:b0,a:b2,b:b3,y:b1,back:b10,guide:b12,start:b11,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,\n" +"030000006f0e00004601000001010000,Rock Candy Wired Controller for Xbox One,platform:Linux,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,guide:b8,leftstick:b9,rightstick:b10,lefttrigger:a2,righttrigger:a5,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"03000000380700001647000010040000,Mad Catz Wired Xbox 360 Controller,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"030000006f0e00003901000020060000,Afterglow Wired Controller for Xbox One,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,platform:Linux,\n" +"030000004f04000015b3000010010000,Thrustmaster Dual Analog 4,platform:Linux,a:b0,b:b2,x:b1,y:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,\n" +"05000000102800000900000000010000,8Bitdo SFC30 GamePad,platform:Linux,x:b4,a:b1,b:b0,y:b3,back:b10,start:b11,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,\n" +"03000000d81400000862000011010000,HitBox (PS3/PC) Analog Mode,platform:Linux,a:b1,b:b2,y:b3,x:b0,start:b12,guide:b9,back:b8,leftshoulder:b4,rightshoulder:b5,lefttrigger:b6,righttrigger:b7,leftx:a0,lefty:a1,\n" +"030000000d0f00000d00000000010000,hori,platform:Linux,a:b0,b:b6,y:b2,x:b1,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,start:b9,guide:b10,back:b8,leftshoulder:b3,rightshoulder:b7,leftx:b4,lefty:b5,\n" +"03000000ad1b000016f0000090040000,Mad Catz Xbox 360 Controller,platform:Linux,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,\n" +"03000000d814000007cd000011010000,Toodles 2008 Chimp PC/PS3,platform:Linux,a:b0,b:b1,y:b2,x:b3,start:b9,back:b8,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,lefttrigger:b6,righttrigger:b7,\n" +"03000000fd0500000030000000010000,InterAct GoPad I-73000 (Fighting Game Layout),platform:Linux,a:b3,b:b4,y:b1,x:b0,start:b7,back:b6,leftx:a0,lefty:a1,rightshoulder:b2,righttrigger:b5,\n" +"05000000010000000100000003000000,Nintendo Wiimote,platform:Linux,a:b0,b:b1,y:b3,x:b2,start:b9,guide:b10,back:b8,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,\n" +"030000005e0400008e02000062230000,Microsoft X-Box 360 pad,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"03000000a30600000901000000010000,Saitek P880,a:b2,b:b3,y:b1,x:b0,leftstick:b8,rightstick:b9,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b6,righttrigger:b7,platform:Linux,\n" +"030000006f0e00000103000000020000,Logic3 Controller,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"05000000380700006652000025010000,Mad Catz C.T.R.L.R ,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,guide:b12,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,\n" +"030000005e0400008e02000073050000,Speedlink TORID Wireless Gamepad,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,\n" +"03000000ad1b00002ef0000090040000,Mad Catz Fightpad SFxT,platform:Linux,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,lefttrigger:a2,righttrigger:a5,\n" +"05000000a00500003232000001000000,8Bitdo Zero GamePad,platform:Linux,a:b0,b:b1,x:b3,y:b4,back:b10,start:b11,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,\n" +"030000001008000001e5000010010000,NEXT Classic USB Game Controller,a:b0,b:b1,back:b8,start:b9,rightx:a2,righty:a3,leftx:a0,lefty:a1,platform:Linux,\n" +"03000000100800000300000010010000,USB Gamepad,platform:Linux,a:b2,b:b1,x:b3,y:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b4,righttrigger:b5,\n" +"05000000ac0500003232000001000000,VR-BOX,platform:Linux,a:b0,b:b1,x:b2,y:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b4,righttrigger:b5,\n" +"03000000780000000600000010010000,Microntek USB Joystick,platform:Linux,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftx:a0,lefty:a1,\n" +"78696e70757401000000000000000000,XInput Gamepad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,\n" +"78696e70757402000000000000000000,XInput Wheel (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,\n" +"78696e70757403000000000000000000,XInput Arcade Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,\n" +"78696e70757404000000000000000000,XInput Flight Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,\n" +"78696e70757405000000000000000000,XInput Dance Pad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,\n" +"78696e70757406000000000000000000,XInput Guitar (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,\n" +"78696e70757408000000000000000000,XInput Drum Kit (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,\n"; + diff --git a/libs/glfw/src/mir_init.cc b/libs/glfw/src/mir_init.cc @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 Mir - www.glfw.org +// GLFW 3.3 Mir - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com> +// Copyright (c) 2014-2017 Brandon Schaefer <brandon.schaefer@canonical.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 @@ -35,124 +35,134 @@ // static void createKeyTables(void) { - memset(_glfw.mir.publicKeys, -1, sizeof(_glfw.mir.publicKeys)); - - _glfw.mir.publicKeys[KEY_GRAVE] = GLFW_KEY_GRAVE_ACCENT; - _glfw.mir.publicKeys[KEY_1] = GLFW_KEY_1; - _glfw.mir.publicKeys[KEY_2] = GLFW_KEY_2; - _glfw.mir.publicKeys[KEY_3] = GLFW_KEY_3; - _glfw.mir.publicKeys[KEY_4] = GLFW_KEY_4; - _glfw.mir.publicKeys[KEY_5] = GLFW_KEY_5; - _glfw.mir.publicKeys[KEY_6] = GLFW_KEY_6; - _glfw.mir.publicKeys[KEY_7] = GLFW_KEY_7; - _glfw.mir.publicKeys[KEY_8] = GLFW_KEY_8; - _glfw.mir.publicKeys[KEY_9] = GLFW_KEY_9; - _glfw.mir.publicKeys[KEY_0] = GLFW_KEY_0; - _glfw.mir.publicKeys[KEY_MINUS] = GLFW_KEY_MINUS; - _glfw.mir.publicKeys[KEY_EQUAL] = GLFW_KEY_EQUAL; - _glfw.mir.publicKeys[KEY_Q] = GLFW_KEY_Q; - _glfw.mir.publicKeys[KEY_W] = GLFW_KEY_W; - _glfw.mir.publicKeys[KEY_E] = GLFW_KEY_E; - _glfw.mir.publicKeys[KEY_R] = GLFW_KEY_R; - _glfw.mir.publicKeys[KEY_T] = GLFW_KEY_T; - _glfw.mir.publicKeys[KEY_Y] = GLFW_KEY_Y; - _glfw.mir.publicKeys[KEY_U] = GLFW_KEY_U; - _glfw.mir.publicKeys[KEY_I] = GLFW_KEY_I; - _glfw.mir.publicKeys[KEY_O] = GLFW_KEY_O; - _glfw.mir.publicKeys[KEY_P] = GLFW_KEY_P; - _glfw.mir.publicKeys[KEY_LEFTBRACE] = GLFW_KEY_LEFT_BRACKET; - _glfw.mir.publicKeys[KEY_RIGHTBRACE] = GLFW_KEY_RIGHT_BRACKET; - _glfw.mir.publicKeys[KEY_A] = GLFW_KEY_A; - _glfw.mir.publicKeys[KEY_S] = GLFW_KEY_S; - _glfw.mir.publicKeys[KEY_D] = GLFW_KEY_D; - _glfw.mir.publicKeys[KEY_F] = GLFW_KEY_F; - _glfw.mir.publicKeys[KEY_G] = GLFW_KEY_G; - _glfw.mir.publicKeys[KEY_H] = GLFW_KEY_H; - _glfw.mir.publicKeys[KEY_J] = GLFW_KEY_J; - _glfw.mir.publicKeys[KEY_K] = GLFW_KEY_K; - _glfw.mir.publicKeys[KEY_L] = GLFW_KEY_L; - _glfw.mir.publicKeys[KEY_SEMICOLON] = GLFW_KEY_SEMICOLON; - _glfw.mir.publicKeys[KEY_APOSTROPHE] = GLFW_KEY_APOSTROPHE; - _glfw.mir.publicKeys[KEY_Z] = GLFW_KEY_Z; - _glfw.mir.publicKeys[KEY_X] = GLFW_KEY_X; - _glfw.mir.publicKeys[KEY_C] = GLFW_KEY_C; - _glfw.mir.publicKeys[KEY_V] = GLFW_KEY_V; - _glfw.mir.publicKeys[KEY_B] = GLFW_KEY_B; - _glfw.mir.publicKeys[KEY_N] = GLFW_KEY_N; - _glfw.mir.publicKeys[KEY_M] = GLFW_KEY_M; - _glfw.mir.publicKeys[KEY_COMMA] = GLFW_KEY_COMMA; - _glfw.mir.publicKeys[KEY_DOT] = GLFW_KEY_PERIOD; - _glfw.mir.publicKeys[KEY_SLASH] = GLFW_KEY_SLASH; - _glfw.mir.publicKeys[KEY_BACKSLASH] = GLFW_KEY_BACKSLASH; - _glfw.mir.publicKeys[KEY_ESC] = GLFW_KEY_ESCAPE; - _glfw.mir.publicKeys[KEY_TAB] = GLFW_KEY_TAB; - _glfw.mir.publicKeys[KEY_LEFTSHIFT] = GLFW_KEY_LEFT_SHIFT; - _glfw.mir.publicKeys[KEY_RIGHTSHIFT] = GLFW_KEY_RIGHT_SHIFT; - _glfw.mir.publicKeys[KEY_LEFTCTRL] = GLFW_KEY_LEFT_CONTROL; - _glfw.mir.publicKeys[KEY_RIGHTCTRL] = GLFW_KEY_RIGHT_CONTROL; - _glfw.mir.publicKeys[KEY_LEFTALT] = GLFW_KEY_LEFT_ALT; - _glfw.mir.publicKeys[KEY_RIGHTALT] = GLFW_KEY_RIGHT_ALT; - _glfw.mir.publicKeys[KEY_LEFTMETA] = GLFW_KEY_LEFT_SUPER; - _glfw.mir.publicKeys[KEY_RIGHTMETA] = GLFW_KEY_RIGHT_SUPER; - _glfw.mir.publicKeys[KEY_MENU] = GLFW_KEY_MENU; - _glfw.mir.publicKeys[KEY_NUMLOCK] = GLFW_KEY_NUM_LOCK; - _glfw.mir.publicKeys[KEY_CAPSLOCK] = GLFW_KEY_CAPS_LOCK; - _glfw.mir.publicKeys[KEY_PRINT] = GLFW_KEY_PRINT_SCREEN; - _glfw.mir.publicKeys[KEY_SCROLLLOCK] = GLFW_KEY_SCROLL_LOCK; - _glfw.mir.publicKeys[KEY_PAUSE] = GLFW_KEY_PAUSE; - _glfw.mir.publicKeys[KEY_DELETE] = GLFW_KEY_DELETE; - _glfw.mir.publicKeys[KEY_BACKSPACE] = GLFW_KEY_BACKSPACE; - _glfw.mir.publicKeys[KEY_ENTER] = GLFW_KEY_ENTER; - _glfw.mir.publicKeys[KEY_HOME] = GLFW_KEY_HOME; - _glfw.mir.publicKeys[KEY_END] = GLFW_KEY_END; - _glfw.mir.publicKeys[KEY_PAGEUP] = GLFW_KEY_PAGE_UP; - _glfw.mir.publicKeys[KEY_PAGEDOWN] = GLFW_KEY_PAGE_DOWN; - _glfw.mir.publicKeys[KEY_INSERT] = GLFW_KEY_INSERT; - _glfw.mir.publicKeys[KEY_LEFT] = GLFW_KEY_LEFT; - _glfw.mir.publicKeys[KEY_RIGHT] = GLFW_KEY_RIGHT; - _glfw.mir.publicKeys[KEY_DOWN] = GLFW_KEY_DOWN; - _glfw.mir.publicKeys[KEY_UP] = GLFW_KEY_UP; - _glfw.mir.publicKeys[KEY_F1] = GLFW_KEY_F1; - _glfw.mir.publicKeys[KEY_F2] = GLFW_KEY_F2; - _glfw.mir.publicKeys[KEY_F3] = GLFW_KEY_F3; - _glfw.mir.publicKeys[KEY_F4] = GLFW_KEY_F4; - _glfw.mir.publicKeys[KEY_F5] = GLFW_KEY_F5; - _glfw.mir.publicKeys[KEY_F6] = GLFW_KEY_F6; - _glfw.mir.publicKeys[KEY_F7] = GLFW_KEY_F7; - _glfw.mir.publicKeys[KEY_F8] = GLFW_KEY_F8; - _glfw.mir.publicKeys[KEY_F9] = GLFW_KEY_F9; - _glfw.mir.publicKeys[KEY_F10] = GLFW_KEY_F10; - _glfw.mir.publicKeys[KEY_F11] = GLFW_KEY_F11; - _glfw.mir.publicKeys[KEY_F12] = GLFW_KEY_F12; - _glfw.mir.publicKeys[KEY_F13] = GLFW_KEY_F13; - _glfw.mir.publicKeys[KEY_F14] = GLFW_KEY_F14; - _glfw.mir.publicKeys[KEY_F15] = GLFW_KEY_F15; - _glfw.mir.publicKeys[KEY_F16] = GLFW_KEY_F16; - _glfw.mir.publicKeys[KEY_F17] = GLFW_KEY_F17; - _glfw.mir.publicKeys[KEY_F18] = GLFW_KEY_F18; - _glfw.mir.publicKeys[KEY_F19] = GLFW_KEY_F19; - _glfw.mir.publicKeys[KEY_F20] = GLFW_KEY_F20; - _glfw.mir.publicKeys[KEY_F21] = GLFW_KEY_F21; - _glfw.mir.publicKeys[KEY_F22] = GLFW_KEY_F22; - _glfw.mir.publicKeys[KEY_F23] = GLFW_KEY_F23; - _glfw.mir.publicKeys[KEY_F24] = GLFW_KEY_F24; - _glfw.mir.publicKeys[KEY_KPSLASH] = GLFW_KEY_KP_DIVIDE; - _glfw.mir.publicKeys[KEY_KPDOT] = GLFW_KEY_KP_MULTIPLY; - _glfw.mir.publicKeys[KEY_KPMINUS] = GLFW_KEY_KP_SUBTRACT; - _glfw.mir.publicKeys[KEY_KPPLUS] = GLFW_KEY_KP_ADD; - _glfw.mir.publicKeys[KEY_KP0] = GLFW_KEY_KP_0; - _glfw.mir.publicKeys[KEY_KP1] = GLFW_KEY_KP_1; - _glfw.mir.publicKeys[KEY_KP2] = GLFW_KEY_KP_2; - _glfw.mir.publicKeys[KEY_KP3] = GLFW_KEY_KP_3; - _glfw.mir.publicKeys[KEY_KP4] = GLFW_KEY_KP_4; - _glfw.mir.publicKeys[KEY_KP5] = GLFW_KEY_KP_5; - _glfw.mir.publicKeys[KEY_KP6] = GLFW_KEY_KP_6; - _glfw.mir.publicKeys[KEY_KP7] = GLFW_KEY_KP_7; - _glfw.mir.publicKeys[KEY_KP8] = GLFW_KEY_KP_8; - _glfw.mir.publicKeys[KEY_KP9] = GLFW_KEY_KP_9; - _glfw.mir.publicKeys[KEY_KPCOMMA] = GLFW_KEY_KP_DECIMAL; - _glfw.mir.publicKeys[KEY_KPEQUAL] = GLFW_KEY_KP_EQUAL; - _glfw.mir.publicKeys[KEY_KPENTER] = GLFW_KEY_KP_ENTER; + int scancode; + + memset(_glfw.mir.keycodes, -1, sizeof(_glfw.mir.keycodes)); + memset(_glfw.mir.scancodes, -1, sizeof(_glfw.mir.scancodes)); + + _glfw.mir.keycodes[KEY_GRAVE] = GLFW_KEY_GRAVE_ACCENT; + _glfw.mir.keycodes[KEY_1] = GLFW_KEY_1; + _glfw.mir.keycodes[KEY_2] = GLFW_KEY_2; + _glfw.mir.keycodes[KEY_3] = GLFW_KEY_3; + _glfw.mir.keycodes[KEY_4] = GLFW_KEY_4; + _glfw.mir.keycodes[KEY_5] = GLFW_KEY_5; + _glfw.mir.keycodes[KEY_6] = GLFW_KEY_6; + _glfw.mir.keycodes[KEY_7] = GLFW_KEY_7; + _glfw.mir.keycodes[KEY_8] = GLFW_KEY_8; + _glfw.mir.keycodes[KEY_9] = GLFW_KEY_9; + _glfw.mir.keycodes[KEY_0] = GLFW_KEY_0; + _glfw.mir.keycodes[KEY_SPACE] = GLFW_KEY_SPACE; + _glfw.mir.keycodes[KEY_MINUS] = GLFW_KEY_MINUS; + _glfw.mir.keycodes[KEY_EQUAL] = GLFW_KEY_EQUAL; + _glfw.mir.keycodes[KEY_Q] = GLFW_KEY_Q; + _glfw.mir.keycodes[KEY_W] = GLFW_KEY_W; + _glfw.mir.keycodes[KEY_E] = GLFW_KEY_E; + _glfw.mir.keycodes[KEY_R] = GLFW_KEY_R; + _glfw.mir.keycodes[KEY_T] = GLFW_KEY_T; + _glfw.mir.keycodes[KEY_Y] = GLFW_KEY_Y; + _glfw.mir.keycodes[KEY_U] = GLFW_KEY_U; + _glfw.mir.keycodes[KEY_I] = GLFW_KEY_I; + _glfw.mir.keycodes[KEY_O] = GLFW_KEY_O; + _glfw.mir.keycodes[KEY_P] = GLFW_KEY_P; + _glfw.mir.keycodes[KEY_LEFTBRACE] = GLFW_KEY_LEFT_BRACKET; + _glfw.mir.keycodes[KEY_RIGHTBRACE] = GLFW_KEY_RIGHT_BRACKET; + _glfw.mir.keycodes[KEY_A] = GLFW_KEY_A; + _glfw.mir.keycodes[KEY_S] = GLFW_KEY_S; + _glfw.mir.keycodes[KEY_D] = GLFW_KEY_D; + _glfw.mir.keycodes[KEY_F] = GLFW_KEY_F; + _glfw.mir.keycodes[KEY_G] = GLFW_KEY_G; + _glfw.mir.keycodes[KEY_H] = GLFW_KEY_H; + _glfw.mir.keycodes[KEY_J] = GLFW_KEY_J; + _glfw.mir.keycodes[KEY_K] = GLFW_KEY_K; + _glfw.mir.keycodes[KEY_L] = GLFW_KEY_L; + _glfw.mir.keycodes[KEY_SEMICOLON] = GLFW_KEY_SEMICOLON; + _glfw.mir.keycodes[KEY_APOSTROPHE] = GLFW_KEY_APOSTROPHE; + _glfw.mir.keycodes[KEY_Z] = GLFW_KEY_Z; + _glfw.mir.keycodes[KEY_X] = GLFW_KEY_X; + _glfw.mir.keycodes[KEY_C] = GLFW_KEY_C; + _glfw.mir.keycodes[KEY_V] = GLFW_KEY_V; + _glfw.mir.keycodes[KEY_B] = GLFW_KEY_B; + _glfw.mir.keycodes[KEY_N] = GLFW_KEY_N; + _glfw.mir.keycodes[KEY_M] = GLFW_KEY_M; + _glfw.mir.keycodes[KEY_COMMA] = GLFW_KEY_COMMA; + _glfw.mir.keycodes[KEY_DOT] = GLFW_KEY_PERIOD; + _glfw.mir.keycodes[KEY_SLASH] = GLFW_KEY_SLASH; + _glfw.mir.keycodes[KEY_BACKSLASH] = GLFW_KEY_BACKSLASH; + _glfw.mir.keycodes[KEY_ESC] = GLFW_KEY_ESCAPE; + _glfw.mir.keycodes[KEY_TAB] = GLFW_KEY_TAB; + _glfw.mir.keycodes[KEY_LEFTSHIFT] = GLFW_KEY_LEFT_SHIFT; + _glfw.mir.keycodes[KEY_RIGHTSHIFT] = GLFW_KEY_RIGHT_SHIFT; + _glfw.mir.keycodes[KEY_LEFTCTRL] = GLFW_KEY_LEFT_CONTROL; + _glfw.mir.keycodes[KEY_RIGHTCTRL] = GLFW_KEY_RIGHT_CONTROL; + _glfw.mir.keycodes[KEY_LEFTALT] = GLFW_KEY_LEFT_ALT; + _glfw.mir.keycodes[KEY_RIGHTALT] = GLFW_KEY_RIGHT_ALT; + _glfw.mir.keycodes[KEY_LEFTMETA] = GLFW_KEY_LEFT_SUPER; + _glfw.mir.keycodes[KEY_RIGHTMETA] = GLFW_KEY_RIGHT_SUPER; + _glfw.mir.keycodes[KEY_MENU] = GLFW_KEY_MENU; + _glfw.mir.keycodes[KEY_NUMLOCK] = GLFW_KEY_NUM_LOCK; + _glfw.mir.keycodes[KEY_CAPSLOCK] = GLFW_KEY_CAPS_LOCK; + _glfw.mir.keycodes[KEY_PRINT] = GLFW_KEY_PRINT_SCREEN; + _glfw.mir.keycodes[KEY_SCROLLLOCK] = GLFW_KEY_SCROLL_LOCK; + _glfw.mir.keycodes[KEY_PAUSE] = GLFW_KEY_PAUSE; + _glfw.mir.keycodes[KEY_DELETE] = GLFW_KEY_DELETE; + _glfw.mir.keycodes[KEY_BACKSPACE] = GLFW_KEY_BACKSPACE; + _glfw.mir.keycodes[KEY_ENTER] = GLFW_KEY_ENTER; + _glfw.mir.keycodes[KEY_HOME] = GLFW_KEY_HOME; + _glfw.mir.keycodes[KEY_END] = GLFW_KEY_END; + _glfw.mir.keycodes[KEY_PAGEUP] = GLFW_KEY_PAGE_UP; + _glfw.mir.keycodes[KEY_PAGEDOWN] = GLFW_KEY_PAGE_DOWN; + _glfw.mir.keycodes[KEY_INSERT] = GLFW_KEY_INSERT; + _glfw.mir.keycodes[KEY_LEFT] = GLFW_KEY_LEFT; + _glfw.mir.keycodes[KEY_RIGHT] = GLFW_KEY_RIGHT; + _glfw.mir.keycodes[KEY_DOWN] = GLFW_KEY_DOWN; + _glfw.mir.keycodes[KEY_UP] = GLFW_KEY_UP; + _glfw.mir.keycodes[KEY_F1] = GLFW_KEY_F1; + _glfw.mir.keycodes[KEY_F2] = GLFW_KEY_F2; + _glfw.mir.keycodes[KEY_F3] = GLFW_KEY_F3; + _glfw.mir.keycodes[KEY_F4] = GLFW_KEY_F4; + _glfw.mir.keycodes[KEY_F5] = GLFW_KEY_F5; + _glfw.mir.keycodes[KEY_F6] = GLFW_KEY_F6; + _glfw.mir.keycodes[KEY_F7] = GLFW_KEY_F7; + _glfw.mir.keycodes[KEY_F8] = GLFW_KEY_F8; + _glfw.mir.keycodes[KEY_F9] = GLFW_KEY_F9; + _glfw.mir.keycodes[KEY_F10] = GLFW_KEY_F10; + _glfw.mir.keycodes[KEY_F11] = GLFW_KEY_F11; + _glfw.mir.keycodes[KEY_F12] = GLFW_KEY_F12; + _glfw.mir.keycodes[KEY_F13] = GLFW_KEY_F13; + _glfw.mir.keycodes[KEY_F14] = GLFW_KEY_F14; + _glfw.mir.keycodes[KEY_F15] = GLFW_KEY_F15; + _glfw.mir.keycodes[KEY_F16] = GLFW_KEY_F16; + _glfw.mir.keycodes[KEY_F17] = GLFW_KEY_F17; + _glfw.mir.keycodes[KEY_F18] = GLFW_KEY_F18; + _glfw.mir.keycodes[KEY_F19] = GLFW_KEY_F19; + _glfw.mir.keycodes[KEY_F20] = GLFW_KEY_F20; + _glfw.mir.keycodes[KEY_F21] = GLFW_KEY_F21; + _glfw.mir.keycodes[KEY_F22] = GLFW_KEY_F22; + _glfw.mir.keycodes[KEY_F23] = GLFW_KEY_F23; + _glfw.mir.keycodes[KEY_F24] = GLFW_KEY_F24; + _glfw.mir.keycodes[KEY_KPSLASH] = GLFW_KEY_KP_DIVIDE; + _glfw.mir.keycodes[KEY_KPDOT] = GLFW_KEY_KP_MULTIPLY; + _glfw.mir.keycodes[KEY_KPMINUS] = GLFW_KEY_KP_SUBTRACT; + _glfw.mir.keycodes[KEY_KPPLUS] = GLFW_KEY_KP_ADD; + _glfw.mir.keycodes[KEY_KP0] = GLFW_KEY_KP_0; + _glfw.mir.keycodes[KEY_KP1] = GLFW_KEY_KP_1; + _glfw.mir.keycodes[KEY_KP2] = GLFW_KEY_KP_2; + _glfw.mir.keycodes[KEY_KP3] = GLFW_KEY_KP_3; + _glfw.mir.keycodes[KEY_KP4] = GLFW_KEY_KP_4; + _glfw.mir.keycodes[KEY_KP5] = GLFW_KEY_KP_5; + _glfw.mir.keycodes[KEY_KP6] = GLFW_KEY_KP_6; + _glfw.mir.keycodes[KEY_KP7] = GLFW_KEY_KP_7; + _glfw.mir.keycodes[KEY_KP8] = GLFW_KEY_KP_8; + _glfw.mir.keycodes[KEY_KP9] = GLFW_KEY_KP_9; + _glfw.mir.keycodes[KEY_KPCOMMA] = GLFW_KEY_KP_DECIMAL; + _glfw.mir.keycodes[KEY_KPEQUAL] = GLFW_KEY_KP_EQUAL; + _glfw.mir.keycodes[KEY_KPENTER] = GLFW_KEY_KP_ENTER; + + for (scancode = 0; scancode < 256; scancode++) + { + if (_glfw.mir.keycodes[scancode] > 0) + _glfw.mir.scancodes[_glfw.mir.keycodes[scancode]] = scancode; + } } @@ -180,21 +190,15 @@ int _glfwPlatformInit(void) createKeyTables(); - if (!_glfwInitThreadLocalStoragePOSIX()) - return GLFW_FALSE; - if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; _glfwInitTimerPOSIX(); - // Need the default conf for when we set a NULL cursor - _glfw.mir.default_conf = mir_cursor_configuration_from_name(mir_arrow_cursor_name); - - _glfw.mir.event_queue = calloc(1, sizeof(EventQueue)); - _glfwInitEventQueueMir(_glfw.mir.event_queue); + _glfw.mir.eventQueue = calloc(1, sizeof(EventQueue)); + _glfwInitEventQueueMir(_glfw.mir.eventQueue); - error = pthread_mutex_init(&_glfw.mir.event_mutex, NULL); + error = pthread_mutex_init(&_glfw.mir.eventMutex, NULL); if (error) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -203,6 +207,7 @@ int _glfwPlatformInit(void) return GLFW_FALSE; } + _glfwPollMonitorsMir(); return GLFW_TRUE; } @@ -210,11 +215,10 @@ void _glfwPlatformTerminate(void) { _glfwTerminateEGL(); _glfwTerminateJoysticksLinux(); - _glfwTerminateThreadLocalStoragePOSIX(); - _glfwDeleteEventQueueMir(_glfw.mir.event_queue); + _glfwDeleteEventQueueMir(_glfw.mir.eventQueue); - pthread_mutex_destroy(&_glfw.mir.event_mutex); + pthread_mutex_destroy(&_glfw.mir.eventMutex); mir_connection_release(_glfw.mir.connection); } @@ -227,9 +231,7 @@ const char* _glfwPlatformGetVersionString(void) #else " gettimeofday" #endif -#if defined(__linux__) - " /dev/js" -#endif + " evdev" #if defined(_GLFW_BUILD_DLL) " shared" #endif diff --git a/libs/glfw/src/mir_monitor.cc b/libs/glfw/src/mir_monitor.cc @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 Mir - www.glfw.org +// GLFW 3.3 Mir - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com> +// Copyright (c) 2014-2017 Brandon Schaefer <brandon.schaefer@canonical.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 @@ -30,53 +30,55 @@ ////////////////////////////////////////////////////////////////////////// -////// GLFW platform API ////// +////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// -_GLFWmonitor** _glfwPlatformGetMonitors(int* count) +// Poll for changes in the set of connected monitors +// +void _glfwPollMonitorsMir(void) { - int i, found = 0; - _GLFWmonitor** monitors = NULL; - MirDisplayConfiguration* displayConfig = - mir_connection_create_display_config(_glfw.mir.connection); + int i; + MirDisplayConfig* displayConfig = + mir_connection_create_display_configuration(_glfw.mir.connection); - *count = 0; + int numOutputs = mir_display_config_get_num_outputs(displayConfig); - for (i = 0; i < displayConfig->num_outputs; i++) + for (i = 0; i < numOutputs; i++) { - const MirDisplayOutput* out = displayConfig->outputs + i; + const MirOutput* output = mir_display_config_get_output(displayConfig, i); + MirOutputConnectionState state = mir_output_get_connection_state(output); + bool enabled = mir_output_is_enabled(output); - if (out->used && - out->connected && - out->num_modes && - out->current_mode < out->num_modes) + if (enabled && state == mir_output_connection_state_connected) { - found++; - monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found); - monitors[i] = _glfwAllocMonitor("Unknown", - out->physical_width_mm, - out->physical_height_mm); - - monitors[i]->mir.x = out->position_x; - monitors[i]->mir.y = out->position_y; - monitors[i]->mir.output_id = out->output_id; - monitors[i]->mir.cur_mode = out->current_mode; - - monitors[i]->modes = _glfwPlatformGetVideoModes(monitors[i], - &monitors[i]->modeCount); + int widthMM = mir_output_get_physical_width_mm(output); + int heightMM = mir_output_get_physical_height_mm(output); + int x = mir_output_get_position_x(output); + int y = mir_output_get_position_y(output); + int id = mir_output_get_id(output); + size_t currentMode = mir_output_get_current_mode_index(output); + const char* name = mir_output_type_name(mir_output_get_type(output)); + + _GLFWmonitor* monitor = _glfwAllocMonitor(name, + widthMM, + heightMM); + monitor->mir.x = x; + monitor->mir.y = y; + monitor->mir.outputId = id; + monitor->mir.curMode = currentMode; + monitor->modes = _glfwPlatformGetVideoModes(monitor, &monitor->modeCount); + + _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST); } } - mir_display_config_destroy(displayConfig); - - *count = found; - return monitors; + mir_display_config_release(displayConfig); } -GLFWbool _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) -{ - return first->mir.output_id == second->mir.output_id; -} + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { @@ -86,7 +88,7 @@ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) *ypos = monitor->mir.y; } -void FillInRGBBitsFromPixelFormat(GLFWvidmode* mode, const MirPixelFormat pf) +static void FillInRGBBitsFromPixelFormat(GLFWvidmode* mode, const MirPixelFormat pf) { switch (pf) { @@ -123,37 +125,59 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) { int i; GLFWvidmode* modes = NULL; - MirDisplayConfiguration* displayConfig = - mir_connection_create_display_config(_glfw.mir.connection); + MirDisplayConfig* displayConfig = + mir_connection_create_display_configuration(_glfw.mir.connection); + + int numOutputs = mir_display_config_get_num_outputs(displayConfig); - for (i = 0; i < displayConfig->num_outputs; i++) + for (i = 0; i < numOutputs; i++) { - const MirDisplayOutput* out = displayConfig->outputs + i; - if (out->output_id != monitor->mir.output_id) + const MirOutput* output = mir_display_config_get_output(displayConfig, i); + int id = mir_output_get_id(output); + + if (id != monitor->mir.outputId) continue; - modes = calloc(out->num_modes, sizeof(GLFWvidmode)); + MirOutputConnectionState state = mir_output_get_connection_state(output); + bool enabled = mir_output_is_enabled(output); - for (*found = 0; *found < out->num_modes; (*found)++) + // We must have been disconnected + if (!enabled || state != mir_output_connection_state_connected) { - modes[*found].width = out->modes[*found].horizontal_resolution; - modes[*found].height = out->modes[*found].vertical_resolution; - modes[*found].refreshRate = out->modes[*found].refresh_rate; + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Monitor no longer connected"); + return NULL; + } + + int numModes = mir_output_get_num_modes(output); + modes = calloc(numModes, sizeof(GLFWvidmode)); - FillInRGBBitsFromPixelFormat(&modes[*found], out->output_formats[*found]); + for (*found = 0; *found < numModes; (*found)++) + { + const MirOutputMode* mode = mir_output_get_mode(output, *found); + int width = mir_output_mode_get_width(mode); + int height = mir_output_mode_get_height(mode); + double refreshRate = mir_output_mode_get_refresh_rate(mode); + MirPixelFormat currentFormat = mir_output_get_current_pixel_format(output); + + modes[*found].width = width; + modes[*found].height = height; + modes[*found].refreshRate = refreshRate; + + FillInRGBBitsFromPixelFormat(&modes[*found], currentFormat); } break; } - mir_display_config_destroy(displayConfig); + mir_display_config_release(displayConfig); return modes; } void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) { - *mode = monitor->modes[monitor->mir.cur_mode]; + *mode = monitor->modes[monitor->mir.curMode]; } void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) @@ -177,6 +201,5 @@ GLFWAPI int glfwGetMirMonitor(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(0); - return monitor->mir.output_id; + return monitor->mir.outputId; } - diff --git a/libs/glfw/src/mir_platform.h b/libs/glfw/src/mir_platform.h @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 Mir - www.glfw.org +// GLFW 3.3 Mir - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com> +// Copyright (c) 2014-2017 Brandon Schaefer <brandon.schaefer@canonical.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 @@ -24,40 +24,38 @@ // //======================================================================== -#ifndef _glfw3_mir_platform_h_ -#define _glfw3_mir_platform_h_ - #include <sys/queue.h> #include <pthread.h> #include <dlfcn.h> #include <mir_toolkit/mir_client_library.h> -typedef VkFlags VkMirSurfaceCreateFlagsKHR; +typedef VkFlags VkMirWindowCreateFlagsKHR; -typedef struct VkMirSurfaceCreateInfoKHR +typedef struct VkMirWindowCreateInfoKHR { VkStructureType sType; const void* pNext; - VkMirSurfaceCreateFlagsKHR flags; + VkMirWindowCreateFlagsKHR flags; MirConnection* connection; - MirSurface* mirSurface; -} VkMirSurfaceCreateInfoKHR; + MirWindow* mirWindow; +} VkMirWindowCreateInfoKHR; -typedef VkResult (APIENTRY *PFN_vkCreateMirSurfaceKHR)(VkInstance,const VkMirSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); +typedef VkResult (APIENTRY *PFN_vkCreateMirWindowKHR)(VkInstance,const VkMirWindowCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)(VkPhysicalDevice,uint32_t,MirConnection*); -#include "posix_tls.h" +#include "posix_thread.h" #include "posix_time.h" #include "linux_joystick.h" #include "xkb_unicode.h" #include "egl_context.h" +#include "osmesa_context.h" #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) #define _glfw_dlclose(handle) dlclose(handle) #define _glfw_dlsym(handle, name) dlsym(handle, name) -#define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->mir.window) +#define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->mir.nativeWindow) #define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfw.mir.display) #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowMir mir @@ -80,10 +78,11 @@ typedef struct EventQueue // typedef struct _GLFWwindowMir { - MirSurface* surface; + MirWindow* window; int width; int height; - MirEGLNativeWindowType window; + MirEGLNativeWindowType nativeWindow; + _GLFWcursor* currentCursor; } _GLFWwindowMir; @@ -91,8 +90,8 @@ typedef struct _GLFWwindowMir // typedef struct _GLFWmonitorMir { - int cur_mode; - int output_id; + int curMode; + int outputId; int x; int y; @@ -104,13 +103,16 @@ typedef struct _GLFWlibraryMir { MirConnection* connection; MirEGLNativeDisplayType display; - MirCursorConfiguration* default_conf; - EventQueue* event_queue; + EventQueue* eventQueue; + + short int keycodes[256]; + short int scancodes[GLFW_KEY_LAST + 1]; - short int publicKeys[256]; + pthread_mutex_t eventMutex; + pthread_cond_t eventCond; - pthread_mutex_t event_mutex; - pthread_cond_t event_cond; + // The window whose disabled cursor mode is active + _GLFWwindow* disabledCursorWindow; } _GLFWlibraryMir; @@ -120,11 +122,12 @@ typedef struct _GLFWlibraryMir typedef struct _GLFWcursorMir { MirCursorConfiguration* conf; - MirBufferStream* custom_cursor; + MirBufferStream* customCursor; + char const* cursorName; // only needed for system cursors } _GLFWcursorMir; +extern void _glfwPollMonitorsMir(void); extern void _glfwInitEventQueueMir(EventQueue* queue); extern void _glfwDeleteEventQueueMir(EventQueue* queue); -#endif // _glfw3_mir_platform_h_ diff --git a/libs/glfw/src/mir_window.cc b/libs/glfw/src/mir_window.cc @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 Mir - www.glfw.org +// GLFW 3.3 Mir - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com> +// Copyright (c) 2014-2017 Brandon Schaefer <brandon.schaefer@canonical.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 @@ -54,44 +54,41 @@ static GLFWbool emptyEventQueue(EventQueue* queue) // for single threaded event handling. static EventNode* newEventNode(const MirEvent* event, _GLFWwindow* context) { - EventNode* new_node = calloc(1, sizeof(EventNode)); - new_node->event = mir_event_ref(event); - new_node->window = context; + EventNode* newNode = calloc(1, sizeof(EventNode)); + newNode->event = mir_event_ref(event); + newNode->window = context; - return new_node; + return newNode; } static void enqueueEvent(const MirEvent* event, _GLFWwindow* context) { - pthread_mutex_lock(&_glfw.mir.event_mutex); + pthread_mutex_lock(&_glfw.mir.eventMutex); - EventNode* new_node = newEventNode(event, context); - TAILQ_INSERT_TAIL(&_glfw.mir.event_queue->head, new_node, entries); + EventNode* newNode = newEventNode(event, context); + TAILQ_INSERT_TAIL(&_glfw.mir.eventQueue->head, newNode, entries); - pthread_cond_signal(&_glfw.mir.event_cond); + pthread_cond_signal(&_glfw.mir.eventCond); - pthread_mutex_unlock(&_glfw.mir.event_mutex); + pthread_mutex_unlock(&_glfw.mir.eventMutex); } static EventNode* dequeueEvent(EventQueue* queue) { EventNode* node = NULL; - pthread_mutex_lock(&_glfw.mir.event_mutex); + pthread_mutex_lock(&_glfw.mir.eventMutex); node = queue->head.tqh_first; if (node) TAILQ_REMOVE(&queue->head, node, entries); - pthread_mutex_unlock(&_glfw.mir.event_mutex); + pthread_mutex_unlock(&_glfw.mir.eventMutex); return node; } -/* FIXME Soon to be changed upstream mir! So we can use an egl config to figure out - the best pixel format! -*/ static MirPixelFormat findValidPixelFormat(void) { unsigned int i, validFormats, mirPixelFormats = 32; @@ -132,8 +129,8 @@ static int mirModToGLFWMod(uint32_t mods) static int toGLFWKeyCode(uint32_t key) { - if (key < sizeof(_glfw.mir.publicKeys) / sizeof(_glfw.mir.publicKeys[0])) - return _glfw.mir.publicKeys[key]; + if (key < sizeof(_glfw.mir.keycodes) / sizeof(_glfw.mir.keycodes[0])) + return _glfw.mir.keycodes[key]; return GLFW_KEY_UNKNOWN; } @@ -201,16 +198,31 @@ static void handlePointerButton(_GLFWwindow* window, static void handlePointerMotion(_GLFWwindow* window, const MirPointerEvent* pointer_event) { - int current_x = window->virtualCursorPosX; - int current_y = window->virtualCursorPosY; - int x = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_x); - int y = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_y); - int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_hscroll); - int dy = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_vscroll); + const int hscroll = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_hscroll); + const int vscroll = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_vscroll); - _glfwInputCursorPos(window, x, y); - if (dx != 0 || dy != 0) - _glfwInputScroll(window, dx, dy); + if (window->cursorMode == GLFW_CURSOR_DISABLED) + { + if (_glfw.mir.disabledCursorWindow != window) + return; + + const int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_x); + const int dy = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_y); + const int current_x = window->virtualCursorPosX; + const int current_y = window->virtualCursorPosY; + + _glfwInputCursorPos(window, dx + current_x, dy + current_y); + } + else + { + const int x = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_x); + const int y = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_y); + + _glfwInputCursorPos(window, x, y); + } + + if (hscroll != 0 || vscroll != 0) + _glfwInputScroll(window, hscroll, vscroll); } static void handlePointerEvent(const MirPointerEvent* pointer_event, @@ -234,7 +246,6 @@ static void handlePointerEvent(const MirPointerEvent* pointer_event, break; default: break; - } } @@ -269,14 +280,14 @@ static void handleEvent(const MirEvent* event, _GLFWwindow* window) } } -static void addNewEvent(MirSurface* surface, const MirEvent* event, void* context) +static void addNewEvent(MirWindow* window, const MirEvent* event, void* context) { enqueueEvent(event, context); } -static GLFWbool createSurface(_GLFWwindow* window) +static GLFWbool createWindow(_GLFWwindow* window) { - MirSurfaceSpec* spec; + MirWindowSpec* spec; MirBufferUsage buffer_usage = mir_buffer_usage_hardware; MirPixelFormat pixel_format = findValidPixelFormat(); @@ -286,32 +297,42 @@ static GLFWbool createSurface(_GLFWwindow* window) "Mir: Unable to find a correct pixel format"); return GLFW_FALSE; } - - spec = mir_connection_create_spec_for_normal_surface(_glfw.mir.connection, - window->mir.width, - window->mir.height, - pixel_format); - mir_surface_spec_set_buffer_usage(spec, buffer_usage); - mir_surface_spec_set_name(spec, "MirSurface"); + spec = mir_create_normal_window_spec(_glfw.mir.connection, + window->mir.width, + window->mir.height); - window->mir.surface = mir_surface_create_sync(spec); - mir_surface_spec_release(spec); + mir_window_spec_set_pixel_format(spec, pixel_format); + mir_window_spec_set_buffer_usage(spec, buffer_usage); - if (!mir_surface_is_valid(window->mir.surface)) + window->mir.window = mir_create_window_sync(spec); + mir_window_spec_release(spec); + + if (!mir_window_is_valid(window->mir.window)) { _glfwInputError(GLFW_PLATFORM_ERROR, - "Mir: Unable to create surface: %s", - mir_surface_get_error_message(window->mir.surface)); + "Mir: Unable to create window: %s", + mir_window_get_error_message(window->mir.window)); return GLFW_FALSE; } - mir_surface_set_event_handler(window->mir.surface, addNewEvent, window); + mir_window_set_event_handler(window->mir.window, addNewEvent, window); return GLFW_TRUE; } +static void setWindowConfinement(_GLFWwindow* window, MirPointerConfinementState state) +{ + MirWindowSpec* spec; + + spec = mir_create_window_spec(_glfw.mir.connection); + mir_window_spec_set_pointer_confinement(spec, state); + + mir_window_apply_spec(window->mir.window, spec); + mir_window_spec_release(spec); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// @@ -356,12 +377,12 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, GLFWvidmode mode; _glfwPlatformGetVideoMode(window->monitor, &mode); - mir_surface_set_state(window->mir.surface, mir_surface_state_fullscreen); + mir_window_set_state(window->mir.window, mir_window_state_fullscreen); if (wndconfig->width > mode.width || wndconfig->height > mode.height) { _glfwInputError(GLFW_PLATFORM_ERROR, - "Mir: Requested surface size too large: %ix%i", + "Mir: Requested window size too large: %ix%i", wndconfig->width, wndconfig->height); return GLFW_FALSE; @@ -370,19 +391,31 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, window->mir.width = wndconfig->width; window->mir.height = wndconfig->height; + window->mir.currentCursor = NULL; - if (!createSurface(window)) + if (!createWindow(window)) return GLFW_FALSE; - window->mir.window = mir_buffer_stream_get_egl_native_window( - mir_surface_get_buffer_stream(window->mir.surface)); + window->mir.nativeWindow = mir_buffer_stream_get_egl_native_window( + mir_window_get_buffer_stream(window->mir.window)); if (ctxconfig->client != GLFW_NO_API) { - if (!_glfwInitEGL()) - return GLFW_FALSE; - if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) - return GLFW_FALSE; + if (ctxconfig->source == GLFW_EGL_CONTEXT_API || + ctxconfig->source == GLFW_NATIVE_CONTEXT_API) + { + if (!_glfwInitEGL()) + return GLFW_FALSE; + if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) + return GLFW_FALSE; + } + else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API) + { + if (!_glfwInitOSMesa()) + return GLFW_FALSE; + if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) + return GLFW_FALSE; + } } return GLFW_TRUE; @@ -390,10 +423,13 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, void _glfwPlatformDestroyWindow(_GLFWwindow* window) { - if (mir_surface_is_valid(window->mir.surface)) + if (_glfw.mir.disabledCursorWindow == window) + _glfw.mir.disabledCursorWindow = NULL; + + if (mir_window_is_valid(window->mir.window)) { - mir_surface_release_sync(window->mir.surface); - window->mir.surface = NULL; + mir_window_release_sync(window->mir.window); + window->mir.window= NULL; } if (window->context.destroy) @@ -402,14 +438,12 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) { - MirSurfaceSpec* spec; - const char* e_title = title ? title : ""; - - spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); - mir_surface_spec_set_name(spec, e_title); + MirWindowSpec* spec; - mir_surface_apply_spec(window->mir.surface, spec); - mir_surface_spec_release(spec); + spec = mir_create_window_spec(_glfw.mir.connection); + mir_window_spec_set_name(spec, title); + mir_window_apply_spec(window->mir.window, spec); + mir_window_spec_release(spec); } void _glfwPlatformSetWindowIcon(_GLFWwindow* window, @@ -421,22 +455,30 @@ void _glfwPlatformSetWindowIcon(_GLFWwindow* window, void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { - MirSurfaceSpec* spec; + MirWindowSpec* spec; - spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); - mir_surface_spec_set_width (spec, width); - mir_surface_spec_set_height(spec, height); + spec = mir_create_window_spec(_glfw.mir.connection); + mir_window_spec_set_width (spec, width); + mir_window_spec_set_height(spec, height); - mir_surface_apply_spec(window->mir.surface, spec); - mir_surface_spec_release(spec); + mir_window_apply_spec(window->mir.window, spec); + mir_window_spec_release(spec); } void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Mir: Unsupported function %s", __PRETTY_FUNCTION__); + MirWindowSpec* spec; + + spec = mir_create_window_spec(_glfw.mir.connection); + mir_window_spec_set_max_width (spec, maxwidth); + mir_window_spec_set_max_height(spec, maxheight); + mir_window_spec_set_min_width (spec, minwidth); + mir_window_spec_set_min_height(spec, minheight); + + mir_window_apply_spec(window->mir.window, spec); + mir_window_spec_release(spec); } void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom) @@ -475,40 +517,63 @@ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) void _glfwPlatformIconifyWindow(_GLFWwindow* window) { - mir_surface_set_state(window->mir.surface, mir_surface_state_minimized); + MirWindowSpec* spec; + + spec = mir_create_window_spec(_glfw.mir.connection); + mir_window_spec_set_state(spec, mir_window_state_minimized); + + mir_window_apply_spec(window->mir.window, spec); + mir_window_spec_release(spec); } void _glfwPlatformRestoreWindow(_GLFWwindow* window) { - mir_surface_set_state(window->mir.surface, mir_surface_state_restored); + MirWindowSpec* spec; + + spec = mir_create_window_spec(_glfw.mir.connection); + mir_window_spec_set_state(spec, mir_window_state_restored); + + mir_window_apply_spec(window->mir.window, spec); + mir_window_spec_release(spec); } void _glfwPlatformMaximizeWindow(_GLFWwindow* window) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Mir: Unsupported function %s", __PRETTY_FUNCTION__); + MirWindowSpec* spec; + + spec = mir_create_window_spec(_glfw.mir.connection); + mir_window_spec_set_state(spec, mir_window_state_maximized); + + mir_window_apply_spec(window->mir.window, spec); + mir_window_spec_release(spec); } void _glfwPlatformHideWindow(_GLFWwindow* window) { - MirSurfaceSpec* spec; + MirWindowSpec* spec; - spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); - mir_surface_spec_set_state(spec, mir_surface_state_hidden); + spec = mir_create_window_spec(_glfw.mir.connection); + mir_window_spec_set_state(spec, mir_window_state_hidden); - mir_surface_apply_spec(window->mir.surface, spec); - mir_surface_spec_release(spec); + mir_window_apply_spec(window->mir.window, spec); + mir_window_spec_release(spec); } void _glfwPlatformShowWindow(_GLFWwindow* window) { - MirSurfaceSpec* spec; + MirWindowSpec* spec; - spec = mir_connection_create_spec_for_changes(_glfw.mir.connection); - mir_surface_spec_set_state(spec, mir_surface_state_restored); + spec = mir_create_window_spec(_glfw.mir.connection); + mir_window_spec_set_state(spec, mir_window_state_restored); - mir_surface_apply_spec(window->mir.surface, spec); - mir_surface_spec_release(spec); + mir_window_apply_spec(window->mir.window, spec); + mir_window_spec_release(spec); +} + +void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) +{ + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unsupported function %s", __PRETTY_FUNCTION__); } void _glfwPlatformFocusWindow(_GLFWwindow* window) @@ -529,9 +594,7 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, int _glfwPlatformWindowFocused(_GLFWwindow* window) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Mir: Unsupported function %s", __PRETTY_FUNCTION__); - return GLFW_FALSE; + return mir_window_get_focus_state(window->mir.window) == mir_window_focus_state_focused; } int _glfwPlatformWindowIconified(_GLFWwindow* window) @@ -543,53 +606,69 @@ int _glfwPlatformWindowIconified(_GLFWwindow* window) int _glfwPlatformWindowVisible(_GLFWwindow* window) { - return mir_surface_get_visibility(window->mir.surface) == mir_surface_visibility_exposed; + return mir_window_get_visibility(window->mir.window) == mir_window_visibility_exposed; } int _glfwPlatformWindowMaximized(_GLFWwindow* window) { + return mir_window_get_state(window->mir.window) == mir_window_state_maximized; +} + +void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled) +{ + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unsupported function %s", __PRETTY_FUNCTION__); +} + +void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled) +{ + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unsupported function %s", __PRETTY_FUNCTION__); +} + +void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled) +{ _glfwInputError(GLFW_PLATFORM_ERROR, "Mir: Unsupported function %s", __PRETTY_FUNCTION__); - return GLFW_FALSE; } void _glfwPlatformPollEvents(void) { EventNode* node = NULL; - while ((node = dequeueEvent(_glfw.mir.event_queue))) + while ((node = dequeueEvent(_glfw.mir.eventQueue))) { handleEvent(node->event, node->window); - deleteNode(_glfw.mir.event_queue, node); + deleteNode(_glfw.mir.eventQueue, node); } } void _glfwPlatformWaitEvents(void) { - pthread_mutex_lock(&_glfw.mir.event_mutex); + pthread_mutex_lock(&_glfw.mir.eventMutex); - if (emptyEventQueue(_glfw.mir.event_queue)) - pthread_cond_wait(&_glfw.mir.event_cond, &_glfw.mir.event_mutex); + while (emptyEventQueue(_glfw.mir.eventQueue)) + pthread_cond_wait(&_glfw.mir.eventCond, &_glfw.mir.eventMutex); - pthread_mutex_unlock(&_glfw.mir.event_mutex); + pthread_mutex_unlock(&_glfw.mir.eventMutex); _glfwPlatformPollEvents(); } void _glfwPlatformWaitEventsTimeout(double timeout) { - pthread_mutex_lock(&_glfw.mir.event_mutex); + pthread_mutex_lock(&_glfw.mir.eventMutex); - if (emptyEventQueue(_glfw.mir.event_queue)) + if (emptyEventQueue(_glfw.mir.eventQueue)) { struct timespec time; clock_gettime(CLOCK_REALTIME, &time); time.tv_sec += (long) timeout; time.tv_nsec += (long) ((timeout - (long) timeout) * 1e9); - pthread_cond_timedwait(&_glfw.mir.event_cond, &_glfw.mir.event_mutex, &time); + pthread_cond_timedwait(&_glfw.mir.eventCond, &_glfw.mir.eventMutex, &time); } - pthread_mutex_unlock(&_glfw.mir.event_mutex); + pthread_mutex_unlock(&_glfw.mir.eventMutex); _glfwPlatformPollEvents(); } @@ -606,60 +685,45 @@ void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* heigh *height = window->mir.height; } -// FIXME implement int _glfwPlatformCreateCursor(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot) { MirBufferStream* stream; - MirPixelFormat pixel_format = findValidPixelFormat(); int i_w = image->width; int i_h = image->height; - if (pixel_format == mir_pixel_format_invalid) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Mir: Unable to find a correct pixel format"); - return GLFW_FALSE; - } - stream = mir_connection_create_buffer_stream_sync(_glfw.mir.connection, i_w, i_h, - pixel_format, + mir_pixel_format_argb_8888, mir_buffer_usage_software); cursor->mir.conf = mir_cursor_configuration_from_buffer_stream(stream, xhot, yhot); - char* dest; - unsigned char *pixels; - int i, r_stride, bytes_per_pixel, bytes_per_row; - MirGraphicsRegion region; mir_buffer_stream_get_graphics_region(stream, &region); - // FIXME Figure this out based on the current_pf - bytes_per_pixel = 4; - bytes_per_row = bytes_per_pixel * i_w; - - dest = region.vaddr; - pixels = image->pixels; - - r_stride = region.stride; + unsigned char* pixels = image->pixels; + char* dest = region.vaddr; + int i; - for (i = 0; i < i_h; i++) + for (i = 0; i < i_w * i_h; i++, pixels += 4) { - memcpy(dest, pixels, bytes_per_row); - dest += r_stride; - pixels += r_stride; + unsigned int alpha = pixels[3]; + *dest++ = (char)(pixels[2] * alpha / 255); + *dest++ = (char)(pixels[1] * alpha / 255); + *dest++ = (char)(pixels[0] * alpha / 255); + *dest++ = (char)alpha; } - cursor->mir.custom_cursor = stream; + mir_buffer_stream_swap_buffers_sync(stream); + cursor->mir.customCursor = stream; return GLFW_TRUE; } -const char* getSystemCursorName(int shape) +static const char* getSystemCursorName(int shape) { switch (shape) { @@ -682,40 +746,47 @@ const char* getSystemCursorName(int shape) int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape) { - const char* cursor_name = getSystemCursorName(shape); + cursor->mir.conf = NULL; + cursor->mir.customCursor = NULL; + cursor->mir.cursorName = getSystemCursorName(shape); - if (cursor_name) - { - cursor->mir.conf = mir_cursor_configuration_from_name(cursor_name); - cursor->mir.custom_cursor = NULL; - - return GLFW_TRUE; - } - - return GLFW_FALSE; + return cursor->mir.cursorName != NULL; } void _glfwPlatformDestroyCursor(_GLFWcursor* cursor) { if (cursor->mir.conf) mir_cursor_configuration_destroy(cursor->mir.conf); - if (cursor->mir.custom_cursor) - mir_buffer_stream_release_sync(cursor->mir.custom_cursor); + if (cursor->mir.customCursor) + mir_buffer_stream_release_sync(cursor->mir.customCursor); +} + +static void setCursorNameForWindow(MirWindow* window, char const* name) +{ + MirWindowSpec* spec = mir_create_window_spec(_glfw.mir.connection); + mir_window_spec_set_cursor_name(spec, name); + mir_window_apply_spec(window, spec); + mir_window_spec_release(spec); } void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) { - if (cursor && cursor->mir.conf) + if (cursor) { - mir_wait_for(mir_surface_configure_cursor(window->mir.surface, cursor->mir.conf)); - if (cursor->mir.custom_cursor) + window->mir.currentCursor = cursor; + + if (cursor->mir.cursorName) { - mir_buffer_stream_swap_buffers_sync(cursor->mir.custom_cursor); + setCursorNameForWindow(window->mir.window, cursor->mir.cursorName); + } + else if (cursor->mir.conf) + { + mir_window_configure_cursor(window->mir.window, cursor->mir.conf); } } else { - mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.default_conf)); + setCursorNameForWindow(window->mir.window, mir_default_cursor_name); } } @@ -733,17 +804,44 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos) void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Mir: Unsupported function %s", __PRETTY_FUNCTION__); + if (mode == GLFW_CURSOR_DISABLED) + { + _glfw.mir.disabledCursorWindow = window; + setWindowConfinement(window, mir_pointer_confined_to_window); + setCursorNameForWindow(window->mir.window, mir_disabled_cursor_name); + } + else + { + // If we were disabled before lets undo that! + if (_glfw.mir.disabledCursorWindow == window) + { + _glfw.mir.disabledCursorWindow = NULL; + setWindowConfinement(window, mir_pointer_unconfined); + } + + if (window->cursorMode == GLFW_CURSOR_NORMAL) + { + _glfwPlatformSetCursor(window, window->mir.currentCursor); + } + else if (window->cursorMode == GLFW_CURSOR_HIDDEN) + { + setCursorNameForWindow(window->mir.window, mir_disabled_cursor_name); + } + } } -const char* _glfwPlatformGetKeyName(int key, int scancode) +const char* _glfwPlatformGetScancodeName(int scancode) { _glfwInputError(GLFW_PLATFORM_ERROR, "Mir: Unsupported function %s", __PRETTY_FUNCTION__); return NULL; } +int _glfwPlatformGetKeyScancode(int key) +{ + return _glfw.mir.scancodes[key]; +} + void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -758,21 +856,13 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) return NULL; } -char** _glfwPlatformGetRequiredInstanceExtensions(uint32_t* count) +void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) { - char** extensions; - - *count = 0; - - if (!_glfw.vk.KHR_mir_surface) - return NULL; - - extensions = calloc(2, sizeof(char*)); - extensions[0] = strdup("VK_KHR_surface"); - extensions[1] = strdup("VK_KHR_mir_surface"); + if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_mir_surface) + return; - *count = 2; - return extensions; + extensions[0] = "VK_KHR_surface"; + extensions[1] = "VK_KHR_mir_surface"; } int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, @@ -800,12 +890,12 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, VkSurfaceKHR* surface) { VkResult err; - VkMirSurfaceCreateInfoKHR sci; - PFN_vkCreateMirSurfaceKHR vkCreateMirSurfaceKHR; + VkMirWindowCreateInfoKHR sci; + PFN_vkCreateMirWindowKHR vkCreateMirWindowKHR; - vkCreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR) - vkGetInstanceProcAddr(instance, "vkCreateMirSurfaceKHR"); - if (!vkCreateMirSurfaceKHR) + vkCreateMirWindowKHR = (PFN_vkCreateMirWindowKHR) + vkGetInstanceProcAddr(instance, "vkCreateMirWindowKHR"); + if (!vkCreateMirWindowKHR) { _glfwInputError(GLFW_API_UNAVAILABLE, "Mir: Vulkan instance missing VK_KHR_mir_surface extension"); @@ -815,9 +905,9 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, memset(&sci, 0, sizeof(sci)); sci.sType = VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR; sci.connection = _glfw.mir.connection; - sci.mirSurface = window->mir.surface; + sci.mirWindow = window->mir.window; - err = vkCreateMirSurfaceKHR(instance, &sci, allocator, surface); + err = vkCreateMirWindowKHR(instance, &sci, allocator, surface); if (err) { _glfwInputError(GLFW_PLATFORM_ERROR, @@ -839,10 +929,10 @@ GLFWAPI MirConnection* glfwGetMirDisplay(void) return _glfw.mir.connection; } -GLFWAPI MirSurface* glfwGetMirWindow(GLFWwindow* handle) +GLFWAPI MirWindow* glfwGetMirWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - return window->mir.surface; + return window->mir.window; } diff --git a/libs/glfw/src/monitor.cc b/libs/glfw/src/monitor.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 - www.glfw.org +// GLFW 3.3 - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -86,83 +86,49 @@ static GLFWbool refreshVideoModes(_GLFWmonitor* monitor) ////// GLFW event API ////// ////////////////////////////////////////////////////////////////////////// -void _glfwInputMonitorChange(void) +void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement) { - int i, j, monitorCount = _glfw.monitorCount; - _GLFWmonitor** monitors = _glfw.monitors; - - _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount); - - // Re-use still connected monitor objects - - for (i = 0; i < _glfw.monitorCount; i++) - { - for (j = 0; j < monitorCount; j++) - { - if (_glfwPlatformIsSameMonitor(_glfw.monitors[i], monitors[j])) - { - _glfwFreeMonitor(_glfw.monitors[i]); - _glfw.monitors[i] = monitors[j]; - break; - } - } - } - - // Find and report disconnected monitors (not in the new list) - - for (i = 0; i < monitorCount; i++) + if (action == GLFW_CONNECTED) { - _GLFWwindow* window; + _glfw.monitorCount++; + _glfw.monitors = + realloc(_glfw.monitors, sizeof(_GLFWmonitor*) * _glfw.monitorCount); - for (j = 0; j < _glfw.monitorCount; j++) + if (placement == _GLFW_INSERT_FIRST) { - if (monitors[i] == _glfw.monitors[j]) - break; + memmove(_glfw.monitors + 1, + _glfw.monitors, + (_glfw.monitorCount - 1) * sizeof(_GLFWmonitor*)); + _glfw.monitors[0] = monitor; } - - if (j < _glfw.monitorCount) - continue; - - for (window = _glfw.windowListHead; window; window = window->next) - { - if (window->monitor == monitors[i]) - { - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - _glfwPlatformSetWindowMonitor(window, NULL, 0, 0, width, height, 0); - } - } - - if (_glfw.callbacks.monitor) - _glfw.callbacks.monitor((GLFWmonitor*) monitors[i], GLFW_DISCONNECTED); + else + _glfw.monitors[_glfw.monitorCount - 1] = monitor; } - - // Find and report newly connected monitors (not in the old list) - // Re-used monitor objects are then removed from the old list to avoid - // having them destroyed at the end of this function - - for (i = 0; i < _glfw.monitorCount; i++) + else if (action == GLFW_DISCONNECTED) { - for (j = 0; j < monitorCount; j++) + int i; + + for (i = 0; i < _glfw.monitorCount; i++) { - if (_glfw.monitors[i] == monitors[j]) + if (_glfw.monitors[i] == monitor) { - monitors[j] = NULL; + _glfw.monitorCount--; + memmove(_glfw.monitors + i, + _glfw.monitors + i + 1, + (_glfw.monitorCount - i) * sizeof(_GLFWmonitor*)); break; } } - - if (j < monitorCount) - continue; - - if (_glfw.callbacks.monitor) - _glfw.callbacks.monitor((GLFWmonitor*) _glfw.monitors[i], GLFW_CONNECTED); } - _glfwFreeMonitors(monitors, monitorCount); + if (_glfw.callbacks.monitor) + _glfw.callbacks.monitor((GLFWmonitor*) monitor, action); + + if (action == GLFW_DISCONNECTED) + _glfwFreeMonitor(monitor); } -void _glfwInputMonitorWindowChange(_GLFWmonitor* monitor, _GLFWwindow* window) +void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window) { monitor->window = window; } @@ -175,10 +141,12 @@ void _glfwInputMonitorWindowChange(_GLFWmonitor* monitor, _GLFWwindow* window) _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM) { _GLFWmonitor* monitor = calloc(1, sizeof(_GLFWmonitor)); - monitor->name = strdup(name); monitor->widthMM = widthMM; monitor->heightMM = heightMM; + if (name) + monitor->name = strdup(name); + return monitor; } @@ -212,16 +180,6 @@ void _glfwFreeGammaArrays(GLFWgammaramp* ramp) memset(ramp, 0, sizeof(GLFWgammaramp)); } -void _glfwFreeMonitors(_GLFWmonitor** monitors, int count) -{ - int i; - - for (i = 0; i < count; i++) - _glfwFreeMonitor(monitors[i]); - - free(monitors); -} - const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired) { @@ -304,6 +262,7 @@ void _glfwSplitBPP(int bpp, int* red, int* green, int* blue) GLFWAPI GLFWmonitor** glfwGetMonitors(int* count) { assert(count != NULL); + *count = 0; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -404,6 +363,10 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma) int i; unsigned short values[256]; GLFWgammaramp ramp; + assert(handle != NULL); + assert(gamma == gamma); + assert(gamma >= 0.f); + assert(gamma <= FLT_MAX); _GLFW_REQUIRE_INIT(); @@ -455,6 +418,7 @@ GLFWAPI void glfwSetGammaRamp(GLFWmonitor* handle, const GLFWgammaramp* ramp) _GLFWmonitor* monitor = (_GLFWmonitor*) handle; assert(monitor != NULL); assert(ramp != NULL); + assert(ramp->size > 0); assert(ramp->red != NULL); assert(ramp->green != NULL); assert(ramp->blue != NULL); diff --git a/libs/glfw/src/nsgl_context.h b/libs/glfw/src/nsgl_context.h @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 OS X - www.glfw.org +// GLFW 3.3 macOS - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2009-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2009-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -24,9 +24,6 @@ // //======================================================================== -#ifndef _glfw3_nsgl_context_h_ -#define _glfw3_nsgl_context_h_ - #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl @@ -57,4 +54,3 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, const _GLFWfbconfig* fbconfig); void _glfwDestroyContextNSGL(_GLFWwindow* window); -#endif // _glfw3_nsgl_context_h_ diff --git a/libs/glfw/src/nsgl_context.m b/libs/glfw/src/nsgl_context.m @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 OS X - www.glfw.org +// GLFW 3.3 macOS - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2009-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2009-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -34,7 +34,7 @@ static void makeContextCurrentNSGL(_GLFWwindow* window) else [NSOpenGLContext clearCurrentContext]; - _glfwPlatformSetCurrentContext(window); + _glfwPlatformSetTls(&_glfw.contextSlot, window); } static void swapBuffersNSGL(_GLFWwindow* window) @@ -45,7 +45,7 @@ static void swapBuffersNSGL(_GLFWwindow* window) static void swapIntervalNSGL(int interval) { - _GLFWwindow* window = _glfwPlatformGetCurrentContext(); + _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); GLint sync = interval; [window->context.nsgl.object setValues:&sync @@ -119,70 +119,83 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig) { - unsigned int attributeCount = 0; - if (ctxconfig->client == GLFW_OPENGL_ES_API) { _glfwInputError(GLFW_API_UNAVAILABLE, - "NSGL: OpenGL ES is not available on OS X"); - return GLFW_FALSE; - } - - if (ctxconfig->major == 3 && ctxconfig->minor < 2) - { - _glfwInputError(GLFW_VERSION_UNAVAILABLE, - "NSGL: The targeted version of OS X does not support OpenGL 3.0 or 3.1"); + "NSGL: OpenGL ES is not available on macOS"); return GLFW_FALSE; } if (ctxconfig->major > 2) { - if (!ctxconfig->forward) + if (ctxconfig->major == 3 && ctxconfig->minor < 2) { _glfwInputError(GLFW_VERSION_UNAVAILABLE, - "NSGL: The targeted version of OS X only supports forward-compatible contexts for OpenGL 3.2 and above"); + "NSGL: The targeted version of macOS does not support OpenGL 3.0 or 3.1 but may support 3.2 and above"); return GLFW_FALSE; } - if (ctxconfig->profile != GLFW_OPENGL_CORE_PROFILE) + if (!ctxconfig->forward || ctxconfig->profile != GLFW_OPENGL_CORE_PROFILE) { _glfwInputError(GLFW_VERSION_UNAVAILABLE, - "NSGL: The targeted version of OS X only supports core profile contexts for OpenGL 3.2 and above"); + "NSGL: The targeted version of macOS only supports forward-compatible core profile contexts for OpenGL 3.2 and above"); return GLFW_FALSE; } } - // Context robustness modes (GL_KHR_robustness) are not yet supported on - // OS X but are not a hard constraint, so ignore and continue + // Context robustness modes (GL_KHR_robustness) are not yet supported by + // macOS but are not a hard constraint, so ignore and continue // Context release behaviors (GL_KHR_context_flush_control) are not yet - // supported on OS X but are not a hard constraint, so ignore and continue + // supported by macOS but are not a hard constraint, so ignore and continue + + // Debug contexts (GL_KHR_debug) are not yet supported by macOS but are not + // a hard constraint, so ignore and continue -#define ADD_ATTR(x) { attributes[attributeCount++] = x; } -#define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); } + // No-error contexts (GL_KHR_no_error) are not yet supported by macOS but + // are not a hard constraint, so ignore and continue + +#define addAttrib(a) \ +{ \ + assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \ + attribs[index++] = a; \ +} +#define setAttrib(a, v) { addAttrib(a); addAttrib(v); } - // Arbitrary array size here - NSOpenGLPixelFormatAttribute attributes[40]; + NSOpenGLPixelFormatAttribute attribs[40]; + int index = 0; - ADD_ATTR(NSOpenGLPFAAccelerated); - ADD_ATTR(NSOpenGLPFAClosestPolicy); + addAttrib(NSOpenGLPFAAccelerated); + addAttrib(NSOpenGLPFAClosestPolicy); + + if (ctxconfig->nsgl.offline) + { + addAttrib(NSOpenGLPFAAllowOfflineRenderers); + // NOTE: This replaces the NSSupportsAutomaticGraphicsSwitching key in + // Info.plist for unbundled applications + // HACK: This assumes that NSOpenGLPixelFormat will remain + // a straightforward wrapper of its CGL counterpart +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 100800 + addAttrib(kCGLPFASupportsAutomaticGraphicsSwitching); +#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ + } #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 if (ctxconfig->major >= 4) { - ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core); + setAttrib(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core); } else #endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ if (ctxconfig->major >= 3) { - ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core); + setAttrib(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core); } if (ctxconfig->major <= 2) { if (fbconfig->auxBuffers != GLFW_DONT_CARE) - ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers); + setAttrib(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers); if (fbconfig->accumRedBits != GLFW_DONT_CARE && fbconfig->accumGreenBits != GLFW_DONT_CARE && @@ -194,7 +207,7 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, fbconfig->accumBlueBits + fbconfig->accumAlphaBits; - ADD_ATTR2(NSOpenGLPFAAccumSize, accumBits); + setAttrib(NSOpenGLPFAAccumSize, accumBits); } } @@ -206,53 +219,61 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, fbconfig->greenBits + fbconfig->blueBits; - // OS X needs non-zero color size, so set reasonable values + // macOS needs non-zero color size, so set reasonable values if (colorBits == 0) colorBits = 24; else if (colorBits < 15) colorBits = 15; - ADD_ATTR2(NSOpenGLPFAColorSize, colorBits); + setAttrib(NSOpenGLPFAColorSize, colorBits); } if (fbconfig->alphaBits != GLFW_DONT_CARE) - ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits); + setAttrib(NSOpenGLPFAAlphaSize, fbconfig->alphaBits); if (fbconfig->depthBits != GLFW_DONT_CARE) - ADD_ATTR2(NSOpenGLPFADepthSize, fbconfig->depthBits); + setAttrib(NSOpenGLPFADepthSize, fbconfig->depthBits); if (fbconfig->stencilBits != GLFW_DONT_CARE) - ADD_ATTR2(NSOpenGLPFAStencilSize, fbconfig->stencilBits); + setAttrib(NSOpenGLPFAStencilSize, fbconfig->stencilBits); if (fbconfig->stereo) - ADD_ATTR(NSOpenGLPFAStereo); + { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 + _glfwInputError(GLFW_FORMAT_UNAVAILABLE, + "NSGL: Stereo rendering is deprecated"); + return GLFW_FALSE; +#else + addAttrib(NSOpenGLPFAStereo); +#endif + } if (fbconfig->doublebuffer) - ADD_ATTR(NSOpenGLPFADoubleBuffer); + addAttrib(NSOpenGLPFADoubleBuffer); if (fbconfig->samples != GLFW_DONT_CARE) { if (fbconfig->samples == 0) { - ADD_ATTR2(NSOpenGLPFASampleBuffers, 0); + setAttrib(NSOpenGLPFASampleBuffers, 0); } else { - ADD_ATTR2(NSOpenGLPFASampleBuffers, 1); - ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples); + setAttrib(NSOpenGLPFASampleBuffers, 1); + setAttrib(NSOpenGLPFASamples, fbconfig->samples); } } // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB // framebuffer, so there's no need (and no way) to request it - ADD_ATTR(0); + addAttrib(0); -#undef ADD_ATTR -#undef ADD_ATTR2 +#undef addAttrib +#undef setAttrib window->context.nsgl.pixelFormat = - [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; + [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; if (window->context.nsgl.pixelFormat == nil) { _glfwInputError(GLFW_FORMAT_UNAVAILABLE, diff --git a/libs/glfw/src/osmesa_context.cc b/libs/glfw/src/osmesa_context.cc @@ -0,0 +1,368 @@ +//======================================================================== +// GLFW 3.3 OSMesa - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2016 Google Inc. +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include "internal.h" + + +static void makeContextCurrentOSMesa(_GLFWwindow* window) +{ + if (window) + { + int width, height; + _glfwPlatformGetFramebufferSize(window, &width, &height); + + // Check to see if we need to allocate a new buffer + if ((window->context.osmesa.buffer == NULL) || + (width != window->context.osmesa.width) || + (height != window->context.osmesa.height)) + { + free(window->context.osmesa.buffer); + + // Allocate the new buffer (width * height * 8-bit RGBA) + window->context.osmesa.buffer = calloc(4, width * height); + window->context.osmesa.width = width; + window->context.osmesa.height = height; + } + + if (!OSMesaMakeCurrent(window->context.osmesa.handle, + window->context.osmesa.buffer, + GL_UNSIGNED_BYTE, + width, height)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "OSMesa: Failed to make context current"); + return; + } + } + + _glfwPlatformSetTls(&_glfw.contextSlot, window); +} + +static GLFWglproc getProcAddressOSMesa(const char* procname) +{ + return (GLFWglproc) OSMesaGetProcAddress(procname); +} + +static void destroyContextOSMesa(_GLFWwindow* window) +{ + if (window->context.osmesa.handle) + { + OSMesaDestroyContext(window->context.osmesa.handle); + window->context.osmesa.handle = NULL; + } + + if (window->context.osmesa.buffer) + { + free(window->context.osmesa.buffer); + window->context.osmesa.width = 0; + window->context.osmesa.height = 0; + } +} + +static void swapBuffersOSMesa(_GLFWwindow* window) +{ + // No double buffering on OSMesa +} + +static void swapIntervalOSMesa(int interval) +{ + // No swap interval on OSMesa +} + +static int extensionSupportedOSMesa(const char* extension) +{ + // OSMesa does not have extensions + return GLFW_FALSE; +} + + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +GLFWbool _glfwInitOSMesa(void) +{ + int i; + const char* sonames[] = + { +#if defined(_WIN32) + "libOSMesa.dll", + "OSMesa.dll", +#elif defined(__APPLE__) + "libOSMesa.8.dylib", +#elif defined(__CYGWIN__) + "libOSMesa-8.so", +#else + "libOSMesa.so.8", + "libOSMesa.so.6", +#endif + NULL + }; + + if (_glfw.osmesa.handle) + return GLFW_TRUE; + + for (i = 0; sonames[i]; i++) + { + _glfw.osmesa.handle = _glfw_dlopen(sonames[i]); + if (_glfw.osmesa.handle) + break; + } + + if (!_glfw.osmesa.handle) + { + _glfwInputError(GLFW_API_UNAVAILABLE, "OSMesa: Library not found"); + return GLFW_FALSE; + } + + _glfw.osmesa.CreateContextExt = (PFN_OSMesaCreateContextExt) + _glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextExt"); + _glfw.osmesa.CreateContextAttribs = (PFN_OSMesaCreateContextAttribs) + _glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextAttribs"); + _glfw.osmesa.DestroyContext = (PFN_OSMesaDestroyContext) + _glfw_dlsym(_glfw.osmesa.handle, "OSMesaDestroyContext"); + _glfw.osmesa.MakeCurrent = (PFN_OSMesaMakeCurrent) + _glfw_dlsym(_glfw.osmesa.handle, "OSMesaMakeCurrent"); + _glfw.osmesa.GetColorBuffer = (PFN_OSMesaGetColorBuffer) + _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetColorBuffer"); + _glfw.osmesa.GetDepthBuffer = (PFN_OSMesaGetDepthBuffer) + _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetDepthBuffer"); + _glfw.osmesa.GetProcAddress = (PFN_OSMesaGetProcAddress) + _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetProcAddress"); + + if (!_glfw.osmesa.CreateContextExt || + !_glfw.osmesa.DestroyContext || + !_glfw.osmesa.MakeCurrent || + !_glfw.osmesa.GetColorBuffer || + !_glfw.osmesa.GetDepthBuffer || + !_glfw.osmesa.GetProcAddress) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "OSMesa: Failed to load required entry points"); + + _glfwTerminateOSMesa(); + return GLFW_FALSE; + } + + return GLFW_TRUE; +} + +void _glfwTerminateOSMesa(void) +{ + if (_glfw.osmesa.handle) + { + _glfw_dlclose(_glfw.osmesa.handle); + _glfw.osmesa.handle = NULL; + } +} + +#define setAttrib(a, v) \ +{ \ + assert((size_t) (index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ + attribs[index++] = a; \ + attribs[index++] = v; \ +} + +GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, + const _GLFWctxconfig* ctxconfig, + const _GLFWfbconfig* fbconfig) +{ + OSMesaContext share = NULL; + const int accumBits = fbconfig->accumRedBits + + fbconfig->accumGreenBits + + fbconfig->accumBlueBits + + fbconfig->accumAlphaBits; + + if (ctxconfig->client == GLFW_OPENGL_ES_API) + { + _glfwInputError(GLFW_API_UNAVAILABLE, + "OSMesa: OpenGL ES is not available on OSMesa"); + return GLFW_FALSE; + } + + if (ctxconfig->share) + share = ctxconfig->share->context.osmesa.handle; + + if (OSMesaCreateContextAttribs) + { + int index = 0, attribs[40]; + + setAttrib(OSMESA_FORMAT, OSMESA_RGBA); + setAttrib(OSMESA_DEPTH_BITS, fbconfig->depthBits); + setAttrib(OSMESA_STENCIL_BITS, fbconfig->stencilBits); + setAttrib(OSMESA_ACCUM_BITS, accumBits); + + if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE) + { + setAttrib(OSMESA_PROFILE, OSMESA_CORE_PROFILE); + } + else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) + { + setAttrib(OSMESA_PROFILE, OSMESA_COMPAT_PROFILE); + } + + if (ctxconfig->major != 1 || ctxconfig->minor != 0) + { + setAttrib(OSMESA_CONTEXT_MAJOR_VERSION, ctxconfig->major); + setAttrib(OSMESA_CONTEXT_MINOR_VERSION, ctxconfig->minor); + } + + if (ctxconfig->forward) + { + _glfwInputError(GLFW_VERSION_UNAVAILABLE, + "OSMesa: Foward-compatible contexts not supported"); + return GLFW_FALSE; + } + + setAttrib(0, 0); + + window->context.osmesa.handle = + OSMesaCreateContextAttribs(attribs, share); + } + else + { + if (ctxconfig->profile) + { + _glfwInputError(GLFW_VERSION_UNAVAILABLE, + "OSMesa: OpenGL profiles unavailable"); + return GLFW_FALSE; + } + + window->context.osmesa.handle = + OSMesaCreateContextExt(OSMESA_RGBA, + fbconfig->depthBits, + fbconfig->stencilBits, + accumBits, + share); + } + + if (window->context.osmesa.handle == NULL) + { + _glfwInputError(GLFW_VERSION_UNAVAILABLE, + "OSMesa: Failed to create context"); + return GLFW_FALSE; + } + + window->context.makeCurrent = makeContextCurrentOSMesa; + window->context.swapBuffers = swapBuffersOSMesa; + window->context.swapInterval = swapIntervalOSMesa; + window->context.extensionSupported = extensionSupportedOSMesa; + window->context.getProcAddress = getProcAddressOSMesa; + window->context.destroy = destroyContextOSMesa; + + return GLFW_TRUE; +} + +#undef setAttrib + + +////////////////////////////////////////////////////////////////////////// +////// GLFW native API ////// +////////////////////////////////////////////////////////////////////////// + +GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* handle, int* width, + int* height, int* format, void** buffer) +{ + void* mesaBuffer; + GLint mesaWidth, mesaHeight, mesaFormat; + _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window != NULL); + + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); + + if (!OSMesaGetColorBuffer(window->context.osmesa.handle, + &mesaWidth, &mesaHeight, + &mesaFormat, &mesaBuffer)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "OSMesa: Failed to retrieve color buffer"); + return GLFW_FALSE; + } + + if (width) + *width = mesaWidth; + if (height) + *height = mesaHeight; + if (format) + *format = mesaFormat; + if (buffer) + *buffer = mesaBuffer; + + return GLFW_TRUE; +} + +GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* handle, + int* width, int* height, + int* bytesPerValue, + void** buffer) +{ + void* mesaBuffer; + GLint mesaWidth, mesaHeight, mesaBytes; + _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window != NULL); + + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); + + if (!OSMesaGetDepthBuffer(window->context.osmesa.handle, + &mesaWidth, &mesaHeight, + &mesaBytes, &mesaBuffer)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "OSMesa: Failed to retrieve depth buffer"); + return GLFW_FALSE; + } + + if (width) + *width = mesaWidth; + if (height) + *height = mesaHeight; + if (bytesPerValue) + *bytesPerValue = mesaBytes; + if (buffer) + *buffer = mesaBuffer; + + return GLFW_TRUE; +} + +GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* handle) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + + if (window->context.client == GLFW_NO_API) + { + _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL); + return NULL; + } + + return window->context.osmesa.handle; +} + diff --git a/libs/glfw/src/osmesa_context.h b/libs/glfw/src/osmesa_context.h @@ -0,0 +1,94 @@ +//======================================================================== +// GLFW 3.3 OSMesa - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2016 Google Inc. +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#define OSMESA_RGBA 0x1908 +#define OSMESA_FORMAT 0x22 +#define OSMESA_DEPTH_BITS 0x30 +#define OSMESA_STENCIL_BITS 0x31 +#define OSMESA_ACCUM_BITS 0x32 +#define OSMESA_PROFILE 0x33 +#define OSMESA_CORE_PROFILE 0x34 +#define OSMESA_COMPAT_PROFILE 0x35 +#define OSMESA_CONTEXT_MAJOR_VERSION 0x36 +#define OSMESA_CONTEXT_MINOR_VERSION 0x37 + +typedef void* OSMesaContext; +typedef void (*OSMESAproc)(); + +typedef OSMesaContext (GLAPIENTRY * PFN_OSMesaCreateContextExt)(GLenum,GLint,GLint,GLint,OSMesaContext); +typedef OSMesaContext (GLAPIENTRY * PFN_OSMesaCreateContextAttribs)(const int*,OSMesaContext); +typedef void (GLAPIENTRY * PFN_OSMesaDestroyContext)(OSMesaContext); +typedef int (GLAPIENTRY * PFN_OSMesaMakeCurrent)(OSMesaContext,void*,int,int,int); +typedef int (GLAPIENTRY * PFN_OSMesaGetColorBuffer)(OSMesaContext,int*,int*,int*,void**); +typedef int (GLAPIENTRY * PFN_OSMesaGetDepthBuffer)(OSMesaContext,int*,int*,int*,void**); +typedef GLFWglproc (GLAPIENTRY * PFN_OSMesaGetProcAddress)(const char*); +#define OSMesaCreateContextExt _glfw.osmesa.CreateContextExt +#define OSMesaCreateContextAttribs _glfw.osmesa.CreateContextAttribs +#define OSMesaDestroyContext _glfw.osmesa.DestroyContext +#define OSMesaMakeCurrent _glfw.osmesa.MakeCurrent +#define OSMesaGetColorBuffer _glfw.osmesa.GetColorBuffer +#define OSMesaGetDepthBuffer _glfw.osmesa.GetDepthBuffer +#define OSMesaGetProcAddress _glfw.osmesa.GetProcAddress + +#define _GLFW_OSMESA_CONTEXT_STATE _GLFWcontextOSMesa osmesa +#define _GLFW_OSMESA_LIBRARY_CONTEXT_STATE _GLFWlibraryOSMesa osmesa + + +// OSMesa-specific per-context data +// +typedef struct _GLFWcontextOSMesa +{ + OSMesaContext handle; + int width; + int height; + void* buffer; + +} _GLFWcontextOSMesa; + +// OSMesa-specific global data +// +typedef struct _GLFWlibraryOSMesa +{ + void* handle; + + PFN_OSMesaCreateContextExt CreateContextExt; + PFN_OSMesaCreateContextAttribs CreateContextAttribs; + PFN_OSMesaDestroyContext DestroyContext; + PFN_OSMesaMakeCurrent MakeCurrent; + PFN_OSMesaGetColorBuffer GetColorBuffer; + PFN_OSMesaGetDepthBuffer GetDepthBuffer; + PFN_OSMesaGetProcAddress GetProcAddress; + +} _GLFWlibraryOSMesa; + + +GLFWbool _glfwInitOSMesa(void); +void _glfwTerminateOSMesa(void); +GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, + const _GLFWctxconfig* ctxconfig, + const _GLFWfbconfig* fbconfig); + diff --git a/libs/glfw/src/posix_thread.cc b/libs/glfw/src/posix_thread.cc @@ -0,0 +1,103 @@ +//======================================================================== +// GLFW 3.3 POSIX - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2002-2006 Marcus Geelnard +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include "internal.h" + +#include <assert.h> +#include <string.h> + + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) +{ + assert(tls->posix.allocated == GLFW_FALSE); + + if (pthread_key_create(&tls->posix.key, NULL) != 0) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "POSIX: Failed to create context TLS"); + return GLFW_FALSE; + } + + tls->posix.allocated = GLFW_TRUE; + return GLFW_TRUE; +} + +void _glfwPlatformDestroyTls(_GLFWtls* tls) +{ + if (tls->posix.allocated) + pthread_key_delete(tls->posix.key); + memset(tls, 0, sizeof(_GLFWtls)); +} + +void* _glfwPlatformGetTls(_GLFWtls* tls) +{ + assert(tls->posix.allocated == GLFW_TRUE); + return pthread_getspecific(tls->posix.key); +} + +void _glfwPlatformSetTls(_GLFWtls* tls, void* value) +{ + assert(tls->posix.allocated == GLFW_TRUE); + pthread_setspecific(tls->posix.key, value); +} + +GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) +{ + assert(mutex->posix.allocated == GLFW_FALSE); + + if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0) + { + _glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex"); + return GLFW_FALSE; + } + + return mutex->posix.allocated = GLFW_TRUE; +} + +void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) +{ + if (mutex->posix.allocated) + pthread_mutex_destroy(&mutex->posix.handle); + memset(mutex, 0, sizeof(_GLFWmutex)); +} + +void _glfwPlatformLockMutex(_GLFWmutex* mutex) +{ + assert(mutex->posix.allocated == GLFW_TRUE); + pthread_mutex_lock(&mutex->posix.handle); +} + +void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) +{ + assert(mutex->posix.allocated == GLFW_TRUE); + pthread_mutex_unlock(&mutex->posix.handle); +} + diff --git a/libs/glfw/src/posix_thread.h b/libs/glfw/src/posix_thread.h @@ -0,0 +1,51 @@ +//======================================================================== +// GLFW 3.3 POSIX - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2002-2006 Marcus Geelnard +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include <pthread.h> + +#define _GLFW_PLATFORM_TLS_STATE _GLFWtlsPOSIX posix +#define _GLFW_PLATFORM_MUTEX_STATE _GLFWmutexPOSIX posix + + +// POSIX-specific thread local storage data +// +typedef struct _GLFWtlsPOSIX +{ + GLFWbool allocated; + pthread_key_t key; + +} _GLFWtlsPOSIX; + +// POSIX-specific mutex data +// +typedef struct _GLFWmutexPOSIX +{ + GLFWbool allocated; + pthread_mutex_t handle; + +} _GLFWmutexPOSIX; + diff --git a/libs/glfw/src/posix_time.cc b/libs/glfw/src/posix_time.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 POSIX - www.glfw.org +// GLFW 3.3 POSIX - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -44,14 +44,14 @@ void _glfwInitTimerPOSIX(void) if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { - _glfw.posix_time.monotonic = GLFW_TRUE; - _glfw.posix_time.frequency = 1000000000; + _glfw.timer.posix.monotonic = GLFW_TRUE; + _glfw.timer.posix.frequency = 1000000000; } else #endif { - _glfw.posix_time.monotonic = GLFW_FALSE; - _glfw.posix_time.frequency = 1000000; + _glfw.timer.posix.monotonic = GLFW_FALSE; + _glfw.timer.posix.frequency = 1000000; } } @@ -63,7 +63,7 @@ void _glfwInitTimerPOSIX(void) uint64_t _glfwPlatformGetTimerValue(void) { #if defined(CLOCK_MONOTONIC) - if (_glfw.posix_time.monotonic) + if (_glfw.timer.posix.monotonic) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); @@ -80,6 +80,6 @@ uint64_t _glfwPlatformGetTimerValue(void) uint64_t _glfwPlatformGetTimerFrequency(void) { - return _glfw.posix_time.frequency; + return _glfw.timer.posix.frequency; } diff --git a/libs/glfw/src/posix_time.h b/libs/glfw/src/posix_time.h @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 POSIX - www.glfw.org +// GLFW 3.3 POSIX - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -25,24 +25,20 @@ // //======================================================================== -#ifndef _glfw3_posix_time_h_ -#define _glfw3_posix_time_h_ - -#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimePOSIX posix_time +#define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix #include <stdint.h> // POSIX-specific global timer data // -typedef struct _GLFWtimePOSIX +typedef struct _GLFWtimerPOSIX { GLFWbool monotonic; uint64_t frequency; -} _GLFWtimePOSIX; +} _GLFWtimerPOSIX; void _glfwInitTimerPOSIX(void); -#endif // _glfw3_posix_time_h_ diff --git a/libs/glfw/src/posix_tls.cc b/libs/glfw/src/posix_tls.cc @@ -1,68 +0,0 @@ -//======================================================================== -// GLFW 3.2 POSIX - www.glfw.org -//------------------------------------------------------------------------ -// Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would -// be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not -// be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -//======================================================================== - -#include "internal.h" - - -////////////////////////////////////////////////////////////////////////// -////// GLFW internal API ////// -////////////////////////////////////////////////////////////////////////// - -GLFWbool _glfwInitThreadLocalStoragePOSIX(void) -{ - if (pthread_key_create(&_glfw.posix_tls.context, NULL) != 0) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "POSIX: Failed to create context TLS"); - return GLFW_FALSE; - } - - _glfw.posix_tls.allocated = GLFW_TRUE; - return GLFW_TRUE; -} - -void _glfwTerminateThreadLocalStoragePOSIX(void) -{ - if (_glfw.posix_tls.allocated) - pthread_key_delete(_glfw.posix_tls.context); -} - - -////////////////////////////////////////////////////////////////////////// -////// GLFW platform API ////// -////////////////////////////////////////////////////////////////////////// - -void _glfwPlatformSetCurrentContext(_GLFWwindow* context) -{ - pthread_setspecific(_glfw.posix_tls.context, context); -} - -_GLFWwindow* _glfwPlatformGetCurrentContext(void) -{ - return pthread_getspecific(_glfw.posix_tls.context); -} - diff --git a/libs/glfw/src/posix_tls.h b/libs/glfw/src/posix_tls.h @@ -1,49 +0,0 @@ -//======================================================================== -// GLFW 3.2 POSIX - www.glfw.org -//------------------------------------------------------------------------ -// Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would -// be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not -// be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -//======================================================================== - -#ifndef _glfw3_posix_tls_h_ -#define _glfw3_posix_tls_h_ - -#include <pthread.h> - -#define _GLFW_PLATFORM_LIBRARY_TLS_STATE _GLFWtlsPOSIX posix_tls - - -// POSIX-specific global TLS data -// -typedef struct _GLFWtlsPOSIX -{ - GLFWbool allocated; - pthread_key_t context; - -} _GLFWtlsPOSIX; - - -GLFWbool _glfwInitThreadLocalStoragePOSIX(void); -void _glfwTerminateThreadLocalStoragePOSIX(void); - -#endif // _glfw3_posix_tls_h_ diff --git a/libs/glfw/src/vulkan.cc b/libs/glfw/src/vulkan.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 - www.glfw.org +// GLFW 3.3 - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -31,30 +31,38 @@ #include <string.h> #include <stdlib.h> +#define _GLFW_FIND_LOADER 1 +#define _GLFW_REQUIRE_LOADER 2 + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// -GLFWbool _glfwInitVulkan(void) +GLFWbool _glfwInitVulkan(int mode) { VkResult err; VkExtensionProperties* ep; uint32_t i, count; + if (_glfw.vk.available) + return GLFW_TRUE; + #if !defined(_GLFW_VULKAN_STATIC) #if defined(_GLFW_WIN32) - const char* name = "vulkan-1.dll"; + _glfw.vk.handle = _glfw_dlopen("vulkan-1.dll"); +#elif defined(_GLFW_COCOA) + _glfw.vk.handle = _glfw_dlopen("libMoltenVK.dylib"); #else - const char* name = "libvulkan.so.1"; + _glfw.vk.handle = _glfw_dlopen("libvulkan.so.1"); #endif - - if (_glfw.vk.available) - return GLFW_TRUE; - - _glfw.vk.handle = _glfw_dlopen(name); if (!_glfw.vk.handle) + { + if (mode == _GLFW_REQUIRE_LOADER) + _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Loader not found"); + return GLFW_FALSE; + } _glfw.vk.GetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) _glfw_dlsym(_glfw.vk.handle, "vkGetInstanceProcAddr"); @@ -82,9 +90,13 @@ GLFWbool _glfwInitVulkan(void) err = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL); if (err) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Vulkan: Failed to query instance extension count: %s", - _glfwGetVulkanResultString(err)); + // NOTE: This happens on systems with a loader but without any Vulkan ICD + if (mode == _GLFW_REQUIRE_LOADER) + { + _glfwInputError(GLFW_API_UNAVAILABLE, + "Vulkan: Failed to query instance extension count: %s", + _glfwGetVulkanResultString(err)); + } _glfwTerminateVulkan(); return GLFW_FALSE; @@ -95,7 +107,7 @@ GLFWbool _glfwInitVulkan(void) err = vkEnumerateInstanceExtensionProperties(NULL, &count, ep); if (err) { - _glfwInputError(GLFW_PLATFORM_ERROR, + _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Failed to query instance extensions: %s", _glfwGetVulkanResultString(err)); @@ -108,41 +120,41 @@ GLFWbool _glfwInitVulkan(void) { if (strcmp(ep[i].extensionName, "VK_KHR_surface") == 0) _glfw.vk.KHR_surface = GLFW_TRUE; - if (strcmp(ep[i].extensionName, "VK_KHR_win32_surface") == 0) +#if defined(_GLFW_WIN32) + else if (strcmp(ep[i].extensionName, "VK_KHR_win32_surface") == 0) _glfw.vk.KHR_win32_surface = GLFW_TRUE; - if (strcmp(ep[i].extensionName, "VK_KHR_xlib_surface") == 0) +#elif defined(_GLFW_COCOA) + else if (strcmp(ep[i].extensionName, "VK_MVK_macos_surface") == 0) + _glfw.vk.MVK_macos_surface = GLFW_TRUE; +#elif defined(_GLFW_X11) + else if (strcmp(ep[i].extensionName, "VK_KHR_xlib_surface") == 0) _glfw.vk.KHR_xlib_surface = GLFW_TRUE; - if (strcmp(ep[i].extensionName, "VK_KHR_xcb_surface") == 0) + else if (strcmp(ep[i].extensionName, "VK_KHR_xcb_surface") == 0) _glfw.vk.KHR_xcb_surface = GLFW_TRUE; - if (strcmp(ep[i].extensionName, "VK_KHR_wayland_surface") == 0) +#elif defined(_GLFW_WAYLAND) + else if (strcmp(ep[i].extensionName, "VK_KHR_wayland_surface") == 0) _glfw.vk.KHR_wayland_surface = GLFW_TRUE; - if (strcmp(ep[i].extensionName, "VK_KHR_mir_surface") == 0) +#elif defined(_GLFW_MIR) + else if (strcmp(ep[i].extensionName, "VK_KHR_mir_surface") == 0) _glfw.vk.KHR_mir_surface = GLFW_TRUE; +#endif } free(ep); _glfw.vk.available = GLFW_TRUE; - if (_glfw.vk.KHR_surface) - { - _glfw.vk.extensions = - _glfwPlatformGetRequiredInstanceExtensions(&_glfw.vk.extensionCount); - } + _glfwPlatformGetRequiredInstanceExtensions(_glfw.vk.extensions); return GLFW_TRUE; } void _glfwTerminateVulkan(void) { - uint32_t i; - - for (i = 0; i < _glfw.vk.extensionCount; i++) - free(_glfw.vk.extensions[i]); - free(_glfw.vk.extensions); - +#if !defined(_GLFW_VULKAN_STATIC) if (_glfw.vk.handle) _glfw_dlclose(_glfw.vk.handle); +#endif } const char* _glfwGetVulkanResultString(VkResult result) @@ -208,22 +220,24 @@ const char* _glfwGetVulkanResultString(VkResult result) GLFWAPI int glfwVulkanSupported(void) { _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); - return _glfwInitVulkan(); + return _glfwInitVulkan(_GLFW_FIND_LOADER); } GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count) { + assert(count != NULL); + *count = 0; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - if (!_glfwInitVulkan()) - { - _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: API not available"); + if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) return NULL; - } - *count = _glfw.vk.extensionCount; + if (!_glfw.vk.extensions[0]) + return NULL; + + *count = 2; return (const char**) _glfw.vk.extensions; } @@ -231,18 +245,24 @@ GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* procname) { GLFWvkproc proc; + assert(procname != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - if (!_glfwInitVulkan()) - { - _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: API not available"); + if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) return NULL; - } proc = (GLFWvkproc) vkGetInstanceProcAddr(instance, procname); +#if defined(_GLFW_VULKAN_STATIC) + if (!proc) + { + if (strcmp(procname, "vkGetInstanceProcAddr") == 0) + return (GLFWvkproc) vkGetInstanceProcAddr; + } +#else if (!proc) proc = (GLFWvkproc) _glfw_dlsym(_glfw.vk.handle, procname); +#endif return proc; } @@ -251,15 +271,15 @@ GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily) { + assert(instance != VK_NULL_HANDLE); + assert(device != VK_NULL_HANDLE); + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); - if (!_glfwInitVulkan()) - { - _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: API not available"); + if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) return GLFW_FALSE; - } - if (!_glfw.vk.extensions) + if (!_glfw.vk.extensions[0]) { _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Window surface creation extensions not found"); @@ -277,6 +297,7 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, VkSurfaceKHR* surface) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(instance != VK_NULL_HANDLE); assert(window != NULL); assert(surface != NULL); @@ -284,13 +305,10 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, _GLFW_REQUIRE_INIT_OR_RETURN(VK_ERROR_INITIALIZATION_FAILED); - if (!_glfwInitVulkan()) - { - _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: API not available"); + if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) return VK_ERROR_INITIALIZATION_FAILED; - } - if (!_glfw.vk.extensions) + if (!_glfw.vk.extensions[0]) { _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Window surface creation extensions not found"); diff --git a/libs/glfw/src/wgl_context.cc b/libs/glfw/src/wgl_context.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 WGL - www.glfw.org +// GLFW 3.3 WGL - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -44,9 +44,8 @@ static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib pixelFormat, 0, 1, &attrib, &value)) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "WGL: Failed to retrieve pixel format attribute %i", - attrib); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to retrieve pixel format attribute"); return 0; } @@ -55,7 +54,9 @@ static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib // Return a list of available and usable framebuffer configs // -static int choosePixelFormat(_GLFWwindow* window, const _GLFWfbconfig* desired) +static int choosePixelFormat(_GLFWwindow* window, + const _GLFWctxconfig* ctxconfig, + const _GLFWfbconfig* fbconfig) { _GLFWfbconfig* usableConfigs; const _GLFWfbconfig* closest; @@ -128,11 +129,25 @@ static int choosePixelFormat(_GLFWwindow* window, const _GLFWfbconfig* desired) if (_glfw.wgl.ARB_multisample) u->samples = getPixelFormatAttrib(window, n, WGL_SAMPLES_ARB); - if (_glfw.wgl.ARB_framebuffer_sRGB || - _glfw.wgl.EXT_framebuffer_sRGB) + if (ctxconfig->client == GLFW_OPENGL_API) { - if (getPixelFormatAttrib(window, n, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB)) - u->sRGB = GLFW_TRUE; + if (_glfw.wgl.ARB_framebuffer_sRGB || + _glfw.wgl.EXT_framebuffer_sRGB) + { + if (getPixelFormatAttrib(window, n, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB)) + u->sRGB = GLFW_TRUE; + } + } + else + { + if (_glfw.wgl.EXT_colorspace) + { + if (getPixelFormatAttrib(window, n, WGL_COLORSPACE_EXT) == + WGL_COLORSPACE_SRGB_EXT) + { + u->sRGB = GLFW_TRUE; + } + } } } else @@ -198,7 +213,7 @@ static int choosePixelFormat(_GLFWwindow* window, const _GLFWfbconfig* desired) return 0; } - closest = _glfwChooseFBConfig(desired, usableConfigs, usableCount); + closest = _glfwChooseFBConfig(fbconfig, usableConfigs, usableCount); if (!closest) { _glfwInputError(GLFW_FORMAT_UNAVAILABLE, @@ -234,23 +249,23 @@ static void makeContextCurrentWGL(_GLFWwindow* window) if (window) { if (wglMakeCurrent(window->context.wgl.dc, window->context.wgl.handle)) - _glfwPlatformSetCurrentContext(window); + _glfwPlatformSetTls(&_glfw.contextSlot, window); else { - _glfwInputError(GLFW_PLATFORM_ERROR, - "WGL: Failed to make context current"); - _glfwPlatformSetCurrentContext(NULL); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to make context current"); + _glfwPlatformSetTls(&_glfw.contextSlot, NULL); } } else { if (!wglMakeCurrent(NULL, NULL)) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "WGL: Failed to clear current context"); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to clear current context"); } - _glfwPlatformSetCurrentContext(NULL); + _glfwPlatformSetTls(&_glfw.contextSlot, NULL); } } @@ -269,7 +284,7 @@ static void swapBuffersWGL(_GLFWwindow* window) static void swapIntervalWGL(int interval) { - _GLFWwindow* window = _glfwPlatformGetCurrentContext(); + _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); window->context.wgl.interval = interval; @@ -353,25 +368,24 @@ static void loadWGLExtensions(void) if (!SetPixelFormat(dc, ChoosePixelFormat(dc, &pfd), &pfd)) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "WGL: Failed to set pixel format for dummy context"); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to set pixel format for dummy context"); return; } rc = wglCreateContext(dc); if (!rc) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "WGL: Failed to create dummy context"); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to create dummy context"); return; } if (!wglMakeCurrent(dc, rc)) { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to make dummy context current"); wglDeleteContext(rc); - - _glfwInputError(GLFW_PLATFORM_ERROR, - "WGL: Failed to make dummy context current"); return; } @@ -404,8 +418,12 @@ static void loadWGLExtensions(void) extensionSupportedWGL("WGL_EXT_create_context_es2_profile"); _glfw.wgl.ARB_create_context_robustness = extensionSupportedWGL("WGL_ARB_create_context_robustness"); + _glfw.wgl.ARB_create_context_no_error = + extensionSupportedWGL("WGL_ARB_create_context_no_error"); _glfw.wgl.EXT_swap_control = extensionSupportedWGL("WGL_EXT_swap_control"); + _glfw.wgl.EXT_colorspace = + extensionSupportedWGL("WGL_EXT_colorspace"); _glfw.wgl.ARB_pixel_format = extensionSupportedWGL("WGL_ARB_pixel_format"); _glfw.wgl.ARB_context_flush_control = @@ -430,21 +448,22 @@ GLFWbool _glfwInitWGL(void) _glfw.wgl.instance = LoadLibraryA("opengl32.dll"); if (!_glfw.wgl.instance) { - _glfwInputError(GLFW_PLATFORM_ERROR, "WGL: Failed to load opengl32.dll"); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to load opengl32.dll"); return GLFW_FALSE; } - _glfw.wgl.CreateContext = (WGLCREATECONTEXT_T) + _glfw.wgl.CreateContext = (PFN_wglCreateContext) GetProcAddress(_glfw.wgl.instance, "wglCreateContext"); - _glfw.wgl.DeleteContext = (WGLDELETECONTEXT_T) + _glfw.wgl.DeleteContext = (PFN_wglDeleteContext) GetProcAddress(_glfw.wgl.instance, "wglDeleteContext"); - _glfw.wgl.GetProcAddress = (WGLGETPROCADDRESS_T) + _glfw.wgl.GetProcAddress = (PFN_wglGetProcAddress) GetProcAddress(_glfw.wgl.instance, "wglGetProcAddress"); - _glfw.wgl.GetCurrentDC = (WGLGETCURRENTDC_T) + _glfw.wgl.GetCurrentDC = (PFN_wglGetCurrentDC) GetProcAddress(_glfw.wgl.instance, "wglGetCurrentDC"); - _glfw.wgl.MakeCurrent = (WGLMAKECURRENT_T) + _glfw.wgl.MakeCurrent = (PFN_wglMakeCurrent) GetProcAddress(_glfw.wgl.instance, "wglMakeCurrent"); - _glfw.wgl.ShareLists = (WGLSHARELISTS_T) + _glfw.wgl.ShareLists = (PFN_wglShareLists) GetProcAddress(_glfw.wgl.instance, "wglShareLists"); return GLFW_TRUE; @@ -458,11 +477,11 @@ void _glfwTerminateWGL(void) FreeLibrary(_glfw.wgl.instance); } -#define setWGLattrib(attribName, attribValue) \ +#define setAttrib(a, v) \ { \ - attribs[index++] = attribName; \ - attribs[index++] = attribValue; \ - assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \ + assert((size_t) (index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ + attribs[index++] = a; \ + attribs[index++] = v; \ } // Create the OpenGL or OpenGL ES context @@ -490,22 +509,22 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, return GLFW_FALSE; } - pixelFormat = choosePixelFormat(window, fbconfig); + pixelFormat = choosePixelFormat(window, ctxconfig, fbconfig); if (!pixelFormat) return GLFW_FALSE; if (!DescribePixelFormat(window->context.wgl.dc, pixelFormat, sizeof(pfd), &pfd)) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "WGL: Failed to retrieve PFD for selected pixel format"); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to retrieve PFD for selected pixel format"); return GLFW_FALSE; } if (!SetPixelFormat(window->context.wgl.dc, pixelFormat, &pfd)) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "WGL: Failed to set selected pixel format"); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to set selected pixel format"); return GLFW_FALSE; } @@ -562,8 +581,6 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, if (ctxconfig->debug) flags |= WGL_CONTEXT_DEBUG_BIT_ARB; - if (ctxconfig->noerror) - flags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR; if (ctxconfig->robustness) { @@ -571,13 +588,13 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, { if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION) { - setWGLattrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, - WGL_NO_RESET_NOTIFICATION_ARB); + setAttrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, + WGL_NO_RESET_NOTIFICATION_ARB); } else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET) { - setWGLattrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, - WGL_LOSE_CONTEXT_ON_RESET_ARB); + setAttrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, + WGL_LOSE_CONTEXT_ON_RESET_ARB); } flags |= WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB; @@ -590,33 +607,39 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, { if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE) { - setWGLattrib(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB, - WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB); + setAttrib(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB, + WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB); } else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH) { - setWGLattrib(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB, - WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB); + setAttrib(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB, + WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB); } } } + if (ctxconfig->noerror) + { + if (_glfw.wgl.ARB_create_context_no_error) + setAttrib(WGL_CONTEXT_OPENGL_NO_ERROR_ARB, GLFW_TRUE); + } + // NOTE: Only request an explicitly versioned context when necessary, as // explicitly requesting version 1.0 does not always return the // highest version supported by the driver if (ctxconfig->major != 1 || ctxconfig->minor != 0) { - setWGLattrib(WGL_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major); - setWGLattrib(WGL_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor); + setAttrib(WGL_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major); + setAttrib(WGL_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor); } if (flags) - setWGLattrib(WGL_CONTEXT_FLAGS_ARB, flags); + setAttrib(WGL_CONTEXT_FLAGS_ARB, flags); if (mask) - setWGLattrib(WGL_CONTEXT_PROFILE_MASK_ARB, mask); + setAttrib(WGL_CONTEXT_PROFILE_MASK_ARB, mask); - setWGLattrib(0, 0); + setAttrib(0, 0); window->context.wgl.handle = _glfw.wgl.CreateContextAttribsARB(window->context.wgl.dc, @@ -647,6 +670,11 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, _glfwInputError(GLFW_VERSION_UNAVAILABLE, "WGL: Driver does not support the requested OpenGL profile"); } + else if (error == (0xc0070000 | ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB)) + { + _glfwInputError(GLFW_INVALID_VALUE, + "WGL: The share context is not compatible with the requested context"); + } else { if (ctxconfig->client == GLFW_OPENGL_API) @@ -669,8 +697,8 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, window->context.wgl.handle = wglCreateContext(window->context.wgl.dc); if (!window->context.wgl.handle) { - _glfwInputError(GLFW_VERSION_UNAVAILABLE, - "WGL: Failed to create OpenGL context"); + _glfwInputErrorWin32(GLFW_VERSION_UNAVAILABLE, + "WGL: Failed to create OpenGL context"); return GLFW_FALSE; } @@ -678,8 +706,8 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, { if (!wglShareLists(share, window->context.wgl.handle)) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "WGL: Failed to enable sharing with specified OpenGL context"); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to enable sharing with specified OpenGL context"); return GLFW_FALSE; } } @@ -695,7 +723,7 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, return GLFW_TRUE; } -#undef setWGLattrib +#undef setAttrib ////////////////////////////////////////////////////////////////////////// diff --git a/libs/glfw/src/wgl_context.h b/libs/glfw/src/wgl_context.h @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 WGL - www.glfw.org +// GLFW 3.3 WGL - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -25,10 +25,6 @@ // //======================================================================== -#ifndef _glfw3_wgl_context_h_ -#define _glfw3_wgl_context_h_ - - #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 #define WGL_SUPPORT_OPENGL_ARB 0x2010 #define WGL_DRAW_TO_WINDOW_ARB 0x2001 @@ -72,9 +68,13 @@ #define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 #define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0 #define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 +#define WGL_CONTEXT_OPENGL_NO_ERROR_ARB 0x31b3 +#define WGL_COLORSPACE_EXT 0x309d +#define WGL_COLORSPACE_SRGB_EXT 0x3089 #define ERROR_INVALID_VERSION_ARB 0x2095 #define ERROR_INVALID_PROFILE_ARB 0x2096 +#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054 typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC)(int); typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC)(HDC,int,int,UINT,const int*,int*); @@ -82,12 +82,12 @@ typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void); typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC); typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC,HGLRC,const int*); -typedef HGLRC (WINAPI * WGLCREATECONTEXT_T)(HDC); -typedef BOOL (WINAPI * WGLDELETECONTEXT_T)(HGLRC); -typedef PROC (WINAPI * WGLGETPROCADDRESS_T)(LPCSTR); -typedef HDC (WINAPI * WGLGETCURRENTDC_T)(void); -typedef BOOL (WINAPI * WGLMAKECURRENT_T)(HDC,HGLRC); -typedef BOOL (WINAPI * WGLSHARELISTS_T)(HGLRC,HGLRC); +typedef HGLRC (WINAPI * PFN_wglCreateContext)(HDC); +typedef BOOL (WINAPI * PFN_wglDeleteContext)(HGLRC); +typedef PROC (WINAPI * PFN_wglGetProcAddress)(LPCSTR); +typedef HDC (WINAPI * PFN_wglGetCurrentDC)(void); +typedef BOOL (WINAPI * PFN_wglMakeCurrent)(HDC,HGLRC); +typedef BOOL (WINAPI * PFN_wglShareLists)(HGLRC,HGLRC); // opengl32.dll function pointer typedefs #define wglCreateContext _glfw.wgl.CreateContext @@ -120,12 +120,12 @@ typedef struct _GLFWcontextWGL typedef struct _GLFWlibraryWGL { HINSTANCE instance; - WGLCREATECONTEXT_T CreateContext; - WGLDELETECONTEXT_T DeleteContext; - WGLGETPROCADDRESS_T GetProcAddress; - WGLGETCURRENTDC_T GetCurrentDC; - WGLMAKECURRENT_T MakeCurrent; - WGLSHARELISTS_T ShareLists; + PFN_wglCreateContext CreateContext; + PFN_wglDeleteContext DeleteContext; + PFN_wglGetProcAddress GetProcAddress; + PFN_wglGetCurrentDC GetCurrentDC; + PFN_wglMakeCurrent MakeCurrent; + PFN_wglShareLists ShareLists; GLFWbool extensionsLoaded; @@ -135,6 +135,7 @@ typedef struct _GLFWlibraryWGL PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; GLFWbool EXT_swap_control; + GLFWbool EXT_colorspace; GLFWbool ARB_multisample; GLFWbool ARB_framebuffer_sRGB; GLFWbool EXT_framebuffer_sRGB; @@ -143,6 +144,7 @@ typedef struct _GLFWlibraryWGL GLFWbool ARB_create_context_profile; GLFWbool EXT_create_context_es2_profile; GLFWbool ARB_create_context_robustness; + GLFWbool ARB_create_context_no_error; GLFWbool ARB_context_flush_control; } _GLFWlibraryWGL; @@ -154,4 +156,3 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); -#endif // _glfw3_wgl_context_h_ diff --git a/libs/glfw/src/win32_init.cc b/libs/glfw/src/win32_init.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 Win32 - www.glfw.org +// GLFW 3.3 Win32 - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -30,20 +30,21 @@ #include <stdlib.h> #include <malloc.h> -#include <initguid.h> -DEFINE_GUID(GUID_DEVINTERFACE_HID,0x4d1e55b2,0xf16f,0x11cf,0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30); +static const GUID _glfw_GUID_DEVINTERFACE_HID = {0x4d1e55b2,0xf16f,0x11cf,{0x88,0xcb,0x00,0x11,0x11,0x00,0x00,0x30}}; + +#define GUID_DEVINTERFACE_HID _glfw_GUID_DEVINTERFACE_HID #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) -// Applications exporting this symbol with this value will be automatically -// directed to the high-performance GPU on Nvidia Optimus systems with -// up-to-date drivers +// Executables (but not DLLs) exporting this symbol with this value will be +// automatically directed to the high-performance GPU on Nvidia Optimus systems +// with up-to-date drivers // __declspec(dllexport) DWORD NvOptimusEnablement = 1; -// Applications exporting this symbol with this value will be automatically -// directed to the high-performance GPU on AMD PowerXpress systems with -// up-to-date drivers +// Executables (but not DLLs) exporting this symbol with this value will be +// automatically directed to the high-performance GPU on AMD PowerXpress systems +// with up-to-date drivers // __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; @@ -67,29 +68,29 @@ static GLFWbool loadLibraries(void) _glfw.win32.winmm.instance = LoadLibraryA("winmm.dll"); if (!_glfw.win32.winmm.instance) { - _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to load winmm.dll"); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to load winmm.dll"); return GLFW_FALSE; } - _glfw.win32.winmm.timeGetTime = (TIMEGETTIME_T) + _glfw.win32.winmm.GetTime = (PFN_timeGetTime) GetProcAddress(_glfw.win32.winmm.instance, "timeGetTime"); _glfw.win32.user32.instance = LoadLibraryA("user32.dll"); if (!_glfw.win32.user32.instance) { - _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to load user32.dll"); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to load user32.dll"); return GLFW_FALSE; } - _glfw.win32.user32.SetProcessDPIAware = (SETPROCESSDPIAWARE_T) + _glfw.win32.user32.SetProcessDPIAware = (PFN_SetProcessDPIAware) GetProcAddress(_glfw.win32.user32.instance, "SetProcessDPIAware"); - _glfw.win32.user32.ChangeWindowMessageFilterEx = (CHANGEWINDOWMESSAGEFILTEREX_T) + _glfw.win32.user32.ChangeWindowMessageFilterEx = (PFN_ChangeWindowMessageFilterEx) GetProcAddress(_glfw.win32.user32.instance, "ChangeWindowMessageFilterEx"); _glfw.win32.dinput8.instance = LoadLibraryA("dinput8.dll"); if (_glfw.win32.dinput8.instance) { - _glfw.win32.dinput8.DirectInput8Create = (DIRECTINPUT8CREATE_T) + _glfw.win32.dinput8.Create = (PFN_DirectInput8Create) GetProcAddress(_glfw.win32.dinput8.instance, "DirectInput8Create"); } @@ -110,9 +111,9 @@ static GLFWbool loadLibraries(void) _glfw.win32.xinput.instance = LoadLibraryA(names[i]); if (_glfw.win32.xinput.instance) { - _glfw.win32.xinput.XInputGetCapabilities = (XINPUTGETCAPABILITIES_T) + _glfw.win32.xinput.GetCapabilities = (PFN_XInputGetCapabilities) GetProcAddress(_glfw.win32.xinput.instance, "XInputGetCapabilities"); - _glfw.win32.xinput.XInputGetState = (XINPUTGETSTATE_T) + _glfw.win32.xinput.GetState = (PFN_XInputGetState) GetProcAddress(_glfw.win32.xinput.instance, "XInputGetState"); break; @@ -123,16 +124,16 @@ static GLFWbool loadLibraries(void) _glfw.win32.dwmapi.instance = LoadLibraryA("dwmapi.dll"); if (_glfw.win32.dwmapi.instance) { - _glfw.win32.dwmapi.DwmIsCompositionEnabled = (DWMISCOMPOSITIONENABLED_T) + _glfw.win32.dwmapi.DwmIsCompositionEnabled = (PFN_DwmIsCompositionEnabled) GetProcAddress(_glfw.win32.dwmapi.instance, "DwmIsCompositionEnabled"); - _glfw.win32.dwmapi.DwmFlush = (DWMFLUSH_T) + _glfw.win32.dwmapi.DwmFlush = (PFN_DwmFlush) GetProcAddress(_glfw.win32.dwmapi.instance, "DwmFlush"); } _glfw.win32.shcore.instance = LoadLibraryA("shcore.dll"); if (_glfw.win32.shcore.instance) { - _glfw.win32.shcore.SetProcessDpiAwareness = (SETPROCESSDPIAWARENESS_T) + _glfw.win32.shcore.SetProcessDpiAwareness = (PFN_SetProcessDpiAwareness) GetProcAddress(_glfw.win32.shcore.instance, "SetProcessDpiAwareness"); } @@ -168,135 +169,135 @@ static void createKeyTables(void) { int scancode; - memset(_glfw.win32.publicKeys, -1, sizeof(_glfw.win32.publicKeys)); - memset(_glfw.win32.nativeKeys, -1, sizeof(_glfw.win32.nativeKeys)); - - _glfw.win32.publicKeys[0x00B] = GLFW_KEY_0; - _glfw.win32.publicKeys[0x002] = GLFW_KEY_1; - _glfw.win32.publicKeys[0x003] = GLFW_KEY_2; - _glfw.win32.publicKeys[0x004] = GLFW_KEY_3; - _glfw.win32.publicKeys[0x005] = GLFW_KEY_4; - _glfw.win32.publicKeys[0x006] = GLFW_KEY_5; - _glfw.win32.publicKeys[0x007] = GLFW_KEY_6; - _glfw.win32.publicKeys[0x008] = GLFW_KEY_7; - _glfw.win32.publicKeys[0x009] = GLFW_KEY_8; - _glfw.win32.publicKeys[0x00A] = GLFW_KEY_9; - _glfw.win32.publicKeys[0x01E] = GLFW_KEY_A; - _glfw.win32.publicKeys[0x030] = GLFW_KEY_B; - _glfw.win32.publicKeys[0x02E] = GLFW_KEY_C; - _glfw.win32.publicKeys[0x020] = GLFW_KEY_D; - _glfw.win32.publicKeys[0x012] = GLFW_KEY_E; - _glfw.win32.publicKeys[0x021] = GLFW_KEY_F; - _glfw.win32.publicKeys[0x022] = GLFW_KEY_G; - _glfw.win32.publicKeys[0x023] = GLFW_KEY_H; - _glfw.win32.publicKeys[0x017] = GLFW_KEY_I; - _glfw.win32.publicKeys[0x024] = GLFW_KEY_J; - _glfw.win32.publicKeys[0x025] = GLFW_KEY_K; - _glfw.win32.publicKeys[0x026] = GLFW_KEY_L; - _glfw.win32.publicKeys[0x032] = GLFW_KEY_M; - _glfw.win32.publicKeys[0x031] = GLFW_KEY_N; - _glfw.win32.publicKeys[0x018] = GLFW_KEY_O; - _glfw.win32.publicKeys[0x019] = GLFW_KEY_P; - _glfw.win32.publicKeys[0x010] = GLFW_KEY_Q; - _glfw.win32.publicKeys[0x013] = GLFW_KEY_R; - _glfw.win32.publicKeys[0x01F] = GLFW_KEY_S; - _glfw.win32.publicKeys[0x014] = GLFW_KEY_T; - _glfw.win32.publicKeys[0x016] = GLFW_KEY_U; - _glfw.win32.publicKeys[0x02F] = GLFW_KEY_V; - _glfw.win32.publicKeys[0x011] = GLFW_KEY_W; - _glfw.win32.publicKeys[0x02D] = GLFW_KEY_X; - _glfw.win32.publicKeys[0x015] = GLFW_KEY_Y; - _glfw.win32.publicKeys[0x02C] = GLFW_KEY_Z; - - _glfw.win32.publicKeys[0x028] = GLFW_KEY_APOSTROPHE; - _glfw.win32.publicKeys[0x02B] = GLFW_KEY_BACKSLASH; - _glfw.win32.publicKeys[0x033] = GLFW_KEY_COMMA; - _glfw.win32.publicKeys[0x00D] = GLFW_KEY_EQUAL; - _glfw.win32.publicKeys[0x029] = GLFW_KEY_GRAVE_ACCENT; - _glfw.win32.publicKeys[0x01A] = GLFW_KEY_LEFT_BRACKET; - _glfw.win32.publicKeys[0x00C] = GLFW_KEY_MINUS; - _glfw.win32.publicKeys[0x034] = GLFW_KEY_PERIOD; - _glfw.win32.publicKeys[0x01B] = GLFW_KEY_RIGHT_BRACKET; - _glfw.win32.publicKeys[0x027] = GLFW_KEY_SEMICOLON; - _glfw.win32.publicKeys[0x035] = GLFW_KEY_SLASH; - _glfw.win32.publicKeys[0x056] = GLFW_KEY_WORLD_2; - - _glfw.win32.publicKeys[0x00E] = GLFW_KEY_BACKSPACE; - _glfw.win32.publicKeys[0x153] = GLFW_KEY_DELETE; - _glfw.win32.publicKeys[0x14F] = GLFW_KEY_END; - _glfw.win32.publicKeys[0x01C] = GLFW_KEY_ENTER; - _glfw.win32.publicKeys[0x001] = GLFW_KEY_ESCAPE; - _glfw.win32.publicKeys[0x147] = GLFW_KEY_HOME; - _glfw.win32.publicKeys[0x152] = GLFW_KEY_INSERT; - _glfw.win32.publicKeys[0x15D] = GLFW_KEY_MENU; - _glfw.win32.publicKeys[0x151] = GLFW_KEY_PAGE_DOWN; - _glfw.win32.publicKeys[0x149] = GLFW_KEY_PAGE_UP; - _glfw.win32.publicKeys[0x045] = GLFW_KEY_PAUSE; - _glfw.win32.publicKeys[0x146] = GLFW_KEY_PAUSE; - _glfw.win32.publicKeys[0x039] = GLFW_KEY_SPACE; - _glfw.win32.publicKeys[0x00F] = GLFW_KEY_TAB; - _glfw.win32.publicKeys[0x03A] = GLFW_KEY_CAPS_LOCK; - _glfw.win32.publicKeys[0x145] = GLFW_KEY_NUM_LOCK; - _glfw.win32.publicKeys[0x046] = GLFW_KEY_SCROLL_LOCK; - _glfw.win32.publicKeys[0x03B] = GLFW_KEY_F1; - _glfw.win32.publicKeys[0x03C] = GLFW_KEY_F2; - _glfw.win32.publicKeys[0x03D] = GLFW_KEY_F3; - _glfw.win32.publicKeys[0x03E] = GLFW_KEY_F4; - _glfw.win32.publicKeys[0x03F] = GLFW_KEY_F5; - _glfw.win32.publicKeys[0x040] = GLFW_KEY_F6; - _glfw.win32.publicKeys[0x041] = GLFW_KEY_F7; - _glfw.win32.publicKeys[0x042] = GLFW_KEY_F8; - _glfw.win32.publicKeys[0x043] = GLFW_KEY_F9; - _glfw.win32.publicKeys[0x044] = GLFW_KEY_F10; - _glfw.win32.publicKeys[0x057] = GLFW_KEY_F11; - _glfw.win32.publicKeys[0x058] = GLFW_KEY_F12; - _glfw.win32.publicKeys[0x064] = GLFW_KEY_F13; - _glfw.win32.publicKeys[0x065] = GLFW_KEY_F14; - _glfw.win32.publicKeys[0x066] = GLFW_KEY_F15; - _glfw.win32.publicKeys[0x067] = GLFW_KEY_F16; - _glfw.win32.publicKeys[0x068] = GLFW_KEY_F17; - _glfw.win32.publicKeys[0x069] = GLFW_KEY_F18; - _glfw.win32.publicKeys[0x06A] = GLFW_KEY_F19; - _glfw.win32.publicKeys[0x06B] = GLFW_KEY_F20; - _glfw.win32.publicKeys[0x06C] = GLFW_KEY_F21; - _glfw.win32.publicKeys[0x06D] = GLFW_KEY_F22; - _glfw.win32.publicKeys[0x06E] = GLFW_KEY_F23; - _glfw.win32.publicKeys[0x076] = GLFW_KEY_F24; - _glfw.win32.publicKeys[0x038] = GLFW_KEY_LEFT_ALT; - _glfw.win32.publicKeys[0x01D] = GLFW_KEY_LEFT_CONTROL; - _glfw.win32.publicKeys[0x02A] = GLFW_KEY_LEFT_SHIFT; - _glfw.win32.publicKeys[0x15B] = GLFW_KEY_LEFT_SUPER; - _glfw.win32.publicKeys[0x137] = GLFW_KEY_PRINT_SCREEN; - _glfw.win32.publicKeys[0x138] = GLFW_KEY_RIGHT_ALT; - _glfw.win32.publicKeys[0x11D] = GLFW_KEY_RIGHT_CONTROL; - _glfw.win32.publicKeys[0x036] = GLFW_KEY_RIGHT_SHIFT; - _glfw.win32.publicKeys[0x15C] = GLFW_KEY_RIGHT_SUPER; - _glfw.win32.publicKeys[0x150] = GLFW_KEY_DOWN; - _glfw.win32.publicKeys[0x14B] = GLFW_KEY_LEFT; - _glfw.win32.publicKeys[0x14D] = GLFW_KEY_RIGHT; - _glfw.win32.publicKeys[0x148] = GLFW_KEY_UP; - - _glfw.win32.publicKeys[0x052] = GLFW_KEY_KP_0; - _glfw.win32.publicKeys[0x04F] = GLFW_KEY_KP_1; - _glfw.win32.publicKeys[0x050] = GLFW_KEY_KP_2; - _glfw.win32.publicKeys[0x051] = GLFW_KEY_KP_3; - _glfw.win32.publicKeys[0x04B] = GLFW_KEY_KP_4; - _glfw.win32.publicKeys[0x04C] = GLFW_KEY_KP_5; - _glfw.win32.publicKeys[0x04D] = GLFW_KEY_KP_6; - _glfw.win32.publicKeys[0x047] = GLFW_KEY_KP_7; - _glfw.win32.publicKeys[0x048] = GLFW_KEY_KP_8; - _glfw.win32.publicKeys[0x049] = GLFW_KEY_KP_9; - _glfw.win32.publicKeys[0x04E] = GLFW_KEY_KP_ADD; - _glfw.win32.publicKeys[0x053] = GLFW_KEY_KP_DECIMAL; - _glfw.win32.publicKeys[0x135] = GLFW_KEY_KP_DIVIDE; - _glfw.win32.publicKeys[0x11C] = GLFW_KEY_KP_ENTER; - _glfw.win32.publicKeys[0x037] = GLFW_KEY_KP_MULTIPLY; - _glfw.win32.publicKeys[0x04A] = GLFW_KEY_KP_SUBTRACT; + memset(_glfw.win32.keycodes, -1, sizeof(_glfw.win32.keycodes)); + memset(_glfw.win32.scancodes, -1, sizeof(_glfw.win32.scancodes)); + + _glfw.win32.keycodes[0x00B] = GLFW_KEY_0; + _glfw.win32.keycodes[0x002] = GLFW_KEY_1; + _glfw.win32.keycodes[0x003] = GLFW_KEY_2; + _glfw.win32.keycodes[0x004] = GLFW_KEY_3; + _glfw.win32.keycodes[0x005] = GLFW_KEY_4; + _glfw.win32.keycodes[0x006] = GLFW_KEY_5; + _glfw.win32.keycodes[0x007] = GLFW_KEY_6; + _glfw.win32.keycodes[0x008] = GLFW_KEY_7; + _glfw.win32.keycodes[0x009] = GLFW_KEY_8; + _glfw.win32.keycodes[0x00A] = GLFW_KEY_9; + _glfw.win32.keycodes[0x01E] = GLFW_KEY_A; + _glfw.win32.keycodes[0x030] = GLFW_KEY_B; + _glfw.win32.keycodes[0x02E] = GLFW_KEY_C; + _glfw.win32.keycodes[0x020] = GLFW_KEY_D; + _glfw.win32.keycodes[0x012] = GLFW_KEY_E; + _glfw.win32.keycodes[0x021] = GLFW_KEY_F; + _glfw.win32.keycodes[0x022] = GLFW_KEY_G; + _glfw.win32.keycodes[0x023] = GLFW_KEY_H; + _glfw.win32.keycodes[0x017] = GLFW_KEY_I; + _glfw.win32.keycodes[0x024] = GLFW_KEY_J; + _glfw.win32.keycodes[0x025] = GLFW_KEY_K; + _glfw.win32.keycodes[0x026] = GLFW_KEY_L; + _glfw.win32.keycodes[0x032] = GLFW_KEY_M; + _glfw.win32.keycodes[0x031] = GLFW_KEY_N; + _glfw.win32.keycodes[0x018] = GLFW_KEY_O; + _glfw.win32.keycodes[0x019] = GLFW_KEY_P; + _glfw.win32.keycodes[0x010] = GLFW_KEY_Q; + _glfw.win32.keycodes[0x013] = GLFW_KEY_R; + _glfw.win32.keycodes[0x01F] = GLFW_KEY_S; + _glfw.win32.keycodes[0x014] = GLFW_KEY_T; + _glfw.win32.keycodes[0x016] = GLFW_KEY_U; + _glfw.win32.keycodes[0x02F] = GLFW_KEY_V; + _glfw.win32.keycodes[0x011] = GLFW_KEY_W; + _glfw.win32.keycodes[0x02D] = GLFW_KEY_X; + _glfw.win32.keycodes[0x015] = GLFW_KEY_Y; + _glfw.win32.keycodes[0x02C] = GLFW_KEY_Z; + + _glfw.win32.keycodes[0x028] = GLFW_KEY_APOSTROPHE; + _glfw.win32.keycodes[0x02B] = GLFW_KEY_BACKSLASH; + _glfw.win32.keycodes[0x033] = GLFW_KEY_COMMA; + _glfw.win32.keycodes[0x00D] = GLFW_KEY_EQUAL; + _glfw.win32.keycodes[0x029] = GLFW_KEY_GRAVE_ACCENT; + _glfw.win32.keycodes[0x01A] = GLFW_KEY_LEFT_BRACKET; + _glfw.win32.keycodes[0x00C] = GLFW_KEY_MINUS; + _glfw.win32.keycodes[0x034] = GLFW_KEY_PERIOD; + _glfw.win32.keycodes[0x01B] = GLFW_KEY_RIGHT_BRACKET; + _glfw.win32.keycodes[0x027] = GLFW_KEY_SEMICOLON; + _glfw.win32.keycodes[0x035] = GLFW_KEY_SLASH; + _glfw.win32.keycodes[0x056] = GLFW_KEY_WORLD_2; + + _glfw.win32.keycodes[0x00E] = GLFW_KEY_BACKSPACE; + _glfw.win32.keycodes[0x153] = GLFW_KEY_DELETE; + _glfw.win32.keycodes[0x14F] = GLFW_KEY_END; + _glfw.win32.keycodes[0x01C] = GLFW_KEY_ENTER; + _glfw.win32.keycodes[0x001] = GLFW_KEY_ESCAPE; + _glfw.win32.keycodes[0x147] = GLFW_KEY_HOME; + _glfw.win32.keycodes[0x152] = GLFW_KEY_INSERT; + _glfw.win32.keycodes[0x15D] = GLFW_KEY_MENU; + _glfw.win32.keycodes[0x151] = GLFW_KEY_PAGE_DOWN; + _glfw.win32.keycodes[0x149] = GLFW_KEY_PAGE_UP; + _glfw.win32.keycodes[0x045] = GLFW_KEY_PAUSE; + _glfw.win32.keycodes[0x146] = GLFW_KEY_PAUSE; + _glfw.win32.keycodes[0x039] = GLFW_KEY_SPACE; + _glfw.win32.keycodes[0x00F] = GLFW_KEY_TAB; + _glfw.win32.keycodes[0x03A] = GLFW_KEY_CAPS_LOCK; + _glfw.win32.keycodes[0x145] = GLFW_KEY_NUM_LOCK; + _glfw.win32.keycodes[0x046] = GLFW_KEY_SCROLL_LOCK; + _glfw.win32.keycodes[0x03B] = GLFW_KEY_F1; + _glfw.win32.keycodes[0x03C] = GLFW_KEY_F2; + _glfw.win32.keycodes[0x03D] = GLFW_KEY_F3; + _glfw.win32.keycodes[0x03E] = GLFW_KEY_F4; + _glfw.win32.keycodes[0x03F] = GLFW_KEY_F5; + _glfw.win32.keycodes[0x040] = GLFW_KEY_F6; + _glfw.win32.keycodes[0x041] = GLFW_KEY_F7; + _glfw.win32.keycodes[0x042] = GLFW_KEY_F8; + _glfw.win32.keycodes[0x043] = GLFW_KEY_F9; + _glfw.win32.keycodes[0x044] = GLFW_KEY_F10; + _glfw.win32.keycodes[0x057] = GLFW_KEY_F11; + _glfw.win32.keycodes[0x058] = GLFW_KEY_F12; + _glfw.win32.keycodes[0x064] = GLFW_KEY_F13; + _glfw.win32.keycodes[0x065] = GLFW_KEY_F14; + _glfw.win32.keycodes[0x066] = GLFW_KEY_F15; + _glfw.win32.keycodes[0x067] = GLFW_KEY_F16; + _glfw.win32.keycodes[0x068] = GLFW_KEY_F17; + _glfw.win32.keycodes[0x069] = GLFW_KEY_F18; + _glfw.win32.keycodes[0x06A] = GLFW_KEY_F19; + _glfw.win32.keycodes[0x06B] = GLFW_KEY_F20; + _glfw.win32.keycodes[0x06C] = GLFW_KEY_F21; + _glfw.win32.keycodes[0x06D] = GLFW_KEY_F22; + _glfw.win32.keycodes[0x06E] = GLFW_KEY_F23; + _glfw.win32.keycodes[0x076] = GLFW_KEY_F24; + _glfw.win32.keycodes[0x038] = GLFW_KEY_LEFT_ALT; + _glfw.win32.keycodes[0x01D] = GLFW_KEY_LEFT_CONTROL; + _glfw.win32.keycodes[0x02A] = GLFW_KEY_LEFT_SHIFT; + _glfw.win32.keycodes[0x15B] = GLFW_KEY_LEFT_SUPER; + _glfw.win32.keycodes[0x137] = GLFW_KEY_PRINT_SCREEN; + _glfw.win32.keycodes[0x138] = GLFW_KEY_RIGHT_ALT; + _glfw.win32.keycodes[0x11D] = GLFW_KEY_RIGHT_CONTROL; + _glfw.win32.keycodes[0x036] = GLFW_KEY_RIGHT_SHIFT; + _glfw.win32.keycodes[0x15C] = GLFW_KEY_RIGHT_SUPER; + _glfw.win32.keycodes[0x150] = GLFW_KEY_DOWN; + _glfw.win32.keycodes[0x14B] = GLFW_KEY_LEFT; + _glfw.win32.keycodes[0x14D] = GLFW_KEY_RIGHT; + _glfw.win32.keycodes[0x148] = GLFW_KEY_UP; + + _glfw.win32.keycodes[0x052] = GLFW_KEY_KP_0; + _glfw.win32.keycodes[0x04F] = GLFW_KEY_KP_1; + _glfw.win32.keycodes[0x050] = GLFW_KEY_KP_2; + _glfw.win32.keycodes[0x051] = GLFW_KEY_KP_3; + _glfw.win32.keycodes[0x04B] = GLFW_KEY_KP_4; + _glfw.win32.keycodes[0x04C] = GLFW_KEY_KP_5; + _glfw.win32.keycodes[0x04D] = GLFW_KEY_KP_6; + _glfw.win32.keycodes[0x047] = GLFW_KEY_KP_7; + _glfw.win32.keycodes[0x048] = GLFW_KEY_KP_8; + _glfw.win32.keycodes[0x049] = GLFW_KEY_KP_9; + _glfw.win32.keycodes[0x04E] = GLFW_KEY_KP_ADD; + _glfw.win32.keycodes[0x053] = GLFW_KEY_KP_DECIMAL; + _glfw.win32.keycodes[0x135] = GLFW_KEY_KP_DIVIDE; + _glfw.win32.keycodes[0x11C] = GLFW_KEY_KP_ENTER; + _glfw.win32.keycodes[0x037] = GLFW_KEY_KP_MULTIPLY; + _glfw.win32.keycodes[0x04A] = GLFW_KEY_KP_SUBTRACT; for (scancode = 0; scancode < 512; scancode++) { - if (_glfw.win32.publicKeys[scancode] > 0) - _glfw.win32.nativeKeys[_glfw.win32.publicKeys[scancode]] = scancode; + if (_glfw.win32.keycodes[scancode] > 0) + _glfw.win32.scancodes[_glfw.win32.keycodes[scancode]] = scancode; } } @@ -304,18 +305,19 @@ static void createKeyTables(void) // static HWND createHelperWindow(void) { + MSG msg; HWND window = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, _GLFW_WNDCLASSNAME, - L"GLFW helper window", + L"GLFW message window", WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 1, 1, - HWND_MESSAGE, NULL, + NULL, NULL, GetModuleHandleW(NULL), NULL); if (!window) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Win32: Failed to create helper window"); + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to create helper window"); return NULL; } @@ -336,6 +338,12 @@ static HWND createHelperWindow(void) DEVICE_NOTIFY_WINDOW_HANDLE); } + while (PeekMessageW(&msg, _glfw.win32.helperWindowHandle, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + return window; } @@ -353,12 +361,18 @@ WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source) length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0); if (!length) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to convert string from UTF-8"); return NULL; + } target = calloc(length, sizeof(WCHAR)); if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length)) { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to convert string from UTF-8"); free(target); return NULL; } @@ -375,12 +389,18 @@ char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source) length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL); if (!length) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to convert string to UTF-8"); return NULL; + } target = calloc(length, 1); if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length, NULL, NULL)) { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to convert string to UTF-8"); free(target); return NULL; } @@ -388,6 +408,27 @@ char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source) return target; } +// Reports the specified error, appending information about the last Win32 error +// +void _glfwInputErrorWin32(int error, const char* description) +{ + WCHAR buffer[_GLFW_MESSAGE_SIZE] = L""; + char message[_GLFW_MESSAGE_SIZE] = ""; + + FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL, + GetLastError() & 0xffff, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buffer, + sizeof(buffer), + NULL); + WideCharToMultiByte(CP_UTF8, 0, buffer, -1, message, sizeof(message), NULL, NULL); + + _glfwInputError(error, "%s: %s", description, message); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// @@ -395,9 +436,6 @@ char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source) int _glfwPlatformInit(void) { - if (!_glfwInitThreadLocalStorageWin32()) - return GLFW_FALSE; - // To make SetForegroundWindow work as we want, we need to fiddle // with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early // as possible in the hope of still being the foreground process) @@ -423,11 +461,10 @@ int _glfwPlatformInit(void) if (!_glfw.win32.helperWindowHandle) return GLFW_FALSE; - _glfwPlatformPollEvents(); - _glfwInitTimerWin32(); _glfwInitJoysticksWin32(); + _glfwPollMonitorsWin32(); return GLFW_TRUE; } @@ -444,12 +481,12 @@ void _glfwPlatformTerminate(void) SPIF_SENDCHANGE); free(_glfw.win32.clipboardString); + free(_glfw.win32.rawInput); _glfwTerminateWGL(); _glfwTerminateEGL(); _glfwTerminateJoysticksWin32(); - _glfwTerminateThreadLocalStorageWin32(); freeLibraries(); } diff --git a/libs/glfw/src/win32_joystick.cc b/libs/glfw/src/win32_joystick.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.1 Win32 - www.glfw.org +// GLFW 3.3 Win32 - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -27,13 +27,9 @@ #include "internal.h" +#include <stdio.h> #include <math.h> -#include <initguid.h> - -#define _GLFW_PRESENCE_ONLY 1 -#define _GLFW_UPDATE_STATE 2 - #define _GLFW_TYPE_AXIS 0 #define _GLFW_TYPE_SLIDER 1 #define _GLFW_TYPE_BUTTON 2 @@ -52,18 +48,29 @@ typedef struct _GLFWobjenumWin32 int povCount; } _GLFWobjenumWin32; -// Define only the necessary GUIDs (it's bad enough that we're exporting these) +// Define local copies of the necessary GUIDs // -DEFINE_GUID(IID_IDirectInput8W,0xbf798031,0x483a,0x4da2,0xaa,0x99,0x5d,0x64,0xed,0x36,0x97,0x00); -DEFINE_GUID(GUID_XAxis,0xa36d02e0,0xc9f3,0x11cf,0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00); -DEFINE_GUID(GUID_YAxis,0xa36d02e1,0xc9f3,0x11cf,0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00); -DEFINE_GUID(GUID_ZAxis,0xa36d02e2,0xc9f3,0x11cf,0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00); -DEFINE_GUID(GUID_RxAxis,0xa36d02f4,0xc9f3,0x11cf,0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00); -DEFINE_GUID(GUID_RyAxis,0xa36d02f5,0xc9f3,0x11cf,0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00); -DEFINE_GUID(GUID_RzAxis,0xa36d02e3,0xc9f3,0x11cf,0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00); -DEFINE_GUID(GUID_Slider,0xa36d02e4,0xc9f3,0x11cf,0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00); -DEFINE_GUID(GUID_Button,0xa36d02f0,0xc9f3,0x11cf,0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00); -DEFINE_GUID(GUID_POV,0xa36d02f2,0xc9f3,0x11cf,0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00); +static const GUID _glfw_IID_IDirectInput8W = {0xbf798031,0x483a,0x4da2,{0xaa,0x99,0x5d,0x64,0xed,0x36,0x97,0x00}}; +static const GUID _glfw_GUID_XAxis = {0xa36d02e0,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}}; +static const GUID _glfw_GUID_YAxis = {0xa36d02e1,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}}; +static const GUID _glfw_GUID_ZAxis = {0xa36d02e2,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}}; +static const GUID _glfw_GUID_RxAxis = {0xa36d02f4,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}}; +static const GUID _glfw_GUID_RyAxis = {0xa36d02f5,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}}; +static const GUID _glfw_GUID_RzAxis = {0xa36d02e3,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}}; +static const GUID _glfw_GUID_Slider = {0xa36d02e4,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}}; +static const GUID _glfw_GUID_Button = {0xa36d02f0,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}}; +static const GUID _glfw_GUID_POV = {0xa36d02f2,0xc9f3,0x11cf,{0xbf,0xc7,0x44,0x45,0x53,0x54,0x00,0x00}}; + +#define IID_IDirectInput8W _glfw_IID_IDirectInput8W +#define GUID_XAxis _glfw_GUID_XAxis +#define GUID_YAxis _glfw_GUID_YAxis +#define GUID_ZAxis _glfw_GUID_ZAxis +#define GUID_RxAxis _glfw_GUID_RxAxis +#define GUID_RyAxis _glfw_GUID_RyAxis +#define GUID_RzAxis _glfw_GUID_RzAxis +#define GUID_Slider _glfw_GUID_Slider +#define GUID_Button _glfw_GUID_Button +#define GUID_POV _glfw_GUID_POV // Object data array for our clone of c_dfDIJoystick // Generated with https://github.com/elmindreda/c_dfDIJoystick2 @@ -149,9 +156,9 @@ static const char* getDeviceDescription(const XINPUT_CAPABILITIES* xic) case XINPUT_DEVSUBTYPE_GAMEPAD: { if (xic->Flags & XINPUT_CAPS_WIRELESS) - return "Wireless Xbox 360 Controller"; + return "Wireless Xbox Controller"; else - return "Xbox 360 Controller"; + return "Xbox Controller"; } } @@ -238,25 +245,20 @@ static GLFWbool supportsXInput(const GUID* guid) // Frees all resources associated with the specified joystick // -static void closeJoystick(_GLFWjoystickWin32* js) +static void closeJoystick(_GLFWjoystick* js) { - if (js->device) + if (js->win32.device) { - IDirectInputDevice8_Unacquire(js->device); - IDirectInputDevice8_Release(js->device); + IDirectInputDevice8_Unacquire(js->win32.device); + IDirectInputDevice8_Release(js->win32.device); } - free(js->name); - free(js->axes); - free(js->buttons); - free(js->objects); - memset(js, 0, sizeof(_GLFWjoystickWin32)); - - _glfwInputJoystickChange((int) (js - _glfw.win32_js), GLFW_DISCONNECTED); + _glfwFreeJoystick(js); + _glfwInputJoystick(js, GLFW_DISCONNECTED); } // DirectInput device object enumeration callback -// Insights gleaned from SDL2 +// Insights gleaned from SDL // static BOOL CALLBACK deviceObjectCallback(const DIDEVICEOBJECTINSTANCEW* doi, void* user) @@ -332,28 +334,23 @@ static BOOL CALLBACK deviceObjectCallback(const DIDEVICEOBJECTINSTANCEW* doi, // static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user) { - int joy = 0; + int jid = 0; DIDEVCAPS dc; DIPROPDWORD dipd; IDirectInputDevice8* device; _GLFWobjenumWin32 data; - _GLFWjoystickWin32* js; + _GLFWjoystick* js; + char guid[33]; + char name[256]; - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) { - if (memcmp(&_glfw.win32_js[joy].guid, &di->guidInstance, sizeof(GUID)) == 0) + if (!_glfw.joysticks[jid].present) + continue; + if (memcmp(&_glfw.joysticks[jid].win32.guid, &di->guidInstance, sizeof(GUID)) == 0) return DIENUM_CONTINUE; } - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) - { - if (!_glfw.win32_js[joy].present) - break; - } - - if (joy > GLFW_JOYSTICK_LAST) - return DIENUM_STOP; - if (supportsXInput(&di->guidProduct)) return DIENUM_CONTINUE; @@ -362,14 +359,14 @@ static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user) &device, NULL))) { - _glfwInputError(GLFW_PLATFORM_ERROR, "DI: Failed to create device"); + _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to create device"); return DIENUM_CONTINUE; } if (FAILED(IDirectInputDevice8_SetDataFormat(device, &_glfwDataFormat))) { _glfwInputError(GLFW_PLATFORM_ERROR, - "DI: Failed to set device data format"); + "Win32: Failed to set device data format"); IDirectInputDevice8_Release(device); return DIENUM_CONTINUE; @@ -381,7 +378,7 @@ static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user) if (FAILED(IDirectInputDevice8_GetCapabilities(device, &dc))) { _glfwInputError(GLFW_PLATFORM_ERROR, - "DI: Failed to query device capabilities"); + "Win32: Failed to query device capabilities"); IDirectInputDevice8_Release(device); return DIENUM_CONTINUE; @@ -398,7 +395,7 @@ static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user) &dipd.diph))) { _glfwInputError(GLFW_PLATFORM_ERROR, - "DI: Failed to set device axis mode"); + "Win32: Failed to set device axis mode"); IDirectInputDevice8_Release(device); return DIENUM_CONTINUE; @@ -415,7 +412,7 @@ static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user) DIDFT_AXIS | DIDFT_BUTTON | DIDFT_POV))) { _glfwInputError(GLFW_PLATFORM_ERROR, - "DI: Failed to enumerate device objects"); + "Win32: Failed to enumerate device objects"); IDirectInputDevice8_Release(device); free(data.objects); @@ -426,89 +423,190 @@ static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user) sizeof(_GLFWjoyobjectWin32), compareJoystickObjects); - js = _glfw.win32_js + joy; - js->device = device; - js->guid = di->guidInstance; - js->axisCount = data.axisCount + data.sliderCount; - js->axes = calloc(js->axisCount, sizeof(float)); - js->buttonCount += data.buttonCount + data.povCount * 4; - js->buttons = calloc(js->buttonCount, 1); - js->objects = data.objects; - js->objectCount = data.objectCount; - js->name = _glfwCreateUTF8FromWideStringWin32(di->tszInstanceName); - js->present = GLFW_TRUE; - - _glfwInputJoystickChange(joy, GLFW_CONNECTED); + if (!WideCharToMultiByte(CP_UTF8, 0, + di->tszInstanceName, -1, + name, sizeof(name), + NULL, NULL)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Win32: Failed to convert joystick name to UTF-8"); + + IDirectInputDevice8_Release(device); + free(data.objects); + return DIENUM_STOP; + } + + // Generate a joystick GUID that matches the SDL 2.0.5+ one + if (memcmp(&di->guidProduct.Data4[2], "PIDVID", 6) == 0) + { + sprintf(guid, "03000000%02x%02x0000%02x%02x000000000000", + (uint8_t) di->guidProduct.Data1, + (uint8_t) (di->guidProduct.Data1 >> 8), + (uint8_t) (di->guidProduct.Data1 >> 16), + (uint8_t) (di->guidProduct.Data1 >> 24)); + } + else + { + sprintf(guid, "05000000%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x00", + name[0], name[1], name[2], name[3], + name[4], name[5], name[6], name[7], + name[8], name[9], name[10]); + } + + js = _glfwAllocJoystick(name, guid, + data.axisCount + data.sliderCount, + data.buttonCount, + data.povCount); + if (!js) + { + IDirectInputDevice8_Release(device); + free(data.objects); + return DIENUM_STOP; + } + + js->win32.device = device; + js->win32.guid = di->guidInstance; + js->win32.objects = data.objects; + js->win32.objectCount = data.objectCount; + + _glfwInputJoystick(js, GLFW_CONNECTED); return DIENUM_CONTINUE; } -// Attempt to open the specified joystick device -// TODO: Pack state arrays for non-gamepad devices + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +// Initialize joystick interface // -static GLFWbool openXinputDevice(DWORD index) +void _glfwInitJoysticksWin32(void) { - int joy; - XINPUT_CAPABILITIES xic; - _GLFWjoystickWin32* js; - - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) + if (_glfw.win32.dinput8.instance) { - if (_glfw.win32_js[joy].present && - _glfw.win32_js[joy].device == NULL && - _glfw.win32_js[joy].index == index) + if (FAILED(DirectInput8Create(GetModuleHandle(NULL), + DIRECTINPUT_VERSION, + &IID_IDirectInput8W, + (void**) &_glfw.win32.dinput8.api, + NULL))) { - return GLFW_FALSE; + _glfwInputError(GLFW_PLATFORM_ERROR, + "Win32: Failed to create interface"); } } - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) + _glfwDetectJoystickConnectionWin32(); +} + +// Close all opened joystick handles +// +void _glfwTerminateJoysticksWin32(void) +{ + int jid; + + for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++) + closeJoystick(_glfw.joysticks + jid); + + if (_glfw.win32.dinput8.api) + IDirectInput8_Release(_glfw.win32.dinput8.api); +} + +// Checks for new joysticks after DBT_DEVICEARRIVAL +// +void _glfwDetectJoystickConnectionWin32(void) +{ + if (_glfw.win32.xinput.instance) { - if (!_glfw.win32_js[joy].present) - break; - } + DWORD index; - if (joy > GLFW_JOYSTICK_LAST) - return GLFW_FALSE; + for (index = 0; index < XUSER_MAX_COUNT; index++) + { + int jid; + char guid[33]; + XINPUT_CAPABILITIES xic; + _GLFWjoystick* js; - if (_glfw_XInputGetCapabilities(index, 0, &xic) != ERROR_SUCCESS) - return GLFW_FALSE; + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) + { + if (_glfw.joysticks[jid].present && + _glfw.joysticks[jid].win32.device == NULL && + _glfw.joysticks[jid].win32.index == index) + { + break; + } + } - js = _glfw.win32_js + joy; - js->axisCount = 6; - js->axes = calloc(js->axisCount, sizeof(float)); - js->buttonCount = 14; - js->buttons = calloc(js->buttonCount, 1); - js->present = GLFW_TRUE; - js->name = strdup(getDeviceDescription(&xic)); - js->index = index; + if (jid <= GLFW_JOYSTICK_LAST) + continue; - _glfwInputJoystickChange(joy, GLFW_CONNECTED); + if (XInputGetCapabilities(index, 0, &xic) != ERROR_SUCCESS) + continue; - return GLFW_TRUE; + // Generate a joystick GUID that matches the SDL 2.0.5+ one + sprintf(guid, "78696e707574%02x000000000000000000", + xic.SubType & 0xff); + + js = _glfwAllocJoystick(getDeviceDescription(&xic), guid, 6, 10, 1); + if (!js) + continue; + + js->win32.index = index; + + _glfwInputJoystick(js, GLFW_CONNECTED); + } + } + + if (_glfw.win32.dinput8.api) + { + if (FAILED(IDirectInput8_EnumDevices(_glfw.win32.dinput8.api, + DI8DEVCLASS_GAMECTRL, + deviceCallback, + NULL, + DIEDFL_ALLDEVICES))) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Failed to enumerate DirectInput8 devices"); + return; + } + } } -// Polls for and processes events the specified joystick +// Checks for joystick disconnection after DBT_DEVICEREMOVECOMPLETE // -static GLFWbool pollJoystickState(_GLFWjoystickWin32* js, int mode) +void _glfwDetectJoystickDisconnectionWin32(void) { - if (!js->present) - return GLFW_FALSE; + int jid; + + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) + { + _GLFWjoystick* js = _glfw.joysticks + jid; + if (js->present) + _glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE); + } +} + - if (js->device) +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode) +{ + if (js->win32.device) { - int i, j, ai = 0, bi = 0; + int i, ai = 0, bi = 0, pi = 0; HRESULT result; DIJOYSTATE state; - IDirectInputDevice8_Poll(js->device); - result = IDirectInputDevice8_GetDeviceState(js->device, + IDirectInputDevice8_Poll(js->win32.device); + result = IDirectInputDevice8_GetDeviceState(js->win32.device, sizeof(state), &state); if (result == DIERR_NOTACQUIRED || result == DIERR_INPUTLOST) { - IDirectInputDevice8_Acquire(js->device); - IDirectInputDevice8_Poll(js->device); - result = IDirectInputDevice8_GetDeviceState(js->device, + IDirectInputDevice8_Acquire(js->win32.device); + IDirectInputDevice8_Poll(js->win32.device); + result = IDirectInputDevice8_GetDeviceState(js->win32.device, sizeof(state), &state); } @@ -519,61 +617,65 @@ static GLFWbool pollJoystickState(_GLFWjoystickWin32* js, int mode) return GLFW_FALSE; } - if (mode == _GLFW_PRESENCE_ONLY) + if (mode == _GLFW_POLL_PRESENCE) return GLFW_TRUE; - for (i = 0; i < js->objectCount; i++) + for (i = 0; i < js->win32.objectCount; i++) { - const void* data = (char*) &state + js->objects[i].offset; + const void* data = (char*) &state + js->win32.objects[i].offset; - switch (js->objects[i].type) + switch (js->win32.objects[i].type) { case _GLFW_TYPE_AXIS: case _GLFW_TYPE_SLIDER: { - js->axes[ai++] = (*((LONG*) data) + 0.5f) / 32767.5f; + const float value = (*((LONG*) data) + 0.5f) / 32767.5f; + _glfwInputJoystickAxis(js, ai, value); + ai++; break; } case _GLFW_TYPE_BUTTON: { - if (*((BYTE*) data) & 0x80) - js->buttons[bi++] = GLFW_PRESS; - else - js->buttons[bi++] = GLFW_RELEASE; - + const char value = (*((BYTE*) data) & 0x80) != 0; + _glfwInputJoystickButton(js, bi, value); + bi++; break; } case _GLFW_TYPE_POV: { - const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; - // Screams of horror are appropriate at this point - int value = LOWORD(*(DWORD*) data) / (45 * DI_DEGREES); - if (value < 0 || value > 8) - value = 8; - - for (j = 0; j < 4; j++) + const int states[9] = { - if (directions[value] & (1 << j)) - js->buttons[bi++] = GLFW_PRESS; - else - js->buttons[bi++] = GLFW_RELEASE; - } + GLFW_HAT_UP, + GLFW_HAT_RIGHT_UP, + GLFW_HAT_RIGHT, + GLFW_HAT_RIGHT_DOWN, + GLFW_HAT_DOWN, + GLFW_HAT_LEFT_DOWN, + GLFW_HAT_LEFT, + GLFW_HAT_LEFT_UP, + GLFW_HAT_CENTERED + }; + + // Screams of horror are appropriate at this point + int state = LOWORD(*(DWORD*) data) / (45 * DI_DEGREES); + if (state < 0 || state > 8) + state = 8; + _glfwInputJoystickHat(js, pi, states[state]); + pi++; break; } } } - - return GLFW_TRUE; } else { - int i; + int i, dpad = 0; DWORD result; XINPUT_STATE xis; - const WORD buttons[14] = + const WORD buttons[10] = { XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, @@ -584,14 +686,10 @@ static GLFWbool pollJoystickState(_GLFWjoystickWin32* js, int mode) XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_START, XINPUT_GAMEPAD_LEFT_THUMB, - XINPUT_GAMEPAD_RIGHT_THUMB, - XINPUT_GAMEPAD_DPAD_UP, - XINPUT_GAMEPAD_DPAD_RIGHT, - XINPUT_GAMEPAD_DPAD_DOWN, - XINPUT_GAMEPAD_DPAD_LEFT + XINPUT_GAMEPAD_RIGHT_THUMB }; - result = _glfw_XInputGetState(js->index, &xis); + result = XInputGetState(js->win32.index, &xis); if (result != ERROR_SUCCESS) { if (result == ERROR_DEVICE_NOT_CONNECTED) @@ -600,164 +698,45 @@ static GLFWbool pollJoystickState(_GLFWjoystickWin32* js, int mode) return GLFW_FALSE; } - if (mode == _GLFW_PRESENCE_ONLY) + if (mode == _GLFW_POLL_PRESENCE) return GLFW_TRUE; - if (sqrt((double) (xis.Gamepad.sThumbLX * xis.Gamepad.sThumbLX + - xis.Gamepad.sThumbLY * xis.Gamepad.sThumbLY)) > - (double) XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) - { - js->axes[0] = (xis.Gamepad.sThumbLX + 0.5f) / 32767.f; - js->axes[1] = (xis.Gamepad.sThumbLY + 0.5f) / 32767.f; - } - else - { - js->axes[0] = 0.f; - js->axes[1] = 0.f; - } + _glfwInputJoystickAxis(js, 0, (xis.Gamepad.sThumbLX + 0.5f) / 32767.5f); + _glfwInputJoystickAxis(js, 1, (xis.Gamepad.sThumbLY + 0.5f) / 32767.5f); + _glfwInputJoystickAxis(js, 2, (xis.Gamepad.sThumbRX + 0.5f) / 32767.5f); + _glfwInputJoystickAxis(js, 3, (xis.Gamepad.sThumbRY + 0.5f) / 32767.5f); + _glfwInputJoystickAxis(js, 4, xis.Gamepad.bLeftTrigger / 127.5f - 1.f); + _glfwInputJoystickAxis(js, 5, xis.Gamepad.bRightTrigger / 127.5f - 1.f); - if (sqrt((double) (xis.Gamepad.sThumbRX * xis.Gamepad.sThumbRX + - xis.Gamepad.sThumbRY * xis.Gamepad.sThumbRY)) > - (double) XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) - { - js->axes[2] = (xis.Gamepad.sThumbRX + 0.5f) / 32767.f; - js->axes[3] = (xis.Gamepad.sThumbRY + 0.5f) / 32767.f; - } - else + for (i = 0; i < 10; i++) { - js->axes[2] = 0.f; - js->axes[3] = 0.f; + const char value = (xis.Gamepad.wButtons & buttons[i]) ? 1 : 0; + _glfwInputJoystickButton(js, i, value); } - if (xis.Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD) - js->axes[4] = xis.Gamepad.bLeftTrigger / 127.5f - 1.f; - else - js->axes[4] = -1.f; - - if (xis.Gamepad.bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD) - js->axes[5] = xis.Gamepad.bRightTrigger / 127.5f - 1.f; - else - js->axes[5] = -1.f; + if (xis.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) + dpad |= GLFW_HAT_UP; + if (xis.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) + dpad |= GLFW_HAT_RIGHT; + if (xis.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) + dpad |= GLFW_HAT_DOWN; + if (xis.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) + dpad |= GLFW_HAT_LEFT; - for (i = 0; i < 14; i++) - js->buttons[i] = (xis.Gamepad.wButtons & buttons[i]) ? 1 : 0; - - return GLFW_TRUE; + _glfwInputJoystickHat(js, 0, dpad); } -} - - -////////////////////////////////////////////////////////////////////////// -////// GLFW internal API ////// -////////////////////////////////////////////////////////////////////////// - -// Initialize joystick interface -// -void _glfwInitJoysticksWin32(void) -{ - if (_glfw.win32.dinput8.instance) - { - if (FAILED(_glfw_DirectInput8Create(GetModuleHandle(NULL), - DIRECTINPUT_VERSION, - &IID_IDirectInput8W, - (void**) &_glfw.win32.dinput8.api, - NULL))) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "DI: Failed to create interface"); - } - } - - _glfwDetectJoystickConnectionWin32(); -} - -// Close all opened joystick handles -// -void _glfwTerminateJoysticksWin32(void) -{ - int joy; - - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) - closeJoystick(_glfw.win32_js + joy); - if (_glfw.win32.dinput8.api) - IDirectInput8_Release(_glfw.win32.dinput8.api); + return GLFW_TRUE; } -// Checks for new joysticks after DBT_DEVICEARRIVAL -// -void _glfwDetectJoystickConnectionWin32(void) +void _glfwPlatformUpdateGamepadGUID(char* guid) { - if (_glfw.win32.xinput.instance) + if (strcmp(guid + 20, "504944564944") == 0) { - DWORD i; - - for (i = 0; i < XUSER_MAX_COUNT; i++) - openXinputDevice(i); + char original[33]; + strcpy(original, guid); + sprintf(guid, "03000000%.4s0000%.4s000000000000", + original, original + 4); } - - if (_glfw.win32.dinput8.api) - { - if (FAILED(IDirectInput8_EnumDevices(_glfw.win32.dinput8.api, - DI8DEVCLASS_GAMECTRL, - deviceCallback, - NULL, - DIEDFL_ALLDEVICES))) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Failed to enumerate DirectInput8 devices"); - return; - } - } -} - -// Checks for joystick disconnection after DBT_DEVICEREMOVECOMPLETE -// -void _glfwDetectJoystickDisconnectionWin32(void) -{ - int joy; - - for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) - pollJoystickState(_glfw.win32_js + joy, _GLFW_PRESENCE_ONLY); -} - - -////////////////////////////////////////////////////////////////////////// -////// GLFW platform API ////// -////////////////////////////////////////////////////////////////////////// - -int _glfwPlatformJoystickPresent(int joy) -{ - _GLFWjoystickWin32* js = _glfw.win32_js + joy; - return pollJoystickState(js, _GLFW_PRESENCE_ONLY); -} - -const float* _glfwPlatformGetJoystickAxes(int joy, int* count) -{ - _GLFWjoystickWin32* js = _glfw.win32_js + joy; - if (!pollJoystickState(js, _GLFW_UPDATE_STATE)) - return NULL; - - *count = js->axisCount; - return js->axes; -} - -const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) -{ - _GLFWjoystickWin32* js = _glfw.win32_js + joy; - if (!pollJoystickState(js, _GLFW_UPDATE_STATE)) - return NULL; - - *count = js->buttonCount; - return js->buttons; -} - -const char* _glfwPlatformGetJoystickName(int joy) -{ - _GLFWjoystickWin32* js = _glfw.win32_js + joy; - if (!pollJoystickState(js, _GLFW_PRESENCE_ONLY)) - return NULL; - - return js->name; } diff --git a/libs/glfw/src/win32_joystick.h b/libs/glfw/src/win32_joystick.h @@ -1,7 +1,7 @@ //======================================================================== -// GLFW 3.2 Win32 - www.glfw.org +// GLFW 3.3 Win32 - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -24,11 +24,10 @@ // //======================================================================== -#ifndef _glfw3_win32_joystick_h_ -#define _glfw3_win32_joystick_h_ +#define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickWin32 win32 +#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE int dummy -#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ - _GLFWjoystickWin32 win32_js[GLFW_JOYSTICK_LAST + 1] +#define _GLFW_PLATFORM_MAPPING_NAME "Windows" // Joystick element (axis, button or slider) // @@ -42,14 +41,8 @@ typedef struct _GLFWjoyobjectWin32 // typedef struct _GLFWjoystickWin32 { - GLFWbool present; - float* axes; - int axisCount; - unsigned char* buttons; - int buttonCount; _GLFWjoyobjectWin32* objects; int objectCount; - char* name; IDirectInputDevice8W* device; DWORD index; GUID guid; @@ -61,4 +54,3 @@ void _glfwTerminateJoysticksWin32(void); void _glfwDetectJoystickConnectionWin32(void); void _glfwDetectJoystickDisconnectionWin32(void); -#endif // _glfw3_win32_joystick_h_ diff --git a/libs/glfw/src/win32_monitor.cc b/libs/glfw/src/win32_monitor.cc @@ -1,8 +1,8 @@ //======================================================================== -// GLFW 3.2 Win32 - www.glfw.org +// GLFW 3.3 Win32 - www.glfw.org //------------------------------------------------------------------------ // Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> +// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org> // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -47,11 +47,7 @@ static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter, else name = _glfwCreateUTF8FromWideStringWin32(adapter->DeviceString); if (!name) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Win32: Failed to convert string to UTF-8"); return NULL; - } dc = CreateDCW(L"DISPLAY", adapter->DeviceName, NULL, NULL); @@ -90,6 +86,116 @@ static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter, ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// +// Poll for changes in the set of connected monitors +// +void _glfwPollMonitorsWin32(void) +{ + int i, disconnectedCount; + _GLFWmonitor** disconnected = NULL; + DWORD adapterIndex, displayIndex; + DISPLAY_DEVICEW adapter, display; + _GLFWmonitor* monitor; + + disconnectedCount = _glfw.monitorCount; + if (disconnectedCount) + { + disconnected = calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*)); + memcpy(disconnected, + _glfw.monitors, + _glfw.monitorCount * sizeof(_GLFWmonitor*)); + } + + for (adapterIndex = 0; ; adapterIndex++) + { + int type = _GLFW_INSERT_LAST; + + ZeroMemory(&adapter, sizeof(DISPLAY_DEVICEW)); + adapter.cb = sizeof(DISPLAY_DEVICEW); + + if (!EnumDisplayDevicesW(NULL, adapterIndex, &adapter, 0)) + break; + + if (!(adapter.StateFlags & DISPLAY_DEVICE_ACTIVE)) + continue; + + if (adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) + type = _GLFW_INSERT_FIRST; + + for (displayIndex = 0; ; displayIndex++) + { + ZeroMemory(&display, sizeof(DISPLAY_DEVICEW)); + display.cb = sizeof(DISPLAY_DEVICEW); + + if (!EnumDisplayDevicesW(adapter.DeviceName, displayIndex, &display, 0)) + break; + + if (!(display.StateFlags & DISPLAY_DEVICE_ACTIVE)) + continue; + + for (i = 0; i < disconnectedCount; i++) + { + if (disconnected[i] && + wcscmp(disconnected[i]->win32.displayName, + display.DeviceName) == 0) + { + disconnected[i] = NULL; + break; + } + } + + if (i < disconnectedCount) + continue; + + monitor = createMonitor(&adapter, &display); + if (!monitor) + { + free(disconnected); + return; + } + + _glfwInputMonitor(monitor, GLFW_CONNECTED, type); + + type = _GLFW_INSERT_LAST; + } + + // HACK: If an active adapter does not have any display devices + // (as sometimes happens), add it directly as a monitor + if (displayIndex == 0) + { + for (i = 0; i < disconnectedCount; i++) + { + if (disconnected[i] && + wcscmp(disconnected[i]->win32.adapterName, + adapter.DeviceName) == 0)