1
0
Fork 0
Commit graph

411 commits

Author SHA1 Message Date
Alex Janka 0d20459065 update deps 2024-08-19 15:28:17 +10:00
Alex Janka e31a11f1c7 x11: raw-window-handle 0.6 2024-08-19 11:14:21 +10:00
Alex Janka 4e6e9737f1 windows rwh 0.6 (untested) 2024-05-26 10:45:32 +10:00
Alex Janka e51b4dd832 raw-window-handle 0.6.0 (windows only!!!!) 2024-05-26 10:45:32 +10:00
Alex Janka 3d186ce51f don't disable mouse coalescing on macos 2024-05-26 10:45:32 +10:00
Adrien Prokopowicz 579130ecb4
Fix usage of spare_capacity_mut which isn't available in MSRV 1.59 (#190) 2024-05-23 01:54:39 +02:00
Adrien Prokopowicz 45465c5f46
X11: Split off the event loop into a separate module (#183)
This PR splits off the X11 event loop logic into a separate module. It also changes the X11 implementation of the `Window` type to take only a shared reference to the inner type (`&WindowInner` instead of `&mut WindowInner`), bringing it in line with the other backends.

This does not change any of the logic however, it only separates some of the window state from the event loop state, to make sure they don't step on each other's toes in the future (particularly around the WindowHandler).

This is part of the effort to split up #174 into smaller pieces.
2024-04-05 14:18:49 -05:00
Fredemus be3d72d524
Handle set_mouse_cursor method on windows (#186)
This adds the ability to change the cursor on Windows platforms. For some reason there are very few default cursors included in Windows so a lot of cursors available on other platforms aren't available yet, which is why many of the `MouseCursor` options just maps to `IDC_ARROW`. I'll look into adding custom cursors next.

`LoadCursorW` is supposedly superseded by [LoadImageW](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadcursorw) but I couldn't find a way to do it with that one that doesn't crash. 

Tested with Vizia's cursor icon example [here](https://github.com/Fredemus/vizia/tree/baseview-window-events) and everything seems to work as it should.
Also tested by hovering over some buttons on a plugin.
2024-04-02 16:14:13 -05:00
Micah Johnston 905854d026
Remove unnecessary dependences from CI pipeline (#185) 2024-03-30 06:29:18 +01:00
Adrien Prokopowicz 119fc25cd6
Add additional CI checks (#182) 2024-03-30 00:55:44 +01:00
Adrien Prokopowicz bcbdb8921f
Fix GL X11 error handling (#181)
This PR fixes a soundness issue inside the `XErrorHandler` utility function, which could use an xlib `Display` pointer that had no guarantee to be still valid.

This could happen because the underlying `XErrorEvent` was stored directly inside the returned error type, and the `Display` pointer it contained was only called to extract the error message during in `Debug` implementation, which could happen long after the associated `Display` had been destroyed.

This PR fixes this by extracting the error message upfront and storing it as a string as soon as the error happens.
This PR also fixes the `handle` method that was not properly marked `unsafe`.
2024-03-28 22:41:40 -05:00
Micah Johnston f5b0c6d460
Call XCloseDisplay instead of xcb_disconnect (#184) 2024-03-29 04:09:23 +01:00
Adrien Prokopowicz 70e7af6c61
Add a new example for OpenGL setup using femtovg (#176) 2024-03-27 06:39:21 +01:00
Adrien Prokopowicz f5ae585758
X11: split off Visual Info negotiation into a separate module (#177) 2024-03-27 06:34:41 +01:00
Micah Johnston e8b1236fda
Fix warnings in examples (#180) 2024-03-27 04:46:47 +01:00
Micah Johnston f7d83a561e
Fix temporary names left over from x11rb migration (#179) 2024-03-27 04:43:27 +01:00
Robbert van der Helm ea0cd5367d
Fix resizing on Windows not triggering an event (#166)
Resizing should trigger a baseview resize event, but because we already
set the new size here the `WM_SIZE` event was ignored.

Co-authored-by: Micah Johnston <micah@photophore.systems>
2024-03-26 11:05:24 -05:00
Adrien Prokopowicz 65d970495f
Render a background for the open_window example (#175)
This PR adds code to render a basic gray background to the opened window in the `open_window` example.

This also helps making the example a bit more useful, since most users will want to render to their window.

And also it looks nicer. 🙂 

This is done using the `softbuffer` crate, in the same manner of the `open_parented` introduced in #172.
2024-03-25 18:41:39 -05:00
Dionysis Athinaios bad50d886a
Implement input focus for Mac & Windows (#170)
* Implement input focus for Mac

* Add stubs for Windows and Linux

* Remove unnecessary call to window

* Implement input focus for Windows

* Add check for key window status

* Rename to `has_focus` & `focus`

* Use GetFocus

* Fix incorrectly named var

---------

Co-authored-by: Micah Johnston <micah@photophore.systems>
2024-03-25 17:05:16 -05:00
Max 085ae2a27e
add support for Window::Focused/Unfocused events on macOS (#171)
trigger `WindowEvent::Focused` and `WindowEvent::Unfocused` events when the plugin window gains/loses focus. implemented by adding observers to `NSNotificationCenter::defaultCenter()` that listen to `NSWindowDidBecomeKeyNotification` and `NSWindowDidResignKeyNotification` notifications on the `NSViews`' window.

tested and confirmed to work in Live, Bitwig, FL Studio, Reaper and AudioPluginHost.
2024-03-25 11:34:10 -05:00
Micah Johnston fdc5d282fc
Switch from xcb crate to x11rb (#173)
Replace the `xcb` and `xcb-util` crates with `x11rb`. We were using an old version of the `xcb` crate which had some soundness issue. `x11rb` doesn't have these issues and generally provides a safer and nicer to use API.

It's possible to use `x11rb` without linking to xcb at all, using the `RustConnection` API, but unfortunately we have to use the `XCBConnection` API (which uses xcb under the hood) due to our use of the xlib GLX API for creating OpenGL contexts. In the future, it might be possible to avoid linking to xlib and xcb by replacing GLX with EGL.

Getting the xlib-xcb integration to work also necessitated upgrading the version of the `x11` crate, since the version we were using was missing some necessary functionality that was previously being provided by the `xcb` crate.
2024-03-25 11:20:28 -05:00
Adrien Prokopowicz 998ced845c
Added functional open_parented example (#172)
This PR adds a simple example that allows to test and showcase the `Window::open_parented` method.

That example first creates a parent window using `Window::open_blocking`, and then creates a smaller child window using `Window::open_parented`.

Both window's handlers log all of their events to the console, in a similar fashion to the `open_window` example.

Both windows actually do rendering (unlike the `open_window` example for now): the parent fills its window with a grey backround, and the child fills its window with a red background.

This example also uses the `softbuffer` crate to perform the rendering, which allows testing it in a more portable manner and in the simplest use case possible, without having to involve OpenGL or any 3D rendering pipeline at all.
2024-03-24 17:16:16 -05:00
Robbert van der Helm 26b019d6a2
Merge pull request #150 from Fredemus/feature/windows-cursor-enter-leave
Add logic for CursorEntered/CursorLeft on Windows
2024-03-18 16:46:27 +01:00
Fredemus d8cedc8a77 Merge branch 'master' into feature/windows-cursor-enter-leave 2024-01-09 01:38:14 +01:00
Micah Johnston 2c1b1a7b0f
Fix window cleanup logic on macOS (#164)
Instead of trying to detect when to clean up the window based on the `NSView`'s retain count, require window cleanup to be initiated explicitly via `Window::close`, `WindowHandle::close`, or `[NSWindowDelegate windowShouldClose:]` (in non-parented mode; called when the user clicks the "X" button). This fixes the leaks and use-after-frees that can be caused by the inherent unreliability of the retain count logic.

As discussed in #153, this change essentially means that the `NSView` created by Baseview will not be suitable as the top-level view for an Audio Unit, since the Baseview API now requires that child windows be cleaned up by an explicit call to `WindowHandle::close`, and the only reliable signal for cleaning up an Audio Unit view is a call to `[NSView dealloc]`. However, this does not mean that Baseview cannot be used in the context of an Audio Unit; it just means that plugin frameworks must implement a compatibility layer with a wrapper `NSView` (which is the approach taken by JUCE).

In order to implement this change:

- `WindowState` is stored in an `Rc` rather than a `Box`.
- `WindowHandle` holds an `Rc<WindowState>` so that `WindowHandle::close` can directly invoke window cleanup logic.
- Since the window can be closed during an event handler, `WindowState::from_view` now returns a clone of the `Rc<WindowState>` held by the `NSView` to ensure that it lives until the end of an event handler.
- In the non-parented case, the `NSView` is set as the window delegate, which allows it to receive the `windowShouldClose:` call when the user clicks the "X" button, upon which it will dispatch the `WillClose` event and initiate window cleanup logic.
- `Window::open_parented` and `open_blocking` no longer `release` the `NSView` immediately after attaching it. Instead, the `NSView` is released as part of the cleanup logic in `WindowInner::close`.
- `Window::resize` now checks if the window is open to avoid using the `NSView` after releasing it.
- The overridden `release` method, the `retain_count_after_build` field, the `ParentHandle` struct, and the `close_requested` flag have all been removed.
2023-12-17 22:57:51 -06:00
Micah Johnston fdb43eac11
Unify Window struct across backends (#162)
The public Window struct holds a mutable reference to `platform::Window`, which is a pattern that doesn't make sense for all backends. On Windows, the `platform::Window` struct itself just holds another (immutable) reference, and on macOS the `platform::Window` struct has to be wrapped in a `RefCell` so that a mutable reference to it can be formed.

Change the public `Window` struct to hold `platform::Window` directly, and change `platform::Window` in the macOS and X11 backends so that it simply holds a reference to another `WindowInner` struct similarly to the Windows backend. This allows us to remove the platform conditional in the declaration of the top-level `Window` struct. It also allows us to remove the `RefCell` wrapping `platform::Window` in the macOS backend and replace it with `Cell`s wrapping its individual fields.
2023-12-17 02:21:31 -06:00
Micah Johnston 937ef965b4
Remove unnecessary PhantomData from platform::WindowHandle definitions (#163)
These `PhantomData` fields are redundant, as the public `WindowHandle` struct already contains one.
2023-12-17 02:16:36 -06:00
Micah Johnston 7d14a555e5
Expose public Window::set_mouse_cursor method (#161)
The X11 backend has a full implementation of a `Window::set_mouse_cursor` method, but it isn't exposed via any public interface, which results in a lot of warnings for unused code. Add a public `set_mouse_cursor` method, along with stubbed-out versions in the Windows and macOS backends.
2023-12-17 02:12:31 -06:00
Micah Johnston 0976a9a6a4
macOS: use interior mutability for WindowState (#157)
Forming mutable references to the WindowState is unsound given the possibility
of reentrant calls to NSView methods. Instead, form only immutable references
to the WindowState and wrap mutable fields in Cell and RefCell.

Follow-up work should use try_borrow_mut instead of borrow_mut to avoid
panicking in the case of reentrant calls.
2023-12-16 19:37:21 -06:00
Micah Johnston 1b8c8760c7
Fix warnings on windows (#159) 2023-12-17 01:33:12 +00:00
Micah Johnston b59a67d287
Fix warnings on X11 (#160) 2023-12-17 01:31:06 +00:00
Micah Johnston 92f1a19b81
Fix warnings in example (#158) 2023-12-16 19:29:27 -06:00
Micah Johnston 348bc9fe61
Remove RawWindowHandleWrapper (#156)
RawWindowHandleWrapper is only necessary since GlContext::create takes an `impl
HasRawWindowHandle` argument, but GlContext::create is an internal unsafe API
and it is can just take a RawWindowHandle directly.
2023-12-12 11:47:32 -06:00
Micah Johnston 3ecc88f9fc
Fix warnings on macos (#155) 2023-12-12 17:40:45 +00:00
Micah Johnston df0e3928a2
Remove Window::open_as_if_parented (#153)
The open_as_if_parented method was intended to support the use case of Audio
Unit plugin views. However, the Audio Unit API differs in important ways from
other plugin APIs (such as VST 3 and CLAP) with regard to the lifetime
management of the plugin's NSView, and trying to support both lifetime
management patterns simultaneously has been the source of complexity and bugs.
Thus, rather than implementing Audio Unit NSView management directly in
Baseview, it will be the responsibility of plugin frameworks to implement a
compatibility layer between the Audio Unit API and the Baseview API.
2023-12-12 16:45:12 +00:00
Micah Johnston d08f7afd49
Run rustfmt (#154) 2023-12-12 10:41:03 -06:00
Nick Gideo d8e3b52acd
Merge pull request #149 from ilmai/drag-and-drop-mac
Drag and drop for Mac OS
2023-12-09 16:13:14 -06:00
Nick Gideo dbf4623b6e
Merge branch 'master' into drag-and-drop-mac 2023-12-09 16:12:05 -06:00
Fredemus 475bd5f88a remove unneeded allocation 2023-10-28 17:35:26 +02:00
Robbert van der Helm f0639b787b
Merge pull request #151 from Fredemus/feature/x11-cursor-enter-leave
Add logic for CursorEntered/CursorLeft on x11
2023-10-08 14:02:37 +02:00
Fredemus 486bb1f069 add MouseMoved event when ENTER_NOTIFY happens 2023-10-07 16:23:12 +02:00
Robbert van der Helm 54af726498
Merge pull request #134 from greatest-ape/raw-window-handle-0.5
Upgrade to raw-window-handle version 0.5
2023-10-07 15:12:01 +02:00
Fredemus fd1a3a4d2e Add logic for CursorEntered/CursorLeft on x11 2023-10-03 17:14:33 +02:00
Fredemus 1274b1c08f Add logic for CursorEntered/CursorLeft on Windows 2023-10-02 02:58:07 +02:00
Joakim Frostegård 0df43486ba X11: provide XlibWindowHandle.visual_id 2023-09-30 17:03:20 +02:00
Joakim Frostegård 4130502a2a X11 GlContext::create: change display arg to *mut xlib::XDisplay 2023-09-30 17:03:20 +02:00
Joakim Frostegård 70f46a691d X11: set XlibDisplayHandle.screen 2023-09-30 17:03:20 +02:00
Joakim Frostegård e35f3080f6 Fix Windows compilation issue 2023-09-30 17:03:20 +02:00
Joakim Frostegård 10c970a329 Fix X11 OpenGL issue 2023-09-30 17:03:20 +02:00
Joakim Frostegård 6f32584149 X11: set XlibWindowHandle.window and XlibDisplayhandle.display 2023-09-30 17:03:20 +02:00