Commit Graph

2840 Commits

Author SHA1 Message Date
Camilla Löwy
2b504e41d5 Wayland: Clean up listener struct initialization
Adapt style to match the rest of the project.

(cherry picked from commit 0f38382e25)
2022-06-09 19:34:29 +02:00
Camilla Löwy
50d5de7cd4 Wayland: Make data offer reading a generic utility
This will be needed for drag and drop reception as well.

(cherry picked from commit f010335b8c)
2022-06-09 19:32:18 +02:00
Camilla Löwy
4d0e98d90c Wayland: Move window related code to window module
The Wayland backend was the only one where half the window and input
related code was in the init module.  As those bits want to share more
utility code with the window module, the interface between them grows.

To prevent that, this gathers nearly all window and input related code
into the window module.

This is adapted to 3.3-stable from
b7a3af9b79.
2022-06-09 19:29:12 +02:00
Camilla Löwy
c0c0d172a1 Wayland: Remove check for error that cannot happen
Famous last words.

(cherry picked from commit 967282c2e6)
2022-05-06 19:34:06 +02:00
Camilla Löwy
9e852ec39e Wayland: Remove error reporting of external bugs
Not sure that GLFW should be reporting that another client has made an
invalid receive request.

(cherry picked from commit 8d216054ad)
2022-05-06 19:34:06 +02:00
Camilla Löwy
4d68daedc9 Wayland: Clean up clipboard writing
(cherry picked from commit 34418951cc)
2022-05-06 19:34:06 +02:00
Camilla Löwy
ea1b6b9638 Move URI list parsing to shared code
This will soon be used by the Wayland backend.

(cherry picked from commit ad4a9e42f0)
2022-05-06 19:34:06 +02:00
Camilla Löwy
f145e1f930 Wayland: Add strerror output to error descriptions
(cherry picked from commit e0889736fd)
2022-05-06 19:34:06 +02:00
Camilla Löwy
915e43885c Wayland: Clean up clipboard reading
(cherry picked from commit c132135332)
2022-05-06 19:34:06 +02:00
Camilla Löwy
857fae4920 Wayland: Simplify clipboard string allocation
(cherry picked from commit 4651165272)
2022-05-06 19:34:06 +02:00
Camilla Löwy
a31c648127 Wayland: Improve handling of pending data offers
The code assumed that all data offers were selections that supported
plaintext UTF-8.

The initial data offer events are now handled almost tolerably.  Only
selection data offers are used for clipboard string and only if they
provide plaintext UTF-8.  Drag and drop data offers are now rejected as
soon as they enter a surface.

Related to #2040

(cherry picked from commit 8d87be1268)
2022-05-06 19:34:06 +02:00
Camilla Löwy
c89899a428 Wayland: Return our clipboard without roundtrips
(cherry picked from commit 89d3ea8d69)
2022-05-06 19:34:06 +02:00
Camilla Löwy
75b27849f6 Wayland: Fix error paths not closing sending fd
Whatever error happens on our end, we should still close the fd so the
other end can move on.

(cherry picked from commit 990dc4b388)
2022-05-06 19:34:05 +02:00
Camilla Löwy
f51ec79951 Wayland: Rename listener user data parameters
(cherry picked from commit a4460b694e)
2022-05-06 19:34:05 +02:00
Camilla Löwy
3599fe4a78 Wayland: Clean up pointer declarations
Adapt style to match the rest of the project.

(cherry picked from commit 4506175023)
2022-05-06 19:34:05 +02:00
Camilla Löwy
1ee540bf48 Wayland: Rename data transfer parameters
No rationale beyond personal preference.

(cherry picked from commit ba11e60859)
2022-05-06 19:34:05 +02:00
Camilla Löwy
32bedd9a94 Wayland: Fix phrasing of error messages
This is adapted to 3.3-stable from
2d45681bc3.
2022-05-06 19:34:05 +02:00
Camilla Löwy
25db8f8014 Wayland: Fix partial writes of clipboard string
The string pointer used to write the contents of our clipboard data
offer was never updated, causing it to repeat parts of the beginning of
the string until the correct number of bytes had been written.

(cherry picked from commit 4c110bba41)
2022-05-06 19:34:05 +02:00
Camilla Löwy
2430d6b7f7 Wayland: Remove superfluous global struct member
It seems unlikely that strlen will be a bottleneck when sending
clipboard contents.

(cherry picked from commit 738b1c73b5)
2022-05-06 19:34:05 +02:00
Camilla Löwy
53bd67ccfe Wayland: Fix double free on data source error
If data source creation fails, the string containing the data for it
would be freed a second time during termination.

(cherry picked from commit b386371f57)
2022-05-06 19:34:05 +02:00
Camilla Löwy
22f718dcf4 Wayland: Fix handling of clipboard set to self
Passing any part of the result of glfwGetClipboardString to
glfwSetClipboardString would result in, at best, a use-after-free error.

(cherry picked from commit 9c95cfb9f1)
2022-05-06 19:34:05 +02:00
Camilla Löwy
f93751ce68 Fix missing newline
(cherry picked from commit 920d110b6c)
2022-05-06 19:34:05 +02:00
Camilla Löwy
8897c8a1cb POSIX: Fix data type of return values
(cherry picked from commit 554cbdb205)
2022-05-06 19:34:05 +02:00
Camilla Löwy
307ccd68a5 Cocoa: Fix AirPlay causing harmless init error
Emitting an error for one specific type of failure in retrieving the
correct name for a display is not very useful, especially when
initialization is otherwise unaffected.

There should be a path for information like that but this isn't it.

Fixes #1791

(cherry picked from commit 955fbd9d26)
2022-05-06 19:34:05 +02:00
Camilla Löwy
de550b60e5 Win32: Fix using executable instance and not ours
Operations that take an instance handle should be passed the handle of
whatever module we are inside instead of blindly passing the handle of
the executable.

This commit makes GLFW retrieve its own instance on initialization.

This makes the most difference for window classes, which are
per-instance.  Using the executable instance led to name conflicts if
there were several copies of GLFW in a single process.

Note that having this is still a bad idea unless you know what things to
avoid, and those things are mostly platform-specific.  This is partly
because the library wasn't designed for it and partly because it needs
to save, update and restore various per-process and per-session settings
like current context and video mode.

However, multiple simultaneous copies of GLFW in a single Win32 process
should now at least initialize, like is already the case on other
platforms.

Fixes #469
Fixes #1296
Fixes #1395
Related to #927
Related to #1885

(cherry picked from commit 07a5518c3e)
2022-05-06 19:34:05 +02:00
Camilla Löwy
802882f7cb Add checks for some invalid values to public API
There were no checks for invalid values or asserts for all invalid NULL
pointers to glfwSetWindowIcon or glfwCreateCursor.

Fixes #1862

(cherry picked from commit 66a4882eb1)
2022-05-06 19:34:05 +02:00
Camilla Löwy
c2ccf6f919 Win32: Fix glfwGetKeyScancode for GLFW_KEY_PAUSE
The bug described in 03cfe957e7 was
already present for another key where modifiers changes its scancode.

Related to #1993

(cherry picked from commit 8d9231fe5e)
2022-05-06 19:34:04 +02:00
Camilla Löwy
32df2ed716 Win32: Fix scancode and key for Alt+PrtSc events
Alt+PrtSc emits a different scancode than just PrtSc.  Since the GLFW
API assumes each key corresponds to only one scancode, this cannot be
added to the keycodes array.

Instead we replace the scancode at the point of entry.

Fixes #1993

(cherry picked from commit 03cfe957e7)
2022-05-06 19:34:04 +02:00
Camilla Löwy
3006c02bc2 Add shared min and max functions for int
(cherry picked from commit 3ee5031fd7)
2022-05-03 15:33:08 +02:00
Slemmie
d9fd087bbf X11: Fix undefined behavior in bit shift of int
Closes #1951

(cherry picked from commit b54fb0af10)
2022-03-20 16:02:44 +01:00
Camilla Löwy
5688fb19e6 Win32: Update rationale for reimplementation
It is true that plain MinGW lacks this header, but that is not the main
reason for reimplementing IsWindowsVersionOrGreater.

(cherry picked from commit aa803f7de5)
2022-03-20 16:02:08 +01:00
Camilla Löwy
d1269c1b7d Win32: Fix calls to encoding compatibility macros
Calls to Unicode specific functions should be made explicit.

(cherry picked from commit 8ff9ed92b4)
2022-03-20 16:00:34 +01:00
Camilla Löwy
541b151cff Win32: Fix maximization showing a hidden window
The normal way of maximizing a window also makes it visible.  This
implements window maximization manually for when the window passed to
glfwMaximizeWindow is hidden.

This will very likely not be forward-compatible and should be replaced.

(cherry picked from commit 723f3eb40d)
2022-03-20 15:57:10 +01:00
Camilla Löwy
85a3bf40fb Win32: Fix scale fixup losing initial position
The window content scale correction at creation overwrote the inital,
more pleasant placement of the window by CW_USEDEFAULT, if the window
was created with GLFW_MAXIMIZED set.  This is because the translation
to screen coordinates was done using the current position, not the
position from the restored window rect.

(cherry picked from commit 367d06deaf)
2022-03-20 15:53:39 +01:00
Camilla Löwy
d9512b694b Win32: Fix rect of undecorated maximized windows
A window created maximized and undecorated would cover the whole monitor
Windows placed it on instead of just that monitor's workarea.

This commit adjusts the maximized rect to cover just the workarea,
similar to how undecorated windows that become maximized are handled
during WM_GETMINMAXINFO.

Fixes #1806

(cherry picked from commit a730acf8e5)
2022-03-20 15:51:55 +01:00
Camilla Löwy
35a65361ff POSIX: Fix undeclared function warning on Cygwin
(cherry picked from commit adc202d2c3)
2022-03-13 16:45:17 +01:00
Camilla Löwy
6659a80040 X11: Fix sonames for loaded libraries on NetBSD
The NetBSD sonames for X11 and related libraries is more stable than on
OpenBSD but the version numbers are still bumped more often than their
Linux counterparts, even excluding the one-time version bump across all
X11 related libraries.

This commit moves to using version-less sonames for X11 and related
libraries on NetBSD, which will hopefully be more forward-compatible
than hard-coding NetBSD-specific sonames.

This may not be the correct long-term solution but it runs now.

Binaries also appear to need an LD_LIBRARY_PATH or rpath entry of
/usr/X11R7/lib in order for the libraries to be found by dlopen.

Tested on NetBSD 9.2.

(cherry picked from commit d78b0a4ead)
2022-03-13 16:43:58 +01:00
Camilla Löwy
9cfd4c49b0 Wayland: Improve event processing with timeout
If the polling was interrupted by a signal or by incomplete or unrelated
data on any file descriptor, handleEvents could return before the full
timeout had elapsed.

This retries the Wayland prepare-to-read and poll until the full timeout
has elapsed or until any event was processed.  Unfortunately, due to how
the Wayland client API is designed, this also includes the delete_id
for the frame callback created by eglSwapBuffers.

This means glfwWaitEvents* are still not fully functional on Wayland.
See #1911 for more details.

(cherry picked from commit 71742d9a27)
2022-03-13 16:38:02 +01:00
Camilla Löwy
eac18b9324 Wayland: Fix glfwPostEmptyEvent not always working
The display sync requests in glfwPostEmptyEvent could just accumulate as
the display was never flushed on secondary threads.

This adds a proper flush after each sync request.

Fixes #1520
Closes #1521

