From 9f2e3f87c021ed32b6620269cf128e3a22d9e2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Sun, 4 Dec 2016 20:05:24 +0100 Subject: [PATCH] support bluetooth HID pointing devices through BTC Mouse --- Mini vMac.xcodeproj/project.pbxproj | 2 ++ Mini vMac/AppDelegate.h | 1 + Mini vMac/AppDelegate.m | 12 +++++++++++- Mini vMac/BTCMouse.h | 20 ++++++++++++++++++++ Mini vMac/InsertDiskViewController.m | 3 +++ Mini vMac/SettingsViewController.m | 3 +++ Mini vMac/ViewController.m | 3 +++ 7 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Mini vMac/BTCMouse.h diff --git a/Mini vMac.xcodeproj/project.pbxproj b/Mini vMac.xcodeproj/project.pbxproj index 90a0153..2347a5d 100644 --- a/Mini vMac.xcodeproj/project.pbxproj +++ b/Mini vMac.xcodeproj/project.pbxproj @@ -274,6 +274,7 @@ 283423EC1CFA329C0088B634 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = ""; }; 283423ED1CFA329C0088B634 /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon@2x.png"; sourceTree = ""; }; 283423EE1CFA329C0088B634 /* Icon@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon@3x.png"; sourceTree = ""; }; + 283CA9821DF47AF300B33D5E /* BTCMouse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BTCMouse.h; sourceTree = ""; }; 285A8C901D05AFD3002993DE /* PlugIn-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "PlugIn-Info.plist"; sourceTree = ""; }; 28848B601CDE97D600B86C45 /* InsertDiskViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InsertDiskViewController.h; sourceTree = ""; }; 28848B611CDE97D600B86C45 /* InsertDiskViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InsertDiskViewController.m; sourceTree = ""; }; @@ -628,6 +629,7 @@ 28F6B4511CF07C48002D76D0 /* UIImage+DiskImageIcon.m */, 28F6B4C91CF1FA7A002D76D0 /* about.plist */, 28F6B4CE1CF77099002D76D0 /* compat.m */, + 283CA9821DF47AF300B33D5E /* BTCMouse.h */, 283422EF1CF8F33A0088B634 /* Emulator Bundles */, ); path = "Mini vMac"; diff --git a/Mini vMac/AppDelegate.h b/Mini vMac/AppDelegate.h index 03a4945..4e511a0 100644 --- a/Mini vMac/AppDelegate.h +++ b/Mini vMac/AppDelegate.h @@ -8,6 +8,7 @@ #import #import "EmulatorProtocol.h" +#import "BTCMouse.h" extern NSString *DocumentsChangedNotification; diff --git a/Mini vMac/AppDelegate.m b/Mini vMac/AppDelegate.m index 5dd80f6..9f840dd 100644 --- a/Mini vMac/AppDelegate.m +++ b/Mini vMac/AppDelegate.m @@ -15,7 +15,7 @@ static AppDelegate *sharedAppDelegate = nil; static NSObject *sharedEmulator = nil; NSString *DocumentsChangedNotification = @"documentsChanged"; -@interface AppDelegate () +@interface AppDelegate () @end @@ -40,6 +40,11 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; [self initDefaults]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL]; [sharedEmulator performSelector:@selector(run) withObject:nil afterDelay:0.1]; + + if ([application respondsToSelector:@selector(btcMouseSetRawMode:)]) { + [application btcMouseSetRawMode:YES]; + [application btcMouseSetDelegate:self]; + } return YES; } @@ -109,6 +114,11 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; } } +- (void)handleEventWithMove:(CGPoint)move andWheel:(float)wheel andPan:(float)pan andButtons:(int)buttons { + [sharedEmulator moveMouseX:move.x/2.0 Y:move.y/2.0]; + [sharedEmulator setMouseButton:buttons == 1]; +} + - (void)applicationWillEnterForeground:(UIApplication *)application { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if (sharedEmulator.running) { diff --git a/Mini vMac/BTCMouse.h b/Mini vMac/BTCMouse.h new file mode 100644 index 0000000..ae60c3f --- /dev/null +++ b/Mini vMac/BTCMouse.h @@ -0,0 +1,20 @@ +// +// BTCMouse.h +// Mini vMac +// +// Created by Jesús A. Álvarez on 04/12/2016. +// Copyright © 2016 namedfork. All rights reserved. +// + + +@protocol BTCMouseDelegate +- (void)handleEventWithMove:(CGPoint)move andWheel:(float)wheel andPan:(float)pan andButtons:(int)buttons; +@end + +@interface UIApplication (BTCMouse) +- (void)btcMouseSetPanning:(BOOL)panning; +- (void)btcMouseSetZooming:(BOOL)zooming; +- (void)btcMouseSetDelegate:(id)delegate; +- (void)btcMouseSetRawMode:(BOOL)rawMode; +@end + diff --git a/Mini vMac/InsertDiskViewController.m b/Mini vMac/InsertDiskViewController.m index 899d48c..8e3fa9d 100644 --- a/Mini vMac/InsertDiskViewController.m +++ b/Mini vMac/InsertDiskViewController.m @@ -65,6 +65,9 @@ [nc addObserver:self selector:@selector(reloadData:) name:[AppDelegate sharedEmulator].insertDiskNotification object:nil]; [nc addObserver:self selector:@selector(reloadData:) name:[AppDelegate sharedEmulator].ejectDiskNotification object:nil]; [nc addObserver:self selector:@selector(reloadData:) name:DocumentsChangedNotification object:nil]; + if ([UIApplication instancesRespondToSelector:@selector(btcMouseSetRawMode:)]) { + [[UIApplication sharedApplication] btcMouseSetRawMode:NO]; + } } - (void)viewDidDisappear:(BOOL)animated { diff --git a/Mini vMac/SettingsViewController.m b/Mini vMac/SettingsViewController.m index bd58e54..af22190 100644 --- a/Mini vMac/SettingsViewController.m +++ b/Mini vMac/SettingsViewController.m @@ -90,6 +90,9 @@ typedef enum : NSInteger { - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [AppDelegate sharedEmulator].running = NO; + if ([UIApplication instancesRespondToSelector:@selector(btcMouseSetRawMode:)]) { + [[UIApplication sharedApplication] btcMouseSetRawMode:NO]; + } } - (void)viewWillDisappear:(BOOL)animated { diff --git a/Mini vMac/ViewController.m b/Mini vMac/ViewController.m index 58daa97..e5052d5 100644 --- a/Mini vMac/ViewController.m +++ b/Mini vMac/ViewController.m @@ -64,6 +64,9 @@ pointingDeviceView = [[pointingDeviceClass alloc] initWithFrame:self.view.bounds]; pointingDeviceView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self.view insertSubview:pointingDeviceView aboveSubview:self.screenView]; + if ([UIApplication instancesRespondToSelector:@selector(btcMouseSetRawMode:)]) { + [[UIApplication sharedApplication] btcMouseSetRawMode:YES]; + } } - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {