Code-Hex / vz

Create virtual machines and run Linux-based operating systems in Go using Apple Virtualization.framework.
https://pkg.go.dev/github.com/Code-Hex/vz/v3
MIT License
563 stars 44 forks source link

Help to implement Zoom In, Zoom out VZVirtualMachineView #35

Open Code-Hex opened 2 years ago

Code-Hex commented 2 years ago

It is not among the features provided by Apple but, I attempted to provide pinch-in zoom-in, and zoom-out functionality like iPhone for the window that serves as the GUI display in this package.

However, This was too difficult than expected and was once out of the scope.

VZVirtualMachineView inherits from NSView. So I was thinking that if I made the document view of the NSScrollView and applied the scroll view to the window, it would be complete.

The problem is...

Code-Hex commented 2 years ago

This is a result of dumped VZVirtualMachineView (/System/Library/Frameworks/Virtualization.framework/Versions/A/Virtualization)

@interface VZVirtualMachineView : NSView {
    id  _becomeKeyWindowObserver;
    bool  _capturesSystemKeys;
    NSCursor * _currentGuestCursor;
    <_VZVirtualMachineViewDelegate> * _delegate;
    id  _eventMonitor;
    _VZFramebufferView * _framebufferView;
    bool  _guestIsUsingHostCursor;
    id  _keyEventMonitor;
    struct vector<unsigned short, std::allocator<unsigned short>> { 
        unsigned short *__begin_; 
        unsigned short *__end_; 
        struct __compressed_pair<unsigned short *, std::allocator<unsigned short>> { 
            unsigned short *__value_; 
        } __end_cap_; 
    }  _keys_down;
    bool  _mouseIsInTrackingArea;
    id  _resignKeyWindowObserver;
    long long  _scaleMode;
    bool  _showsHostCursor;
    NSTrackingArea * _trackingArea;
    VZVirtualMachine * _virtualMachine;
    bool  _virtualMachineIsRunning;
    VZObserverProxy * _virtualMachineObserver;
}

@property (readonly) bool _canGrabMouseInput;
@property (readonly) bool _canReleaseMouseInput;
@property (setter=_setDelegate:) <_VZVirtualMachineViewDelegate> *_delegate;
@property (setter=_setScaleMode:) long long _scaleMode;
@property bool capturesSystemKeys;
@property (retain) VZVirtualMachine *virtualMachine;

- (id).cxx_construct;
- (void).cxx_destruct;
- (bool)acceptsFirstResponder;
- (bool)becomeFirstResponder;
- (bool)capturesSystemKeys;
- (void)dealloc;
- (void)flagsChanged:(id)arg1;
- (id)initWithCoder:(id)arg1;
- (id)initWithFrame:(struct CGRect { struct CGPoint { double x_1_1_1; double x_1_1_2; } x1; struct CGSize { double x_2_1_1; double x_2_1_2; } x2; })arg1;
- (void)keyDown:(id)arg1;
- (void)keyUp:(id)arg1;
- (void)layout;
- (void)magnifyWithEvent:(id)arg1;
- (void)mouseDown:(id)arg1;
- (void)mouseDragged:(id)arg1;
- (void)mouseEntered:(id)arg1;
- (void)mouseExited:(id)arg1;
- (void)mouseMoved:(id)arg1;
- (void)mouseUp:(id)arg1;
- (void)observeValueForKeyPath:(id)arg1 ofObject:(id)arg2 change:(id)arg3 context:(void*)arg4;
- (void)otherMouseDown:(id)arg1;
- (void)otherMouseDragged:(id)arg1;
- (void)otherMouseUp:(id)arg1;
- (void)quickLookWithEvent:(id)arg1;
- (bool)resignFirstResponder;
- (void)rightMouseDown:(id)arg1;
- (void)rightMouseDragged:(id)arg1;
- (void)rightMouseUp:(id)arg1;
- (void)rotateWithEvent:(id)arg1;
- (void)scrollWheel:(id)arg1;
- (void)setCapturesSystemKeys:(bool)arg1;
- (void)setVirtualMachine:(id)arg1;
- (void)smartMagnifyWithEvent:(id)arg1;
- (void)updateTrackingAreas;
- (void)viewDidMoveToWindow;
- (void)viewWillMoveToWindow:(id)arg1;
- (id)virtualMachine;

// VZVirtualMachineView (VZPrivate)

- (bool)_canGrabMouseInput;
- (bool)_canReleaseMouseInput;
- (id)_delegate;
- (bool)_grabMouseInput;
- (bool)_releaseMouseInput;
- (long long)_scaleMode;
- (void)_setDelegate:(id)arg1;
- (void)_setScaleMode:(long long)arg1;

@end
Code-Hex commented 2 years ago

A test repository is available here. https://github.com/Code-Hex/vm-scroll-test

You can try it out by creating a VM.bundle directory on your home directory with the file AuxiliaryStorage Disk.img HardwareModel MachineIdentifier RestoreImage.ipsw. These can be created by preparing a Restore Image according to the examples for macOS in this package. (also followed as Apple Running macOS in a Virtual Machine on Apple Silicon Macs instruction)