Merge branch 'master' into pr/1

This commit is contained in:
cats studio 2024-01-20 18:14:39 +00:00 committed by GitHub
commit 37d31948a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
101 changed files with 14590 additions and 4144 deletions

View File

@ -15,10 +15,10 @@ environment:
- GENERATOR: MinGW Makefiles - GENERATOR: MinGW Makefiles
BUILD_SHARED_LIBS: OFF BUILD_SHARED_LIBS: OFF
CFLAGS: -Werror CFLAGS: -Werror
- GENERATOR: Visual Studio 10 2010 - GENERATOR: Visual Studio 12 2013
BUILD_SHARED_LIBS: ON BUILD_SHARED_LIBS: ON
CFLAGS: /WX CFLAGS: /WX
- GENERATOR: Visual Studio 10 2010 - GENERATOR: Visual Studio 12 2013
BUILD_SHARED_LIBS: OFF BUILD_SHARED_LIBS: OFF
CFLAGS: /WX CFLAGS: /WX
matrix: matrix:
@ -30,14 +30,14 @@ for:
- GENERATOR: MinGW Makefiles - GENERATOR: MinGW Makefiles
build_script: build_script:
- set PATH=%PATH:C:\Program Files\Git\usr\bin=C:\MinGW\bin% - set PATH=%PATH:C:\Program Files\Git\usr\bin=C:\MinGW\bin%
- cmake -S . -B build -G "%GENERATOR%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% - cmake -B build -G "%GENERATOR%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS%
- cmake --build build - cmake --build build
- -
matrix: matrix:
only: only:
- GENERATOR: Visual Studio 10 2010 - GENERATOR: Visual Studio 12 2013
build_script: build_script:
- cmake -S . -B build -G "%GENERATOR%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% - cmake -B build -G "%GENERATOR%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS%
- cmake --build build --target glfw - cmake --build build --target glfw
notifications: notifications:
- provider: Email - provider: Email

67
.editorconfig Normal file
View File

@ -0,0 +1,67 @@
# EditorConfig for GLFW and its internal dependencies
#
# All files created by GLFW should indent with four spaces unless their format requires
# otherwise. A few files still use other indent styles for historical reasons.
#
# Dependencies have (what seemed to be) their existing styles described. Those with
# existing trailing whitespace have it preserved to avoid cluttering future commits.
root = true
[*]
charset = utf-8
end_of_line = lf
[include/GLFW/*.h]
indent_style = space
indent_size = 4
[{src,examples,tests}/*.{c,m,h,rc,in}]
indent_style = space
indent_size = 4
[CMakeLists.txt]
indent_style = space
indent_size = 4
[CMake/**.{cmake,in}]
indent_style = space
indent_size = 4
[*.{dox,md}]
indent_style = space
indent_size = 4
trim_trailing_whitespace = false
[DoxygenLayout.xml]
indent_style = space
indent_size = 2
[docs/*.{scss,html}]
indent_style = tab
indent_size = unset
[deps/mingw/*.h]
indent_style = space
indent_size = 4
tab_width = 8
trim_trailing_whitespace = false
[deps/getopt.{c,h}]
indent_style = space
indent_size = 2
[deps/linmath.h]
indent_style = tab
tab_width = 4
indent_size = 4
trim_trailing_whitespace = false
[deps/nuklear*.h]
indent_style = space
indent_size = 4
[deps/tinycthread.{c,h}]
indent_style = space
indent_size = 2

View File

@ -1,8 +1,6 @@
* @elmindreda * @elmindreda
src/wl_* @linkmauve
docs/*.css @glfw/webdev docs/*.css @glfw/webdev
docs/*.scss @glfw/webdev docs/*.scss @glfw/webdev
docs/*.html @glfw/webdev docs/*.html @glfw/webdev

View File

@ -3,91 +3,98 @@ on:
pull_request: pull_request:
push: push:
branches: [ ci, master, latest, 3.3-stable ] branches: [ ci, master, latest, 3.3-stable ]
workflow_dispatch:
permissions: permissions:
statuses: write statuses: write
contents: read contents: read
jobs: jobs:
build-linux-x11-clang: build-linux-clang:
name: X11 (Linux, Clang) name: Linux (Clang)
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 4
env: env:
CC: clang CC: clang
CFLAGS: -Werror CFLAGS: -Werror
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Install dependencies - name: Install dependencies
run: | run: |
sudo apt update sudo apt update
sudo apt install libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev sudo apt install libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev libwayland-dev libxkbcommon-dev
- name: Configure static library - name: Configure Null shared library
run: cmake -S . -B build-static run: cmake -B build-null-shared -D GLFW_BUILD_WAYLAND=OFF -D GLFW_BUILD_X11=OFF -D BUILD_SHARED_LIBS=ON
- name: Build static library - name: Build Null shared library
run: cmake --build build-static --parallel run: cmake --build build-null-shared --parallel
- name: Configure shared library - name: Configure X11 shared library
run: cmake -S . -B build-shared -D BUILD_SHARED_LIBS=ON run: cmake -B build-x11-shared -D GLFW_BUILD_WAYLAND=OFF -D GLFW_BUILD_X11=ON -D BUILD_SHARED_LIBS=ON
- name: Build shared library - name: Build X11 shared library
run: cmake --build build-shared --parallel run: cmake --build build-x11-shared --parallel
build-linux-full-clang: - name: Configure Wayland shared library
name: X11+Wayland (Linux, Clang) run: cmake -B build-wayland-shared -D GLFW_BUILD_WAYLAND=ON -D GLFW_BUILD_X11=OFF -D BUILD_SHARED_LIBS=ON
runs-on: ubuntu-latest - name: Build Wayland shared library
env: run: cmake --build build-wayland-shared --parallel
CC: clang
CFLAGS: -Werror
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt update
sudo apt install libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev wayland-protocols libwayland-dev libxkbcommon-dev
- name: Configure static library - name: Configure Wayland+X11 static library
run: cmake -S . -B build-static -D GLFW_BUILD_WAYLAND=ON run: cmake -B build-full-static -D GLFW_BUILD_WAYLAND=ON -D GLFW_BUILD_X11=ON
- name: Build static library - name: Build Wayland+X11 static library
run: cmake --build build-static --parallel run: cmake --build build-full-static --parallel
- name: Configure shared library - name: Configure Wayland+X11 shared library
run: cmake -S . -B build-shared -D GLFW_BUILD_WAYLAND=ON -D BUILD_SHARED_LIBS=ON run: cmake -B build-full-shared -D GLFW_BUILD_WAYLAND=ON -D BUILD_SHARED_LIBS=ON -D GLFW_BUILD_X11=ON
- name: Build shared library - name: Build Wayland+X11 shared library
run: cmake --build build-shared --parallel run: cmake --build build-full-shared --parallel
build-macos-cocoa-clang: build-macos-clang:
name: Cocoa (macOS, Clang) name: macOS (Clang)
runs-on: macos-latest runs-on: macos-latest
timeout-minutes: 4
env: env:
CFLAGS: -Werror CFLAGS: -Werror
MACOSX_DEPLOYMENT_TARGET: 10.8 MACOSX_DEPLOYMENT_TARGET: 10.8
CMAKE_OSX_ARCHITECTURES: x86_64;arm64
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Configure static library - name: Configure Null shared library
run: cmake -S . -B build-static run: cmake -B build-null-shared -D GLFW_BUILD_COCOA=OFF -D BUILD_SHARED_LIBS=ON
- name: Build static library - name: Build Null shared library
run: cmake --build build-static --parallel run: cmake --build build-null-shared --parallel
- name: Configure shared library - name: Configure Cocoa static library
run: cmake -S . -B build-shared -D BUILD_SHARED_LIBS=ON run: cmake -B build-cocoa-static
- name: Build shared library - name: Build Cocoa static library
run: cmake --build build-shared --parallel run: cmake --build build-cocoa-static --parallel
build-windows-win32-vs2019: - name: Configure Cocoa shared library
name: Win32 (Windows, VS2019) run: cmake -B build-cocoa-shared -D BUILD_SHARED_LIBS=ON
- name: Build Cocoa shared library
run: cmake --build build-cocoa-shared --parallel
build-windows-vs2022:
name: Windows (VS2022)
runs-on: windows-latest runs-on: windows-latest
timeout-minutes: 4
env: env:
CFLAGS: /WX CFLAGS: /WX
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Configure static library - name: Configure Win32 shared x86 library
run: cmake -S . -B build-static -G "Visual Studio 16 2019" run: cmake -B build-win32-shared-x86 -G "Visual Studio 17 2022" -A Win32 -D BUILD_SHARED_LIBS=ON
- name: Build static library - name: Build Win32 shared x86 library
run: cmake --build build-static --parallel run: cmake --build build-win32-shared-x86 --parallel
- name: Configure shared library - name: Configure Win32 static x64 library
run: cmake -S . -B build-shared -G "Visual Studio 16 2019" -D BUILD_SHARED_LIBS=ON run: cmake -B build-win32-static-x64 -G "Visual Studio 17 2022" -A x64
- name: Build shared library - name: Build Win32 static x64 library
run: cmake --build build-shared --parallel run: cmake --build build-win32-static-x64 --parallel
- name: Configure Win32 shared x64 library
run: cmake -B build-win32-shared-x64 -G "Visual Studio 17 2022" -A x64 -D BUILD_SHARED_LIBS=ON
- name: Build Win32 shared x64 library
run: cmake --build build-win32-shared-x64 --parallel

3
.gitignore vendored
View File

@ -1,5 +1,4 @@
# External junk
.DS_Store
_ReSharper* _ReSharper*
*.opensdf *.opensdf
*.sdf *.sdf

View File

@ -8,6 +8,6 @@ Description: A multi-platform library for OpenGL, window and input
Version: @GLFW_VERSION@ Version: @GLFW_VERSION@
URL: https://www.glfw.org/ URL: https://www.glfw.org/
Requires.private: @GLFW_PKG_CONFIG_REQUIRES_PRIVATE@ Requires.private: @GLFW_PKG_CONFIG_REQUIRES_PRIVATE@
Libs: -L${libdir} -l@GLFW_LIB_NAME@ Libs: -L${libdir} -l@GLFW_LIB_NAME@@GLFW_LIB_NAME_SUFFIX@
Libs.private: @GLFW_PKG_CONFIG_LIBS_PRIVATE@ Libs.private: @GLFW_PKG_CONFIG_LIBS_PRIVATE@
Cflags: -I${includedir} Cflags: -I${includedir}

View File

@ -2,12 +2,6 @@ cmake_minimum_required(VERSION 3.4...3.20 FATAL_ERROR)
project(GLFW VERSION 3.4.0 LANGUAGES C) project(GLFW VERSION 3.4.0 LANGUAGES C)
set(CMAKE_LEGACY_CYGWIN_WIN32 OFF)
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
if (POLICY CMP0069) if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW) cmake_policy(SET CMP0069 NEW)
endif() endif()
@ -18,9 +12,7 @@ endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) string(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" GLFW_STANDALONE)
set(GLFW_STANDALONE TRUE)
endif()
option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ${GLFW_STANDALONE}) option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ${GLFW_STANDALONE})

View File

@ -8,8 +8,10 @@ video tutorials.
- Bobyshev Alexander - Bobyshev Alexander
- Laurent Aphecetche - Laurent Aphecetche
- Matt Arsenault - Matt Arsenault
- Takuro Ashie
- ashishgamedev - ashishgamedev
- David Avedissian - David Avedissian
- Luca Bacci
- Keith Bauer - Keith Bauer
- John Bartholomew - John Bartholomew
- Coşku Baş - Coşku Baş
@ -18,17 +20,21 @@ video tutorials.
- Nevyn Bengtsson - Nevyn Bengtsson
- Niklas Bergström - Niklas Bergström
- Denis Bernard - Denis Bernard
- BiBi
- Doug Binks - Doug Binks
- blanco - blanco
- Waris Boonyasiriwat - Waris Boonyasiriwat
- Kyle Brenneman - Kyle Brenneman
- Rok Breulj - Rok Breulj
- TheBrokenRail
- Kai Burjack - Kai Burjack
- Martin Capitanio - Martin Capitanio
- Nicolas Caramelli - Nicolas Caramelli
- David Carlier - David Carlier
- Arturo Castro - Arturo Castro
- Chi-kwan Chan - Chi-kwan Chan
- TheChocolateOre
- Ali Chraghi
- Joseph Chua - Joseph Chua
- Ian Clarkson - Ian Clarkson
- Michał Cichoń - Michał Cichoń
@ -42,6 +48,7 @@ video tutorials.
- Noel Cower - Noel Cower
- CuriouserThing - CuriouserThing
- Jason Daly - Jason Daly
- danhambleton
- Jarrod Davis - Jarrod Davis
- Olivier Delannoy - Olivier Delannoy
- Paul R. Deppe - Paul R. Deppe
@ -56,35 +63,49 @@ video tutorials.
- Jan Ekström - Jan Ekström
- Siavash Eliasi - Siavash Eliasi
- Ahmad Fatoum - Ahmad Fatoum
- Nikita Fediuchin
- Felipe Ferreira - Felipe Ferreira
- Michael Fogleman - Michael Fogleman
- forworldm
- Jason Francis - Jason Francis
- Gerald Franz - Gerald Franz
- Mário Freitas - Mário Freitas
- GeO4d - GeO4d
- Marcus Geelnard - Marcus Geelnard
- Gegy
- ghuser404 - ghuser404
- Charles Giessen - Charles Giessen
- Ryan C. Gordon - Ryan C. Gordon
- Stephen Gowen - Stephen Gowen
- Kovid Goyal - Kovid Goyal
- Kevin Grandemange
- Eloi Marín Gratacós - Eloi Marín Gratacós
- Grzesiek11
- Stefan Gustavson - Stefan Gustavson
- Andrew Gutekanst - Andrew Gutekanst
- Stephen Gutekanst - Stephen Gutekanst
- Jonathan Hale - Jonathan Hale
- Daniel Hauser
- hdf89shfdfs - hdf89shfdfs
- Moritz Heinemann
- Sylvain Hellegouarch - Sylvain Hellegouarch
- Björn Hempel
- Matthew Henry - Matthew Henry
- heromyth - heromyth
- Lucas Hinderberger - Lucas Hinderberger
- Paul Holden - Paul Holden
- Hajime Hoshi
- Warren Hu - Warren Hu
- Charles Huber - Charles Huber
- Brent Huisman
- illustris
- InKryption - InKryption
- IntellectualKitty - IntellectualKitty
- Aaron Jacobs - Aaron Jacobs
- JannikGM
- Erik S. V. Jansson - Erik S. V. Jansson
- jjYBdx4IL
- Peter Johnson
- Toni Jovanoski - Toni Jovanoski
- Arseny Kapoulkine - Arseny Kapoulkine
- Cem Karan - Cem Karan
@ -107,12 +128,16 @@ video tutorials.
- Anders Lindqvist - Anders Lindqvist
- Leon Linhart - Leon Linhart
- Marco Lizza - Marco Lizza
- lo-v-ol
- Eyal Lotem - Eyal Lotem
- Aaron Loucks - Aaron Loucks
- Ned Loynd
- Luflosi - Luflosi
- lukect - lukect
- Tristam MacDonald - Tristam MacDonald
- Jean-Luc Mackail
- Hans Mackowiak - Hans Mackowiak
- Ramiro Magno
- Дмитри Малышев - Дмитри Малышев
- Zbigniew Mandziejewicz - Zbigniew Mandziejewicz
- Adam Marcus - Adam Marcus
@ -125,10 +150,12 @@ video tutorials.
- Marcel Metz - Marcel Metz
- Liam Middlebrook - Liam Middlebrook
- Ave Milia - Ave Milia
- Icyllis Milica
- Jonathan Miller - Jonathan Miller
- Kenneth Miller - Kenneth Miller
- Bruce Mitchener - Bruce Mitchener
- Jack Moffitt - Jack Moffitt
- Ravi Mohan
- Jeff Molofee - Jeff Molofee
- Alexander Monakov - Alexander Monakov
- Pierre Morel - Pierre Morel
@ -136,10 +163,13 @@ video tutorials.
- Pierre Moulon - Pierre Moulon
- Martins Mozeiko - Martins Mozeiko
- Pascal Muetschard - Pascal Muetschard
- James Murphy
- Julian Møller - Julian Møller
- ndogxj - ndogxj
- F. Nedelec
- n3rdopolis - n3rdopolis
- Kristian Nielsen - Kristian Nielsen
- Joel Niemelä
- Kamil Nowakowski - Kamil Nowakowski
- onox - onox
- Denis Ovod - Denis Ovod
@ -149,12 +179,15 @@ video tutorials.
- Peoro - Peoro
- Braden Pellett - Braden Pellett
- Christopher Pelloux - Christopher Pelloux
- Michael Pennington
- Arturo J. Pérez - Arturo J. Pérez
- Vladimir Perminov - Vladimir Perminov
- Olivier Perret
- Anthony Pesch - Anthony Pesch
- Orson Peters - Orson Peters
- Emmanuel Gil Peyrot - Emmanuel Gil Peyrot
- Cyril Pichard - Cyril Pichard
- Pilzschaf
- Keith Pitt - Keith Pitt
- Stanislav Podgorskiy - Stanislav Podgorskiy
- Konstantin Podsvirov - Konstantin Podsvirov
@ -163,10 +196,14 @@ video tutorials.
- Pablo Prietz - Pablo Prietz
- przemekmirek - przemekmirek
- pthom - pthom
- Martin Pulec
- Guillaume Racicot - Guillaume Racicot
- Juan Ramos
- Christian Rauch
- Philip Rideout - Philip Rideout
- Eddie Ringle - Eddie Ringle
- Max Risuhin - Max Risuhin
- Joe Roback
- Jorge Rodriguez - Jorge Rodriguez
- Jari Ronkainen - Jari Ronkainen
- Luca Rood - Luca Rood
@ -174,22 +211,30 @@ video tutorials.
- Aleksey Rybalkin - Aleksey Rybalkin
- Mikko Rytkönen - Mikko Rytkönen
- Riku Salminen - Riku Salminen
- Yoshinori Sano
- Brandon Schaefer - Brandon Schaefer
- Sebastian Schuberth - Sebastian Schuberth
- Scr3amer
- Christian Sdunek - Christian Sdunek
- Matt Sealey - Matt Sealey
- Steve Sexton - Steve Sexton
- Arkady Shapkin - Arkady Shapkin
- Mingjie Shen
- Ali Sherief - Ali Sherief
- Yoshiki Shibukawa - Yoshiki Shibukawa
- Dmitri Shuralyov - Dmitri Shuralyov
- Joao da Silva
- Daniel Sieger - Daniel Sieger
- Daljit Singh
- Michael Skec
- Daniel Skorupski - Daniel Skorupski
- Slemmie
- Anthony Smith - Anthony Smith
- Bradley Smith - Bradley Smith
- Cliff Smolinsky - Cliff Smolinsky
- Patrick Snape - Patrick Snape
- Erlend Sogge Heggen - Erlend Sogge Heggen
- Olivier Sohn
- Julian Squires - Julian Squires
- Johannes Stein - Johannes Stein
- Pontus Stenetorp - Pontus Stenetorp
@ -202,6 +247,7 @@ video tutorials.
- Jared Tiala - Jared Tiala
- Sergey Tikhomirov - Sergey Tikhomirov
- Arthur Tombs - Arthur Tombs
- TronicLabs
- Ioannis Tsakpinis - Ioannis Tsakpinis
- Samuli Tuomola - Samuli Tuomola
- Matthew Turner - Matthew Turner
@ -211,11 +257,14 @@ video tutorials.
- Jari Vetoniemi - Jari Vetoniemi
- Ricardo Vieira - Ricardo Vieira
- Nicholas Vitovitch - Nicholas Vitovitch
- Vladimír Vondruš
- Simon Voordouw - Simon Voordouw
- Corentin Wallez - Corentin Wallez
- Torsten Walluhn - Torsten Walluhn
- Patrick Walton - Patrick Walton
- Jim Wang
- Xo Wang - Xo Wang
- Andre Weissflog
- Jay Weisskopf - Jay Weisskopf
- Frank Wille - Frank Wille
- Andy Williams - Andy Williams

113
README.md
View File

@ -79,6 +79,8 @@ more information.
## System requirements ## System requirements
GLFW is written in C99 and does not support Visual Studio 2012 or earlier.
GLFW supports Windows XP and later and macOS 10.8 and later. Linux and other GLFW supports Windows XP and later and macOS 10.8 and later. Linux and other
Unix-like systems running the X Window System are supported even without Unix-like systems running the X Window System are supported even without
a desktop environment or modern extensions, although some features require a desktop environment or modern extensions, although some features require
@ -139,13 +141,21 @@ information on what to include when reporting a bug.
- Added `GLFW_POINTING_HAND_CURSOR` alias for `GLFW_HAND_CURSOR` (#427) - Added `GLFW_POINTING_HAND_CURSOR` alias for `GLFW_HAND_CURSOR` (#427)
- Added `GLFW_MOUSE_PASSTHROUGH` window hint for letting mouse input pass - Added `GLFW_MOUSE_PASSTHROUGH` window hint for letting mouse input pass
through the window (#1236,#1568) through the window (#1236,#1568)
- Added `GLFW_CURSOR_CAPTURED` cursor mode to confine the cursor to the window
content area (#58)
- Added `GLFW_POSITION_X` and `GLFW_POSITION_Y` window hints for initial position
(#1603,#1747)
- Added `GLFW_ANY_POSITION` hint value for letting the window manager choose (#1603,#1747)
- Added `GLFW_PLATFORM_UNAVAILABLE` error for platform detection failures (#1958) - Added `GLFW_PLATFORM_UNAVAILABLE` error for platform detection failures (#1958)
- Added `GLFW_FEATURE_UNAVAILABLE` error for platform limitations (#1692) - Added `GLFW_FEATURE_UNAVAILABLE` error for platform limitations (#1692)
- Added `GLFW_FEATURE_UNIMPLEMENTED` error for incomplete backends (#1692) - Added `GLFW_FEATURE_UNIMPLEMENTED` error for incomplete backends (#1692)
- Added `GLFW_WAYLAND_APP_ID` window hint string for Wayland app\_id selection
(#2121,#2122)
- Added `GLFW_ANGLE_PLATFORM_TYPE` init hint and `GLFW_ANGLE_PLATFORM_TYPE_*` - Added `GLFW_ANGLE_PLATFORM_TYPE` init hint and `GLFW_ANGLE_PLATFORM_TYPE_*`
values to select ANGLE backend (#1380) values to select ANGLE backend (#1380)
- Added `GLFW_X11_XCB_VULKAN_SURFACE` init hint for selecting X11 Vulkan - Added `GLFW_X11_XCB_VULKAN_SURFACE` init hint for selecting X11 Vulkan
surface extension (#1793) surface extension (#1793)
- Added `GLFW_NATIVE_INCLUDE_NONE` for disabling inclusion of native headers (#1348)
- Added `GLFW_BUILD_WIN32` CMake option for enabling Win32 support (#1958) - Added `GLFW_BUILD_WIN32` CMake option for enabling Win32 support (#1958)
- Added `GLFW_BUILD_COCOA` CMake option for enabling Cocoa support (#1958) - Added `GLFW_BUILD_COCOA` CMake option for enabling Cocoa support (#1958)
- Added `GLFW_BUILD_X11` CMake option for enabling X11 support (#1958) - Added `GLFW_BUILD_X11` CMake option for enabling X11 support (#1958)
@ -172,9 +182,15 @@ information on what to include when reporting a bug.
- Bugfix: Gamepad mapping updates could spam `GLFW_INVALID_VALUE` due to - Bugfix: Gamepad mapping updates could spam `GLFW_INVALID_VALUE` due to
incompatible controllers sharing hardware ID (#1763) incompatible controllers sharing hardware ID (#1763)
- Bugfix: Native access functions for context handles did not check that the API matched - Bugfix: Native access functions for context handles did not check that the API matched
- Bugfix: `glfwMakeContextCurrent` would access TLS slot before initialization
- Bugfix: `glfwSetGammaRamp` could emit `GLFW_INVALID_VALUE` before initialization
- Bugfix: `glfwGetJoystickUserPointer` returned `NULL` during disconnection (#2092)
- Bugfix: `glfwGetKeyScancode` returned `0` on error when initialized instead of `-1`
- Bugfix: Failure to make a newly created context current could cause segfault (#2327)
- [Win32] Added the `GLFW_WIN32_KEYBOARD_MENU` window hint for enabling access - [Win32] Added the `GLFW_WIN32_KEYBOARD_MENU` window hint for enabling access
to the window menu to the window menu
- [Win32] Added a version info resource to the GLFW DLL - [Win32] Added a version info resource to the GLFW DLL
- [Win32] Made hidden helper window use its own window class
- [Win32] Disabled framebuffer transparency on Windows 7 when DWM windows are - [Win32] Disabled framebuffer transparency on Windows 7 when DWM windows are
opaque (#1512) opaque (#1512)
- [Win32] Bugfix: `GLFW_INCLUDE_VULKAN` plus `VK_USE_PLATFORM_WIN32_KHR` caused - [Win32] Bugfix: `GLFW_INCLUDE_VULKAN` plus `VK_USE_PLATFORM_WIN32_KHR` caused
@ -205,12 +221,29 @@ information on what to include when reporting a bug.
- [Win32] Bugfix: Content scale queries could fail silently (#1615) - [Win32] Bugfix: Content scale queries could fail silently (#1615)
- [Win32] Bugfix: Content scales could have garbage values if monitor was recently - [Win32] Bugfix: Content scales could have garbage values if monitor was recently
disconnected (#1615) disconnected (#1615)
- [Win32] Bugfix: A window created maximized and undecorated would cover the whole
monitor (#1806)
- [Win32] Bugfix: The default restored window position was lost when creating a maximized
window
- [Win32] Bugfix: `glfwMaximizeWindow` would make a hidden window visible
- [Win32] Bugfix: `Alt+PrtSc` would emit `GLFW_KEY_UNKNOWN` and a different
scancode than `PrtSc` (#1993)
- [Win32] Bugfix: `GLFW_KEY_PAUSE` scancode from `glfwGetKeyScancode` did not
match event scancode (#1993)
- [Win32] Bugfix: Instance-local operations used executable instance (#469,#1296,#1395)
- [Win32] Bugfix: The OSMesa library was not unloaded on termination
- [Win32] Bugfix: Right shift emitted `GLFW_KEY_UNKNOWN` when using a CJK IME (#2050)
- [Win32] Bugfix: `glfwWaitEventsTimeout` did not return for some sent messages (#2408)
- [Win32] Bugfix: Fix pkg-config for dynamic library on Windows (#2386, #2420)
- [Win32] Bugfix: XInput could reportedly provide invalid DPad bit masks (#2291)
- [Win32] Bugfix: Rapid clipboard calls could fail due to Clipboard History
- [Cocoa] Added support for `VK_EXT_metal_surface` (#1619) - [Cocoa] Added support for `VK_EXT_metal_surface` (#1619)
- [Cocoa] Added locating the Vulkan loader at runtime in an application bundle - [Cocoa] Added locating the Vulkan loader at runtime in an application bundle
- [Cocoa] Moved main menu creation to GLFW initialization time (#1649) - [Cocoa] Moved main menu creation to GLFW initialization time (#1649)
- [Cocoa] Changed `EGLNativeWindowType` from `NSView` to `CALayer` (#1169) - [Cocoa] Changed `EGLNativeWindowType` from `NSView` to `CALayer` (#1169)
- [Cocoa] Changed F13 key to report Print Screen for cross-platform consistency - [Cocoa] Changed F13 key to report Print Screen for cross-platform consistency
(#1786) (#1786)
- [Cocoa] Disabled macOS fullscreen when `GLFW_RESIZABLE` is false
- [Cocoa] Removed dependency on the CoreVideo framework - [Cocoa] Removed dependency on the CoreVideo framework
- [Cocoa] Bugfix: `glfwSetWindowSize` used a bottom-left anchor point (#1553) - [Cocoa] Bugfix: `glfwSetWindowSize` used a bottom-left anchor point (#1553)
- [Cocoa] Bugfix: Window remained on screen after destruction until event poll - [Cocoa] Bugfix: Window remained on screen after destruction until event poll
@ -235,6 +268,19 @@ information on what to include when reporting a bug.
a fraction of a second (#1962) a fraction of a second (#1962)
- [Cocoa] Bugfix: `kIOMasterPortDefault` was deprecated in macOS 12.0 (#1980) - [Cocoa] Bugfix: `kIOMasterPortDefault` was deprecated in macOS 12.0 (#1980)
- [Cocoa] Bugfix: `kUTTypeURL` was deprecated in macOS 12.0 (#2003) - [Cocoa] Bugfix: `kUTTypeURL` was deprecated in macOS 12.0 (#2003)
- [Cocoa] Bugfix: A connected Apple AirPlay would emit a useless error (#1791)
- [Cocoa] Bugfix: The EGL and OSMesa libraries were not unloaded on termination
- [Cocoa] Bugfix: `GLFW_MAXIMIZED` was always true when `GLFW_RESIZABLE` was false
- [Cocoa] Bugfix: Changing `GLFW_DECORATED` in macOS fullscreen would abort
application (#1886)
- [Cocoa] Bugfix: Setting a monitor from macOS fullscreen would abort
application (#2110)
- [Cocoa] Bugfix: The Vulkan loader was not loaded from the `Frameworks` bundle
subdirectory (#2113,#2120)
- [Cocoa] Bugfix: Compilation failed on OS X 10.8 due to unconditional use of 10.9+
symbols (#2161)
- [Cocoa] Bugfix: Querying joystick elements could reportedly segfault on macOS
13 Ventura (#2320)
- [X11] Bugfix: The CMake files did not check for the XInput headers (#1480) - [X11] Bugfix: The CMake files did not check for the XInput headers (#1480)
- [X11] Bugfix: Key names were not updated when the keyboard layout changed - [X11] Bugfix: Key names were not updated when the keyboard layout changed
(#1462,#1528) (#1462,#1528)
@ -266,8 +312,24 @@ information on what to include when reporting a bug.
- [X11] Bugfix: Icon pixel format conversion worked only by accident, relying on - [X11] Bugfix: Icon pixel format conversion worked only by accident, relying on
undefined behavior (#1986) undefined behavior (#1986)
- [X11] Bugfix: Dynamic loading on OpenBSD failed due to soname differences - [X11] Bugfix: Dynamic loading on OpenBSD failed due to soname differences
- [X11] Bugfix: Waiting for events would fail if file descriptor was too large
(#2024)
- [X11] Bugfix: Joystick events could lead to busy-waiting (#1872)
- [X11] Bugfix: `glfwWaitEvents*` did not continue for joystick events
- [X11] Bugfix: `glfwPostEmptyEvent` could be ignored due to race condition
(#379,#1281,#1285,#2033)
- [X11] Bugfix: Dynamic loading on NetBSD failed due to soname differences
- [X11] Bugfix: Left shift of int constant relied on undefined behavior (#1951)
- [X11] Bugfix: The OSMesa libray was not unloaded on termination
- [X11] Bugfix: A malformed response during selection transfer could cause a segfault
- [X11] Bugfix: Some calls would reset Xlib to the default error handler (#2108)
- [Wayland] Added improved fallback window decorations via libdecor (#1639,#1693)
- [Wayland] Added dynamic loading of all Wayland libraries - [Wayland] Added dynamic loading of all Wayland libraries
- [Wayland] Added support for key names via xkbcommon - [Wayland] Added support for key names via xkbcommon
- [Wayland] Added support for file path drop events (#2040)
- [Wayland] Added support for more human-readable monitor names where available
- [Wayland] Disabled alpha channel for opaque windows on systems lacking
`EGL_EXT_present_opaque` (#1895)
- [Wayland] Removed support for `wl_shell` (#1443) - [Wayland] Removed support for `wl_shell` (#1443)
- [Wayland] Bugfix: The `GLFW_HAND_CURSOR` shape used the wrong image (#1432) - [Wayland] Bugfix: The `GLFW_HAND_CURSOR` shape used the wrong image (#1432)
- [Wayland] Bugfix: `CLOCK_MONOTONIC` was not correctly enabled - [Wayland] Bugfix: `CLOCK_MONOTONIC` was not correctly enabled
@ -290,8 +352,55 @@ information on what to include when reporting a bug.
- [Wayland] Bugfix: Full screen window creation did not ignore `GLFW_VISIBLE` - [Wayland] Bugfix: Full screen window creation did not ignore `GLFW_VISIBLE`
- [Wayland] Bugfix: Some keys were reported as wrong key or `GLFW_KEY_UNKNOWN` - [Wayland] Bugfix: Some keys were reported as wrong key or `GLFW_KEY_UNKNOWN`
- [Wayland] Bugfix: Text input did not repeat along with key repeat - [Wayland] Bugfix: Text input did not repeat along with key repeat
- [Wayland] Bugfix: `glfwPostEmptyEvent` sometimes had no effect (#1520,#1521)
- [Wayland] Bugfix: `glfwSetClipboardString` would fail if set to result of
`glfwGetClipboardString`
- [Wayland] Bugfix: Data source creation error would cause double free at termination
- [Wayland] Bugfix: Partial writes of clipboard string would cause beginning to repeat
- [Wayland] Bugfix: Some errors would cause clipboard string transfer to hang
- [Wayland] Bugfix: Drag and drop data was misinterpreted as clipboard string
- [Wayland] Bugfix: MIME type matching was not performed for clipboard string
- [Wayland] Bugfix: The OSMesa library was not unloaded on termination
- [Wayland] Bugfix: `glfwCreateWindow` could emit `GLFW_FEATURE_UNAVAILABLE`
- [Wayland] Bugfix: Lock key modifier bits were only set when lock keys were pressed
- [Wayland] Bugfix: A window leaving full screen mode would be iconified (#1995)
- [Wayland] Bugfix: A window leaving full screen mode ignored its desired size
- [Wayland] Bugfix: `glfwSetWindowMonitor` did not update windowed mode size
- [Wayland] Bugfix: `glfwRestoreWindow` would make a full screen window windowed
- [Wayland] Bugfix: A window maximized or restored by the user would enter an
inconsistent state
- [Wayland] Bugfix: Window maximization events were not emitted
- [Wayland] Bugfix: `glfwRestoreWindow` assumed it was always in windowed mode
- [Wayland] Bugfix: `glfwSetWindowSize` would resize a full screen window
- [Wayland] Bugfix: A window content scale event would be emitted every time
the window resized
- [Wayland] Bugfix: If `glfwInit` failed it would close stdin
- [Wayland] Bugfix: Manual resizing with fallback decorations behaved erratically
(#1991,#2115,#2127)
- [Wayland] Bugfix: Size limits included frame size for fallback decorations
- [Wayland] Bugfix: Updating `GLFW_DECORATED` had no effect on server-side
decorations
- [Wayland] Bugfix: A monitor would be reported as connected again if its scale
changed
- [Wayland] Bugfix: `glfwTerminate` would segfault if any monitor had changed
scale
- [Wayland] Bugfix: Window content scale events were not emitted when monitor
scale changed
- [Wayland] Bugfix: `glfwSetWindowAspectRatio` reported an error instead of
applying the specified ratio
- [Wayland] Bugfix: `GLFW_MAXIMIZED` window hint had no effect
- [Wayland] Bugfix: `glfwRestoreWindow` had no effect before first show
- [Wayland] Bugfix: Hiding and then showing a window caused program abort on
wlroots compositors (#1268)
- [Wayland] Bugfix: `GLFW_DECORATED` was ignored when showing a window with XDG
decorations
- [Wayland] Bugfix: Connecting a mouse after `glfwInit` would segfault (#1450)
- [Wayland] Bugfix: Joysticks connected after `glfwInit` were not detected (#2198)
- [Wayland] Bugfix: Fallback decorations emitted `GLFW_CURSOR_UNAVAILABLE` errors
- [POSIX] Removed use of deprecated function `gettimeofday` - [POSIX] Removed use of deprecated function `gettimeofday`
- [POSIX] Bugfix: `CLOCK_MONOTONIC` was not correctly tested for or enabled - [POSIX] Bugfix: `CLOCK_MONOTONIC` was not correctly tested for or enabled
- [Linux] Bugfix: Joysticks without buttons were ignored (#2042,#2043)
- [Linux] Bugfix: A small amount of memory could leak if initialization failed (#2229)
- [WGL] Disabled the DWM swap interval hack for Windows 8 and later (#1072) - [WGL] Disabled the DWM swap interval hack for Windows 8 and later (#1072)
- [NSGL] Removed enforcement of forward-compatible flag for core contexts - [NSGL] Removed enforcement of forward-compatible flag for core contexts
- [NSGL] Bugfix: `GLFW_COCOA_RETINA_FRAMEBUFFER` had no effect on newer - [NSGL] Bugfix: `GLFW_COCOA_RETINA_FRAMEBUFFER` had no effect on newer
@ -303,7 +412,11 @@ information on what to include when reporting a bug.
(#442) (#442)
- [EGL] Added ANGLE backend selection via `EGL_ANGLE_platform_angle` extension - [EGL] Added ANGLE backend selection via `EGL_ANGLE_platform_angle` extension
(#1380) (#1380)
- [EGL] Added loading of glvnd `libOpenGL.so.0` where available for OpenGL
- [EGL] Bugfix: The `GLFW_DOUBLEBUFFER` context attribute was ignored (#1843) - [EGL] Bugfix: The `GLFW_DOUBLEBUFFER` context attribute was ignored (#1843)
- [EGL] Bugfix: Setting `GLFW_CONTEXT_DEBUG` caused creation to fail (#2348)
- [GLX] Added loading of glvnd `libGLX.so.0` where available
- [GLX] Bugfix: Context creation failed if GLX 1.4 was not exported by GLX library
## Contact ## Contact

2412
deps/glad/vulkan.h vendored

File diff suppressed because it is too large Load Diff

910
deps/stb_image_write.h vendored

File diff suppressed because it is too large Load Diff

247
deps/vs2008/stdint.h vendored
View File

@ -1,247 +0,0 @@
// ISO C9x compliant stdint.h for Microsoft Visual Studio
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
//
// Copyright (c) 2006-2008 Alexander Chemeris
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. The name of the author may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _MSC_VER // [
#error "Use this header only with Microsoft Visual C++ compilers!"
#endif // _MSC_VER ]
#ifndef _MSC_STDINT_H_ // [
#define _MSC_STDINT_H_
#if _MSC_VER > 1000
#pragma once
#endif
#include <limits.h>
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
// or compiler give many errors like this:
// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
#ifdef __cplusplus
extern "C" {
#endif
# include <wchar.h>
#ifdef __cplusplus
}
#endif
// Define _W64 macros to mark types changing their size, like intptr_t.
#ifndef _W64
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
# define _W64 __w64
# else
# define _W64
# endif
#endif
// 7.18.1 Integer types
// 7.18.1.1 Exact-width integer types
// Visual Studio 6 and Embedded Visual C++ 4 doesn't
// realize that, e.g. char has the same size as __int8
// so we give up on __intX for them.
#if (_MSC_VER < 1300)
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#else
typedef signed __int8 int8_t;
typedef signed __int16 int16_t;
typedef signed __int32 int32_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
#endif
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
// 7.18.1.2 Minimum-width integer types
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
typedef int32_t int_least32_t;
typedef int64_t int_least64_t;
typedef uint8_t uint_least8_t;
typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
typedef uint64_t uint_least64_t;
// 7.18.1.3 Fastest minimum-width integer types
typedef int8_t int_fast8_t;
typedef int16_t int_fast16_t;
typedef int32_t int_fast32_t;
typedef int64_t int_fast64_t;
typedef uint8_t uint_fast8_t;
typedef uint16_t uint_fast16_t;
typedef uint32_t uint_fast32_t;
typedef uint64_t uint_fast64_t;
// 7.18.1.4 Integer types capable of holding object pointers
#ifdef _WIN64 // [
typedef signed __int64 intptr_t;
typedef unsigned __int64 uintptr_t;
#else // _WIN64 ][
typedef _W64 signed int intptr_t;
typedef _W64 unsigned int uintptr_t;
#endif // _WIN64 ]
// 7.18.1.5 Greatest-width integer types
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
// 7.18.2 Limits of specified-width integer types
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
// 7.18.2.1 Limits of exact-width integer types
#define INT8_MIN ((int8_t)_I8_MIN)
#define INT8_MAX _I8_MAX
#define INT16_MIN ((int16_t)_I16_MIN)
#define INT16_MAX _I16_MAX
#define INT32_MIN ((int32_t)_I32_MIN)
#define INT32_MAX _I32_MAX
#define INT64_MIN ((int64_t)_I64_MIN)
#define INT64_MAX _I64_MAX
#define UINT8_MAX _UI8_MAX
#define UINT16_MAX _UI16_MAX
#define UINT32_MAX _UI32_MAX
#define UINT64_MAX _UI64_MAX
// 7.18.2.2 Limits of minimum-width integer types
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
// 7.18.2.3 Limits of fastest minimum-width integer types
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
// 7.18.2.4 Limits of integer types capable of holding object pointers
#ifdef _WIN64 // [
# define INTPTR_MIN INT64_MIN
# define INTPTR_MAX INT64_MAX
# define UINTPTR_MAX UINT64_MAX
#else // _WIN64 ][
# define INTPTR_MIN INT32_MIN
# define INTPTR_MAX INT32_MAX
# define UINTPTR_MAX UINT32_MAX
#endif // _WIN64 ]
// 7.18.2.5 Limits of greatest-width integer types
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
// 7.18.3 Limits of other integer types
#ifdef _WIN64 // [
# define PTRDIFF_MIN _I64_MIN
# define PTRDIFF_MAX _I64_MAX
#else // _WIN64 ][
# define PTRDIFF_MIN _I32_MIN
# define PTRDIFF_MAX _I32_MAX
#endif // _WIN64 ]
#define SIG_ATOMIC_MIN INT_MIN
#define SIG_ATOMIC_MAX INT_MAX
#ifndef SIZE_MAX // [
# ifdef _WIN64 // [
# define SIZE_MAX _UI64_MAX
# else // _WIN64 ][
# define SIZE_MAX _UI32_MAX
# endif // _WIN64 ]
#endif // SIZE_MAX ]
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
#ifndef WCHAR_MIN // [
# define WCHAR_MIN 0
#endif // WCHAR_MIN ]
#ifndef WCHAR_MAX // [
# define WCHAR_MAX _UI16_MAX
#endif // WCHAR_MAX ]
#define WINT_MIN 0
#define WINT_MAX _UI16_MAX
#endif // __STDC_LIMIT_MACROS ]
// 7.18.4 Limits of other integer types
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
// 7.18.4.1 Macros for minimum-width integer constants
#define INT8_C(val) val##i8
#define INT16_C(val) val##i16
#define INT32_C(val) val##i32
#define INT64_C(val) val##i64
#define UINT8_C(val) val##ui8
#define UINT16_C(val) val##ui16
#define UINT32_C(val) val##ui32
#define UINT64_C(val) val##ui64
// 7.18.4.2 Macros for greatest-width integer constants
#define INTMAX_C INT64_C
#define UINTMAX_C UINT64_C
#endif // __STDC_CONSTANT_MACROS ]
#endif // _MSC_STDINT_H_ ]

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="idle_inhibit_unstable_v1">
<copyright>
Copyright © 2015 Samsung Electronics Co., Ltd
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="zwp_idle_inhibit_manager_v1" version="1">
<description summary="control behavior when display idles">
This interface permits inhibiting the idle behavior such as screen
blanking, locking, and screensaving. The client binds the idle manager
globally, then creates idle-inhibitor objects for each surface.
Warning! The protocol described in this file is experimental and
backward incompatible changes may be made. Backward compatible changes
may be added together with the corresponding interface version bump.
Backward incompatible changes are done by bumping the version number in
the protocol and interface names and resetting the interface version.
Once the protocol is to be declared stable, the 'z' prefix and the
version number in the protocol and interface names are removed and the
interface version number is reset.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the idle inhibitor object">
Destroy the inhibit manager.
</description>
</request>
<request name="create_inhibitor">
<description summary="create a new inhibitor object">
Create a new inhibitor object associated with the given surface.
</description>
<arg name="id" type="new_id" interface="zwp_idle_inhibitor_v1"/>
<arg name="surface" type="object" interface="wl_surface"
summary="the surface that inhibits the idle behavior"/>
</request>
</interface>
<interface name="zwp_idle_inhibitor_v1" version="1">
<description summary="context object for inhibiting idle behavior">
An idle inhibitor prevents the output that the associated surface is
visible on from being set to a state where it is not visually usable due
to lack of user interaction (e.g. blanked, dimmed, locked, set to power
save, etc.) Any screensaver processes are also blocked from displaying.
If the surface is destroyed, unmapped, becomes occluded, loses
visibility, or otherwise becomes not visually relevant for the user, the
idle inhibitor will not be honored by the compositor; if the surface
subsequently regains visibility the inhibitor takes effect once again.
Likewise, the inhibitor isn't honored if the system was already idled at
the time the inhibitor was established, although if the system later
de-idles and re-idles the inhibitor will take effect.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the idle inhibitor object">
Remove the inhibitor effect from the associated wl_surface.
</description>
</request>
</interface>
</protocol>

View File

@ -0,0 +1,339 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="pointer_constraints_unstable_v1">
<copyright>
Copyright © 2014 Jonas Ådahl
Copyright © 2015 Red Hat Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<description summary="protocol for constraining pointer motions">
This protocol specifies a set of interfaces used for adding constraints to
the motion of a pointer. Possible constraints include confining pointer
motions to a given region, or locking it to its current position.
In order to constrain the pointer, a client must first bind the global
interface "wp_pointer_constraints" which, if a compositor supports pointer
constraints, is exposed by the registry. Using the bound global object, the
client uses the request that corresponds to the type of constraint it wants
to make. See wp_pointer_constraints for more details.
Warning! The protocol described in this file is experimental and backward
incompatible changes may be made. Backward compatible changes may be added
together with the corresponding interface version bump. Backward
incompatible changes are done by bumping the version number in the protocol
and interface names and resetting the interface version. Once the protocol
is to be declared stable, the 'z' prefix and the version number in the
protocol and interface names are removed and the interface version number is
reset.
</description>
<interface name="zwp_pointer_constraints_v1" version="1">
<description summary="constrain the movement of a pointer">
The global interface exposing pointer constraining functionality. It
exposes two requests: lock_pointer for locking the pointer to its
position, and confine_pointer for locking the pointer to a region.
The lock_pointer and confine_pointer requests create the objects
wp_locked_pointer and wp_confined_pointer respectively, and the client can
use these objects to interact with the lock.
For any surface, only one lock or confinement may be active across all
wl_pointer objects of the same seat. If a lock or confinement is requested
when another lock or confinement is active or requested on the same surface
and with any of the wl_pointer objects of the same seat, an
'already_constrained' error will be raised.
</description>
<enum name="error">
<description summary="wp_pointer_constraints error values">
These errors can be emitted in response to wp_pointer_constraints
requests.
</description>
<entry name="already_constrained" value="1"
summary="pointer constraint already requested on that surface"/>
</enum>
<enum name="lifetime">
<description summary="constraint lifetime">
These values represent different lifetime semantics. They are passed
as arguments to the factory requests to specify how the constraint
lifetimes should be managed.
</description>
<entry name="oneshot" value="1">
<description summary="the pointer constraint is defunct once deactivated">
A oneshot pointer constraint will never reactivate once it has been
deactivated. See the corresponding deactivation event
(wp_locked_pointer.unlocked and wp_confined_pointer.unconfined) for
details.
</description>
</entry>
<entry name="persistent" value="2">
<description summary="the pointer constraint may reactivate">
A persistent pointer constraint may again reactivate once it has
been deactivated. See the corresponding deactivation event
(wp_locked_pointer.unlocked and wp_confined_pointer.unconfined) for
details.
</description>
</entry>
</enum>
<request name="destroy" type="destructor">
<description summary="destroy the pointer constraints manager object">
Used by the client to notify the server that it will no longer use this
pointer constraints object.
</description>
</request>
<request name="lock_pointer">
<description summary="lock pointer to a position">
The lock_pointer request lets the client request to disable movements of
the virtual pointer (i.e. the cursor), effectively locking the pointer
to a position. This request may not take effect immediately; in the
future, when the compositor deems implementation-specific constraints
are satisfied, the pointer lock will be activated and the compositor
sends a locked event.
The protocol provides no guarantee that the constraints are ever
satisfied, and does not require the compositor to send an error if the
constraints cannot ever be satisfied. It is thus possible to request a
lock that will never activate.
There may not be another pointer constraint of any kind requested or
active on the surface for any of the wl_pointer objects of the seat of
the passed pointer when requesting a lock. If there is, an error will be
raised. See general pointer lock documentation for more details.
The intersection of the region passed with this request and the input
region of the surface is used to determine where the pointer must be
in order for the lock to activate. It is up to the compositor whether to
warp the pointer or require some kind of user interaction for the lock
to activate. If the region is null the surface input region is used.
A surface may receive pointer focus without the lock being activated.
The request creates a new object wp_locked_pointer which is used to
interact with the lock as well as receive updates about its state. See
the the description of wp_locked_pointer for further information.
Note that while a pointer is locked, the wl_pointer objects of the
corresponding seat will not emit any wl_pointer.motion events, but
relative motion events will still be emitted via wp_relative_pointer
objects of the same seat. wl_pointer.axis and wl_pointer.button events
are unaffected.
</description>
<arg name="id" type="new_id" interface="zwp_locked_pointer_v1"/>
<arg name="surface" type="object" interface="wl_surface"
summary="surface to lock pointer to"/>
<arg name="pointer" type="object" interface="wl_pointer"
summary="the pointer that should be locked"/>
<arg name="region" type="object" interface="wl_region" allow-null="true"
summary="region of surface"/>
<arg name="lifetime" type="uint" enum="lifetime" summary="lock lifetime"/>
</request>
<request name="confine_pointer">
<description summary="confine pointer to a region">
The confine_pointer request lets the client request to confine the
pointer cursor to a given region. This request may not take effect
immediately; in the future, when the compositor deems implementation-
specific constraints are satisfied, the pointer confinement will be
activated and the compositor sends a confined event.
The intersection of the region passed with this request and the input
region of the surface is used to determine where the pointer must be
in order for the confinement to activate. It is up to the compositor
whether to warp the pointer or require some kind of user interaction for
the confinement to activate. If the region is null the surface input
region is used.
The request will create a new object wp_confined_pointer which is used
to interact with the confinement as well as receive updates about its
state. See the the description of wp_confined_pointer for further
information.
</description>
<arg name="id" type="new_id" interface="zwp_confined_pointer_v1"/>
<arg name="surface" type="object" interface="wl_surface"
summary="surface to lock pointer to"/>
<arg name="pointer" type="object" interface="wl_pointer"
summary="the pointer that should be confined"/>
<arg name="region" type="object" interface="wl_region" allow-null="true"
summary="region of surface"/>
<arg name="lifetime" type="uint" enum="lifetime" summary="confinement lifetime"/>
</request>
</interface>
<interface name="zwp_locked_pointer_v1" version="1">
<description summary="receive relative pointer motion events">
The wp_locked_pointer interface represents a locked pointer state.
While the lock of this object is active, the wl_pointer objects of the
associated seat will not emit any wl_pointer.motion events.
This object will send the event 'locked' when the lock is activated.
Whenever the lock is activated, it is guaranteed that the locked surface
will already have received pointer focus and that the pointer will be
within the region passed to the request creating this object.
To unlock the pointer, send the destroy request. This will also destroy
the wp_locked_pointer object.
If the compositor decides to unlock the pointer the unlocked event is
sent. See wp_locked_pointer.unlock for details.
When unlocking, the compositor may warp the cursor position to the set
cursor position hint. If it does, it will not result in any relative
motion events emitted via wp_relative_pointer.
If the surface the lock was requested on is destroyed and the lock is not
yet activated, the wp_locked_pointer object is now defunct and must be
destroyed.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the locked pointer object">
Destroy the locked pointer object. If applicable, the compositor will
unlock the pointer.
</description>
</request>
<request name="set_cursor_position_hint">
<description summary="set the pointer cursor position hint">
Set the cursor position hint relative to the top left corner of the
surface.
If the client is drawing its own cursor, it should update the position
hint to the position of its own cursor. A compositor may use this
information to warp the pointer upon unlock in order to avoid pointer
jumps.
The cursor position hint is double buffered. The new hint will only take
effect when the associated surface gets it pending state applied. See
wl_surface.commit for details.
</description>
<arg name="surface_x" type="fixed"
summary="surface-local x coordinate"/>
<arg name="surface_y" type="fixed"
summary="surface-local y coordinate"/>
</request>
<request name="set_region">
<description summary="set a new lock region">
Set a new region used to lock the pointer.
The new lock region is double-buffered. The new lock region will
only take effect when the associated surface gets its pending state
applied. See wl_surface.commit for details.
For details about the lock region, see wp_locked_pointer.
</description>
<arg name="region" type="object" interface="wl_region" allow-null="true"
summary="region of surface"/>
</request>
<event name="locked">
<description summary="lock activation event">
Notification that the pointer lock of the seat's pointer is activated.
</description>
</event>
<event name="unlocked">
<description summary="lock deactivation event">
Notification that the pointer lock of the seat's pointer is no longer
active. If this is a oneshot pointer lock (see
wp_pointer_constraints.lifetime) this object is now defunct and should
be destroyed. If this is a persistent pointer lock (see
wp_pointer_constraints.lifetime) this pointer lock may again
reactivate in the future.
</description>
</event>
</interface>
<interface name="zwp_confined_pointer_v1" version="1">
<description summary="confined pointer object">
The wp_confined_pointer interface represents a confined pointer state.
This object will send the event 'confined' when the confinement is
activated. Whenever the confinement is activated, it is guaranteed that
the surface the pointer is confined to will already have received pointer
focus and that the pointer will be within the region passed to the request
creating this object. It is up to the compositor to decide whether this
requires some user interaction and if the pointer will warp to within the
passed region if outside.
To unconfine the pointer, send the destroy request. This will also destroy
the wp_confined_pointer object.
If the compositor decides to unconfine the pointer the unconfined event is
sent. The wp_confined_pointer object is at this point defunct and should
be destroyed.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the confined pointer object">
Destroy the confined pointer object. If applicable, the compositor will
unconfine the pointer.
</description>
</request>
<request name="set_region">
<description summary="set a new confine region">
Set a new region used to confine the pointer.
The new confine region is double-buffered. The new confine region will
only take effect when the associated surface gets its pending state
applied. See wl_surface.commit for details.
If the confinement is active when the new confinement region is applied
and the pointer ends up outside of newly applied region, the pointer may
warped to a position within the new confinement region. If warped, a
wl_pointer.motion event will be emitted, but no
wp_relative_pointer.relative_motion event.
The compositor may also, instead of using the new region, unconfine the
pointer.
For details about the confine region, see wp_confined_pointer.
</description>
<arg name="region" type="object" interface="wl_region" allow-null="true"
summary="region of surface"/>
</request>
<event name="confined">
<description summary="pointer confined">
Notification that the pointer confinement of the seat's pointer is
activated.
</description>
</event>
<event name="unconfined">
<description summary="pointer unconfined">
Notification that the pointer confinement of the seat's pointer is no
longer active. If this is a oneshot pointer confinement (see
wp_pointer_constraints.lifetime) this object is now defunct and should
be destroyed. If this is a persistent pointer confinement (see
wp_pointer_constraints.lifetime) this pointer confinement may again
reactivate in the future.
</description>
</event>
</interface>
</protocol>

View File

@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="relative_pointer_unstable_v1">
<copyright>
Copyright © 2014 Jonas Ådahl
Copyright © 2015 Red Hat Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<description summary="protocol for relative pointer motion events">
This protocol specifies a set of interfaces used for making clients able to
receive relative pointer events not obstructed by barriers (such as the
monitor edge or other pointer barriers).
To start receiving relative pointer events, a client must first bind the
global interface "wp_relative_pointer_manager" which, if a compositor
supports relative pointer motion events, is exposed by the registry. After
having created the relative pointer manager proxy object, the client uses
it to create the actual relative pointer object using the
"get_relative_pointer" request given a wl_pointer. The relative pointer
motion events will then, when applicable, be transmitted via the proxy of
the newly created relative pointer object. See the documentation of the
relative pointer interface for more details.
Warning! The protocol described in this file is experimental and backward
incompatible changes may be made. Backward compatible changes may be added
together with the corresponding interface version bump. Backward
incompatible changes are done by bumping the version number in the protocol
and interface names and resetting the interface version. Once the protocol
is to be declared stable, the 'z' prefix and the version number in the
protocol and interface names are removed and the interface version number is
reset.
</description>
<interface name="zwp_relative_pointer_manager_v1" version="1">
<description summary="get relative pointer objects">
A global interface used for getting the relative pointer object for a
given pointer.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the relative pointer manager object">
Used by the client to notify the server that it will no longer use this
relative pointer manager object.
</description>
</request>
<request name="get_relative_pointer">
<description summary="get a relative pointer object">
Create a relative pointer interface given a wl_pointer object. See the
wp_relative_pointer interface for more details.
</description>
<arg name="id" type="new_id" interface="zwp_relative_pointer_v1"/>
<arg name="pointer" type="object" interface="wl_pointer"/>
</request>
</interface>
<interface name="zwp_relative_pointer_v1" version="1">
<description summary="relative pointer object">
A wp_relative_pointer object is an extension to the wl_pointer interface
used for emitting relative pointer events. It shares the same focus as
wl_pointer objects of the same seat and will only emit events when it has
focus.
</description>
<request name="destroy" type="destructor">
<description summary="release the relative pointer object"/>
</request>
<event name="relative_motion">
<description summary="relative pointer motion">
Relative x/y pointer motion from the pointer of the seat associated with
this object.
A relative motion is in the same dimension as regular wl_pointer motion
events, except they do not represent an absolute position. For example,
moving a pointer from (x, y) to (x', y') would have the equivalent
relative motion (x' - x, y' - y). If a pointer motion caused the
absolute pointer position to be clipped by for example the edge of the
monitor, the relative motion is unaffected by the clipping and will
represent the unclipped motion.
This event also contains non-accelerated motion deltas. The
non-accelerated delta is, when applicable, the regular pointer motion
delta as it was before having applied motion acceleration and other
transformations such as normalization.
Note that the non-accelerated delta does not represent 'raw' events as
they were read from some device. Pointer motion acceleration is device-
and configuration-specific and non-accelerated deltas and accelerated
deltas may have the same value on some devices.
Relative motions are not coupled to wl_pointer.motion events, and can be
sent in combination with such events, but also independently. There may
also be scenarios where wl_pointer.motion is sent, but there is no
relative motion. The order of an absolute and relative motion event
originating from the same physical motion is not guaranteed.
If the client needs button events or focus state, it can receive them
from a wl_pointer object of the same seat that the wp_relative_pointer
object is associated with.
</description>
<arg name="utime_hi" type="uint"
summary="high 32 bits of a 64 bit timestamp with microsecond granularity"/>
<arg name="utime_lo" type="uint"
summary="low 32 bits of a 64 bit timestamp with microsecond granularity"/>
<arg name="dx" type="fixed"
summary="the x component of the motion vector"/>
<arg name="dy" type="fixed"
summary="the y component of the motion vector"/>
<arg name="dx_unaccel" type="fixed"
summary="the x component of the unaccelerated motion vector"/>
<arg name="dy_unaccel" type="fixed"
summary="the y component of the unaccelerated motion vector"/>
</event>
</interface>
</protocol>

180
deps/wayland/viewporter.xml vendored Normal file
View File

@ -0,0 +1,180 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="viewporter">
<copyright>
Copyright © 2013-2016 Collabora, Ltd.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="wp_viewporter" version="1">
<description summary="surface cropping and scaling">
The global interface exposing surface cropping and scaling
capabilities is used to instantiate an interface extension for a
wl_surface object. This extended interface will then allow
cropping and scaling the surface contents, effectively
disconnecting the direct relationship between the buffer and the
surface size.
</description>
<request name="destroy" type="destructor">
<description summary="unbind from the cropping and scaling interface">
Informs the server that the client will not be using this
protocol object anymore. This does not affect any other objects,
wp_viewport objects included.
</description>
</request>
<enum name="error">
<entry name="viewport_exists" value="0"
summary="the surface already has a viewport object associated"/>
</enum>
<request name="get_viewport">
<description summary="extend surface interface for crop and scale">
Instantiate an interface extension for the given wl_surface to
crop and scale its content. If the given wl_surface already has
a wp_viewport object associated, the viewport_exists
protocol error is raised.
</description>
<arg name="id" type="new_id" interface="wp_viewport"
summary="the new viewport interface id"/>
<arg name="surface" type="object" interface="wl_surface"
summary="the surface"/>
</request>
</interface>
<interface name="wp_viewport" version="1">
<description summary="crop and scale interface to a wl_surface">
An additional interface to a wl_surface object, which allows the
client to specify the cropping and scaling of the surface
contents.
This interface works with two concepts: the source rectangle (src_x,
src_y, src_width, src_height), and the destination size (dst_width,
dst_height). The contents of the source rectangle are scaled to the
destination size, and content outside the source rectangle is ignored.
This state is double-buffered, and is applied on the next
wl_surface.commit.
The two parts of crop and scale state are independent: the source
rectangle, and the destination size. Initially both are unset, that
is, no scaling is applied. The whole of the current wl_buffer is
used as the source, and the surface size is as defined in
wl_surface.attach.
If the destination size is set, it causes the surface size to become
dst_width, dst_height. The source (rectangle) is scaled to exactly
this size. This overrides whatever the attached wl_buffer size is,
unless the wl_buffer is NULL. If the wl_buffer is NULL, the surface
has no content and therefore no size. Otherwise, the size is always
at least 1x1 in surface local coordinates.
If the source rectangle is set, it defines what area of the wl_buffer is
taken as the source. If the source rectangle is set and the destination
size is not set, then src_width and src_height must be integers, and the
surface size becomes the source rectangle size. This results in cropping
without scaling. If src_width or src_height are not integers and
destination size is not set, the bad_size protocol error is raised when
the surface state is applied.
The coordinate transformations from buffer pixel coordinates up to
the surface-local coordinates happen in the following order:
1. buffer_transform (wl_surface.set_buffer_transform)
2. buffer_scale (wl_surface.set_buffer_scale)
3. crop and scale (wp_viewport.set*)
This means, that the source rectangle coordinates of crop and scale
are given in the coordinates after the buffer transform and scale,
i.e. in the coordinates that would be the surface-local coordinates
if the crop and scale was not applied.
If src_x or src_y are negative, the bad_value protocol error is raised.
Otherwise, if the source rectangle is partially or completely outside of
the non-NULL wl_buffer, then the out_of_buffer protocol error is raised
when the surface state is applied. A NULL wl_buffer does not raise the
out_of_buffer error.
If the wl_surface associated with the wp_viewport is destroyed,
all wp_viewport requests except 'destroy' raise the protocol error
no_surface.
If the wp_viewport object is destroyed, the crop and scale
state is removed from the wl_surface. The change will be applied
on the next wl_surface.commit.
</description>
<request name="destroy" type="destructor">
<description summary="remove scaling and cropping from the surface">
The associated wl_surface's crop and scale state is removed.
The change is applied on the next wl_surface.commit.
</description>
</request>
<enum name="error">
<entry name="bad_value" value="0"
summary="negative or zero values in width or height"/>
<entry name="bad_size" value="1"
summary="destination size is not integer"/>
<entry name="out_of_buffer" value="2"
summary="source rectangle extends outside of the content area"/>
<entry name="no_surface" value="3"
summary="the wl_surface was destroyed"/>
</enum>
<request name="set_source">
<description summary="set the source rectangle for cropping">
Set the source rectangle of the associated wl_surface. See
wp_viewport for the description, and relation to the wl_buffer
size.
If all of x, y, width and height are -1.0, the source rectangle is
unset instead. Any other set of values where width or height are zero
or negative, or x or y are negative, raise the bad_value protocol
error.
The crop and scale state is double-buffered state, and will be
applied on the next wl_surface.commit.
</description>
<arg name="x" type="fixed" summary="source rectangle x"/>
<arg name="y" type="fixed" summary="source rectangle y"/>
<arg name="width" type="fixed" summary="source rectangle width"/>
<arg name="height" type="fixed" summary="source rectangle height"/>
</request>
<request name="set_destination">
<description summary="set the surface size for scaling">
Set the destination size of the associated wl_surface. See
wp_viewport for the description, and relation to the wl_buffer
size.
If width is -1 and height is -1, the destination size is unset
instead. Any other pair of values for width and height that
contains zero or negative values raises the bad_value protocol
error.
The crop and scale state is double-buffered state, and will be
applied on the next wl_surface.commit.
</description>
<arg name="width" type="int" summary="surface width"/>
<arg name="height" type="int" summary="surface height"/>
</request>
</interface>
</protocol>

3151
deps/wayland/wayland.xml vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="xdg_decoration_unstable_v1">
<copyright>
Copyright © 2018 Simon Ser
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="zxdg_decoration_manager_v1" version="1">
<description summary="window decoration manager">
This interface allows a compositor to announce support for server-side
decorations.
A window decoration is a set of window controls as deemed appropriate by
the party managing them, such as user interface components used to move,
resize and change a window's state.
A client can use this protocol to request being decorated by a supporting
compositor.
If compositor and client do not negotiate the use of a server-side
decoration using this protocol, clients continue to self-decorate as they
see fit.
Warning! The protocol described in this file is experimental and
backward incompatible changes may be made. Backward compatible changes
may be added together with the corresponding interface version bump.
Backward incompatible changes are done by bumping the version number in
the protocol and interface names and resetting the interface version.
Once the protocol is to be declared stable, the 'z' prefix and the
version number in the protocol and interface names are removed and the
interface version number is reset.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the decoration manager object">
Destroy the decoration manager. This doesn't destroy objects created
with the manager.
</description>
</request>
<request name="get_toplevel_decoration">
<description summary="create a new toplevel decoration object">
Create a new decoration object associated with the given toplevel.
Creating an xdg_toplevel_decoration from an xdg_toplevel which has a
buffer attached or committed is a client error, and any attempts by a
client to attach or manipulate a buffer prior to the first
xdg_toplevel_decoration.configure event must also be treated as
errors.
</description>
<arg name="id" type="new_id" interface="zxdg_toplevel_decoration_v1"/>
<arg name="toplevel" type="object" interface="xdg_toplevel"/>
</request>
</interface>
<interface name="zxdg_toplevel_decoration_v1" version="1">
<description summary="decoration object for a toplevel surface">
The decoration object allows the compositor to toggle server-side window
decorations for a toplevel surface. The client can request to switch to
another mode.
The xdg_toplevel_decoration object must be destroyed before its
xdg_toplevel.
</description>
<enum name="error">
<entry name="unconfigured_buffer" value="0"
summary="xdg_toplevel has a buffer attached before configure"/>
<entry name="already_constructed" value="1"
summary="xdg_toplevel already has a decoration object"/>
<entry name="orphaned" value="2"
summary="xdg_toplevel destroyed before the decoration object"/>
</enum>
<request name="destroy" type="destructor">
<description summary="destroy the decoration object">
Switch back to a mode without any server-side decorations at the next
commit.
</description>
</request>
<enum name="mode">
<description summary="window decoration modes">
These values describe window decoration modes.
</description>
<entry name="client_side" value="1"
summary="no server-side window decoration"/>
<entry name="server_side" value="2"
summary="server-side window decoration"/>
</enum>
<request name="set_mode">
<description summary="set the decoration mode">
Set the toplevel surface decoration mode. This informs the compositor
that the client prefers the provided decoration mode.
After requesting a decoration mode, the compositor will respond by
emitting an xdg_surface.configure event. The client should then update
its content, drawing it without decorations if the received mode is
server-side decorations. The client must also acknowledge the configure
when committing the new content (see xdg_surface.ack_configure).
The compositor can decide not to use the client's mode and enforce a
different mode instead.
Clients whose decoration mode depend on the xdg_toplevel state may send
a set_mode request in response to an xdg_surface.configure event and wait
for the next xdg_surface.configure event to prevent unwanted state.
Such clients are responsible for preventing configure loops and must
make sure not to send multiple successive set_mode requests with the
same decoration mode.
</description>
<arg name="mode" type="uint" enum="mode" summary="the decoration mode"/>
</request>
<request name="unset_mode">
<description summary="unset the decoration mode">
Unset the toplevel surface decoration mode. This informs the compositor
that the client doesn't prefer a particular decoration mode.
This request has the same semantics as set_mode.
</description>
</request>
<event name="configure">
<description summary="suggest a surface change">
The configure event asks the client to change its decoration mode. The
configured state should not be applied immediately. Clients must send an
ack_configure in response to this event. See xdg_surface.configure and
xdg_surface.ack_configure for details.
A configure event can be sent at any time. The specified mode must be
obeyed by the client.
</description>
<arg name="mode" type="uint" enum="mode" summary="the decoration mode"/>
</event>
</interface>
</protocol>

1370
deps/wayland/xdg-shell.xml vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -327,7 +327,7 @@ a thousand line one, if that is the appropriate size for the fix.
In addition to the code, a complete bug fix includes: In addition to the code, a complete bug fix includes:
- Change log entry in `README.md`, describing the incorrect behavior - Change log entry in `README.md`, describing the incorrect behavior
- Credits entries for all authors of the bug fix - Credits entries in `CONTRIBUTORS.md` for all authors of the bug fix
Bug fixes will not be rejected because they don't include all the above parts, Bug fixes will not be rejected because they don't include all the above parts,
but please keep in mind that maintainer time is finite and that there are many but please keep in mind that maintainer time is finite and that there are many
@ -351,18 +351,18 @@ __Note:__ If you haven't already implemented the feature, check first if there
already is an open issue for it and if it's already being developed in an already is an open issue for it and if it's already being developed in an
[experimental branch](https://github.com/glfw/glfw/branches/all). [experimental branch](https://github.com/glfw/glfw/branches/all).
__There is no preferred patch size__. A one character change is just as welcome __There is no preferred patch size__. A one-character change is just as welcome
as one adding a thousand line one, if that is the appropriate size for the as one adding a thousand lines, if that is the appropriate size for the
feature. feature.
In addition to the code, a complete feature includes: In addition to the code, a complete feature includes:
- Change log entry in `README.md`, listing all new symbols - Change log entry in `README.md`, listing all new symbols
- News page entry, briefly describing the feature - News page entry in `docs/news.dox`, briefly describing the feature
- Guide documentation, with minimal examples, in the relevant guide - Guide documentation, with minimal examples, in the relevant guide in the `docs` folder
- Reference documentation, with all applicable tags - Reference documentation, with all applicable tags
- Cross-references and mentions in appropriate places - Cross-references and mentions in appropriate places
- Credits entries for all authors of the feature - Credits entries in `CONTRIBUTORS.md` for all authors of the feature
If the feature requires platform-specific code, at minimum stubs must be added If the feature requires platform-specific code, at minimum stubs must be added
for the new platform function to all supported and experimental platforms. for the new platform function to all supported and experimental platforms.

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,7 @@ GLFW.
@endcode @endcode
This header defines all the constants and declares all the types and function This header defines all the constants and declares all the types and function
prototypes of the GLFW API. By default it also includes the OpenGL header from prototypes of the GLFW API. By default, it also includes the OpenGL header from
your development environment. See [option macros](@ref build_macros) below for your development environment. See [option macros](@ref build_macros) below for
how to select OpenGL ES headers and more. how to select OpenGL ES headers and more.
@ -57,7 +57,7 @@ macros that disable similar headers below it.
Both of these mechanisms depend on the extension loader header defining a known Both of these mechanisms depend on the extension loader header defining a known
macro. If yours doesn't or you don't know which one your users will pick, the macro. If yours doesn't or you don't know which one your users will pick, the
@ref GLFW_INCLUDE_NONE macro will explicitly to prevent the GLFW header from @ref GLFW_INCLUDE_NONE macro will explicitly prevent the GLFW header from
including the OpenGL header. This will also allow you to include the two including the OpenGL header. This will also allow you to include the two
headers in any order. headers in any order.

View File

@ -100,46 +100,45 @@ has sole responsibility for interacting well with every compositor in use on
Unix-like systems. Most of the features are provided by the core protocol, Unix-like systems. Most of the features are provided by the core protocol,
while cursor support is provided by the libwayland-cursor helper library, EGL while cursor support is provided by the libwayland-cursor helper library, EGL
integration by libwayland-egl, and keyboard handling by integration by libwayland-egl, and keyboard handling by
[libxkbcommon](https://xkbcommon.org/). In addition, GLFW uses some protocols [libxkbcommon](https://xkbcommon.org/). In addition, GLFW uses some additional
from wayland-protocols to provide additional features if the compositor Wayland protocols to implement certain features if the compositor supports them.
supports them.
GLFW uses xkbcommon 0.5.0 to provide key and text input support. Earlier GLFW uses xkbcommon 0.5.0 to provide key and text input support. Earlier
versions are not supported. versions are not supported.
GLFW uses the [xdg-shell GLFW uses the [xdg-shell protocol](https://wayland.app/protocols/xdg-shell)
protocol](https://cgit.freedesktop.org/wayland/wayland-protocols/tree/stable/xdg-shell/xdg-shell.xml) to provide better window management. This protocol is mandatory for GLFW to
to provide better window management. This protocol is part of display a window.
wayland-protocols 1.12, and is mandatory for GLFW to display a window.
GLFW uses the [relative pointer GLFW uses the
protocol](https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/relative-pointer/relative-pointer-unstable-v1.xml) [relative pointer protocol](https://wayland.app/protocols/relative-pointer-unstable-v1)
alongside the [pointer constraints alongside the
protocol](https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml) [pointer constraints protocol](https://wayland.app/protocols/pointer-constraints-unstable-v1)
to implement disabled cursor. These two protocols are part of to implement disabled cursor. If the running compositor does not support both
wayland-protocols 1.1, and mandatory at build time. If the running compositor of these protocols, disabling the cursor will have no effect.
does not support both of these protocols, disabling the cursor will have no
effect.
GLFW uses the [idle inhibit GLFW uses the
protocol](https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml) [idle inhibit protocol](https://wayland.app/protocols/idle-inhibit-unstable-v1)
to prohibit the screensaver from starting. This protocol is part of to prohibit the screensaver from starting. If the running compositor does not
wayland-protocols 1.6, and mandatory at build time. If the running compositor support this protocol, the screensaver may start even for full screen windows.
does not support this protocol, the screensaver may start even for full screen
windows.
GLFW uses the [xdg-decoration GLFW uses the
protocol](https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml) [libdecor library](https://gitlab.freedesktop.org/libdecor/libdecor) for window
decorations, where available. This in turn provides good quality client-side
decorations (drawn by the application) on desktop systems that do not support
server-side decorations (drawn by the window manager). On systems that do not
provide either libdecor or xdg-decoration, very basic window decorations are
provided. These do not include the window title or any caption buttons.
GLFW uses the
[xdg-decoration protocol](https://wayland.app/protocols/xdg-decoration-unstable-v1)
to request decorations to be drawn around its windows. This protocol is part to request decorations to be drawn around its windows. This protocol is part
of wayland-protocols 1.15, and mandatory at build time. If the running of wayland-protocols 1.15, and mandatory at build time. If the running
compositor does not support this protocol, a very simple frame will be drawn by compositor does not support this protocol, a very simple frame will be drawn by
GLFW itself, using the [viewporter GLFW itself, using the
protocol](https://cgit.freedesktop.org/wayland/wayland-protocols/tree/stable/viewporter/viewporter.xml) [viewporter protocol](https://wayland.app/protocols/viewporter)
alongside alongside subsurfaces. If the running compositor does not support these
[subsurfaces](https://cgit.freedesktop.org/wayland/wayland/tree/protocol/wayland.xml#n2598). protocols either, no decorations will be drawn around windows.
This protocol is part of wayland-protocols 1.4, and mandatory at build time.
If the running compositor does not support this protocol either, no decorations
will be drawn around windows.
@section compat_glx GLX extensions @section compat_glx GLX extensions
@ -152,7 +151,7 @@ formats. If GLX 1.3 is not supported, @ref glfwInit will fail.
GLFW uses the `GLX_MESA_swap_control,` `GLX_EXT_swap_control` and GLFW uses the `GLX_MESA_swap_control,` `GLX_EXT_swap_control` and
`GLX_SGI_swap_control` extensions to provide vertical retrace synchronization `GLX_SGI_swap_control` extensions to provide vertical retrace synchronization
(or _vsync_), in that order of preference. Where none of these extension are (or _vsync_), in that order of preference. When none of these extensions are
available, calling @ref glfwSwapInterval will have no effect. available, calling @ref glfwSwapInterval will have no effect.
GLFW uses the `GLX_ARB_multisample` extension to create contexts with GLFW uses the `GLX_ARB_multisample` extension to create contexts with
@ -219,8 +218,8 @@ extension is unavailable, the `GLFW_CONTEXT_RELEASE_BEHAVIOR` hint will have no
effect and the context will always be flushed when released. effect and the context will always be flushed when released.
GLFW uses the `WGL_ARB_framebuffer_sRGB` and `WGL_EXT_framebuffer_sRGB` GLFW uses the `WGL_ARB_framebuffer_sRGB` and `WGL_EXT_framebuffer_sRGB`
extensions to provide support for sRGB framebuffers. Where both of these extensions to provide support for sRGB framebuffers. When both of these
extension are unavailable, the `GLFW_SRGB_CAPABLE` hint will have no effect. extensions are unavailable, the `GLFW_SRGB_CAPABLE` hint will have no effect.
@section compat_osx OpenGL on macOS @section compat_osx OpenGL on macOS

View File

@ -7,6 +7,8 @@
This is about compiling the GLFW library itself. For information on how to This is about compiling the GLFW library itself. For information on how to
build applications that use GLFW, see @ref build_guide. build applications that use GLFW, see @ref build_guide.
GLFW uses some C99 features and does not support Visual Studio 2012 and earlier.
@section compile_cmake Using CMake @section compile_cmake Using CMake
@ -45,7 +47,7 @@ Linux and FreeBSD you will need a few extra packages.
To compile GLFW for X11, you need to have the X11 development packages To compile GLFW for X11, you need to have the X11 development packages
installed. They are not needed to build or run programs that use GLFW. installed. They are not needed to build or run programs that use GLFW.
On Debian and derivates like Ubuntu and Linux Mint the `xorg-dev` meta-package On Debian and derivatives like Ubuntu and Linux Mint the `xorg-dev` meta-package
pulls in the development packages for all of X11. pulls in the development packages for all of X11.
@code{.sh} @code{.sh}
@ -68,8 +70,10 @@ install the `xorgproto` package.
pkg install xorgproto pkg install xorgproto
@endcode @endcode
On Cygwin the `xorgproto` package in the Devel section of the GUI installer will On Cygwin the `libXcursor-devel`, `libXi-devel`, `libXinerama-devel`,
install the headers and other development related files for all of X11. `libXrandr-devel` and `libXrender-devel` packages in the Libs section of the GUI
installer will install all the headers and other development related files GLFW
requires for X11.
Once you have the required dependencies, move on to @ref compile_generate. Once you have the required dependencies, move on to @ref compile_generate.
@ -81,29 +85,28 @@ development packages installed. They are not needed to build or run programs th
GLFW. You will also need to set the @ref GLFW_BUILD_WAYLAND CMake option in the next GLFW. You will also need to set the @ref GLFW_BUILD_WAYLAND CMake option in the next
step when generating build files. step when generating build files.
On Debian and derivates like Ubuntu and Linux Mint you will need the `libwayland-dev`, On Debian and derivatives like Ubuntu and Linux Mint you will need the `libwayland-dev`
`libxkbcommon-dev` and `wayland-protocols` packages and the `xorg-dev` meta-package. and `libxkbcommon-dev` packages and the `xorg-dev` meta-package. These will pull in all
These will pull in all other dependencies. other dependencies.
@code{.sh} @code{.sh}
sudo apt install libwayland-dev libxkbcommon-dev wayland-protocols xorg-dev sudo apt install libwayland-dev libxkbcommon-dev xorg-dev
@endcode @endcode
On Fedora and derivatives like Red Hat you will need the `wayland-devel`, On Fedora and derivatives like Red Hat you will need the `wayland-devel`,
`libxkbcommon-devel`, `wayland-protocols-devel`, `libXcursor-devel`, `libXi-devel`, `libxkbcommon-devel`, `libXcursor-devel`, `libXi-devel`, `libXinerama-devel` and
`libXinerama-devel` and `libXrandr-devel` packages. These will pull in all other `libXrandr-devel` packages. These will pull in all other dependencies.
dependencies.
@code{.sh} @code{.sh}
sudo dnf install wayland-devel libxkbcommon-devel wayland-protocols-devel libXcursor-devel libXi-devel libXinerama-devel libXrandr-devel sudo dnf install wayland-devel libxkbcommon-devel libXcursor-devel libXi-devel libXinerama-devel libXrandr-devel
@endcode @endcode
On FreeBSD you will need the `wayland`, `libxkbcommon` and `wayland-protocols` packages. On FreeBSD you will need the `wayland` and `libxkbcommon` packages. The X11 headers are
The X11 headers are installed along the end-user X11 packages, so if you have an X server installed along the end-user X11 packages, so if you have an X server running you should
running you should have the headers as well. If not, install the `xorgproto` package. have the headers as well. If not, install the `xorgproto` package.
@code{.sh} @code{.sh}
pkg install wayland libxkbcommon wayland-protocols xorgproto pkg install wayland libxkbcommon xorgproto
@endcode @endcode
Once you have the required dependencies, move on to @ref compile_generate. Once you have the required dependencies, move on to @ref compile_generate.
@ -140,7 +143,7 @@ If you wish change any CMake variables in the list, press _Configure_ and then
_Generate_ to have the new values take effect. The variable list will be _Generate_ to have the new values take effect. The variable list will be
populated after the first configure step. populated after the first configure step.
By default GLFW will use X11 on Linux and other Unix-like systems other than macOS. To By default, GLFW will use X11 on Linux and other Unix-like systems other than macOS. To
include support for Wayland as well, set the @ref GLFW_BUILD_WAYLAND option in the GLFW include support for Wayland as well, set the @ref GLFW_BUILD_WAYLAND option in the GLFW
section of the variable list, then apply the new value as described above. section of the variable list, then apply the new value as described above.
@ -174,7 +177,7 @@ flag.
cmake -S path/to/glfw -B path/to/build -G Xcode cmake -S path/to/glfw -B path/to/build -G Xcode
@endcode @endcode
By default GLFW will use X11 on Linux and other Unix-like systems other By default, GLFW will use X11 on Linux and other Unix-like systems other
than macOS. To also include support for Wayland, set the @ref GLFW_BUILD_WAYLAND CMake than macOS. To also include support for Wayland, set the @ref GLFW_BUILD_WAYLAND CMake
option. option.
@ -261,12 +264,12 @@ build GLFW as a static library, `SHARED` to build it as a shared library
@anchor GLFW_BUILD_EXAMPLES @anchor GLFW_BUILD_EXAMPLES
__GLFW_BUILD_EXAMPLES__ determines whether the GLFW examples are built __GLFW_BUILD_EXAMPLES__ determines whether the GLFW examples are built
along with the library. This is enabled by default unless GLFW is being built along with the library. This is enabled by default unless GLFW is being built
as a sub-project of a larger CMake project. as a subproject of a larger CMake project.
@anchor GLFW_BUILD_TESTS @anchor GLFW_BUILD_TESTS
__GLFW_BUILD_TESTS__ determines whether the GLFW test programs are __GLFW_BUILD_TESTS__ determines whether the GLFW test programs are
built along with the library. This is enabled by default unless GLFW is being built along with the library. This is enabled by default unless GLFW is being
built as a sub-project of a larger CMake project. built as a subproject of a larger CMake project.
@anchor GLFW_BUILD_DOCS @anchor GLFW_BUILD_DOCS
__GLFW_BUILD_DOCS__ determines whether the GLFW documentation is built along __GLFW_BUILD_DOCS__ determines whether the GLFW documentation is built along
@ -356,7 +359,7 @@ For more details see the
@section compile_manual Compiling GLFW manually @section compile_manual Compiling GLFW manually
If you wish to compile GLFW without its CMake build environment then you will have to do If you wish to compile GLFW without its CMake build environment then you will have to do
at least some of the platform detection yourself. There are preprocessor macros for at least some platform-detection yourself. There are preprocessor macros for
enabling support for the platforms (window systems) available. There are also optional, enabling support for the platforms (window systems) available. There are also optional,
platform-specific macros for various features. platform-specific macros for various features.

View File

@ -61,7 +61,7 @@ information. The name and number of this chapter unfortunately varies between
versions and APIs, but has at times been named _Shared Objects and Multiple versions and APIs, but has at times been named _Shared Objects and Multiple
Contexts_. Contexts_.
GLFW comes with a barebones object sharing example program called `sharing`. GLFW comes with a bare-bones object sharing example program called `sharing`.
@subsection context_offscreen Offscreen contexts @subsection context_offscreen Offscreen contexts
@ -88,9 +88,10 @@ window, even if none of them are visible.
@subsection context_less Windows without contexts @subsection context_less Windows without contexts
You can disable context creation by setting the You can disable context creation by setting the
[GLFW_CLIENT_API](@ref GLFW_CLIENT_API_hint) hint to `GLFW_NO_API`. Windows [GLFW_CLIENT_API](@ref GLFW_CLIENT_API_hint) hint to `GLFW_NO_API`.
without contexts must not be passed to @ref glfwMakeContextCurrent or @ref
glfwSwapBuffers. Windows without contexts should not be passed to @ref glfwMakeContextCurrent or
@ref glfwSwapBuffers. Doing this generates a @ref GLFW_NO_WINDOW_CONTEXT error.
@section context_current Current context @section context_current Current context
@ -189,7 +190,7 @@ it suppresses the development environment's OpenGL or OpenGL ES header.
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@endcode @endcode
Finally you need to initialize glad once you have a suitable current context. Finally, you need to initialize glad once you have a suitable current context.
@code @code
window = glfwCreateWindow(640, 480, "My Window", NULL, NULL); window = glfwCreateWindow(640, 480, "My Window", NULL, NULL);
@ -205,7 +206,7 @@ gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
Once glad has been loaded, you have access to all OpenGL core and extension Once glad has been loaded, you have access to all OpenGL core and extension
functions supported by both the context you created and the glad loader you functions supported by both the context you created and the glad loader you
generated and you are ready to start rendering. generated. After that, you are ready to start rendering.
You can specify a minimum required OpenGL or OpenGL ES version with You can specify a minimum required OpenGL or OpenGL ES version with
[context hints](@ref window_hints_ctx). If your needs are more complex, you can [context hints](@ref window_hints_ctx). If your needs are more complex, you can

View File

@ -24,7 +24,7 @@ All input callbacks receive a window handle. By using the
or objects from your callbacks. or objects from your callbacks.
To get a better feel for how the various events callbacks behave, run the To get a better feel for how the various events callbacks behave, run the
`events` test program. It register every callback supported by GLFW and prints `events` test program. It registers every callback supported by GLFW and prints
out all arguments provided for every event, along with time and sequence out all arguments provided for every event, along with time and sequence
information. information.
@ -95,7 +95,7 @@ new size before everything returns back out of the @ref glfwSetWindowSize call.
GLFW divides keyboard input into two categories; key events and character GLFW divides keyboard input into two categories; key events and character
events. Key events relate to actual physical keyboard keys, whereas character events. Key events relate to actual physical keyboard keys, whereas character
events relate to the Unicode code points generated by pressing some of them. events relate to the text that is generated by pressing some of them.
Keys and characters do not map 1:1. A single key press may produce several Keys and characters do not map 1:1. A single key press may produce several
characters, and a single character may require several keys to produce. This characters, and a single character may require several keys to produce. This
@ -123,23 +123,39 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
} }
@endcode @endcode
The action is one of `GLFW_PRESS`, `GLFW_REPEAT` or `GLFW_RELEASE`. The key The action is one of `GLFW_PRESS`, `GLFW_REPEAT` or `GLFW_RELEASE`. Events with
will be `GLFW_KEY_UNKNOWN` if GLFW lacks a key token for it, for example `GLFW_PRESS` and `GLFW_RELEASE` actions are emitted for every key press. Most
_E-mail_ and _Play_ keys. keys will also emit events with `GLFW_REPEAT` actions while a key is held down.
Note that many keyboards have a limit on how many keys being simultaneous held
down that they can detect. This limit is called
[key rollover](https://en.wikipedia.org/wiki/Key_rollover).
Key events with `GLFW_REPEAT` actions are intended for text input. They are
emitted at the rate set in the user's keyboard settings. At most one key is
repeated even if several keys are held down. `GLFW_REPEAT` actions should not
be relied on to know which keys are being held down or to drive animation.
Instead you should either save the state of relevant keys based on `GLFW_PRESS`
and `GLFW_RELEASE` actions, or call @ref glfwGetKey, which provides basic cached
key state.
The key will be one of the existing [key tokens](@ref keys), or
`GLFW_KEY_UNKNOWN` if GLFW lacks a token for it, for example _E-mail_ and _Play_
keys.
The scancode is unique for every key, regardless of whether it has a key token. The scancode is unique for every key, regardless of whether it has a key token.
Scancodes are platform-specific but consistent over time, so keys will have Scancodes are platform-specific but consistent over time, so keys will have
different scancodes depending on the platform but they are safe to save to disk. different scancodes depending on the platform but they are safe to save to disk.
You can query the scancode for any [named key](@ref keys) on the current You can query the scancode for any [key token](@ref keys) supported on the
platform with @ref glfwGetKeyScancode. current platform with @ref glfwGetKeyScancode.
@code @code
const int scancode = glfwGetKeyScancode(GLFW_KEY_X); const int scancode = glfwGetKeyScancode(GLFW_KEY_X);
set_key_mapping(scancode, swap_weapons); set_key_mapping(scancode, swap_weapons);
@endcode @endcode
The last reported state for every [named key](@ref keys) is also saved in The last reported state for every physical key with a [key token](@ref keys) is
per-window state arrays that can be polled with @ref glfwGetKey. also saved in per-window state arrays that can be polled with @ref glfwGetKey.
@code @code
int state = glfwGetKey(window, GLFW_KEY_E); int state = glfwGetKey(window, GLFW_KEY_E);
@ -152,7 +168,8 @@ if (state == GLFW_PRESS)
The returned state is one of `GLFW_PRESS` or `GLFW_RELEASE`. The returned state is one of `GLFW_PRESS` or `GLFW_RELEASE`.
This function only returns cached key event state. It does not poll the This function only returns cached key event state. It does not poll the
system for the current physical state of the key. system for the current state of the physical key. It also does not provide any
key repeat information.
@anchor GLFW_STICKY_KEYS @anchor GLFW_STICKY_KEYS
Whenever you poll state, you risk missing the state change you are looking for. Whenever you poll state, you risk missing the state change you are looking for.
@ -183,15 +200,15 @@ Lock was on when the event occurred and the @ref GLFW_MOD_NUM_LOCK bit set if
Num Lock was on. Num Lock was on.
The `GLFW_KEY_LAST` constant holds the highest value of any The `GLFW_KEY_LAST` constant holds the highest value of any
[named key](@ref keys). [key token](@ref keys).
@subsection input_char Text input @subsection input_char Text input
GLFW supports text input in the form of a stream of GLFW supports text input in the form of a stream of
[Unicode code points](https://en.wikipedia.org/wiki/Unicode), as produced by the [Unicode code points](https://en.wikipedia.org/wiki/Unicode), as produced by the
operating system text input system. Unlike key input, text input obeys keyboard operating system text input system. Unlike key input, text input is affected by
layouts and modifier keys and supports composing characters using keyboard layouts and modifier keys and supports composing characters using
[dead keys](https://en.wikipedia.org/wiki/Dead_key). Once received, you can [dead keys](https://en.wikipedia.org/wiki/Dead_key). Once received, you can
encode the code points into UTF-8 or any other encoding you prefer. encode the code points into UTF-8 or any other encoding you prefer.
@ -300,6 +317,16 @@ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
This mode puts no limit on the motion of the cursor. This mode puts no limit on the motion of the cursor.
If you wish the cursor to be visible but confined to the content area of the
window, set the cursor mode to `GLFW_CURSOR_CAPTURED`.
@code
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_CAPTURED);
@endcode
The cursor will behave normally inside the content area but will not be able to
leave unless the window loses focus.
To exit out of either of these special modes, restore the `GLFW_CURSOR_NORMAL` To exit out of either of these special modes, restore the `GLFW_CURSOR_NORMAL`
cursor mode. cursor mode.
@ -307,6 +334,8 @@ cursor mode.
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
@endcode @endcode
If the cursor was disabled, this will move it back to its last visible position.
@anchor GLFW_RAW_MOUSE_MOTION @anchor GLFW_RAW_MOUSE_MOTION
@subsection raw_mouse_motion Raw mouse motion @subsection raw_mouse_motion Raw mouse motion
@ -370,7 +399,7 @@ sequential rows, starting from the top-left corner.
@subsubsection cursor_standard Standard cursor creation @subsubsection cursor_standard Standard cursor creation
A cursor with a [standard shape](@ref shapes) from the current system cursor A cursor with a [standard shape](@ref shapes) from the current system cursor
theme can be can be created with @ref glfwCreateStandardCursor. theme can be created with @ref glfwCreateStandardCursor.
@code @code
GLFWcursor* url_cursor = glfwCreateStandardCursor(GLFW_POINTING_HAND_CURSOR); GLFWcursor* url_cursor = glfwCreateStandardCursor(GLFW_POINTING_HAND_CURSOR);
@ -478,8 +507,9 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
The action is one of `GLFW_PRESS` or `GLFW_RELEASE`. The action is one of `GLFW_PRESS` or `GLFW_RELEASE`.
Mouse button states for [named buttons](@ref buttons) are also saved in The last reported state for every [supported mouse button](@ref buttons) is also
per-window state arrays that can be polled with @ref glfwGetMouseButton. saved in per-window state arrays that can be polled with @ref
glfwGetMouseButton.
@code @code
int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT); int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT);
@ -512,7 +542,7 @@ had been processed in the meantime, the state will reset to `GLFW_RELEASE`,
otherwise it will remain `GLFW_PRESS`. otherwise it will remain `GLFW_PRESS`.
The `GLFW_MOUSE_BUTTON_LAST` constant holds the highest value of any The `GLFW_MOUSE_BUTTON_LAST` constant holds the highest value of any
[named button](@ref buttons). [supported mouse button](@ref buttons).
@subsection scrolling Scroll input @subsection scrolling Scroll input
@ -821,7 +851,7 @@ The second value is always the human-readable name of the gamepad.
All subsequent values are in the form `<field>:<value>` and describe the layout All subsequent values are in the form `<field>:<value>` and describe the layout
of the mapping. These fields may not all be present and may occur in any order. of the mapping. These fields may not all be present and may occur in any order.
The button fields are `a`, `b`, `c`, `d`, `back`, `start`, `guide`, `dpup`, The button fields are `a`, `b`, `x`, `y`, `back`, `start`, `guide`, `dpup`,
`dpright`, `dpdown`, `dpleft`, `leftshoulder`, `rightshoulder`, `leftstick` and `dpright`, `dpdown`, `dpleft`, `leftshoulder`, `rightshoulder`, `leftstick` and
`rightstick`. `rightstick`.

View File

@ -144,6 +144,15 @@ the `VK_KHR_xlib_surface` extension. Possible values are `GLFW_TRUE` and
`GLFW_FALSE`. This is ignored on other platforms. `GLFW_FALSE`. This is ignored on other platforms.
@subsubsection init_hints_wayland Wayland specific init hints
@anchor GLFW_WAYLAND_LIBDECOR_hint
__GLFW_WAYLAND_LIBDECOR__ specifies whether to use
[libdecor](https://gitlab.freedesktop.org/libdecor/libdecor) for window
decorations where available. Possible values are `GLFW_WAYLAND_PREFER_LIBDECOR`
and `GLFW_WAYLAND_DISABLE_LIBDECOR`. This is ignored on other platforms.
@subsubsection init_hints_values Supported and default values @subsubsection init_hints_values Supported and default values
Initialization hint | Default value | Supported values Initialization hint | Default value | Supported values
@ -154,6 +163,7 @@ Initialization hint | Default value | Supported v
@ref GLFW_COCOA_CHDIR_RESOURCES | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` @ref GLFW_COCOA_CHDIR_RESOURCES | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
@ref GLFW_COCOA_MENUBAR | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` @ref GLFW_COCOA_MENUBAR | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
@ref GLFW_X11_XCB_VULKAN_SURFACE | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` @ref GLFW_X11_XCB_VULKAN_SURFACE | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
@ref GLFW_WAYLAND_LIBDECOR | `GLFW_WAYLAND_PREFER_LIBDECOR` | `GLFW_WAYLAND_PREFER_LIBDECOR` or `GLFW_WAYLAND_DISABLE_LIBDECOR`
@subsection platform Runtime platform selection @subsection platform Runtime platform selection
@ -162,7 +172,7 @@ GLFW can be compiled for more than one platform (window system) at once. This l
a single library binary support both X11 and Wayland on Linux and other Unix-like systems. a single library binary support both X11 and Wayland on Linux and other Unix-like systems.
You can control platform selection via the @ref GLFW_PLATFORM initialization hint. By You can control platform selection via the @ref GLFW_PLATFORM initialization hint. By
default this is set to @ref GLFW_ANY_PLATFORM, which will look for supported window default, this is set to @ref GLFW_ANY_PLATFORM, which will look for supported window
systems in order of priority and select the first one it finds. It can also be set to any systems in order of priority and select the first one it finds. It can also be set to any
specific platform to have GLFW only look for that one. specific platform to have GLFW only look for that one.
@ -269,9 +279,9 @@ This will destroy any remaining window, monitor and cursor objects, restore any
modified gamma ramps, re-enable the screensaver if it had been disabled and free modified gamma ramps, re-enable the screensaver if it had been disabled and free
any other resources allocated by GLFW. any other resources allocated by GLFW.
Once the library is terminated, it is as if it had never been initialized and Once the library is terminated, it is as if it had never been initialized, therefore
you will need to initialize it again before being able to use GLFW. If the you will need to initialize it again before being able to use GLFW. If the
library was not initialized or had already been terminated, it return library was not initialized or had already been terminated, it returns
immediately. immediately.
@ -391,14 +401,14 @@ which monitor the window is currently considered to be on.
This section describes the conditions under which GLFW can be expected to This section describes the conditions under which GLFW can be expected to
function, barring bugs in the operating system or drivers. Use of GLFW outside function, barring bugs in the operating system or drivers. Use of GLFW outside
of these limits may work on some platforms, or on some machines, or some of the these limits may work on some platforms, or on some machines, or some of the
time, or on some versions of GLFW, but it may break at any time and this will time, or on some versions of GLFW, but it may break at any time and this will
not be considered a bug. not be considered a bug.
@subsection lifetime Pointer lifetimes @subsection lifetime Pointer lifetimes
GLFW will never free any pointer you provide to it and you must never free any GLFW will never free any pointer you provide to it, and you must never free any
pointer it provides to you. pointer it provides to you.
Many GLFW functions return pointers to dynamically allocated structures, strings Many GLFW functions return pointers to dynamically allocated structures, strings
@ -602,15 +612,15 @@ The format of the string is as follows:
- The names of the always supported context creation APIs EGL and OSMesa - The names of the always supported context creation APIs EGL and OSMesa
- Any additional compile-time options, APIs and (on Windows) what compiler was used - Any additional compile-time options, APIs and (on Windows) what compiler was used
For example, GLFW 3.4 compiled as a DLL for Windows with MinGW may have a version string For example, compiling GLFW 3.4 with MinGW as a DLL for Windows, may result in a version string
like this: like this:
@code @code
3.4.0 Win32 WGL Null EGL OSMesa MinGW DLL 3.4.0 Win32 WGL Null EGL OSMesa MinGW DLL
@endcode @endcode
While GLFW compiled as as static library for Linux with both Wayland and X11 enabled may Compiling GLFW as a static library for Linux, with both Wayland and X11 enabled, may
have a version string like this: result in a version string like this:
@code @code
3.4.0 Wayland X11 GLX Null EGL OSMesa monotonic 3.4.0 Wayland X11 GLX Null EGL OSMesa monotonic

View File

@ -138,7 +138,7 @@ glfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm);
@endcode @endcode
While this can be used to calculate the raw DPI of a monitor, this is often not While this can be used to calculate the raw DPI of a monitor, this is often not
useful. Instead use the [monitor content scale](@ref monitor_scale) and useful. Instead, use the [monitor content scale](@ref monitor_scale) and
[window content scale](@ref window_scale) to scale your content. [window content scale](@ref window_scale) to scale your content.
@ -261,7 +261,7 @@ To experiment with gamma correction via the @ref glfwSetGamma function, run the
`gamma` test program. `gamma` test program.
@note The software controlled gamma ramp is applied _in addition_ to the @note The software controlled gamma ramp is applied _in addition_ to the
hardware gamma correction, which today is usually an approximation of sRGB hardware gamma correction, which today is typically an approximation of sRGB
gamma. This means that setting a perfectly linear ramp, or gamma 1.0, will gamma. This means that setting a perfectly linear ramp, or gamma 1.0, will
produce the default (usually sRGB-like) behavior. produce the default (usually sRGB-like) behavior.

View File

@ -243,7 +243,7 @@ while (!glfwWindowShouldClose(window))
@endcode @endcode
The close callback no longer returns a value. Instead, it is called after the The close callback no longer returns a value. Instead, it is called after the
close flag has been set so it can override its value, if it chooses to, before close flag has been set, so it can optionally override its value, before
event processing completes. You may however not call @ref glfwDestroyWindow event processing completes. You may however not call @ref glfwDestroyWindow
from the close callback (or any other window related callback). from the close callback (or any other window related callback).
@ -350,11 +350,11 @@ from a repeat. Note that @ref glfwGetKey still returns only `GLFW_PRESS` or
GLFW 3 key tokens map to physical keys, unlike in GLFW 2 where they mapped to GLFW 3 key tokens map to physical keys, unlike in GLFW 2 where they mapped to
the values generated by the current keyboard layout. The tokens are named the values generated by the current keyboard layout. The tokens are named
according to the values they would have using the standard US layout, but this according to the values they would have in the standard US layout, but this
is only a convenience, as most programmers are assumed to know that layout. is only a convenience, as most programmers are assumed to know that layout.
This means that (for example) `GLFW_KEY_LEFT_BRACKET` is always a single key and This means that (for example) `GLFW_KEY_LEFT_BRACKET` is always a single key and
is the same key in the same place regardless of what keyboard layouts the users is the same key in the same place regardless of what keyboard layouts the users
of your program has. of your program have.
The key input facility was never meant for text input, although using it that The key input facility was never meant for text input, although using it that
way worked slightly better in GLFW 2. If you were using it to input text, you way worked slightly better in GLFW 2. If you were using it to input text, you

View File

@ -21,7 +21,7 @@ support for a given platform is compiled in with @ref glfwPlatformSupported.
GLFW now provides the standard cursor shapes @ref GLFW_RESIZE_NWSE_CURSOR and GLFW now provides the standard cursor shapes @ref GLFW_RESIZE_NWSE_CURSOR and
@ref GLFW_RESIZE_NESW_CURSOR for diagonal resizing, @ref GLFW_RESIZE_ALL_CURSOR @ref GLFW_RESIZE_NESW_CURSOR for diagonal resizing, @ref GLFW_RESIZE_ALL_CURSOR
for omni-directional resizing and @ref GLFW_NOT_ALLOWED_CURSOR for showing an for omnidirectional resizing and @ref GLFW_NOT_ALLOWED_CURSOR for showing an
action is not allowed. action is not allowed.
Unlike the original set, these shapes may not be available everywhere and Unlike the original set, these shapes may not be available everywhere and
@ -43,6 +43,22 @@ to whatever window is behind it. This can also be changed after window
creation with the matching [window attribute](@ref GLFW_MOUSE_PASSTHROUGH_attrib). creation with the matching [window attribute](@ref GLFW_MOUSE_PASSTHROUGH_attrib).
@subsubsection wayland_libdecor_34 Wayland libdecor decorations
GLFW now supports improved fallback window decorations via
[libdecor](https://gitlab.freedesktop.org/libdecor/libdecor).
Support for libdecor can be toggled before GLFW is initialized with the
[GLFW_WAYLAND_LIBDECOR](@ref GLFW_WAYLAND_LIBDECOR_hint) init hint. It is
enabled by default.
@subsubsection wayland_app_id_34 Wayland app_id specification
GLFW now supports specifying the app_id for a Wayland window using the
[GLFW_WAYLAND_APP_ID](@ref GLFW_WAYLAND_APP_ID_hint) window hint string.
@subsubsection features_34_angle_backend Support for ANGLE rendering backend selection @subsubsection features_34_angle_backend Support for ANGLE rendering backend selection
GLFW now provides the GLFW now provides the
@ -52,6 +68,14 @@ requesting a specific rendering backend when using
contexts. contexts.
@subsubsection captured_cursor_34 Captured cursor mode
GLFW now supports confining the cursor to the window content area with the @ref
GLFW_CURSOR_CAPTURED cursor mode.
For more information see @ref cursor_mode.
@subsubsection features_34_init_allocator Support for custom memory allocator @subsubsection features_34_init_allocator Support for custom memory allocator
GLFW now supports plugging a custom memory allocator at initialization with @ref GLFW now supports plugging a custom memory allocator at initialization with @ref
@ -62,6 +86,14 @@ function pointers corresponding to the standard library functions `malloc`,
For more information see @ref init_allocator. For more information see @ref init_allocator.
@subsubsection features_34_position_hint Window hints for initial position
GLFW now provides the @ref GLFW_POSITION_X and @ref GLFW_POSITION_Y window hints for
specifying the initial position of the window. This removes the need to create a hidden
window, move it and then show it. The default value of these hints is
`GLFW_ANY_POSITION`, which selects the previous behavior.
@subsubsection features_34_win32_keymenu Support for keyboard access to Windows window menu @subsubsection features_34_win32_keymenu Support for keyboard access to Windows window menu
GLFW now provides the GLFW now provides the
@ -78,7 +110,7 @@ applications.
Because GLFW now supports runtime selection of platform (window system), a library binary Because GLFW now supports runtime selection of platform (window system), a library binary
may export native access functions for multiple platforms. Starting with version 3.4 you may export native access functions for multiple platforms. Starting with version 3.4 you
must not assume that GLFW is running on a platform just because it exports native access must not assume that GLFW is running on a platform just because it exports native access
functions for it. After initialization you can query the selected platform with @ref functions for it. After initialization, you can query the selected platform with @ref
glfwGetPlatform. glfwGetPlatform.
@ -104,7 +136,20 @@ To work around this, call any joystick function before waiting for events, for
example by setting a [joystick callback](@ref joystick_event). example by setting a [joystick callback](@ref joystick_event).
@subsubsection standalone_34 Tests and examples are disabled when built as a sub-project @subsubsection wayland_alpha_34 Frambuffer may lack alpha channel on older Wayland systems
On Wayland, when creating an EGL context on a machine lacking the new
`EGL_EXT_present_opaque` extension, the @ref GLFW_ALPHA_BITS window hint will be
ignored and the framebuffer will have no alpha channel. This is because some
Wayland compositors treat any buffer with an alpha channel as per-pixel
transparent.
If you want a per-pixel transparent window, see the
[GLFW_TRANSPARENT_FRAMEBUFFER](@ref GLFW_TRANSPARENT_FRAMEBUFFER_hint) window
hint.
@subsubsection standalone_34 Tests and examples are disabled when built as a subproject
GLFW now does not build the tests and examples when it is added as GLFW now does not build the tests and examples when it is added as
a subdirectory of another CMake project. To enable these, set the @ref a subdirectory of another CMake project. To enable these, set the @ref
@ -138,6 +183,12 @@ GLFW_TRANSPARENT_FRAMEBUFFER on Windows 7 if DWM transparency is off
(the Transparency setting under Personalization > Window Color). (the Transparency setting under Personalization > Window Color).
@subsubsection emptyevents_34 Empty events on X11 no longer round-trip to server
Events posted with @ref glfwPostEmptyEvent now use a separate unnamed pipe
instead of sending an X11 client event to the helper window.
@subsection deprecations_34 Deprecations in version 3.4 @subsection deprecations_34 Deprecations in version 3.4
@subsection removals_34 Removals in 3.4 @subsection removals_34 Removals in 3.4
@ -222,6 +273,14 @@ then GLFW will fail to initialize.
- @ref GLFW_ANGLE_PLATFORM_TYPE_VULKAN - @ref GLFW_ANGLE_PLATFORM_TYPE_VULKAN
- @ref GLFW_ANGLE_PLATFORM_TYPE_METAL - @ref GLFW_ANGLE_PLATFORM_TYPE_METAL
- @ref GLFW_X11_XCB_VULKAN_SURFACE - @ref GLFW_X11_XCB_VULKAN_SURFACE
- @ref GLFW_CURSOR_CAPTURED
- @ref GLFW_POSITION_X
- @ref GLFW_POSITION_Y
- @ref GLFW_ANY_POSITION
- @ref GLFW_WAYLAND_APP_ID
- @ref GLFW_WAYLAND_LIBDECOR
- @ref GLFW_WAYLAND_PREFER_LIBDECOR
- @ref GLFW_WAYLAND_DISABLE_LIBDECOR
@section news_archive Release notes for earlier versions @section news_archive Release notes for earlier versions

View File

@ -149,10 +149,6 @@ if (!window)
} }
@endcode @endcode
The window handle is passed to all window related functions and is provided to
along to all window related callbacks, so they can tell which window received
the event.
When a window and context is no longer needed, destroy it. When a window and context is no longer needed, destroy it.
@code @code
@ -238,7 +234,7 @@ events as described below.
@subsection quick_render Rendering with OpenGL @subsection quick_render Rendering with OpenGL
Once you have a current OpenGL context, you can use OpenGL normally. In this Once you have a current OpenGL context, you can use OpenGL normally. In this
tutorial, a multi-colored rotating triangle will be rendered. The framebuffer tutorial, a multicolored rotating triangle will be rendered. The framebuffer
size needs to be retrieved for `glViewport`. size needs to be retrieved for `glViewport`.
@code @code

View File

@ -37,8 +37,8 @@ By default, GLFW will load the Vulkan loader dynamically at runtime via its stan
`vulkan-1.dll` on Windows, `libvulkan.so.1` on Linux and other Unix-like systems and `vulkan-1.dll` on Windows, `libvulkan.so.1` on Linux and other Unix-like systems and
`libvulkan.1.dylib` on macOS. `libvulkan.1.dylib` on macOS.
@macos GLFW will also look up and search the executable subdirectory of your application @macos GLFW will also look up and search the `Frameworks` subdirectory of your
bundle. application bundle.
If your code is using a Vulkan loader with a different name or in a non-standard location If your code is using a Vulkan loader with a different name or in a non-standard location
you will need to direct GLFW to it. Pass your version of `vkGetInstanceProcAddr` to @ref you will need to direct GLFW to it. Pass your version of `vkGetInstanceProcAddr` to @ref
@ -142,7 +142,7 @@ PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)
glfwGetInstanceProcAddress(instance, "vkGetDeviceProcAddr"); glfwGetInstanceProcAddress(instance, "vkGetDeviceProcAddr");
@endcode @endcode
Device-specific functions may execute a little bit faster, due to not having to Device-specific functions may execute a little faster, due to not having to
dispatch internally based on the device passed to them. For more information dispatch internally based on the device passed to them. For more information
about `vkGetDeviceProcAddr`, see the Vulkan documentation. about `vkGetDeviceProcAddr`, see the Vulkan documentation.
@ -188,6 +188,13 @@ check whether 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 array, as it is an error to specify an extension more than once in the
`VkInstanceCreateInfo` struct. `VkInstanceCreateInfo` struct.
@macos MoltenVK is (as of July 2022) not yet a fully conformant implementation
of Vulkan. As of Vulkan SDK 1.3.216.0, this means you must also enable the
`VK_KHR_portability_enumeration` instance extension and set the
`VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR` bit in the instance creation
info flags for MoltenVK to show up in the list of physical devices. For more
information, see the Vulkan and MoltenVK documentation.
@section vulkan_present Querying for Vulkan presentation support @section vulkan_present Querying for Vulkan presentation support

View File

@ -256,6 +256,14 @@ This is only supported for undecorated windows. Decorated windows with this
enabled will behave differently between platforms. Possible values are enabled will behave differently between platforms. Possible values are
`GLFW_TRUE` and `GLFW_FALSE`. `GLFW_TRUE` and `GLFW_FALSE`.
@anchor GLFW_POSITION_X
@anchor GLFW_POSITION_Y
__GLFW_POSITION_X__ and __GLFW_POSITION_Y__ specify the desired initial position
of the window. The window manager may modify or ignore these coordinates. If
either or both of these hints are set to `GLFW_ANY_POSITION` then the window
manager will position the window where it thinks the user will prefer it.
Possible values are any valid screen coordinates and `GLFW_ANY_POSITION`.
@subsubsection window_hints_fb Framebuffer related hints @subsubsection window_hints_fb Framebuffer related hints
@ -489,9 +497,17 @@ should also declare this in its `Info.plist` by setting the
@anchor GLFW_X11_CLASS_NAME_hint @anchor GLFW_X11_CLASS_NAME_hint
@anchor GLFW_X11_INSTANCE_NAME_hint @anchor GLFW_X11_INSTANCE_NAME_hint
__GLFW_X11_CLASS_NAME__ and __GLFW_X11_INSTANCE_NAME__ specifies the desired __GLFW_X11_CLASS_NAME__ and __GLFW_X11_INSTANCE_NAME__ specifies the desired
ASCII encoded class and instance parts of the ICCCM `WM_CLASS` window property. ASCII encoded class and instance parts of the ICCCM `WM_CLASS` window property. Both
hints need to be set to something other than an empty string for them to take effect.
These are set with @ref glfwWindowHintString. These are set with @ref glfwWindowHintString.
@subsubsection window_hints_wayland Wayland specific window hints
@anchor GLFW_WAYLAND_APP_ID_hint
__GLFW_WAYLAND_APP_ID__ specifies the Wayland app_id for a window, used
by window managers to identify types of windows. This is set with
@ref glfwWindowHintString.
@subsubsection window_hints_values Supported and default values @subsubsection window_hints_values Supported and default values
@ -509,6 +525,8 @@ GLFW_TRANSPARENT_FRAMEBUFFER | `GLFW_FALSE` | `GLFW_TRUE` or `GL
GLFW_FOCUS_ON_SHOW | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_FOCUS_ON_SHOW | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_SCALE_TO_MONITOR | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_SCALE_TO_MONITOR | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_MOUSE_PASSTHROUGH | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_MOUSE_PASSTHROUGH | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_POSITION_X | `GLFW_ANY_POSITION` | Any valid screen x-coordinate or `GLFW_ANY_POSITION`
GLFW_POSITION_Y | `GLFW_ANY_POSITION` | Any valid screen y-coordinate or `GLFW_ANY_POSITION`
GLFW_RED_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE` GLFW_RED_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
GLFW_GREEN_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE` GLFW_GREEN_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
GLFW_BLUE_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE` GLFW_BLUE_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
@ -540,6 +558,7 @@ GLFW_COCOA_FRAME_NAME | `""` | A UTF-8 encoded fr
GLFW_COCOA_GRAPHICS_SWITCHING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_COCOA_GRAPHICS_SWITCHING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_X11_CLASS_NAME | `""` | An ASCII encoded `WM_CLASS` class name GLFW_X11_CLASS_NAME | `""` | An ASCII encoded `WM_CLASS` class name
GLFW_X11_INSTANCE_NAME | `""` | An ASCII encoded `WM_CLASS` instance name GLFW_X11_INSTANCE_NAME | `""` | An ASCII encoded `WM_CLASS` instance name
GLFW_WAYLAND_APP_ID | `""` | An ASCII encoded Wayland `app_id` name
@section window_events Window event processing @section window_events Window event processing
@ -790,7 +809,20 @@ are undefined if they conflict.
@subsection window_pos Window position @subsection window_pos Window position
The position of a windowed-mode window can be changed with @ref By default, the window manager chooses the position of new windowed mode
windows, based on its size and which monitor the user appears to be working on.
This is most often the right choice. If you need to create a window at
a specific position, you can set the desired position with the @ref
GLFW_POSITION_X and @ref GLFW_POSITION_Y window hints.
@code
glfwWindowHint(GLFW_POSITION_X, 70);
glfwWindowHint(GLFW_POSITION_Y, 83);
@endcode
To restore the previous behavior, set these hints to `GLFW_ANY_POSITION`.
The position of a windowed mode window can be changed with @ref
glfwSetWindowPos. This moves the window so that the upper-left corner of its glfwSetWindowPos. This moves the window so that the upper-left corner of its
content area has the specified [screen coordinates](@ref coordinate_systems). content area has the specified [screen coordinates](@ref coordinate_systems).
The window system may put limitations on window placement. The window system may put limitations on window placement.

View File

@ -50,11 +50,6 @@ set_target_properties(${GUI_ONLY_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
C_STANDARD 99 C_STANDARD 99
FOLDER "GLFW3/Examples") FOLDER "GLFW3/Examples")
if (GLFW_USE_OSMESA)
find_package(OSMesa REQUIRED)
target_compile_definitions(offscreen PRIVATE USE_NATIVE_OSMESA)
endif()
if (MSVC) if (MSVC)
# Tell MSVC to use main instead of WinMain # Tell MSVC to use main instead of WinMain
set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES

View File

@ -28,11 +28,6 @@
#define GLFW_INCLUDE_NONE #define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#if USE_NATIVE_OSMESA
#define GLFW_EXPOSE_NATIVE_OSMESA
#include <GLFW/glfw3native.h>
#endif
#include "linmath.h" #include "linmath.h"
#include <stdlib.h> #include <stdlib.h>
@ -151,12 +146,8 @@ int main(void)
glDrawArrays(GL_TRIANGLES, 0, 3); glDrawArrays(GL_TRIANGLES, 0, 3);
glFinish(); glFinish();
#if USE_NATIVE_OSMESA
glfwGetOSMesaColorBuffer(window, &width, &height, NULL, (void**) &buffer);
#else
buffer = calloc(4, width * height); buffer = calloc(4, width * height);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
#endif
// Write image Y-flipped because OpenGL // Write image Y-flipped because OpenGL
stbi_write_png("offscreen.png", stbi_write_png("offscreen.png",
@ -164,11 +155,7 @@ int main(void)
buffer + (width * 4 * (height - 1)), buffer + (width * 4 * (height - 1)),
-width * 4); -width * 4);
#if USE_NATIVE_OSMESA
// Here is where there's nothing
#else
free(buffer); free(buffer);
#endif
glfwDestroyWindow(window); glfwDestroyWindow(window);

View File

@ -31,7 +31,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "getopt.h"
#include "linmath.h" #include "linmath.h"
static const char* vertex_shader_text = static const char* vertex_shader_text =

View File

@ -44,7 +44,6 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &xpos, &ypos, NULL, &height); glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &xpos, &ypos, NULL, &height);
@ -66,6 +65,9 @@ int main(int argc, char** argv)
if (i > 0) if (i > 0)
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE); glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE);
glfwWindowHint(GLFW_POSITION_X, xpos + size * (1 + (i & 1)));
glfwWindowHint(GLFW_POSITION_Y, ypos + size * (1 + (i >> 1)));
windows[i] = glfwCreateWindow(size, size, "Multi-Window Example", NULL, NULL); windows[i] = glfwCreateWindow(size, size, "Multi-Window Example", NULL, NULL);
if (!windows[i]) if (!windows[i])
{ {
@ -75,9 +77,6 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
glfwSetWindowPos(windows[i],
xpos + size * (1 + (i & 1)),
ypos + size * (1 + (i >> 1)));
glfwSetInputMode(windows[i], GLFW_STICKY_KEYS, GLFW_TRUE); glfwSetInputMode(windows[i], GLFW_STICKY_KEYS, GLFW_TRUE);
glfwMakeContextCurrent(windows[i]); glfwMakeContextCurrent(windows[i]);
@ -85,9 +84,6 @@ int main(int argc, char** argv)
glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f); glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f);
} }
for (int i = 0; i < 4; i++)
glfwShowWindow(windows[i]);
for (;;) for (;;)
{ {
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)

View File

@ -262,13 +262,12 @@ extern "C" {
/* We are building GLFW as a Win32 DLL */ /* We are building GLFW as a Win32 DLL */
#define GLFWAPI __declspec(dllexport) #define GLFWAPI __declspec(dllexport)
#elif defined(_WIN32) && defined(GLFW_DLL) #elif defined(_WIN32) && defined(GLFW_DLL)
/* We are calling GLFW as a Win32 DLL */ /* We are calling a GLFW Win32 DLL */
#define GLFWAPI __declspec(dllimport) #define GLFWAPI __declspec(dllimport)
#elif defined(__GNUC__) && defined(_GLFW_BUILD_DLL) #elif defined(__GNUC__) && defined(_GLFW_BUILD_DLL)
/* We are building GLFW as a shared / dynamic library */ /* We are building GLFW as a Unix shared library */
#define GLFWAPI __attribute__((visibility("default"))) #define GLFWAPI __attribute__((visibility("default")))
#else #else
/* We are building or calling GLFW as a static library */
#define GLFWAPI #define GLFWAPI
#endif #endif
@ -362,10 +361,15 @@ extern "C" {
#define GLFW_HAT_RIGHT_DOWN (GLFW_HAT_RIGHT | GLFW_HAT_DOWN) #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_UP (GLFW_HAT_LEFT | GLFW_HAT_UP)
#define GLFW_HAT_LEFT_DOWN (GLFW_HAT_LEFT | GLFW_HAT_DOWN) #define GLFW_HAT_LEFT_DOWN (GLFW_HAT_LEFT | GLFW_HAT_DOWN)
/*! @ingroup input
*/
#define GLFW_KEY_UNKNOWN -1
/*! @} */ /*! @} */
/*! @defgroup keys Keyboard keys /*! @defgroup keys Keyboard key tokens
* @brief Keyboard key IDs. * @brief Keyboard key tokens.
* *
* See [key input](@ref input_key) for how these are used. * See [key input](@ref input_key) for how these are used.
* *
@ -388,9 +392,6 @@ extern "C" {
* @{ * @{
*/ */
/* The unknown key */
#define GLFW_KEY_UNKNOWN -1
/* Printable keys */ /* Printable keys */
#define GLFW_KEY_SPACE 32 #define GLFW_KEY_SPACE 32
#define GLFW_KEY_APOSTROPHE 39 /* ' */ #define GLFW_KEY_APOSTROPHE 39 /* ' */
@ -826,11 +827,11 @@ extern "C" {
#define GLFW_FEATURE_UNIMPLEMENTED 0x0001000D #define GLFW_FEATURE_UNIMPLEMENTED 0x0001000D
/*! @brief Platform unavailable or no matching platform was found. /*! @brief Platform unavailable or no matching platform was found.
* *
* If emitted during initialization, no matching platform was found. If @ref * If emitted during initialization, no matching platform was found. If the @ref
* GLFW_PLATFORM is set to `GLFW_ANY_PLATFORM`, GLFW could not detect any of the * GLFW_PLATFORM init hint was set to `GLFW_ANY_PLATFORM`, GLFW could not detect any of
* platforms supported by this library binary, except for the Null platform. If set to * the platforms supported by this library binary, except for the Null platform. If the
* a specific platform, it is either not supported by this library binary or GLFW was not * init hint was set to a specific platform, it is either not supported by this library
* able to detect it. * binary or GLFW was not able to detect it.
* *
* If emitted by a native access function, GLFW was initialized for a different platform * If emitted by a native access function, GLFW was initialized for a different platform
* than the function is for. * than the function is for.
@ -936,6 +937,18 @@ extern "C" {
*/ */
#define GLFW_MOUSE_PASSTHROUGH 0x0002000D #define GLFW_MOUSE_PASSTHROUGH 0x0002000D
/*! @brief Initial position x-coordinate window hint.
*
* Initial position x-coordinate [window hint](@ref GLFW_POSITION_X).
*/
#define GLFW_POSITION_X 0x0002000E
/*! @brief Initial position y-coordinate window hint.
*
* Initial position y-coordinate [window hint](@ref GLFW_POSITION_Y).
*/
#define GLFW_POSITION_Y 0x0002000F
/*! @brief Framebuffer bit depth hint. /*! @brief Framebuffer bit depth hint.
* *
* Framebuffer bit depth [hint](@ref GLFW_RED_BITS). * Framebuffer bit depth [hint](@ref GLFW_RED_BITS).
@ -1114,6 +1127,12 @@ extern "C" {
*/ */
#define GLFW_X11_INSTANCE_NAME 0x00024002 #define GLFW_X11_INSTANCE_NAME 0x00024002
#define GLFW_WIN32_KEYBOARD_MENU 0x00025001 #define GLFW_WIN32_KEYBOARD_MENU 0x00025001
/*! @brief Wayland specific
* [window hint](@ref GLFW_WAYLAND_APP_ID_hint).
*
* Allows specification of the Wayland app_id.
*/
#define GLFW_WAYLAND_APP_ID 0x00026001
/*! @} */ /*! @} */
#define GLFW_NO_API 0 #define GLFW_NO_API 0
@ -1137,6 +1156,7 @@ extern "C" {
#define GLFW_CURSOR_NORMAL 0x00034001 #define GLFW_CURSOR_NORMAL 0x00034001
#define GLFW_CURSOR_HIDDEN 0x00034002 #define GLFW_CURSOR_HIDDEN 0x00034002
#define GLFW_CURSOR_DISABLED 0x00034003 #define GLFW_CURSOR_DISABLED 0x00034003
#define GLFW_CURSOR_CAPTURED 0x00034004
#define GLFW_ANY_RELEASE_BEHAVIOR 0 #define GLFW_ANY_RELEASE_BEHAVIOR 0
#define GLFW_RELEASE_BEHAVIOR_FLUSH 0x00035001 #define GLFW_RELEASE_BEHAVIOR_FLUSH 0x00035001
@ -1154,6 +1174,11 @@ extern "C" {
#define GLFW_ANGLE_PLATFORM_TYPE_VULKAN 0x00037007 #define GLFW_ANGLE_PLATFORM_TYPE_VULKAN 0x00037007
#define GLFW_ANGLE_PLATFORM_TYPE_METAL 0x00037008 #define GLFW_ANGLE_PLATFORM_TYPE_METAL 0x00037008
#define GLFW_WAYLAND_PREFER_LIBDECOR 0x00038001
#define GLFW_WAYLAND_DISABLE_LIBDECOR 0x00038002
#define GLFW_ANY_POSITION 0x80000000
/*! @defgroup shapes Standard cursor shapes /*! @defgroup shapes Standard cursor shapes
* @brief Standard system cursor shapes. * @brief Standard system cursor shapes.
* *
@ -1295,6 +1320,11 @@ extern "C" {
* X11 specific [init hint](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint). * X11 specific [init hint](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint).
*/ */
#define GLFW_X11_XCB_VULKAN_SURFACE 0x00052001 #define GLFW_X11_XCB_VULKAN_SURFACE 0x00052001
/*! @brief Wayland specific init hint.
*
* Wayland specific [init hint](@ref GLFW_WAYLAND_LIBDECOR_hint).
*/
#define GLFW_WAYLAND_LIBDECOR 0x00053001
/*! @} */ /*! @} */
/*! @addtogroup init /*! @addtogroup init
@ -2844,11 +2874,11 @@ GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor);
* @param[in] monitor The monitor whose gamma ramp to set. * @param[in] monitor The monitor whose gamma ramp to set.
* @param[in] gamma The desired exponent. * @param[in] gamma The desired exponent.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref GLFW_INVALID_VALUE,
* GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. * @ref GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks).
* *
* @remark @wayland Gamma handling is a privileged protocol, this function * @remark @wayland Gamma handling is a privileged protocol, this function
* will thus never be implemented and emits @ref GLFW_PLATFORM_ERROR. * will thus never be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE.
* *
* @thread_safety This function must only be called from the main thread. * @thread_safety This function must only be called from the main thread.
* *
@ -2868,11 +2898,11 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* monitor, float gamma);
* @return The current gamma ramp, or `NULL` if an * @return The current gamma ramp, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref GLFW_PLATFORM_ERROR
* GLFW_PLATFORM_ERROR. * and @ref GLFW_FEATURE_UNAVAILABLE (see remarks).
* *
* @remark @wayland Gamma handling is a privileged protocol, this function * @remark @wayland Gamma handling is a privileged protocol, this function
* will thus never be implemented and emits @ref GLFW_PLATFORM_ERROR while * will thus never be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE while
* returning `NULL`. * returning `NULL`.
* *
* @pointer_lifetime The returned structure and its arrays are allocated and * @pointer_lifetime The returned structure and its arrays are allocated and
@ -2907,8 +2937,8 @@ GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor);
* @param[in] monitor The monitor whose gamma ramp to set. * @param[in] monitor The monitor whose gamma ramp to set.
* @param[in] ramp The gamma ramp to use. * @param[in] ramp The gamma ramp to use.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref GLFW_PLATFORM_ERROR
* GLFW_PLATFORM_ERROR. * and @ref GLFW_FEATURE_UNAVAILABLE (see remarks).
* *
* @remark The size of the specified gamma ramp should match the size of the * @remark The size of the specified gamma ramp should match the size of the
* current ramp for that monitor. * current ramp for that monitor.
@ -2916,7 +2946,7 @@ GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor);
* @remark @win32 The gamma ramp size must be 256. * @remark @win32 The gamma ramp size must be 256.
* *
* @remark @wayland Gamma handling is a privileged protocol, this function * @remark @wayland Gamma handling is a privileged protocol, this function
* will thus never be implemented and emits @ref GLFW_PLATFORM_ERROR. * will thus never be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE.
* *
* @pointer_lifetime The specified gamma ramp is copied before this function * @pointer_lifetime The specified gamma ramp is copied before this function
* returns. * returns.
@ -3059,10 +3089,10 @@ GLFWAPI void glfwWindowHintString(int hint, const char* value);
* OpenGL or OpenGL ES context. * OpenGL or OpenGL ES context.
* *
* By default, newly created windows use the placement recommended by the * By default, newly created windows use the placement recommended by the
* window system. To create the window at a specific position, make it * window system. To create the window at a specific position, set the @ref
* initially invisible using the [GLFW_VISIBLE](@ref GLFW_VISIBLE_hint) window * GLFW_POSITION_X and @ref GLFW_POSITION_Y window hints before creation. To
* hint, set its [position](@ref window_pos) and then [show](@ref window_hide) * restore the default behavior, set either or both hints back to
* it. * `GLFW_ANY_POSITION`.
* *
* As long as at least one full screen window is not iconified, the screensaver * As long as at least one full screen window is not iconified, the screensaver
* is prohibited from starting. * is prohibited from starting.
@ -3088,8 +3118,8 @@ GLFWAPI void glfwWindowHintString(int hint, const char* value);
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_INVALID_ENUM, @ref GLFW_INVALID_VALUE, @ref GLFW_API_UNAVAILABLE, @ref * GLFW_INVALID_ENUM, @ref GLFW_INVALID_VALUE, @ref GLFW_API_UNAVAILABLE, @ref
* GLFW_VERSION_UNAVAILABLE, @ref GLFW_FORMAT_UNAVAILABLE and @ref * GLFW_VERSION_UNAVAILABLE, @ref GLFW_FORMAT_UNAVAILABLE, @ref
* GLFW_PLATFORM_ERROR. * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_ERROR.
* *
* @remark @win32 Window creation will fail if the Microsoft GDI software * @remark @win32 Window creation will fail if the Microsoft GDI software
* OpenGL implementation is the only one available. * OpenGL implementation is the only one available.
@ -3287,7 +3317,8 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow* window, const char* title);
* count is zero. * count is zero.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * GLFW_INVALID_VALUE, @ref GLFW_PLATFORM_ERROR and @ref
* GLFW_FEATURE_UNAVAILABLE (see remarks).
* *
* @pointer_lifetime The specified image data is copied before this function * @pointer_lifetime The specified image data is copied before this function
* returns. * returns.
@ -3700,8 +3731,9 @@ GLFWAPI void glfwSetWindowOpacity(GLFWwindow* window, float opacity);
* previously restored. If the window is already iconified, this function does * previously restored. If the window is already iconified, this function does
* nothing. * nothing.
* *
* If the specified window is a full screen window, the original monitor * If the specified window is a full screen window, GLFW restores the original
* resolution is restored until the window is restored. * video mode of the monitor. The window's desired video mode is set again
* when the window is restored.
* *
* @param[in] window The window to iconify. * @param[in] window The window to iconify.
* *
@ -3731,8 +3763,8 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow* window);
* (minimized) or maximized. If the window is already restored, this function * (minimized) or maximized. If the window is already restored, this function
* does nothing. * does nothing.
* *
* If the specified window is a full screen window, the resolution chosen for * If the specified window is an iconified full screen window, its desired
* the window is restored on the selected monitor. * video mode is set again for its monitor when the window is restored.
* *
* @param[in] window The window to restore. * @param[in] window The window to restore.
* *
@ -4000,6 +4032,9 @@ GLFWAPI void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int
* errors. However, this function should not fail as long as it is passed * errors. However, this function should not fail as long as it is passed
* valid arguments and the library has been [initialized](@ref intro_init). * valid arguments and the library has been [initialized](@ref intro_init).
* *
* @remark @wayland The Wayland protocol provides no way to check whether a
* window is iconfied, so @ref GLFW_ICONIFIED always returns `GLFW_FALSE`.
*
* @thread_safety This function must only be called from the main thread. * @thread_safety This function must only be called from the main thread.
* *
* @sa @ref window_attribs * @sa @ref window_attribs
@ -4034,7 +4069,8 @@ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* window, int attrib);
* @param[in] value `GLFW_TRUE` or `GLFW_FALSE`. * @param[in] value `GLFW_TRUE` or `GLFW_FALSE`.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_INVALID_ENUM, @ref GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. * GLFW_INVALID_ENUM, @ref GLFW_INVALID_VALUE, @ref GLFW_PLATFORM_ERROR and @ref
* GLFW_FEATURE_UNAVAILABLE.
* *
* @remark Calling @ref glfwGetWindowAttrib will always return the latest * @remark Calling @ref glfwGetWindowAttrib will always return the latest
* value, even if that value is ignored by the current mode of the window. * value, even if that value is ignored by the current mode of the window.
@ -4616,6 +4652,8 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode);
* - `GLFW_CURSOR_DISABLED` hides and grabs the cursor, providing virtual * - `GLFW_CURSOR_DISABLED` hides and grabs the cursor, providing virtual
* and unlimited cursor movement. This is useful for implementing for * and unlimited cursor movement. This is useful for implementing for
* example 3D camera controls. * example 3D camera controls.
* - `GLFW_CURSOR_CAPTURED` makes the cursor visible and confines it to the
* content area of the window.
* *
* If the mode is `GLFW_STICKY_KEYS`, the value must be either `GLFW_TRUE` to * If the mode is `GLFW_STICKY_KEYS`, the value must be either `GLFW_TRUE` to
* enable sticky keys, or `GLFW_FALSE` to disable it. If sticky keys are * enable sticky keys, or `GLFW_FALSE` to disable it. If sticky keys are
@ -4742,8 +4780,8 @@ GLFWAPI int glfwRawMouseMotionSupported(void);
* @param[in] scancode The scancode of the key to query. * @param[in] scancode The scancode of the key to query.
* @return The UTF-8 encoded, layout-specific 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 * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_PLATFORM_ERROR. * GLFW_INVALID_VALUE, @ref GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR.
* *
* @remark The contents of the returned string may change when a keyboard * @remark The contents of the returned string may change when a keyboard
* layout change event is received. * layout change event is received.
@ -4765,15 +4803,18 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode);
* *
* This function 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 * If the specified [key token](@ref keys) corresponds to a physical key not
* method will return `-1`. * supported on the current platform then this method will return `-1`.
* Calling this function with anything other than a key token will return `-1`
* and generate a @ref GLFW_INVALID_ENUM error.
* *
* @param[in] key Any [named key](@ref keys). * @param[in] key Any [key token](@ref keys).
* @return The platform-specific scancode for the key, or `-1` if an * @return The platform-specific scancode for the key, or `-1` if the key is
* [error](@ref error_handling) occurred. * not supported on the current platform or an [error](@ref error_handling)
* occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. * GLFW_INVALID_ENUM.
* *
* @thread_safety This function may be called from any thread. * @thread_safety This function may be called from any thread.
* *
@ -4790,8 +4831,7 @@ GLFWAPI int glfwGetKeyScancode(int key);
* *
* This function returns the last state reported for the specified key to the * This function returns the last state reported for the specified key to the
* specified window. The returned state is one of `GLFW_PRESS` or * specified window. The returned state is one of `GLFW_PRESS` or
* `GLFW_RELEASE`. The higher-level action `GLFW_REPEAT` is only reported to * `GLFW_RELEASE`. The action `GLFW_REPEAT` is only reported to the key callback.
* the key callback.
* *
* If the @ref 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 * `GLFW_PRESS` the first time you call it for a key that was pressed, even if
@ -4915,11 +4955,11 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos);
* @param[in] ypos The desired y-coordinate, relative to the top edge of the * @param[in] ypos The desired y-coordinate, relative to the top edge of the
* content area. * content area.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_PLATFORM_ERROR. * GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks).
* *
* @remark @wayland This function will only work when the cursor mode is * @remark @wayland This function will only work when the cursor mode is
* `GLFW_CURSOR_DISABLED`, otherwise it will do nothing. * `GLFW_CURSOR_DISABLED`, otherwise it will emit @ref GLFW_FEATURE_UNAVAILABLE.
* *
* @thread_safety This function must only be called from the main thread. * @thread_safety This function must only be called from the main thread.
* *
@ -4952,8 +4992,8 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos);
* @return The handle of the created cursor, or `NULL` if an * @return The handle of the created cursor, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_PLATFORM_ERROR. * GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR.
* *
* @pointer_lifetime The specified image data is copied before this function * @pointer_lifetime The specified image data is copied before this function
* returns. * returns.
@ -5083,9 +5123,9 @@ GLFWAPI void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor);
* [character callback](@ref glfwSetCharCallback) instead. * [character callback](@ref glfwSetCharCallback) instead.
* *
* When a window loses input focus, it will generate synthetic key release * When a window loses input focus, it will generate synthetic key release
* events for all pressed keys. You can tell these events from user-generated * events for all pressed keys with associated key tokens. You can tell these
* events by the fact that the synthetic ones are generated after the focus * events from user-generated events by the fact that the synthetic ones are
* loss event has been processed, i.e. after the * generated after the focus loss event has been processed, i.e. after the
* [window focus callback](@ref glfwSetWindowFocusCallback) has been called. * [window focus callback](@ref glfwSetWindowFocusCallback) has been called.
* *
* The scancode of a key is specific to that platform or sometimes even to that * The scancode of a key is specific to that platform or sometimes even to that
@ -5834,6 +5874,11 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state);
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR. * GLFW_PLATFORM_ERROR.
* *
* @remark @win32 The clipboard on Windows has a single global lock for reading and
* writing. GLFW tries to acquire it a few times, which is almost always enough. If it
* cannot acquire the lock then this function emits @ref GLFW_PLATFORM_ERROR and returns.
* It is safe to try this multiple times.
*
* @pointer_lifetime The specified string is copied before this function * @pointer_lifetime The specified string is copied before this function
* returns. * returns.
* *
@ -5862,6 +5907,11 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string);
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_FORMAT_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR. * GLFW_FORMAT_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR.
* *
* @remark @win32 The clipboard on Windows has a single global lock for reading and
* writing. GLFW tries to acquire it a few times, which is almost always enough. If it
* cannot acquire the lock then this function emits @ref GLFW_PLATFORM_ERROR and returns.
* It is safe to try this multiple times.
*
* @pointer_lifetime The returned string is allocated and freed by GLFW. You * @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 * should not free it yourself. It is valid until the next call to @ref
* glfwGetClipboardString or @ref glfwSetClipboardString, or until the library * glfwGetClipboardString or @ref glfwSetClipboardString, or until the library
@ -5984,12 +6034,15 @@ GLFWAPI uint64_t glfwGetTimerFrequency(void);
* thread. * thread.
* *
* This function makes the OpenGL or OpenGL ES context of the specified window * This function makes the OpenGL or OpenGL ES context of the specified window
* current on the calling thread. A context must only be made current on * current on the calling thread. It can also detach the current context from
* a single thread at a time and each thread can have only a single current * the calling thread without making a new one current by passing in `NULL`.
* context at a time.
* *
* When moving a context between threads, you must make it non-current on the * A context must only be made current on a single thread at a time and each
* old thread before making it current on the new one. * thread can have only a single current context at a time. Making a context
* current detaches any previously current context on the calling thread.
*
* When moving a context between threads, you must detach it (make it
* non-current) on the old thread before making it current on the new one.
* *
* By default, making a context non-current implicitly forces a pipeline flush. * By default, making a context non-current implicitly forces a pipeline flush.
* On machines that support `GL_KHR_context_flush_control`, you can control * On machines that support `GL_KHR_context_flush_control`, you can control
@ -6004,6 +6057,10 @@ GLFWAPI uint64_t glfwGetTimerFrequency(void);
* @param[in] window The window whose context to make current, or `NULL` to * @param[in] window The window whose context to make current, or `NULL` to
* detach the current context. * detach the current context.
* *
* @remarks If the previously current context was created via a different
* context creation API than the one passed to this function, GLFW will still
* detach the previous one from its API before making the new one current.
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_ERROR. * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_ERROR.
* *
@ -6443,6 +6500,7 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window
*/ */
#ifndef GLAPIENTRY #ifndef GLAPIENTRY
#define GLAPIENTRY APIENTRY #define GLAPIENTRY APIENTRY
#define GLFW_GLAPIENTRY_DEFINED
#endif #endif
/* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */ /* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */

View File

@ -74,6 +74,16 @@ extern "C" {
* and which platform-specific headers to include. It is then up your (by * and which platform-specific headers to include. It is then up your (by
* definition platform-specific) code to handle which of these should be * definition platform-specific) code to handle which of these should be
* defined. * defined.
*
* If you do not want the platform-specific headers to be included, define
* `GLFW_NATIVE_INCLUDE_NONE` before including the @ref glfw3native.h header.
*
* @code
* #define GLFW_EXPOSE_NATIVE_WIN32
* #define GLFW_EXPOSE_NATIVE_WGL
* #define GLFW_NATIVE_INCLUDE_NONE
* #include <GLFW/glfw3native.h>
* @endcode
*/ */
@ -81,44 +91,71 @@ extern "C" {
* System headers and types * System headers and types
*************************************************************************/ *************************************************************************/
#if defined(GLFW_EXPOSE_NATIVE_WIN32) || defined(GLFW_EXPOSE_NATIVE_WGL) #if !defined(GLFW_NATIVE_INCLUDE_NONE)
// This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
// example to allow applications to correctly declare a GL_KHR_debug callback) #if defined(GLFW_EXPOSE_NATIVE_WIN32) || defined(GLFW_EXPOSE_NATIVE_WGL)
// but windows.h assumes no one will define APIENTRY before it does /* This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
* example to allow applications to correctly declare a GL_KHR_debug callback)
* but windows.h assumes no one will define APIENTRY before it does
*/
#if defined(GLFW_APIENTRY_DEFINED) #if defined(GLFW_APIENTRY_DEFINED)
#undef APIENTRY #undef APIENTRY
#undef GLFW_APIENTRY_DEFINED #undef GLFW_APIENTRY_DEFINED
#endif #endif
#include <windows.h> #include <windows.h>
#elif defined(GLFW_EXPOSE_NATIVE_COCOA) || defined(GLFW_EXPOSE_NATIVE_NSGL) #endif
#if defined(GLFW_EXPOSE_NATIVE_COCOA) || defined(GLFW_EXPOSE_NATIVE_NSGL)
#if defined(__OBJC__) #if defined(__OBJC__)
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#else #else
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
typedef void* id; #include <objc/objc.h>
#endif #endif
#elif defined(GLFW_EXPOSE_NATIVE_X11) || defined(GLFW_EXPOSE_NATIVE_GLX) #endif
#if defined(GLFW_EXPOSE_NATIVE_X11) || defined(GLFW_EXPOSE_NATIVE_GLX)
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#elif defined(GLFW_EXPOSE_NATIVE_WAYLAND) #endif
#include <wayland-client.h>
#endif
#if defined(GLFW_EXPOSE_NATIVE_WGL) #if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
#include <wayland-client.h>
#endif
#if defined(GLFW_EXPOSE_NATIVE_WGL)
/* WGL is declared by windows.h */ /* WGL is declared by windows.h */
#endif #endif
#if defined(GLFW_EXPOSE_NATIVE_NSGL) #if defined(GLFW_EXPOSE_NATIVE_NSGL)
/* NSGL is declared by Cocoa.h */ /* NSGL is declared by Cocoa.h */
#endif #endif
#if defined(GLFW_EXPOSE_NATIVE_GLX) #if defined(GLFW_EXPOSE_NATIVE_GLX)
/* This is a workaround for the fact that glfw3.h defines GLAPIENTRY because by
* default it also acts as an OpenGL header
* However, glx.h will include gl.h, which will define it unconditionally
*/
#if defined(GLFW_GLAPIENTRY_DEFINED)
#undef GLAPIENTRY
#undef GLFW_GLAPIENTRY_DEFINED
#endif
#include <GL/glx.h> #include <GL/glx.h>
#endif #endif
#if defined(GLFW_EXPOSE_NATIVE_EGL) #if defined(GLFW_EXPOSE_NATIVE_EGL)
#include <EGL/egl.h> #include <EGL/egl.h>
#endif #endif
#if defined(GLFW_EXPOSE_NATIVE_OSMESA) #if defined(GLFW_EXPOSE_NATIVE_OSMESA)
/* This is a workaround for the fact that glfw3.h defines GLAPIENTRY because by
* default it also acts as an OpenGL header
* However, osmesa.h will include gl.h, which will define it unconditionally
*/
#if defined(GLFW_GLAPIENTRY_DEFINED)
#undef GLAPIENTRY
#undef GLFW_GLAPIENTRY_DEFINED
#endif
#include <GL/osmesa.h> #include <GL/osmesa.h>
#endif #endif
#endif /*GLFW_NATIVE_INCLUDE_NONE*/
/************************************************************************* /*************************************************************************
@ -132,7 +169,8 @@ extern "C" {
* of the specified monitor, or `NULL` if an [error](@ref error_handling) * of the specified monitor, or `NULL` if an [error](@ref error_handling)
* occurred. * occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -149,7 +187,8 @@ GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor);
* `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -165,7 +204,8 @@ GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor);
* @return The `HWND` of the specified window, or `NULL` if an * @return The `HWND` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @remark The `HDC` associated with the window can be queried with the * @remark The `HDC` associated with the window can be queried with the
* [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc) * [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc)
@ -191,8 +231,8 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window);
* @return The `HGLRC` of the specified window, or `NULL` if an * @return The `HGLRC` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_NOT_INITIALIZED. * GLFW_PLATFORM_UNAVAILABLE and @ref GLFW_NO_WINDOW_CONTEXT.
* *
* @remark The `HDC` associated with the window can be queried with the * @remark The `HDC` associated with the window can be queried with the
* [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc) * [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc)
@ -218,7 +258,8 @@ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window);
* @return The `CGDirectDisplayID` of the specified monitor, or * @return The `CGDirectDisplayID` of the specified monitor, or
* `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred. * `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -234,7 +275,8 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
* @return The `NSWindow` of the specified window, or `nil` if an * @return The `NSWindow` of the specified window, or `nil` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -252,8 +294,8 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
* @return The `NSOpenGLContext` of the specified window, or `nil` if an * @return The `NSOpenGLContext` of the specified window, or `nil` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_NOT_INITIALIZED. * GLFW_PLATFORM_UNAVAILABLE and @ref GLFW_NO_WINDOW_CONTEXT.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -271,7 +313,8 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* window);
* @return The `Display` used by GLFW, or `NULL` if an * @return The `Display` used by GLFW, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -287,7 +330,8 @@ GLFWAPI Display* glfwGetX11Display(void);
* @return The `RRCrtc` of the specified monitor, or `None` if an * @return The `RRCrtc` of the specified monitor, or `None` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -303,7 +347,8 @@ GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor);
* @return The `RROutput` of the specified monitor, or `None` if an * @return The `RROutput` of the specified monitor, or `None` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -319,7 +364,8 @@ GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor);
* @return The `Window` of the specified window, or `None` if an * @return The `Window` of the specified window, or `None` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -334,8 +380,8 @@ GLFWAPI Window glfwGetX11Window(GLFWwindow* window);
* *
* @param[in] string A UTF-8 encoded string. * @param[in] string A UTF-8 encoded string.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_PLATFORM_ERROR. * GLFW_PLATFORM_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR.
* *
* @pointer_lifetime The specified string is copied before this function * @pointer_lifetime The specified string is copied before this function
* returns. * returns.
@ -360,8 +406,8 @@ GLFWAPI void glfwSetX11SelectionString(const char* string);
* @return The contents of the selection as a UTF-8 encoded string, or `NULL` * @return The contents of the selection as a UTF-8 encoded string, or `NULL`
* if an [error](@ref error_handling) occurred. * if an [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_PLATFORM_ERROR. * GLFW_PLATFORM_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR.
* *
* @pointer_lifetime The returned string is allocated and freed by GLFW. You * @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 * should not free it yourself. It is valid until the next call to @ref
@ -387,8 +433,8 @@ GLFWAPI const char* glfwGetX11SelectionString(void);
* @return The `GLXContext` of the specified window, or `NULL` if an * @return The `GLXContext` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_NOT_INITIALIZED. * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -404,8 +450,8 @@ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window);
* @return The `GLXWindow` of the specified window, or `None` if an * @return The `GLXWindow` of the specified window, or `None` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_NOT_INITIALIZED. * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -423,7 +469,8 @@ GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window);
* @return The `struct wl_display*` used by GLFW, or `NULL` if an * @return The `struct wl_display*` used by GLFW, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -439,7 +486,8 @@ GLFWAPI struct wl_display* glfwGetWaylandDisplay(void);
* @return The `struct wl_output*` of the specified monitor, or `NULL` if an * @return The `struct wl_output*` of the specified monitor, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -455,7 +503,8 @@ GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor);
* @return The main `struct wl_surface*` of the specified window, or `NULL` if * @return The main `struct wl_surface*` of the specified window, or `NULL` if
* an [error](@ref error_handling) occurred. * an [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -475,6 +524,9 @@ GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window);
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
* *
* @remark Because EGL is initialized on demand, this function will return
* `EGL_NO_DISPLAY` until the first context has been created via EGL.
*
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
* *
@ -489,8 +541,8 @@ GLFWAPI EGLDisplay glfwGetEGLDisplay(void);
* @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an * @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_NOT_INITIALIZED. * GLFW_NO_WINDOW_CONTEXT.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -506,8 +558,8 @@ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window);
* @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an * @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_NOT_INITIALIZED. * GLFW_NO_WINDOW_CONTEXT.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -532,8 +584,8 @@ GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window);
* @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_NOT_INITIALIZED. * GLFW_NO_WINDOW_CONTEXT.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -556,8 +608,8 @@ GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* window, int* width, int* height
* @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_NOT_INITIALIZED. * GLFW_NO_WINDOW_CONTEXT.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.
@ -573,8 +625,8 @@ GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height
* @return The `OSMesaContext` of the specified window, or `NULL` if an * @return The `OSMesaContext` of the specified window, or `NULL` if an
* [error](@ref error_handling) occurred. * [error](@ref error_handling) occurred.
* *
* @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_NOT_INITIALIZED. * GLFW_NO_WINDOW_CONTEXT.
* *
* @thread_safety This function may be called from any thread. Access is not * @thread_safety This function may be called from any thread. Access is not
* synchronized. * synchronized.

View File

@ -60,6 +60,7 @@ if (GLFW_BUILD_X11 OR GLFW_BUILD_WAYLAND)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux") if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_sources(glfw PRIVATE linux_joystick.h linux_joystick.c) target_sources(glfw PRIVATE linux_joystick.h linux_joystick.c)
endif() endif()
target_sources(glfw PRIVATE posix_poll.h posix_poll.c)
endif() endif()
if (GLFW_BUILD_WAYLAND) if (GLFW_BUILD_WAYLAND)
@ -71,47 +72,36 @@ if (GLFW_BUILD_WAYLAND)
endif() endif()
find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner) find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner)
if (NOT WAYLAND_SCANNER_EXECUTABLE)
message(FATAL_ERROR "Failed to find wayland-scanner")
endif()
include(FindPkgConfig) macro(generate_wayland_protocol protocol_file)
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols>=1.15) set(protocol_path "${GLFW_SOURCE_DIR}/deps/wayland/${protocol_file}")
pkg_get_variable(WAYLAND_PROTOCOLS_BASE wayland-protocols pkgdatadir)
pkg_get_variable(WAYLAND_CLIENT_PKGDATADIR wayland-client pkgdatadir)
macro(wayland_generate protocol_file output_file) string(REGEX REPLACE "\\.xml$" "-client-protocol.h" header_file ${protocol_file})
add_custom_command(OUTPUT "${output_file}.h" string(REGEX REPLACE "\\.xml$" "-client-protocol-code.h" code_file ${protocol_file})
COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" client-header "${protocol_file}" "${output_file}.h"
DEPENDS "${protocol_file}" add_custom_command(OUTPUT ${header_file}
COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" client-header "${protocol_path}" ${header_file}
DEPENDS "${protocol_path}"
VERBATIM) VERBATIM)
add_custom_command(OUTPUT "${output_file}-code.h" add_custom_command(OUTPUT ${code_file}
COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" private-code "${protocol_file}" "${output_file}-code.h" COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" private-code "${protocol_path}" ${code_file}
DEPENDS "${protocol_file}" DEPENDS "${protocol_path}"
VERBATIM) VERBATIM)
target_sources(glfw PRIVATE "${output_file}.h" "${output_file}-code.h") target_sources(glfw PRIVATE ${header_file} ${code_file})
endmacro() endmacro()
wayland_generate( generate_wayland_protocol("wayland.xml")
"${WAYLAND_CLIENT_PKGDATADIR}/wayland.xml" generate_wayland_protocol("viewporter.xml")
"${GLFW_BINARY_DIR}/src/wayland-client-protocol") generate_wayland_protocol("xdg-shell.xml")
wayland_generate( generate_wayland_protocol("idle-inhibit-unstable-v1.xml")
"${WAYLAND_PROTOCOLS_BASE}/stable/xdg-shell/xdg-shell.xml" generate_wayland_protocol("pointer-constraints-unstable-v1.xml")
"${GLFW_BINARY_DIR}/src/wayland-xdg-shell-client-protocol") generate_wayland_protocol("relative-pointer-unstable-v1.xml")
wayland_generate( generate_wayland_protocol("xdg-decoration-unstable-v1.xml")
"${WAYLAND_PROTOCOLS_BASE}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"
"${GLFW_BINARY_DIR}/src/wayland-xdg-decoration-client-protocol")
wayland_generate(
"${WAYLAND_PROTOCOLS_BASE}/stable/viewporter/viewporter.xml"
"${GLFW_BINARY_DIR}/src/wayland-viewporter-client-protocol")
wayland_generate(
"${WAYLAND_PROTOCOLS_BASE}/unstable/relative-pointer/relative-pointer-unstable-v1.xml"
"${GLFW_BINARY_DIR}/src/wayland-relative-pointer-unstable-v1-client-protocol")
wayland_generate(
"${WAYLAND_PROTOCOLS_BASE}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml"
"${GLFW_BINARY_DIR}/src/wayland-pointer-constraints-unstable-v1-client-protocol")
wayland_generate(
"${WAYLAND_PROTOCOLS_BASE}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml"
"${GLFW_BINARY_DIR}/src/wayland-idle-inhibit-unstable-v1-client-protocol")
endif() endif()
if (WIN32 AND GLFW_BUILD_SHARED_LIBRARY) if (WIN32 AND GLFW_BUILD_SHARED_LIBRARY)
@ -125,6 +115,7 @@ if (UNIX AND GLFW_BUILD_SHARED_LIBRARY)
else() else()
set(GLFW_LIB_NAME glfw3) set(GLFW_LIB_NAME glfw3)
endif() endif()
set(GLFW_LIB_NAME_SUFFIX "")
set_target_properties(glfw PROPERTIES set_target_properties(glfw PROPERTIES
OUTPUT_NAME ${GLFW_LIB_NAME} OUTPUT_NAME ${GLFW_LIB_NAME}
@ -165,6 +156,8 @@ if (GLFW_BUILD_COCOA)
endif() endif()
if (GLFW_BUILD_WAYLAND) if (GLFW_BUILD_WAYLAND)
include(FindPkgConfig)
pkg_check_modules(Wayland REQUIRED pkg_check_modules(Wayland REQUIRED
wayland-client>=0.2.7 wayland-client>=0.2.7
wayland-cursor>=0.2.7 wayland-cursor>=0.2.7
@ -244,17 +237,6 @@ if (UNIX AND NOT APPLE)
endif() endif()
endif() endif()
# Make GCC warn about declarations that VS 2010 and 2012 won't accept for all
# source files that VS will build (Clang ignores this because we set -std=c99)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set_source_files_properties(context.c init.c input.c monitor.c platform.c vulkan.c
window.c null_init.c null_joystick.c null_monitor.c
null_window.c win32_init.c win32_joystick.c win32_module.c
win32_monitor.c win32_time.c win32_thread.c win32_window.c
wgl_context.c egl_context.c osmesa_context.c PROPERTIES
COMPILE_FLAGS -Wdeclaration-after-statement)
endif()
if (WIN32) if (WIN32)
if (GLFW_USE_HYBRID_HPG) if (GLFW_USE_HYBRID_HPG)
target_compile_definitions(glfw PRIVATE _GLFW_USE_HYBRID_HPG) target_compile_definitions(glfw PRIVATE _GLFW_USE_HYBRID_HPG)
@ -299,25 +281,9 @@ if (MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC")
target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS) target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS)
endif() endif()
# Workaround for VS 2008 not shipping with stdint.h
if (MSVC90)
target_include_directories(glfw PUBLIC "${GLFW_SOURCE_DIR}/deps/vs2008")
endif()
# Check for the DirectX 9 SDK as it is not included with VS 2008
if (MSVC90)
include(CheckIncludeFile)
check_include_file(dinput.h DINPUT_H_FOUND)
if (NOT DINPUT_H_FOUND)
message(FATAL_ERROR "DirectX 9 headers not found; install DirectX 9 SDK")
endif()
endif()
# Workaround for -std=c99 on Linux disabling _DEFAULT_SOURCE (POSIX 2008 and more) # Workaround for -std=c99 on Linux disabling _DEFAULT_SOURCE (POSIX 2008 and more)
if (GLFW_BUILD_X11 OR GLFW_BUILD_WAYLAND) if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_compile_definitions(glfw PRIVATE _DEFAULT_SOURCE) target_compile_definitions(glfw PRIVATE _DEFAULT_SOURCE)
endif()
endif() endif()
if (GLFW_BUILD_SHARED_LIBRARY) if (GLFW_BUILD_SHARED_LIBRARY)
@ -336,6 +302,7 @@ if (GLFW_BUILD_SHARED_LIBRARY)
# Add a suffix to the import library to avoid naming conflicts # Add a suffix to the import library to avoid naming conflicts
set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib")
endif() endif()
set (GLFW_LIB_NAME_SUFFIX "dll")
target_compile_definitions(glfw INTERFACE GLFW_DLL) target_compile_definitions(glfw INTERFACE GLFW_DLL)
endif() endif()

View File

@ -27,6 +27,9 @@
//======================================================================== //========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_COCOA)
#include <sys/param.h> // For MAXPATHLEN #include <sys/param.h> // For MAXPATHLEN
// Needed for _NSGetProgname // Needed for _NSGetProgname
@ -460,18 +463,26 @@ void* _glfwLoadLocalVulkanLoaderCocoa(void)
if (!bundle) if (!bundle)
return NULL; return NULL;
CFURLRef url = CFURLRef frameworksUrl = CFBundleCopyPrivateFrameworksURL(bundle);
CFBundleCopyAuxiliaryExecutableURL(bundle, CFSTR("libvulkan.1.dylib")); if (!frameworksUrl)
if (!url)
return NULL; return NULL;
CFURLRef loaderUrl = CFURLCreateCopyAppendingPathComponent(
kCFAllocatorDefault, frameworksUrl, CFSTR("libvulkan.1.dylib"), false);
if (!loaderUrl)
{
CFRelease(frameworksUrl);
return NULL;
}
char path[PATH_MAX]; char path[PATH_MAX];
void* handle = NULL; void* handle = NULL;
if (CFURLGetFileSystemRepresentation(url, true, (UInt8*) path, sizeof(path) - 1)) if (CFURLGetFileSystemRepresentation(loaderUrl, true, (UInt8*) path, sizeof(path) - 1))
handle = _glfwPlatformLoadModule(path); handle = _glfwPlatformLoadModule(path);
CFRelease(url); CFRelease(loaderUrl);
CFRelease(frameworksUrl);
return handle; return handle;
} }
@ -680,7 +691,11 @@ void _glfwTerminateCocoa(void)
_glfw_free(_glfw.ns.clipboardString); _glfw_free(_glfw.ns.clipboardString);
_glfwTerminateNSGL(); _glfwTerminateNSGL();
_glfwTerminateEGL();
_glfwTerminateOSMesa();
} // autoreleasepool } // autoreleasepool
} }
#endif // _GLFW_COCOA

View File

@ -31,8 +31,6 @@
#define GLFW_COCOA_JOYSTICK_STATE _GLFWjoystickNS ns; #define GLFW_COCOA_JOYSTICK_STATE _GLFWjoystickNS ns;
#define GLFW_COCOA_LIBRARY_JOYSTICK_STATE #define GLFW_COCOA_LIBRARY_JOYSTICK_STATE
#define GLFW_BUILD_COCOA_MAPPINGS
// Cocoa-specific per-joystick data // Cocoa-specific per-joystick data
// //
typedef struct _GLFWjoystickNS typedef struct _GLFWjoystickNS
@ -45,7 +43,7 @@ typedef struct _GLFWjoystickNS
GLFWbool _glfwInitJoysticksCocoa(void); GLFWbool _glfwInitJoysticksCocoa(void);
void _glfwTerminateJoysticksCocoa(void); void _glfwTerminateJoysticksCocoa(void);
int _glfwPollJoystickCocoa(_GLFWjoystick* js, int mode); GLFWbool _glfwPollJoystickCocoa(_GLFWjoystick* js, int mode);
const char* _glfwGetMappingNameCocoa(void); const char* _glfwGetMappingNameCocoa(void);
void _glfwUpdateGamepadGUIDCocoa(char* guid); void _glfwUpdateGamepadGUIDCocoa(char* guid);

View File

@ -29,6 +29,8 @@
#include "internal.h" #include "internal.h"
#if defined(_GLFW_COCOA)
#include <unistd.h> #include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
@ -96,8 +98,7 @@ static CFComparisonResult compareElements(const void* fp,
// //
static void closeJoystick(_GLFWjoystick* js) static void closeJoystick(_GLFWjoystick* js)
{ {
if (!js->present) _glfwInputJoystick(js, GLFW_DISCONNECTED);
return;
for (int i = 0; i < CFArrayGetCount(js->ns.axes); i++) for (int i = 0; i < CFArrayGetCount(js->ns.axes); i++)
_glfw_free((void*) CFArrayGetValueAtIndex(js->ns.axes, i)); _glfw_free((void*) CFArrayGetValueAtIndex(js->ns.axes, i));
@ -112,7 +113,6 @@ static void closeJoystick(_GLFWjoystick* js)
CFRelease(js->ns.hats); CFRelease(js->ns.hats);
_glfwFreeJoystick(js); _glfwFreeJoystick(js);
_glfwInputJoystick(js, GLFW_DISCONNECTED);
} }
// Callback for user-initiated joystick addition // Callback for user-initiated joystick addition
@ -136,6 +136,14 @@ static void matchCallback(void* context,
return; return;
} }
CFArrayRef elements =
IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone);
// It is reportedly possible for this to fail on macOS 13 Ventura
// if the application does not have input monitoring permissions
if (!elements)
return;
axes = CFArrayCreateMutable(NULL, 0, NULL); axes = CFArrayCreateMutable(NULL, 0, NULL);
buttons = CFArrayCreateMutable(NULL, 0, NULL); buttons = CFArrayCreateMutable(NULL, 0, NULL);
hats = CFArrayCreateMutable(NULL, 0, NULL); hats = CFArrayCreateMutable(NULL, 0, NULL);
@ -179,9 +187,6 @@ static void matchCallback(void* context,
name[8], name[9], name[10]); name[8], name[9], name[10]);
} }
CFArrayRef elements =
IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone);
for (CFIndex i = 0; i < CFArrayGetCount(elements); i++) for (CFIndex i = 0; i < CFArrayGetCount(elements); i++)
{ {
IOHIDElementRef native = (IOHIDElementRef) IOHIDElementRef native = (IOHIDElementRef)
@ -289,9 +294,9 @@ static void removeCallback(void* context,
{ {
for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{ {
if (_glfw.joysticks[jid].ns.device == device) if (_glfw.joysticks[jid].connected && _glfw.joysticks[jid].ns.device == device)
{ {
closeJoystick(_glfw.joysticks + jid); closeJoystick(&_glfw.joysticks[jid]);
break; break;
} }
} }
@ -382,7 +387,10 @@ GLFWbool _glfwInitJoysticksCocoa(void)
void _glfwTerminateJoysticksCocoa(void) void _glfwTerminateJoysticksCocoa(void)
{ {
for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
closeJoystick(_glfw.joysticks + jid); {
if (_glfw.joysticks[jid].connected)
closeJoystick(&_glfw.joysticks[jid]);
}
if (_glfw.ns.hidManager) if (_glfw.ns.hidManager)
{ {
@ -392,7 +400,7 @@ void _glfwTerminateJoysticksCocoa(void)
} }
int _glfwPollJoystickCocoa(_GLFWjoystick* js, int mode) GLFWbool _glfwPollJoystickCocoa(_GLFWjoystick* js, int mode)
{ {
if (mode & _GLFW_POLL_AXES) if (mode & _GLFW_POLL_AXES)
{ {
@ -455,7 +463,7 @@ int _glfwPollJoystickCocoa(_GLFWjoystick* js, int mode)
} }
} }
return js->present; return js->connected;
} }
const char* _glfwGetMappingNameCocoa(void) const char* _glfwGetMappingNameCocoa(void)
@ -475,3 +483,5 @@ void _glfwUpdateGamepadGUIDCocoa(char* guid)
} }
} }
#endif // _GLFW_COCOA

View File

@ -29,6 +29,8 @@
#include "internal.h" #include "internal.h"
#if defined(_GLFW_COCOA)
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>
@ -98,11 +100,7 @@ static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen)
IOObjectRelease(it); IOObjectRelease(it);
if (!service) if (!service)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Cocoa: Failed to find service port for display");
return _glfw_strdup("Display"); return _glfw_strdup("Display");
}
CFDictionaryRef names = CFDictionaryRef names =
CFDictionaryGetValue(info, CFSTR(kDisplayProductName)); CFDictionaryGetValue(info, CFSTR(kDisplayProductName));
@ -629,3 +627,5 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* handle)
return monitor->ns.displayID; return monitor->ns.displayID;
} }
#endif // _GLFW_COCOA

View File

@ -214,7 +214,7 @@ GLFWbool _glfwConnectCocoa(int platformID, _GLFWplatform* platform);
int _glfwInitCocoa(void); int _glfwInitCocoa(void);
void _glfwTerminateCocoa(void); void _glfwTerminateCocoa(void);
int _glfwCreateWindowCocoa(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); GLFWbool _glfwCreateWindowCocoa(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowCocoa(_GLFWwindow* window); void _glfwDestroyWindowCocoa(_GLFWwindow* window);
void _glfwSetWindowTitleCocoa(_GLFWwindow* window, const char* title); void _glfwSetWindowTitleCocoa(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconCocoa(_GLFWwindow* window, int count, const GLFWimage* images); void _glfwSetWindowIconCocoa(_GLFWwindow* window, int count, const GLFWimage* images);
@ -235,12 +235,12 @@ void _glfwHideWindowCocoa(_GLFWwindow* window);
void _glfwRequestWindowAttentionCocoa(_GLFWwindow* window); void _glfwRequestWindowAttentionCocoa(_GLFWwindow* window);
void _glfwFocusWindowCocoa(_GLFWwindow* window); void _glfwFocusWindowCocoa(_GLFWwindow* window);
void _glfwSetWindowMonitorCocoa(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); void _glfwSetWindowMonitorCocoa(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
int _glfwWindowFocusedCocoa(_GLFWwindow* window); GLFWbool _glfwWindowFocusedCocoa(_GLFWwindow* window);
int _glfwWindowIconifiedCocoa(_GLFWwindow* window); GLFWbool _glfwWindowIconifiedCocoa(_GLFWwindow* window);
int _glfwWindowVisibleCocoa(_GLFWwindow* window); GLFWbool _glfwWindowVisibleCocoa(_GLFWwindow* window);
int _glfwWindowMaximizedCocoa(_GLFWwindow* window); GLFWbool _glfwWindowMaximizedCocoa(_GLFWwindow* window);
int _glfwWindowHoveredCocoa(_GLFWwindow* window); GLFWbool _glfwWindowHoveredCocoa(_GLFWwindow* window);
int _glfwFramebufferTransparentCocoa(_GLFWwindow* window); GLFWbool _glfwFramebufferTransparentCocoa(_GLFWwindow* window);
void _glfwSetWindowResizableCocoa(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowResizableCocoa(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowDecoratedCocoa(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowDecoratedCocoa(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowFloatingCocoa(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowFloatingCocoa(_GLFWwindow* window, GLFWbool enabled);
@ -261,8 +261,8 @@ void _glfwSetCursorPosCocoa(_GLFWwindow* window, double xpos, double ypos);
void _glfwSetCursorModeCocoa(_GLFWwindow* window, int mode); void _glfwSetCursorModeCocoa(_GLFWwindow* window, int mode);
const char* _glfwGetScancodeNameCocoa(int scancode); const char* _glfwGetScancodeNameCocoa(int scancode);
int _glfwGetKeyScancodeCocoa(int key); int _glfwGetKeyScancodeCocoa(int key);
int _glfwCreateCursorCocoa(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); GLFWbool _glfwCreateCursorCocoa(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot);
int _glfwCreateStandardCursorCocoa(_GLFWcursor* cursor, int shape); GLFWbool _glfwCreateStandardCursorCocoa(_GLFWcursor* cursor, int shape);
void _glfwDestroyCursorCocoa(_GLFWcursor* cursor); void _glfwDestroyCursorCocoa(_GLFWcursor* cursor);
void _glfwSetCursorCocoa(_GLFWwindow* window, _GLFWcursor* cursor); void _glfwSetCursorCocoa(_GLFWwindow* window, _GLFWcursor* cursor);
void _glfwSetClipboardStringCocoa(const char* string); void _glfwSetClipboardStringCocoa(const char* string);
@ -273,7 +273,7 @@ EGLNativeDisplayType _glfwGetEGLNativeDisplayCocoa(void);
EGLNativeWindowType _glfwGetEGLNativeWindowCocoa(_GLFWwindow* window); EGLNativeWindowType _glfwGetEGLNativeWindowCocoa(_GLFWwindow* window);
void _glfwGetRequiredInstanceExtensionsCocoa(char** extensions); void _glfwGetRequiredInstanceExtensionsCocoa(char** extensions);
int _glfwGetPhysicalDevicePresentationSupportCocoa(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); GLFWbool _glfwGetPhysicalDevicePresentationSupportCocoa(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
void _glfwFreeMonitorCocoa(_GLFWmonitor* monitor); void _glfwFreeMonitorCocoa(_GLFWmonitor* monitor);

View File

@ -23,11 +23,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(GLFW_BUILD_COCOA_TIMER)
#include <mach/mach_time.h> #include <mach/mach_time.h>
@ -53,3 +53,5 @@ uint64_t _glfwPlatformGetTimerFrequency(void)
return _glfw.timer.ns.frequency; return _glfw.timer.ns.frequency;
} }
#endif // GLFW_BUILD_COCOA_TIMER

View File

@ -28,28 +28,14 @@
#include "internal.h" #include "internal.h"
#if defined(_GLFW_COCOA)
#include <float.h> #include <float.h>
#include <string.h> #include <string.h>
// Returns the style mask corresponding to the window settings // HACK: This enum value is missing from framework headers on OS X 10.11 despite
// // having been (according to documentation) added in Mac OS X 10.7
static NSUInteger getStyleMask(_GLFWwindow* window) #define NSWindowCollectionBehaviorFullScreenNone (1 << 9)
{
NSUInteger styleMask = NSWindowStyleMaskMiniaturizable;
if (window->monitor || !window->decorated)
styleMask |= NSWindowStyleMaskBorderless;
else
{
styleMask |= NSWindowStyleMaskTitled |
NSWindowStyleMaskClosable;
if (window->resizable)
styleMask |= NSWindowStyleMaskResizable;
}
return styleMask;
}
// Returns whether the cursor is in the content area of the specified window // Returns whether the cursor is in the content area of the specified window
// //
@ -325,10 +311,15 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
- (void)windowDidChangeOcclusionState:(NSNotification* )notification - (void)windowDidChangeOcclusionState:(NSNotification* )notification
{ {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
if ([window->ns.object respondsToSelector:@selector(occlusionState)])
{
if ([window->ns.object occlusionState] & NSWindowOcclusionStateVisible) if ([window->ns.object occlusionState] & NSWindowOcclusionStateVisible)
window->ns.occluded = GLFW_FALSE; window->ns.occluded = GLFW_FALSE;
else else
window->ns.occluded = GLFW_TRUE; window->ns.occluded = GLFW_TRUE;
}
#endif
} }
@end @end
@ -807,11 +798,35 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
contentRect = NSMakeRect(xpos, ypos, mode.width, mode.height); contentRect = NSMakeRect(xpos, ypos, mode.width, mode.height);
} }
else else
{
if (wndconfig->xpos == GLFW_ANY_POSITION ||
wndconfig->ypos == GLFW_ANY_POSITION)
{
contentRect = NSMakeRect(0, 0, wndconfig->width, wndconfig->height); contentRect = NSMakeRect(0, 0, wndconfig->width, wndconfig->height);
}
else
{
const int xpos = wndconfig->xpos;
const int ypos = _glfwTransformYCocoa(wndconfig->ypos + wndconfig->height - 1);
contentRect = NSMakeRect(xpos, ypos, wndconfig->width, wndconfig->height);
}
}
NSUInteger styleMask = NSWindowStyleMaskMiniaturizable;
if (window->monitor || !window->decorated)
styleMask |= NSWindowStyleMaskBorderless;
else
{
styleMask |= (NSWindowStyleMaskTitled | NSWindowStyleMaskClosable);
if (window->resizable)
styleMask |= NSWindowStyleMaskResizable;
}
window->ns.object = [[GLFWWindow alloc] window->ns.object = [[GLFWWindow alloc]
initWithContentRect:contentRect initWithContentRect:contentRect
styleMask:getStyleMask(window) styleMask:styleMask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]; defer:NO];
@ -824,11 +839,15 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
if (window->monitor) if (window->monitor)
[window->ns.object setLevel:NSMainMenuWindowLevel + 1]; [window->ns.object setLevel:NSMainMenuWindowLevel + 1];
else else
{
if (wndconfig->xpos == GLFW_ANY_POSITION ||
wndconfig->ypos == GLFW_ANY_POSITION)
{ {
[(NSWindow*) window->ns.object center]; [(NSWindow*) window->ns.object center];
_glfw.ns.cascadePoint = _glfw.ns.cascadePoint =
NSPointToCGPoint([window->ns.object cascadeTopLeftFromPoint: NSPointToCGPoint([window->ns.object cascadeTopLeftFromPoint:
NSPointFromCGPoint(_glfw.ns.cascadePoint)]); NSPointFromCGPoint(_glfw.ns.cascadePoint)]);
}
if (wndconfig->resizable) if (wndconfig->resizable)
{ {
@ -837,6 +856,12 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
NSWindowCollectionBehaviorManaged; NSWindowCollectionBehaviorManaged;
[window->ns.object setCollectionBehavior:behavior]; [window->ns.object setCollectionBehavior:behavior];
} }
else
{
const NSWindowCollectionBehavior behavior =
NSWindowCollectionBehaviorFullScreenNone;
[window->ns.object setCollectionBehavior:behavior];
}
if (wndconfig->floating) if (wndconfig->floating)
[window->ns.object setLevel:NSFloatingWindowLevel]; [window->ns.object setLevel:NSFloatingWindowLevel];
@ -893,7 +918,7 @@ float _glfwTransformYCocoa(float y)
////// GLFW platform API ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
int _glfwCreateWindowCocoa(_GLFWwindow* window, GLFWbool _glfwCreateWindowCocoa(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig, const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
@ -931,13 +956,31 @@ int _glfwCreateWindowCocoa(_GLFWwindow* window,
if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
} }
if (!_glfwRefreshContextAttribs(window, ctxconfig))
return GLFW_FALSE;
} }
if (wndconfig->mousePassthrough)
_glfwSetWindowMousePassthroughCocoa(window, GLFW_TRUE);
if (window->monitor) if (window->monitor)
{ {
_glfwShowWindowCocoa(window); _glfwShowWindowCocoa(window);
_glfwFocusWindowCocoa(window); _glfwFocusWindowCocoa(window);
acquireMonitor(window); acquireMonitor(window);
if (wndconfig->centerCursor)
_glfwCenterCursorInContentArea(window);
}
else
{
if (wndconfig->visible)
{
_glfwShowWindowCocoa(window);
if (wndconfig->focused)
_glfwFocusWindowCocoa(window);
}
} }
return GLFW_TRUE; return GLFW_TRUE;
@ -1217,9 +1260,10 @@ void _glfwSetWindowMonitorCocoa(_GLFWwindow* window,
{ {
const NSRect contentRect = const NSRect contentRect =
NSMakeRect(xpos, _glfwTransformYCocoa(ypos + height - 1), width, height); NSMakeRect(xpos, _glfwTransformYCocoa(ypos + height - 1), width, height);
const NSUInteger styleMask = [window->ns.object styleMask];
const NSRect frameRect = const NSRect frameRect =
[window->ns.object frameRectForContentRect:contentRect [window->ns.object frameRectForContentRect:contentRect
styleMask:getStyleMask(window)]; styleMask:styleMask];
[window->ns.object setFrame:frameRect display:YES]; [window->ns.object setFrame:frameRect display:YES];
} }
@ -1236,7 +1280,27 @@ void _glfwSetWindowMonitorCocoa(_GLFWwindow* window,
// TODO: Solve this in a less terrible way // TODO: Solve this in a less terrible way
_glfwPollEventsCocoa(); _glfwPollEventsCocoa();
const NSUInteger styleMask = getStyleMask(window); NSUInteger styleMask = [window->ns.object styleMask];
if (window->monitor)
{
styleMask &= ~(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable);
styleMask |= NSWindowStyleMaskBorderless;
}
else
{
if (window->decorated)
{
styleMask &= ~NSWindowStyleMaskBorderless;
styleMask |= (NSWindowStyleMaskTitled | NSWindowStyleMaskClosable);
}
if (window->resizable)
styleMask |= NSWindowStyleMaskResizable;
else
styleMask &= ~NSWindowStyleMaskResizable;
}
[window->ns.object setStyleMask:styleMask]; [window->ns.object setStyleMask:styleMask];
// HACK: Changing the style mask can cause the first responder to be cleared // HACK: Changing the style mask can cause the first responder to be cleared
[window->ns.object makeFirstResponder:window->ns.view]; [window->ns.object makeFirstResponder:window->ns.view];
@ -1282,6 +1346,20 @@ void _glfwSetWindowMonitorCocoa(_GLFWwindow* window,
else else
[window->ns.object setLevel:NSNormalWindowLevel]; [window->ns.object setLevel:NSNormalWindowLevel];
if (window->resizable)
{
const NSWindowCollectionBehavior behavior =
NSWindowCollectionBehaviorFullScreenPrimary |
NSWindowCollectionBehaviorManaged;
[window->ns.object setCollectionBehavior:behavior];
}
else
{
const NSWindowCollectionBehavior behavior =
NSWindowCollectionBehaviorFullScreenNone;
[window->ns.object setCollectionBehavior:behavior];
}
[window->ns.object setHasShadow:YES]; [window->ns.object setHasShadow:YES];
// HACK: Clearing NSWindowStyleMaskTitled resets and disables the window // HACK: Clearing NSWindowStyleMaskTitled resets and disables the window
// title property but the miniwindow title property is unaffected // title property but the miniwindow title property is unaffected
@ -1291,35 +1369,40 @@ void _glfwSetWindowMonitorCocoa(_GLFWwindow* window,
} // autoreleasepool } // autoreleasepool
} }
int _glfwWindowFocusedCocoa(_GLFWwindow* window) GLFWbool _glfwWindowFocusedCocoa(_GLFWwindow* window)
{ {
@autoreleasepool { @autoreleasepool {
return [window->ns.object isKeyWindow]; return [window->ns.object isKeyWindow];
} // autoreleasepool } // autoreleasepool
} }
int _glfwWindowIconifiedCocoa(_GLFWwindow* window) GLFWbool _glfwWindowIconifiedCocoa(_GLFWwindow* window)
{ {
@autoreleasepool { @autoreleasepool {
return [window->ns.object isMiniaturized]; return [window->ns.object isMiniaturized];
} // autoreleasepool } // autoreleasepool
} }
int _glfwWindowVisibleCocoa(_GLFWwindow* window) GLFWbool _glfwWindowVisibleCocoa(_GLFWwindow* window)
{ {
@autoreleasepool { @autoreleasepool {
return [window->ns.object isVisible]; return [window->ns.object isVisible];
} // autoreleasepool } // autoreleasepool
} }
int _glfwWindowMaximizedCocoa(_GLFWwindow* window) GLFWbool _glfwWindowMaximizedCocoa(_GLFWwindow* window)
{ {
@autoreleasepool { @autoreleasepool {
if (window->resizable)
return [window->ns.object isZoomed]; return [window->ns.object isZoomed];
else
return GLFW_FALSE;
} // autoreleasepool } // autoreleasepool
} }
int _glfwWindowHoveredCocoa(_GLFWwindow* window) GLFWbool _glfwWindowHoveredCocoa(_GLFWwindow* window)
{ {
@autoreleasepool { @autoreleasepool {
@ -1337,7 +1420,7 @@ int _glfwWindowHoveredCocoa(_GLFWwindow* window)
} // autoreleasepool } // autoreleasepool
} }
int _glfwFramebufferTransparentCocoa(_GLFWwindow* window) GLFWbool _glfwFramebufferTransparentCocoa(_GLFWwindow* window)
{ {
@autoreleasepool { @autoreleasepool {
return ![window->ns.object isOpaque] && ![window->ns.view isOpaque]; return ![window->ns.object isOpaque] && ![window->ns.view isOpaque];
@ -1347,15 +1430,46 @@ int _glfwFramebufferTransparentCocoa(_GLFWwindow* window)
void _glfwSetWindowResizableCocoa(_GLFWwindow* window, GLFWbool enabled) void _glfwSetWindowResizableCocoa(_GLFWwindow* window, GLFWbool enabled)
{ {
@autoreleasepool { @autoreleasepool {
[window->ns.object setStyleMask:getStyleMask(window)];
const NSUInteger styleMask = [window->ns.object styleMask];
if (enabled)
{
[window->ns.object setStyleMask:(styleMask | NSWindowStyleMaskResizable)];
const NSWindowCollectionBehavior behavior =
NSWindowCollectionBehaviorFullScreenPrimary |
NSWindowCollectionBehaviorManaged;
[window->ns.object setCollectionBehavior:behavior];
}
else
{
[window->ns.object setStyleMask:(styleMask & ~NSWindowStyleMaskResizable)];
const NSWindowCollectionBehavior behavior =
NSWindowCollectionBehaviorFullScreenNone;
[window->ns.object setCollectionBehavior:behavior];
}
} // autoreleasepool } // autoreleasepool
} }
void _glfwSetWindowDecoratedCocoa(_GLFWwindow* window, GLFWbool enabled) void _glfwSetWindowDecoratedCocoa(_GLFWwindow* window, GLFWbool enabled)
{ {
@autoreleasepool { @autoreleasepool {
[window->ns.object setStyleMask:getStyleMask(window)];
NSUInteger styleMask = [window->ns.object styleMask];
if (enabled)
{
styleMask |= (NSWindowStyleMaskTitled | NSWindowStyleMaskClosable);
styleMask &= ~NSWindowStyleMaskBorderless;
}
else
{
styleMask |= NSWindowStyleMaskBorderless;
styleMask &= ~(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable);
}
[window->ns.object setStyleMask:styleMask];
[window->ns.object makeFirstResponder:window->ns.view]; [window->ns.object makeFirstResponder:window->ns.view];
} // autoreleasepool } // autoreleasepool
} }
@ -1535,8 +1649,16 @@ void _glfwSetCursorPosCocoa(_GLFWwindow* window, double x, double y)
void _glfwSetCursorModeCocoa(_GLFWwindow* window, int mode) void _glfwSetCursorModeCocoa(_GLFWwindow* window, int mode)
{ {
@autoreleasepool { @autoreleasepool {
if (mode == GLFW_CURSOR_CAPTURED)
{
_glfwInputError(GLFW_FEATURE_UNIMPLEMENTED,
"Cocoa: Captured cursor mode not yet implemented");
}
if (_glfwWindowFocusedCocoa(window)) if (_glfwWindowFocusedCocoa(window))
updateCursorMode(window); updateCursorMode(window);
} // autoreleasepool } // autoreleasepool
} }
@ -1594,7 +1716,7 @@ int _glfwGetKeyScancodeCocoa(int key)
return _glfw.ns.scancodes[key]; return _glfw.ns.scancodes[key];
} }
int _glfwCreateCursorCocoa(_GLFWcursor* cursor, GLFWbool _glfwCreateCursorCocoa(_GLFWcursor* cursor,
const GLFWimage* image, const GLFWimage* image,
int xhot, int yhot) int xhot, int yhot)
{ {
@ -1638,7 +1760,7 @@ int _glfwCreateCursorCocoa(_GLFWcursor* cursor,
} // autoreleasepool } // autoreleasepool
} }
int _glfwCreateStandardCursorCocoa(_GLFWcursor* cursor, int shape) GLFWbool _glfwCreateStandardCursorCocoa(_GLFWcursor* cursor, int shape)
{ {
@autoreleasepool { @autoreleasepool {
@ -1821,7 +1943,7 @@ void _glfwGetRequiredInstanceExtensionsCocoa(char** extensions)
} }
} }
int _glfwGetPhysicalDevicePresentationSupportCocoa(VkInstance instance, GLFWbool _glfwGetPhysicalDevicePresentationSupportCocoa(VkInstance instance,
VkPhysicalDevice device, VkPhysicalDevice device,
uint32_t queuefamily) uint32_t queuefamily)
{ {
@ -1939,3 +2061,5 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle)
return window->ns.object; return window->ns.object;
} }
#endif // _GLFW_COCOA

View File

@ -24,8 +24,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
@ -48,16 +46,6 @@
// //
GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig) GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig)
{ {
if (ctxconfig->share)
{
if (ctxconfig->client == GLFW_NO_API ||
ctxconfig->share->context.client == GLFW_NO_API)
{
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
return GLFW_FALSE;
}
}
if (ctxconfig->source != GLFW_NATIVE_CONTEXT_API && 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) ctxconfig->source != GLFW_OSMESA_CONTEXT_API)
@ -78,6 +66,23 @@ GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig)
return GLFW_FALSE; return GLFW_FALSE;
} }
if (ctxconfig->share)
{
if (ctxconfig->client == GLFW_NO_API ||
ctxconfig->share->context.client == GLFW_NO_API)
{
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
return GLFW_FALSE;
}
if (ctxconfig->source != ctxconfig->share->context.source)
{
_glfwInputError(GLFW_INVALID_ENUM,
"Context creation APIs do not match between contexts");
return GLFW_FALSE;
}
}
if (ctxconfig->client == GLFW_OPENGL_API) if (ctxconfig->client == GLFW_OPENGL_API)
{ {
if ((ctxconfig->major < 1 || ctxconfig->minor < 0) || if ((ctxconfig->major < 1 || ctxconfig->minor < 0) ||
@ -356,6 +361,8 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window,
previous = _glfwPlatformGetTls(&_glfw.contextSlot); previous = _glfwPlatformGetTls(&_glfw.contextSlot);
glfwMakeContextCurrent((GLFWwindow*) window); glfwMakeContextCurrent((GLFWwindow*) window);
if (_glfwPlatformGetTls(&_glfw.contextSlot) != window)
return GLFW_FALSE;
window->context.GetIntegerv = (PFNGLGETINTEGERVPROC) window->context.GetIntegerv = (PFNGLGETINTEGERVPROC)
window->context.getProcAddress("glGetIntegerv"); window->context.getProcAddress("glGetIntegerv");
@ -609,10 +616,12 @@ GLFWbool _glfwStringInExtensionString(const char* string, const char* extensions
GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle) GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFWwindow* previous = _glfwPlatformGetTls(&_glfw.contextSlot); _GLFWwindow* previous;
_GLFW_REQUIRE_INIT(); _GLFW_REQUIRE_INIT();
previous = _glfwPlatformGetTls(&_glfw.contextSlot);
if (window && window->context.client == GLFW_NO_API) if (window && window->context.client == GLFW_NO_API)
{ {
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, _glfwInputError(GLFW_NO_WINDOW_CONTEXT,

View File

@ -24,8 +24,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
@ -88,13 +86,30 @@ static int getEGLConfigAttrib(EGLConfig config, int attrib)
// Return the EGLConfig most closely matching the specified hints // Return the EGLConfig most closely matching the specified hints
// //
static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig, static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* desired, const _GLFWfbconfig* fbconfig,
EGLConfig* result) EGLConfig* result)
{ {
EGLConfig* nativeConfigs; EGLConfig* nativeConfigs;
_GLFWfbconfig* usableConfigs; _GLFWfbconfig* usableConfigs;
const _GLFWfbconfig* closest; const _GLFWfbconfig* closest;
int i, nativeCount, usableCount; int i, nativeCount, usableCount, apiBit;
GLFWbool wrongApiAvailable = GLFW_FALSE;
if (ctxconfig->client == GLFW_OPENGL_ES_API)
{
if (ctxconfig->major == 1)
apiBit = EGL_OPENGL_ES_BIT;
else
apiBit = EGL_OPENGL_ES2_BIT;
}
else
apiBit = EGL_OPENGL_BIT;
if (fbconfig->stereo)
{
_glfwInputError(GLFW_FORMAT_UNAVAILABLE, "EGL: Stereo rendering not supported");
return GLFW_FALSE;
}
eglGetConfigs(_glfw.egl.display, NULL, 0, &nativeCount); eglGetConfigs(_glfw.egl.display, NULL, 0, &nativeCount);
if (!nativeCount) if (!nativeCount)
@ -132,7 +147,7 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
if (!vi.visualid) if (!vi.visualid)
continue; continue;
if (desired->transparent) if (fbconfig->transparent)
{ {
int count; int count;
XVisualInfo* vis = XVisualInfo* vis =
@ -146,22 +161,9 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
} }
#endif // _GLFW_X11 #endif // _GLFW_X11
if (ctxconfig->client == GLFW_OPENGL_ES_API) if (!(getEGLConfigAttrib(n, EGL_RENDERABLE_TYPE) & apiBit))
{ {
if (ctxconfig->major == 1) wrongApiAvailable = GLFW_TRUE;
{
if (!(getEGLConfigAttrib(n, EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES_BIT))
continue;
}
else
{
if (!(getEGLConfigAttrib(n, EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT))
continue;
}
}
else if (ctxconfig->client == GLFW_OPENGL_API)
{
if (!(getEGLConfigAttrib(n, EGL_RENDERABLE_TYPE) & EGL_OPENGL_BIT))
continue; continue;
} }
@ -173,16 +175,60 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
u->depthBits = getEGLConfigAttrib(n, EGL_DEPTH_SIZE); u->depthBits = getEGLConfigAttrib(n, EGL_DEPTH_SIZE);
u->stencilBits = getEGLConfigAttrib(n, EGL_STENCIL_SIZE); u->stencilBits = getEGLConfigAttrib(n, EGL_STENCIL_SIZE);
#if defined(_GLFW_WAYLAND)
if (_glfw.platform.platformID == GLFW_PLATFORM_WAYLAND)
{
// NOTE: The wl_surface opaque region is no guarantee that its buffer
// is presented as opaque, if it also has an alpha channel
// HACK: If EGL_EXT_present_opaque is unavailable, ignore any config
// with an alpha channel to ensure the buffer is opaque
if (!_glfw.egl.EXT_present_opaque)
{
if (!fbconfig->transparent && u->alphaBits > 0)
continue;
}
}
#endif // _GLFW_WAYLAND
u->samples = getEGLConfigAttrib(n, EGL_SAMPLES); u->samples = getEGLConfigAttrib(n, EGL_SAMPLES);
u->doublebuffer = desired->doublebuffer; u->doublebuffer = fbconfig->doublebuffer;
u->handle = (uintptr_t) n; u->handle = (uintptr_t) n;
usableCount++; usableCount++;
} }
closest = _glfwChooseFBConfig(desired, usableConfigs, usableCount); closest = _glfwChooseFBConfig(fbconfig, usableConfigs, usableCount);
if (closest) if (closest)
*result = (EGLConfig) closest->handle; *result = (EGLConfig) closest->handle;
else
{
if (wrongApiAvailable)
{
if (ctxconfig->client == GLFW_OPENGL_ES_API)
{
if (ctxconfig->major == 1)
{
_glfwInputError(GLFW_API_UNAVAILABLE,
"EGL: Failed to find support for OpenGL ES 1.x");
}
else
{
_glfwInputError(GLFW_API_UNAVAILABLE,
"EGL: Failed to find support for OpenGL ES 2 or later");
}
}
else
{
_glfwInputError(GLFW_API_UNAVAILABLE,
"EGL: Failed to find support for OpenGL");
}
}
else
{
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
"EGL: Failed to find a suitable EGLConfig");
}
}
_glfw_free(nativeConfigs); _glfw_free(nativeConfigs);
_glfw_free(usableConfigs); _glfw_free(usableConfigs);
@ -263,6 +309,7 @@ static int extensionSupportedEGL(const char* extension)
static GLFWglproc getProcAddressEGL(const char* procname) static GLFWglproc getProcAddressEGL(const char* procname)
{ {
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
assert(window != NULL);
if (window->context.egl.client) if (window->context.egl.client)
{ {
@ -325,7 +372,7 @@ GLFWbool _glfwInitEGL(void)
"libEGL.dylib", "libEGL.dylib",
#elif defined(__CYGWIN__) #elif defined(__CYGWIN__)
"libEGL-1.so", "libEGL-1.so",
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
"libEGL.so", "libEGL.so",
#else #else
"libEGL.so.1", "libEGL.so.1",
@ -506,7 +553,7 @@ void _glfwTerminateEGL(void)
} }
} }
#define setAttrib(a, v) \ #define SET_ATTRIB(a, v) \
{ \ { \
assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
attribs[index++] = a; \ attribs[index++] = a; \
@ -535,11 +582,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
share = ctxconfig->share->context.egl.handle; share = ctxconfig->share->context.egl.handle;
if (!chooseEGLConfig(ctxconfig, fbconfig, &config)) if (!chooseEGLConfig(ctxconfig, fbconfig, &config))
{
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
"EGL: Failed to find a suitable EGLConfig");
return GLFW_FALSE; return GLFW_FALSE;
}
if (ctxconfig->client == GLFW_OPENGL_ES_API) if (ctxconfig->client == GLFW_OPENGL_ES_API)
{ {
@ -584,57 +627,57 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
{ {
if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION) if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION)
{ {
setAttrib(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, SET_ATTRIB(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR,
EGL_NO_RESET_NOTIFICATION_KHR); EGL_NO_RESET_NOTIFICATION_KHR);
} }
else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET) else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET)
{ {
setAttrib(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, SET_ATTRIB(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR,
EGL_LOSE_CONTEXT_ON_RESET_KHR); EGL_LOSE_CONTEXT_ON_RESET_KHR);
} }
flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR; flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR;
} }
if (ctxconfig->major != 1 || ctxconfig->minor != 0)
{
SET_ATTRIB(EGL_CONTEXT_MAJOR_VERSION_KHR, ctxconfig->major);
SET_ATTRIB(EGL_CONTEXT_MINOR_VERSION_KHR, ctxconfig->minor);
}
if (ctxconfig->noerror) if (ctxconfig->noerror)
{ {
if (_glfw.egl.KHR_create_context_no_error) if (_glfw.egl.KHR_create_context_no_error)
setAttrib(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, GLFW_TRUE); SET_ATTRIB(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, GLFW_TRUE);
}
if (ctxconfig->major != 1 || ctxconfig->minor != 0)
{
setAttrib(EGL_CONTEXT_MAJOR_VERSION_KHR, ctxconfig->major);
setAttrib(EGL_CONTEXT_MINOR_VERSION_KHR, ctxconfig->minor);
} }
if (mask) if (mask)
setAttrib(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, mask); SET_ATTRIB(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, mask);
if (flags) if (flags)
setAttrib(EGL_CONTEXT_FLAGS_KHR, flags); SET_ATTRIB(EGL_CONTEXT_FLAGS_KHR, flags);
} }
else else
{ {
if (ctxconfig->client == GLFW_OPENGL_ES_API) if (ctxconfig->client == GLFW_OPENGL_ES_API)
setAttrib(EGL_CONTEXT_CLIENT_VERSION, ctxconfig->major); SET_ATTRIB(EGL_CONTEXT_CLIENT_VERSION, ctxconfig->major);
} }
if (_glfw.egl.KHR_context_flush_control) if (_glfw.egl.KHR_context_flush_control)
{ {
if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE) if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE)
{ {
setAttrib(EGL_CONTEXT_RELEASE_BEHAVIOR_KHR, SET_ATTRIB(EGL_CONTEXT_RELEASE_BEHAVIOR_KHR,
EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR); EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR);
} }
else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH) else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH)
{ {
setAttrib(EGL_CONTEXT_RELEASE_BEHAVIOR_KHR, SET_ATTRIB(EGL_CONTEXT_RELEASE_BEHAVIOR_KHR,
EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR); EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR);
} }
} }
setAttrib(EGL_NONE, EGL_NONE); SET_ATTRIB(EGL_NONE, EGL_NONE);
window->context.egl.handle = eglCreateContext(_glfw.egl.display, window->context.egl.handle = eglCreateContext(_glfw.egl.display,
config, share, attribs); config, share, attribs);
@ -653,16 +696,19 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
if (fbconfig->sRGB) if (fbconfig->sRGB)
{ {
if (_glfw.egl.KHR_gl_colorspace) if (_glfw.egl.KHR_gl_colorspace)
setAttrib(EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR); SET_ATTRIB(EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR);
} }
if (!fbconfig->doublebuffer) if (!fbconfig->doublebuffer)
setAttrib(EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER); SET_ATTRIB(EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER);
if (_glfw.platform.platformID == GLFW_PLATFORM_WAYLAND)
{
if (_glfw.egl.EXT_present_opaque) if (_glfw.egl.EXT_present_opaque)
setAttrib(EGL_PRESENT_OPAQUE_EXT, !fbconfig->transparent); SET_ATTRIB(EGL_PRESENT_OPAQUE_EXT, !fbconfig->transparent);
}
setAttrib(EGL_NONE, EGL_NONE); SET_ATTRIB(EGL_NONE, EGL_NONE);
native = _glfw.platform.getEGLNativeWindow(window); native = _glfw.platform.getEGLNativeWindow(window);
// HACK: ANGLE does not implement eglCreatePlatformWindowSurfaceEXT // HACK: ANGLE does not implement eglCreatePlatformWindowSurfaceEXT
@ -702,7 +748,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
"libGLES_CM.dll", "libGLES_CM.dll",
#elif defined(_GLFW_COCOA) #elif defined(_GLFW_COCOA)
"libGLESv1_CM.dylib", "libGLESv1_CM.dylib",
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
"libGLESv1_CM.so", "libGLESv1_CM.so",
#else #else
"libGLESv1_CM.so.1", "libGLESv1_CM.so.1",
@ -721,7 +767,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
"libGLESv2.dylib", "libGLESv2.dylib",
#elif defined(__CYGWIN__) #elif defined(__CYGWIN__)
"libGLESv2-2.so", "libGLESv2-2.so",
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
"libGLESv2.so", "libGLESv2.so",
#else #else
"libGLESv2.so.2", "libGLESv2.so.2",
@ -734,9 +780,10 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
_GLFW_OPENGL_LIBRARY, _GLFW_OPENGL_LIBRARY,
#elif defined(_GLFW_WIN32) #elif defined(_GLFW_WIN32)
#elif defined(_GLFW_COCOA) #elif defined(_GLFW_COCOA)
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
"libGL.so", "libGL.so",
#else #else
"libOpenGL.so.0",
"libGL.so.1", "libGL.so.1",
#endif #endif
NULL NULL
@ -782,7 +829,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
return GLFW_TRUE; return GLFW_TRUE;
} }
#undef setAttrib #undef SET_ATTRIB
// Returns the Visual and depth of the chosen EGLConfig // Returns the Visual and depth of the chosen EGLConfig
// //
@ -799,11 +846,7 @@ GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig,
const long vimask = VisualScreenMask | VisualIDMask; const long vimask = VisualScreenMask | VisualIDMask;
if (!chooseEGLConfig(ctxconfig, fbconfig, &native)) if (!chooseEGLConfig(ctxconfig, fbconfig, &native))
{
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
"EGL: Failed to find a suitable EGLConfig");
return GLFW_FALSE; return GLFW_FALSE;
}
eglGetConfigAttrib(_glfw.egl.display, native, eglGetConfigAttrib(_glfw.egl.display, native,
EGL_NATIVE_VISUAL_ID, &visualID); EGL_NATIVE_VISUAL_ID, &visualID);

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_X11)
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
@ -190,6 +190,7 @@ static void swapBuffersGLX(_GLFWwindow* window)
static void swapIntervalGLX(int interval) static void swapIntervalGLX(int interval)
{ {
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
assert(window != NULL);
if (_glfw.glx.EXT_swap_control) if (_glfw.glx.EXT_swap_control)
{ {
@ -226,7 +227,10 @@ static GLFWglproc getProcAddressGLX(const char* procname)
else if (_glfw.glx.GetProcAddressARB) else if (_glfw.glx.GetProcAddressARB)
return _glfw.glx.GetProcAddressARB((const GLubyte*) procname); return _glfw.glx.GetProcAddressARB((const GLubyte*) procname);
else else
{
// NOTE: glvnd provides GLX 1.4, so this can only happen with libGL
return _glfwPlatformGetModuleSymbol(_glfw.glx.handle, procname); return _glfwPlatformGetModuleSymbol(_glfw.glx.handle, procname);
}
} }
static void destroyContextGLX(_GLFWwindow* window) static void destroyContextGLX(_GLFWwindow* window)
@ -259,9 +263,10 @@ GLFWbool _glfwInitGLX(void)
_GLFW_GLX_LIBRARY, _GLFW_GLX_LIBRARY,
#elif defined(__CYGWIN__) #elif defined(__CYGWIN__)
"libGL-1.so", "libGL-1.so",
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
"libGL.so", "libGL.so",
#else #else
"libGLX.so.0",
"libGL.so.1", "libGL.so.1",
"libGL.so", "libGL.so",
#endif #endif
@ -308,10 +313,6 @@ GLFWbool _glfwInitGLX(void)
_glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXCreateWindow"); _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXCreateWindow");
_glfw.glx.DestroyWindow = (PFNGLXDESTROYWINDOWPROC) _glfw.glx.DestroyWindow = (PFNGLXDESTROYWINDOWPROC)
_glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXDestroyWindow"); _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXDestroyWindow");
_glfw.glx.GetProcAddress = (PFNGLXGETPROCADDRESSPROC)
_glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetProcAddress");
_glfw.glx.GetProcAddressARB = (PFNGLXGETPROCADDRESSPROC)
_glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetProcAddressARB");
_glfw.glx.GetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGPROC) _glfw.glx.GetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGPROC)
_glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetVisualFromFBConfig"); _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetVisualFromFBConfig");
@ -327,8 +328,6 @@ GLFWbool _glfwInitGLX(void)
!_glfw.glx.CreateNewContext || !_glfw.glx.CreateNewContext ||
!_glfw.glx.CreateWindow || !_glfw.glx.CreateWindow ||
!_glfw.glx.DestroyWindow || !_glfw.glx.DestroyWindow ||
!_glfw.glx.GetProcAddress ||
!_glfw.glx.GetProcAddressARB ||
!_glfw.glx.GetVisualFromFBConfig) !_glfw.glx.GetVisualFromFBConfig)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -336,6 +335,12 @@ GLFWbool _glfwInitGLX(void)
return GLFW_FALSE; return GLFW_FALSE;
} }
// NOTE: Unlike GLX 1.3 entry points these are not required to be present
_glfw.glx.GetProcAddress = (PFNGLXGETPROCADDRESSPROC)
_glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetProcAddress");
_glfw.glx.GetProcAddressARB = (PFNGLXGETPROCADDRESSPROC)
_glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetProcAddressARB");
if (!glXQueryExtension(_glfw.x11.display, if (!glXQueryExtension(_glfw.x11.display,
&_glfw.glx.errorBase, &_glfw.glx.errorBase,
&_glfw.glx.eventBase)) &_glfw.glx.eventBase))
@ -435,7 +440,7 @@ void _glfwTerminateGLX(void)
} }
} }
#define setAttrib(a, v) \ #define SET_ATTRIB(a, v) \
{ \ { \
assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
attribs[index++] = a; \ attribs[index++] = a; \
@ -523,12 +528,12 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window,
{ {
if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION) if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION)
{ {
setAttrib(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, SET_ATTRIB(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
GLX_NO_RESET_NOTIFICATION_ARB); GLX_NO_RESET_NOTIFICATION_ARB);
} }
else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET) else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET)
{ {
setAttrib(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, SET_ATTRIB(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
GLX_LOSE_CONTEXT_ON_RESET_ARB); GLX_LOSE_CONTEXT_ON_RESET_ARB);
} }
@ -542,12 +547,12 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window,
{ {
if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE) if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE)
{ {
setAttrib(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB, SET_ATTRIB(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB,
GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB); GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB);
} }
else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH) else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH)
{ {
setAttrib(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB, SET_ATTRIB(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB,
GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB); GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB);
} }
} }
@ -556,7 +561,7 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window,
if (ctxconfig->noerror) if (ctxconfig->noerror)
{ {
if (_glfw.glx.ARB_create_context_no_error) if (_glfw.glx.ARB_create_context_no_error)
setAttrib(GLX_CONTEXT_OPENGL_NO_ERROR_ARB, GLFW_TRUE); SET_ATTRIB(GLX_CONTEXT_OPENGL_NO_ERROR_ARB, GLFW_TRUE);
} }
// NOTE: Only request an explicitly versioned context when necessary, as // NOTE: Only request an explicitly versioned context when necessary, as
@ -564,17 +569,17 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window,
// highest version supported by the driver // highest version supported by the driver
if (ctxconfig->major != 1 || ctxconfig->minor != 0) if (ctxconfig->major != 1 || ctxconfig->minor != 0)
{ {
setAttrib(GLX_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major); SET_ATTRIB(GLX_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major);
setAttrib(GLX_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor); SET_ATTRIB(GLX_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor);
} }
if (mask) if (mask)
setAttrib(GLX_CONTEXT_PROFILE_MASK_ARB, mask); SET_ATTRIB(GLX_CONTEXT_PROFILE_MASK_ARB, mask);
if (flags) if (flags)
setAttrib(GLX_CONTEXT_FLAGS_ARB, flags); SET_ATTRIB(GLX_CONTEXT_FLAGS_ARB, flags);
setAttrib(None, None); SET_ATTRIB(None, None);
window->context.glx.handle = window->context.glx.handle =
_glfw.glx.CreateContextAttribsARB(_glfw.x11.display, _glfw.glx.CreateContextAttribsARB(_glfw.x11.display,
@ -631,7 +636,7 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window,
return GLFW_TRUE; return GLFW_TRUE;
} }
#undef setAttrib #undef SET_ATTRIB
// Returns the Visual and depth of the chosen GLXFBConfig // Returns the Visual and depth of the chosen GLXFBConfig
// //
@ -710,3 +715,5 @@ GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* handle)
return window->context.glx.window; return window->context.glx.window;
} }
#endif // _GLFW_X11

View File

@ -24,8 +24,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
@ -62,6 +60,9 @@ static _GLFWinitconfig _glfwInitHints =
{ {
GLFW_TRUE, // X11 XCB Vulkan surface GLFW_TRUE, // X11 XCB Vulkan surface
}, },
{
GLFW_WAYLAND_PREFER_LIBDECOR // Wayland libdecor mode
},
}; };
// The allocation function used when no custom allocator is set // The allocation function used when no custom allocator is set
@ -171,6 +172,59 @@ size_t _glfwEncodeUTF8(char* s, uint32_t codepoint)
return count; return count;
} }
// Splits and translates a text/uri-list into separate file paths
// NOTE: This function destroys the provided string
//
char** _glfwParseUriList(char* text, int* count)
{
const char* prefix = "file://";
char** paths = NULL;
char* line;
*count = 0;
while ((line = strtok(text, "\r\n")))
{
char* path;
text = NULL;
if (line[0] == '#')
continue;
if (strncmp(line, prefix, strlen(prefix)) == 0)
{
line += strlen(prefix);
// TODO: Validate hostname
while (*line != '/')
line++;
}
(*count)++;
path = _glfw_calloc(strlen(line) + 1, 1);
paths = _glfw_realloc(paths, *count * sizeof(char*));
paths[*count - 1] = path;
while (*line)
{
if (line[0] == '%' && line[1] && line[2])
{
const char digits[3] = { line[1], line[2], '\0' };
*path = (char) strtol(digits, NULL, 16);
line += 2;
}
else
*path = *line;
path++;
line++;
}
}
return paths;
}
char* _glfw_strdup(const char* source) char* _glfw_strdup(const char* source)
{ {
const size_t length = strlen(source); const size_t length = strlen(source);
@ -179,6 +233,16 @@ char* _glfw_strdup(const char* source)
return result; return result;
} }
int _glfw_min(int a, int b)
{
return a < b ? a : b;
}
int _glfw_max(int a, int b)
{
return a > b ? a : b;
}
float _glfw_fminf(float a, float b) float _glfw_fminf(float a, float b)
{ {
if (a != a) if (a != a)
@ -416,6 +480,9 @@ GLFWAPI void glfwInitHint(int hint, int value)
case GLFW_X11_XCB_VULKAN_SURFACE: case GLFW_X11_XCB_VULKAN_SURFACE:
_glfwInitHints.x11.xcbVulkanSurface = value; _glfwInitHints.x11.xcbVulkanSurface = value;
return; return;
case GLFW_WAYLAND_LIBDECOR:
_glfwInitHints.wl.libdecorMode = value;
return;
} }
_glfwInputError(GLFW_INVALID_ENUM, _glfwInputError(GLFW_INVALID_ENUM,

View File

@ -24,8 +24,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
#include "mappings.h" #include "mappings.h"
@ -44,6 +42,13 @@
#define _GLFW_JOYSTICK_BUTTON 2 #define _GLFW_JOYSTICK_BUTTON 2
#define _GLFW_JOYSTICK_HATBIT 3 #define _GLFW_JOYSTICK_HATBIT 3
#define GLFW_MOD_MASK (GLFW_MOD_SHIFT | \
GLFW_MOD_CONTROL | \
GLFW_MOD_ALT | \
GLFW_MOD_SUPER | \
GLFW_MOD_CAPS_LOCK | \
GLFW_MOD_NUM_LOCK)
// Initializes the platform joystick API if it has not been already // Initializes the platform joystick API if it has not been already
// //
static GLFWbool initJoysticks(void) static GLFWbool initJoysticks(void)
@ -266,6 +271,12 @@ static GLFWbool parseMapping(_GLFWmapping* mapping, const char* string)
// //
void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int mods) void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int mods)
{ {
assert(window != NULL);
assert(key >= 0 || key == GLFW_KEY_UNKNOWN);
assert(key <= GLFW_KEY_LAST);
assert(action == GLFW_PRESS || action == GLFW_RELEASE);
assert(mods == (mods & GLFW_MOD_MASK));
if (key >= 0 && key <= GLFW_KEY_LAST) if (key >= 0 && key <= GLFW_KEY_LAST)
{ {
GLFWbool repeated = GLFW_FALSE; GLFWbool repeated = GLFW_FALSE;
@ -297,6 +308,10 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m
// //
void _glfwInputChar(_GLFWwindow* window, uint32_t codepoint, int mods, GLFWbool plain) void _glfwInputChar(_GLFWwindow* window, uint32_t codepoint, int mods, GLFWbool plain)
{ {
assert(window != NULL);
assert(mods == (mods & GLFW_MOD_MASK));
assert(plain == GLFW_TRUE || plain == GLFW_FALSE);
if (codepoint < 32 || (codepoint > 126 && codepoint < 160)) if (codepoint < 32 || (codepoint > 126 && codepoint < 160))
return; return;
@ -317,6 +332,12 @@ void _glfwInputChar(_GLFWwindow* window, uint32_t codepoint, int mods, GLFWbool
// //
void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset) void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
{ {
assert(window != NULL);
assert(xoffset > -FLT_MAX);
assert(xoffset < FLT_MAX);
assert(yoffset > -FLT_MAX);
assert(yoffset < FLT_MAX);
if (window->callbacks.scroll) if (window->callbacks.scroll)
window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset); window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset);
} }
@ -325,6 +346,12 @@ void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
// //
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods) void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
{ {
assert(window != NULL);
assert(button >= 0);
assert(button <= GLFW_MOUSE_BUTTON_LAST);
assert(action == GLFW_PRESS || action == GLFW_RELEASE);
assert(mods == (mods & GLFW_MOD_MASK));
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
return; return;
@ -345,6 +372,12 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
// //
void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos) void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos)
{ {
assert(window != NULL);
assert(xpos > -FLT_MAX);
assert(xpos < FLT_MAX);
assert(ypos > -FLT_MAX);
assert(ypos < FLT_MAX);
if (window->virtualCursorPosX == xpos && window->virtualCursorPosY == ypos) if (window->virtualCursorPosX == xpos && window->virtualCursorPosY == ypos)
return; return;
@ -359,6 +392,9 @@ void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos)
// //
void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered) void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered)
{ {
assert(window != NULL);
assert(entered == GLFW_TRUE || entered == GLFW_FALSE);
if (window->callbacks.cursorEnter) if (window->callbacks.cursorEnter)
window->callbacks.cursorEnter((GLFWwindow*) window, entered); window->callbacks.cursorEnter((GLFWwindow*) window, entered);
} }
@ -367,6 +403,10 @@ void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered)
// //
void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths) void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths)
{ {
assert(window != NULL);
assert(count > 0);
assert(paths != NULL);
if (window->callbacks.drop) if (window->callbacks.drop)
window->callbacks.drop((GLFWwindow*) window, count, paths); window->callbacks.drop((GLFWwindow*) window, count, paths);
} }
@ -375,16 +415,26 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths)
// //
void _glfwInputJoystick(_GLFWjoystick* js, int event) void _glfwInputJoystick(_GLFWjoystick* js, int event)
{ {
const int jid = (int) (js - _glfw.joysticks); assert(js != NULL);
assert(event == GLFW_CONNECTED || event == GLFW_DISCONNECTED);
if (event == GLFW_CONNECTED)
js->connected = GLFW_TRUE;
else if (event == GLFW_DISCONNECTED)
js->connected = GLFW_FALSE;
if (_glfw.callbacks.joystick) if (_glfw.callbacks.joystick)
_glfw.callbacks.joystick(jid, event); _glfw.callbacks.joystick((int) (js - _glfw.joysticks), event);
} }
// Notifies shared code of the new value of a joystick axis // Notifies shared code of the new value of a joystick axis
// //
void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value) void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value)
{ {
assert(js != NULL);
assert(axis >= 0);
assert(axis < js->axisCount);
js->axes[axis] = value; js->axes[axis] = value;
} }
@ -392,6 +442,11 @@ void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value)
// //
void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value) void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value)
{ {
assert(js != NULL);
assert(button >= 0);
assert(button < js->buttonCount);
assert(value == GLFW_PRESS || value == GLFW_RELEASE);
js->buttons[button] = value; js->buttons[button] = value;
} }
@ -399,7 +454,19 @@ void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value)
// //
void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value) void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value)
{ {
const int base = js->buttonCount + hat * 4; int base;
assert(js != NULL);
assert(hat >= 0);
assert(hat < js->hatCount);
// Valid hat values only use the least significant nibble
assert((value & 0xf0) == 0);
// Valid hat values do not have both bits of an axis set
assert((value & GLFW_HAT_LEFT) == 0 || (value & GLFW_HAT_RIGHT) == 0);
assert((value & GLFW_HAT_UP) == 0 || (value & GLFW_HAT_DOWN) == 0);
base = js->buttonCount + hat * 4;
js->buttons[base + 0] = (value & 0x01) ? GLFW_PRESS : GLFW_RELEASE; js->buttons[base + 0] = (value & 0x01) ? GLFW_PRESS : GLFW_RELEASE;
js->buttons[base + 1] = (value & 0x02) ? GLFW_PRESS : GLFW_RELEASE; js->buttons[base + 1] = (value & 0x02) ? GLFW_PRESS : GLFW_RELEASE;
@ -442,7 +509,7 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{ {
if (!_glfw.joysticks[jid].present) if (!_glfw.joysticks[jid].allocated)
break; break;
} }
@ -450,7 +517,7 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
return NULL; return NULL;
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
js->present = GLFW_TRUE; js->allocated = GLFW_TRUE;
js->axes = _glfw_calloc(axisCount, sizeof(float)); js->axes = _glfw_calloc(axisCount, sizeof(float));
js->buttons = _glfw_calloc(buttonCount + (size_t) hatCount * 4, 1); js->buttons = _glfw_calloc(buttonCount + (size_t) hatCount * 4, 1);
js->hats = _glfw_calloc(hatCount, 1); js->hats = _glfw_calloc(hatCount, 1);
@ -528,7 +595,8 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
{ {
if (value != GLFW_CURSOR_NORMAL && if (value != GLFW_CURSOR_NORMAL &&
value != GLFW_CURSOR_HIDDEN && value != GLFW_CURSOR_HIDDEN &&
value != GLFW_CURSOR_DISABLED) value != GLFW_CURSOR_DISABLED &&
value != GLFW_CURSOR_CAPTURED)
{ {
_glfwInputError(GLFW_INVALID_ENUM, _glfwInputError(GLFW_INVALID_ENUM,
"Invalid cursor mode 0x%08X", "Invalid cursor mode 0x%08X",
@ -632,6 +700,12 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode)
if (key != GLFW_KEY_UNKNOWN) if (key != GLFW_KEY_UNKNOWN)
{ {
if (key < GLFW_KEY_SPACE || key > GLFW_KEY_LAST)
{
_glfwInputError(GLFW_INVALID_ENUM, "Invalid key %i", key);
return NULL;
}
if (key != GLFW_KEY_KP_EQUAL && if (key != GLFW_KEY_KP_EQUAL &&
(key < GLFW_KEY_KP_0 || key > GLFW_KEY_KP_ADD) && (key < GLFW_KEY_KP_0 || key > GLFW_KEY_KP_ADD) &&
(key < GLFW_KEY_APOSTROPHE || key > GLFW_KEY_WORLD_2)) (key < GLFW_KEY_APOSTROPHE || key > GLFW_KEY_WORLD_2))
@ -652,7 +726,7 @@ GLFWAPI int glfwGetKeyScancode(int key)
if (key < GLFW_KEY_SPACE || key > GLFW_KEY_LAST) if (key < GLFW_KEY_SPACE || key > GLFW_KEY_LAST)
{ {
_glfwInputError(GLFW_INVALID_ENUM, "Invalid key %i", key); _glfwInputError(GLFW_INVALID_ENUM, "Invalid key %i", key);
return GLFW_RELEASE; return -1;
} }
return _glfw.platform.getKeyScancode(key); return _glfw.platform.getKeyScancode(key);
@ -764,9 +838,16 @@ GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)
_GLFWcursor* cursor; _GLFWcursor* cursor;
assert(image != NULL); assert(image != NULL);
assert(image->pixels != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (image->width <= 0 || image->height <= 0)
{
_glfwInputError(GLFW_INVALID_VALUE, "Invalid image dimensions for cursor");
return NULL;
}
cursor = _glfw_calloc(1, sizeof(_GLFWcursor)); cursor = _glfw_calloc(1, sizeof(_GLFWcursor));
cursor->next = _glfw.cursorListHead; cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor; _glfw.cursorListHead = cursor;
@ -965,7 +1046,7 @@ GLFWAPI int glfwJoystickPresent(int jid)
return GLFW_FALSE; return GLFW_FALSE;
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->connected)
return GLFW_FALSE; return GLFW_FALSE;
return _glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE); return _glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE);
@ -993,7 +1074,7 @@ GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count)
return NULL; return NULL;
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->connected)
return NULL; return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_AXES)) if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_AXES))
@ -1025,7 +1106,7 @@ GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count)
return NULL; return NULL;
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->connected)
return NULL; return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_BUTTONS)) if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_BUTTONS))
@ -1061,7 +1142,7 @@ GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count)
return NULL; return NULL;
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->connected)
return NULL; return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_BUTTONS)) if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_BUTTONS))
@ -1090,7 +1171,7 @@ GLFWAPI const char* glfwGetJoystickName(int jid)
return NULL; return NULL;
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->connected)
return NULL; return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE)) if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
@ -1118,7 +1199,7 @@ GLFWAPI const char* glfwGetJoystickGUID(int jid)
return NULL; return NULL;
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->connected)
return NULL; return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE)) if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
@ -1137,7 +1218,7 @@ GLFWAPI void glfwSetJoystickUserPointer(int jid, void* pointer)
_GLFW_REQUIRE_INIT(); _GLFW_REQUIRE_INIT();
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->allocated)
return; return;
js->userPointer = pointer; js->userPointer = pointer;
@ -1153,7 +1234,7 @@ GLFWAPI void* glfwGetJoystickUserPointer(int jid)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->allocated)
return NULL; return NULL;
return js->userPointer; return js->userPointer;
@ -1223,7 +1304,7 @@ GLFWAPI int glfwUpdateGamepadMappings(const char* string)
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{ {
_GLFWjoystick* js = _glfw.joysticks + jid; _GLFWjoystick* js = _glfw.joysticks + jid;
if (js->present) if (js->connected)
js->mapping = findValidMapping(js); js->mapping = findValidMapping(js);
} }
@ -1249,7 +1330,7 @@ GLFWAPI int glfwJoystickIsGamepad(int jid)
return GLFW_FALSE; return GLFW_FALSE;
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->connected)
return GLFW_FALSE; return GLFW_FALSE;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE)) if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
@ -1277,7 +1358,7 @@ GLFWAPI const char* glfwGetGamepadName(int jid)
return NULL; return NULL;
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->connected)
return NULL; return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE)) if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
@ -1312,7 +1393,7 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
return GLFW_FALSE; return GLFW_FALSE;
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (!js->present) if (!js->connected)
return GLFW_FALSE; return GLFW_FALSE;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_ALL)) if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_ALL))
@ -1421,3 +1502,4 @@ GLFWAPI uint64_t glfwGetTimerFrequency(void)
_GLFW_REQUIRE_INIT_OR_RETURN(0); _GLFW_REQUIRE_INIT_OR_RETURN(0);
return _glfwPlatformGetTimerFrequency(); return _glfwPlatformGetTimerFrequency();
} }

View File

@ -330,13 +330,6 @@ typedef VkResult (APIENTRY * PFN_vkEnumerateInstanceExtensionProperties)(const c
#include "platform.h" #include "platform.h"
// Constructs a version number string from the public header macros
#define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r
#define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r)
#define _GLFW_VERSION_NUMBER _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR, \
GLFW_VERSION_MINOR, \
GLFW_VERSION_REVISION)
// Checks for whether the library has been initialized // Checks for whether the library has been initialized
#define _GLFW_REQUIRE_INIT() \ #define _GLFW_REQUIRE_INIT() \
if (!_glfw.initialized) \ if (!_glfw.initialized) \
@ -386,6 +379,9 @@ struct _GLFWinitconfig
struct { struct {
GLFWbool xcbVulkanSurface; GLFWbool xcbVulkanSurface;
} x11; } x11;
struct {
int libdecorMode;
} wl;
}; };
// Window configuration // Window configuration
@ -396,6 +392,8 @@ struct _GLFWinitconfig
// //
struct _GLFWwndconfig struct _GLFWwndconfig
{ {
int xpos;
int ypos;
int width; int width;
int height; int height;
const char* title; const char* title;
@ -422,6 +420,9 @@ struct _GLFWwndconfig
struct { struct {
GLFWbool keymenu; GLFWbool keymenu;
} win32; } win32;
struct {
char appId[256];
} wl;
}; };
// Context configuration // Context configuration
@ -636,7 +637,8 @@ struct _GLFWmapping
// //
struct _GLFWjoystick struct _GLFWjoystick
{ {
GLFWbool present; GLFWbool allocated;
GLFWbool connected;
float* axes; float* axes;
int axisCount; int axisCount;
unsigned char* buttons; unsigned char* buttons;
@ -682,8 +684,8 @@ struct _GLFWplatform
void (*setCursorMode)(_GLFWwindow*,int); void (*setCursorMode)(_GLFWwindow*,int);
void (*setRawMouseMotion)(_GLFWwindow*,GLFWbool); void (*setRawMouseMotion)(_GLFWwindow*,GLFWbool);
GLFWbool (*rawMouseMotionSupported)(void); GLFWbool (*rawMouseMotionSupported)(void);
int (*createCursor)(_GLFWcursor*,const GLFWimage*,int,int); GLFWbool (*createCursor)(_GLFWcursor*,const GLFWimage*,int,int);
int (*createStandardCursor)(_GLFWcursor*,int); GLFWbool (*createStandardCursor)(_GLFWcursor*,int);
void (*destroyCursor)(_GLFWcursor*); void (*destroyCursor)(_GLFWcursor*);
void (*setCursor)(_GLFWwindow*,_GLFWcursor*); void (*setCursor)(_GLFWwindow*,_GLFWcursor*);
const char* (*getScancodeName)(int); const char* (*getScancodeName)(int);
@ -692,7 +694,7 @@ struct _GLFWplatform
const char* (*getClipboardString)(void); const char* (*getClipboardString)(void);
GLFWbool (*initJoysticks)(void); GLFWbool (*initJoysticks)(void);
void (*terminateJoysticks)(void); void (*terminateJoysticks)(void);
int (*pollJoystick)(_GLFWjoystick*,int); GLFWbool (*pollJoystick)(_GLFWjoystick*,int);
const char* (*getMappingName)(void); const char* (*getMappingName)(void);
void (*updateGamepadGUID)(char*); void (*updateGamepadGUID)(char*);
// monitor // monitor
@ -705,7 +707,7 @@ struct _GLFWplatform
GLFWbool (*getGammaRamp)(_GLFWmonitor*,GLFWgammaramp*); GLFWbool (*getGammaRamp)(_GLFWmonitor*,GLFWgammaramp*);
void (*setGammaRamp)(_GLFWmonitor*,const GLFWgammaramp*); void (*setGammaRamp)(_GLFWmonitor*,const GLFWgammaramp*);
// window // window
int (*createWindow)(_GLFWwindow*,const _GLFWwndconfig*,const _GLFWctxconfig*,const _GLFWfbconfig*); GLFWbool (*createWindow)(_GLFWwindow*,const _GLFWwndconfig*,const _GLFWctxconfig*,const _GLFWfbconfig*);
void (*destroyWindow)(_GLFWwindow*); void (*destroyWindow)(_GLFWwindow*);
void (*setWindowTitle)(_GLFWwindow*,const char*); void (*setWindowTitle)(_GLFWwindow*,const char*);
void (*setWindowIcon)(_GLFWwindow*,int,const GLFWimage*); void (*setWindowIcon)(_GLFWwindow*,int,const GLFWimage*);
@ -726,12 +728,12 @@ struct _GLFWplatform
void (*requestWindowAttention)(_GLFWwindow*); void (*requestWindowAttention)(_GLFWwindow*);
void (*focusWindow)(_GLFWwindow*); void (*focusWindow)(_GLFWwindow*);
void (*setWindowMonitor)(_GLFWwindow*,_GLFWmonitor*,int,int,int,int,int); void (*setWindowMonitor)(_GLFWwindow*,_GLFWmonitor*,int,int,int,int,int);
int (*windowFocused)(_GLFWwindow*); GLFWbool (*windowFocused)(_GLFWwindow*);
int (*windowIconified)(_GLFWwindow*); GLFWbool (*windowIconified)(_GLFWwindow*);
int (*windowVisible)(_GLFWwindow*); GLFWbool (*windowVisible)(_GLFWwindow*);
int (*windowMaximized)(_GLFWwindow*); GLFWbool (*windowMaximized)(_GLFWwindow*);
int (*windowHovered)(_GLFWwindow*); GLFWbool (*windowHovered)(_GLFWwindow*);
int (*framebufferTransparent)(_GLFWwindow*); GLFWbool (*framebufferTransparent)(_GLFWwindow*);
float (*getWindowOpacity)(_GLFWwindow*); float (*getWindowOpacity)(_GLFWwindow*);
void (*setWindowResizable)(_GLFWwindow*,GLFWbool); void (*setWindowResizable)(_GLFWwindow*,GLFWbool);
void (*setWindowDecorated)(_GLFWwindow*,GLFWbool); void (*setWindowDecorated)(_GLFWwindow*,GLFWbool);
@ -752,7 +754,7 @@ struct _GLFWplatform
EGLNativeWindowType (*getEGLNativeWindow)(_GLFWwindow*); EGLNativeWindowType (*getEGLNativeWindow)(_GLFWwindow*);
// vulkan // vulkan
void (*getRequiredInstanceExtensions)(char**); void (*getRequiredInstanceExtensions)(char**);
int (*getPhysicalDevicePresentationSupport)(VkInstance,VkPhysicalDevice,uint32_t); GLFWbool (*getPhysicalDevicePresentationSupport)(VkInstance,VkPhysicalDevice,uint32_t);
VkResult (*createWindowSurface)(VkInstance,_GLFWwindow*,const VkAllocationCallbacks*,VkSurfaceKHR*); VkResult (*createWindowSurface)(VkInstance,_GLFWwindow*,const VkAllocationCallbacks*,VkSurfaceKHR*);
}; };
@ -1062,8 +1064,11 @@ void _glfwTerminateVulkan(void);
const char* _glfwGetVulkanResultString(VkResult result); const char* _glfwGetVulkanResultString(VkResult result);
size_t _glfwEncodeUTF8(char* s, uint32_t codepoint); size_t _glfwEncodeUTF8(char* s, uint32_t codepoint);
char** _glfwParseUriList(char* text, int* count);
char* _glfw_strdup(const char* source); char* _glfw_strdup(const char* source);
int _glfw_min(int a, int b);
int _glfw_max(int a, int b);
float _glfw_fminf(float a, float b); float _glfw_fminf(float a, float b);
float _glfw_fmaxf(float a, float b); float _glfw_fmaxf(float a, float b);

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(GLFW_BUILD_LINUX_JOYSTICK)
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/inotify.h> #include <sys/inotify.h>
@ -128,7 +128,7 @@ static GLFWbool openJoystickDevice(const char* path)
{ {
for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{ {
if (!_glfw.joysticks[jid].present) if (!_glfw.joysticks[jid].connected)
continue; continue;
if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0) if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0)
return GLFW_FALSE; return GLFW_FALSE;
@ -157,7 +157,7 @@ static GLFWbool openJoystickDevice(const char* path)
} }
// Ensure this device supports the events expected of a joystick // Ensure this device supports the events expected of a joystick
if (!isBitSet(EV_KEY, evBits) || !isBitSet(EV_ABS, evBits)) if (!isBitSet(EV_ABS, evBits))
{ {
close(linjs.fd); close(linjs.fd);
return GLFW_FALSE; return GLFW_FALSE;
@ -245,9 +245,9 @@ static GLFWbool openJoystickDevice(const char* path)
// //
static void closeJoystick(_GLFWjoystick* js) static void closeJoystick(_GLFWjoystick* js)
{ {
_glfwInputJoystick(js, GLFW_DISCONNECTED);
close(js->linjs.fd); close(js->linjs.fd);
_glfwFreeJoystick(js); _glfwFreeJoystick(js);
_glfwInputJoystick(js, GLFW_DISCONNECTED);
} }
// Lexically compare joysticks by name; used by qsort // Lexically compare joysticks by name; used by qsort
@ -324,7 +324,8 @@ GLFWbool _glfwInitJoysticksLinux(void)
// Continue without device connection notifications if inotify fails // Continue without device connection notifications if inotify fails
if (regcomp(&_glfw.linjs.regex, "^event[0-9]\\+$", 0) != 0) _glfw.linjs.regexCompiled = (regcomp(&_glfw.linjs.regex, "^event[0-9]\\+$", 0) == 0);
if (!_glfw.linjs.regexCompiled)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to compile regex"); _glfwInputError(GLFW_PLATFORM_ERROR, "Linux: Failed to compile regex");
return GLFW_FALSE; return GLFW_FALSE;
@ -366,7 +367,7 @@ void _glfwTerminateJoysticksLinux(void)
for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{ {
_GLFWjoystick* js = _glfw.joysticks + jid; _GLFWjoystick* js = _glfw.joysticks + jid;
if (js->present) if (js->connected)
closeJoystick(js); closeJoystick(js);
} }
@ -376,11 +377,13 @@ void _glfwTerminateJoysticksLinux(void)
inotify_rm_watch(_glfw.linjs.inotify, _glfw.linjs.watch); inotify_rm_watch(_glfw.linjs.inotify, _glfw.linjs.watch);
close(_glfw.linjs.inotify); close(_glfw.linjs.inotify);
regfree(&_glfw.linjs.regex);
} }
if (_glfw.linjs.regexCompiled)
regfree(&_glfw.linjs.regex);
} }
int _glfwPollJoystickLinux(_GLFWjoystick* js, int mode) GLFWbool _glfwPollJoystickLinux(_GLFWjoystick* js, int mode)
{ {
// Read all queued events (non-blocking) // Read all queued events (non-blocking)
for (;;) for (;;)
@ -417,7 +420,7 @@ int _glfwPollJoystickLinux(_GLFWjoystick* js, int mode)
handleAbsEvent(js, e.code, e.value); handleAbsEvent(js, e.code, e.value);
} }
return js->present; return js->connected;
} }
const char* _glfwGetMappingNameLinux(void) const char* _glfwGetMappingNameLinux(void)
@ -429,3 +432,5 @@ void _glfwUpdateGamepadGUIDLinux(char* guid)
{ {
} }
#endif // GLFW_BUILD_LINUX_JOYSTICK

View File

@ -31,8 +31,6 @@
#define GLFW_LINUX_JOYSTICK_STATE _GLFWjoystickLinux linjs; #define GLFW_LINUX_JOYSTICK_STATE _GLFWjoystickLinux linjs;
#define GLFW_LINUX_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs; #define GLFW_LINUX_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs;
#define GLFW_BUILD_LINUX_MAPPINGS
// Linux-specific joystick data // Linux-specific joystick data
// //
typedef struct _GLFWjoystickLinux typedef struct _GLFWjoystickLinux
@ -52,6 +50,7 @@ typedef struct _GLFWlibraryLinux
int inotify; int inotify;
int watch; int watch;
regex_t regex; regex_t regex;
GLFWbool regexCompiled;
GLFWbool dropped; GLFWbool dropped;
} _GLFWlibraryLinux; } _GLFWlibraryLinux;
@ -59,7 +58,7 @@ void _glfwDetectJoystickConnectionLinux(void);
GLFWbool _glfwInitJoysticksLinux(void); GLFWbool _glfwInitJoysticksLinux(void);
void _glfwTerminateJoysticksLinux(void); void _glfwTerminateJoysticksLinux(void);
int _glfwPollJoystickLinux(_GLFWjoystick* js, int mode); GLFWbool _glfwPollJoystickLinux(_GLFWjoystick* js, int mode);
const char* _glfwGetMappingNameLinux(void); const char* _glfwGetMappingNameLinux(void);
void _glfwUpdateGamepadGUIDLinux(char* guid); void _glfwUpdateGamepadGUIDLinux(char* guid);

View File

@ -60,7 +60,7 @@
const char* _glfwDefaultMappings[] = const char* _glfwDefaultMappings[] =
{ {
#if defined(GLFW_BUILD_WIN32_MAPPINGS) #if defined(_GLFW_WIN32)
"03000000fa2d00000100000000000000,3DRUDDER,leftx:a0,lefty:a1,rightx:a5,righty:a2,platform:Windows,", "03000000fa2d00000100000000000000,3DRUDDER,leftx:a0,lefty:a1,rightx:a5,righty:a2,platform:Windows,",
"03000000c82d00002038000000000000,8bitdo,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,platform:Windows,", "03000000c82d00002038000000000000,8bitdo,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b2,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,platform:Windows,",
"03000000c82d00000951000000000000,8BitDo Dogbone Modkit,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,start:b11,platform:Windows,", "03000000c82d00000951000000000000,8BitDo Dogbone Modkit,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,start:b11,platform:Windows,",
@ -426,9 +426,9 @@ const char* _glfwDefaultMappings[] =
"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,", "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,",
"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,", "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,",
"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,", "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,",
#endif // GLFW_BUILD_WIN32_MAPPINGS #endif // _GLFW_WIN32
#if defined(GLFW_BUILD_COCOA_MAPPINGS) #if defined(_GLFW_COCOA)
"030000008f0e00000300000009010000,2In1 USB Joystick,a:b2,b:b1,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:b3,y:b0,platform:Mac OS X,", "030000008f0e00000300000009010000,2In1 USB Joystick,a:b2,b:b1,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:b3,y:b0,platform:Mac OS X,",
"03000000c82d00000090000001000000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Mac OS X,", "03000000c82d00000090000001000000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Mac OS X,",
"03000000c82d00001038000000010000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Mac OS X,", "03000000c82d00001038000000010000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Mac OS X,",
@ -598,9 +598,9 @@ const char* _glfwDefaultMappings[] =
"03000000172700004431000029010000,XiaoMi Game Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b15,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a6,rightx:a2,righty:a5,start:b11,x:b3,y:b4,platform:Mac OS X,", "03000000172700004431000029010000,XiaoMi Game Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b15,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a6,rightx:a2,righty:a5,start:b11,x:b3,y:b4,platform:Mac OS X,",
"03000000120c0000100e000000010000,ZEROPLUS P4 Gamepad,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:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X,", "03000000120c0000100e000000010000,ZEROPLUS P4 Gamepad,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:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X,",
"03000000120c0000101e000000010000,ZEROPLUS P4 Wired Gamepad,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:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X,", "03000000120c0000101e000000010000,ZEROPLUS P4 Wired Gamepad,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:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Mac OS X,",
#endif // GLFW_BUILD_COCOA_MAPPINGS #endif // _GLFW_COCOA
#if defined(GLFW_BUILD_LINUX_MAPPINGS) #if defined(GLFW_BUILD_LINUX_JOYSTICK)
"03000000c82d00000090000011010000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Linux,", "03000000c82d00000090000011010000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Linux,",
"05000000c82d00001038000000010000,8Bitdo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Linux,", "05000000c82d00001038000000010000,8Bitdo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Linux,",
"05000000c82d00005106000000010000,8BitDo M30,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b8,lefttrigger:b9,leftx:a0,lefty:a1,rightshoulder:b6,righttrigger:b7,start:b11,x:b3,y:b4,platform:Linux,", "05000000c82d00005106000000010000,8BitDo M30,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b8,lefttrigger:b9,leftx:a0,lefty:a1,rightshoulder:b6,righttrigger:b7,start:b11,x:b3,y:b4,platform:Linux,",
@ -996,6 +996,6 @@ const char* _glfwDefaultMappings[] =
"03000000c0160000e105000001010000,Xin-Mo Xin-Mo Dual Arcade,a:b4,b:b3,back:b6,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b9,leftshoulder:b2,leftx:a0,lefty:a1,rightshoulder:b5,start:b7,x:b1,y:b0,platform:Linux,", "03000000c0160000e105000001010000,Xin-Mo Xin-Mo Dual Arcade,a:b4,b:b3,back:b6,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b9,leftshoulder:b2,leftx:a0,lefty:a1,rightshoulder:b5,start:b7,x:b1,y:b0,platform:Linux,",
"03000000120c0000100e000011010000,ZEROPLUS P4 Gamepad,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:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,", "03000000120c0000100e000011010000,ZEROPLUS P4 Gamepad,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:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,",
"03000000120c0000101e000011010000,ZEROPLUS P4 Wired Gamepad,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:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,", "03000000120c0000101e000011010000,ZEROPLUS P4 Wired Gamepad,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:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,",
#endif // GLFW_BUILD_LINUX_MAPPINGS #endif // GLFW_BUILD_LINUX_JOYSTICK
}; };

View File

@ -60,7 +60,7 @@
const char* _glfwDefaultMappings[] = const char* _glfwDefaultMappings[] =
{ {
#if defined(GLFW_BUILD_WIN32_MAPPINGS) #if defined(_GLFW_WIN32)
@GLFW_WIN32_MAPPINGS@ @GLFW_WIN32_MAPPINGS@
"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,", "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,",
"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,", "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,",
@ -69,14 +69,14 @@ const char* _glfwDefaultMappings[] =
"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,", "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,",
"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,", "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,",
"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,", "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,",
#endif // GLFW_BUILD_WIN32_MAPPINGS #endif // _GLFW_WIN32
#if defined(GLFW_BUILD_COCOA_MAPPINGS) #if defined(_GLFW_COCOA)
@GLFW_COCOA_MAPPINGS@ @GLFW_COCOA_MAPPINGS@
#endif // GLFW_BUILD_COCOA_MAPPINGS #endif // _GLFW_COCOA
#if defined(GLFW_BUILD_LINUX_MAPPINGS) #if defined(GLFW_BUILD_LINUX_JOYSTICK)
@GLFW_LINUX_MAPPINGS@ @GLFW_LINUX_MAPPINGS@
#endif // GLFW_BUILD_LINUX_MAPPINGS #endif // GLFW_BUILD_LINUX_JOYSTICK
}; };

View File

@ -24,8 +24,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
@ -96,6 +94,10 @@ static GLFWbool refreshVideoModes(_GLFWmonitor* monitor)
// //
void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement) void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement)
{ {
assert(monitor != NULL);
assert(action == GLFW_CONNECTED || action == GLFW_DISCONNECTED);
assert(placement == _GLFW_INSERT_FIRST || placement == _GLFW_INSERT_LAST);
if (action == GLFW_CONNECTED) if (action == GLFW_CONNECTED)
{ {
_glfw.monitorCount++; _glfw.monitorCount++;
@ -155,6 +157,7 @@ void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement)
// //
void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window) void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window)
{ {
assert(monitor != NULL);
monitor->window = window; monitor->window = window;
} }
@ -522,6 +525,8 @@ GLFWAPI void glfwSetGammaRamp(GLFWmonitor* handle, const GLFWgammaramp* ramp)
assert(ramp->green != NULL); assert(ramp->green != NULL);
assert(ramp->blue != NULL); assert(ramp->blue != NULL);
_GLFW_REQUIRE_INIT();
if (ramp->size <= 0) if (ramp->size <= 0)
{ {
_glfwInputError(GLFW_INVALID_VALUE, _glfwInputError(GLFW_INVALID_VALUE,
@ -530,8 +535,6 @@ GLFWAPI void glfwSetGammaRamp(GLFWmonitor* handle, const GLFWgammaramp* ramp)
return; return;
} }
_GLFW_REQUIRE_INIT();
if (!monitor->originalRamp.size) if (!monitor->originalRamp.size)
{ {
if (!_glfw.platform.getGammaRamp(monitor, &monitor->originalRamp)) if (!_glfw.platform.getGammaRamp(monitor, &monitor->originalRamp))

View File

@ -28,6 +28,8 @@
#include "internal.h" #include "internal.h"
#if defined(_GLFW_COCOA)
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <math.h>
@ -81,11 +83,10 @@ static void swapIntervalNSGL(int interval)
@autoreleasepool { @autoreleasepool {
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
if (window) assert(window != NULL);
{
[window->context.nsgl.object setValues:&interval [window->context.nsgl.object setValues:&interval
forParameter:NSOpenGLContextParameterSwapInterval]; forParameter:NSOpenGLContextParameterSwapInterval];
}
} // autoreleasepool } // autoreleasepool
} }
@ -188,45 +189,45 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
// No-error contexts (GL_KHR_no_error) are not yet supported by macOS but // No-error contexts (GL_KHR_no_error) are not yet supported by macOS but
// are not a hard constraint, so ignore and continue // are not a hard constraint, so ignore and continue
#define addAttrib(a) \ #define ADD_ATTRIB(a) \
{ \ { \
assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \ assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \
attribs[index++] = a; \ attribs[index++] = a; \
} }
#define setAttrib(a, v) { addAttrib(a); addAttrib(v); } #define SET_ATTRIB(a, v) { ADD_ATTRIB(a); ADD_ATTRIB(v); }
NSOpenGLPixelFormatAttribute attribs[40]; NSOpenGLPixelFormatAttribute attribs[40];
int index = 0; int index = 0;
addAttrib(NSOpenGLPFAAccelerated); ADD_ATTRIB(NSOpenGLPFAAccelerated);
addAttrib(NSOpenGLPFAClosestPolicy); ADD_ATTRIB(NSOpenGLPFAClosestPolicy);
if (ctxconfig->nsgl.offline) if (ctxconfig->nsgl.offline)
{ {
addAttrib(NSOpenGLPFAAllowOfflineRenderers); ADD_ATTRIB(NSOpenGLPFAAllowOfflineRenderers);
// NOTE: This replaces the NSSupportsAutomaticGraphicsSwitching key in // NOTE: This replaces the NSSupportsAutomaticGraphicsSwitching key in
// Info.plist for unbundled applications // Info.plist for unbundled applications
// HACK: This assumes that NSOpenGLPixelFormat will remain // HACK: This assumes that NSOpenGLPixelFormat will remain
// a straightforward wrapper of its CGL counterpart // a straightforward wrapper of its CGL counterpart
addAttrib(kCGLPFASupportsAutomaticGraphicsSwitching); ADD_ATTRIB(kCGLPFASupportsAutomaticGraphicsSwitching);
} }
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
if (ctxconfig->major >= 4) if (ctxconfig->major >= 4)
{ {
setAttrib(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core); SET_ATTRIB(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core);
} }
else else
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ #endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
if (ctxconfig->major >= 3) if (ctxconfig->major >= 3)
{ {
setAttrib(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core); SET_ATTRIB(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
} }
if (ctxconfig->major <= 2) if (ctxconfig->major <= 2)
{ {
if (fbconfig->auxBuffers != GLFW_DONT_CARE) if (fbconfig->auxBuffers != GLFW_DONT_CARE)
setAttrib(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers); SET_ATTRIB(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers);
if (fbconfig->accumRedBits != GLFW_DONT_CARE && if (fbconfig->accumRedBits != GLFW_DONT_CARE &&
fbconfig->accumGreenBits != GLFW_DONT_CARE && fbconfig->accumGreenBits != GLFW_DONT_CARE &&
@ -238,7 +239,7 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
fbconfig->accumBlueBits + fbconfig->accumBlueBits +
fbconfig->accumAlphaBits; fbconfig->accumAlphaBits;
setAttrib(NSOpenGLPFAAccumSize, accumBits); SET_ATTRIB(NSOpenGLPFAAccumSize, accumBits);
} }
} }
@ -256,17 +257,17 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
else if (colorBits < 15) else if (colorBits < 15)
colorBits = 15; colorBits = 15;
setAttrib(NSOpenGLPFAColorSize, colorBits); SET_ATTRIB(NSOpenGLPFAColorSize, colorBits);
} }
if (fbconfig->alphaBits != GLFW_DONT_CARE) if (fbconfig->alphaBits != GLFW_DONT_CARE)
setAttrib(NSOpenGLPFAAlphaSize, fbconfig->alphaBits); SET_ATTRIB(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
if (fbconfig->depthBits != GLFW_DONT_CARE) if (fbconfig->depthBits != GLFW_DONT_CARE)
setAttrib(NSOpenGLPFADepthSize, fbconfig->depthBits); SET_ATTRIB(NSOpenGLPFADepthSize, fbconfig->depthBits);
if (fbconfig->stencilBits != GLFW_DONT_CARE) if (fbconfig->stencilBits != GLFW_DONT_CARE)
setAttrib(NSOpenGLPFAStencilSize, fbconfig->stencilBits); SET_ATTRIB(NSOpenGLPFAStencilSize, fbconfig->stencilBits);
if (fbconfig->stereo) if (fbconfig->stereo)
{ {
@ -275,33 +276,33 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
"NSGL: Stereo rendering is deprecated"); "NSGL: Stereo rendering is deprecated");
return GLFW_FALSE; return GLFW_FALSE;
#else #else
addAttrib(NSOpenGLPFAStereo); ADD_ATTRIB(NSOpenGLPFAStereo);
#endif #endif
} }
if (fbconfig->doublebuffer) if (fbconfig->doublebuffer)
addAttrib(NSOpenGLPFADoubleBuffer); ADD_ATTRIB(NSOpenGLPFADoubleBuffer);
if (fbconfig->samples != GLFW_DONT_CARE) if (fbconfig->samples != GLFW_DONT_CARE)
{ {
if (fbconfig->samples == 0) if (fbconfig->samples == 0)
{ {
setAttrib(NSOpenGLPFASampleBuffers, 0); SET_ATTRIB(NSOpenGLPFASampleBuffers, 0);
} }
else else
{ {
setAttrib(NSOpenGLPFASampleBuffers, 1); SET_ATTRIB(NSOpenGLPFASampleBuffers, 1);
setAttrib(NSOpenGLPFASamples, fbconfig->samples); SET_ATTRIB(NSOpenGLPFASamples, fbconfig->samples);
} }
} }
// NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
// framebuffer, so there's no need (and no way) to request it // framebuffer, so there's no need (and no way) to request it
addAttrib(0); ADD_ATTRIB(0);
#undef addAttrib #undef ADD_ATTRIB
#undef setAttrib #undef SET_ATTRIB
window->context.nsgl.pixelFormat = window->context.nsgl.pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
@ -374,3 +375,5 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle)
return window->context.nsgl.object; return window->context.nsgl.object;
} }
#endif // _GLFW_COCOA

View File

@ -24,12 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -121,6 +120,138 @@ GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform)
int _glfwInitNull(void) int _glfwInitNull(void)
{ {
int scancode;
memset(_glfw.null.keycodes, -1, sizeof(_glfw.null.keycodes));
memset(_glfw.null.scancodes, -1, sizeof(_glfw.null.scancodes));
_glfw.null.keycodes[GLFW_NULL_SC_SPACE] = GLFW_KEY_SPACE;
_glfw.null.keycodes[GLFW_NULL_SC_APOSTROPHE] = GLFW_KEY_APOSTROPHE;
_glfw.null.keycodes[GLFW_NULL_SC_COMMA] = GLFW_KEY_COMMA;
_glfw.null.keycodes[GLFW_NULL_SC_MINUS] = GLFW_KEY_MINUS;
_glfw.null.keycodes[GLFW_NULL_SC_PERIOD] = GLFW_KEY_PERIOD;
_glfw.null.keycodes[GLFW_NULL_SC_SLASH] = GLFW_KEY_SLASH;
_glfw.null.keycodes[GLFW_NULL_SC_0] = GLFW_KEY_0;
_glfw.null.keycodes[GLFW_NULL_SC_1] = GLFW_KEY_1;
_glfw.null.keycodes[GLFW_NULL_SC_2] = GLFW_KEY_2;
_glfw.null.keycodes[GLFW_NULL_SC_3] = GLFW_KEY_3;
_glfw.null.keycodes[GLFW_NULL_SC_4] = GLFW_KEY_4;
_glfw.null.keycodes[GLFW_NULL_SC_5] = GLFW_KEY_5;
_glfw.null.keycodes[GLFW_NULL_SC_6] = GLFW_KEY_6;
_glfw.null.keycodes[GLFW_NULL_SC_7] = GLFW_KEY_7;
_glfw.null.keycodes[GLFW_NULL_SC_8] = GLFW_KEY_8;
_glfw.null.keycodes[GLFW_NULL_SC_9] = GLFW_KEY_9;
_glfw.null.keycodes[GLFW_NULL_SC_SEMICOLON] = GLFW_KEY_SEMICOLON;
_glfw.null.keycodes[GLFW_NULL_SC_EQUAL] = GLFW_KEY_EQUAL;
_glfw.null.keycodes[GLFW_NULL_SC_A] = GLFW_KEY_A;
_glfw.null.keycodes[GLFW_NULL_SC_B] = GLFW_KEY_B;
_glfw.null.keycodes[GLFW_NULL_SC_C] = GLFW_KEY_C;
_glfw.null.keycodes[GLFW_NULL_SC_D] = GLFW_KEY_D;
_glfw.null.keycodes[GLFW_NULL_SC_E] = GLFW_KEY_E;
_glfw.null.keycodes[GLFW_NULL_SC_F] = GLFW_KEY_F;
_glfw.null.keycodes[GLFW_NULL_SC_G] = GLFW_KEY_G;
_glfw.null.keycodes[GLFW_NULL_SC_H] = GLFW_KEY_H;
_glfw.null.keycodes[GLFW_NULL_SC_I] = GLFW_KEY_I;
_glfw.null.keycodes[GLFW_NULL_SC_J] = GLFW_KEY_J;
_glfw.null.keycodes[GLFW_NULL_SC_K] = GLFW_KEY_K;
_glfw.null.keycodes[GLFW_NULL_SC_L] = GLFW_KEY_L;
_glfw.null.keycodes[GLFW_NULL_SC_M] = GLFW_KEY_M;
_glfw.null.keycodes[GLFW_NULL_SC_N] = GLFW_KEY_N;
_glfw.null.keycodes[GLFW_NULL_SC_O] = GLFW_KEY_O;
_glfw.null.keycodes[GLFW_NULL_SC_P] = GLFW_KEY_P;
_glfw.null.keycodes[GLFW_NULL_SC_Q] = GLFW_KEY_Q;
_glfw.null.keycodes[GLFW_NULL_SC_R] = GLFW_KEY_R;
_glfw.null.keycodes[GLFW_NULL_SC_S] = GLFW_KEY_S;
_glfw.null.keycodes[GLFW_NULL_SC_T] = GLFW_KEY_T;
_glfw.null.keycodes[GLFW_NULL_SC_U] = GLFW_KEY_U;
_glfw.null.keycodes[GLFW_NULL_SC_V] = GLFW_KEY_V;
_glfw.null.keycodes[GLFW_NULL_SC_W] = GLFW_KEY_W;
_glfw.null.keycodes[GLFW_NULL_SC_X] = GLFW_KEY_X;
_glfw.null.keycodes[GLFW_NULL_SC_Y] = GLFW_KEY_Y;
_glfw.null.keycodes[GLFW_NULL_SC_Z] = GLFW_KEY_Z;
_glfw.null.keycodes[GLFW_NULL_SC_LEFT_BRACKET] = GLFW_KEY_LEFT_BRACKET;
_glfw.null.keycodes[GLFW_NULL_SC_BACKSLASH] = GLFW_KEY_BACKSLASH;
_glfw.null.keycodes[GLFW_NULL_SC_RIGHT_BRACKET] = GLFW_KEY_RIGHT_BRACKET;
_glfw.null.keycodes[GLFW_NULL_SC_GRAVE_ACCENT] = GLFW_KEY_GRAVE_ACCENT;
_glfw.null.keycodes[GLFW_NULL_SC_WORLD_1] = GLFW_KEY_WORLD_1;
_glfw.null.keycodes[GLFW_NULL_SC_WORLD_2] = GLFW_KEY_WORLD_2;
_glfw.null.keycodes[GLFW_NULL_SC_ESCAPE] = GLFW_KEY_ESCAPE;
_glfw.null.keycodes[GLFW_NULL_SC_ENTER] = GLFW_KEY_ENTER;
_glfw.null.keycodes[GLFW_NULL_SC_TAB] = GLFW_KEY_TAB;
_glfw.null.keycodes[GLFW_NULL_SC_BACKSPACE] = GLFW_KEY_BACKSPACE;
_glfw.null.keycodes[GLFW_NULL_SC_INSERT] = GLFW_KEY_INSERT;
_glfw.null.keycodes[GLFW_NULL_SC_DELETE] = GLFW_KEY_DELETE;
_glfw.null.keycodes[GLFW_NULL_SC_RIGHT] = GLFW_KEY_RIGHT;
_glfw.null.keycodes[GLFW_NULL_SC_LEFT] = GLFW_KEY_LEFT;
_glfw.null.keycodes[GLFW_NULL_SC_DOWN] = GLFW_KEY_DOWN;
_glfw.null.keycodes[GLFW_NULL_SC_UP] = GLFW_KEY_UP;
_glfw.null.keycodes[GLFW_NULL_SC_PAGE_UP] = GLFW_KEY_PAGE_UP;
_glfw.null.keycodes[GLFW_NULL_SC_PAGE_DOWN] = GLFW_KEY_PAGE_DOWN;
_glfw.null.keycodes[GLFW_NULL_SC_HOME] = GLFW_KEY_HOME;
_glfw.null.keycodes[GLFW_NULL_SC_END] = GLFW_KEY_END;
_glfw.null.keycodes[GLFW_NULL_SC_CAPS_LOCK] = GLFW_KEY_CAPS_LOCK;
_glfw.null.keycodes[GLFW_NULL_SC_SCROLL_LOCK] = GLFW_KEY_SCROLL_LOCK;
_glfw.null.keycodes[GLFW_NULL_SC_NUM_LOCK] = GLFW_KEY_NUM_LOCK;
_glfw.null.keycodes[GLFW_NULL_SC_PRINT_SCREEN] = GLFW_KEY_PRINT_SCREEN;
_glfw.null.keycodes[GLFW_NULL_SC_PAUSE] = GLFW_KEY_PAUSE;
_glfw.null.keycodes[GLFW_NULL_SC_F1] = GLFW_KEY_F1;
_glfw.null.keycodes[GLFW_NULL_SC_F2] = GLFW_KEY_F2;
_glfw.null.keycodes[GLFW_NULL_SC_F3] = GLFW_KEY_F3;
_glfw.null.keycodes[GLFW_NULL_SC_F4] = GLFW_KEY_F4;
_glfw.null.keycodes[GLFW_NULL_SC_F5] = GLFW_KEY_F5;
_glfw.null.keycodes[GLFW_NULL_SC_F6] = GLFW_KEY_F6;
_glfw.null.keycodes[GLFW_NULL_SC_F7] = GLFW_KEY_F7;
_glfw.null.keycodes[GLFW_NULL_SC_F8] = GLFW_KEY_F8;
_glfw.null.keycodes[GLFW_NULL_SC_F9] = GLFW_KEY_F9;
_glfw.null.keycodes[GLFW_NULL_SC_F10] = GLFW_KEY_F10;
_glfw.null.keycodes[GLFW_NULL_SC_F11] = GLFW_KEY_F11;
_glfw.null.keycodes[GLFW_NULL_SC_F12] = GLFW_KEY_F12;
_glfw.null.keycodes[GLFW_NULL_SC_F13] = GLFW_KEY_F13;
_glfw.null.keycodes[GLFW_NULL_SC_F14] = GLFW_KEY_F14;
_glfw.null.keycodes[GLFW_NULL_SC_F15] = GLFW_KEY_F15;
_glfw.null.keycodes[GLFW_NULL_SC_F16] = GLFW_KEY_F16;
_glfw.null.keycodes[GLFW_NULL_SC_F17] = GLFW_KEY_F17;
_glfw.null.keycodes[GLFW_NULL_SC_F18] = GLFW_KEY_F18;
_glfw.null.keycodes[GLFW_NULL_SC_F19] = GLFW_KEY_F19;
_glfw.null.keycodes[GLFW_NULL_SC_F20] = GLFW_KEY_F20;
_glfw.null.keycodes[GLFW_NULL_SC_F21] = GLFW_KEY_F21;
_glfw.null.keycodes[GLFW_NULL_SC_F22] = GLFW_KEY_F22;
_glfw.null.keycodes[GLFW_NULL_SC_F23] = GLFW_KEY_F23;
_glfw.null.keycodes[GLFW_NULL_SC_F24] = GLFW_KEY_F24;
_glfw.null.keycodes[GLFW_NULL_SC_F25] = GLFW_KEY_F25;
_glfw.null.keycodes[GLFW_NULL_SC_KP_0] = GLFW_KEY_KP_0;
_glfw.null.keycodes[GLFW_NULL_SC_KP_1] = GLFW_KEY_KP_1;
_glfw.null.keycodes[GLFW_NULL_SC_KP_2] = GLFW_KEY_KP_2;
_glfw.null.keycodes[GLFW_NULL_SC_KP_3] = GLFW_KEY_KP_3;
_glfw.null.keycodes[GLFW_NULL_SC_KP_4] = GLFW_KEY_KP_4;
_glfw.null.keycodes[GLFW_NULL_SC_KP_5] = GLFW_KEY_KP_5;
_glfw.null.keycodes[GLFW_NULL_SC_KP_6] = GLFW_KEY_KP_6;
_glfw.null.keycodes[GLFW_NULL_SC_KP_7] = GLFW_KEY_KP_7;
_glfw.null.keycodes[GLFW_NULL_SC_KP_8] = GLFW_KEY_KP_8;
_glfw.null.keycodes[GLFW_NULL_SC_KP_9] = GLFW_KEY_KP_9;
_glfw.null.keycodes[GLFW_NULL_SC_KP_DECIMAL] = GLFW_KEY_KP_DECIMAL;
_glfw.null.keycodes[GLFW_NULL_SC_KP_DIVIDE] = GLFW_KEY_KP_DIVIDE;
_glfw.null.keycodes[GLFW_NULL_SC_KP_MULTIPLY] = GLFW_KEY_KP_MULTIPLY;
_glfw.null.keycodes[GLFW_NULL_SC_KP_SUBTRACT] = GLFW_KEY_KP_SUBTRACT;
_glfw.null.keycodes[GLFW_NULL_SC_KP_ADD] = GLFW_KEY_KP_ADD;
_glfw.null.keycodes[GLFW_NULL_SC_KP_ENTER] = GLFW_KEY_KP_ENTER;
_glfw.null.keycodes[GLFW_NULL_SC_KP_EQUAL] = GLFW_KEY_KP_EQUAL;
_glfw.null.keycodes[GLFW_NULL_SC_LEFT_SHIFT] = GLFW_KEY_LEFT_SHIFT;
_glfw.null.keycodes[GLFW_NULL_SC_LEFT_CONTROL] = GLFW_KEY_LEFT_CONTROL;
_glfw.null.keycodes[GLFW_NULL_SC_LEFT_ALT] = GLFW_KEY_LEFT_ALT;
_glfw.null.keycodes[GLFW_NULL_SC_LEFT_SUPER] = GLFW_KEY_LEFT_SUPER;
_glfw.null.keycodes[GLFW_NULL_SC_RIGHT_SHIFT] = GLFW_KEY_RIGHT_SHIFT;
_glfw.null.keycodes[GLFW_NULL_SC_RIGHT_CONTROL] = GLFW_KEY_RIGHT_CONTROL;
_glfw.null.keycodes[GLFW_NULL_SC_RIGHT_ALT] = GLFW_KEY_RIGHT_ALT;
_glfw.null.keycodes[GLFW_NULL_SC_RIGHT_SUPER] = GLFW_KEY_RIGHT_SUPER;
_glfw.null.keycodes[GLFW_NULL_SC_MENU] = GLFW_KEY_MENU;
for (scancode = GLFW_NULL_SC_FIRST; scancode < GLFW_NULL_SC_LAST; scancode++)
{
if (_glfw.null.keycodes[scancode] > 0)
_glfw.null.scancodes[_glfw.null.keycodes[scancode]] = scancode;
}
_glfwPollMonitorsNull(); _glfwPollMonitorsNull();
return GLFW_TRUE; return GLFW_TRUE;
} }

View File

@ -23,8 +23,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
@ -42,7 +40,7 @@ void _glfwTerminateJoysticksNull(void)
{ {
} }
int _glfwPollJoystickNull(_GLFWjoystick* js, int mode) GLFWbool _glfwPollJoystickNull(_GLFWjoystick* js, int mode)
{ {
return GLFW_FALSE; return GLFW_FALSE;
} }

View File

@ -26,7 +26,7 @@
GLFWbool _glfwInitJoysticksNull(void); GLFWbool _glfwInitJoysticksNull(void);
void _glfwTerminateJoysticksNull(void); void _glfwTerminateJoysticksNull(void);
int _glfwPollJoystickNull(_GLFWjoystick* js, int mode); GLFWbool _glfwPollJoystickNull(_GLFWjoystick* js, int mode);
const char* _glfwGetMappingNameNull(void); const char* _glfwGetMappingNameNull(void);
void _glfwUpdateGamepadGUIDNull(char* guid); void _glfwUpdateGamepadGUIDNull(char* guid);

View File

@ -24,8 +24,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"

View File

@ -33,6 +33,128 @@
#define GLFW_NULL_CURSOR_STATE #define GLFW_NULL_CURSOR_STATE
#define GLFW_NULL_LIBRARY_CONTEXT_STATE #define GLFW_NULL_LIBRARY_CONTEXT_STATE
#define GLFW_NULL_SC_FIRST GLFW_NULL_SC_SPACE
#define GLFW_NULL_SC_SPACE 1
#define GLFW_NULL_SC_APOSTROPHE 2
#define GLFW_NULL_SC_COMMA 3
#define GLFW_NULL_SC_MINUS 4
#define GLFW_NULL_SC_PERIOD 5
#define GLFW_NULL_SC_SLASH 6
#define GLFW_NULL_SC_0 7
#define GLFW_NULL_SC_1 8
#define GLFW_NULL_SC_2 9
#define GLFW_NULL_SC_3 10
#define GLFW_NULL_SC_4 11
#define GLFW_NULL_SC_5 12
#define GLFW_NULL_SC_6 13
#define GLFW_NULL_SC_7 14
#define GLFW_NULL_SC_8 15
#define GLFW_NULL_SC_9 16
#define GLFW_NULL_SC_SEMICOLON 17
#define GLFW_NULL_SC_EQUAL 18
#define GLFW_NULL_SC_LEFT_BRACKET 19
#define GLFW_NULL_SC_BACKSLASH 20
#define GLFW_NULL_SC_RIGHT_BRACKET 21
#define GLFW_NULL_SC_GRAVE_ACCENT 22
#define GLFW_NULL_SC_WORLD_1 23
#define GLFW_NULL_SC_WORLD_2 24
#define GLFW_NULL_SC_ESCAPE 25
#define GLFW_NULL_SC_ENTER 26
#define GLFW_NULL_SC_TAB 27
#define GLFW_NULL_SC_BACKSPACE 28
#define GLFW_NULL_SC_INSERT 29
#define GLFW_NULL_SC_DELETE 30
#define GLFW_NULL_SC_RIGHT 31
#define GLFW_NULL_SC_LEFT 32
#define GLFW_NULL_SC_DOWN 33
#define GLFW_NULL_SC_UP 34
#define GLFW_NULL_SC_PAGE_UP 35
#define GLFW_NULL_SC_PAGE_DOWN 36
#define GLFW_NULL_SC_HOME 37
#define GLFW_NULL_SC_END 38
#define GLFW_NULL_SC_CAPS_LOCK 39
#define GLFW_NULL_SC_SCROLL_LOCK 40
#define GLFW_NULL_SC_NUM_LOCK 41
#define GLFW_NULL_SC_PRINT_SCREEN 42
#define GLFW_NULL_SC_PAUSE 43
#define GLFW_NULL_SC_A 44
#define GLFW_NULL_SC_B 45
#define GLFW_NULL_SC_C 46
#define GLFW_NULL_SC_D 47
#define GLFW_NULL_SC_E 48
#define GLFW_NULL_SC_F 49
#define GLFW_NULL_SC_G 50
#define GLFW_NULL_SC_H 51
#define GLFW_NULL_SC_I 52
#define GLFW_NULL_SC_J 53
#define GLFW_NULL_SC_K 54
#define GLFW_NULL_SC_L 55
#define GLFW_NULL_SC_M 56
#define GLFW_NULL_SC_N 57
#define GLFW_NULL_SC_O 58
#define GLFW_NULL_SC_P 59
#define GLFW_NULL_SC_Q 60
#define GLFW_NULL_SC_R 61
#define GLFW_NULL_SC_S 62
#define GLFW_NULL_SC_T 63
#define GLFW_NULL_SC_U 64
#define GLFW_NULL_SC_V 65
#define GLFW_NULL_SC_W 66
#define GLFW_NULL_SC_X 67
#define GLFW_NULL_SC_Y 68
#define GLFW_NULL_SC_Z 69
#define GLFW_NULL_SC_F1 70
#define GLFW_NULL_SC_F2 71
#define GLFW_NULL_SC_F3 72
#define GLFW_NULL_SC_F4 73
#define GLFW_NULL_SC_F5 74
#define GLFW_NULL_SC_F6 75
#define GLFW_NULL_SC_F7 76
#define GLFW_NULL_SC_F8 77
#define GLFW_NULL_SC_F9 78
#define GLFW_NULL_SC_F10 79
#define GLFW_NULL_SC_F11 80
#define GLFW_NULL_SC_F12 81
#define GLFW_NULL_SC_F13 82
#define GLFW_NULL_SC_F14 83
#define GLFW_NULL_SC_F15 84
#define GLFW_NULL_SC_F16 85
#define GLFW_NULL_SC_F17 86
#define GLFW_NULL_SC_F18 87
#define GLFW_NULL_SC_F19 88
#define GLFW_NULL_SC_F20 89
#define GLFW_NULL_SC_F21 90
#define GLFW_NULL_SC_F22 91
#define GLFW_NULL_SC_F23 92
#define GLFW_NULL_SC_F24 93
#define GLFW_NULL_SC_F25 94
#define GLFW_NULL_SC_KP_0 95
#define GLFW_NULL_SC_KP_1 96
#define GLFW_NULL_SC_KP_2 97
#define GLFW_NULL_SC_KP_3 98
#define GLFW_NULL_SC_KP_4 99
#define GLFW_NULL_SC_KP_5 100
#define GLFW_NULL_SC_KP_6 101
#define GLFW_NULL_SC_KP_7 102
#define GLFW_NULL_SC_KP_8 103
#define GLFW_NULL_SC_KP_9 104
#define GLFW_NULL_SC_KP_DECIMAL 105
#define GLFW_NULL_SC_KP_DIVIDE 106
#define GLFW_NULL_SC_KP_MULTIPLY 107
#define GLFW_NULL_SC_KP_SUBTRACT 108
#define GLFW_NULL_SC_KP_ADD 109
#define GLFW_NULL_SC_KP_ENTER 110
#define GLFW_NULL_SC_KP_EQUAL 111
#define GLFW_NULL_SC_LEFT_SHIFT 112
#define GLFW_NULL_SC_LEFT_CONTROL 113
#define GLFW_NULL_SC_LEFT_ALT 114
#define GLFW_NULL_SC_LEFT_SUPER 115
#define GLFW_NULL_SC_RIGHT_SHIFT 116
#define GLFW_NULL_SC_RIGHT_CONTROL 117
#define GLFW_NULL_SC_RIGHT_ALT 118
#define GLFW_NULL_SC_RIGHT_SUPER 119
#define GLFW_NULL_SC_MENU 120
#define GLFW_NULL_SC_LAST GLFW_NULL_SC_MENU
// Null-specific per-window data // Null-specific per-window data
// //
@ -69,6 +191,8 @@ typedef struct _GLFWlibraryNull
int ycursor; int ycursor;
char* clipboardString; char* clipboardString;
_GLFWwindow* focusedWindow; _GLFWwindow* focusedWindow;
uint16_t keycodes[GLFW_NULL_SC_LAST + 1];
uint8_t scancodes[GLFW_KEY_LAST + 1];
} _GLFWlibraryNull; } _GLFWlibraryNull;
void _glfwPollMonitorsNull(void); void _glfwPollMonitorsNull(void);
@ -86,7 +210,7 @@ void _glfwGetVideoModeNull(_GLFWmonitor* monitor, GLFWvidmode* mode);
GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp); GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp); void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
int _glfwCreateWindowNull(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); GLFWbool _glfwCreateWindowNull(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowNull(_GLFWwindow* window); void _glfwDestroyWindowNull(_GLFWwindow* window);
void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title); void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images); void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images);
@ -103,9 +227,9 @@ void _glfwGetWindowContentScaleNull(_GLFWwindow* window, float* xscale, float* y
void _glfwIconifyWindowNull(_GLFWwindow* window); void _glfwIconifyWindowNull(_GLFWwindow* window);
void _glfwRestoreWindowNull(_GLFWwindow* window); void _glfwRestoreWindowNull(_GLFWwindow* window);
void _glfwMaximizeWindowNull(_GLFWwindow* window); void _glfwMaximizeWindowNull(_GLFWwindow* window);
int _glfwWindowMaximizedNull(_GLFWwindow* window); GLFWbool _glfwWindowMaximizedNull(_GLFWwindow* window);
int _glfwWindowHoveredNull(_GLFWwindow* window); GLFWbool _glfwWindowHoveredNull(_GLFWwindow* window);
int _glfwFramebufferTransparentNull(_GLFWwindow* window); GLFWbool _glfwFramebufferTransparentNull(_GLFWwindow* window);
void _glfwSetWindowResizableNull(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowResizableNull(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowDecoratedNull(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowDecoratedNull(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowFloatingNull(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowFloatingNull(_GLFWwindow* window, GLFWbool enabled);
@ -116,12 +240,11 @@ void _glfwSetRawMouseMotionNull(_GLFWwindow *window, GLFWbool enabled);
GLFWbool _glfwRawMouseMotionSupportedNull(void); GLFWbool _glfwRawMouseMotionSupportedNull(void);
void _glfwShowWindowNull(_GLFWwindow* window); void _glfwShowWindowNull(_GLFWwindow* window);
void _glfwRequestWindowAttentionNull(_GLFWwindow* window); void _glfwRequestWindowAttentionNull(_GLFWwindow* window);
void _glfwRequestWindowAttentionNull(_GLFWwindow* window);
void _glfwHideWindowNull(_GLFWwindow* window); void _glfwHideWindowNull(_GLFWwindow* window);
void _glfwFocusWindowNull(_GLFWwindow* window); void _glfwFocusWindowNull(_GLFWwindow* window);
int _glfwWindowFocusedNull(_GLFWwindow* window); GLFWbool _glfwWindowFocusedNull(_GLFWwindow* window);
int _glfwWindowIconifiedNull(_GLFWwindow* window); GLFWbool _glfwWindowIconifiedNull(_GLFWwindow* window);
int _glfwWindowVisibleNull(_GLFWwindow* window); GLFWbool _glfwWindowVisibleNull(_GLFWwindow* window);
void _glfwPollEventsNull(void); void _glfwPollEventsNull(void);
void _glfwWaitEventsNull(void); void _glfwWaitEventsNull(void);
void _glfwWaitEventsTimeoutNull(double timeout); void _glfwWaitEventsTimeoutNull(double timeout);
@ -133,8 +256,8 @@ void _glfwSetWindowTitlebarNull(_GLFWwindow* window, GLFWbool enabled);
void _glfwGetCursorPosNull(_GLFWwindow* window, double* xpos, double* ypos); void _glfwGetCursorPosNull(_GLFWwindow* window, double* xpos, double* ypos);
void _glfwSetCursorPosNull(_GLFWwindow* window, double x, double y); void _glfwSetCursorPosNull(_GLFWwindow* window, double x, double y);
void _glfwSetCursorModeNull(_GLFWwindow* window, int mode); void _glfwSetCursorModeNull(_GLFWwindow* window, int mode);
int _glfwCreateCursorNull(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); GLFWbool _glfwCreateCursorNull(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot);
int _glfwCreateStandardCursorNull(_GLFWcursor* cursor, int shape); GLFWbool _glfwCreateStandardCursorNull(_GLFWcursor* cursor, int shape);
void _glfwDestroyCursorNull(_GLFWcursor* cursor); void _glfwDestroyCursorNull(_GLFWcursor* cursor);
void _glfwSetCursorNull(_GLFWwindow* window, _GLFWcursor* cursor); void _glfwSetCursorNull(_GLFWwindow* window, _GLFWcursor* cursor);
void _glfwSetClipboardStringNull(const char* string); void _glfwSetClipboardStringNull(const char* string);
@ -147,7 +270,7 @@ EGLNativeDisplayType _glfwGetEGLNativeDisplayNull(void);
EGLNativeWindowType _glfwGetEGLNativeWindowNull(_GLFWwindow* window); EGLNativeWindowType _glfwGetEGLNativeWindowNull(_GLFWwindow* window);
void _glfwGetRequiredInstanceExtensionsNull(char** extensions); void _glfwGetRequiredInstanceExtensionsNull(char** extensions);
int _glfwGetPhysicalDevicePresentationSupportNull(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); GLFWbool _glfwGetPhysicalDevicePresentationSupportNull(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
VkResult _glfwCreateWindowSurfaceNull(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); VkResult _glfwCreateWindowSurfaceNull(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
void _glfwPollMonitorsNull(void); void _glfwPollMonitorsNull(void);

View File

@ -24,8 +24,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
@ -39,15 +37,15 @@ static void applySizeLimits(_GLFWwindow* window, int* width, int* height)
*height = (int) (*width / ratio); *height = (int) (*width / ratio);
} }
if (window->minwidth != GLFW_DONT_CARE && *width < window->minwidth) if (window->minwidth != GLFW_DONT_CARE)
*width = window->minwidth; *width = _glfw_max(*width, window->minwidth);
else if (window->maxwidth != GLFW_DONT_CARE && *width > window->maxwidth) else if (window->maxwidth != GLFW_DONT_CARE)
*width = window->maxwidth; *width = _glfw_min(*width, window->maxwidth);
if (window->minheight != GLFW_DONT_CARE && *height < window->minheight) if (window->minheight != GLFW_DONT_CARE)
*height = window->minheight; *height = _glfw_min(*height, window->minheight);
else if (window->maxheight != GLFW_DONT_CARE && *height > window->maxheight) else if (window->maxheight != GLFW_DONT_CARE)
*height = window->maxheight; *height = _glfw_max(*height, window->maxheight);
} }
static void fitToMonitor(_GLFWwindow* window) static void fitToMonitor(_GLFWwindow* window)
@ -81,9 +79,18 @@ static int createNativeWindow(_GLFWwindow* window,
if (window->monitor) if (window->monitor)
fitToMonitor(window); fitToMonitor(window);
else else
{
if (wndconfig->xpos == GLFW_ANY_POSITION && wndconfig->ypos == GLFW_ANY_POSITION)
{ {
window->null.xpos = 17; window->null.xpos = 17;
window->null.ypos = 17; window->null.ypos = 17;
}
else
{
window->null.xpos = wndconfig->xpos;
window->null.ypos = wndconfig->ypos;
}
window->null.width = wndconfig->width; window->null.width = wndconfig->width;
window->null.height = wndconfig->height; window->null.height = wndconfig->height;
} }
@ -103,7 +110,7 @@ static int createNativeWindow(_GLFWwindow* window,
////// GLFW platform API ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
int _glfwCreateWindowNull(_GLFWwindow* window, GLFWbool _glfwCreateWindowNull(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig, const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
@ -128,13 +135,31 @@ int _glfwCreateWindowNull(_GLFWwindow* window,
if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
} }
if (!_glfwRefreshContextAttribs(window, ctxconfig))
return GLFW_FALSE;
} }
if (wndconfig->mousePassthrough)
_glfwSetWindowMousePassthroughNull(window, GLFW_TRUE);
if (window->monitor) if (window->monitor)
{ {
_glfwShowWindowNull(window); _glfwShowWindowNull(window);
_glfwFocusWindowNull(window); _glfwFocusWindowNull(window);
acquireMonitor(window); acquireMonitor(window);
if (wndconfig->centerCursor)
_glfwCenterCursorInContentArea(window);
}
else
{
if (wndconfig->visible)
{
_glfwShowWindowNull(window);
if (wndconfig->focused)
_glfwFocusWindowNull(window);
}
} }
return GLFW_TRUE; return GLFW_TRUE;
@ -344,12 +369,12 @@ void _glfwMaximizeWindowNull(_GLFWwindow* window)
} }
} }
int _glfwWindowMaximizedNull(_GLFWwindow* window) GLFWbool _glfwWindowMaximizedNull(_GLFWwindow* window)
{ {
return window->null.maximized; return window->null.maximized;
} }
int _glfwWindowHoveredNull(_GLFWwindow* window) GLFWbool _glfwWindowHoveredNull(_GLFWwindow* window)
{ {
return _glfw.null.xcursor >= window->null.xpos && return _glfw.null.xcursor >= window->null.xpos &&
_glfw.null.ycursor >= window->null.ypos && _glfw.null.ycursor >= window->null.ypos &&
@ -357,7 +382,7 @@ int _glfwWindowHoveredNull(_GLFWwindow* window)
_glfw.null.ycursor <= window->null.ypos + window->null.height - 1; _glfw.null.ycursor <= window->null.ypos + window->null.height - 1;
} }
int _glfwFramebufferTransparentNull(_GLFWwindow* window) GLFWbool _glfwFramebufferTransparentNull(_GLFWwindow* window)
{ {
return window->null.transparent; return window->null.transparent;
} }
@ -448,17 +473,17 @@ void _glfwFocusWindowNull(_GLFWwindow* window)
_glfwInputWindowFocus(window, GLFW_TRUE); _glfwInputWindowFocus(window, GLFW_TRUE);
} }
int _glfwWindowFocusedNull(_GLFWwindow* window) GLFWbool _glfwWindowFocusedNull(_GLFWwindow* window)
{ {
return _glfw.null.focusedWindow == window; return _glfw.null.focusedWindow == window;
} }
int _glfwWindowIconifiedNull(_GLFWwindow* window) GLFWbool _glfwWindowIconifiedNull(_GLFWwindow* window)
{ {
return window->null.iconified; return window->null.iconified;
} }
int _glfwWindowVisibleNull(_GLFWwindow* window) GLFWbool _glfwWindowVisibleNull(_GLFWwindow* window)
{ {
return window->null.visible; return window->null.visible;
} }
@ -497,14 +522,14 @@ void _glfwSetCursorModeNull(_GLFWwindow* window, int mode)
{ {
} }
int _glfwCreateCursorNull(_GLFWcursor* cursor, GLFWbool _glfwCreateCursorNull(_GLFWcursor* cursor,
const GLFWimage* image, const GLFWimage* image,
int xhot, int yhot) int xhot, int yhot)
{ {
return GLFW_TRUE; return GLFW_TRUE;
} }
int _glfwCreateStandardCursorNull(_GLFWcursor* cursor, int shape) GLFWbool _glfwCreateStandardCursorNull(_GLFWcursor* cursor, int shape)
{ {
return GLFW_TRUE; return GLFW_TRUE;
} }
@ -546,7 +571,7 @@ EGLNativeWindowType _glfwGetEGLNativeWindowNull(_GLFWwindow* window)
const char* _glfwGetScancodeNameNull(int scancode) const char* _glfwGetScancodeNameNull(int scancode)
{ {
if (scancode < GLFW_KEY_SPACE || scancode > GLFW_KEY_LAST) if (scancode < GLFW_NULL_SC_FIRST || scancode > GLFW_NULL_SC_LAST)
{ {
_glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode); _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode);
return NULL; return NULL;
@ -554,117 +579,117 @@ const char* _glfwGetScancodeNameNull(int scancode)
switch (scancode) switch (scancode)
{ {
case GLFW_KEY_APOSTROPHE: case GLFW_NULL_SC_APOSTROPHE:
return "'"; return "'";
case GLFW_KEY_COMMA: case GLFW_NULL_SC_COMMA:
return ","; return ",";
case GLFW_KEY_MINUS: case GLFW_NULL_SC_MINUS:
case GLFW_KEY_KP_SUBTRACT: case GLFW_NULL_SC_KP_SUBTRACT:
return "-"; return "-";
case GLFW_KEY_PERIOD: case GLFW_NULL_SC_PERIOD:
case GLFW_KEY_KP_DECIMAL: case GLFW_NULL_SC_KP_DECIMAL:
return "."; return ".";
case GLFW_KEY_SLASH: case GLFW_NULL_SC_SLASH:
case GLFW_KEY_KP_DIVIDE: case GLFW_NULL_SC_KP_DIVIDE:
return "/"; return "/";
case GLFW_KEY_SEMICOLON: case GLFW_NULL_SC_SEMICOLON:
return ";"; return ";";
case GLFW_KEY_EQUAL: case GLFW_NULL_SC_EQUAL:
case GLFW_KEY_KP_EQUAL: case GLFW_NULL_SC_KP_EQUAL:
return "="; return "=";
case GLFW_KEY_LEFT_BRACKET: case GLFW_NULL_SC_LEFT_BRACKET:
return "["; return "[";
case GLFW_KEY_RIGHT_BRACKET: case GLFW_NULL_SC_RIGHT_BRACKET:
return "]"; return "]";
case GLFW_KEY_KP_MULTIPLY: case GLFW_NULL_SC_KP_MULTIPLY:
return "*"; return "*";
case GLFW_KEY_KP_ADD: case GLFW_NULL_SC_KP_ADD:
return "+"; return "+";
case GLFW_KEY_BACKSLASH: case GLFW_NULL_SC_BACKSLASH:
case GLFW_KEY_WORLD_1: case GLFW_NULL_SC_WORLD_1:
case GLFW_KEY_WORLD_2: case GLFW_NULL_SC_WORLD_2:
return "\\"; return "\\";
case GLFW_KEY_0: case GLFW_NULL_SC_0:
case GLFW_KEY_KP_0: case GLFW_NULL_SC_KP_0:
return "0"; return "0";
case GLFW_KEY_1: case GLFW_NULL_SC_1:
case GLFW_KEY_KP_1: case GLFW_NULL_SC_KP_1:
return "1"; return "1";
case GLFW_KEY_2: case GLFW_NULL_SC_2:
case GLFW_KEY_KP_2: case GLFW_NULL_SC_KP_2:
return "2"; return "2";
case GLFW_KEY_3: case GLFW_NULL_SC_3:
case GLFW_KEY_KP_3: case GLFW_NULL_SC_KP_3:
return "3"; return "3";
case GLFW_KEY_4: case GLFW_NULL_SC_4:
case GLFW_KEY_KP_4: case GLFW_NULL_SC_KP_4:
return "4"; return "4";
case GLFW_KEY_5: case GLFW_NULL_SC_5:
case GLFW_KEY_KP_5: case GLFW_NULL_SC_KP_5:
return "5"; return "5";
case GLFW_KEY_6: case GLFW_NULL_SC_6:
case GLFW_KEY_KP_6: case GLFW_NULL_SC_KP_6:
return "6"; return "6";
case GLFW_KEY_7: case GLFW_NULL_SC_7:
case GLFW_KEY_KP_7: case GLFW_NULL_SC_KP_7:
return "7"; return "7";
case GLFW_KEY_8: case GLFW_NULL_SC_8:
case GLFW_KEY_KP_8: case GLFW_NULL_SC_KP_8:
return "8"; return "8";
case GLFW_KEY_9: case GLFW_NULL_SC_9:
case GLFW_KEY_KP_9: case GLFW_NULL_SC_KP_9:
return "9"; return "9";
case GLFW_KEY_A: case GLFW_NULL_SC_A:
return "a"; return "a";
case GLFW_KEY_B: case GLFW_NULL_SC_B:
return "b"; return "b";
case GLFW_KEY_C: case GLFW_NULL_SC_C:
return "c"; return "c";
case GLFW_KEY_D: case GLFW_NULL_SC_D:
return "d"; return "d";
case GLFW_KEY_E: case GLFW_NULL_SC_E:
return "e"; return "e";
case GLFW_KEY_F: case GLFW_NULL_SC_F:
return "f"; return "f";
case GLFW_KEY_G: case GLFW_NULL_SC_G:
return "g"; return "g";
case GLFW_KEY_H: case GLFW_NULL_SC_H:
return "h"; return "h";
case GLFW_KEY_I: case GLFW_NULL_SC_I:
return "i"; return "i";
case GLFW_KEY_J: case GLFW_NULL_SC_J:
return "j"; return "j";
case GLFW_KEY_K: case GLFW_NULL_SC_K:
return "k"; return "k";
case GLFW_KEY_L: case GLFW_NULL_SC_L:
return "l"; return "l";
case GLFW_KEY_M: case GLFW_NULL_SC_M:
return "m"; return "m";
case GLFW_KEY_N: case GLFW_NULL_SC_N:
return "n"; return "n";
case GLFW_KEY_O: case GLFW_NULL_SC_O:
return "o"; return "o";
case GLFW_KEY_P: case GLFW_NULL_SC_P:
return "p"; return "p";
case GLFW_KEY_Q: case GLFW_NULL_SC_Q:
return "q"; return "q";
case GLFW_KEY_R: case GLFW_NULL_SC_R:
return "r"; return "r";
case GLFW_KEY_S: case GLFW_NULL_SC_S:
return "s"; return "s";
case GLFW_KEY_T: case GLFW_NULL_SC_T:
return "t"; return "t";
case GLFW_KEY_U: case GLFW_NULL_SC_U:
return "u"; return "u";
case GLFW_KEY_V: case GLFW_NULL_SC_V:
return "v"; return "v";
case GLFW_KEY_W: case GLFW_NULL_SC_W:
return "w"; return "w";
case GLFW_KEY_X: case GLFW_NULL_SC_X:
return "x"; return "x";
case GLFW_KEY_Y: case GLFW_NULL_SC_Y:
return "y"; return "y";
case GLFW_KEY_Z: case GLFW_NULL_SC_Z:
return "z"; return "z";
} }
@ -673,14 +698,14 @@ const char* _glfwGetScancodeNameNull(int scancode)
int _glfwGetKeyScancodeNull(int key) int _glfwGetKeyScancodeNull(int key)
{ {
return key; return _glfw.null.scancodes[key];
} }
void _glfwGetRequiredInstanceExtensionsNull(char** extensions) void _glfwGetRequiredInstanceExtensionsNull(char** extensions)
{ {
} }
int _glfwGetPhysicalDevicePresentationSupportNull(VkInstance instance, GLFWbool _glfwGetPhysicalDevicePresentationSupportNull(VkInstance instance,
VkPhysicalDevice device, VkPhysicalDevice device,
uint32_t queuefamily) uint32_t queuefamily)
{ {

View File

@ -24,8 +24,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -124,7 +122,7 @@ GLFWbool _glfwInitOSMesa(void)
"libOSMesa.8.dylib", "libOSMesa.8.dylib",
#elif defined(__CYGWIN__) #elif defined(__CYGWIN__)
"libOSMesa-8.so", "libOSMesa-8.so",
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
"libOSMesa.so", "libOSMesa.so",
#else #else
"libOSMesa.so.8", "libOSMesa.so.8",
@ -190,7 +188,7 @@ void _glfwTerminateOSMesa(void)
} }
} }
#define setAttrib(a, v) \ #define SET_ATTRIB(a, v) \
{ \ { \
assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
attribs[index++] = a; \ attribs[index++] = a; \
@ -221,24 +219,24 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
{ {
int index = 0, attribs[40]; int index = 0, attribs[40];
setAttrib(OSMESA_FORMAT, OSMESA_RGBA); SET_ATTRIB(OSMESA_FORMAT, OSMESA_RGBA);
setAttrib(OSMESA_DEPTH_BITS, fbconfig->depthBits); SET_ATTRIB(OSMESA_DEPTH_BITS, fbconfig->depthBits);
setAttrib(OSMESA_STENCIL_BITS, fbconfig->stencilBits); SET_ATTRIB(OSMESA_STENCIL_BITS, fbconfig->stencilBits);
setAttrib(OSMESA_ACCUM_BITS, accumBits); SET_ATTRIB(OSMESA_ACCUM_BITS, accumBits);
if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE) if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE)
{ {
setAttrib(OSMESA_PROFILE, OSMESA_CORE_PROFILE); SET_ATTRIB(OSMESA_PROFILE, OSMESA_CORE_PROFILE);
} }
else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE)
{ {
setAttrib(OSMESA_PROFILE, OSMESA_COMPAT_PROFILE); SET_ATTRIB(OSMESA_PROFILE, OSMESA_COMPAT_PROFILE);
} }
if (ctxconfig->major != 1 || ctxconfig->minor != 0) if (ctxconfig->major != 1 || ctxconfig->minor != 0)
{ {
setAttrib(OSMESA_CONTEXT_MAJOR_VERSION, ctxconfig->major); SET_ATTRIB(OSMESA_CONTEXT_MAJOR_VERSION, ctxconfig->major);
setAttrib(OSMESA_CONTEXT_MINOR_VERSION, ctxconfig->minor); SET_ATTRIB(OSMESA_CONTEXT_MINOR_VERSION, ctxconfig->minor);
} }
if (ctxconfig->forward) if (ctxconfig->forward)
@ -248,7 +246,7 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
return GLFW_FALSE; return GLFW_FALSE;
} }
setAttrib(0, 0); SET_ATTRIB(0, 0);
window->context.osmesa.handle = window->context.osmesa.handle =
OSMesaCreateContextAttribs(attribs, share); OSMesaCreateContextAttribs(attribs, share);
@ -287,7 +285,7 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
return GLFW_TRUE; return GLFW_TRUE;
} }
#undef setAttrib #undef SET_ATTRIB
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////

View File

@ -24,11 +24,13 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
// These construct a string literal from individual numeric constants
#define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r
#define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -146,7 +148,9 @@ GLFWAPI int glfwPlatformSupported(int platformID)
GLFWAPI const char* glfwGetVersionString(void) GLFWAPI const char* glfwGetVersionString(void)
{ {
return _GLFW_VERSION_NUMBER return _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR,
GLFW_VERSION_MINOR,
GLFW_VERSION_REVISION)
#if defined(_GLFW_WIN32) #if defined(_GLFW_WIN32)
" Win32 WGL" " Win32 WGL"
#endif #endif

View File

@ -25,6 +25,18 @@
// //
//======================================================================== //========================================================================
#if defined(GLFW_BUILD_WIN32_TIMER) || \
defined(GLFW_BUILD_WIN32_MODULE) || \
defined(GLFW_BUILD_WIN32_THREAD) || \
defined(GLFW_BUILD_COCOA_TIMER) || \
defined(GLFW_BUILD_POSIX_TIMER) || \
defined(GLFW_BUILD_POSIX_MODULE) || \
defined(GLFW_BUILD_POSIX_THREAD) || \
defined(GLFW_BUILD_POSIX_POLL) || \
defined(GLFW_BUILD_LINUX_JOYSTICK)
#error "You must not define these; define zero or more _GLFW_<platform> macros instead"
#endif
#include "null_platform.h" #include "null_platform.h"
#if defined(_GLFW_WIN32) #if defined(_GLFW_WIN32)
@ -86,36 +98,16 @@
#endif #endif
#if (defined(_GLFW_X11) || defined(_GLFW_WAYLAND)) && defined(__linux__) #if (defined(_GLFW_X11) || defined(_GLFW_WAYLAND)) && defined(__linux__)
#define GLFW_BUILD_LINUX_JOYSTICK
#endif
#if defined(GLFW_BUILD_LINUX_JOYSTICK)
#include "linux_joystick.h" #include "linux_joystick.h"
#else #else
#define GLFW_LINUX_JOYSTICK_STATE #define GLFW_LINUX_JOYSTICK_STATE
#define GLFW_LINUX_LIBRARY_JOYSTICK_STATE #define GLFW_LINUX_LIBRARY_JOYSTICK_STATE
#endif #endif
#if defined(_WIN32)
#include "win32_thread.h"
#define GLFW_POSIX_TLS_STATE
#define GLFW_POSIX_MUTEX_STATE
#else
#include "posix_thread.h"
#define GLFW_WIN32_TLS_STATE
#define GLFW_WIN32_MUTEX_STATE
#endif
#if defined(_WIN32)
#include "win32_time.h"
#define GLFW_POSIX_LIBRARY_TIMER_STATE
#define GLFW_COCOA_LIBRARY_TIMER_STATE
#elif defined(__APPLE__)
#include "cocoa_time.h"
#define GLFW_WIN32_LIBRARY_TIMER_STATE
#define GLFW_POSIX_LIBRARY_TIMER_STATE
#else
#include "posix_time.h"
#define GLFW_WIN32_LIBRARY_TIMER_STATE
#define GLFW_COCOA_LIBRARY_TIMER_STATE
#endif
#define GLFW_PLATFORM_WINDOW_STATE \ #define GLFW_PLATFORM_WINDOW_STATE \
GLFW_WIN32_WINDOW_STATE \ GLFW_WIN32_WINDOW_STATE \
GLFW_COCOA_WINDOW_STATE \ GLFW_COCOA_WINDOW_STATE \
@ -142,14 +134,6 @@
GLFW_COCOA_JOYSTICK_STATE \ GLFW_COCOA_JOYSTICK_STATE \
GLFW_LINUX_JOYSTICK_STATE GLFW_LINUX_JOYSTICK_STATE
#define GLFW_PLATFORM_TLS_STATE \
GLFW_WIN32_TLS_STATE \
GLFW_POSIX_TLS_STATE \
#define GLFW_PLATFORM_MUTEX_STATE \
GLFW_WIN32_MUTEX_STATE \
GLFW_POSIX_MUTEX_STATE \
#define GLFW_PLATFORM_LIBRARY_WINDOW_STATE \ #define GLFW_PLATFORM_LIBRARY_WINDOW_STATE \
GLFW_WIN32_LIBRARY_WINDOW_STATE \ GLFW_WIN32_LIBRARY_WINDOW_STATE \
GLFW_COCOA_LIBRARY_WINDOW_STATE \ GLFW_COCOA_LIBRARY_WINDOW_STATE \
@ -162,11 +146,6 @@
GLFW_COCOA_LIBRARY_JOYSTICK_STATE \ GLFW_COCOA_LIBRARY_JOYSTICK_STATE \
GLFW_LINUX_LIBRARY_JOYSTICK_STATE GLFW_LINUX_LIBRARY_JOYSTICK_STATE
#define GLFW_PLATFORM_LIBRARY_TIMER_STATE \
GLFW_WIN32_LIBRARY_TIMER_STATE \
GLFW_COCOA_LIBRARY_TIMER_STATE \
GLFW_POSIX_LIBRARY_TIMER_STATE \
#define GLFW_PLATFORM_CONTEXT_STATE \ #define GLFW_PLATFORM_CONTEXT_STATE \
GLFW_WGL_CONTEXT_STATE \ GLFW_WGL_CONTEXT_STATE \
GLFW_NSGL_CONTEXT_STATE \ GLFW_NSGL_CONTEXT_STATE \
@ -177,3 +156,48 @@
GLFW_NSGL_LIBRARY_CONTEXT_STATE \ GLFW_NSGL_LIBRARY_CONTEXT_STATE \
GLFW_GLX_LIBRARY_CONTEXT_STATE GLFW_GLX_LIBRARY_CONTEXT_STATE
#if defined(_WIN32)
#define GLFW_BUILD_WIN32_THREAD
#else
#define GLFW_BUILD_POSIX_THREAD
#endif
#if defined(GLFW_BUILD_WIN32_THREAD)
#include "win32_thread.h"
#define GLFW_PLATFORM_TLS_STATE GLFW_WIN32_TLS_STATE
#define GLFW_PLATFORM_MUTEX_STATE GLFW_WIN32_MUTEX_STATE
#elif defined(GLFW_BUILD_POSIX_THREAD)
#include "posix_thread.h"
#define GLFW_PLATFORM_TLS_STATE GLFW_POSIX_TLS_STATE
#define GLFW_PLATFORM_MUTEX_STATE GLFW_POSIX_MUTEX_STATE
#endif
#if defined(_WIN32)
#define GLFW_BUILD_WIN32_TIMER
#elif defined(__APPLE__)
#define GLFW_BUILD_COCOA_TIMER
#else
#define GLFW_BUILD_POSIX_TIMER
#endif
#if defined(GLFW_BUILD_WIN32_TIMER)
#include "win32_time.h"
#define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_WIN32_LIBRARY_TIMER_STATE
#elif defined(GLFW_BUILD_COCOA_TIMER)
#include "cocoa_time.h"
#define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_COCOA_LIBRARY_TIMER_STATE
#elif defined(GLFW_BUILD_POSIX_TIMER)
#include "posix_time.h"
#define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_POSIX_LIBRARY_TIMER_STATE
#endif
#if defined(_WIN32)
#define GLFW_BUILD_WIN32_MODULE
#else
#define GLFW_BUILD_POSIX_MODULE
#endif
#if defined(_GLFW_WAYLAND) || defined(_GLFW_X11)
#define GLFW_BUILD_POSIX_POLL
#endif

View File

@ -23,11 +23,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(GLFW_BUILD_POSIX_MODULE)
#include <dlfcn.h> #include <dlfcn.h>
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -49,3 +49,5 @@ GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name)
return dlsym(module, name); return dlsym(module, name);
} }
#endif // GLFW_BUILD_POSIX_MODULE

83
src/posix_poll.c Normal file
View File

@ -0,0 +1,83 @@
//========================================================================
// GLFW 3.4 POSIX - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2022 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 _GNU_SOURCE
#include "internal.h"
#if defined(GLFW_BUILD_POSIX_POLL)
#include <signal.h>
#include <time.h>
#include <errno.h>
GLFWbool _glfwPollPOSIX(struct pollfd* fds, nfds_t count, double* timeout)
{
for (;;)
{
if (timeout)
{
const uint64_t base = _glfwPlatformGetTimerValue();
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__)
const time_t seconds = (time_t) *timeout;
const long nanoseconds = (long) ((*timeout - seconds) * 1e9);
const struct timespec ts = { seconds, nanoseconds };
const int result = ppoll(fds, count, &ts, NULL);
#elif defined(__NetBSD__)
const time_t seconds = (time_t) *timeout;
const long nanoseconds = (long) ((*timeout - seconds) * 1e9);
const struct timespec ts = { seconds, nanoseconds };
const int result = pollts(fds, count, &ts, NULL);
#else
const int milliseconds = (int) (*timeout * 1e3);
const int result = poll(fds, count, milliseconds);
#endif
const int error = errno; // clock_gettime may overwrite our error
*timeout -= (_glfwPlatformGetTimerValue() - base) /
(double) _glfwPlatformGetTimerFrequency();
if (result > 0)
return GLFW_TRUE;
else if (result == -1 && error != EINTR && error != EAGAIN)
return GLFW_FALSE;
else if (*timeout <= 0.0)
return GLFW_FALSE;
}
else
{
const int result = poll(fds, count, -1);
if (result > 0)
return GLFW_TRUE;
else if (result == -1 && errno != EINTR && errno != EAGAIN)
return GLFW_FALSE;
}
}
}
#endif // GLFW_BUILD_POSIX_POLL

30
src/posix_poll.h Normal file
View File

@ -0,0 +1,30 @@
//========================================================================
// GLFW 3.4 POSIX - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2022 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 <poll.h>
GLFWbool _glfwPollPOSIX(struct pollfd* fds, nfds_t count, double* timeout);

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(GLFW_BUILD_POSIX_THREAD)
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@ -103,3 +103,5 @@ void _glfwPlatformUnlockMutex(_GLFWmutex* mutex)
pthread_mutex_unlock(&mutex->posix.handle); pthread_mutex_unlock(&mutex->posix.handle);
} }
#endif // GLFW_BUILD_POSIX_THREAD

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(GLFW_BUILD_POSIX_TIMER)
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
@ -61,3 +61,5 @@ uint64_t _glfwPlatformGetTimerFrequency(void)
return _glfw.timer.posix.frequency; return _glfw.timer.posix.frequency;
} }
#endif // GLFW_BUILD_POSIX_TIMER

View File

@ -24,8 +24,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
@ -63,7 +61,7 @@ GLFWbool _glfwInitVulkan(int mode)
_glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.1.dylib"); _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.1.dylib");
if (!_glfw.vk.handle) if (!_glfw.vk.handle)
_glfw.vk.handle = _glfwLoadLocalVulkanLoaderCocoa(); _glfw.vk.handle = _glfwLoadLocalVulkanLoaderCocoa();
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
_glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so"); _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so");
#else #else
_glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so.1"); _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so.1");

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_WIN32)
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
@ -52,12 +52,12 @@ static int findPixelFormatAttribValueWGL(const int* attribs,
return 0; return 0;
} }
#define addAttrib(a) \ #define ADD_ATTRIB(a) \
{ \ { \
assert((size_t) attribCount < sizeof(attribs) / sizeof(attribs[0])); \ assert((size_t) attribCount < sizeof(attribs) / sizeof(attribs[0])); \
attribs[attribCount++] = a; \ attribs[attribCount++] = a; \
} }
#define findAttribValue(a) \ #define FIND_ATTRIB_VALUE(a) \
findPixelFormatAttribValueWGL(attribs, attribCount, values, a) findPixelFormatAttribValueWGL(attribs, attribCount, values, a)
// Return a list of available and usable framebuffer configs // Return a list of available and usable framebuffer configs
@ -72,61 +72,49 @@ static int choosePixelFormatWGL(_GLFWwindow* window,
int attribs[40]; int attribs[40];
int values[sizeof(attribs) / sizeof(attribs[0])]; int values[sizeof(attribs) / sizeof(attribs[0])];
if (_glfw.wgl.ARB_pixel_format)
{
const int attrib = WGL_NUMBER_PIXEL_FORMATS_ARB;
if (!wglGetPixelFormatAttribivARB(window->context.wgl.dc,
1, 0, 1, &attrib, &nativeCount))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to retrieve pixel format attribute");
return 0;
}
addAttrib(WGL_SUPPORT_OPENGL_ARB);
addAttrib(WGL_DRAW_TO_WINDOW_ARB);
addAttrib(WGL_PIXEL_TYPE_ARB);
addAttrib(WGL_ACCELERATION_ARB);
addAttrib(WGL_RED_BITS_ARB);
addAttrib(WGL_RED_SHIFT_ARB);
addAttrib(WGL_GREEN_BITS_ARB);
addAttrib(WGL_GREEN_SHIFT_ARB);
addAttrib(WGL_BLUE_BITS_ARB);
addAttrib(WGL_BLUE_SHIFT_ARB);
addAttrib(WGL_ALPHA_BITS_ARB);
addAttrib(WGL_ALPHA_SHIFT_ARB);
addAttrib(WGL_DEPTH_BITS_ARB);
addAttrib(WGL_STENCIL_BITS_ARB);
addAttrib(WGL_ACCUM_BITS_ARB);
addAttrib(WGL_ACCUM_RED_BITS_ARB);
addAttrib(WGL_ACCUM_GREEN_BITS_ARB);
addAttrib(WGL_ACCUM_BLUE_BITS_ARB);
addAttrib(WGL_ACCUM_ALPHA_BITS_ARB);
addAttrib(WGL_AUX_BUFFERS_ARB);
addAttrib(WGL_STEREO_ARB);
addAttrib(WGL_DOUBLE_BUFFER_ARB);
if (_glfw.wgl.ARB_multisample)
addAttrib(WGL_SAMPLES_ARB);
if (ctxconfig->client == GLFW_OPENGL_API)
{
if (_glfw.wgl.ARB_framebuffer_sRGB || _glfw.wgl.EXT_framebuffer_sRGB)
addAttrib(WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB);
}
else
{
if (_glfw.wgl.EXT_colorspace)
addAttrib(WGL_COLORSPACE_EXT);
}
}
else
{
nativeCount = DescribePixelFormat(window->context.wgl.dc, nativeCount = DescribePixelFormat(window->context.wgl.dc,
1, 1,
sizeof(PIXELFORMATDESCRIPTOR), sizeof(PIXELFORMATDESCRIPTOR),
NULL); NULL);
if (_glfw.wgl.ARB_pixel_format)
{
ADD_ATTRIB(WGL_SUPPORT_OPENGL_ARB);
ADD_ATTRIB(WGL_DRAW_TO_WINDOW_ARB);
ADD_ATTRIB(WGL_PIXEL_TYPE_ARB);
ADD_ATTRIB(WGL_ACCELERATION_ARB);
ADD_ATTRIB(WGL_RED_BITS_ARB);
ADD_ATTRIB(WGL_RED_SHIFT_ARB);
ADD_ATTRIB(WGL_GREEN_BITS_ARB);
ADD_ATTRIB(WGL_GREEN_SHIFT_ARB);
ADD_ATTRIB(WGL_BLUE_BITS_ARB);
ADD_ATTRIB(WGL_BLUE_SHIFT_ARB);
ADD_ATTRIB(WGL_ALPHA_BITS_ARB);
ADD_ATTRIB(WGL_ALPHA_SHIFT_ARB);
ADD_ATTRIB(WGL_DEPTH_BITS_ARB);
ADD_ATTRIB(WGL_STENCIL_BITS_ARB);
ADD_ATTRIB(WGL_ACCUM_BITS_ARB);
ADD_ATTRIB(WGL_ACCUM_RED_BITS_ARB);
ADD_ATTRIB(WGL_ACCUM_GREEN_BITS_ARB);
ADD_ATTRIB(WGL_ACCUM_BLUE_BITS_ARB);
ADD_ATTRIB(WGL_ACCUM_ALPHA_BITS_ARB);
ADD_ATTRIB(WGL_AUX_BUFFERS_ARB);
ADD_ATTRIB(WGL_STEREO_ARB);
ADD_ATTRIB(WGL_DOUBLE_BUFFER_ARB);
if (_glfw.wgl.ARB_multisample)
ADD_ATTRIB(WGL_SAMPLES_ARB);
if (ctxconfig->client == GLFW_OPENGL_API)
{
if (_glfw.wgl.ARB_framebuffer_sRGB || _glfw.wgl.EXT_framebuffer_sRGB)
ADD_ATTRIB(WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB);
}
else
{
if (_glfw.wgl.EXT_colorspace)
ADD_ATTRIB(WGL_COLORSPACE_EXT);
}
} }
usableConfigs = _glfw_calloc(nativeCount, sizeof(_GLFWfbconfig)); usableConfigs = _glfw_calloc(nativeCount, sizeof(_GLFWfbconfig));
@ -152,48 +140,48 @@ static int choosePixelFormatWGL(_GLFWwindow* window,
return 0; return 0;
} }
if (!findAttribValue(WGL_SUPPORT_OPENGL_ARB) || if (!FIND_ATTRIB_VALUE(WGL_SUPPORT_OPENGL_ARB) ||
!findAttribValue(WGL_DRAW_TO_WINDOW_ARB)) !FIND_ATTRIB_VALUE(WGL_DRAW_TO_WINDOW_ARB))
{ {
continue; continue;
} }
if (findAttribValue(WGL_PIXEL_TYPE_ARB) != WGL_TYPE_RGBA_ARB) if (FIND_ATTRIB_VALUE(WGL_PIXEL_TYPE_ARB) != WGL_TYPE_RGBA_ARB)
continue; continue;
if (findAttribValue(WGL_ACCELERATION_ARB) == WGL_NO_ACCELERATION_ARB) if (FIND_ATTRIB_VALUE(WGL_ACCELERATION_ARB) == WGL_NO_ACCELERATION_ARB)
continue; continue;
if (findAttribValue(WGL_DOUBLE_BUFFER_ARB) != fbconfig->doublebuffer) if (FIND_ATTRIB_VALUE(WGL_DOUBLE_BUFFER_ARB) != fbconfig->doublebuffer)
continue; continue;
u->redBits = findAttribValue(WGL_RED_BITS_ARB); u->redBits = FIND_ATTRIB_VALUE(WGL_RED_BITS_ARB);
u->greenBits = findAttribValue(WGL_GREEN_BITS_ARB); u->greenBits = FIND_ATTRIB_VALUE(WGL_GREEN_BITS_ARB);
u->blueBits = findAttribValue(WGL_BLUE_BITS_ARB); u->blueBits = FIND_ATTRIB_VALUE(WGL_BLUE_BITS_ARB);
u->alphaBits = findAttribValue(WGL_ALPHA_BITS_ARB); u->alphaBits = FIND_ATTRIB_VALUE(WGL_ALPHA_BITS_ARB);
u->depthBits = findAttribValue(WGL_DEPTH_BITS_ARB); u->depthBits = FIND_ATTRIB_VALUE(WGL_DEPTH_BITS_ARB);
u->stencilBits = findAttribValue(WGL_STENCIL_BITS_ARB); u->stencilBits = FIND_ATTRIB_VALUE(WGL_STENCIL_BITS_ARB);
u->accumRedBits = findAttribValue(WGL_ACCUM_RED_BITS_ARB); u->accumRedBits = FIND_ATTRIB_VALUE(WGL_ACCUM_RED_BITS_ARB);
u->accumGreenBits = findAttribValue(WGL_ACCUM_GREEN_BITS_ARB); u->accumGreenBits = FIND_ATTRIB_VALUE(WGL_ACCUM_GREEN_BITS_ARB);
u->accumBlueBits = findAttribValue(WGL_ACCUM_BLUE_BITS_ARB); u->accumBlueBits = FIND_ATTRIB_VALUE(WGL_ACCUM_BLUE_BITS_ARB);
u->accumAlphaBits = findAttribValue(WGL_ACCUM_ALPHA_BITS_ARB); u->accumAlphaBits = FIND_ATTRIB_VALUE(WGL_ACCUM_ALPHA_BITS_ARB);
u->auxBuffers = findAttribValue(WGL_AUX_BUFFERS_ARB); u->auxBuffers = FIND_ATTRIB_VALUE(WGL_AUX_BUFFERS_ARB);
if (findAttribValue(WGL_STEREO_ARB)) if (FIND_ATTRIB_VALUE(WGL_STEREO_ARB))
u->stereo = GLFW_TRUE; u->stereo = GLFW_TRUE;
if (_glfw.wgl.ARB_multisample) if (_glfw.wgl.ARB_multisample)
u->samples = findAttribValue(WGL_SAMPLES_ARB); u->samples = FIND_ATTRIB_VALUE(WGL_SAMPLES_ARB);
if (ctxconfig->client == GLFW_OPENGL_API) if (ctxconfig->client == GLFW_OPENGL_API)
{ {
if (_glfw.wgl.ARB_framebuffer_sRGB || if (_glfw.wgl.ARB_framebuffer_sRGB ||
_glfw.wgl.EXT_framebuffer_sRGB) _glfw.wgl.EXT_framebuffer_sRGB)
{ {
if (findAttribValue(WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB)) if (FIND_ATTRIB_VALUE(WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB))
u->sRGB = GLFW_TRUE; u->sRGB = GLFW_TRUE;
} }
} }
@ -201,7 +189,7 @@ static int choosePixelFormatWGL(_GLFWwindow* window,
{ {
if (_glfw.wgl.EXT_colorspace) if (_glfw.wgl.EXT_colorspace)
{ {
if (findAttribValue(WGL_COLORSPACE_EXT) == WGL_COLORSPACE_SRGB_EXT) if (FIND_ATTRIB_VALUE(WGL_COLORSPACE_EXT) == WGL_COLORSPACE_SRGB_EXT)
u->sRGB = GLFW_TRUE; u->sRGB = GLFW_TRUE;
} }
} }
@ -290,8 +278,8 @@ static int choosePixelFormatWGL(_GLFWwindow* window,
return pixelFormat; return pixelFormat;
} }
#undef addAttrib #undef ADD_ATTRIB
#undef findAttribValue #undef FIND_ATTRIB_VALUE
static void makeContextCurrentWGL(_GLFWwindow* window) static void makeContextCurrentWGL(_GLFWwindow* window)
{ {
@ -342,6 +330,7 @@ static void swapBuffersWGL(_GLFWwindow* window)
static void swapIntervalWGL(int interval) static void swapIntervalWGL(int interval)
{ {
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot); _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
assert(window != NULL);
window->context.wgl.interval = interval; window->context.wgl.interval = interval;
@ -523,7 +512,7 @@ void _glfwTerminateWGL(void)
_glfwPlatformFreeModule(_glfw.wgl.instance); _glfwPlatformFreeModule(_glfw.wgl.instance);
} }
#define setAttrib(a, v) \ #define SET_ATTRIB(a, v) \
{ \ { \
assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
attribs[index++] = a; \ attribs[index++] = a; \
@ -631,12 +620,12 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
{ {
if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION) if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION)
{ {
setAttrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, SET_ATTRIB(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
WGL_NO_RESET_NOTIFICATION_ARB); WGL_NO_RESET_NOTIFICATION_ARB);
} }
else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET) else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET)
{ {
setAttrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, SET_ATTRIB(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
WGL_LOSE_CONTEXT_ON_RESET_ARB); WGL_LOSE_CONTEXT_ON_RESET_ARB);
} }
@ -650,12 +639,12 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
{ {
if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE) if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE)
{ {
setAttrib(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB, SET_ATTRIB(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB,
WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB); WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB);
} }
else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH) else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH)
{ {
setAttrib(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB, SET_ATTRIB(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB,
WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB); WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB);
} }
} }
@ -664,7 +653,7 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
if (ctxconfig->noerror) if (ctxconfig->noerror)
{ {
if (_glfw.wgl.ARB_create_context_no_error) if (_glfw.wgl.ARB_create_context_no_error)
setAttrib(WGL_CONTEXT_OPENGL_NO_ERROR_ARB, GLFW_TRUE); SET_ATTRIB(WGL_CONTEXT_OPENGL_NO_ERROR_ARB, GLFW_TRUE);
} }
// NOTE: Only request an explicitly versioned context when necessary, as // NOTE: Only request an explicitly versioned context when necessary, as
@ -672,17 +661,17 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
// highest version supported by the driver // highest version supported by the driver
if (ctxconfig->major != 1 || ctxconfig->minor != 0) if (ctxconfig->major != 1 || ctxconfig->minor != 0)
{ {
setAttrib(WGL_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major); SET_ATTRIB(WGL_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major);
setAttrib(WGL_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor); SET_ATTRIB(WGL_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor);
} }
if (flags) if (flags)
setAttrib(WGL_CONTEXT_FLAGS_ARB, flags); SET_ATTRIB(WGL_CONTEXT_FLAGS_ARB, flags);
if (mask) if (mask)
setAttrib(WGL_CONTEXT_PROFILE_MASK_ARB, mask); SET_ATTRIB(WGL_CONTEXT_PROFILE_MASK_ARB, mask);
setAttrib(0, 0); SET_ATTRIB(0, 0);
window->context.wgl.handle = window->context.wgl.handle =
wglCreateContextAttribsARB(window->context.wgl.dc, share, attribs); wglCreateContextAttribsARB(window->context.wgl.dc, share, attribs);
@ -765,7 +754,7 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
return GLFW_TRUE; return GLFW_TRUE;
} }
#undef setAttrib #undef SET_ATTRIB
GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle) GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle)
{ {
@ -788,3 +777,5 @@ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle)
return window->context.wgl.handle; return window->context.wgl.handle;
} }
#endif // _GLFW_WIN32

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_WIN32)
#include <stdlib.h> #include <stdlib.h>
static const GUID _glfw_GUID_DEVINTERFACE_HID = static const GUID _glfw_GUID_DEVINTERFACE_HID =
@ -71,6 +71,16 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
// //
static GLFWbool loadLibraries(void) static GLFWbool loadLibraries(void)
{ {
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(const WCHAR*) &_glfw,
(HMODULE*) &_glfw.win32.instance))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to retrieve own module handle");
return GLFW_FALSE;
}
_glfw.win32.user32.instance = _glfwPlatformLoadModule("user32.dll"); _glfw.win32.user32.instance = _glfwPlatformLoadModule("user32.dll");
if (!_glfw.win32.user32.instance) if (!_glfw.win32.user32.instance)
{ {
@ -91,6 +101,8 @@ static GLFWbool loadLibraries(void)
_glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "GetDpiForWindow"); _glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "GetDpiForWindow");
_glfw.win32.user32.AdjustWindowRectExForDpi_ = (PFN_AdjustWindowRectExForDpi) _glfw.win32.user32.AdjustWindowRectExForDpi_ = (PFN_AdjustWindowRectExForDpi)
_glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "AdjustWindowRectExForDpi"); _glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "AdjustWindowRectExForDpi");
_glfw.win32.user32.GetSystemMetricsForDpi_ = (PFN_GetSystemMetricsForDpi)
_glfwPlatformGetModuleSymbol(_glfw.win32.user32.instance, "GetSystemMetricsForDpi");
_glfw.win32.dinput8.instance = _glfwPlatformLoadModule("dinput8.dll"); _glfw.win32.dinput8.instance = _glfwPlatformLoadModule("dinput8.dll");
if (_glfw.win32.dinput8.instance) if (_glfw.win32.dinput8.instance)
@ -251,7 +263,6 @@ static void createKeyTables(void)
_glfw.win32.keycodes[0x151] = GLFW_KEY_PAGE_DOWN; _glfw.win32.keycodes[0x151] = GLFW_KEY_PAGE_DOWN;
_glfw.win32.keycodes[0x149] = GLFW_KEY_PAGE_UP; _glfw.win32.keycodes[0x149] = GLFW_KEY_PAGE_UP;
_glfw.win32.keycodes[0x045] = GLFW_KEY_PAUSE; _glfw.win32.keycodes[0x045] = GLFW_KEY_PAUSE;
_glfw.win32.keycodes[0x146] = GLFW_KEY_PAUSE;
_glfw.win32.keycodes[0x039] = GLFW_KEY_SPACE; _glfw.win32.keycodes[0x039] = GLFW_KEY_SPACE;
_glfw.win32.keycodes[0x00F] = GLFW_KEY_TAB; _glfw.win32.keycodes[0x00F] = GLFW_KEY_TAB;
_glfw.win32.keycodes[0x03A] = GLFW_KEY_CAPS_LOCK; _glfw.win32.keycodes[0x03A] = GLFW_KEY_CAPS_LOCK;
@ -320,20 +331,69 @@ static void createKeyTables(void)
} }
} }
// Window procedure for the hidden helper window
//
static LRESULT CALLBACK helperWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DISPLAYCHANGE:
_glfwPollMonitorsWin32();
break;
case WM_DEVICECHANGE:
{
if (!_glfw.joysticksInitialized)
break;
if (wParam == DBT_DEVICEARRIVAL)
{
DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam;
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
_glfwDetectJoystickConnectionWin32();
}
else if (wParam == DBT_DEVICEREMOVECOMPLETE)
{
DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam;
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
_glfwDetectJoystickDisconnectionWin32();
}
break;
}
}
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
// Creates a dummy window for behind-the-scenes work // Creates a dummy window for behind-the-scenes work
// //
static GLFWbool createHelperWindow(void) static GLFWbool createHelperWindow(void)
{ {
MSG msg; MSG msg;
WNDCLASSEXW wc = { sizeof(wc) };
wc.style = CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) helperWindowProc;
wc.hInstance = _glfw.win32.instance;
wc.lpszClassName = L"GLFW3 Helper";
_glfw.win32.helperWindowClass = RegisterClassExW(&wc);
if (!_glfw.win32.helperWindowClass)
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to register helper window class");
return GLFW_FALSE;
}
_glfw.win32.helperWindowHandle = _glfw.win32.helperWindowHandle =
CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
_GLFW_WNDCLASSNAME, MAKEINTATOM(_glfw.win32.helperWindowClass),
L"GLFW message window", L"GLFW message window",
WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
0, 0, 1, 1, 0, 0, 1, 1,
NULL, NULL, NULL, NULL,
GetModuleHandleW(NULL), _glfw.win32.instance,
NULL); NULL);
if (!_glfw.win32.helperWindowHandle) if (!_glfw.win32.helperWindowHandle)
@ -483,7 +543,7 @@ void _glfwUpdateKeyNamesWin32(void)
vk = vks[key - GLFW_KEY_KP_0]; vk = vks[key - GLFW_KEY_KP_0];
} }
else else
vk = MapVirtualKey(scancode, MAPVK_VSC_TO_VK); vk = MapVirtualKeyW(scancode, MAPVK_VSC_TO_VK);
length = ToUnicode(vk, scancode, state, length = ToUnicode(vk, scancode, state,
chars, sizeof(chars) / sizeof(WCHAR), chars, sizeof(chars) / sizeof(WCHAR),
@ -491,6 +551,8 @@ void _glfwUpdateKeyNamesWin32(void)
if (length == -1) if (length == -1)
{ {
// This is a dead key, so we need a second simulated key press
// to make it output its own character (usually a diacritic)
length = ToUnicode(vk, scancode, state, length = ToUnicode(vk, scancode, state,
chars, sizeof(chars) / sizeof(WCHAR), chars, sizeof(chars) / sizeof(WCHAR),
0); 0);
@ -506,7 +568,8 @@ void _glfwUpdateKeyNamesWin32(void)
} }
} }
// Replacement for IsWindowsVersionOrGreater as MinGW lacks versionhelpers.h // Replacement for IsWindowsVersionOrGreater, as we cannot rely on the
// application having a correct embedded manifest
// //
BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp) BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp)
{ {
@ -627,16 +690,13 @@ int _glfwInitWin32(void)
createKeyTables(); createKeyTables();
_glfwUpdateKeyNamesWin32(); _glfwUpdateKeyNamesWin32();
if (_glfwIsWindows10CreatorsUpdateOrGreaterWin32()) if (_glfwIsWindows10Version1703OrGreaterWin32())
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
else if (IsWindows8Point1OrGreater()) else if (IsWindows8Point1OrGreater())
SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
else if (IsWindowsVistaOrGreater()) else if (IsWindowsVistaOrGreater())
SetProcessDPIAware(); SetProcessDPIAware();
if (!_glfwRegisterWindowClassWin32())
return GLFW_FALSE;
if (!createHelperWindow()) if (!createHelperWindow())
return GLFW_FALSE; return GLFW_FALSE;
@ -651,15 +711,20 @@ void _glfwTerminateWin32(void)
if (_glfw.win32.helperWindowHandle) if (_glfw.win32.helperWindowHandle)
DestroyWindow(_glfw.win32.helperWindowHandle); DestroyWindow(_glfw.win32.helperWindowHandle);
if (_glfw.win32.helperWindowClass)
_glfwUnregisterWindowClassWin32(); UnregisterClassW(MAKEINTATOM(_glfw.win32.helperWindowClass), _glfw.win32.instance);
if (_glfw.win32.mainWindowClass)
UnregisterClassW(MAKEINTATOM(_glfw.win32.mainWindowClass), _glfw.win32.instance);
_glfw_free(_glfw.win32.clipboardString); _glfw_free(_glfw.win32.clipboardString);
_glfw_free(_glfw.win32.rawInput); _glfw_free(_glfw.win32.rawInput);
_glfwTerminateWGL(); _glfwTerminateWGL();
_glfwTerminateEGL(); _glfwTerminateEGL();
_glfwTerminateOSMesa();
freeLibraries(); freeLibraries();
} }
#endif // _GLFW_WIN32

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_WIN32)
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
@ -256,6 +256,8 @@ static GLFWbool supportsXInput(const GUID* guid)
// //
static void closeJoystick(_GLFWjoystick* js) static void closeJoystick(_GLFWjoystick* js)
{ {
_glfwInputJoystick(js, GLFW_DISCONNECTED);
if (js->win32.device) if (js->win32.device)
{ {
IDirectInputDevice8_Unacquire(js->win32.device); IDirectInputDevice8_Unacquire(js->win32.device);
@ -263,9 +265,7 @@ static void closeJoystick(_GLFWjoystick* js)
} }
_glfw_free(js->win32.objects); _glfw_free(js->win32.objects);
_glfwFreeJoystick(js); _glfwFreeJoystick(js);
_glfwInputJoystick(js, GLFW_DISCONNECTED);
} }
// DirectInput device object enumeration callback // DirectInput device object enumeration callback
@ -357,7 +357,7 @@ static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user)
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{ {
js = _glfw.joysticks + jid; js = _glfw.joysticks + jid;
if (js->present) if (js->connected)
{ {
if (memcmp(&js->win32.guid, &di->guidInstance, sizeof(GUID)) == 0) if (memcmp(&js->win32.guid, &di->guidInstance, sizeof(GUID)) == 0)
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
@ -508,7 +508,7 @@ void _glfwDetectJoystickConnectionWin32(void)
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{ {
if (_glfw.joysticks[jid].present && if (_glfw.joysticks[jid].connected &&
_glfw.joysticks[jid].win32.device == NULL && _glfw.joysticks[jid].win32.device == NULL &&
_glfw.joysticks[jid].win32.index == index) _glfw.joysticks[jid].win32.index == index)
{ {
@ -560,7 +560,7 @@ void _glfwDetectJoystickDisconnectionWin32(void)
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{ {
_GLFWjoystick* js = _glfw.joysticks + jid; _GLFWjoystick* js = _glfw.joysticks + jid;
if (js->present) if (js->connected)
_glfwPollJoystickWin32(js, _GLFW_POLL_PRESENCE); _glfwPollJoystickWin32(js, _GLFW_POLL_PRESENCE);
} }
} }
@ -574,7 +574,7 @@ GLFWbool _glfwInitJoysticksWin32(void)
{ {
if (_glfw.win32.dinput8.instance) if (_glfw.win32.dinput8.instance)
{ {
if (FAILED(DirectInput8Create(GetModuleHandle(NULL), if (FAILED(DirectInput8Create(_glfw.win32.instance,
DIRECTINPUT_VERSION, DIRECTINPUT_VERSION,
&IID_IDirectInput8W, &IID_IDirectInput8W,
(void**) &_glfw.win32.dinput8.api, (void**) &_glfw.win32.dinput8.api,
@ -601,13 +601,13 @@ void _glfwTerminateJoysticksWin32(void)
IDirectInput8_Release(_glfw.win32.dinput8.api); IDirectInput8_Release(_glfw.win32.dinput8.api);
} }
int _glfwPollJoystickWin32(_GLFWjoystick* js, int mode) GLFWbool _glfwPollJoystickWin32(_GLFWjoystick* js, int mode)
{ {
if (js->win32.device) if (js->win32.device)
{ {
int i, ai = 0, bi = 0, pi = 0; int i, ai = 0, bi = 0, pi = 0;
HRESULT result; HRESULT result;
DIJOYSTATE state; DIJOYSTATE state = {0};
IDirectInputDevice8_Poll(js->win32.device); IDirectInputDevice8_Poll(js->win32.device);
result = IDirectInputDevice8_GetDeviceState(js->win32.device, result = IDirectInputDevice8_GetDeviceState(js->win32.device,
@ -734,6 +734,13 @@ int _glfwPollJoystickWin32(_GLFWjoystick* js, int mode)
if (xis.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) if (xis.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT)
dpad |= GLFW_HAT_LEFT; dpad |= GLFW_HAT_LEFT;
// Treat invalid combinations as neither being pressed
// while preserving what data can be preserved
if ((dpad & GLFW_HAT_RIGHT) && (dpad & GLFW_HAT_LEFT))
dpad &= ~(GLFW_HAT_RIGHT | GLFW_HAT_LEFT);
if ((dpad & GLFW_HAT_UP) && (dpad & GLFW_HAT_DOWN))
dpad &= ~(GLFW_HAT_UP | GLFW_HAT_DOWN);
_glfwInputJoystickHat(js, 0, dpad); _glfwInputJoystickHat(js, 0, dpad);
} }
@ -756,3 +763,5 @@ void _glfwUpdateGamepadGUIDWin32(char* guid)
} }
} }
#endif // _GLFW_WIN32

View File

@ -27,8 +27,6 @@
#define GLFW_WIN32_JOYSTICK_STATE _GLFWjoystickWin32 win32; #define GLFW_WIN32_JOYSTICK_STATE _GLFWjoystickWin32 win32;
#define GLFW_WIN32_LIBRARY_JOYSTICK_STATE #define GLFW_WIN32_LIBRARY_JOYSTICK_STATE
#define GLFW_BUILD_WIN32_MAPPINGS
// Joystick element (axis, button or slider) // Joystick element (axis, button or slider)
// //
typedef struct _GLFWjoyobjectWin32 typedef struct _GLFWjoyobjectWin32

View File

@ -23,11 +23,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(GLFW_BUILD_WIN32_MODULE)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW platform API ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -47,3 +47,5 @@ GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name)
return (GLFWproc) GetProcAddress((HMODULE) module, name); return (GLFWproc) GetProcAddress((HMODULE) module, name);
} }
#endif // GLFW_BUILD_WIN32_MODULE

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_WIN32)
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
@ -381,7 +381,7 @@ void _glfwGetMonitorWorkareaWin32(_GLFWmonitor* monitor,
int* width, int* height) int* width, int* height)
{ {
MONITORINFO mi = { sizeof(mi) }; MONITORINFO mi = { sizeof(mi) };
GetMonitorInfo(monitor->win32.handle, &mi); GetMonitorInfoW(monitor->win32.handle, &mi);
if (xpos) if (xpos)
*xpos = mi.rcWork.left; *xpos = mi.rcWork.left;
@ -545,3 +545,5 @@ GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* handle)
return monitor->win32.publicDisplayName; return monitor->win32.publicDisplayName;
} }
#endif // _GLFW_WIN32

View File

@ -162,7 +162,9 @@ typedef enum
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((HANDLE) -4) #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((HANDLE) -4)
#endif /*DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2*/ #endif /*DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2*/
// HACK: Define versionhelpers.h functions manually as MinGW lacks the header // Replacement for versionhelpers.h macros, as we cannot rely on the
// application having a correct embedded manifest
//
#define IsWindowsVistaOrGreater() \ #define IsWindowsVistaOrGreater() \
_glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_VISTA), \ _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_VISTA), \
LOBYTE(_WIN32_WINNT_VISTA), 0) LOBYTE(_WIN32_WINNT_VISTA), 0)
@ -176,9 +178,11 @@ typedef enum
_glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WINBLUE), \ _glfwIsWindowsVersionOrGreaterWin32(HIBYTE(_WIN32_WINNT_WINBLUE), \
LOBYTE(_WIN32_WINNT_WINBLUE), 0) LOBYTE(_WIN32_WINNT_WINBLUE), 0)
#define _glfwIsWindows10AnniversaryUpdateOrGreaterWin32() \ // Windows 10 Anniversary Update
#define _glfwIsWindows10Version1607OrGreaterWin32() \
_glfwIsWindows10BuildOrGreaterWin32(14393) _glfwIsWindows10BuildOrGreaterWin32(14393)
#define _glfwIsWindows10CreatorsUpdateOrGreaterWin32() \ // Windows 10 Creators Update
#define _glfwIsWindows10Version1703OrGreaterWin32() \
_glfwIsWindows10BuildOrGreaterWin32(15063) _glfwIsWindows10BuildOrGreaterWin32(15063)
// HACK: Define macros that some xinput.h variants don't // HACK: Define macros that some xinput.h variants don't
@ -283,12 +287,14 @@ typedef BOOL (WINAPI * PFN_EnableNonClientDpiScaling)(HWND);
typedef BOOL (WINAPI * PFN_SetProcessDpiAwarenessContext)(HANDLE); typedef BOOL (WINAPI * PFN_SetProcessDpiAwarenessContext)(HANDLE);
typedef UINT (WINAPI * PFN_GetDpiForWindow)(HWND); typedef UINT (WINAPI * PFN_GetDpiForWindow)(HWND);
typedef BOOL (WINAPI * PFN_AdjustWindowRectExForDpi)(LPRECT,DWORD,BOOL,DWORD,UINT); typedef BOOL (WINAPI * PFN_AdjustWindowRectExForDpi)(LPRECT,DWORD,BOOL,DWORD,UINT);
typedef int (WINAPI * PFN_GetSystemMetricsForDpi)(int,UINT);
#define SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware_ #define SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware_
#define ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx_ #define ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx_
#define EnableNonClientDpiScaling _glfw.win32.user32.EnableNonClientDpiScaling_ #define EnableNonClientDpiScaling _glfw.win32.user32.EnableNonClientDpiScaling_
#define SetProcessDpiAwarenessContext _glfw.win32.user32.SetProcessDpiAwarenessContext_ #define SetProcessDpiAwarenessContext _glfw.win32.user32.SetProcessDpiAwarenessContext_
#define GetDpiForWindow _glfw.win32.user32.GetDpiForWindow_ #define GetDpiForWindow _glfw.win32.user32.GetDpiForWindow_
#define AdjustWindowRectExForDpi _glfw.win32.user32.AdjustWindowRectExForDpi_ #define AdjustWindowRectExForDpi _glfw.win32.user32.AdjustWindowRectExForDpi_
#define GetSystemMetricsForDpi _glfw.win32.user32.GetSystemMetricsForDpi_
// dwmapi.dll function pointer typedefs // dwmapi.dll function pointer typedefs
typedef HRESULT (WINAPI * PFN_DwmIsCompositionEnabled)(BOOL*); typedef HRESULT (WINAPI * PFN_DwmIsCompositionEnabled)(BOOL*);
@ -352,10 +358,6 @@ typedef struct VkWin32SurfaceCreateInfoKHR
typedef VkResult (APIENTRY *PFN_vkCreateWin32SurfaceKHR)(VkInstance,const VkWin32SurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); typedef VkResult (APIENTRY *PFN_vkCreateWin32SurfaceKHR)(VkInstance,const VkWin32SurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*);
typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice,uint32_t); typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice,uint32_t);
#if !defined(_GLFW_WNDCLASSNAME)
#define _GLFW_WNDCLASSNAME L"GLFW30"
#endif
#define GLFW_WIN32_WINDOW_STATE _GLFWwindowWin32 win32; #define GLFW_WIN32_WINDOW_STATE _GLFWwindowWin32 win32;
#define GLFW_WIN32_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32; #define GLFW_WIN32_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32;
#define GLFW_WIN32_MONITOR_STATE _GLFWmonitorWin32 win32; #define GLFW_WIN32_MONITOR_STATE _GLFWmonitorWin32 win32;
@ -436,7 +438,10 @@ typedef struct _GLFWwindowWin32
// //
typedef struct _GLFWlibraryWin32 typedef struct _GLFWlibraryWin32
{ {
HINSTANCE instance;
HWND helperWindowHandle; HWND helperWindowHandle;
ATOM helperWindowClass;
ATOM mainWindowClass;
HDEVNOTIFY deviceNotificationHandle; HDEVNOTIFY deviceNotificationHandle;
int acquiredMonitorCount; int acquiredMonitorCount;
char* clipboardString; char* clipboardString;
@ -447,6 +452,8 @@ typedef struct _GLFWlibraryWin32
double restoreCursorPosX, restoreCursorPosY; double restoreCursorPosX, restoreCursorPosY;
// The window whose disabled cursor mode is active // The window whose disabled cursor mode is active
_GLFWwindow* disabledCursorWindow; _GLFWwindow* disabledCursorWindow;
// The window the cursor is captured in
_GLFWwindow* capturedCursorWindow;
RAWINPUT* rawInput; RAWINPUT* rawInput;
int rawInputSize; int rawInputSize;
UINT mouseTrailSize; UINT mouseTrailSize;
@ -471,6 +478,7 @@ typedef struct _GLFWlibraryWin32
PFN_SetProcessDpiAwarenessContext SetProcessDpiAwarenessContext_; PFN_SetProcessDpiAwarenessContext SetProcessDpiAwarenessContext_;
PFN_GetDpiForWindow GetDpiForWindow_; PFN_GetDpiForWindow GetDpiForWindow_;
PFN_AdjustWindowRectExForDpi AdjustWindowRectExForDpi_; PFN_AdjustWindowRectExForDpi AdjustWindowRectExForDpi_;
PFN_GetSystemMetricsForDpi GetSystemMetricsForDpi_;
} user32; } user32;
struct { struct {
@ -519,9 +527,6 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform);
int _glfwInitWin32(void); int _glfwInitWin32(void);
void _glfwTerminateWin32(void); void _glfwTerminateWin32(void);
GLFWbool _glfwRegisterWindowClassWin32(void);
void _glfwUnregisterWindowClassWin32(void);
WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source); WCHAR* _glfwCreateWideStringFromUTF8Win32(const char* source);
char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source); char* _glfwCreateUTF8FromWideStringWin32(const WCHAR* source);
BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp); BOOL _glfwIsWindowsVersionOrGreaterWin32(WORD major, WORD minor, WORD sp);
@ -534,7 +539,7 @@ void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor); void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor);
void _glfwGetHMONITORContentScaleWin32(HMONITOR handle, float* xscale, float* yscale); void _glfwGetHMONITORContentScaleWin32(HMONITOR handle, float* xscale, float* yscale);
int _glfwCreateWindowWin32(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); GLFWbool _glfwCreateWindowWin32(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowWin32(_GLFWwindow* window); void _glfwDestroyWindowWin32(_GLFWwindow* window);
void _glfwSetWindowTitleWin32(_GLFWwindow* window, const char* title); void _glfwSetWindowTitleWin32(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconWin32(_GLFWwindow* window, int count, const GLFWimage* images); void _glfwSetWindowIconWin32(_GLFWwindow* window, int count, const GLFWimage* images);
@ -555,12 +560,12 @@ void _glfwHideWindowWin32(_GLFWwindow* window);
void _glfwRequestWindowAttentionWin32(_GLFWwindow* window); void _glfwRequestWindowAttentionWin32(_GLFWwindow* window);
void _glfwFocusWindowWin32(_GLFWwindow* window); void _glfwFocusWindowWin32(_GLFWwindow* window);
void _glfwSetWindowMonitorWin32(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); void _glfwSetWindowMonitorWin32(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
int _glfwWindowFocusedWin32(_GLFWwindow* window); GLFWbool _glfwWindowFocusedWin32(_GLFWwindow* window);
int _glfwWindowIconifiedWin32(_GLFWwindow* window); GLFWbool _glfwWindowIconifiedWin32(_GLFWwindow* window);
int _glfwWindowVisibleWin32(_GLFWwindow* window); GLFWbool _glfwWindowVisibleWin32(_GLFWwindow* window);
int _glfwWindowMaximizedWin32(_GLFWwindow* window); GLFWbool _glfwWindowMaximizedWin32(_GLFWwindow* window);
int _glfwWindowHoveredWin32(_GLFWwindow* window); GLFWbool _glfwWindowHoveredWin32(_GLFWwindow* window);
int _glfwFramebufferTransparentWin32(_GLFWwindow* window); GLFWbool _glfwFramebufferTransparentWin32(_GLFWwindow* window);
void _glfwSetWindowResizableWin32(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowResizableWin32(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowDecoratedWin32(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowDecoratedWin32(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowFloatingWin32(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowFloatingWin32(_GLFWwindow* window, GLFWbool enabled);
@ -584,8 +589,8 @@ void _glfwSetCursorPosWin32(_GLFWwindow* window, double xpos, double ypos);
void _glfwSetCursorModeWin32(_GLFWwindow* window, int mode); void _glfwSetCursorModeWin32(_GLFWwindow* window, int mode);
const char* _glfwGetScancodeNameWin32(int scancode); const char* _glfwGetScancodeNameWin32(int scancode);
int _glfwGetKeyScancodeWin32(int key); int _glfwGetKeyScancodeWin32(int key);
int _glfwCreateCursorWin32(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); GLFWbool _glfwCreateCursorWin32(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot);
int _glfwCreateStandardCursorWin32(_GLFWcursor* cursor, int shape); GLFWbool _glfwCreateStandardCursorWin32(_GLFWcursor* cursor, int shape);
void _glfwDestroyCursorWin32(_GLFWcursor* cursor); void _glfwDestroyCursorWin32(_GLFWcursor* cursor);
void _glfwSetCursorWin32(_GLFWwindow* window, _GLFWcursor* cursor); void _glfwSetCursorWin32(_GLFWwindow* window, _GLFWcursor* cursor);
void _glfwSetClipboardStringWin32(const char* string); void _glfwSetClipboardStringWin32(const char* string);
@ -596,7 +601,7 @@ EGLNativeDisplayType _glfwGetEGLNativeDisplayWin32(void);
EGLNativeWindowType _glfwGetEGLNativeWindowWin32(_GLFWwindow* window); EGLNativeWindowType _glfwGetEGLNativeWindowWin32(_GLFWwindow* window);
void _glfwGetRequiredInstanceExtensionsWin32(char** extensions); void _glfwGetRequiredInstanceExtensionsWin32(char** extensions);
int _glfwGetPhysicalDevicePresentationSupportWin32(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); GLFWbool _glfwGetPhysicalDevicePresentationSupportWin32(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
VkResult _glfwCreateWindowSurfaceWin32(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); VkResult _glfwCreateWindowSurfaceWin32(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
void _glfwFreeMonitorWin32(_GLFWmonitor* monitor); void _glfwFreeMonitorWin32(_GLFWmonitor* monitor);
@ -610,7 +615,7 @@ void _glfwSetGammaRampWin32(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
GLFWbool _glfwInitJoysticksWin32(void); GLFWbool _glfwInitJoysticksWin32(void);
void _glfwTerminateJoysticksWin32(void); void _glfwTerminateJoysticksWin32(void);
int _glfwPollJoystickWin32(_GLFWjoystick* js, int mode); GLFWbool _glfwPollJoystickWin32(_GLFWjoystick* js, int mode);
const char* _glfwGetMappingNameWin32(void); const char* _glfwGetMappingNameWin32(void);
void _glfwUpdateGamepadGUIDWin32(char* guid); void _glfwUpdateGamepadGUIDWin32(char* guid);

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(GLFW_BUILD_WIN32_THREAD)
#include <assert.h> #include <assert.h>
@ -96,3 +96,5 @@ void _glfwPlatformUnlockMutex(_GLFWmutex* mutex)
LeaveCriticalSection(&mutex->win32.section); LeaveCriticalSection(&mutex->win32.section);
} }
#endif // GLFW_BUILD_WIN32_THREAD

View File

@ -25,6 +25,11 @@
// //
//======================================================================== //========================================================================
// This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
// example to allow applications to correctly declare a GL_KHR_debug callback)
// but windows.h assumes no one will define APIENTRY before it does
#undef APIENTRY
#include <windows.h> #include <windows.h>
#define GLFW_WIN32_TLS_STATE _GLFWtlsWin32 win32; #define GLFW_WIN32_TLS_STATE _GLFWtlsWin32 win32;

View File

@ -24,11 +24,10 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(GLFW_BUILD_WIN32_TIMER)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW platform API ////// ////// GLFW platform API //////
@ -51,3 +50,5 @@ uint64_t _glfwPlatformGetTimerFrequency(void)
return _glfw.timer.win32.frequency; return _glfw.timer.win32.frequency;
} }
#endif // GLFW_BUILD_WIN32_TIMER

View File

@ -25,6 +25,11 @@
// //
//======================================================================== //========================================================================
// This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
// example to allow applications to correctly declare a GL_KHR_debug callback)
// but windows.h assumes no one will define APIENTRY before it does
#undef APIENTRY
#include <windows.h> #include <windows.h>
#define GLFW_WIN32_LIBRARY_TIMER_STATE _GLFWtimerWin32 win32; #define GLFW_WIN32_LIBRARY_TIMER_STATE _GLFWtimerWin32 win32;

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_WIN32)
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -98,8 +98,7 @@ static const GLFWimage* chooseImage(int count, const GLFWimage* images,
// Creates an RGBA icon or cursor // Creates an RGBA icon or cursor
// //
static HICON createIcon(const GLFWimage* image, static HICON createIcon(const GLFWimage* image, int xhot, int yhot, GLFWbool icon)
int xhot, int yhot, GLFWbool icon)
{ {
int i; int i;
HDC dc; HDC dc;
@ -186,53 +185,38 @@ static HICON createIcon(const GLFWimage* image,
return handle; return handle;
} }
// Translate content area size to full window size according to styles and DPI
//
static void getFullWindowSize(DWORD style, DWORD exStyle,
int contentWidth, int contentHeight,
int* fullWidth, int* fullHeight,
UINT dpi)
{
RECT rect = { 0, 0, contentWidth, contentHeight };
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
AdjustWindowRectExForDpi(&rect, style, FALSE, exStyle, dpi);
else
AdjustWindowRectEx(&rect, style, FALSE, exStyle);
*fullWidth = rect.right - rect.left;
*fullHeight = rect.bottom - rect.top;
}
// Enforce the content area aspect ratio based on which edge is being dragged // Enforce the content area aspect ratio based on which edge is being dragged
// //
static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area) static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area)
{ {
int xoff, yoff; RECT frame = {0};
UINT dpi = USER_DEFAULT_SCREEN_DPI;
const float ratio = (float) window->numer / (float) window->denom; const float ratio = (float) window->numer / (float) window->denom;
const DWORD style = getWindowStyle(window);
const DWORD exStyle = getWindowExStyle(window);
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32()) if (_glfwIsWindows10Version1607OrGreaterWin32())
dpi = GetDpiForWindow(window->win32.handle); {
AdjustWindowRectExForDpi(&frame, style, FALSE, exStyle,
getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), GetDpiForWindow(window->win32.handle));
0, 0, &xoff, &yoff, dpi); }
else
AdjustWindowRectEx(&frame, style, FALSE, exStyle);
if (edge == WMSZ_LEFT || edge == WMSZ_BOTTOMLEFT || if (edge == WMSZ_LEFT || edge == WMSZ_BOTTOMLEFT ||
edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT) edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT)
{ {
area->bottom = area->top + yoff + area->bottom = area->top + (frame.bottom - frame.top) +
(int) ((area->right - area->left - xoff) / ratio); (int) (((area->right - area->left) - (frame.right - frame.left)) / ratio);
} }
else if (edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT) else if (edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT)
{ {
area->top = area->bottom - yoff - area->top = area->bottom - (frame.bottom - frame.top) -
(int) ((area->right - area->left - xoff) / ratio); (int) (((area->right - area->left) - (frame.right - frame.left)) / ratio);
} }
else if (edge == WMSZ_TOP || edge == WMSZ_BOTTOM) else if (edge == WMSZ_TOP || edge == WMSZ_BOTTOM)
{ {
area->right = area->left + xoff + area->right = area->left + (frame.right - frame.left) +
(int) ((area->bottom - area->top - yoff) * ratio); (int) (((area->bottom - area->top) - (frame.bottom - frame.top)) * ratio);
} }
} }
@ -240,7 +224,8 @@ static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area)
// //
static void updateCursorImage(_GLFWwindow* window) static void updateCursorImage(_GLFWwindow* window)
{ {
if (window->cursorMode == GLFW_CURSOR_NORMAL) if (window->cursorMode == GLFW_CURSOR_NORMAL ||
window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (window->cursor) if (window->cursor)
SetCursor(window->cursor->win32.handle); SetCursor(window->cursor->win32.handle);
@ -251,20 +236,24 @@ static void updateCursorImage(_GLFWwindow* window)
SetCursor(NULL); SetCursor(NULL);
} }
// Updates the cursor clip rect // Sets the cursor clip rect to the window content area
// //
static void updateClipRect(_GLFWwindow* window) static void captureCursor(_GLFWwindow* window)
{ {
if (window)
{
RECT clipRect; RECT clipRect;
GetClientRect(window->win32.handle, &clipRect); GetClientRect(window->win32.handle, &clipRect);
ClientToScreen(window->win32.handle, (POINT*) &clipRect.left); ClientToScreen(window->win32.handle, (POINT*) &clipRect.left);
ClientToScreen(window->win32.handle, (POINT*) &clipRect.right); ClientToScreen(window->win32.handle, (POINT*) &clipRect.right);
ClipCursor(&clipRect); ClipCursor(&clipRect);
} _glfw.win32.capturedCursorWindow = window;
else }
// Disabled clip cursor
//
static void releaseCursor(void)
{
ClipCursor(NULL); ClipCursor(NULL);
_glfw.win32.capturedCursorWindow = NULL;
} }
// Enables WM_INPUT messages for the mouse for the specified window // Enables WM_INPUT messages for the mouse for the specified window
@ -303,7 +292,7 @@ static void disableCursor(_GLFWwindow* window)
&_glfw.win32.restoreCursorPosY); &_glfw.win32.restoreCursorPosY);
updateCursorImage(window); updateCursorImage(window);
_glfwCenterCursorInContentArea(window); _glfwCenterCursorInContentArea(window);
updateClipRect(window); captureCursor(window);
if (window->rawMouseMotion) if (window->rawMouseMotion)
enableRawMouseMotion(window); enableRawMouseMotion(window);
@ -317,7 +306,7 @@ static void enableCursor(_GLFWwindow* window)
disableRawMouseMotion(window); disableRawMouseMotion(window);
_glfw.win32.disabledCursorWindow = NULL; _glfw.win32.disabledCursorWindow = NULL;
updateClipRect(NULL); releaseCursor();
_glfwSetCursorPosWin32(window, _glfwSetCursorPosWin32(window,
_glfw.win32.restoreCursorPosX, _glfw.win32.restoreCursorPosX,
_glfw.win32.restoreCursorPosY); _glfw.win32.restoreCursorPosY);
@ -355,7 +344,7 @@ static void updateWindowStyles(const _GLFWwindow* window)
GetClientRect(window->win32.handle, &rect); GetClientRect(window->win32.handle, &rect);
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32()) if (_glfwIsWindows10Version1607OrGreaterWin32())
{ {
AdjustWindowRectExForDpi(&rect, style, FALSE, AdjustWindowRectExForDpi(&rect, style, FALSE,
getWindowExStyle(window), getWindowExStyle(window),
@ -435,7 +424,7 @@ static int getKeyMods(void)
static void fitToMonitor(_GLFWwindow* window) static void fitToMonitor(_GLFWwindow* window)
{ {
MONITORINFO mi = { sizeof(mi) }; MONITORINFO mi = { sizeof(mi) };
GetMonitorInfo(window->monitor->win32.handle, &mi); GetMonitorInfoW(window->monitor->win32.handle, &mi);
SetWindowPos(window->win32.handle, HWND_TOPMOST, SetWindowPos(window->win32.handle, HWND_TOPMOST,
mi.rcMonitor.left, mi.rcMonitor.left,
mi.rcMonitor.top, mi.rcMonitor.top,
@ -454,8 +443,8 @@ static void acquireMonitor(_GLFWwindow* window)
// HACK: When mouse trails are enabled the cursor becomes invisible when // HACK: When mouse trails are enabled the cursor becomes invisible when
// the OpenGL ICD switches to page flipping // the OpenGL ICD switches to page flipping
SystemParametersInfo(SPI_GETMOUSETRAILS, 0, &_glfw.win32.mouseTrailSize, 0); SystemParametersInfoW(SPI_GETMOUSETRAILS, 0, &_glfw.win32.mouseTrailSize, 0);
SystemParametersInfo(SPI_SETMOUSETRAILS, 0, 0, 0); SystemParametersInfoW(SPI_SETMOUSETRAILS, 0, 0, 0);
} }
if (!window->monitor->window) if (!window->monitor->window)
@ -478,17 +467,66 @@ static void releaseMonitor(_GLFWwindow* window)
SetThreadExecutionState(ES_CONTINUOUS); SetThreadExecutionState(ES_CONTINUOUS);
// HACK: Restore mouse trail length saved in acquireMonitor // HACK: Restore mouse trail length saved in acquireMonitor
SystemParametersInfo(SPI_SETMOUSETRAILS, _glfw.win32.mouseTrailSize, 0, 0); SystemParametersInfoW(SPI_SETMOUSETRAILS, _glfw.win32.mouseTrailSize, 0, 0);
} }
_glfwInputMonitorWindow(window->monitor, NULL); _glfwInputMonitorWindow(window->monitor, NULL);
_glfwRestoreVideoModeWin32(window->monitor); _glfwRestoreVideoModeWin32(window->monitor);
} }
// Window callback function (handles window messages) // Manually maximize the window, for when SW_MAXIMIZE cannot be used
// //
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, static void maximizeWindowManually(_GLFWwindow* window)
WPARAM wParam, LPARAM lParam) {
RECT rect;
DWORD style;
MONITORINFO mi = { sizeof(mi) };
GetMonitorInfoW(MonitorFromWindow(window->win32.handle,
MONITOR_DEFAULTTONEAREST), &mi);
rect = mi.rcWork;
if (window->maxwidth != GLFW_DONT_CARE && window->maxheight != GLFW_DONT_CARE)
{
rect.right = _glfw_min(rect.right, rect.left + window->maxwidth);
rect.bottom = _glfw_min(rect.bottom, rect.top + window->maxheight);
}
style = GetWindowLongW(window->win32.handle, GWL_STYLE);
style |= WS_MAXIMIZE;
SetWindowLongW(window->win32.handle, GWL_STYLE, style);
if (window->decorated)
{
const DWORD exStyle = GetWindowLongW(window->win32.handle, GWL_EXSTYLE);
if (_glfwIsWindows10Version1607OrGreaterWin32())
{
const UINT dpi = GetDpiForWindow(window->win32.handle);
AdjustWindowRectExForDpi(&rect, style, FALSE, exStyle, dpi);
OffsetRect(&rect, 0, GetSystemMetricsForDpi(SM_CYCAPTION, dpi));
}
else
{
AdjustWindowRectEx(&rect, style, FALSE, exStyle);
OffsetRect(&rect, 0, GetSystemMetrics(SM_CYCAPTION));
}
rect.bottom = _glfw_min(rect.bottom, mi.rcWork.bottom);
}
SetWindowPos(window->win32.handle, HWND_TOP,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
// Window procedure for user-created windows
//
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
static RECT border_thickness = { 4, 4, 4, 4 }; static RECT border_thickness = { 4, 4, 4, 4 };
BOOL hasThickFrame = GetWindowLongPtr(hWnd, GWL_STYLE) & WS_THICKFRAME; BOOL hasThickFrame = GetWindowLongPtr(hWnd, GWL_STYLE) & WS_THICKFRAME;
@ -496,14 +534,9 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
_GLFWwindow* window = GetPropW(hWnd, L"GLFW"); _GLFWwindow* window = GetPropW(hWnd, L"GLFW");
if (!window) if (!window)
{ {
// This is the message handling for the hidden helper window if (uMsg == WM_NCCREATE)
// and for a regular window during its initial creation
switch (uMsg)
{ {
case WM_NCCREATE: if (_glfwIsWindows10Version1607OrGreaterWin32())
{
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
{ {
const CREATESTRUCTW* cs = (const CREATESTRUCTW*) lParam; const CREATESTRUCTW* cs = (const CREATESTRUCTW*) lParam;
const _GLFWwndconfig* wndconfig = cs->lpCreateParams; const _GLFWwndconfig* wndconfig = cs->lpCreateParams;
@ -516,34 +549,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
EnableNonClientDpiScaling(hWnd); EnableNonClientDpiScaling(hWnd);
} }
break;
}
case WM_DISPLAYCHANGE:
_glfwPollMonitorsWin32();
break;
case WM_DEVICECHANGE:
{
if (!_glfw.joysticksInitialized)
break;
if (wParam == DBT_DEVICEARRIVAL)
{
DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam;
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
_glfwDetectJoystickConnectionWin32();
}
else if (wParam == DBT_DEVICEREMOVECOMPLETE)
{
DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam;
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
_glfwDetectJoystickDisconnectionWin32();
}
break;
}
case WM_CREATE: case WM_CREATE:
{ {
if (_glfw.hints.window.titlebar) if (_glfw.hints.window.titlebar)
@ -605,6 +610,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
{ {
if (window->cursorMode == GLFW_CURSOR_DISABLED) if (window->cursorMode == GLFW_CURSOR_DISABLED)
disableCursor(window); disableCursor(window);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
captureCursor(window);
window->win32.frameAction = GLFW_FALSE; window->win32.frameAction = GLFW_FALSE;
} }
@ -623,6 +630,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (window->cursorMode == GLFW_CURSOR_DISABLED) if (window->cursorMode == GLFW_CURSOR_DISABLED)
disableCursor(window); disableCursor(window);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
captureCursor(window);
return 0; return 0;
} }
@ -631,6 +640,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
{ {
if (window->cursorMode == GLFW_CURSOR_DISABLED) if (window->cursorMode == GLFW_CURSOR_DISABLED)
enableCursor(window); enableCursor(window);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
releaseCursor();
if (window->monitor && window->autoIconify) if (window->monitor && window->autoIconify)
_glfwIconifyWindowWin32(window); _glfwIconifyWindowWin32(window);
@ -742,6 +753,18 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
scancode = MapVirtualKeyW((UINT) wParam, MAPVK_VK_TO_VSC); scancode = MapVirtualKeyW((UINT) wParam, MAPVK_VK_TO_VSC);
} }
// HACK: Alt+PrtSc has a different scancode than just PrtSc
if (scancode == 0x54)
scancode = 0x137;
// HACK: Ctrl+Pause has a different scancode than just Pause
if (scancode == 0x146)
scancode = 0x45;
// HACK: CJK IME sets the extended bit for right Shift
if (scancode == 0x136)
scancode = 0x36;
key = _glfw.win32.keycodes[scancode]; key = _glfw.win32.keycodes[scancode];
// The Ctrl keys require special handling // The Ctrl keys require special handling
@ -988,6 +1011,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
// resizing the window or using the window menu // resizing the window or using the window menu
if (window->cursorMode == GLFW_CURSOR_DISABLED) if (window->cursorMode == GLFW_CURSOR_DISABLED)
enableCursor(window); enableCursor(window);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
releaseCursor();
break; break;
} }
@ -1002,6 +1027,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
// resizing the window or using the menu // resizing the window or using the menu
if (window->cursorMode == GLFW_CURSOR_DISABLED) if (window->cursorMode == GLFW_CURSOR_DISABLED)
disableCursor(window); disableCursor(window);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
captureCursor(window);
break; break;
} }
@ -1057,8 +1084,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
(window->win32.maximized && (window->win32.maximized &&
wParam != SIZE_RESTORED); wParam != SIZE_RESTORED);
if (_glfw.win32.disabledCursorWindow == window) if (_glfw.win32.capturedCursorWindow == window)
updateClipRect(window); captureCursor(window);
if (window->win32.iconified != iconified) if (window->win32.iconified != iconified)
_glfwInputWindowIconify(window, iconified); _glfwInputWindowIconify(window, iconified);
@ -1105,8 +1132,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_MOVE: case WM_MOVE:
{ {
if (_glfw.win32.disabledCursorWindow == window) if (_glfw.win32.capturedCursorWindow == window)
updateClipRect(window); captureCursor(window);
// NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as // NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as
// those macros do not handle negative window positions correctly // those macros do not handle negative window positions correctly
@ -1130,31 +1157,34 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_GETMINMAXINFO: case WM_GETMINMAXINFO:
{ {
int xoff, yoff; RECT frame = {0};
UINT dpi = USER_DEFAULT_SCREEN_DPI;
MINMAXINFO* mmi = (MINMAXINFO*) lParam; MINMAXINFO* mmi = (MINMAXINFO*) lParam;
const DWORD style = getWindowStyle(window);
const DWORD exStyle = getWindowExStyle(window);
if (window->monitor) if (window->monitor)
break; break;
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32()) if (_glfwIsWindows10Version1607OrGreaterWin32())
dpi = GetDpiForWindow(window->win32.handle); {
AdjustWindowRectExForDpi(&frame, style, FALSE, exStyle,
getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), GetDpiForWindow(window->win32.handle));
0, 0, &xoff, &yoff, dpi); }
else
AdjustWindowRectEx(&frame, style, FALSE, exStyle);
if (window->minwidth != GLFW_DONT_CARE && if (window->minwidth != GLFW_DONT_CARE &&
window->minheight != GLFW_DONT_CARE) window->minheight != GLFW_DONT_CARE)
{ {
mmi->ptMinTrackSize.x = window->minwidth + xoff; mmi->ptMinTrackSize.x = window->minwidth + frame.right - frame.left;
mmi->ptMinTrackSize.y = window->minheight + yoff; mmi->ptMinTrackSize.y = window->minheight + frame.bottom - frame.top;
} }
if (window->maxwidth != GLFW_DONT_CARE && if (window->maxwidth != GLFW_DONT_CARE &&
window->maxheight != GLFW_DONT_CARE) window->maxheight != GLFW_DONT_CARE)
{ {
mmi->ptMaxTrackSize.x = window->maxwidth + xoff; mmi->ptMaxTrackSize.x = window->maxwidth + frame.right - frame.left;
mmi->ptMaxTrackSize.y = window->maxheight + yoff; mmi->ptMaxTrackSize.y = window->maxheight + frame.bottom - frame.top;
} }
if (!window->decorated) if (!window->decorated)
@ -1165,7 +1195,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
ZeroMemory(&mi, sizeof(mi)); ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi); mi.cbSize = sizeof(mi);
GetMonitorInfo(mh, &mi); GetMonitorInfoW(mh, &mi);
mmi->ptMaxPosition.x = mi.rcWork.left - mi.rcMonitor.left; mmi->ptMaxPosition.x = mi.rcWork.left - mi.rcMonitor.left;
mmi->ptMaxPosition.y = mi.rcWork.top - mi.rcMonitor.top; mmi->ptMaxPosition.y = mi.rcWork.top - mi.rcMonitor.top;
@ -1212,7 +1242,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
break; break;
// Adjust the window size to keep the content area size constant // Adjust the window size to keep the content area size constant
if (_glfwIsWindows10CreatorsUpdateOrGreaterWin32()) if (_glfwIsWindows10Version1703OrGreaterWin32())
{ {
RECT source = {0}, target = {0}; RECT source = {0}, target = {0};
SIZE* size = (SIZE*) lParam; SIZE* size = (SIZE*) lParam;
@ -1243,7 +1273,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
// need it to compensate for non-client area scaling // need it to compensate for non-client area scaling
if (!window->monitor && if (!window->monitor &&
(window->win32.scaleToMonitor || (window->win32.scaleToMonitor ||
_glfwIsWindows10CreatorsUpdateOrGreaterWin32())) _glfwIsWindows10Version1703OrGreaterWin32()))
{ {
RECT* suggested = (RECT*) lParam; RECT* suggested = (RECT*) lParam;
SetWindowPos(window->win32.handle, HWND_TOP, SetWindowPos(window->win32.handle, HWND_TOP,
@ -1371,36 +1401,80 @@ static int createNativeWindow(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig, const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
{ {
int xpos, ypos, fullWidth, fullHeight; int frameX, frameY, frameWidth, frameHeight;
WCHAR* wideTitle; WCHAR* wideTitle;
DWORD style = getWindowStyle(window); DWORD style = getWindowStyle(window);
DWORD exStyle = getWindowExStyle(window); DWORD exStyle = getWindowExStyle(window);
if (!_glfw.win32.mainWindowClass)
{
WNDCLASSEXW wc = { sizeof(wc) };
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = windowProc;
wc.hInstance = _glfw.win32.instance;
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
#if defined(_GLFW_WNDCLASSNAME)
wc.lpszClassName = _GLFW_WNDCLASSNAME;
#else
wc.lpszClassName = L"GLFW30";
#endif
// Load user-provided icon if available
wc.hIcon = LoadImageW(GetModuleHandleW(NULL),
L"GLFW_ICON", IMAGE_ICON,
0, 0, LR_DEFAULTSIZE | LR_SHARED);
if (!wc.hIcon)
{
// No user-provided icon found, load default icon
wc.hIcon = LoadImageW(NULL,
IDI_APPLICATION, IMAGE_ICON,
0, 0, LR_DEFAULTSIZE | LR_SHARED);
}
_glfw.win32.mainWindowClass = RegisterClassExW(&wc);
if (!_glfw.win32.mainWindowClass)
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to register window class");
return GLFW_FALSE;
}
}
if (window->monitor) if (window->monitor)
{ {
GLFWvidmode mode; MONITORINFO mi = { sizeof(mi) };
GetMonitorInfoW(window->monitor->win32.handle, &mi);
// NOTE: This window placement is temporary and approximate, as the // NOTE: This window placement is temporary and approximate, as the
// correct position and size cannot be known until the monitor // correct position and size cannot be known until the monitor
// video mode has been picked in _glfwSetVideoModeWin32 // video mode has been picked in _glfwSetVideoModeWin32
_glfwGetMonitorPosWin32(window->monitor, &xpos, &ypos); frameX = mi.rcMonitor.left;
_glfwGetVideoModeWin32(window->monitor, &mode); frameY = mi.rcMonitor.top;
fullWidth = mode.width; frameWidth = mi.rcMonitor.right - mi.rcMonitor.left;
fullHeight = mode.height; frameHeight = mi.rcMonitor.bottom - mi.rcMonitor.top;
} }
else else
{ {
xpos = CW_USEDEFAULT; RECT rect = { 0, 0, wndconfig->width, wndconfig->height };
ypos = CW_USEDEFAULT;
window->win32.maximized = wndconfig->maximized; window->win32.maximized = wndconfig->maximized;
if (wndconfig->maximized) if (wndconfig->maximized)
style |= WS_MAXIMIZE; style |= WS_MAXIMIZE;
getFullWindowSize(style, exStyle, AdjustWindowRectEx(&rect, style, FALSE, exStyle);
wndconfig->width, wndconfig->height,
&fullWidth, &fullHeight, if (wndconfig->xpos == GLFW_ANY_POSITION && wndconfig->ypos == GLFW_ANY_POSITION)
USER_DEFAULT_SCREEN_DPI); {
frameX = CW_USEDEFAULT;
frameY = CW_USEDEFAULT;
}
else
{
frameX = wndconfig->xpos + rect.left;
frameY = wndconfig->ypos + rect.top;
}
frameWidth = rect.right - rect.left;
frameHeight = rect.bottom - rect.top;
} }
wideTitle = _glfwCreateWideStringFromUTF8Win32(wndconfig->title); wideTitle = _glfwCreateWideStringFromUTF8Win32(wndconfig->title);
@ -1408,14 +1482,14 @@ static int createNativeWindow(_GLFWwindow* window,
return GLFW_FALSE; return GLFW_FALSE;
window->win32.handle = CreateWindowExW(exStyle, window->win32.handle = CreateWindowExW(exStyle,
_GLFW_WNDCLASSNAME, MAKEINTATOM(_glfw.win32.mainWindowClass),
wideTitle, wideTitle,
style, style,
xpos, ypos, frameX, frameY,
fullWidth, fullHeight, frameWidth, frameHeight,
NULL, // No parent window NULL, // No parent window
NULL, // No window menu NULL, // No window menu
GetModuleHandleW(NULL), _glfw.win32.instance,
(LPVOID) wndconfig); (LPVOID) wndconfig);
_glfw_free(wideTitle); _glfw_free(wideTitle);
@ -1442,18 +1516,22 @@ static int createNativeWindow(_GLFWwindow* window,
window->win32.scaleToMonitor = wndconfig->scaleToMonitor; window->win32.scaleToMonitor = wndconfig->scaleToMonitor;
window->win32.keymenu = wndconfig->win32.keymenu; window->win32.keymenu = wndconfig->win32.keymenu;
// Adjust window rect to account for DPI scaling of the window frame and
// (if enabled) DPI scaling of the content area
// This cannot be done until we know what monitor the window was placed on
if (!window->monitor) if (!window->monitor)
{ {
RECT rect = { 0, 0, wndconfig->width, wndconfig->height }; RECT rect = { 0, 0, wndconfig->width, wndconfig->height };
WINDOWPLACEMENT wp = { sizeof(wp) }; WINDOWPLACEMENT wp = { sizeof(wp) };
const HMONITOR mh = MonitorFromWindow(window->win32.handle,
MONITOR_DEFAULTTONEAREST);
// Adjust window rect to account for DPI scaling of the window frame and
// (if enabled) DPI scaling of the content area
// This cannot be done until we know what monitor the window was placed on
// Only update the restored window rect as the window may be maximized
if (wndconfig->scaleToMonitor) if (wndconfig->scaleToMonitor)
{ {
float xscale, yscale; float xscale, yscale;
_glfwGetWindowContentScaleWin32(window, &xscale, &yscale); _glfwGetHMONITORContentScaleWin32(mh, &xscale, &yscale);
if (xscale > 0.f && yscale > 0.f) if (xscale > 0.f && yscale > 0.f)
{ {
@ -1462,10 +1540,7 @@ static int createNativeWindow(_GLFWwindow* window,
} }
} }
ClientToScreen(window->win32.handle, (POINT*) &rect.left); if (_glfwIsWindows10Version1607OrGreaterWin32())
ClientToScreen(window->win32.handle, (POINT*) &rect.right);
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
{ {
AdjustWindowRectExForDpi(&rect, style, FALSE, exStyle, AdjustWindowRectExForDpi(&rect, style, FALSE, exStyle,
GetDpiForWindow(window->win32.handle)); GetDpiForWindow(window->win32.handle));
@ -1473,11 +1548,30 @@ static int createNativeWindow(_GLFWwindow* window,
else else
AdjustWindowRectEx(&rect, style, FALSE, exStyle); AdjustWindowRectEx(&rect, style, FALSE, exStyle);
// Only update the restored window rect as the window may be maximized
GetWindowPlacement(window->win32.handle, &wp); GetWindowPlacement(window->win32.handle, &wp);
OffsetRect(&rect,
wp.rcNormalPosition.left - rect.left,
wp.rcNormalPosition.top - rect.top);
wp.rcNormalPosition = rect; wp.rcNormalPosition = rect;
wp.showCmd = SW_HIDE; wp.showCmd = SW_HIDE;
SetWindowPlacement(window->win32.handle, &wp); SetWindowPlacement(window->win32.handle, &wp);
// Adjust rect of maximized undecorated window, because by default Windows will
// make such a window cover the whole monitor instead of its workarea
if (wndconfig->maximized && !wndconfig->decorated)
{
MONITORINFO mi = { sizeof(mi) };
GetMonitorInfoW(mh, &mi);
SetWindowPos(window->win32.handle, HWND_TOP,
mi.rcWork.left,
mi.rcWork.top,
mi.rcWork.right - mi.rcWork.left,
mi.rcWork.bottom - mi.rcWork.top,
SWP_NOACTIVATE | SWP_NOZORDER);
}
} }
DragAcceptFiles(window->win32.handle, TRUE); DragAcceptFiles(window->win32.handle, TRUE);
@ -1493,50 +1587,7 @@ static int createNativeWindow(_GLFWwindow* window,
return GLFW_TRUE; return GLFW_TRUE;
} }
// Registers the GLFW window class GLFWbool _glfwCreateWindowWin32(_GLFWwindow* window,
//
GLFWbool _glfwRegisterWindowClassWin32(void)
{
WNDCLASSEXW wc;
ZeroMemory(&wc, sizeof(wc));
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) windowProc;
wc.hInstance = GetModuleHandleW(NULL);
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.lpszClassName = _GLFW_WNDCLASSNAME;
// Load user-provided icon if available
wc.hIcon = LoadImageW(GetModuleHandleW(NULL),
L"GLFW_ICON", IMAGE_ICON,
0, 0, LR_DEFAULTSIZE | LR_SHARED);
if (!wc.hIcon)
{
// No user-provided icon found, load default icon
wc.hIcon = LoadImageW(NULL,
IDI_APPLICATION, IMAGE_ICON,
0, 0, LR_DEFAULTSIZE | LR_SHARED);
}
if (!RegisterClassExW(&wc))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to register window class");
return GLFW_FALSE;
}
return GLFW_TRUE;
}
// Unregisters the GLFW window class
//
void _glfwUnregisterWindowClassWin32(void)
{
UnregisterClassW(_GLFW_WNDCLASSNAME, GetModuleHandleW(NULL));
}
int _glfwCreateWindowWin32(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig, const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
@ -1567,14 +1618,32 @@ int _glfwCreateWindowWin32(_GLFWwindow* window,
if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
} }
if (!_glfwRefreshContextAttribs(window, ctxconfig))
return GLFW_FALSE;
} }
if (wndconfig->mousePassthrough)
_glfwSetWindowMousePassthroughWin32(window, GLFW_TRUE);
if (window->monitor) if (window->monitor)
{ {
_glfwShowWindowWin32(window); _glfwShowWindowWin32(window);
_glfwFocusWindowWin32(window); _glfwFocusWindowWin32(window);
acquireMonitor(window); acquireMonitor(window);
fitToMonitor(window); fitToMonitor(window);
if (wndconfig->centerCursor)
_glfwCenterCursorInContentArea(window);
}
else
{
if (wndconfig->visible)
{
_glfwShowWindowWin32(window);
if (wndconfig->focused)
_glfwFocusWindowWin32(window);
}
} }
return GLFW_TRUE; return GLFW_TRUE;
@ -1589,7 +1658,10 @@ void _glfwDestroyWindowWin32(_GLFWwindow* window)
window->context.destroy(window); window->context.destroy(window);
if (_glfw.win32.disabledCursorWindow == window) if (_glfw.win32.disabledCursorWindow == window)
_glfw.win32.disabledCursorWindow = NULL; enableCursor(window);
if (_glfw.win32.capturedCursorWindow == window)
releaseCursor();
if (window->win32.handle) if (window->win32.handle)
{ {
@ -1615,8 +1687,7 @@ void _glfwSetWindowTitleWin32(_GLFWwindow* window, const char* title)
_glfw_free(wideTitle); _glfw_free(wideTitle);
} }
void _glfwSetWindowIconWin32(_GLFWwindow* window, void _glfwSetWindowIconWin32(_GLFWwindow* window, int count, const GLFWimage* images)
int count, const GLFWimage* images)
{ {
HICON bigIcon = NULL, smallIcon = NULL; HICON bigIcon = NULL, smallIcon = NULL;
@ -1638,8 +1709,8 @@ void _glfwSetWindowIconWin32(_GLFWwindow* window,
smallIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICONSM); smallIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICONSM);
} }
SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM) bigIcon); SendMessageW(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM) bigIcon);
SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM) smallIcon); SendMessageW(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM) smallIcon);
if (window->win32.bigIcon) if (window->win32.bigIcon)
DestroyIcon(window->win32.bigIcon); DestroyIcon(window->win32.bigIcon);
@ -1669,7 +1740,7 @@ void _glfwSetWindowPosWin32(_GLFWwindow* window, int xpos, int ypos)
{ {
RECT rect = { xpos, ypos, xpos, ypos }; RECT rect = { xpos, ypos, xpos, ypos };
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32()) if (_glfwIsWindows10Version1607OrGreaterWin32())
{ {
AdjustWindowRectExForDpi(&rect, getWindowStyle(window), AdjustWindowRectExForDpi(&rect, getWindowStyle(window),
FALSE, getWindowExStyle(window), FALSE, getWindowExStyle(window),
@ -1710,7 +1781,7 @@ void _glfwSetWindowSizeWin32(_GLFWwindow* window, int width, int height)
{ {
RECT rect = { 0, 0, width, height }; RECT rect = { 0, 0, width, height };
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32()) if (_glfwIsWindows10Version1607OrGreaterWin32())
{ {
AdjustWindowRectExForDpi(&rect, getWindowStyle(window), AdjustWindowRectExForDpi(&rect, getWindowStyle(window),
FALSE, getWindowExStyle(window), FALSE, getWindowExStyle(window),
@ -1777,7 +1848,7 @@ void _glfwGetWindowFrameSizeWin32(_GLFWwindow* window,
_glfwGetWindowSizeWin32(window, &width, &height); _glfwGetWindowSizeWin32(window, &width, &height);
SetRect(&rect, 0, 0, width, height); SetRect(&rect, 0, 0, width, height);
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32()) if (_glfwIsWindows10Version1607OrGreaterWin32())
{ {
AdjustWindowRectExForDpi(&rect, getWindowStyle(window), AdjustWindowRectExForDpi(&rect, getWindowStyle(window),
FALSE, getWindowExStyle(window), FALSE, getWindowExStyle(window),
@ -1818,7 +1889,10 @@ void _glfwRestoreWindowWin32(_GLFWwindow* window)
void _glfwMaximizeWindowWin32(_GLFWwindow* window) void _glfwMaximizeWindowWin32(_GLFWwindow* window)
{ {
if (IsWindowVisible(window->win32.handle))
ShowWindow(window->win32.handle, SW_MAXIMIZE); ShowWindow(window->win32.handle, SW_MAXIMIZE);
else
maximizeWindowManually(window);
} }
void _glfwShowWindowWin32(_GLFWwindow* window) void _glfwShowWindowWin32(_GLFWwindow* window)
@ -1863,7 +1937,7 @@ void _glfwSetWindowMonitorWin32(_GLFWwindow* window,
{ {
RECT rect = { xpos, ypos, xpos + width, ypos + height }; RECT rect = { xpos, ypos, xpos + width, ypos + height };
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32()) if (_glfwIsWindows10Version1607OrGreaterWin32())
{ {
AdjustWindowRectExForDpi(&rect, getWindowStyle(window), AdjustWindowRectExForDpi(&rect, getWindowStyle(window),
FALSE, getWindowExStyle(window), FALSE, getWindowExStyle(window),
@ -1905,7 +1979,7 @@ void _glfwSetWindowMonitorWin32(_GLFWwindow* window,
acquireMonitor(window); acquireMonitor(window);
GetMonitorInfo(window->monitor->win32.handle, &mi); GetMonitorInfoW(window->monitor->win32.handle, &mi);
SetWindowPos(window->win32.handle, HWND_TOPMOST, SetWindowPos(window->win32.handle, HWND_TOPMOST,
mi.rcMonitor.left, mi.rcMonitor.left,
mi.rcMonitor.top, mi.rcMonitor.top,
@ -1934,7 +2008,7 @@ void _glfwSetWindowMonitorWin32(_GLFWwindow* window,
else else
after = HWND_NOTOPMOST; after = HWND_NOTOPMOST;
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32()) if (_glfwIsWindows10Version1607OrGreaterWin32())
{ {
AdjustWindowRectExForDpi(&rect, getWindowStyle(window), AdjustWindowRectExForDpi(&rect, getWindowStyle(window),
FALSE, getWindowExStyle(window), FALSE, getWindowExStyle(window),
@ -1953,32 +2027,32 @@ void _glfwSetWindowMonitorWin32(_GLFWwindow* window,
} }
} }
int _glfwWindowFocusedWin32(_GLFWwindow* window) GLFWbool _glfwWindowFocusedWin32(_GLFWwindow* window)
{ {
return window->win32.handle == GetActiveWindow(); return window->win32.handle == GetActiveWindow();
} }
int _glfwWindowIconifiedWin32(_GLFWwindow* window) GLFWbool _glfwWindowIconifiedWin32(_GLFWwindow* window)
{ {
return IsIconic(window->win32.handle); return IsIconic(window->win32.handle);
} }
int _glfwWindowVisibleWin32(_GLFWwindow* window) GLFWbool _glfwWindowVisibleWin32(_GLFWwindow* window)
{ {
return IsWindowVisible(window->win32.handle); return IsWindowVisible(window->win32.handle);
} }
int _glfwWindowMaximizedWin32(_GLFWwindow* window) GLFWbool _glfwWindowMaximizedWin32(_GLFWwindow* window)
{ {
return IsZoomed(window->win32.handle); return IsZoomed(window->win32.handle);
} }
int _glfwWindowHoveredWin32(_GLFWwindow* window) GLFWbool _glfwWindowHoveredWin32(_GLFWwindow* window)
{ {
return cursorInContentArea(window); return cursorInContentArea(window);
} }
int _glfwFramebufferTransparentWin32(_GLFWwindow* window) GLFWbool _glfwFramebufferTransparentWin32(_GLFWwindow* window)
{ {
BOOL composition, opaque; BOOL composition, opaque;
DWORD color; DWORD color;
@ -2200,14 +2274,14 @@ void _glfwWaitEventsWin32(void)
void _glfwWaitEventsTimeoutWin32(double timeout) void _glfwWaitEventsTimeoutWin32(double timeout)
{ {
MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLEVENTS); MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLINPUT);
_glfwPollEventsWin32(); _glfwPollEventsWin32();
} }
void _glfwPostEmptyEventWin32(void) void _glfwPostEmptyEventWin32(void)
{ {
PostMessage(_glfw.win32.helperWindowHandle, WM_NULL, 0, 0); PostMessageW(_glfw.win32.helperWindowHandle, WM_NULL, 0, 0);
} }
void _glfwGetCursorPosWin32(_GLFWwindow* window, double* xpos, double* ypos) void _glfwGetCursorPosWin32(_GLFWwindow* window, double* xpos, double* ypos)
@ -2239,14 +2313,40 @@ void _glfwSetCursorPosWin32(_GLFWwindow* window, double xpos, double ypos)
void _glfwSetCursorModeWin32(_GLFWwindow* window, int mode) void _glfwSetCursorModeWin32(_GLFWwindow* window, int mode)
{ {
if (_glfwWindowFocusedWin32(window))
{
if (mode == GLFW_CURSOR_DISABLED) if (mode == GLFW_CURSOR_DISABLED)
{ {
if (_glfwWindowFocusedWin32(window)) _glfwGetCursorPosWin32(window,
disableCursor(window); &_glfw.win32.restoreCursorPosX,
&_glfw.win32.restoreCursorPosY);
_glfwCenterCursorInContentArea(window);
if (window->rawMouseMotion)
enableRawMouseMotion(window);
} }
else if (_glfw.win32.disabledCursorWindow == window) else if (_glfw.win32.disabledCursorWindow == window)
enableCursor(window); {
else if (cursorInContentArea(window)) if (window->rawMouseMotion)
disableRawMouseMotion(window);
}
if (mode == GLFW_CURSOR_DISABLED || mode == GLFW_CURSOR_CAPTURED)
captureCursor(window);
else
releaseCursor();
if (mode == GLFW_CURSOR_DISABLED)
_glfw.win32.disabledCursorWindow = window;
else if (_glfw.win32.disabledCursorWindow == window)
{
_glfw.win32.disabledCursorWindow = NULL;
_glfwSetCursorPosWin32(window,
_glfw.win32.restoreCursorPosX,
_glfw.win32.restoreCursorPosY);
}
}
if (cursorInContentArea(window))
updateCursorImage(window); updateCursorImage(window);
} }
@ -2267,7 +2367,7 @@ int _glfwGetKeyScancodeWin32(int key)
return _glfw.win32.scancodes[key]; return _glfw.win32.scancodes[key];
} }
int _glfwCreateCursorWin32(_GLFWcursor* cursor, GLFWbool _glfwCreateCursorWin32(_GLFWcursor* cursor,
const GLFWimage* image, const GLFWimage* image,
int xhot, int yhot) int xhot, int yhot)
{ {
@ -2278,7 +2378,7 @@ int _glfwCreateCursorWin32(_GLFWcursor* cursor,
return GLFW_TRUE; return GLFW_TRUE;
} }
int _glfwCreateStandardCursorWin32(_GLFWcursor* cursor, int shape) GLFWbool _glfwCreateStandardCursorWin32(_GLFWcursor* cursor, int shape)
{ {
int id = 0; int id = 0;
@ -2346,7 +2446,7 @@ void _glfwSetCursorWin32(_GLFWwindow* window, _GLFWcursor* cursor)
void _glfwSetClipboardStringWin32(const char* string) void _glfwSetClipboardStringWin32(const char* string)
{ {
int characterCount; int characterCount, tries = 0;
HANDLE object; HANDLE object;
WCHAR* buffer; WCHAR* buffer;
@ -2374,13 +2474,21 @@ void _glfwSetClipboardStringWin32(const char* string)
MultiByteToWideChar(CP_UTF8, 0, string, -1, buffer, characterCount); MultiByteToWideChar(CP_UTF8, 0, string, -1, buffer, characterCount);
GlobalUnlock(object); GlobalUnlock(object);
if (!OpenClipboard(_glfw.win32.helperWindowHandle)) // NOTE: Retry clipboard opening a few times as some other application may have it
// open and also the Windows Clipboard History reads it after each update
while (!OpenClipboard(_glfw.win32.helperWindowHandle))
{
Sleep(1);
tries++;
if (tries == 3)
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to open clipboard"); "Win32: Failed to open clipboard");
GlobalFree(object); GlobalFree(object);
return; return;
} }
}
EmptyClipboard(); EmptyClipboard();
SetClipboardData(CF_UNICODETEXT, object); SetClipboardData(CF_UNICODETEXT, object);
@ -2391,13 +2499,22 @@ const char* _glfwGetClipboardStringWin32(void)
{ {
HANDLE object; HANDLE object;
WCHAR* buffer; WCHAR* buffer;
int tries = 0;
if (!OpenClipboard(_glfw.win32.helperWindowHandle)) // NOTE: Retry clipboard opening a few times as some other application may have it
// open and also the Windows Clipboard History reads it after each update
while (!OpenClipboard(_glfw.win32.helperWindowHandle))
{
Sleep(1);
tries++;
if (tries == 3)
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to open clipboard"); "Win32: Failed to open clipboard");
return NULL; return NULL;
} }
}
object = GetClipboardData(CF_UNICODETEXT); object = GetClipboardData(CF_UNICODETEXT);
if (!object) if (!object)
@ -2486,7 +2603,7 @@ void _glfwGetRequiredInstanceExtensionsWin32(char** extensions)
extensions[1] = "VK_KHR_win32_surface"; extensions[1] = "VK_KHR_win32_surface";
} }
int _glfwGetPhysicalDevicePresentationSupportWin32(VkInstance instance, GLFWbool _glfwGetPhysicalDevicePresentationSupportWin32(VkInstance instance,
VkPhysicalDevice device, VkPhysicalDevice device,
uint32_t queuefamily) uint32_t queuefamily)
{ {
@ -2524,7 +2641,7 @@ VkResult _glfwCreateWindowSurfaceWin32(VkInstance instance,
memset(&sci, 0, sizeof(sci)); memset(&sci, 0, sizeof(sci));
sci.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; sci.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
sci.hinstance = GetModuleHandle(NULL); sci.hinstance = _glfw.win32.instance;
sci.hwnd = window->win32.handle; sci.hwnd = window->win32.handle;
err = vkCreateWin32SurfaceKHR(instance, &sci, allocator, surface); err = vkCreateWin32SurfaceKHR(instance, &sci, allocator, surface);
@ -2553,3 +2670,5 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
return window->win32.handle; return window->win32.handle;
} }
#endif // _GLFW_WIN32

View File

@ -25,8 +25,6 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h" #include "internal.h"
@ -44,6 +42,9 @@
// //
void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused) void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused)
{ {
assert(window != NULL);
assert(focused == GLFW_TRUE || focused == GLFW_FALSE);
if (window->callbacks.focus) if (window->callbacks.focus)
window->callbacks.focus((GLFWwindow*) window, focused); window->callbacks.focus((GLFWwindow*) window, focused);
@ -73,6 +74,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused)
// //
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y) void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
{ {
assert(window != NULL);
if (window->callbacks.pos) if (window->callbacks.pos)
window->callbacks.pos((GLFWwindow*) window, x, y); window->callbacks.pos((GLFWwindow*) window, x, y);
} }
@ -82,6 +85,10 @@ void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
// //
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height) void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
{ {
assert(window != NULL);
assert(width >= 0);
assert(height >= 0);
if (window->callbacks.size) if (window->callbacks.size)
window->callbacks.size((GLFWwindow*) window, width, height); window->callbacks.size((GLFWwindow*) window, width, height);
} }
@ -98,6 +105,9 @@ void _glfwInputTitleBarHitTest(_GLFWwindow* window, int posX, int posY, int* hit
// //
void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified) void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified)
{ {
assert(window != NULL);
assert(iconified == GLFW_TRUE || iconified == GLFW_FALSE);
if (window->callbacks.iconify) if (window->callbacks.iconify)
window->callbacks.iconify((GLFWwindow*) window, iconified); window->callbacks.iconify((GLFWwindow*) window, iconified);
} }
@ -106,6 +116,9 @@ void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified)
// //
void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized) void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized)
{ {
assert(window != NULL);
assert(maximized == GLFW_TRUE || maximized == GLFW_FALSE);
if (window->callbacks.maximize) if (window->callbacks.maximize)
window->callbacks.maximize((GLFWwindow*) window, maximized); window->callbacks.maximize((GLFWwindow*) window, maximized);
} }
@ -115,6 +128,10 @@ void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized)
// //
void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height) void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height)
{ {
assert(window != NULL);
assert(width >= 0);
assert(height >= 0);
if (window->callbacks.fbsize) if (window->callbacks.fbsize)
window->callbacks.fbsize((GLFWwindow*) window, width, height); window->callbacks.fbsize((GLFWwindow*) window, width, height);
} }
@ -124,6 +141,12 @@ void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height)
// //
void _glfwInputWindowContentScale(_GLFWwindow* window, float xscale, float yscale) void _glfwInputWindowContentScale(_GLFWwindow* window, float xscale, float yscale)
{ {
assert(window != NULL);
assert(xscale > 0.f);
assert(xscale < FLT_MAX);
assert(yscale > 0.f);
assert(yscale < FLT_MAX);
if (window->callbacks.scale) if (window->callbacks.scale)
window->callbacks.scale((GLFWwindow*) window, xscale, yscale); window->callbacks.scale((GLFWwindow*) window, xscale, yscale);
} }
@ -132,6 +155,8 @@ void _glfwInputWindowContentScale(_GLFWwindow* window, float xscale, float yscal
// //
void _glfwInputWindowDamage(_GLFWwindow* window) void _glfwInputWindowDamage(_GLFWwindow* window)
{ {
assert(window != NULL);
if (window->callbacks.refresh) if (window->callbacks.refresh)
window->callbacks.refresh((GLFWwindow*) window); window->callbacks.refresh((GLFWwindow*) window);
} }
@ -140,6 +165,8 @@ void _glfwInputWindowDamage(_GLFWwindow* window)
// //
void _glfwInputWindowCloseRequest(_GLFWwindow* window) void _glfwInputWindowCloseRequest(_GLFWwindow* window)
{ {
assert(window != NULL);
window->shouldClose = GLFW_TRUE; window->shouldClose = GLFW_TRUE;
if (window->callbacks.close) if (window->callbacks.close)
@ -150,6 +177,7 @@ void _glfwInputWindowCloseRequest(_GLFWwindow* window)
// //
void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor) void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor)
{ {
assert(window != NULL);
window->monitor = monitor; window->monitor = monitor;
} }
@ -223,40 +251,12 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
window->numer = GLFW_DONT_CARE; window->numer = GLFW_DONT_CARE;
window->denom = GLFW_DONT_CARE; window->denom = GLFW_DONT_CARE;
// Open the actual window and create its context
if (!_glfw.platform.createWindow(window, &wndconfig, &ctxconfig, &fbconfig)) if (!_glfw.platform.createWindow(window, &wndconfig, &ctxconfig, &fbconfig))
{ {
glfwDestroyWindow((GLFWwindow*) window); glfwDestroyWindow((GLFWwindow*) window);
return NULL; return NULL;
} }
if (ctxconfig.client != GLFW_NO_API)
{
if (!_glfwRefreshContextAttribs(window, &ctxconfig))
{
glfwDestroyWindow((GLFWwindow*) window);
return NULL;
}
}
if (wndconfig.mousePassthrough)
_glfw.platform.setWindowMousePassthrough(window, GLFW_TRUE);
if (window->monitor)
{
if (wndconfig.centerCursor)
_glfwCenterCursorInContentArea(window);
}
else
{
if (wndconfig.visible)
{
_glfw.platform.showWindow(window);
if (wndconfig.focused)
_glfw.platform.focusWindow(window);
}
}
return (GLFWwindow*) window; return (GLFWwindow*) window;
} }
@ -281,6 +281,8 @@ void glfwDefaultWindowHints(void)
_glfw.hints.window.autoIconify = GLFW_TRUE; _glfw.hints.window.autoIconify = GLFW_TRUE;
_glfw.hints.window.centerCursor = GLFW_TRUE; _glfw.hints.window.centerCursor = GLFW_TRUE;
_glfw.hints.window.focusOnShow = GLFW_TRUE; _glfw.hints.window.focusOnShow = GLFW_TRUE;
_glfw.hints.window.xpos = GLFW_ANY_POSITION;
_glfw.hints.window.ypos = GLFW_ANY_POSITION;
// The default is 24 bits of color, 24 bits of depth and 8 bits of stencil, // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil,
// double buffered // double buffered
@ -378,6 +380,12 @@ GLFWAPI void glfwWindowHint(int hint, int value)
case GLFW_VISIBLE: case GLFW_VISIBLE:
_glfw.hints.window.visible = value ? GLFW_TRUE : GLFW_FALSE; _glfw.hints.window.visible = value ? GLFW_TRUE : GLFW_FALSE;
return; return;
case GLFW_POSITION_X:
_glfw.hints.window.xpos = value;
return;
case GLFW_POSITION_Y:
_glfw.hints.window.ypos = value;
return;
case GLFW_COCOA_RETINA_FRAMEBUFFER: case GLFW_COCOA_RETINA_FRAMEBUFFER:
_glfw.hints.window.ns.retina = value ? GLFW_TRUE : GLFW_FALSE; _glfw.hints.window.ns.retina = value ? GLFW_TRUE : GLFW_FALSE;
return; return;
@ -457,6 +465,10 @@ GLFWAPI void glfwWindowHintString(int hint, const char* value)
strncpy(_glfw.hints.window.x11.instanceName, value, strncpy(_glfw.hints.window.x11.instanceName, value,
sizeof(_glfw.hints.window.x11.instanceName) - 1); sizeof(_glfw.hints.window.x11.instanceName) - 1);
return; return;
case GLFW_WAYLAND_APP_ID:
strncpy(_glfw.hints.window.wl.appId, value,
sizeof(_glfw.hints.window.wl.appId) - 1);
return;
} }
_glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint string 0x%08X", hint); _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint string 0x%08X", hint);
@ -526,12 +538,33 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title)
GLFWAPI void glfwSetWindowIcon(GLFWwindow* handle, GLFWAPI void glfwSetWindowIcon(GLFWwindow* handle,
int count, const GLFWimage* images) int count, const GLFWimage* images)
{ {
int i;
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL); assert(window != NULL);
assert(count >= 0); assert(count >= 0);
assert(count == 0 || images != NULL); assert(count == 0 || images != NULL);
_GLFW_REQUIRE_INIT(); _GLFW_REQUIRE_INIT();
if (count < 0)
{
_glfwInputError(GLFW_INVALID_VALUE, "Invalid image count for window icon");
return;
}
for (i = 0; i < count; i++)
{
assert(images[i].pixels != NULL);
if (images[i].width <= 0 || images[i].height <= 0)
{
_glfwInputError(GLFW_INVALID_VALUE,
"Invalid image dimensions for window icon");
return;
}
}
_glfw.platform.setWindowIcon(window, count, images); _glfw.platform.setWindowIcon(window, count, images);
} }

File diff suppressed because it is too large Load Diff

View File

@ -23,11 +23,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_WAYLAND)
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -37,7 +37,7 @@
#include "wayland-client-protocol.h" #include "wayland-client-protocol.h"
static void outputHandleGeometry(void* data, static void outputHandleGeometry(void* userData,
struct wl_output* output, struct wl_output* output,
int32_t x, int32_t x,
int32_t y, int32_t y,
@ -48,24 +48,25 @@ static void outputHandleGeometry(void* data,
const char* model, const char* model,
int32_t transform) int32_t transform)
{ {
struct _GLFWmonitor *monitor = data; struct _GLFWmonitor* monitor = userData;
monitor->wl.x = x; monitor->wl.x = x;
monitor->wl.y = y; monitor->wl.y = y;
monitor->widthMM = physicalWidth; monitor->widthMM = physicalWidth;
monitor->heightMM = physicalHeight; monitor->heightMM = physicalHeight;
if (strlen(monitor->name) == 0)
snprintf(monitor->name, sizeof(monitor->name), "%s %s", make, model); snprintf(monitor->name, sizeof(monitor->name), "%s %s", make, model);
} }
static void outputHandleMode(void* data, static void outputHandleMode(void* userData,
struct wl_output* output, struct wl_output* output,
uint32_t flags, uint32_t flags,
int32_t width, int32_t width,
int32_t height, int32_t height,
int32_t refresh) int32_t refresh)
{ {
struct _GLFWmonitor *monitor = data; struct _GLFWmonitor* monitor = userData;
GLFWvidmode mode; GLFWvidmode mode;
mode.width = width; mode.width = width;
@ -84,9 +85,9 @@ static void outputHandleMode(void* data,
monitor->wl.currentMode = monitor->modeCount - 1; monitor->wl.currentMode = monitor->modeCount - 1;
} }
static void outputHandleDone(void* data, struct wl_output* output) static void outputHandleDone(void* userData, struct wl_output* output)
{ {
struct _GLFWmonitor *monitor = data; struct _GLFWmonitor* monitor = userData;
if (monitor->widthMM <= 0 || monitor->heightMM <= 0) if (monitor->widthMM <= 0 || monitor->heightMM <= 0)
{ {
@ -96,23 +97,58 @@ static void outputHandleDone(void* data, struct wl_output* output)
monitor->heightMM = (int) (mode->height * 25.4f / 96.f); monitor->heightMM = (int) (mode->height * 25.4f / 96.f);
} }
for (int i = 0; i < _glfw.monitorCount; i++)
{
if (_glfw.monitors[i] == monitor)
return;
}
_glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST); _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST);
} }
static void outputHandleScale(void* data, static void outputHandleScale(void* userData,
struct wl_output* output, struct wl_output* output,
int32_t factor) int32_t factor)
{ {
struct _GLFWmonitor *monitor = data; struct _GLFWmonitor* monitor = userData;
monitor->wl.scale = factor; monitor->wl.contentScale = factor;
for (_GLFWwindow* window = _glfw.windowListHead; window; window = window->next)
{
for (int i = 0; i < window->wl.scaleCount; i++)
{
if (window->wl.scales[i].output == monitor->wl.output)
{
window->wl.scales[i].factor = monitor->wl.contentScale;
_glfwUpdateContentScaleWayland(window);
break;
}
}
}
} }
static const struct wl_output_listener outputListener = { void outputHandleName(void* userData, struct wl_output* wl_output, const char* name)
{
struct _GLFWmonitor* monitor = userData;
strncpy(monitor->name, name, sizeof(monitor->name) - 1);
}
void outputHandleDescription(void* userData,
struct wl_output* wl_output,
const char* description)
{
}
static const struct wl_output_listener outputListener =
{
outputHandleGeometry, outputHandleGeometry,
outputHandleMode, outputHandleMode,
outputHandleDone, outputHandleDone,
outputHandleScale, outputHandleScale,
outputHandleName,
outputHandleDescription,
}; };
@ -122,9 +158,6 @@ static const struct wl_output_listener outputListener = {
void _glfwAddOutputWayland(uint32_t name, uint32_t version) void _glfwAddOutputWayland(uint32_t name, uint32_t version)
{ {
_GLFWmonitor *monitor;
struct wl_output *output;
if (version < 2) if (version < 2)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -132,23 +165,22 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version)
return; return;
} }
// The actual name of this output will be set in the geometry handler. version = _glfw_min(version, WL_OUTPUT_NAME_SINCE_VERSION);
monitor = _glfwAllocMonitor("", 0, 0);
output = wl_registry_bind(_glfw.wl.registry, struct wl_output* output = wl_registry_bind(_glfw.wl.registry,
name, name,
&wl_output_interface, &wl_output_interface,
2); version);
if (!output) if (!output)
{
_glfwFreeMonitor(monitor);
return; return;
}
monitor->wl.scale = 1; // The actual name of this output will be set in the geometry handler
_GLFWmonitor* monitor = _glfwAllocMonitor("", 0, 0);
monitor->wl.contentScale = 1;
monitor->wl.output = output; monitor->wl.output = output;
monitor->wl.name = name; monitor->wl.name = name;
wl_proxy_set_tag((struct wl_proxy*) output, &_glfw.wl.tag);
wl_output_add_listener(output, &outputListener, monitor); wl_output_add_listener(output, &outputListener, monitor);
} }
@ -175,9 +207,9 @@ void _glfwGetMonitorContentScaleWayland(_GLFWmonitor* monitor,
float* xscale, float* yscale) float* xscale, float* yscale)
{ {
if (xscale) if (xscale)
*xscale = (float) monitor->wl.scale; *xscale = (float) monitor->wl.contentScale;
if (yscale) if (yscale)
*yscale = (float) monitor->wl.scale; *yscale = (float) monitor->wl.contentScale;
} }
void _glfwGetMonitorWorkareaWayland(_GLFWmonitor* monitor, void _glfwGetMonitorWorkareaWayland(_GLFWmonitor* monitor,
@ -230,3 +262,5 @@ GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* handle)
return monitor->wl.output; return monitor->wl.output;
} }
#endif // _GLFW_WAYLAND

View File

@ -28,6 +28,8 @@
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-compose.h> #include <xkbcommon/xkbcommon-compose.h>
#include <stdbool.h>
typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; typedef VkFlags VkWaylandSurfaceCreateFlagsKHR;
typedef struct VkWaylandSurfaceCreateInfoKHR typedef struct VkWaylandSurfaceCreateInfoKHR
@ -43,11 +45,12 @@ typedef VkResult (APIENTRY *PFN_vkCreateWaylandSurfaceKHR)(VkInstance,const VkWa
typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice,uint32_t,struct wl_display*); typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice,uint32_t,struct wl_display*);
#include "xkb_unicode.h" #include "xkb_unicode.h"
#include "posix_poll.h"
typedef int (* PFN_wl_display_flush)(struct wl_display *display); typedef int (* PFN_wl_display_flush)(struct wl_display* display);
typedef void (* PFN_wl_display_cancel_read)(struct wl_display *display); typedef void (* PFN_wl_display_cancel_read)(struct wl_display* display);
typedef int (* PFN_wl_display_dispatch_pending)(struct wl_display *display); typedef int (* PFN_wl_display_dispatch_pending)(struct wl_display* display);
typedef int (* PFN_wl_display_read_events)(struct wl_display *display); typedef int (* PFN_wl_display_read_events)(struct wl_display* display);
typedef struct wl_display* (* PFN_wl_display_connect)(const char*); typedef struct wl_display* (* PFN_wl_display_connect)(const char*);
typedef void (* PFN_wl_display_disconnect)(struct wl_display*); typedef void (* PFN_wl_display_disconnect)(struct wl_display*);
typedef int (* PFN_wl_display_roundtrip)(struct wl_display*); typedef int (* PFN_wl_display_roundtrip)(struct wl_display*);
@ -60,6 +63,8 @@ typedef struct wl_proxy* (* PFN_wl_proxy_marshal_constructor)(struct wl_proxy*,u
typedef struct wl_proxy* (* PFN_wl_proxy_marshal_constructor_versioned)(struct wl_proxy*,uint32_t,const struct wl_interface*,uint32_t,...); typedef struct wl_proxy* (* PFN_wl_proxy_marshal_constructor_versioned)(struct wl_proxy*,uint32_t,const struct wl_interface*,uint32_t,...);
typedef void* (* PFN_wl_proxy_get_user_data)(struct wl_proxy*); typedef void* (* PFN_wl_proxy_get_user_data)(struct wl_proxy*);
typedef void (* PFN_wl_proxy_set_user_data)(struct wl_proxy*,void*); typedef void (* PFN_wl_proxy_set_user_data)(struct wl_proxy*,void*);
typedef void (* PFN_wl_proxy_set_tag)(struct wl_proxy*,const char*const*);
typedef const char* const* (* PFN_wl_proxy_get_tag)(struct wl_proxy*);
typedef uint32_t (* PFN_wl_proxy_get_version)(struct wl_proxy*); typedef uint32_t (* PFN_wl_proxy_get_version)(struct wl_proxy*);
typedef struct wl_proxy* (* PFN_wl_proxy_marshal_flags)(struct wl_proxy*,uint32_t,const struct wl_interface*,uint32_t,uint32_t,...); typedef struct wl_proxy* (* PFN_wl_proxy_marshal_flags)(struct wl_proxy*,uint32_t,const struct wl_interface*,uint32_t,uint32_t,...);
#define wl_display_flush _glfw.wl.client.display_flush #define wl_display_flush _glfw.wl.client.display_flush
@ -77,10 +82,13 @@ typedef struct wl_proxy* (* PFN_wl_proxy_marshal_flags)(struct wl_proxy*,uint32_
#define wl_proxy_marshal_constructor_versioned _glfw.wl.client.proxy_marshal_constructor_versioned #define wl_proxy_marshal_constructor_versioned _glfw.wl.client.proxy_marshal_constructor_versioned
#define wl_proxy_get_user_data _glfw.wl.client.proxy_get_user_data #define wl_proxy_get_user_data _glfw.wl.client.proxy_get_user_data
#define wl_proxy_set_user_data _glfw.wl.client.proxy_set_user_data #define wl_proxy_set_user_data _glfw.wl.client.proxy_set_user_data
#define wl_proxy_get_tag _glfw.wl.client.proxy_get_tag
#define wl_proxy_set_tag _glfw.wl.client.proxy_set_tag
#define wl_proxy_get_version _glfw.wl.client.proxy_get_version #define wl_proxy_get_version _glfw.wl.client.proxy_get_version
#define wl_proxy_marshal_flags _glfw.wl.client.proxy_marshal_flags #define wl_proxy_marshal_flags _glfw.wl.client.proxy_marshal_flags
struct wl_shm; struct wl_shm;
struct wl_output;
#define wl_display_interface _glfw_wl_display_interface #define wl_display_interface _glfw_wl_display_interface
#define wl_subcompositor_interface _glfw_wl_subcompositor_interface #define wl_subcompositor_interface _glfw_wl_subcompositor_interface
@ -166,8 +174,8 @@ typedef struct xkb_state* (* PFN_xkb_state_new)(struct xkb_keymap*);
typedef void (* PFN_xkb_state_unref)(struct xkb_state*); typedef void (* PFN_xkb_state_unref)(struct xkb_state*);
typedef int (* PFN_xkb_state_key_get_syms)(struct xkb_state*, xkb_keycode_t, const xkb_keysym_t**); typedef int (* PFN_xkb_state_key_get_syms)(struct xkb_state*, xkb_keycode_t, const xkb_keysym_t**);
typedef enum xkb_state_component (* PFN_xkb_state_update_mask)(struct xkb_state*, xkb_mod_mask_t, xkb_mod_mask_t, xkb_mod_mask_t, xkb_layout_index_t, xkb_layout_index_t, xkb_layout_index_t); typedef enum xkb_state_component (* PFN_xkb_state_update_mask)(struct xkb_state*, xkb_mod_mask_t, xkb_mod_mask_t, xkb_mod_mask_t, xkb_layout_index_t, xkb_layout_index_t, xkb_layout_index_t);
typedef xkb_mod_mask_t (* PFN_xkb_state_serialize_mods)(struct xkb_state*, enum xkb_state_component);
typedef xkb_layout_index_t (* PFN_xkb_state_key_get_layout)(struct xkb_state*,xkb_keycode_t); typedef xkb_layout_index_t (* PFN_xkb_state_key_get_layout)(struct xkb_state*,xkb_keycode_t);
typedef int (* PFN_xkb_state_mod_index_is_active)(struct xkb_state*,xkb_mod_index_t,enum xkb_state_component);
#define xkb_context_new _glfw.wl.xkb.context_new #define xkb_context_new _glfw.wl.xkb.context_new
#define xkb_context_unref _glfw.wl.xkb.context_unref #define xkb_context_unref _glfw.wl.xkb.context_unref
#define xkb_keymap_new_from_string _glfw.wl.xkb.keymap_new_from_string #define xkb_keymap_new_from_string _glfw.wl.xkb.keymap_new_from_string
@ -179,8 +187,8 @@ typedef xkb_layout_index_t (* PFN_xkb_state_key_get_layout)(struct xkb_state*,xk
#define xkb_state_unref _glfw.wl.xkb.state_unref #define xkb_state_unref _glfw.wl.xkb.state_unref
#define xkb_state_key_get_syms _glfw.wl.xkb.state_key_get_syms #define xkb_state_key_get_syms _glfw.wl.xkb.state_key_get_syms
#define xkb_state_update_mask _glfw.wl.xkb.state_update_mask #define xkb_state_update_mask _glfw.wl.xkb.state_update_mask
#define xkb_state_serialize_mods _glfw.wl.xkb.state_serialize_mods
#define xkb_state_key_get_layout _glfw.wl.xkb.state_key_get_layout #define xkb_state_key_get_layout _glfw.wl.xkb.state_key_get_layout
#define xkb_state_mod_index_is_active _glfw.wl.xkb.state_mod_index_is_active
typedef struct xkb_compose_table* (* PFN_xkb_compose_table_new_from_locale)(struct xkb_context*, const char*, enum xkb_compose_compile_flags); typedef struct xkb_compose_table* (* PFN_xkb_compose_table_new_from_locale)(struct xkb_context*, const char*, enum xkb_compose_compile_flags);
typedef void (* PFN_xkb_compose_table_unref)(struct xkb_compose_table*); typedef void (* PFN_xkb_compose_table_unref)(struct xkb_compose_table*);
@ -197,18 +205,129 @@ typedef xkb_keysym_t (* PFN_xkb_compose_state_get_one_sym)(struct xkb_compose_st
#define xkb_compose_state_get_status _glfw.wl.xkb.compose_state_get_status #define xkb_compose_state_get_status _glfw.wl.xkb.compose_state_get_status
#define xkb_compose_state_get_one_sym _glfw.wl.xkb.compose_state_get_one_sym #define xkb_compose_state_get_one_sym _glfw.wl.xkb.compose_state_get_one_sym
#define _GLFW_DECORATION_WIDTH 4 struct libdecor;
#define _GLFW_DECORATION_TOP 24 struct libdecor_frame;
#define _GLFW_DECORATION_VERTICAL (_GLFW_DECORATION_TOP + _GLFW_DECORATION_WIDTH) struct libdecor_state;
#define _GLFW_DECORATION_HORIZONTAL (2 * _GLFW_DECORATION_WIDTH) struct libdecor_configuration;
enum libdecor_error
{
LIBDECOR_ERROR_COMPOSITOR_INCOMPATIBLE,
LIBDECOR_ERROR_INVALID_FRAME_CONFIGURATION,
};
enum libdecor_window_state
{
LIBDECOR_WINDOW_STATE_NONE = 0,
LIBDECOR_WINDOW_STATE_ACTIVE = 1,
LIBDECOR_WINDOW_STATE_MAXIMIZED = 2,
LIBDECOR_WINDOW_STATE_FULLSCREEN = 4,
LIBDECOR_WINDOW_STATE_TILED_LEFT = 8,
LIBDECOR_WINDOW_STATE_TILED_RIGHT = 16,
LIBDECOR_WINDOW_STATE_TILED_TOP = 32,
LIBDECOR_WINDOW_STATE_TILED_BOTTOM = 64
};
enum libdecor_capabilities
{
LIBDECOR_ACTION_MOVE = 1,
LIBDECOR_ACTION_RESIZE = 2,
LIBDECOR_ACTION_MINIMIZE = 4,
LIBDECOR_ACTION_FULLSCREEN = 8,
LIBDECOR_ACTION_CLOSE = 16
};
struct libdecor_interface
{
void (* error)(struct libdecor*,enum libdecor_error,const char*);
void (* reserved0)(void);
void (* reserved1)(void);
void (* reserved2)(void);
void (* reserved3)(void);
void (* reserved4)(void);
void (* reserved5)(void);
void (* reserved6)(void);
void (* reserved7)(void);
void (* reserved8)(void);
void (* reserved9)(void);
};
struct libdecor_frame_interface
{
void (* configure)(struct libdecor_frame*,struct libdecor_configuration*,void*);
void (* close)(struct libdecor_frame*,void*);
void (* commit)(struct libdecor_frame*,void*);
void (* dismiss_popup)(struct libdecor_frame*,const char*,void*);
void (* reserved0)(void);
void (* reserved1)(void);
void (* reserved2)(void);
void (* reserved3)(void);
void (* reserved4)(void);
void (* reserved5)(void);
void (* reserved6)(void);
void (* reserved7)(void);
void (* reserved8)(void);
void (* reserved9)(void);
};
typedef struct libdecor* (* PFN_libdecor_new)(struct wl_display*,const struct libdecor_interface*);
typedef void (* PFN_libdecor_unref)(struct libdecor*);
typedef int (* PFN_libdecor_get_fd)(struct libdecor*);
typedef int (* PFN_libdecor_dispatch)(struct libdecor*,int);
typedef struct libdecor_frame* (* PFN_libdecor_decorate)(struct libdecor*,struct wl_surface*,const struct libdecor_frame_interface*,void*);
typedef void (* PFN_libdecor_frame_unref)(struct libdecor_frame*);
typedef void (* PFN_libdecor_frame_set_app_id)(struct libdecor_frame*,const char*);
typedef void (* PFN_libdecor_frame_set_title)(struct libdecor_frame*,const char*);
typedef void (* PFN_libdecor_frame_set_minimized)(struct libdecor_frame*);
typedef void (* PFN_libdecor_frame_set_fullscreen)(struct libdecor_frame*,struct wl_output*);
typedef void (* PFN_libdecor_frame_unset_fullscreen)(struct libdecor_frame*);
typedef void (* PFN_libdecor_frame_map)(struct libdecor_frame*);
typedef void (* PFN_libdecor_frame_commit)(struct libdecor_frame*,struct libdecor_state*,struct libdecor_configuration*);
typedef void (* PFN_libdecor_frame_set_min_content_size)(struct libdecor_frame*,int,int);
typedef void (* PFN_libdecor_frame_set_max_content_size)(struct libdecor_frame*,int,int);
typedef void (* PFN_libdecor_frame_set_maximized)(struct libdecor_frame*);
typedef void (* PFN_libdecor_frame_unset_maximized)(struct libdecor_frame*);
typedef void (* PFN_libdecor_frame_set_capabilities)(struct libdecor_frame*,enum libdecor_capabilities);
typedef void (* PFN_libdecor_frame_unset_capabilities)(struct libdecor_frame*,enum libdecor_capabilities);
typedef void (* PFN_libdecor_frame_set_visibility)(struct libdecor_frame*,bool visible);
typedef struct xdg_toplevel* (* PFN_libdecor_frame_get_xdg_toplevel)(struct libdecor_frame*);
typedef bool (* PFN_libdecor_configuration_get_content_size)(struct libdecor_configuration*,struct libdecor_frame*,int*,int*);
typedef bool (* PFN_libdecor_configuration_get_window_state)(struct libdecor_configuration*,enum libdecor_window_state*);
typedef struct libdecor_state* (* PFN_libdecor_state_new)(int,int);
typedef void (* PFN_libdecor_state_free)(struct libdecor_state*);
#define libdecor_new _glfw.wl.libdecor.libdecor_new_
#define libdecor_unref _glfw.wl.libdecor.libdecor_unref_
#define libdecor_get_fd _glfw.wl.libdecor.libdecor_get_fd_
#define libdecor_dispatch _glfw.wl.libdecor.libdecor_dispatch_
#define libdecor_decorate _glfw.wl.libdecor.libdecor_decorate_
#define libdecor_frame_unref _glfw.wl.libdecor.libdecor_frame_unref_
#define libdecor_frame_set_app_id _glfw.wl.libdecor.libdecor_frame_set_app_id_
#define libdecor_frame_set_title _glfw.wl.libdecor.libdecor_frame_set_title_
#define libdecor_frame_set_minimized _glfw.wl.libdecor.libdecor_frame_set_minimized_
#define libdecor_frame_set_fullscreen _glfw.wl.libdecor.libdecor_frame_set_fullscreen_
#define libdecor_frame_unset_fullscreen _glfw.wl.libdecor.libdecor_frame_unset_fullscreen_
#define libdecor_frame_map _glfw.wl.libdecor.libdecor_frame_map_
#define libdecor_frame_commit _glfw.wl.libdecor.libdecor_frame_commit_
#define libdecor_frame_set_min_content_size _glfw.wl.libdecor.libdecor_frame_set_min_content_size_
#define libdecor_frame_set_max_content_size _glfw.wl.libdecor.libdecor_frame_set_max_content_size_
#define libdecor_frame_set_maximized _glfw.wl.libdecor.libdecor_frame_set_maximized_
#define libdecor_frame_unset_maximized _glfw.wl.libdecor.libdecor_frame_unset_maximized_
#define libdecor_frame_set_capabilities _glfw.wl.libdecor.libdecor_frame_set_capabilities_
#define libdecor_frame_unset_capabilities _glfw.wl.libdecor.libdecor_frame_unset_capabilities_
#define libdecor_frame_set_visibility _glfw.wl.libdecor.libdecor_frame_set_visibility_
#define libdecor_frame_get_xdg_toplevel _glfw.wl.libdecor.libdecor_frame_get_xdg_toplevel_
#define libdecor_configuration_get_content_size _glfw.wl.libdecor.libdecor_configuration_get_content_size_
#define libdecor_configuration_get_window_state _glfw.wl.libdecor.libdecor_configuration_get_window_state_
#define libdecor_state_new _glfw.wl.libdecor.libdecor_state_new_
#define libdecor_state_free _glfw.wl.libdecor.libdecor_state_free_
typedef enum _GLFWdecorationSideWayland typedef enum _GLFWdecorationSideWayland
{ {
mainWindow, GLFW_MAIN_WINDOW,
topDecoration, GLFW_TOP_DECORATION,
leftDecoration, GLFW_LEFT_DECORATION,
rightDecoration, GLFW_RIGHT_DECORATION,
bottomDecoration, GLFW_BOTTOM_DECORATION
} _GLFWdecorationSideWayland; } _GLFWdecorationSideWayland;
typedef struct _GLFWdecorationWayland typedef struct _GLFWdecorationWayland
@ -218,6 +337,19 @@ typedef struct _GLFWdecorationWayland
struct wp_viewport* viewport; struct wp_viewport* viewport;
} _GLFWdecorationWayland; } _GLFWdecorationWayland;
typedef struct _GLFWofferWayland
{
struct wl_data_offer* offer;
GLFWbool text_plain_utf8;
GLFWbool text_uri_list;
} _GLFWofferWayland;
typedef struct _GLFWscaleWayland
{
struct wl_output* output;
int factor;
} _GLFWscaleWayland;
// Wayland-specific per-window data // Wayland-specific per-window data
// //
typedef struct _GLFWwindowWayland typedef struct _GLFWwindowWayland
@ -225,44 +357,60 @@ typedef struct _GLFWwindowWayland
int width, height; int width, height;
GLFWbool visible; GLFWbool visible;
GLFWbool maximized; GLFWbool maximized;
GLFWbool activated;
GLFWbool fullscreen;
GLFWbool hovered; GLFWbool hovered;
GLFWbool transparent; GLFWbool transparent;
struct wl_surface* surface; struct wl_surface* surface;
struct wl_egl_window* native;
struct wl_callback* callback; struct wl_callback* callback;
struct {
struct wl_egl_window* window;
} egl;
struct {
int width, height;
GLFWbool maximized;
GLFWbool iconified;
GLFWbool activated;
GLFWbool fullscreen;
} pending;
struct { struct {
struct xdg_surface* surface; struct xdg_surface* surface;
struct xdg_toplevel* toplevel; struct xdg_toplevel* toplevel;
struct zxdg_toplevel_decoration_v1* decoration; struct zxdg_toplevel_decoration_v1* decoration;
uint32_t decorationMode;
} xdg; } xdg;
struct {
struct libdecor_frame* frame;
int mode;
} libdecor;
_GLFWcursor* currentCursor; _GLFWcursor* currentCursor;
double cursorPosX, cursorPosY; double cursorPosX, cursorPosY;
char* title; char* title;
char* appId;
// We need to track the monitors the window spans on to calculate the // We need to track the monitors the window spans on to calculate the
// optimal scaling factor. // optimal scaling factor.
int scale; int contentScale;
_GLFWmonitor** monitors; _GLFWscaleWayland* scales;
int monitorsCount; int scaleCount;
int monitorsSize; int scaleSize;
struct {
struct zwp_relative_pointer_v1* relativePointer; struct zwp_relative_pointer_v1* relativePointer;
struct zwp_locked_pointer_v1* lockedPointer; struct zwp_locked_pointer_v1* lockedPointer;
} pointerLock; struct zwp_confined_pointer_v1* confinedPointer;
struct zwp_idle_inhibitor_v1* idleInhibitor; struct zwp_idle_inhibitor_v1* idleInhibitor;
GLFWbool wasFullscreen;
struct { struct {
GLFWbool serverSide;
struct wl_buffer* buffer; struct wl_buffer* buffer;
_GLFWdecorationWayland top, left, right, bottom; _GLFWdecorationWayland top, left, right, bottom;
int focus; _GLFWdecorationSideWayland focus;
} decorations; } decorations;
} _GLFWwindowWayland; } _GLFWwindowWayland;
@ -280,8 +428,6 @@ typedef struct _GLFWlibraryWayland
struct wl_keyboard* keyboard; struct wl_keyboard* keyboard;
struct wl_data_device_manager* dataDeviceManager; struct wl_data_device_manager* dataDeviceManager;
struct wl_data_device* dataDevice; struct wl_data_device* dataDevice;
struct wl_data_offer* dataOffer;
struct wl_data_source* dataSource;
struct xdg_wm_base* wmBase; struct xdg_wm_base* wmBase;
struct zxdg_decoration_manager_v1* decorationManager; struct zxdg_decoration_manager_v1* decorationManager;
struct wp_viewporter* viewporter; struct wp_viewporter* viewporter;
@ -289,8 +435,17 @@ typedef struct _GLFWlibraryWayland
struct zwp_pointer_constraints_v1* pointerConstraints; struct zwp_pointer_constraints_v1* pointerConstraints;
struct zwp_idle_inhibit_manager_v1* idleInhibitManager; struct zwp_idle_inhibit_manager_v1* idleInhibitManager;
int compositorVersion; _GLFWofferWayland* offers;
int seatVersion; unsigned int offerCount;
struct wl_data_offer* selectionOffer;
struct wl_data_source* selectionSource;
struct wl_data_offer* dragOffer;
_GLFWwindow* dragFocus;
uint32_t dragSerial;
const char* tag;
struct wl_cursor_theme* cursorTheme; struct wl_cursor_theme* cursorTheme;
struct wl_cursor_theme* cursorThemeHiDPI; struct wl_cursor_theme* cursorThemeHiDPI;
@ -300,15 +455,12 @@ typedef struct _GLFWlibraryWayland
uint32_t serial; uint32_t serial;
uint32_t pointerEnterSerial; uint32_t pointerEnterSerial;
int32_t keyboardRepeatRate; int keyRepeatTimerfd;
int32_t keyboardRepeatDelay; int32_t keyRepeatRate;
int keyboardLastKey; int32_t keyRepeatDelay;
int keyboardLastScancode; int keyRepeatScancode;
char* clipboardString; char* clipboardString;
size_t clipboardSize;
char* clipboardSendString;
size_t clipboardSendSize;
int timerfd;
short int keycodes[256]; short int keycodes[256];
short int scancodes[GLFW_KEY_LAST + 1]; short int scancodes[GLFW_KEY_LAST + 1];
char keynames[GLFW_KEY_LAST + 1][5]; char keynames[GLFW_KEY_LAST + 1][5];
@ -321,12 +473,12 @@ typedef struct _GLFWlibraryWayland
struct xkb_compose_state* composeState; struct xkb_compose_state* composeState;
xkb_mod_mask_t controlMask; xkb_mod_index_t controlIndex;
xkb_mod_mask_t altMask; xkb_mod_index_t altIndex;
xkb_mod_mask_t shiftMask; xkb_mod_index_t shiftIndex;
xkb_mod_mask_t superMask; xkb_mod_index_t superIndex;
xkb_mod_mask_t capsLockMask; xkb_mod_index_t capsLockIndex;
xkb_mod_mask_t numLockMask; xkb_mod_index_t numLockIndex;
unsigned int modifiers; unsigned int modifiers;
PFN_xkb_context_new context_new; PFN_xkb_context_new context_new;
@ -340,8 +492,8 @@ typedef struct _GLFWlibraryWayland
PFN_xkb_state_unref state_unref; PFN_xkb_state_unref state_unref;
PFN_xkb_state_key_get_syms state_key_get_syms; PFN_xkb_state_key_get_syms state_key_get_syms;
PFN_xkb_state_update_mask state_update_mask; PFN_xkb_state_update_mask state_update_mask;
PFN_xkb_state_serialize_mods state_serialize_mods;
PFN_xkb_state_key_get_layout state_key_get_layout; PFN_xkb_state_key_get_layout state_key_get_layout;
PFN_xkb_state_mod_index_is_active state_mod_index_is_active;
PFN_xkb_compose_table_new_from_locale compose_table_new_from_locale; PFN_xkb_compose_table_new_from_locale compose_table_new_from_locale;
PFN_xkb_compose_table_unref compose_table_unref; PFN_xkb_compose_table_unref compose_table_unref;
@ -372,6 +524,8 @@ typedef struct _GLFWlibraryWayland
PFN_wl_proxy_marshal_constructor_versioned proxy_marshal_constructor_versioned; PFN_wl_proxy_marshal_constructor_versioned proxy_marshal_constructor_versioned;
PFN_wl_proxy_get_user_data proxy_get_user_data; PFN_wl_proxy_get_user_data proxy_get_user_data;
PFN_wl_proxy_set_user_data proxy_set_user_data; PFN_wl_proxy_set_user_data proxy_set_user_data;
PFN_wl_proxy_get_tag proxy_get_tag;
PFN_wl_proxy_set_tag proxy_set_tag;
PFN_wl_proxy_get_version proxy_get_version; PFN_wl_proxy_get_version proxy_get_version;
PFN_wl_proxy_marshal_flags proxy_marshal_flags; PFN_wl_proxy_marshal_flags proxy_marshal_flags;
} client; } client;
@ -392,6 +546,38 @@ typedef struct _GLFWlibraryWayland
PFN_wl_egl_window_destroy window_destroy; PFN_wl_egl_window_destroy window_destroy;
PFN_wl_egl_window_resize window_resize; PFN_wl_egl_window_resize window_resize;
} egl; } egl;
struct {
void* handle;
struct libdecor* context;
struct wl_callback* callback;
GLFWbool ready;
PFN_libdecor_new libdecor_new_;
PFN_libdecor_unref libdecor_unref_;
PFN_libdecor_get_fd libdecor_get_fd_;
PFN_libdecor_dispatch libdecor_dispatch_;
PFN_libdecor_decorate libdecor_decorate_;
PFN_libdecor_frame_unref libdecor_frame_unref_;
PFN_libdecor_frame_set_app_id libdecor_frame_set_app_id_;
PFN_libdecor_frame_set_title libdecor_frame_set_title_;
PFN_libdecor_frame_set_minimized libdecor_frame_set_minimized_;
PFN_libdecor_frame_set_fullscreen libdecor_frame_set_fullscreen_;
PFN_libdecor_frame_unset_fullscreen libdecor_frame_unset_fullscreen_;
PFN_libdecor_frame_map libdecor_frame_map_;
PFN_libdecor_frame_commit libdecor_frame_commit_;
PFN_libdecor_frame_set_min_content_size libdecor_frame_set_min_content_size_;
PFN_libdecor_frame_set_max_content_size libdecor_frame_set_max_content_size_;
PFN_libdecor_frame_set_maximized libdecor_frame_set_maximized_;
PFN_libdecor_frame_unset_maximized libdecor_frame_unset_maximized_;
PFN_libdecor_frame_set_capabilities libdecor_frame_set_capabilities_;
PFN_libdecor_frame_unset_capabilities libdecor_frame_unset_capabilities_;
PFN_libdecor_frame_set_visibility libdecor_frame_set_visibility_;
PFN_libdecor_frame_get_xdg_toplevel libdecor_frame_get_xdg_toplevel_;
PFN_libdecor_configuration_get_content_size libdecor_configuration_get_content_size_;
PFN_libdecor_configuration_get_window_state libdecor_configuration_get_window_state_;
PFN_libdecor_state_new libdecor_state_new_;
PFN_libdecor_state_free libdecor_state_free_;
} libdecor;
} _GLFWlibraryWayland; } _GLFWlibraryWayland;
// Wayland-specific per-monitor data // Wayland-specific per-monitor data
@ -404,7 +590,7 @@ typedef struct _GLFWmonitorWayland
int x; int x;
int y; int y;
int scale; int contentScale;
} _GLFWmonitorWayland; } _GLFWmonitorWayland;
// Wayland-specific per-cursor data // Wayland-specific per-cursor data
@ -423,7 +609,7 @@ GLFWbool _glfwConnectWayland(int platformID, _GLFWplatform* platform);
int _glfwInitWayland(void); int _glfwInitWayland(void);
void _glfwTerminateWayland(void); void _glfwTerminateWayland(void);
int _glfwCreateWindowWayland(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); GLFWbool _glfwCreateWindowWayland(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowWayland(_GLFWwindow* window); void _glfwDestroyWindowWayland(_GLFWwindow* window);
void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title); void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconWayland(_GLFWwindow* window, int count, const GLFWimage* images); void _glfwSetWindowIconWayland(_GLFWwindow* window, int count, const GLFWimage* images);
@ -444,12 +630,12 @@ void _glfwHideWindowWayland(_GLFWwindow* window);
void _glfwRequestWindowAttentionWayland(_GLFWwindow* window); void _glfwRequestWindowAttentionWayland(_GLFWwindow* window);
void _glfwFocusWindowWayland(_GLFWwindow* window); void _glfwFocusWindowWayland(_GLFWwindow* window);
void _glfwSetWindowMonitorWayland(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); void _glfwSetWindowMonitorWayland(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
int _glfwWindowFocusedWayland(_GLFWwindow* window); GLFWbool _glfwWindowFocusedWayland(_GLFWwindow* window);
int _glfwWindowIconifiedWayland(_GLFWwindow* window); GLFWbool _glfwWindowIconifiedWayland(_GLFWwindow* window);
int _glfwWindowVisibleWayland(_GLFWwindow* window); GLFWbool _glfwWindowVisibleWayland(_GLFWwindow* window);
int _glfwWindowMaximizedWayland(_GLFWwindow* window); GLFWbool _glfwWindowMaximizedWayland(_GLFWwindow* window);
int _glfwWindowHoveredWayland(_GLFWwindow* window); GLFWbool _glfwWindowHoveredWayland(_GLFWwindow* window);
int _glfwFramebufferTransparentWayland(_GLFWwindow* window); GLFWbool _glfwFramebufferTransparentWayland(_GLFWwindow* window);
void _glfwSetWindowResizableWayland(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowResizableWayland(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowDecoratedWayland(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowDecoratedWayland(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowFloatingWayland(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowFloatingWayland(_GLFWwindow* window, GLFWbool enabled);
@ -457,7 +643,7 @@ float _glfwGetWindowOpacityWayland(_GLFWwindow* window);
void _glfwSetWindowOpacityWayland(_GLFWwindow* window, float opacity); void _glfwSetWindowOpacityWayland(_GLFWwindow* window, float opacity);
void _glfwSetWindowMousePassthroughWayland(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowMousePassthroughWayland(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetRawMouseMotionWayland(_GLFWwindow *window, GLFWbool enabled); void _glfwSetRawMouseMotionWayland(_GLFWwindow* window, GLFWbool enabled);
GLFWbool _glfwRawMouseMotionSupportedWayland(void); GLFWbool _glfwRawMouseMotionSupportedWayland(void);
void _glfwPollEventsWayland(void); void _glfwPollEventsWayland(void);
@ -470,8 +656,8 @@ void _glfwSetCursorPosWayland(_GLFWwindow* window, double xpos, double ypos);
void _glfwSetCursorModeWayland(_GLFWwindow* window, int mode); void _glfwSetCursorModeWayland(_GLFWwindow* window, int mode);
const char* _glfwGetScancodeNameWayland(int scancode); const char* _glfwGetScancodeNameWayland(int scancode);
int _glfwGetKeyScancodeWayland(int key); int _glfwGetKeyScancodeWayland(int key);
int _glfwCreateCursorWayland(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); GLFWbool _glfwCreateCursorWayland(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot);
int _glfwCreateStandardCursorWayland(_GLFWcursor* cursor, int shape); GLFWbool _glfwCreateStandardCursorWayland(_GLFWcursor* cursor, int shape);
void _glfwDestroyCursorWayland(_GLFWcursor* cursor); void _glfwDestroyCursorWayland(_GLFWcursor* cursor);
void _glfwSetCursorWayland(_GLFWwindow* window, _GLFWcursor* cursor); void _glfwSetCursorWayland(_GLFWwindow* window, _GLFWcursor* cursor);
void _glfwSetClipboardStringWayland(const char* string); void _glfwSetClipboardStringWayland(const char* string);
@ -482,7 +668,7 @@ EGLNativeDisplayType _glfwGetEGLNativeDisplayWayland(void);
EGLNativeWindowType _glfwGetEGLNativeWindowWayland(_GLFWwindow* window); EGLNativeWindowType _glfwGetEGLNativeWindowWayland(_GLFWwindow* window);
void _glfwGetRequiredInstanceExtensionsWayland(char** extensions); void _glfwGetRequiredInstanceExtensionsWayland(char** extensions);
int _glfwGetPhysicalDevicePresentationSupportWayland(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); GLFWbool _glfwGetPhysicalDevicePresentationSupportWayland(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
VkResult _glfwCreateWindowSurfaceWayland(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); VkResult _glfwCreateWindowSurfaceWayland(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
void _glfwFreeMonitorWayland(_GLFWmonitor* monitor); void _glfwFreeMonitorWayland(_GLFWmonitor* monitor);
@ -495,5 +681,8 @@ GLFWbool _glfwGetGammaRampWayland(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
void _glfwSetGammaRampWayland(_GLFWmonitor* monitor, const GLFWgammaramp* ramp); void _glfwSetGammaRampWayland(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
void _glfwAddOutputWayland(uint32_t name, uint32_t version); void _glfwAddOutputWayland(uint32_t name, uint32_t version);
GLFWbool _glfwInputTextWayland(_GLFWwindow* window, uint32_t scancode); void _glfwUpdateContentScaleWayland(_GLFWwindow* window);
void _glfwAddSeatListenerWayland(struct wl_seat* seat);
void _glfwAddDataDeviceListenerWayland(struct wl_data_device* device);

File diff suppressed because it is too large Load Diff

View File

@ -24,17 +24,20 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_X11)
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <locale.h> #include <locale.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
// Translate the X11 KeySyms for a key to a GLFW key code // Translate the X11 KeySyms for a key to a GLFW key code
@ -601,7 +604,7 @@ static void detectEWMH(void)
// //
static GLFWbool initExtensions(void) static GLFWbool initExtensions(void)
{ {
#if defined(__OpenBSD__) #if defined(__OpenBSD__) || defined(__NetBSD__)
_glfw.x11.vidmode.handle = _glfwPlatformLoadModule("libXxf86vm.so"); _glfw.x11.vidmode.handle = _glfwPlatformLoadModule("libXxf86vm.so");
#else #else
_glfw.x11.vidmode.handle = _glfwPlatformLoadModule("libXxf86vm.so.1"); _glfw.x11.vidmode.handle = _glfwPlatformLoadModule("libXxf86vm.so.1");
@ -625,7 +628,7 @@ static GLFWbool initExtensions(void)
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
_glfw.x11.xi.handle = _glfwPlatformLoadModule("libXi-6.so"); _glfw.x11.xi.handle = _glfwPlatformLoadModule("libXi-6.so");
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
_glfw.x11.xi.handle = _glfwPlatformLoadModule("libXi.so"); _glfw.x11.xi.handle = _glfwPlatformLoadModule("libXi.so");
#else #else
_glfw.x11.xi.handle = _glfwPlatformLoadModule("libXi.so.6"); _glfw.x11.xi.handle = _glfwPlatformLoadModule("libXi.so.6");
@ -657,7 +660,7 @@ static GLFWbool initExtensions(void)
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
_glfw.x11.randr.handle = _glfwPlatformLoadModule("libXrandr-2.so"); _glfw.x11.randr.handle = _glfwPlatformLoadModule("libXrandr-2.so");
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
_glfw.x11.randr.handle = _glfwPlatformLoadModule("libXrandr.so"); _glfw.x11.randr.handle = _glfwPlatformLoadModule("libXrandr.so");
#else #else
_glfw.x11.randr.handle = _glfwPlatformLoadModule("libXrandr.so.2"); _glfw.x11.randr.handle = _glfwPlatformLoadModule("libXrandr.so.2");
@ -751,7 +754,7 @@ static GLFWbool initExtensions(void)
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
_glfw.x11.xcursor.handle = _glfwPlatformLoadModule("libXcursor-1.so"); _glfw.x11.xcursor.handle = _glfwPlatformLoadModule("libXcursor-1.so");
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
_glfw.x11.xcursor.handle = _glfwPlatformLoadModule("libXcursor.so"); _glfw.x11.xcursor.handle = _glfwPlatformLoadModule("libXcursor.so");
#else #else
_glfw.x11.xcursor.handle = _glfwPlatformLoadModule("libXcursor.so.1"); _glfw.x11.xcursor.handle = _glfwPlatformLoadModule("libXcursor.so.1");
@ -774,7 +777,7 @@ static GLFWbool initExtensions(void)
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
_glfw.x11.xinerama.handle = _glfwPlatformLoadModule("libXinerama-1.so"); _glfw.x11.xinerama.handle = _glfwPlatformLoadModule("libXinerama-1.so");
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
_glfw.x11.xinerama.handle = _glfwPlatformLoadModule("libXinerama.so"); _glfw.x11.xinerama.handle = _glfwPlatformLoadModule("libXinerama.so");
#else #else
_glfw.x11.xinerama.handle = _glfwPlatformLoadModule("libXinerama.so.1"); _glfw.x11.xinerama.handle = _glfwPlatformLoadModule("libXinerama.so.1");
@ -829,7 +832,7 @@ static GLFWbool initExtensions(void)
{ {
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
_glfw.x11.x11xcb.handle = _glfwPlatformLoadModule("libX11-xcb-1.so"); _glfw.x11.x11xcb.handle = _glfwPlatformLoadModule("libX11-xcb-1.so");
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
_glfw.x11.x11xcb.handle = _glfwPlatformLoadModule("libX11-xcb.so"); _glfw.x11.x11xcb.handle = _glfwPlatformLoadModule("libX11-xcb.so");
#else #else
_glfw.x11.x11xcb.handle = _glfwPlatformLoadModule("libX11-xcb.so.1"); _glfw.x11.x11xcb.handle = _glfwPlatformLoadModule("libX11-xcb.so.1");
@ -844,7 +847,7 @@ static GLFWbool initExtensions(void)
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
_glfw.x11.xrender.handle = _glfwPlatformLoadModule("libXrender-1.so"); _glfw.x11.xrender.handle = _glfwPlatformLoadModule("libXrender-1.so");
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
_glfw.x11.xrender.handle = _glfwPlatformLoadModule("libXrender.so"); _glfw.x11.xrender.handle = _glfwPlatformLoadModule("libXrender.so");
#else #else
_glfw.x11.xrender.handle = _glfwPlatformLoadModule("libXrender.so.1"); _glfw.x11.xrender.handle = _glfwPlatformLoadModule("libXrender.so.1");
@ -873,7 +876,7 @@ static GLFWbool initExtensions(void)
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
_glfw.x11.xshape.handle = _glfwPlatformLoadModule("libXext-6.so"); _glfw.x11.xshape.handle = _glfwPlatformLoadModule("libXext-6.so");
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
_glfw.x11.xshape.handle = _glfwPlatformLoadModule("libXext.so"); _glfw.x11.xshape.handle = _glfwPlatformLoadModule("libXext.so");
#else #else
_glfw.x11.xshape.handle = _glfwPlatformLoadModule("libXext.so.6"); _glfw.x11.xshape.handle = _glfwPlatformLoadModule("libXext.so.6");
@ -1042,6 +1045,37 @@ static Window createHelperWindow(void)
CWEventMask, &wa); CWEventMask, &wa);
} }
// Create the pipe for empty events without assumuing the OS has pipe2(2)
//
static GLFWbool createEmptyEventPipe(void)
{
if (pipe(_glfw.x11.emptyEventPipe) != 0)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to create empty event pipe: %s",
strerror(errno));
return GLFW_FALSE;
}
for (int i = 0; i < 2; i++)
{
const int sf = fcntl(_glfw.x11.emptyEventPipe[i], F_GETFL, 0);
const int df = fcntl(_glfw.x11.emptyEventPipe[i], F_GETFD, 0);
if (sf == -1 || df == -1 ||
fcntl(_glfw.x11.emptyEventPipe[i], F_SETFL, sf | O_NONBLOCK) == -1 ||
fcntl(_glfw.x11.emptyEventPipe[i], F_SETFD, df | FD_CLOEXEC) == -1)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to set flags for empty event pipe: %s",
strerror(errno));
return GLFW_FALSE;
}
}
return GLFW_TRUE;
}
// X error handler // X error handler
// //
static int errorHandler(Display *display, XErrorEvent* event) static int errorHandler(Display *display, XErrorEvent* event)
@ -1062,8 +1096,9 @@ static int errorHandler(Display *display, XErrorEvent* event)
// //
void _glfwGrabErrorHandlerX11(void) void _glfwGrabErrorHandlerX11(void)
{ {
assert(_glfw.x11.errorHandler == NULL);
_glfw.x11.errorCode = Success; _glfw.x11.errorCode = Success;
XSetErrorHandler(errorHandler); _glfw.x11.errorHandler = XSetErrorHandler(errorHandler);
} }
// Clears the X error handler callback // Clears the X error handler callback
@ -1072,7 +1107,8 @@ void _glfwReleaseErrorHandlerX11(void)
{ {
// Synchronize to make sure all commands are processed // Synchronize to make sure all commands are processed
XSync(_glfw.x11.display, False); XSync(_glfw.x11.display, False);
XSetErrorHandler(NULL); XSetErrorHandler(_glfw.x11.errorHandler);
_glfw.x11.errorHandler = NULL;
} }
// Reports the specified error, appending information about the last X error // Reports the specified error, appending information about the last X error
@ -1146,7 +1182,7 @@ GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform)
_glfwGetKeyScancodeX11, _glfwGetKeyScancodeX11,
_glfwSetClipboardStringX11, _glfwSetClipboardStringX11,
_glfwGetClipboardStringX11, _glfwGetClipboardStringX11,
#if defined(__linux__) #if defined(GLFW_BUILD_LINUX_JOYSTICK)
_glfwInitJoysticksLinux, _glfwInitJoysticksLinux,
_glfwTerminateJoysticksLinux, _glfwTerminateJoysticksLinux,
_glfwPollJoystickLinux, _glfwPollJoystickLinux,
@ -1225,7 +1261,7 @@ GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform)
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
void* module = _glfwPlatformLoadModule("libX11-6.so"); void* module = _glfwPlatformLoadModule("libX11-6.so");
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)
void* module = _glfwPlatformLoadModule("libX11.so"); void* module = _glfwPlatformLoadModule("libX11.so");
#else #else
void* module = _glfwPlatformLoadModule("libX11.so.6"); void* module = _glfwPlatformLoadModule("libX11.so.6");
@ -1495,6 +1531,9 @@ int _glfwInitX11(void)
getSystemContentScale(&_glfw.x11.contentScaleX, &_glfw.x11.contentScaleY); getSystemContentScale(&_glfw.x11.contentScaleX, &_glfw.x11.contentScaleY);
if (!createEmptyEventPipe())
return GLFW_FALSE;
if (!initExtensions()) if (!initExtensions())
return GLFW_FALSE; return GLFW_FALSE;
@ -1598,6 +1637,7 @@ void _glfwTerminateX11(void)
_glfw.x11.xi.handle = NULL; _glfw.x11.xi.handle = NULL;
} }
_glfwTerminateOSMesa();
// NOTE: These need to be unloaded after XCloseDisplay, as they register // NOTE: These need to be unloaded after XCloseDisplay, as they register
// cleanup callbacks that get called by that function // cleanup callbacks that get called by that function
_glfwTerminateEGL(); _glfwTerminateEGL();
@ -1608,5 +1648,13 @@ void _glfwTerminateX11(void)
_glfwPlatformFreeModule(_glfw.x11.xlib.handle); _glfwPlatformFreeModule(_glfw.x11.xlib.handle);
_glfw.x11.xlib.handle = NULL; _glfw.x11.xlib.handle = NULL;
} }
if (_glfw.x11.emptyEventPipe[0] || _glfw.x11.emptyEventPipe[1])
{
close(_glfw.x11.emptyEventPipe[0]);
close(_glfw.x11.emptyEventPipe[1]);
}
} }
#endif // _GLFW_X11

View File

@ -24,11 +24,11 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_X11)
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -614,3 +614,5 @@ GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* handle)
return monitor->x11.output; return monitor->x11.output;
} }
#endif // _GLFW_X11

View File

@ -453,6 +453,7 @@ typedef VkResult (APIENTRY *PFN_vkCreateXcbSurfaceKHR)(VkInstance,const VkXcbSur
typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice,uint32_t,xcb_connection_t*,xcb_visualid_t); typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice,uint32_t,xcb_connection_t*,xcb_visualid_t);
#include "xkb_unicode.h" #include "xkb_unicode.h"
#include "posix_poll.h"
#define GLFW_X11_WINDOW_STATE _GLFWwindowX11 x11; #define GLFW_X11_WINDOW_STATE _GLFWwindowX11 x11;
#define GLFW_X11_LIBRARY_WINDOW_STATE _GLFWlibraryX11 x11; #define GLFW_X11_LIBRARY_WINDOW_STATE _GLFWlibraryX11 x11;
@ -479,7 +480,6 @@ typedef struct _GLFWlibraryGLX
int eventBase; int eventBase;
int errorBase; int errorBase;
// dlopen handle for libGL.so.1
void* handle; void* handle;
// GLX 1.3 functions // GLX 1.3 functions
@ -566,6 +566,8 @@ typedef struct _GLFWlibraryX11
XContext context; XContext context;
// XIM input method // XIM input method
XIM im; XIM im;
// The previous X error handler, to be restored later
XErrorHandler errorHandler;
// Most recent error code received by X error handler // Most recent error code received by X error handler
int errorCode; int errorCode;
// Primary selection string (while the primary selection is owned) // Primary selection string (while the primary selection is owned)
@ -582,6 +584,7 @@ typedef struct _GLFWlibraryX11
double restoreCursorPosX, restoreCursorPosY; double restoreCursorPosX, restoreCursorPosY;
// The window whose disabled cursor mode is active // The window whose disabled cursor mode is active
_GLFWwindow* disabledCursorWindow; _GLFWwindow* disabledCursorWindow;
int emptyEventPipe[2];
// Window manager atoms // Window manager atoms
Atom NET_SUPPORTED; Atom NET_SUPPORTED;
@ -898,7 +901,7 @@ GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform);
int _glfwInitX11(void); int _glfwInitX11(void);
void _glfwTerminateX11(void); void _glfwTerminateX11(void);
int _glfwCreateWindowX11(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); GLFWbool _glfwCreateWindowX11(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowX11(_GLFWwindow* window); void _glfwDestroyWindowX11(_GLFWwindow* window);
void _glfwSetWindowTitleX11(_GLFWwindow* window, const char* title); void _glfwSetWindowTitleX11(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* images); void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* images);
@ -919,12 +922,12 @@ void _glfwHideWindowX11(_GLFWwindow* window);
void _glfwRequestWindowAttentionX11(_GLFWwindow* window); void _glfwRequestWindowAttentionX11(_GLFWwindow* window);
void _glfwFocusWindowX11(_GLFWwindow* window); void _glfwFocusWindowX11(_GLFWwindow* window);
void _glfwSetWindowMonitorX11(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); void _glfwSetWindowMonitorX11(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
int _glfwWindowFocusedX11(_GLFWwindow* window); GLFWbool _glfwWindowFocusedX11(_GLFWwindow* window);
int _glfwWindowIconifiedX11(_GLFWwindow* window); GLFWbool _glfwWindowIconifiedX11(_GLFWwindow* window);
int _glfwWindowVisibleX11(_GLFWwindow* window); GLFWbool _glfwWindowVisibleX11(_GLFWwindow* window);
int _glfwWindowMaximizedX11(_GLFWwindow* window); GLFWbool _glfwWindowMaximizedX11(_GLFWwindow* window);
int _glfwWindowHoveredX11(_GLFWwindow* window); GLFWbool _glfwWindowHoveredX11(_GLFWwindow* window);
int _glfwFramebufferTransparentX11(_GLFWwindow* window); GLFWbool _glfwFramebufferTransparentX11(_GLFWwindow* window);
void _glfwSetWindowResizableX11(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowResizableX11(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowDecoratedX11(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowDecoratedX11(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowFloatingX11(_GLFWwindow* window, GLFWbool enabled); void _glfwSetWindowFloatingX11(_GLFWwindow* window, GLFWbool enabled);
@ -945,8 +948,8 @@ void _glfwSetCursorPosX11(_GLFWwindow* window, double xpos, double ypos);
void _glfwSetCursorModeX11(_GLFWwindow* window, int mode); void _glfwSetCursorModeX11(_GLFWwindow* window, int mode);
const char* _glfwGetScancodeNameX11(int scancode); const char* _glfwGetScancodeNameX11(int scancode);
int _glfwGetKeyScancodeX11(int key); int _glfwGetKeyScancodeX11(int key);
int _glfwCreateCursorX11(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); GLFWbool _glfwCreateCursorX11(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot);
int _glfwCreateStandardCursorX11(_GLFWcursor* cursor, int shape); GLFWbool _glfwCreateStandardCursorX11(_GLFWcursor* cursor, int shape);
void _glfwDestroyCursorX11(_GLFWcursor* cursor); void _glfwDestroyCursorX11(_GLFWcursor* cursor);
void _glfwSetCursorX11(_GLFWwindow* window, _GLFWcursor* cursor); void _glfwSetCursorX11(_GLFWwindow* window, _GLFWcursor* cursor);
void _glfwSetClipboardStringX11(const char* string); void _glfwSetClipboardStringX11(const char* string);
@ -957,7 +960,7 @@ EGLNativeDisplayType _glfwGetEGLNativeDisplayX11(void);
EGLNativeWindowType _glfwGetEGLNativeWindowX11(_GLFWwindow* window); EGLNativeWindowType _glfwGetEGLNativeWindowX11(_GLFWwindow* window);
void _glfwGetRequiredInstanceExtensionsX11(char** extensions); void _glfwGetRequiredInstanceExtensionsX11(char** extensions);
int _glfwGetPhysicalDevicePresentationSupportX11(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); GLFWbool _glfwGetPhysicalDevicePresentationSupportX11(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
VkResult _glfwCreateWindowSurfaceX11(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); VkResult _glfwCreateWindowSurfaceX11(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
void _glfwFreeMonitorX11(_GLFWmonitor* monitor); void _glfwFreeMonitorX11(_GLFWmonitor* monitor);

View File

@ -24,15 +24,15 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_X11)
#include <X11/cursorfont.h> #include <X11/cursorfont.h>
#include <X11/Xmd.h> #include <X11/Xmd.h>
#include <sys/select.h> #include <poll.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -56,50 +56,79 @@
#define _GLFW_XDND_VERSION 5 #define _GLFW_XDND_VERSION 5
// Wait for event data to arrive on the X11 display socket
// Wait for data to arrive using select
// This avoids blocking other threads via the per-display Xlib lock that also // This avoids blocking other threads via the per-display Xlib lock that also
// covers GLX functions // covers GLX functions
// //
static GLFWbool waitForEvent(double* timeout) static GLFWbool waitForX11Event(double* timeout)
{ {
fd_set fds; struct pollfd fd = { ConnectionNumber(_glfw.x11.display), POLLIN };
const int fd = ConnectionNumber(_glfw.x11.display);
int count = fd + 1;
#if defined(__linux__) while (!XPending(_glfw.x11.display))
if (_glfw.linjs.inotify > fd)
count = _glfw.linjs.inotify + 1;
#endif
for (;;)
{ {
FD_ZERO(&fds); if (!_glfwPollPOSIX(&fd, 1, timeout))
FD_SET(fd, &fds);
#if defined(__linux__)
if (_glfw.linjs.inotify > 0)
FD_SET(_glfw.linjs.inotify, &fds);
#endif
if (timeout)
{
const long seconds = (long) *timeout;
const long microseconds = (long) ((*timeout - seconds) * 1e6);
struct timeval tv = { seconds, microseconds };
const uint64_t base = _glfwPlatformGetTimerValue();
const int result = select(count, &fds, NULL, NULL, &tv);
const int error = errno;
*timeout -= (_glfwPlatformGetTimerValue() - base) /
(double) _glfwPlatformGetTimerFrequency();
if (result > 0)
return GLFW_TRUE;
if ((result == -1 && error == EINTR) || *timeout <= 0.0)
return GLFW_FALSE; return GLFW_FALSE;
} }
else if (select(count, &fds, NULL, NULL, NULL) != -1 || errno != EINTR)
return GLFW_TRUE; return GLFW_TRUE;
}
// Wait for event data to arrive on any event file descriptor
// This avoids blocking other threads via the per-display Xlib lock that also
// covers GLX functions
//
static GLFWbool waitForAnyEvent(double* timeout)
{
nfds_t count = 2;
struct pollfd fds[3] =
{
{ ConnectionNumber(_glfw.x11.display), POLLIN },
{ _glfw.x11.emptyEventPipe[0], POLLIN }
};
#if defined(GLFW_BUILD_LINUX_JOYSTICK)
if (_glfw.joysticksInitialized)
fds[count++] = (struct pollfd) { _glfw.linjs.inotify, POLLIN };
#endif
while (!XPending(_glfw.x11.display))
{
if (!_glfwPollPOSIX(fds, count, timeout))
return GLFW_FALSE;
for (int i = 1; i < count; i++)
{
if (fds[i].revents & POLLIN)
return GLFW_TRUE;
}
}
return GLFW_TRUE;
}
// Writes a byte to the empty event pipe
//
static void writeEmptyEvent(void)
{
for (;;)
{
const char byte = 0;
const ssize_t result = write(_glfw.x11.emptyEventPipe[1], &byte, 1);
if (result == 1 || (result == -1 && errno != EINTR))
break;
}
}
// Drains available data from the empty event pipe
//
static void drainEmptyEvents(void)
{
for (;;)
{
char dummy[64];
const ssize_t result = read(_glfw.x11.emptyEventPipe[0], dummy, sizeof(dummy));
if (result == -1 && errno != EINTR)
break;
} }
} }
@ -116,7 +145,7 @@ static GLFWbool waitForVisibilityNotify(_GLFWwindow* window)
VisibilityNotify, VisibilityNotify,
&dummy)) &dummy))
{ {
if (!waitForEvent(&timeout)) if (!waitForX11Event(&timeout))
return GLFW_FALSE; return GLFW_FALSE;
} }
@ -241,6 +270,11 @@ static void updateNormalHints(_GLFWwindow* window, int width, int height)
{ {
XSizeHints* hints = XAllocSizeHints(); XSizeHints* hints = XAllocSizeHints();
long supplied;
XGetWMNormalHints(_glfw.x11.display, window->x11.handle, hints, &supplied);
hints->flags &= ~(PMinSize | PMaxSize | PAspect);
if (!window->monitor) if (!window->monitor)
{ {
if (window->resizable) if (window->resizable)
@ -277,9 +311,6 @@ static void updateNormalHints(_GLFWwindow* window, int width, int height)
} }
} }
hints->flags |= PWinGravity;
hints->win_gravity = StaticGravity;
XSetWMNormalHints(_glfw.x11.display, window->x11.handle, hints); XSetWMNormalHints(_glfw.x11.display, window->x11.handle, hints);
XFree(hints); XFree(hints);
} }
@ -378,57 +409,6 @@ static void updateWindowMode(_GLFWwindow* window)
} }
} }
// Splits and translates a text/uri-list into separate file paths
// NOTE: This function destroys the provided string
//
static char** parseUriList(char* text, int* count)
{
const char* prefix = "file://";
char** paths = NULL;
char* line;
*count = 0;
while ((line = strtok(text, "\r\n")))
{
text = NULL;
if (line[0] == '#')
continue;
if (strncmp(line, prefix, strlen(prefix)) == 0)
{
line += strlen(prefix);
// TODO: Validate hostname
while (*line != '/')
line++;
}
(*count)++;
char* path = _glfw_calloc(strlen(line) + 1, 1);
paths = _glfw_realloc(paths, *count * sizeof(char*));
paths[*count - 1] = path;
while (*line)
{
if (line[0] == '%' && line[1] && line[2])
{
const char digits[3] = { line[1], line[2], '\0' };
*path = strtol(digits, NULL, 16);
line += 2;
}
else
*path = *line;
path++;
line++;
}
}
return paths;
}
// Decode a Unicode code point from a UTF-8 stream // Decode a Unicode code point from a UTF-8 stream
// Based on cutef8 by Jeff Bezanson (Public Domain) // Based on cutef8 by Jeff Bezanson (Public Domain)
// //
@ -475,7 +455,8 @@ static char* convertLatin1toUTF8(const char* source)
// //
static void updateCursorImage(_GLFWwindow* window) static void updateCursorImage(_GLFWwindow* window)
{ {
if (window->cursorMode == GLFW_CURSOR_NORMAL) if (window->cursorMode == GLFW_CURSOR_NORMAL ||
window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (window->cursor) if (window->cursor)
{ {
@ -492,6 +473,25 @@ static void updateCursorImage(_GLFWwindow* window)
} }
} }
// Grabs the cursor and confines it to the window
//
static void captureCursor(_GLFWwindow* window)
{
XGrabPointer(_glfw.x11.display, window->x11.handle, True,
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync,
window->x11.handle,
None,
CurrentTime);
}
// Ungrabs the cursor
//
static void releaseCursor(void)
{
XUngrabPointer(_glfw.x11.display, CurrentTime);
}
// Enable XI2 raw mouse motion events // Enable XI2 raw mouse motion events
// //
static void enableRawMouseMotion(_GLFWwindow* window) static void enableRawMouseMotion(_GLFWwindow* window)
@ -534,12 +534,7 @@ static void disableCursor(_GLFWwindow* window)
&_glfw.x11.restoreCursorPosY); &_glfw.x11.restoreCursorPosY);
updateCursorImage(window); updateCursorImage(window);
_glfwCenterCursorInContentArea(window); _glfwCenterCursorInContentArea(window);
XGrabPointer(_glfw.x11.display, window->x11.handle, True, captureCursor(window);
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync,
window->x11.handle,
_glfw.x11.hiddenCursorHandle,
CurrentTime);
} }
// Exit disabled cursor mode for the specified window // Exit disabled cursor mode for the specified window
@ -550,7 +545,7 @@ static void enableCursor(_GLFWwindow* window)
disableRawMouseMotion(window); disableRawMouseMotion(window);
_glfw.x11.disabledCursorWindow = NULL; _glfw.x11.disabledCursorWindow = NULL;
XUngrabPointer(_glfw.x11.display, CurrentTime); releaseCursor();
_glfwSetCursorPosX11(window, _glfwSetCursorPosX11(window,
_glfw.x11.restoreCursorPosX, _glfw.x11.restoreCursorPosX,
_glfw.x11.restoreCursorPosY); _glfw.x11.restoreCursorPosY);
@ -580,6 +575,14 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
height *= _glfw.x11.contentScaleY; height *= _glfw.x11.contentScaleY;
} }
int xpos = 0, ypos = 0;
if (wndconfig->xpos != GLFW_ANY_POSITION && wndconfig->ypos != GLFW_ANY_POSITION)
{
xpos = wndconfig->xpos;
ypos = wndconfig->ypos;
}
// Create a colormap based on the visual used by the current context // Create a colormap based on the visual used by the current context
window->x11.colormap = XCreateColormap(_glfw.x11.display, window->x11.colormap = XCreateColormap(_glfw.x11.display,
_glfw.x11.root, _glfw.x11.root,
@ -600,7 +603,7 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
window->x11.parent = _glfw.x11.root; window->x11.parent = _glfw.x11.root;
window->x11.handle = XCreateWindow(_glfw.x11.display, window->x11.handle = XCreateWindow(_glfw.x11.display,
_glfw.x11.root, _glfw.x11.root,
0, 0, // Position xpos, ypos,
width, height, width, height,
0, // Border width 0, // Border width
depth, // Color depth depth, // Color depth
@ -703,7 +706,37 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
XFree(hints); XFree(hints);
} }
updateNormalHints(window, width, height); // Set ICCCM WM_NORMAL_HINTS property
{
XSizeHints* hints = XAllocSizeHints();
if (!hints)
{
_glfwInputError(GLFW_OUT_OF_MEMORY, "X11: Failed to allocate size hints");
return GLFW_FALSE;
}
if (!wndconfig->resizable)
{
hints->flags |= (PMinSize | PMaxSize);
hints->min_width = hints->max_width = width;
hints->min_height = hints->max_height = height;
}
// HACK: Explicitly setting PPosition to any value causes some WMs, notably
// Compiz and Metacity, to honor the position of unmapped windows
if (wndconfig->xpos != GLFW_ANY_POSITION && wndconfig->ypos != GLFW_ANY_POSITION)
{
hints->flags |= PPosition;
hints->x = 0;
hints->y = 0;
}
hints->flags |= PWinGravity;
hints->win_gravity = StaticGravity;
XSetWMNormalHints(_glfw.x11.display, window->x11.handle, hints);
XFree(hints);
}
// Set ICCCM WM_CLASS property // Set ICCCM WM_CLASS property
{ {
@ -887,20 +920,6 @@ static Atom writeTargetToProperty(const XSelectionRequestEvent* request)
return None; return None;
} }
static void handleSelectionClear(XEvent* event)
{
if (event->xselectionclear.selection == _glfw.x11.PRIMARY)
{
_glfw_free(_glfw.x11.primarySelectionString);
_glfw.x11.primarySelectionString = NULL;
}
else
{
_glfw_free(_glfw.x11.clipboardString);
_glfw.x11.clipboardString = NULL;
}
}
static void handleSelectionRequest(XEvent* event) static void handleSelectionRequest(XEvent* event)
{ {
const XSelectionRequestEvent* request = &event->xselectionrequest; const XSelectionRequestEvent* request = &event->xselectionrequest;
@ -958,7 +977,7 @@ static const char* getSelectionString(Atom selection)
SelectionNotify, SelectionNotify,
&notification)) &notification))
{ {
waitForEvent(NULL); waitForX11Event(NULL);
} }
if (notification.xselection.property == None) if (notification.xselection.property == None)
@ -994,7 +1013,7 @@ static const char* getSelectionString(Atom selection)
isSelPropNewValueNotify, isSelPropNewValueNotify,
(XPointer) &notification)) (XPointer) &notification))
{ {
waitForEvent(NULL); waitForX11Event(NULL);
} }
XFree(data); XFree(data);
@ -1020,6 +1039,8 @@ static const char* getSelectionString(Atom selection)
} }
if (!itemCount) if (!itemCount)
{
if (string)
{ {
if (targets[i] == XA_STRING) if (targets[i] == XA_STRING)
{ {
@ -1028,6 +1049,7 @@ static const char* getSelectionString(Atom selection)
} }
else else
*selectionString = string; *selectionString = string;
}
break; break;
} }
@ -1193,12 +1215,7 @@ static void processEvent(XEvent *event)
return; return;
} }
if (event->type == SelectionClear) if (event->type == SelectionRequest)
{
handleSelectionClear(event);
return;
}
else if (event->type == SelectionRequest)
{ {
handleSelectionRequest(event); handleSelectionRequest(event);
return; return;
@ -1238,7 +1255,7 @@ static void processEvent(XEvent *event)
// (the server never sends a timestamp of zero) // (the server never sends a timestamp of zero)
// NOTE: Timestamp difference is compared to handle wrap-around // NOTE: Timestamp difference is compared to handle wrap-around
Time diff = event->xkey.time - window->x11.keyPressTimes[keycode]; Time diff = event->xkey.time - window->x11.keyPressTimes[keycode];
if (diff == event->xkey.time || (diff > 0 && diff < (1 << 31))) if (diff == event->xkey.time || (diff > 0 && diff < ((Time)1 << 31)))
{ {
if (keycode) if (keycode)
_glfwInputKey(window, key, keycode, GLFW_PRESS, mods); _glfwInputKey(window, key, keycode, GLFW_PRESS, mods);
@ -1686,7 +1703,7 @@ static void processEvent(XEvent *event)
if (result) if (result)
{ {
int count; int count;
char** paths = parseUriList(data, &count); char** paths = _glfwParseUriList(data, &count);
_glfwInputDrop(window, count, (const char**) paths); _glfwInputDrop(window, count, (const char**) paths);
@ -1729,6 +1746,8 @@ static void processEvent(XEvent *event)
if (window->cursorMode == GLFW_CURSOR_DISABLED) if (window->cursorMode == GLFW_CURSOR_DISABLED)
disableCursor(window); disableCursor(window);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
captureCursor(window);
if (window->x11.ic) if (window->x11.ic)
XSetICFocus(window->x11.ic); XSetICFocus(window->x11.ic);
@ -1749,6 +1768,8 @@ static void processEvent(XEvent *event)
if (window->cursorMode == GLFW_CURSOR_DISABLED) if (window->cursorMode == GLFW_CURSOR_DISABLED)
enableCursor(window); enableCursor(window);
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
releaseCursor();
if (window->x11.ic) if (window->x11.ic)
XUnsetICFocus(window->x11.ic); XUnsetICFocus(window->x11.ic);
@ -1875,10 +1896,6 @@ void _glfwPushSelectionToManagerX11(void)
handleSelectionRequest(&event); handleSelectionRequest(&event);
break; break;
case SelectionClear:
handleSelectionClear(&event);
break;
case SelectionNotify: case SelectionNotify:
{ {
if (event.xselection.target == _glfw.x11.SAVE_TARGETS) if (event.xselection.target == _glfw.x11.SAVE_TARGETS)
@ -1896,7 +1913,7 @@ void _glfwPushSelectionToManagerX11(void)
} }
} }
waitForEvent(NULL); waitForX11Event(NULL);
} }
} }
@ -1937,7 +1954,7 @@ void _glfwCreateInputContextX11(_GLFWwindow* window)
////// GLFW platform API ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
int _glfwCreateWindowX11(_GLFWwindow* window, GLFWbool _glfwCreateWindowX11(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig, const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
@ -1994,13 +2011,31 @@ int _glfwCreateWindowX11(_GLFWwindow* window,
if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
} }
if (!_glfwRefreshContextAttribs(window, ctxconfig))
return GLFW_FALSE;
} }
if (wndconfig->mousePassthrough)
_glfwSetWindowMousePassthroughX11(window, GLFW_TRUE);
if (window->monitor) if (window->monitor)
{ {
_glfwShowWindowX11(window); _glfwShowWindowX11(window);
updateWindowMode(window); updateWindowMode(window);
acquireMonitor(window); acquireMonitor(window);
if (wndconfig->centerCursor)
_glfwCenterCursorInContentArea(window);
}
else
{
if (wndconfig->visible)
{
_glfwShowWindowX11(window);
if (wndconfig->focused)
_glfwFocusWindowX11(window);
}
} }
XFlush(_glfw.x11.display); XFlush(_glfw.x11.display);
@ -2010,7 +2045,7 @@ int _glfwCreateWindowX11(_GLFWwindow* window,
void _glfwDestroyWindowX11(_GLFWwindow* window) void _glfwDestroyWindowX11(_GLFWwindow* window)
{ {
if (_glfw.x11.disabledCursorWindow == window) if (_glfw.x11.disabledCursorWindow == window)
_glfw.x11.disabledCursorWindow = NULL; enableCursor(window);
if (window->monitor) if (window->monitor)
releaseMonitor(window); releaseMonitor(window);
@ -2238,7 +2273,7 @@ void _glfwGetWindowFrameSizeX11(_GLFWwindow* window,
isFrameExtentsEvent, isFrameExtentsEvent,
(XPointer) window)) (XPointer) window))
{ {
if (!waitForEvent(&timeout)) if (!waitForX11Event(&timeout))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"X11: The window manager has a broken _NET_REQUEST_FRAME_EXTENTS implementation; please report this issue"); "X11: The window manager has a broken _NET_REQUEST_FRAME_EXTENTS implementation; please report this issue");
@ -2486,7 +2521,7 @@ void _glfwSetWindowMonitorX11(_GLFWwindow* window,
XFlush(_glfw.x11.display); XFlush(_glfw.x11.display);
} }
int _glfwWindowFocusedX11(_GLFWwindow* window) GLFWbool _glfwWindowFocusedX11(_GLFWwindow* window)
{ {
Window focused; Window focused;
int state; int state;
@ -2495,19 +2530,19 @@ int _glfwWindowFocusedX11(_GLFWwindow* window)
return window->x11.handle == focused; return window->x11.handle == focused;
} }
int _glfwWindowIconifiedX11(_GLFWwindow* window) GLFWbool _glfwWindowIconifiedX11(_GLFWwindow* window)
{ {
return getWindowState(window) == IconicState; return getWindowState(window) == IconicState;
} }
int _glfwWindowVisibleX11(_GLFWwindow* window) GLFWbool _glfwWindowVisibleX11(_GLFWwindow* window)
{ {
XWindowAttributes wa; XWindowAttributes wa;
XGetWindowAttributes(_glfw.x11.display, window->x11.handle, &wa); XGetWindowAttributes(_glfw.x11.display, window->x11.handle, &wa);
return wa.map_state == IsViewable; return wa.map_state == IsViewable;
} }
int _glfwWindowMaximizedX11(_GLFWwindow* window) GLFWbool _glfwWindowMaximizedX11(_GLFWwindow* window)
{ {
Atom* states; Atom* states;
GLFWbool maximized = GLFW_FALSE; GLFWbool maximized = GLFW_FALSE;
@ -2541,7 +2576,7 @@ int _glfwWindowMaximizedX11(_GLFWwindow* window)
return maximized; return maximized;
} }
int _glfwWindowHoveredX11(_GLFWwindow* window) GLFWbool _glfwWindowHoveredX11(_GLFWwindow* window)
{ {
Window w = _glfw.x11.root; Window w = _glfw.x11.root;
while (w) while (w)
@ -2569,7 +2604,7 @@ int _glfwWindowHoveredX11(_GLFWwindow* window)
return GLFW_FALSE; return GLFW_FALSE;
} }
int _glfwFramebufferTransparentX11(_GLFWwindow* window) GLFWbool _glfwFramebufferTransparentX11(_GLFWwindow* window)
{ {
if (!window->x11.transparent) if (!window->x11.transparent)
return GLFW_FALSE; return GLFW_FALSE;
@ -2751,9 +2786,9 @@ GLFWbool _glfwRawMouseMotionSupportedX11(void)
void _glfwPollEventsX11(void) void _glfwPollEventsX11(void)
{ {
_GLFWwindow* window; drainEmptyEvents();
#if defined(__linux__) #if defined(GLFW_BUILD_LINUX_JOYSTICK)
if (_glfw.joysticksInitialized) if (_glfw.joysticksInitialized)
_glfwDetectJoystickConnectionLinux(); _glfwDetectJoystickConnectionLinux();
#endif #endif
@ -2766,7 +2801,7 @@ void _glfwPollEventsX11(void)
processEvent(&event); processEvent(&event);
} }
window = _glfw.x11.disabledCursorWindow; _GLFWwindow* window = _glfw.x11.disabledCursorWindow;
if (window) if (window)
{ {
int width, height; int width, height;
@ -2786,32 +2821,19 @@ void _glfwPollEventsX11(void)
void _glfwWaitEventsX11(void) void _glfwWaitEventsX11(void)
{ {
while (!XPending(_glfw.x11.display)) waitForAnyEvent(NULL);
waitForEvent(NULL);
_glfwPollEventsX11(); _glfwPollEventsX11();
} }
void _glfwWaitEventsTimeoutX11(double timeout) void _glfwWaitEventsTimeoutX11(double timeout)
{ {
while (!XPending(_glfw.x11.display)) waitForAnyEvent(&timeout);
{
if (!waitForEvent(&timeout))
break;
}
_glfwPollEventsX11(); _glfwPollEventsX11();
} }
void _glfwPostEmptyEventX11(void) void _glfwPostEmptyEventX11(void)
{ {
XEvent event = { ClientMessage }; writeEmptyEvent();
event.xclient.window = _glfw.x11.helperWindowHandle;
event.xclient.format = 32; // Data is 32-bit longs
event.xclient.message_type = _glfw.x11.NULL_;
XSendEvent(_glfw.x11.display, _glfw.x11.helperWindowHandle, False, 0, &event);
XFlush(_glfw.x11.display);
} }
void _glfwGetCursorPosX11(_GLFWwindow* window, double* xpos, double* ypos) void _glfwGetCursorPosX11(_GLFWwindow* window, double* xpos, double* ypos)
@ -2844,16 +2866,40 @@ void _glfwSetCursorPosX11(_GLFWwindow* window, double x, double y)
void _glfwSetCursorModeX11(_GLFWwindow* window, int mode) void _glfwSetCursorModeX11(_GLFWwindow* window, int mode)
{ {
if (_glfwWindowFocusedX11(window))
{
if (mode == GLFW_CURSOR_DISABLED) if (mode == GLFW_CURSOR_DISABLED)
{ {
if (_glfwWindowFocusedX11(window)) _glfwGetCursorPosX11(window,
disableCursor(window); &_glfw.x11.restoreCursorPosX,
&_glfw.x11.restoreCursorPosY);
_glfwCenterCursorInContentArea(window);
if (window->rawMouseMotion)
enableRawMouseMotion(window);
} }
else if (_glfw.x11.disabledCursorWindow == window) else if (_glfw.x11.disabledCursorWindow == window)
enableCursor(window); {
else if (window->rawMouseMotion)
updateCursorImage(window); disableRawMouseMotion(window);
}
if (mode == GLFW_CURSOR_DISABLED || mode == GLFW_CURSOR_CAPTURED)
captureCursor(window);
else
releaseCursor();
if (mode == GLFW_CURSOR_DISABLED)
_glfw.x11.disabledCursorWindow = window;
else if (_glfw.x11.disabledCursorWindow == window)
{
_glfw.x11.disabledCursorWindow = NULL;
_glfwSetCursorPosX11(window,
_glfw.x11.restoreCursorPosX,
_glfw.x11.restoreCursorPosY);
}
}
updateCursorImage(window);
XFlush(_glfw.x11.display); XFlush(_glfw.x11.display);
} }
@ -2892,7 +2938,7 @@ int _glfwGetKeyScancodeX11(int key)
return _glfw.x11.scancodes[key]; return _glfw.x11.scancodes[key];
} }
int _glfwCreateCursorX11(_GLFWcursor* cursor, GLFWbool _glfwCreateCursorX11(_GLFWcursor* cursor,
const GLFWimage* image, const GLFWimage* image,
int xhot, int yhot) int xhot, int yhot)
{ {
@ -2903,7 +2949,7 @@ int _glfwCreateCursorX11(_GLFWcursor* cursor,
return GLFW_TRUE; return GLFW_TRUE;
} }
int _glfwCreateStandardCursorX11(_GLFWcursor* cursor, int shape) GLFWbool _glfwCreateStandardCursorX11(_GLFWcursor* cursor, int shape)
{ {
if (_glfw.x11.xcursor.handle) if (_glfw.x11.xcursor.handle)
{ {
@ -3009,7 +3055,8 @@ void _glfwDestroyCursorX11(_GLFWcursor* cursor)
void _glfwSetCursorX11(_GLFWwindow* window, _GLFWcursor* cursor) void _glfwSetCursorX11(_GLFWwindow* window, _GLFWcursor* cursor)
{ {
if (window->cursorMode == GLFW_CURSOR_NORMAL) if (window->cursorMode == GLFW_CURSOR_NORMAL ||
window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
updateCursorImage(window); updateCursorImage(window);
XFlush(_glfw.x11.display); XFlush(_glfw.x11.display);
@ -3110,7 +3157,7 @@ void _glfwGetRequiredInstanceExtensionsX11(char** extensions)
extensions[1] = "VK_KHR_xlib_surface"; extensions[1] = "VK_KHR_xlib_surface";
} }
int _glfwGetPhysicalDevicePresentationSupportX11(VkInstance instance, GLFWbool _glfwGetPhysicalDevicePresentationSupportX11(VkInstance instance,
VkPhysicalDevice device, VkPhysicalDevice device,
uint32_t queuefamily) uint32_t queuefamily)
{ {
@ -3309,3 +3356,5 @@ GLFWAPI const char* glfwGetX11SelectionString(void)
return getSelectionString(_glfw.x11.PRIMARY); return getSelectionString(_glfw.x11.PRIMARY);
} }
#endif // _GLFW_X11

View File

@ -24,11 +24,10 @@
// distribution. // distribution.
// //
//======================================================================== //========================================================================
// It is fine to use C99 in this file because it will not be built with VS
//========================================================================
#include "internal.h" #include "internal.h"
#if defined(_GLFW_X11) || defined(_GLFW_WAYLAND)
/* /*
* Marcus: This code was originally written by Markus G. Kuhn. * Marcus: This code was originally written by Markus G. Kuhn.
@ -940,3 +939,5 @@ uint32_t _glfwKeySym2Unicode(unsigned int keysym)
return GLFW_INVALID_CODEPOINT; return GLFW_INVALID_CODEPOINT;
} }
#endif // _GLFW_WAYLAND or _GLFW_X11

View File

@ -172,7 +172,8 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
case GLFW_KEY_ESCAPE: case GLFW_KEY_ESCAPE:
{ {
if (glfwGetInputMode(window, GLFW_CURSOR) != GLFW_CURSOR_DISABLED) const int mode = glfwGetInputMode(window, GLFW_CURSOR);
if (mode != GLFW_CURSOR_DISABLED && mode != GLFW_CURSOR_CAPTURED)
{ {
glfwSetWindowShouldClose(window, GLFW_TRUE); glfwSetWindowShouldClose(window, GLFW_TRUE);
break; break;
@ -197,6 +198,11 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
printf("(( cursor is hidden ))\n"); printf("(( cursor is hidden ))\n");
break; break;
case GLFW_KEY_C:
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_CAPTURED);
printf("(( cursor is captured ))\n");
break;
case GLFW_KEY_R: case GLFW_KEY_R:
if (!glfwRawMouseMotionSupported()) if (!glfwRawMouseMotionSupported())
break; break;

View File

@ -642,7 +642,7 @@ int main(int argc, char** argv)
glfwMakeContextCurrent(slots[i].window); glfwMakeContextCurrent(slots[i].window);
gladLoadGL(glfwGetProcAddress); gladLoadGL(glfwGetProcAddress);
glfwSwapInterval(1); glfwSwapBuffers(slots[i].window);
} }
printf("Main loop starting\n"); printf("Main loop starting\n");

View File

@ -255,21 +255,6 @@ static void list_context_extensions(int client, int major, int minor)
} }
} }
static void list_vulkan_instance_extensions(void)
{
printf("Vulkan instance extensions:\n");
uint32_t ep_count;
vkEnumerateInstanceExtensionProperties(NULL, &ep_count, NULL);
VkExtensionProperties* ep = calloc(ep_count, sizeof(VkExtensionProperties));
vkEnumerateInstanceExtensionProperties(NULL, &ep_count, ep);
for (uint32_t i = 0; i < ep_count; i++)
printf(" %s (spec version %u)\n", ep[i].extensionName, ep[i].specVersion);
free(ep);
}
static void list_vulkan_instance_layers(void) static void list_vulkan_instance_layers(void)
{ {
printf("Vulkan instance layers:\n"); printf("Vulkan instance layers:\n");
@ -281,30 +266,16 @@ static void list_vulkan_instance_layers(void)
for (uint32_t i = 0; i < lp_count; i++) for (uint32_t i = 0; i < lp_count; i++)
{ {
printf(" %s (spec version %u) \"%s\"\n", printf(" %s (spec version %u.%u) \"%s\"\n",
lp[i].layerName, lp[i].layerName,
lp[i].specVersion >> 22, VK_VERSION_MAJOR(lp[i].specVersion),
VK_VERSION_MINOR(lp[i].specVersion),
lp[i].description); lp[i].description);
} }
free(lp); free(lp);
} }
static void list_vulkan_device_extensions(VkInstance instance, VkPhysicalDevice device)
{
printf("Vulkan device extensions:\n");
uint32_t ep_count;
vkEnumerateDeviceExtensionProperties(device, NULL, &ep_count, NULL);
VkExtensionProperties* ep = calloc(ep_count, sizeof(VkExtensionProperties));
vkEnumerateDeviceExtensionProperties(device, NULL, &ep_count, ep);
for (uint32_t i = 0; i < ep_count; i++)
printf(" %s (spec version %u)\n", ep[i].extensionName, ep[i].specVersion);
free(ep);
}
static void list_vulkan_device_layers(VkInstance instance, VkPhysicalDevice device) static void list_vulkan_device_layers(VkInstance instance, VkPhysicalDevice device)
{ {
printf("Vulkan device layers:\n"); printf("Vulkan device layers:\n");
@ -316,9 +287,10 @@ static void list_vulkan_device_layers(VkInstance instance, VkPhysicalDevice devi
for (uint32_t i = 0; i < lp_count; i++) for (uint32_t i = 0; i < lp_count; i++)
{ {
printf(" %s (spec version %u) \"%s\"\n", printf(" %s (spec version %u.%u) \"%s\"\n",
lp[i].layerName, lp[i].layerName,
lp[i].specVersion >> 22, VK_VERSION_MAJOR(lp[i].specVersion),
VK_VERSION_MINOR(lp[i].specVersion),
lp[i].description); lp[i].description);
} }
@ -740,12 +712,8 @@ int main(int argc, char** argv)
glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, cocoa_graphics_switching); glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, cocoa_graphics_switching);
GLFWwindow* window = glfwCreateWindow(200, 200, "Version", NULL, NULL); GLFWwindow* window = glfwCreateWindow(200, 200, "Version", NULL, NULL);
if (!window) if (window)
{ {
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
gladLoadGL(glfwGetProcAddress); gladLoadGL(glfwGetProcAddress);
@ -923,6 +891,7 @@ int main(int argc, char** argv)
list_context_extensions(client, major, minor); list_context_extensions(client, major, minor);
glfwDestroyWindow(window); glfwDestroyWindow(window);
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
@ -953,20 +922,51 @@ int main(int argc, char** argv)
VK_VERSION_MAJOR(loader_version), VK_VERSION_MAJOR(loader_version),
VK_VERSION_MINOR(loader_version)); VK_VERSION_MINOR(loader_version));
uint32_t re_count; uint32_t glfw_re_count;
const char** re = glfwGetRequiredInstanceExtensions(&re_count); const char** glfw_re = glfwGetRequiredInstanceExtensions(&glfw_re_count);
if (re) uint32_t re_count = glfw_re_count;
const char** re = calloc(glfw_re_count, sizeof(char*));
if (glfw_re)
{ {
printf("Vulkan window surface required instance extensions:\n"); printf("Vulkan window surface required instance extensions:\n");
for (uint32_t i = 0; i < re_count; i++) for (uint32_t i = 0; i < glfw_re_count; i++)
printf(" %s\n", re[i]); {
printf(" %s\n", glfw_re[i]);
re[i] = glfw_re[i];
}
} }
else else
printf("Vulkan window surface extensions missing\n"); printf("Vulkan window surface extensions missing\n");
uint32_t ep_count;
vkEnumerateInstanceExtensionProperties(NULL, &ep_count, NULL);
VkExtensionProperties* ep = calloc(ep_count, sizeof(VkExtensionProperties));
vkEnumerateInstanceExtensionProperties(NULL, &ep_count, ep);
if (list_extensions) if (list_extensions)
list_vulkan_instance_extensions(); {
printf("Vulkan instance extensions:\n");
for (uint32_t i = 0; i < ep_count; i++)
printf(" %s (spec version %u)\n", ep[i].extensionName, ep[i].specVersion);
}
bool portability_enumeration = false;
for (uint32_t i = 0; i < ep_count; i++)
{
if (strcmp(ep[i].extensionName, "VK_KHR_portability_enumeration") != 0)
continue;
re_count++;
re = realloc((void*) re, sizeof(char*) * re_count);
re[re_count - 1] = "VK_KHR_portability_enumeration";
portability_enumeration = true;
}
free(ep);
if (list_layers) if (list_layers)
list_vulkan_instance_layers(); list_vulkan_instance_layers();
@ -987,6 +987,9 @@ int main(int argc, char** argv)
ici.enabledExtensionCount = re_count; ici.enabledExtensionCount = re_count;
ici.ppEnabledExtensionNames = re; ici.ppEnabledExtensionNames = re;
if (portability_enumeration)
ici.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
VkInstance instance = VK_NULL_HANDLE; VkInstance instance = VK_NULL_HANDLE;
if (vkCreateInstance(&ici, NULL, &instance) != VK_SUCCESS) if (vkCreateInstance(&ici, NULL, &instance) != VK_SUCCESS)
@ -995,9 +998,11 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
free((void*) re);
gladLoadVulkanUserPtr(NULL, (GLADuserptrloadfunc) glfwGetInstanceProcAddress, instance); gladLoadVulkanUserPtr(NULL, (GLADuserptrloadfunc) glfwGetInstanceProcAddress, instance);
if (re) if (glfw_re_count)
{ {
VkSurfaceKHR surface = VK_NULL_HANDLE; VkSurfaceKHR surface = VK_NULL_HANDLE;
@ -1020,16 +1025,44 @@ int main(int argc, char** argv)
VkPhysicalDeviceProperties pdp; VkPhysicalDeviceProperties pdp;
vkGetPhysicalDeviceProperties(pd[i], &pdp); vkGetPhysicalDeviceProperties(pd[i], &pdp);
uint32_t qfp_count;
vkGetPhysicalDeviceQueueFamilyProperties(pd[i], &qfp_count, NULL);
uint32_t ep_count;
vkEnumerateDeviceExtensionProperties(pd[i], NULL, &ep_count, NULL);
VkExtensionProperties* ep = calloc(ep_count, sizeof(VkExtensionProperties));
vkEnumerateDeviceExtensionProperties(pd[i], NULL, &ep_count, ep);
if (portability_enumeration)
{
bool conformant = true;
for (uint32_t j = 0; j < ep_count; j++)
{
if (strcmp(ep[j].extensionName, "VK_KHR_portability_subset") == 0)
{
conformant = false;
break;
}
}
printf("Vulkan %s %s device: \"%s\" (API version %i.%i)\n",
conformant ? "conformant" : "non-conformant",
get_device_type_name(pdp.deviceType),
pdp.deviceName,
VK_VERSION_MAJOR(pdp.apiVersion),
VK_VERSION_MINOR(pdp.apiVersion));
}
else
{
printf("Vulkan %s device: \"%s\" (API version %i.%i)\n", printf("Vulkan %s device: \"%s\" (API version %i.%i)\n",
get_device_type_name(pdp.deviceType), get_device_type_name(pdp.deviceType),
pdp.deviceName, pdp.deviceName,
VK_VERSION_MAJOR(pdp.apiVersion), VK_VERSION_MAJOR(pdp.apiVersion),
VK_VERSION_MINOR(pdp.apiVersion)); VK_VERSION_MINOR(pdp.apiVersion));
}
uint32_t qfp_count; if (glfw_re_count)
vkGetPhysicalDeviceQueueFamilyProperties(pd[i], &qfp_count, NULL);
if (re)
{ {
printf("Vulkan device queue family presentation support:\n"); printf("Vulkan device queue family presentation support:\n");
for (uint32_t j = 0; j < qfp_count; j++) for (uint32_t j = 0; j < qfp_count; j++)
@ -1043,7 +1076,13 @@ int main(int argc, char** argv)
} }
if (list_extensions) if (list_extensions)
list_vulkan_device_extensions(instance, pd[i]); {
printf("Vulkan device extensions:\n");
for (uint32_t j = 0; j < ep_count; j++)
printf(" %s (spec version %u)\n", ep[j].extensionName, ep[j].specVersion);
}
free(ep);
if (list_layers) if (list_layers)
list_vulkan_device_layers(instance, pd[i]); list_vulkan_device_layers(instance, pd[i]);

View File

@ -96,10 +96,11 @@ int main(void)
if (!glfwInit()) if (!glfwInit())
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
glfwWindowHint(GLFW_POSITION_X, 200 + 250 * i);
glfwWindowHint(GLFW_POSITION_Y, 200);
threads[i].window = glfwCreateWindow(200, 200, threads[i].window = glfwCreateWindow(200, 200,
threads[i].title, threads[i].title,
NULL, NULL); NULL, NULL);
@ -110,9 +111,6 @@ int main(void)
} }
glfwSetKeyCallback(threads[i].window, key_callback); glfwSetKeyCallback(threads[i].window, key_callback);
glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200);
glfwShowWindow(threads[i].window);
} }
glfwMakeContextCurrent(threads[0].window); glfwMakeContextCurrent(threads[0].window);

Some files were not shown because too many files have changed in this diff Show More