(cherry picked from commit a32cbf6d4f)
2022-03-13 16:36:17 +01:00
Camilla Löwy
499a5a7917 Formatting
(cherry picked from commit 7ce1f3e1cf)
2022-03-13 16:35:41 +01:00
Camilla Löwy
b0af476799 Wayland: Adopt the poll wrapper from X11
This is adapted to 3.3-stable from
bb9d699ae6.
2022-03-13 16:25:19 +01:00
Camilla Löwy
9dd3f25d6d Wayland: Cancel display fd read before callbacks
Cancel the prepared-to-read state on the calling thread before starting
to call back to user code.

Emitting close requests here is not a good choice but that is for
a future commit to address.

(cherry picked from commit 203a7c59d2)
2022-03-13 16:19:31 +01:00
Camilla Löwy
7302a8f520 Wayland: Fix potential incomplete display flushing
The flushing of a Wayland display may need to be done in several steps,
signalled by it failing with EAGAIN.

(cherry picked from commit 3c2913dcb9)
2022-03-13 16:18:56 +01:00
Camilla Löwy
9f73e9afa3 X11: Use lower-latency poll where available
This uses ppoll for waiting on file descriptors with a timeout, where
that function has been available a while.  On NetBSD, which will be
getting ppoll in the next release, the equivalent pollts is used.

This commit is based on work by OlivierSohn and kovidgoyal.

Related to #1281
Related to #1285

(cherry picked from commit 84b0923fe6)
2022-03-13 16:18:07 +01:00
Camilla Löwy
5ccc756c56 X11: Fix empty event race condition with a pipe
There is a seemingly unavoidable race condition when waiting for data on
the X11 display connection, as long as any other thread is also making
Xlib calls.  The event data we are waiting for could be read by the
other thread as part of looking for the reply to its request, before our
poll has begun.

This commit replaces the X11 event sent by glfwPostEmptyEvent with
writing to an unnamed pipe.  The race condition remains if other Xlib
calls are made on other threads, but glfwPostEmptyEvent should now be
race-free.

This commit is based on work by pcwalton, OlivierSohn, kovidgoyal and
joaodasilva.

Closes #2033
Related to #379
Related to #1281
Related to #1285

(cherry picked from commit cd22e28495)
2022-03-13 16:17:25 +01:00
Camilla Löwy
e219c00d87 Cleanup
(cherry picked from commit 363d471441)
2022-03-13 16:13:54 +01:00
Camilla Löwy
7f752c17c6 X11: Fix glfwWaitEvents* ignoring joystick events
The data available on the X11 connection may be a reply or an internal
event for an X11 extension.  Previously the check for whether an event
was available for us was done outside waitForEvent.  This prevented data
available on other file descriptors from breaking the outer wait loop.

This commit moves the check for whether an event is available into the
wait functions, where there is enough knowledge to limit the check to
the X11 connection.

Related to #932

(cherry picked from commit 87970b7f26)
2022-03-13 16:13:34 +01:00
Camilla Löwy
811e6bb01c X11: Fix joystick events causing busy waiting
On Linux, the inotify descriptor was included in the set used for
select, but could not break the outer loop, leading to busy waiting
until timeout or the correct X11 event arrived.

This commit adds a new function for waiting just on X11 events.

Fixes #1872

(cherry picked from commit 1e987cb92e)
2022-03-13 16:11:28 +01:00
Camilla Löwy
b4aa5f626f X11: Retry poll when failed with EINTR or EAGAIN
Both of these errors should just lead to local retry.

(cherry picked from commit 92b5c67b50)
2022-03-13 16:08:48 +01:00
Camilla Löwy
ca1a98e7a2 X11: Fix event polling when event fd > 1023
This replaces select with poll for checking for data on event file
descriptors, as select cannot handle file descriptors larger than 1023.

Closes #2024

(cherry picked from commit d3e4fcf8b7)
2022-03-13 16:07:11 +01:00
Camilla Löwy
54f2a865e9 GLX: Fix context creation failing unnecessarily
Regression introduced with 3bb5c459d6.

(cherry picked from commit 2e656afc49)
2022-03-13 15:42:22 +01:00
Camilla Löwy
09470b68c1 Wayland: Clean up monitor scale update
(cherry picked from commit 20adc18aa5)
2022-03-13 15:39:58 +01:00
Camilla Löwy
9340324380 Wayland: Fix error type for allocation failure
(cherry picked from commit 152f50cd01)
2022-03-13 15:37:39 +01:00
Camilla Löwy
7a4813cedd Wayland: Remove unnecessary NULL checks
It is fine to pass NULL to free.

(cherry picked from commit 4a68926bfd)
2022-03-13 15:37:08 +01:00
Camilla Löwy
d1c0797630 Wayland: Fix multiple copies of single constant
(cherry picked from commit a28adba06a)
2022-03-13 15:34:34 +01:00
Camilla Löwy
b716ff5b97 Cocoa: Clarify comments on compatibility macros
(cherry picked from commit 97da62a027)
2022-02-15 21:25:42 +01:00
Camilla Löwy
dccec7fcae Cocoa: Fix deprecation warning for kUTTypeURL
We switched to kUTTypeURL when NSURLPboardType was deprecated, as the
official replacement symbol NSPasteboardTypeURL was not available on
every version of macOS supported by GLFW.

kUTTypeURL has now also been deprecated.

This commit moves to a compile-time choice between NSURLPboardType and
NSPasteboardTypeURL depending on the minimum targeted macOS version.

Fixes #2003

(cherry picked from commit 7f6aa587f8)
2022-02-15 21:24:03 +01:00
Camilla Löwy
4bf6bd42fd Wayland: Clean up modifier key event handler
Adapt style and naming to match the rest of the project.

(cherry picked from commit df8d7bc892)
2022-02-15 21:23:09 +01:00
Camilla Löwy
c68ad09c04 Wayland: Clean up key translation
Adapt style and naming to match the rest of the project.

(cherry picked from commit 0ce611958e)
2022-02-15 21:23:02 +01:00
Camilla Löwy
e155c19f8e Wayland: Fix text input not following key repeat
The manual key repeat implementation did not call text input.

(cherry picked from commit 1a7da42e6e)
2022-02-15 21:22:26 +01:00
Camilla Löwy
6b15731e6c Wayland: Clean up key event handler
Adapt style and naming to match the rest of the project.

(cherry picked from commit bf99587005)
2022-02-15 21:21:43 +01:00
Camilla Löwy
554f5d0492 Wayland: Require xkbcommon 0.5.0 or greater
The Wayland backend now requires xkbcommon-compose, which was added in
version 0.5.0.  xkbcommon 0.5.0 was released in 2014.

This removes the non-composing fallback path for text input.

(cherry picked from commit 293d19a153)
2022-02-15 21:20:28 +01:00
Camilla Löwy
3901824c0e Wayland: Clean up text input
Adapt style and naming to match the rest of the project.

(cherry picked from commit b70259e52d)
2022-02-15 21:08:41 +01:00
Camilla Löwy
5066f57371 Clean up internal Unicode code point handling
Call code points by their name and store them as uint32_t.

(cherry picked from commit fe7be39793)
2022-02-15 21:08:17 +01:00
Camilla Löwy
1f7ce12cbc Wayland: Implement key name support
(cherry picked from commit 17a9e34fbc)
2022-02-15 21:02:07 +01:00
Camilla Löwy
0eaf9d557f Move UTF-8 encoding to shared code
This will be used by the Wayland code too.

(cherry picked from commit cb22c54119)
2022-02-15 20:58:44 +01:00
Camilla Löwy
61497796e6 Wayland: Fix keys reported as wrong or unknown key
(cherry picked from commit 37b7540db9)
2022-02-15 20:58:07 +01:00
Camilla Löwy
86a1d3b628 Wayland: Fix GLFW_VISIBLE affecting full screen
Full screen window creation was not ignoring the GLFW_VISIBLE hint.

(cherry picked from commit 715b874db3)
2022-02-15 20:57:26 +01:00
Camilla Löwy
f5dab59071 Wayland: Fix missing damage event on window show
By definition a hidden window on Wayland does not have valid framebuffer
contents.

This adds a window damage (refresh) event when a window is shown, to
request an initial frame for the now visible window.

(cherry picked from commit 25c521cbe5)
2022-02-15 20:56:21 +01:00
Camilla Löwy
658c931561 Wayland: Fix window not visible after initial swap
A window created with GLFW_VISIBLE set was not made visible by the
initial buffer swap during context attribute refresh.

Regression introduced by @elmindreda in
094aa6d3c7.

(cherry picked from commit c05acf6246)
2022-02-15 20:55:35 +01:00
Camilla Löwy
0c46a730de Wayland: Remove window monitor array pre-alloc
The array will be allocated by surfaceHandleEnter when needed.

(cherry picked from commit 12c2ccd609)
2022-02-15 20:55:16 +01:00
Camilla Löwy
1fa4312b29 Wayland: Remove superfluous initialize to NULL
The whole window struct has already been cleared to zero.

(cherry picked from commit 216ea3d735)
2022-02-15 20:53:55 +01:00
Camilla Löwy
eb6fc17746 Wayland: Move window title cloning to creation
(cherry picked from commit c1ecd4673e)
2022-02-15 20:53:13 +01:00
Camilla Löwy
ed785a2c79 Wayland: Gather framebuffer transparency logic
(cherry picked from commit 7bede13b1d)
2022-02-15 20:53:08 +01:00
Camilla Löwy
fba79aaaec Wayland: Move surface creation function
This needs to be after createXdgSurface, which it will soon be calling.

(cherry picked from commit a3d1633e1d)
2022-02-15 20:52:54 +01:00
Camilla Löwy
ec934edfbf Wayland: Fix repeated key not released on defocus
Platform code should not generate key events with GLFW_REPEAT.
GLFW_PRESS is translated into GLFW_REPEAT by shared code based on the
key state cache.

This confused the automatic key release logic into not generating an
event with GLFW_RELEASE for a key being repeated when the window lost
input focus.

(cherry picked from commit 3f5dfeaf29)
2022-02-15 20:51:55 +01:00
Camilla Löwy
5f0b316c24 Wayland: Control key repeat via timerfd state
The key repeat logic is now controlled only via the key repeat timerfd.

(cherry picked from commit 850893a39f)
2022-02-15 20:50:58 +01:00
Camilla Löwy
5e8186af0a Wayland: Clean up event pump
Adapt style to the rest of the project.

(cherry picked from commit 79e7e65c9d)
2022-02-15 20:50:38 +01:00
Emmanuel Gil Peyrot
17c5c53910 Wayland: Use correct action on fallback decoration
We were previously storing the pointer position only when on the main
window, so when the user clicked on a fallback decoration it would use
the last position of the cursor on the main window, instead of the
position in the decoration surface.

Fixes part of #1991.

(cherry picked from commit 855d338a65)
2022-02-15 20:46:36 +01:00
Camilla Löwy
65fc4fa625 X11: Fix sonames for loaded libraries on OpenBSD
The OpenBSD ports tree assigns its own soname version numbers, so the
hardcoded sonames GLFW uses to load libraries on non-macOS Unices are
often incorrect.  Instead OpenBSD recommends that run-time loading
should leave out the version numbers entirely.  The OpenBSD ld.so then
finds the correct library.

This upstreams the ports tree fixes for Xcursor and EGL, and adds the
corresponding fix for all other run-time loaded library sonames.

Tested on OpenBSD 7.0.

This issue was initially reported on IRC.

(cherry picked from commit 7d060ba4f1)
2022-02-15 20:36:11 +01:00
Jason Francis
8ecb49d143 Wayland: Fix window hiding
Corrects the protocol violation when creating an xdg_surface from a
wl_surface that already has a buffer due to EGL buffer swaps.

This commit is based on PR #1731 by @ghost, but adapted and altered:
 - The XDG surface and role are now only created when a window is shown
   to prevent application lists from showing command-line applications
   with off-screen-only windows
 - The special case of Wayland+EGL buffer swap is now in the EGL code
   to mirror how X11 is handled
 - Adaption to run-time platform selection and separate credits file

