I tried using the GameController APIs for this, but they didn't seem to work. Is that the recommended API for handling keyboard/mouse? The notifications for mouse and keyboard connect/disconnect don't seem to be defined for visionOS.
The visionOS 2.0 touts keyboard and mouse support. The simulator can even forward keyboard/mouse to the app. But there don't seem to be any sample code of how to programatically receive either of these. The game controller works fine (on device, not on Simulator).
Post
Replies
Boosts
Views
Activity
I would like to see examples of how to do this. Apple states that explicit clang modules don't work with C++ interop. ObjC++ has simple interop with C++. Swift does not. And so I'd like to know how to setup my C++ projects to build them as clang modules.
This has been broken for over 5 years now. I see 2 different behaviors in 2 different SwiftUI apps. This makes SwiftUI not ready for prime time apps, but I just have tools right now.
The VStack { List } doesn't scroll to the item in a long list. The selection moves to the next item in the list, but can't see it. This is just basic UI functionality of a list. UIListView doesn't have this issue.
The NavigationView { List { NavigationLink }} wraps around back to the top of the list when pressing down arrow past the last visible item, but there are plenty more list items to visit.
First I get this
ar_world_tracking_provider_query_device_anchor_at_timestamp <0x302b9c0a0>: The device_anchor can only be queried when the world tracking provider is running.
This seemed to all break with the auto-update to 2.0.1. Simulator runs the code fine.
I seem to see an infinite stall here
frameLayer.endUpdate()
// Pace frames by waiting for the optimal prediction time.
try await LayerRenderer.Clock().sleep(until: timing.optimalInputTime, tolerance: nil)
// Start submitting the updated frame.
frameLayer.startSubmission() <-
I have this game controller connected to my M1, and the Simulator won't announced it via .GCControllerDidConnect. This works fine on iOS and macOS.
I have the simulator set to "Send Game Controller to Device" which the Simulator does. If I disable that, then I can control the simulator view. But once enabled, the Simulator doesn't tell the app about the controller.
There's nowhere to add -mf16c and -mfma that doesn't cause a uinversal build to spew warnings about those settings when it builds arm64. I'd rather not have to add a xcconfig file across every project with an x64 specific setting. So why doesn't the AVX2 setting (-mavx2) also set these flags?
-mhaswell does, and so does -mx86-64-...-v3, but those seem to only be supported by clang-cli on Windows.
Xcode 16 breaks fundamental feature of error/warning clickthrough to a given header or .cpp file. The issues list will jump to the point of include, instead of the actual error/warning. There's not even a highlighted line since these files aren't the source of the error.
Not really sure how this one got through QA since Apple uses Xcode internally. Now I'm constantly having to scour the report navigator, open the items, and then manually jump to file/line.
So I'm trying to maintain free open-source macOS tools. These two tools are sandboxed and hardened runtime. One is an image viewer that writes out a perftrace file into the sandbox folder (in Containers). Then another app tries to open that perftrace file (json).
When the perftrace file is opened in Xcode (signed and notarized), the file opens fine the first and all subsequent times.
When the opening app is kram-profile (signed not notaraized), the file opens once and then nothing can ever open it again. The app has attribute com.apple.quarantine set on it.
The only workaround to then open this file is to remove the attribute
xattr -d com.apple.quarantine <filename>
This is my tool build in Xcode, and having to sign let alone notarize an app is a large amount of complexity. Also this app is available on github.
The following generates a prior definition warning from #include <__config>. But that has an ifndef in it. I'm in C++17 on Xcode latest (14.5). Is this documented anywhere?
-D_LIBCPP_ENABLE_ASSERTIONS=1
I create @State holding a WKWebView (heavyweight object), and then wrap that in a VKViewRepresentable, then
@State var myWebView = newWebView(request: URLRequest(url:URL(string: request)!))
This is the only way I can then reference the webView late on to run javascript queries on it. Otherwise, it's embedded in the View/ContentView hierarchy.
So then when I moved from Window to WindowGroup, only one of these WKWebView is created. This looks bad to have an empty detail panel in the previous Window. The docs on WindowGroup state that it makes new state to go with each Window in the WindowGroup, but in this case, that's not the case here.
Not sure why this has to be so obscure. But somehow adding the call into toggleFullscreen, even though this appDelegate doesn't have a window set, adds a menu item with the fn+F menu item. Posting this to save other pain. Plus the View menu doesn't even have a reference, and is empty otherwise. Pretty hard to polish something shippable with these unfixed outstanding flaws in the API.
CommandGroup(after: .toolbar) {
// must call through NSWindow
Button("See Below") {
// Window isn't set in AppDelegate, so menu item is skipped.
// But add fn+F menu item into app. Suo many stupid hacks.
appDelegate.window?.toggleFullScreen(nil)
}
}
I have a webpage that needs to receive keypresses to zoom and scroll. This seems to be the only way to prevent the annoying NSBeep from occurring. Return true too much, and command keys stop working. So need to be explicit about which keys you want. Also no way to block delete/shift+delete from going fwd/back in the history using this same mechanism.
func isKeyHandled(_ event: NSEvent) -> Bool {
// can't block delete or shift+delete
// so the WKWebView goes back/foward through it's 1 page history.
// that loses all context for the user.
// prevent super annoying bonk/NSBeep
// if don't check modifier flags (can't check isEmpty since 256 is often set
// then the cmd+S stops working
if !(event.modifierFlags.contains(.command) ||
event.modifierFlags.contains(.control) ||
event.modifierFlags.contains(.option)) {
// wasd
if event.keyCode == Keycode.w || event.keyCode == Keycode.a || event.keyCode == Keycode.s || event.keyCode == Keycode.d {
return true
}
}
return false
}
// Apple doesn't want this to be overridden by user, but key handling
// just doesn't work atop the WKWebView without this. KeyUp/KeyDown
// overrides don't matter, since we need the WKWebView to forward them
override func performKeyEquivalent(with event: NSEvent) -> Bool {
if !isKeyHandled(event) {
return super.performKeyEquivalent(with: event)
}
return true
}
Trying to create a List that sorts by some criteria and handles searchable without any samples is only made even more difficult by the textfield constantly refocusing itself. So I can't even tab away from it. This is some awful bug in SwiftUI.
class FileSearcher: ObservableObject {
@Published var searchIsActive = false
@Published var searchText = ""
var files: [File] = []
...
}
NavigationSplitView() {
}
.searchablel(text: $fileSearcher.searchText,
isPresented: $fileSearcher.searchIsActive,
placement: .sidebar,
prompt: "Filter")
I have an app hosting a page with a 'drop' operation where the page accepts file drops. But I can't easily intercept that, nor seep to be able to block it in Javascript. Yet WKWebView has no way to disable the drop operation from settings, or intercept the url of the dropped file. Either would be useful here.
I have the following set, but the WKWebView is losing the page content that I'm updating in a given page whenever the user presses the "delete" key. This is in SwiftUI, and I see no way to intercept and block this key.
webView.allowsBackForwardNavigationGestures = false
Isn't the whole point of setting this flag, to not just have "swipe" navigation stop, but all back/forward support stop? Also with the backForwardList immutable, it's not like I can delete an entry from it.