Skip to content

Commit

Permalink
Improve non interactive external display support. Refs #1696
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Sep 1, 2023
1 parent 2bb0b25 commit c2fb93a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Blink/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
<string>Blink.WhatsNewSceneDelegate</string>
</dict>
</array>
<key>UIWindowSceneSessionRoleExternalDisplay</key>
<key>UIWindowSceneSessionRoleExternalDisplayNonInteractive</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
Expand Down
2 changes: 1 addition & 1 deletion Blink/LayoutManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ + (BKLayoutMode) deviceDefaultLayoutMode {
+ (UIEdgeInsets) buildSafeInsetsForController:(UIViewController *)ctrl andMode:(BKLayoutMode) mode {
UIWindow *window = ctrl.view.window;

if (window == ShadowWindow.shared || window.windowScene.session.role == UIWindowSceneSessionRoleExternalDisplay) {
if (window == ShadowWindow.shared || window.windowScene.session.role == UIWindowSceneSessionRoleExternalDisplayNonInteractive) {
// we are on external monitor, so we use device margins to accomodate overscan and ignore mode
// it is like BKLayoutModeSafeFit mode
return ShadowWindow.shared.refWindow.safeAreaInsets;
Expand Down
54 changes: 32 additions & 22 deletions Blink/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
_spCtrl.sceneRole = session.role
_spCtrl.restoreWith(stateRestorationActivity: session.stateRestorationActivity)

if session.role == .windowExternalDisplay,
if session.role == .windowExternalDisplayNonInteractive,
let mainScene = UIApplication.shared.connectedScenes.activeAppScene() {

if BLKDefaults.overscanCompensation() == .BKBKOverscanCompensationMirror {
Expand Down Expand Up @@ -287,36 +287,46 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}
}

func sceneDidBecomeActive(_ scene: UIScene) {

guard let window = window else {
private func _lockNonInteractiveScreenIfNeeded() {
guard
let window = ShadowWindow.shared?.refWindow,
let sceneDelegate = window.windowScene?.delegate as? SceneDelegate
else {
return
}

if (scene.session.role == .windowExternalDisplay) {
if LocalAuth.shared.lockRequired {
if let lockCtrl = _lockCtrl {
if window.rootViewController != lockCtrl {
window.rootViewController = lockCtrl
}

return
if LocalAuth.shared.lockRequired {
if let lockCtrl = sceneDelegate._lockCtrl {
if window.rootViewController != lockCtrl {
window.rootViewController = lockCtrl
}


_lockCtrl = UIHostingController(rootView: LockView(unlockAction: nil))
window.rootViewController = _lockCtrl
return
}
if window.rootViewController == _lockCtrl {
window.rootViewController = UIViewController()
}
_lockCtrl = nil

if let shadowWin = ShadowWindow.shared {
window.layer.addSublayer(shadowWin.layer)
}

sceneDelegate._lockCtrl = UIHostingController(rootView: LockView(unlockAction: nil))
window.rootViewController = _lockCtrl
return
}


if window.rootViewController == _lockCtrl {
window.rootViewController = UIViewController()
}
_lockCtrl = nil

if let shadowWin = ShadowWindow.shared {
window.layer.addSublayer(shadowWin.layer)
}
}

func sceneDidBecomeActive(_ scene: UIScene) {

// 0. Local Auth AutoLock Check on old screens
_lockNonInteractiveScreenIfNeeded()

guard let window = window else {
return
}

Expand Down
73 changes: 51 additions & 22 deletions Blink/SpaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class SpaceController: UIViewController {

#endif

if scene.session.role == .windowExternalDisplay,
if scene.session.role == .windowExternalDisplayNonInteractive,
let sharedWindow = ShadowWindow.shared,
sharedWindow === view.window,
let ctrl = sharedWindow.spaceController.currentTerm() {
Expand Down Expand Up @@ -787,7 +787,7 @@ extension SpaceController {
return
}

sessions = sessions.filter { $0.role != .windowExternalDisplay }
sessions = sessions.filter { $0.role != .windowExternalDisplayNonInteractive }

let nextSession: UISceneSession
if idx < sessions.endIndex {
Expand Down Expand Up @@ -838,7 +838,7 @@ extension SpaceController {
return
}

sessions = sessions.filter { $0.role != .windowExternalDisplay }
sessions = sessions.filter { $0.role != .windowExternalDisplayNonInteractive }

let nextSession: UISceneSession
if idx < sessions.endIndex {
Expand Down Expand Up @@ -944,13 +944,12 @@ extension SpaceController {
return
}
self.presentSnippetsController()
if let _ = _blinkMenu {
if let _ = self._interactiveSpaceController()._blinkMenu {
self.toggleQuickActionsAction()
}
}

@objc func toggleQuickActionsAction() {

private func _toggleQuickActionActionWith(receiver: SpaceController) {
if let menu = _blinkMenu {
_blinkMenu = nil
UIView.animate(withDuration: 0.15) {
Expand All @@ -973,7 +972,7 @@ extension SpaceController {
ids.append(contentsOf: [.layoutMenu])
}
ids.append(contentsOf: [.toggleLayoutLock, .toggleGeoTrack])
menu.delegate = self;
menu.delegate = receiver;
menu.build(withIDs: ids, andAppearance: [:])
_blinkMenu = menu
self.view.addSubview(menu)
Expand All @@ -988,7 +987,23 @@ extension SpaceController {
menu.frame = finalMenuFrame
}
}

}

func _interactiveSpaceController() -> SpaceController {
if let shadowWin = ShadowWindow.shared,
self.view.window == shadowWin,
let mainScreenSession = _activeSessions()
.first(where: {$0.role == .windowApplication }),
let delegate = mainScreenSession.scene?.delegate as? SceneDelegate
{
return delegate.spaceController
}
return self
}

@objc func toggleQuickActionsAction() {
_interactiveSpaceController()
._toggleQuickActionActionWith(receiver: self)
}

@objc func toggleGeoTrack() {
Expand Down Expand Up @@ -1139,27 +1154,39 @@ extension SpaceController: CommandsHUDDelegate {
}

extension SpaceController: SnippetContext {
func presentSnippetsController() {

func _presentSnippetsController(receiver: SpaceController) {
do {
let ctrl = try SnippetsViewController.create(context: self, transitionFrame: _blinkMenu?.bounds)
ctrl.view.frame = self.view.bounds
ctrl.willMove(toParent: self)
self.view.addSubview(ctrl.view)
self.addChild(ctrl)
ctrl.didMove(toParent: self)
_snippetsVC = ctrl
self.view.window?.makeKeyAndVisible()
let ctrl = try SnippetsViewController.create(context: receiver, transitionFrame: _blinkMenu?.bounds)
DispatchQueue.main.async {
ctrl.view.frame = self.view.bounds
ctrl.willMove(toParent: self)
self.view.addSubview(ctrl.view)
self.addChild(ctrl)
ctrl.didMove(toParent: self)
self._snippetsVC = ctrl
}
} catch {
self.showAlert(msg: "Could not display Snips: \(error)")
}
}

func presentSnippetsController() {
_interactiveSpaceController()._presentSnippetsController(receiver: self)
}

func _dismissSnippetsController(ctrl: SpaceController) {
ctrl.presentedViewController?.dismiss(animated: true)
ctrl._snippetsVC?.willMove(toParent: nil)
ctrl._snippetsVC?.view.removeFromSuperview()
ctrl._snippetsVC?.removeFromParent()
ctrl._snippetsVC?.didMove(toParent: nil)
ctrl._snippetsVC = nil
}

func dismissSnippetsController() {
self.presentedViewController?.dismiss(animated: true)
self._snippetsVC?.willMove(toParent: nil)
self._snippetsVC?.view.removeFromSuperview()
self._snippetsVC?.removeFromParent()
self._snippetsVC?.didMove(toParent: nil)
self._snippetsVC = nil
_dismissSnippetsController(ctrl: _interactiveSpaceController())
self.focusOnShellAction()
}

Expand All @@ -1169,3 +1196,5 @@ extension SpaceController: SnippetContext {
}

}


2 changes: 1 addition & 1 deletion Blink/TermController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class TermController: UIViewController {

convenience init(sceneRole: UISceneSession.Role? = nil) {
self.init(meta: nil)
if sceneRole == .windowExternalDisplay {
if sceneRole == .windowExternalDisplayNonInteractive {
_sessionParams.fontSize = BLKDefaults.selectedExternalDisplayFontSize()?.intValue ?? 24
}
}
Expand Down

0 comments on commit c2fb93a

Please sign in to comment.