Fixes #1492
Closes #1731

(cherry picked from commit 094aa6d3c7)
2021-12-24 01:59:16 +01:00
Camilla Löwy
9240ee5ddf Wayland: Fix key repeat continuing when refocused
If a window lost input focus while a key was held down, the key repeat
mechanism would resume once the window regained focus.

(cherry picked from commit e24fe4b189)
2021-12-24 01:53:53 +01:00
Camilla Löwy
3b806aef27 Wayland: Fix duplicate focus event on activation
(cherry picked from commit c2f0a0ae59)
2021-12-24 01:52:43 +01:00
Emmanuel Gil Peyrot
5470fd6de9 EGL: Use EGL_EXT_present_opaque when available
This extensions allows GLFW to instruct the driver to ignore the alpha
bits, even in formats which contain them.  This makes it possible to use
the alpha bits as extra storage, without it affecting the end result
getting displayed to the user.

Fixes #1434
Fixes #1803

(cherry picked from commit 6281f498c8)
2021-12-24 01:51:24 +01:00
Emmanuel Gil Peyrot
52133a3690 Wayland: Continue poll() if timerfd can’t be read
In the case the key repeat timerfd was interrupted before read(), the
cursor timerfd wasn’t read at all even when it could.

Related to #1711

(cherry picked from commit 68879081cb)
2021-12-24 01:45:22 +01:00
Stone Tickle
8f3677a0d4 Wayland: Set O_NONBLOCK on repeat timerfd
Fixes #1710
Fixes #1711

(cherry picked from commit 963e728881)
2021-12-24 01:43:44 +01:00
Camilla Löwy
a69648e192 Win32: Handle content scale error on creation
Only apply the content scale to the initial size of the window if
content scale retrieval succeeded.

Related to #1615.

(cherry picked from commit 53d86c64d7)
2021-12-08 20:06:18 +01:00
Camilla Löwy
e10def6de7 Win32: Fix bad content scale on monitor disconnect
The monitor handle could have become invalid just before the call to
GetDpiForMonitor.  It was possible for both window and monitor content
scale queries.

This ensures both that an appropriate error is emitted and that the
retrieved values are zero on error.

Fixes #1615

(cherry picked from commit fbfd7e65c8)
2021-12-08 20:05:32 +01:00
Camilla Löwy
84c881c1a8 Cleanup
(cherry picked from commit 79de08db06)
2021-12-08 20:02:58 +01:00
Stephen Gutekanst
6281424988 X11: Fix undefined behavior in glfwSetWindowIcon
The conversion of window icon image data involves unsigned char color
values being promoted to int and then shifted to the left by 24.  For
32-bit ints this is just far enough to trigger undefined behavior.

It worked by accident because of how current compilers translate this
piece of code.

This was caught by @slimsag while working on [Zig bindings for GLFW][1],
and diagnosed together with @Andoryuuta, as described [in an
article][2].  Zig has UBSan enabled by default, which caught this
undefined behavior.

[1]: https://github.com/hexops/mach-glfw
[2]: https://devlog.hexops.com/2021/perfecting-glfw-for-zig-and-finding-undefined-behavior#finding-lurking-undefined-behavior-in-6-year-old-glfw-code

Thanks to Maato, martinhath, dcousens, drfuchs and Validark for helping
to refine the solution.

This commit message was rewritten by @elmindreda to hopefully reflect
the conclusions of the pull request thread.

Related to hexops/mach#20
Closes #1986

(cherry picked from commit 9cd4d2fa20)
2021-12-08 19:58:12 +01:00
Camilla Löwy
486724c433 Update comments for global mutable data
(cherry picked from commit b3a98f8555)
2021-11-30 19:04:38 +01:00
Camilla Löwy
bfd9eaf092 Fix mappings for gamepads present at init
Joysticks already connected when GLFW was initalized did not get gamepad
mappings applied to them.

Regression introduced by 74a8ba26c3.

This change was backported without taking into account that 3.3.x does
not have on-demand joystick init.

Fixes #1996
2021-11-24 23:09:24 +01:00
Jan Ekström
bec6e7565b Cocoa: Use MACH_PORT_NULL for default IOKit port
Looking into the definition of kIOMainPortDefault, the following
description can be found:

When specifying a main port to IOKit functions, the NULL argument
indicates "use the default". This is a synonym for NULL, if you'd
rather use a named constant.

Thus, we do not have to utilize an external symbol for the identifier
of the default main IOKit port, but MACH_PORT_NULL suffice. This
simplifies compatibility between macOS versions as the symbol was
renamed with macOS 12.0.

Fixes #1985
Closes #1994

(cherry picked from commit 544790666b)
2021-11-24 23:01:46 +01:00
Josh Codd
472d45c07b Cocoa: Fix deprecation of kIOMasterPortDefault
This adds a workaround for kIOMasterPortDefault having been deprecated
in favor of kIOMainPortDefault in macOS 12.0.

Closes #1980

(cherry picked from commit f75c251dec)
2021-10-28 12:39:39 +02:00
Ioannis Tsakpinis
db85858062 Fix context API checks in native access functions
(cherry picked from commit 727db55c3a)
2021-10-28 12:29:57 +02:00
Camilla Löwy
ca676357c0 Win32: Remove timeGetTime fallback for timer
The performance counter API is guaranteed to succeed on Windows XP and
later so there is no need for a fallback.

This removes our last dependency on winmm.

(cherry picked from commit b6834bf2a1)
2021-10-28 12:24:38 +02:00
Camilla Löwy
4ea7485fbe Remove blank line before the end of some structs
(cherry picked from commit efe764b492)
2021-10-28 12:14:58 +02:00
Camilla Löwy
2d3ce6eaae Make native access functions verify context API
The native access functions for context handles did not verify that the
context had been created with the same API the function was for.

This makes these functions emit GLFW_NO_WINDOW_CONTEXT on API mismatch.

(cherry picked from commit cca9008db2)
2021-10-28 12:13:19 +02:00
Camilla Löwy
95df61e5ed Cocoa: Fix unresponsive cursor after cursor warp
This is a companion to 157ebb80aa and
fixes the same issue for calls to glfwSetCursorPos.

Related to #1962

(cherry picked from commit 6ed5294223)
2021-10-13 23:11:00 +02:00
Ioannis Tsakpinis
c32fefc6a0 Cocoa: Fix unresponsive cursor after ungrab
There is a suppression interval (0.25 seconds by default) after a call
to CGWarpMouseCursorPosition, during which local hardware events
(keyboard and mouse) are ignored. GLFW already calls
CGEventSourceSetLocalEventsSuppressionInterval with a value of 0.0, but
it doesn't help in this case, there is still a short delay before the
cursor can be moved. Moving the CGAssociateMouseAndMouseCursorPosition
call after the cursor position has been restored, fixes the issue.

Closes #1962

(cherry picked from commit 157ebb80aa)
2021-10-13 23:10:15 +02:00
Waris Boonyasiriwat
6bb5f5d59d Wayland: Fix cursor offset when shape changes
The Wayland protocol spec[1] states that set_cursor must be called
with the serial number of the enter event.  However, GLFW is passing in
the serial number of the latest received event, which does not meet the
protocol spec.

[1] https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_pointer

As a result, set_cursor calls were simply ignored by the compositor.

This fix complies with the protocol more closely by specifically caching
the enter event serial, and using it for all set_cursor calls.

Fixes #1706
Closes #1899

(cherry picked from commit e7758c506d)
2021-10-13 23:06:40 +02:00
Koray Kilinc
33ff23dc07 Wayland: Fix some keys not repeating
According to the libxkbcommon documentation[1], xkb_keymap_key_repeats
requires keymap and keycode as input:

int xkb_keymap_key_repeats( struct xkb_keymap * keymap,
			    xkb_keycode_t key)

However, in inputChar in wl_input.c we are passing in xkb_keysym_t,
which was a type mismatch.

This results in some keys not repeating when they should and vice versa.

[1] https://xkbcommon.org/doc/current/group__components.html#ga9d7f998efeca98b3afc7c257bbac90a8

Closes #1908.

(cherry picked from commit 216d5e8402)
2021-09-01 19:47:59 +02:00
Richard Boldiš
1d7339f3fc Win32: Fix invalid preprocessor command 'warning'
The GCCism #warning had snuck into the Win32 platform code.

Merges #1953.

(cherry picked from commit 2ac7e20aaf)
2021-08-27 17:20:00 +02:00
Camilla Löwy
50b09938e7 X11: Fix function returning before cleanup
The _glfwPlatformSetWindowFloating function would return without freeing
the state array if the window was already in the requested state.

(cherry picked from commit 071d7c0f46)
2021-08-27 17:19:46 +02:00
Camilla Löwy
74a8ba26c3 Simplify parsing of default gamepad mappings
The outer glfwUpdateGamepadMappings function is now bypassed when
parsing the default gamepad mappings.  The data in mappings.h does not
contain any comments or line breaks.  Also this is done before joystick
support has been initialized, so there is no need to look for matching
devices.

Finally, the array of default mappings is pre-allocated.  This has no
measurable performance impact but does generate a lot of calls, which
won't be nice for a user provided custom allocator to deal with.

(cherry picked from commit 201400b974)
2021-08-27 17:13:12 +02:00
Camilla Löwy
929286ca47 Update gamepad mappings from upstream
(cherry picked from commit afa78b4270)
2021-08-27 17:13:01 +02:00
Camilla Löwy
d3317b4937 Add gamepad mapping filtering by backend
This fixes gamepad mappings being included in GLFW binaries that would
then never use them because they were for a different platform.

(cherry picked from commit 0c90e1a33f)
2021-08-03 16:01:03 +02:00
Camilla Löwy
b3b82cdd78 Add custom target for updating gamepad mappings
(cherry picked from commit 01778329ec)
2021-08-03 16:00:30 +02:00
Camilla Löwy
20a7962a9b Improve error description for invalid scancodes
(cherry picked from commit 56092814f3)
2021-08-03 15:59:59 +02:00
Stephen Gowen
1e98fc325d Cocoa: Fix macro redefinition warning
This avoids generating a macro redefinition warning when the
GL_SILENCE_DEPRECATION macro has been defined for the whole of a larger
project.

Closes #1840.

(cherry picked from commit 1d88a2e3d6)
2021-08-03 15:43:16 +02:00
Camilla Löwy
545b6c7970 Cocoa: Fix MoltenVK layer scale out of sync
The contents scale of the hosted CAMetalLayer created for MoltenVK was
updated only after the GLFW content scale and framebuffer size events
were emitted, causing the layer to get out of sync with the monitor the
window was on.

(cherry picked from commit 076bfd55be)
2021-08-03 15:43:03 +02:00
Camilla Löwy
a7202e2341 Cocoa: Remove calls to -update on nil
These calls have no effect unless the context was created with NSGL.

(cherry picked from commit 836e709503)
2021-08-03 15:41:57 +02:00
Camilla Löwy
8f0198e82e Remove errors for gamepad element mismatch
Because there are controllers in the wild using the same hardware ID
despite having different numbers of buttons and axes, an error message
was triggered that was only expected for a corrupted mapping database.

This removes the error for now, in preparation for better error handling
for gamepad mappings overall.

Fixes #1763.

(cherry picked from commit 6876cf8d7e)
2021-08-03 14:04:01 +02:00
Camilla Löwy
d61f7225d1 Wayland: Fix missing constant on FreeBSD
On FreeBSD O_CLOEXEC is only available when _POSIX_C_SOURCE >= 200809.
O_CLOEXEC is in turn required by the epollshim header.

Issue reported on IRC.

(cherry picked from commit a89fcd20d8)
2021-08-03 14:03:01 +02:00
Camilla Löwy
163fa83fac EGL: Fix creation of single-buffered windows
The EGL backend ignored the state of GLFW_DOUBLEBUFFER and always
created a double-buffered EGL window.

This sets the EGL_RENDER_BUFFER attribute at EGL window creation
appropriately.

Fixes #1843.

(cherry picked from commit 114776a246)
2021-06-15 18:07:38 +02:00
Camilla Löwy
6769ffcd0f Move single/double-buffer filtering to backends
There is no need to enumerate framebuffer configs that will just be
filtered out later by the GLFW_DOUBLEBUFFER hard constraint.

(cherry picked from commit fd79b02840)
2021-06-15 18:07:28 +02:00
Camilla Löwy
07c29d1c1c Skip initial buffer swap when single-buffered
This skips the buffer swap after the initial glClear performed during
window creation, if the window is single-buffered.  This call confused
apitrace into thinking the window was double-buffered.

Fixes #1873.

(cherry picked from commit 184377b493)
2021-06-15 18:06:46 +02:00
Camilla Löwy
508e24c01c Add tracking of single-/double-buffering
This adds the state part of 04f21abb52
(Make GLFW_DOUBLEBUFFER a window attribute), but without the associated
API change, because this is needed by later bug fixes that will go into
the stable branch.
2021-06-15 18:04:05 +02:00
Camilla Löwy
e756ae1d85 Make monitor and joystick names static strings
Related to #478.

(cherry picked from commit da236ba807)
2021-06-09 18:37:31 +02:00
Camilla Löwy
728aaccbbb Win32: Always define UNICODE and _UNICODE
(cherry picked from commit 9a3a8bc267)
2021-06-09 18:32:24 +02:00
Camilla Löwy
52b2775c2e Win32: Fix macros being enabled for other backends
_UNICODE should not be defined for other backends even when built on
Windows.

(cherry picked from commit a646f51bca)
2021-06-09 18:32:10 +02:00
Konstantin Podsvirov
9ef9b1361a Fix hardcoded runtime destination in CMake install
Closes #1883.
Closes #1884.

(cherry picked from commit e3f916808d)
2021-06-09 18:31:56 +02:00
Camilla Löwy
5dd6716ee9 Win32: Fix compilation with standalone LLVM
The /clang: suffix passed to Clang-CL was accidentally also passed to
the regular standalone Clang, which caused compilation to fail.  We now
pass /W3 to Clang-CL, which it interprets as -Wall.

The _CRT_SECURE_NO_WARNINGS macro is now defined for both Clang and
Clang-CL.

The /entry: flag passed to link.exe is now also passed to lld-link,
letting the windows subsystem tests and examples link.

Fixes #1807.
Closes #1824.
Closes #1874.

(cherry picked from commit 061a0263a9)
2021-06-09 18:31:39 +02:00
Camilla Löwy
3cded29c2f Replace GL_ARB_debug_output in comments
(cherry picked from commit 85bce8a8ea)
2021-06-09 18:26:39 +02:00
Camilla Löwy
b39c02b118 Win32: Add warning when option will have no effect
The GPU driver only looks in the executable for the symbol requesting
the high-performance GPU, so enabling them when buidling GLFW as a DLL
will have no effect.

(cherry picked from commit 52ba8c7f07)
2021-03-21 23:23:17 +01:00
Camilla Löwy
0f46d089e8 X11: Fix attribs not applied on leaving fullscreen
If the GLFW_DECORATED and/or GLFW_FLOATING window attributes were
changed while in fullscreen mode, the changes did not take effect when
the window entered windowed mode.

Bug reported on the GLFW forum.
https://discourse.glfw.org/t/turning-on-off-window-decorations-while-in-full-screen-wont-work-properly/1780

(cherry picked from commit 4afa227a05)
2021-03-19 16:18:12 +01:00
Camilla Löwy
0c22ebac36 Wayland: Move DPI fallback work to output done
This removes the dependency on the (unspecified) ordering of geometry
and mode events in wl_output.

Based on feedback from @linkmauve and @caramelli.

Related to #1792.

(cherry picked from commit b925a54ef1)
2021-02-17 21:15:51 +01:00
Camilla Löwy
900dda7e89 Win32: Fix content area rescaling on older systems
GLFW_SCALE_TO_MONITOR had no effect on Windows 8.1 up to and including
Windows 10 version 1607 (Anniversary Update), despite those having
support for per-monitor DPI.

That done was to avoid handling systems that have non-client scaling,
introduced in Windows 10 version 1607, without reliable overriding of
the new window size, introduced in Windows 10 version 1703 (Creators
Update).  Both are needed to keep the content area at a fixed size for
windows that have GLFW_SCALE_TO_MONITOR disabled.

This change enables window rescaling on Windows 8.1 and all later
versions but disables non-client scaling for unscaled windows on Windows
10 version 1607.  Versions after 1607 are unaffected.

Fixes #1511.

(cherry picked from commit 729c9988d0)
2021-02-17 21:15:32 +01:00
Camilla Löwy
56230ca173 Win32: Fix full screen windows affected by scaling
Per-monitor DPI scaling should not affect full screen windows.

Fixes #1582.

(cherry picked from commit 410890aa80)
2021-02-17 21:14:47 +01:00
Camilla Löwy
c6fa2c8cfb Cocoa: Fix console apps getting a dock icon
Regression introduced by @elmindreda in
8b11867464.

Adapted to 3.3-stable from 6de084000b.
2021-02-10 18:17:16 +01:00
Laurent Aphecetche
5a15d8a784 Cocoa: Fix install name for installed dylib
The install name was incorrectly set to a relative path.

This change leaves the install name of the installed dylib as
@rpath/soname.  Those who wish to override this can set the
CMAKE_INSTALL_NAME_DIR variable.

Closes #1504.

(cherry picked from commit 384ff74a46)
2021-02-10 17:14:46 +01:00
Camilla Löwy
8270081334 Simplify references in CMake if-statements
Adapted to 3.3-stable from f8d6801a50.
2021-02-10 17:14:46 +01:00
Camilla Löwy
15b0c43e2d Cocoa: Unify CG display to NS screen mapping
This moves the matching of CG displays to NS screens to monitor
enumeration time.

(cherry picked from commit 3959ee8949)
2021-02-10 17:14:46 +01:00
Nevyn Bengtsson
8746f68d61 Cocoa: Use modern API to get display name
On Apple Silicon, IOKit is deprecated and there will be no
matching io_service that we can query for name. Luckilly,
NSScreen got an API to fetch the display name in 10.15.

This is a blocker to get glfw running on Apple Silicon.

Fixes #1809.
Closes #1833.

(cherry picked from commit 2bc52ca82e)
2021-02-10 17:14:45 +01:00
Camilla Löwy
14921d1e24 Cocoa: Fix duplicate monitor connection events
(cherry picked from commit 5aff72aa00)
2021-02-10 17:14:45 +01:00
Camilla Löwy
eda12dd949 Cocoa: Fix menubar for unbundled apps on 10.15
NSApp setActivationPolicy: was being called too soon when the app was
not bundled and launched from the command line.

This fix is based on #1802 by @richardwilkes.

Fixes #1648.
Closes #1802.

Adapted to 3.3-stable from 8b11867464.
2021-02-10 17:14:45 +01:00
Philip Rideout
078e8fcf55 Cocoa: Fix duplicate video mode detection
Closes #1830.

(cherry picked from commit f5af421a6b)
2021-02-09 21:49:17 +01:00
ashishgamedev
cdd5ee8d36 Fix indentation in internal.h
Closes #1818.

(cherry picked from commit 761f97d6b6)
2021-02-09 21:49:17 +01:00
Leonard König
b31d7ddc8c Wayland: Fix destroying CSDs in the correct order
On Wayland we implement Client-Side Decorations if the compositors do not
implement SSDs.  In that case, the destructors of the surfaces were called
in the wrong order, leading to a dereference of an already freed object.
We need to first destroy the subsurface before destroying the parent surface.

Related PR on kitty: https://github.com/kovidgoyal/kitty/pull/3066
Related issue on kitty: https://github.com/kovidgoyal/kitty/issues/3051

Closes #1798.

(cherry picked from commit 0dc1005c85)
2021-02-09 21:49:16 +01:00
Camilla Löwy
baf26a6ea7 Cocoa: Fix ObjC being built as C with CMake 3.19
CMake 3.19 adds -xc when the LANGUAGE file property is C, breaking our
workaround for CMake 3.15 and earlier not understanding the .m suffix.

Fixes #1787.

(cherry picked from commit 3327050ca6)
2021-02-09 21:49:16 +01:00
Camilla Löwy
395ab660d5 Win32: Filter out duplicate size events
This mirrors the filtering done on X11 and Cocoa.  Possibly this should
be done by shared code instead.

Fixes #1610.

(cherry picked from commit 0bccc3852b)
2021-02-09 21:49:16 +01:00
Camilla Löwy
7dee4e05f9 Win32: Fix clang-cl interpreting -Wall as /Wall
Unlike -Wall, VS /Wall really means all warnings.

Closes #1780.

(cherry picked from commit ac627706ef)
2021-02-09 21:49:16 +01:00
Camilla Löwy
e0b3361683 Win32: Enable /W3 on VS for library sources
/W3 is the default for new VS projects and the library builds cleanly
with it on VS 2010-2019 so let's try to keep it that way.

(cherry picked from commit 6b78419c9a)
2021-02-09 21:49:16 +01:00
Camilla Löwy
0b56adb721 Remove ignored Clang compiler flag
Clang ignores this when C99 is enabled, while GCC does not.  Removing
the checks for Clang to hopefully avoid a false sense of security.

(cherry picked from commit 9b140d08d7)
2020-12-14 22:50:33 +01:00
Vladimir Perminov
41ad058ce3 Win32: Fix value for _WIN32_WINNT_WINBLUE
An incorrect value for _WIN32_WINNT_WINBLUE caused GLFW to think Windows
8 was 8.1 or greater.  This led to a crash when attempting to call
SetProcessDpiAwareness.

Closes #1775.

(cherry picked from commit e1d71cfa4701250a44a6c02d1bbb43309ac8a46c)
2020-09-30 16:11:14 +02:00
Doug Binks
c3250be690 Win32: Update all monitor handles on config change
Closes #1761.

(cherry picked from commit fecd711e0bc9779c379f00e63c1ab7a5081e1954)
2020-09-30 16:10:17 +02:00
Camilla Löwy
0ab31db9c0 Formatting
(cherry picked from commit 7765451d0f)
2020-09-02 22:29:30 +02:00
Camilla Löwy
8363179eee Win32: Disable fb transparency when it is broken
On Windows 7, when GLFW framebuffer transparency and the DWM are enabled
but DWM transparency is disabled (i.e. when the Transparency setting is
disabled under Personalization > Color), the contents of the framebuffer
is combined with the last frame using additive blending instead of
replacing the previous contents.

This commit limits GLFW framebuffer transparency on Windows 7 to when
DWM transparency is enabled, removing the previous workaround of setting
a layered window color key that led to rendering artifacts.

Fixes #1512.

(cherry picked from commit 05dd2fa298)
2020-09-02 22:27:45 +02:00
Camilla Löwy
b8a6254a26 Cocoa: Fix potential leak of CFNumber object
Spotted by Clang static analysis.

(cherry picked from commit a2674a9034)
2020-09-02 22:12:40 +02:00
Camilla Löwy
114704262c Wayland: Fix scroll offsets being inverted
Scrolling offsets were inverted compared to X11 and Win32.

Fixes #1463.

(cherry picked from commit f760b124ca)
2020-07-16 13:34:28 +02:00