├── COPYRIGHT
├── CREDITS
├── Common
├── Event.h
├── Version.h
└── inputevent.h
├── INSTALL
├── Mac OS X
├── AppController.h
├── AppController.m
├── English.lproj
│ ├── Credits.rtf
│ ├── InfoPlist.strings
│ └── MainMenu.xib
├── Info.plist
├── Makefile4dist
├── RemotePad Server.icns
├── RemotePad Server.xcodeproj
│ ├── TemplateIcon.icns
│ └── project.pbxproj
├── RemotePad Server_Prefix.pch
├── TCPServer.h
├── TCPServer.m
├── icon.xcf
├── main.m
├── pointer-notconnected.png
└── pointer.png
├── README
├── RemotePad
├── AppController.h
├── AppController.m
├── Bonjour.png
├── BrowserViewController.h
├── BrowserViewController.m
├── ButtonBack.png
├── ButtonCenter.png
├── ButtonCenterHighlighted.png
├── ButtonLeft.png
├── ButtonLeftHighlighted.png
├── ButtonRight.png
├── ButtonRightHighlighted.png
├── ButtonRounded.png
├── ButtonRounded.xcf
├── ButtonRoundedHighlighted.png
├── Constants.h
├── Default.png
├── Info.plist
├── Picker.h
├── Picker.m
├── PickerViewController.h
├── PickerViewController.m
├── RemotePad.xcodeproj
│ └── project.pbxproj
├── RemotePad_Prefix.pch
├── SetupViewController.h
├── SetupViewController.m
├── TCPServer.h
├── TCPServer.m
├── TapView.h
├── TapView.m
├── adhoc-Entitlements.plist
├── bg.png
├── icon.png
├── icon.xcf
├── itunes.txt
├── largeicon.jpg
└── main.m
├── Windows
├── RemotePad Server.cpp
├── RemotePad Server.h
├── RemotePad Server.ico
├── RemotePad Server.rc
├── RemotePad Server.sln
├── RemotePad Server.vcproj
├── icon-connected.ico
├── icon-notconnected.ico
└── icon.xcf
└── X11
├── Imakefile
├── Makefile
├── Makefile.in
├── config.h.in
├── configure
├── configure.ac
├── remotepad.c
└── ucs2keysym.c
/COPYRIGHT:
--------------------------------------------------------------------------------
1 | RemotePad for iPhone and RemotePad Server COPYRIGHTs
2 |
3 | The following files included in this directory are copyrighted by the
4 | Apple and licensed by the Apple Public Software License.
5 |
6 | Mac OS X/AppController.h
7 | Mac OS X/AppController.m
8 | Mac OS X/TCPServer.h
9 | Mac OS X/TCPServer.m
10 | RemotePad/AppController.h
11 | RemotePad/AppController.m
12 | RemotePad/bg.png
13 | RemotePad/BrowserViewController.h
14 | RemotePad/BrowserViewController.m
15 | RemotePad/Picker.h
16 | RemotePad/Picker.m
17 | RemotePad/TapView.h
18 | RemotePad/TapView.m
19 | RemotePad/TCPServer.h
20 | RemotePad/TCPServer.m
21 |
22 | The following files included in this directory and executable binaries
23 | which you compile are licensed by the GNU General Public License v2.
24 |
25 | Common/inputevent.h
26 | Windows/remotepadwin.cpp
27 | X11/remotepad.c
28 |
29 | The files excluding the aboves are copyrighted by the tenjin.org and
30 | licensed by the following license.
31 |
32 |
33 | TENJIN.ORG COPYRIGHT NOTICE
34 |
35 | Copyright 2008, 2009 tenjin.org. All rights reserved.
36 |
37 | Redistribution and use in source and binary forms, with or without
38 | modification, are permitted provided that the following conditions
39 | are met:
40 | 1. Redistributions of source code must retain the above copyright
41 | notice, this list of conditions and the following disclaimer.
42 | 2. Redistributions in binary form must reproduce the above copyright
43 | notice, this list of conditions and the following disclaimer in the
44 | documentation and/or other materials provided with the distribution.
45 |
46 | THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
47 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
48 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
50 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
56 | POSSIBILITY OF SUCH DAMAGE.
57 |
--------------------------------------------------------------------------------
/CREDITS:
--------------------------------------------------------------------------------
1 | Engineering:
2 | Yoshihisa Kawamoto
3 | Rui Paulo
4 |
5 | With special thanks to:
6 | Iwan Smith
7 | Justin Hawkwood
8 | and RemotePad Discussion Forum Members
9 |
--------------------------------------------------------------------------------
/Common/Event.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Event.h
3 | * RemotePad, RemotePad Server
4 | *
5 | * Created by iKawamoto Yosihisa! on 08/08/27.
6 | * Copyright 2008, 2009 tenjin.org. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #define EVENT_NULL 0 /* void */
31 | #define EVENT_VERSION 128 /* version number */
32 | /* $NetBSD: wsconsio.h,v 1.88 2007/08/27 02:01:23 macallan Exp $ */
33 | #define EVENT_KEY_UP 1 /* key code */
34 | #define EVENT_KEY_DOWN 2 /* key code */
35 | #define EVENT_ALL_KEYS_UP 3 /* void */
36 | #define EVENT_MOUSE_UP 4 /* button # (leftmost = 0) */
37 | #define EVENT_MOUSE_DOWN 5 /* button # (leftmost = 0) */
38 | #define EVENT_MOUSE_DELTA_X 6 /* X delta amount */
39 | #define EVENT_MOUSE_DELTA_Y 7 /* Y delta amount */
40 | #define EVENT_MOUSE_ABSOLUTE_X 8 /* X location */
41 | #define EVENT_MOUSE_ABSOLUTE_Y 9 /* Y location */
42 | #define EVENT_MOUSE_DELTA_Z 10 /* Z delta amount */
43 | #define EVENT_MOUSE_ABSOLUTE_Z 11 /* Z location */
44 | #define EVENT_SCREEN_SWITCH 12 /* New screen number */
45 | #define EVENT_ASCII 13 /* key code is already ascii */
46 | #define EVENT_MOUSE_DELTA_W 14 /* W delta amount */
47 | #define EVENT_MOUSE_ABSOLUTE_W 15 /* W location */
48 |
49 | // key modifiers for Windows
50 | #define kWinModifierShift (1 << 0)
51 | #define kWinModifierControl (1 << 1)
52 | #define kWinModifierAlternate (1 << 2)
53 | #define kWinModifierHankaku (1 << 3)
54 |
55 | // key modifiers for X11
56 | #define kX11ModifierShift (1 << 0)
57 | #define kX11ModifierControl (1 << 1)
58 | #define kX11ModifierMod1 (1 << 2)
59 | #define kX11ModifierHankaku (1 << 3)
60 |
61 | // key codes for RemotePad and Mac OS X
62 | #define kKeycodeBackSpace 51
63 | #define kKeycodeReturn 52
64 | #define kKeycodeShift 56
65 | #define kKeycodeOption 58
66 | #define kKeycodeLeft 123
67 | #define kKeycodeRight 124
68 | #define kKeycodeDown 125
69 | #define kKeycodeUp 126
70 |
71 | typedef struct {
72 | uint32_t type;
73 | int32_t value;
74 | uint32_t tv_sec;
75 | uint32_t tv_nsec;
76 | } MouseEvent;
77 |
78 | #define MouseNumber(v) ((int)(v) & 0xff)
79 | #define MouseClickCount(v) ((int)(v) >> 8)
80 | #define MouseEventValue(n,c) (((int)(c) << 8) | (int)(n) & 0xff)
81 |
--------------------------------------------------------------------------------
/Common/Version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Version.h
3 | * RemotePad, RemotePad Server
4 | *
5 | * Created by iKawamoto Yosihisa! on 09/03/07.
6 | * Copyright 2009 tenjin.org. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | // version strings
31 | #define kVersionRemotePad @"1.5"
32 | #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
33 | #define kVersionMac @"2.5 for Mac OS X 10.5"
34 | #else
35 | #define kVersionMac @"2.5 for Mac OS X 10.4"
36 | #endif
37 | #define kVersionX11 "1.10"
38 | #define kVersionWindows "2.0"
39 |
40 | // current version
41 | #define kVersionRemotePadCurrent 0x01010500
42 | #define kVersionMacCurrent 0x02020500
43 | #define kVersionX11Current 0x03010a00
44 | #define kVersionWindowsCurrent 0x04020003
45 |
46 | // keyboard supported version
47 | #define kVersionRemotePadKeyboard 0x01010400
48 | #define kVersionMacKeyboard 0x02020200
49 | #define kVersionX11Keyboard 0x03010800
50 | #define kVersionWindowsKeyboard 0x04010800
51 |
--------------------------------------------------------------------------------
/Common/inputevent.h:
--------------------------------------------------------------------------------
1 | //inputevent.h
2 | //Will Dietz
3 |
4 | //Defines the network structs, and the consts used to identify
5 | //what kind of input event this is, and information required to
6 | //recreate it on the server end
7 |
8 | /*
9 | This file is part of iTouchpad.
10 |
11 | iTouchpad is free software: you can redistribute it and/or modify
12 | it under the terms of the GNU General Public License as published by
13 | the Free Software Foundation, either version 3 of the License, or
14 | (at your option) any later version.
15 |
16 | iTouchpad is distributed in the hope that it will be useful,
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | GNU General Public License for more details.
20 |
21 | You should have received a copy of the GNU General Public License
22 | along with iTouchpad. If not, see .
23 |
24 | */
25 |
26 | #ifndef _INPUTEVENT_H_
27 | #define _INPUTEVENT_H_
28 |
29 | //TODO: does this belong here?
30 | #define PORT 5583
31 |
32 | typedef enum
33 | {
34 | EVENT_TYPE_MOUSE_DOWN,
35 | EVENT_TYPE_MOUSE_UP,
36 | EVENT_TYPE_MOUSE_MOVE,
37 | EVENT_TYPE_MOUSE_SCROLL_MOVE,
38 | EVENT_TYPE_KEY_DOWN,
39 | EVENT_TYPE_KEY_UP
40 | } eventtype;
41 |
42 | typedef enum
43 | {
44 | BUTTON_LEFT = 1,
45 | BUTTON_RIGHT = 2
46 | } buttontype;
47 |
48 | typedef struct
49 | {
50 | int dx;
51 | int dy;
52 | } mousemove_info;
53 |
54 | typedef struct
55 | {
56 | buttontype button;
57 | } mousebutton_info;
58 |
59 | typedef struct
60 | {
61 | int keycode;
62 | int modifier;
63 |
64 | } keyevent_info;
65 |
66 |
67 | typedef struct
68 | {
69 | eventtype event_t;
70 | union
71 | {
72 | mousemove_info move_info;
73 | mousebutton_info button_info;
74 | keyevent_info key_info;
75 | };
76 |
77 | } InputEvent, *pInputEvent;
78 |
79 |
80 | /*-----------------------------------------------------------------------------
81 | * KEY CODES:
82 | *-----------------------------------------------------------------------------*/
83 | //if not defined here, then just encode as a standard ascii.
84 | //we can tackle support for unicode as we come to that--but since we're passing an int
85 | //we coud use utf-32 without much difficulty.
86 |
87 | //arrows
88 | static const int kKeyLeft = 0xEF51; /* Move left, left arrow */
89 | static const int kKeyUp = 0xEF52; /* Move up, up arrow */
90 | static const int kKeyRight = 0xEF53; /* Move right, right arrow */
91 | static const int kKeyDown = 0xEF54; /* Move down, down arrow */
92 |
93 | //misc
94 | static const int kKeyBackSpace = 0xEF08; /* back space, back char */
95 | static const int kKeyTab = 0xEF09;
96 | static const int kKeyReturn = 0xEF0D; /* Return, enter */
97 | static const int kKeyEscape = 0xEF1B;
98 | //static const int kKeyDelete = 0xEFFF; /* Delete, rubout */
99 |
100 |
101 | /*-----------------------------------------------------------------------------
102 | * Modifiers
103 | *-----------------------------------------------------------------------------*/
104 | static const int kModShift = 1 << 0;
105 | static const int kModControl = 1 << 1;
106 | static const int kModAlt = 1 << 2;
107 | static const int kModCmd = 1 << 3;//AFAIK only valid for a mac
108 | static const int kModFn = 1 << 4;//free modifier, various usage
109 |
110 |
111 | #endif // _INPUTEVENT_H_
112 |
--------------------------------------------------------------------------------
/INSTALL:
--------------------------------------------------------------------------------
1 | How to compile and install RemotePad for iPhone or RemotePad Servers
2 |
3 | To compile RemotePad for iPhone or RemotePad Servers, please read
4 | a suitable part for your system.
5 |
6 | X11 (Linux or BSDs)
7 |
8 | 1. Open terminal emulator (xterm perhaps).
9 | 2. Change your directory to where the downloaded file is.
10 | prompt% cd the_directory_where_the_downloaded_file_is
11 | 3. Extract source files from the downloaded file. This command
12 | outputs extracted file names.
13 | prompt% tar xvfz RemotePadServer-_the_version_-Source.tgz
14 | 4. Change your directory to an extracted one.
15 | prompt% cd X11
16 | 5. Do configure.
17 | prompt% ./configure
18 | 6. Do compile with make command. This command outputs compiling
19 | commands and its outputs.
20 | prompt% make
21 | 7. You have now get the RemotePad Server program named 'remotepad.'
22 | 8. Run this server.
23 | prompt% ./remotepad
24 | 9. You may install this program to /usr/local/bin with root privilege.
25 | prompt% su
26 | prompt# make install
27 |
28 | Mac OS X
29 |
30 | NOTE: Pre-compiled binary is available at
31 | http://www.tenjin.org/RemotePad/
32 | NOTE: You need a Xcode 3 development tool to compile.
33 | 1. Open file 'Mac OS X/RemotePad Server.xcodeproj'.
34 | 2. Choose 'Active SDK' to 'Mac OS X 10.5' or 'Mac OS X 10.4' in a
35 | Project menu.
36 | 3. Do 'Build' from Build menu.
37 | 4. 'RemotePad Server.app' is built in a directory 'build'.
38 |
39 | Windows
40 |
41 | NOTE: Pre-compiled binary is available at
42 | http://www.tenjin.org/RemotePad/
43 | NOTE: You need a Visual C++ development tool to compile.
44 | 1. Open file 'Windows\RemotePad Server.vcproj'.
45 | 2. Choose a solution from 'Debug' to 'Release' in the 'Solution
46 | Configuration' in the Toolbar.
47 | 3. Do 'Build Solution' from Build menu.
48 | 4. 'RemotePad Server.exe' is built in a directory 'Release'.
49 |
50 | RemotePad for iPhone
51 |
52 | To compile this, you need a iPhone SDK(free). And to run this on
53 | iPhone or iPod touch, you need a iPhone Developer Program(not
54 | free).
55 | 1. Open file 'RemotePad/RemotePad.xcodeproj'.
56 | 2. Do 'Build' from Build menu.
57 |
58 | I'm sorry to say that I don't answer the generic questions related
59 | to the iPhone SDK. Please see the iPhone Dev Center resources.
60 |
--------------------------------------------------------------------------------
/Mac OS X/AppController.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppController.h
3 | // RemotePad Server
4 | //
5 | // Derived from an Apple's sample code AppController.h of WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/17.
7 | // Modified by Rui Paulo on 23/01/2009.
8 | // Copyright 2008, 2009 tenjin.org. All rights reserved.
9 | //
10 | //
11 |
12 | /*
13 |
14 | File: AppController.m
15 | Abstract: UIApplication's delegate class, the central controller of the
16 | application.
17 |
18 | Version: 1.5
19 |
20 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
21 | ("Apple") in consideration of your agreement to the following terms, and your
22 | use, installation, modification or redistribution of this Apple software
23 | constitutes acceptance of these terms. If you do not agree with these terms,
24 | please do not use, install, modify or redistribute this Apple software.
25 |
26 | In consideration of your agreement to abide by the following terms, and subject
27 | to these terms, Apple grants you a personal, non-exclusive license, under
28 | Apple's copyrights in this original Apple software (the "Apple Software"), to
29 | use, reproduce, modify and redistribute the Apple Software, with or without
30 | modifications, in source and/or binary forms; provided that if you redistribute
31 | the Apple Software in its entirety and without modifications, you must retain
32 | this notice and the following text and disclaimers in all such redistributions
33 | of the Apple Software.
34 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
35 | to endorse or promote products derived from the Apple Software without specific
36 | prior written permission from Apple. Except as expressly stated in this notice,
37 | no other rights or licenses, express or implied, are granted by Apple herein,
38 | including but not limited to any patent rights that may be infringed by your
39 | derivative works or by other works in which the Apple Software may be
40 | incorporated.
41 |
42 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
43 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
44 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
46 | COMBINATION WITH YOUR PRODUCTS.
47 |
48 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
49 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
50 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
52 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
53 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
54 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 |
56 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
57 |
58 | */
59 | #import
60 | #import
61 |
62 | #import "TCPServer.h"
63 | #import "Event.h"
64 |
65 | #define kNumUniChar 65536
66 |
67 | @interface AppController : NSObject {
68 | TCPServer* _server;
69 | NSInputStream* _inStream;
70 | NSOutputStream* _outStream;
71 | BOOL _inReady;
72 | BOOL _outReady;
73 | MouseEvent prevevent;
74 | BOOL mouse1Clicked;
75 | BOOL mouse2Clicked;
76 | BOOL mouse3Clicked;
77 | NSThread *streamThread;
78 | CFRunLoopSourceRef runLoopSource;
79 | NSTimer *keepAliveTimer;
80 | int32_t accumuW;
81 | int32_t accumuZ;
82 | UCKeyboardLayout *currentKeyboardLayout;
83 | CGKeyCode charToKey[kNumUniChar];
84 | UInt32 charToMod[kNumUniChar];
85 | UCKeyboardLayout *currentKeyboardLayoutKCHR;
86 | CGKeyCode charToKeyKCHR[kNumUniChar];
87 | UInt32 charToModKCHR[kNumUniChar];
88 |
89 | NSStatusItem *statusItem;
90 | NSMenuItem *inTheDockItem;
91 | NSImage *connectedImage;
92 | NSImage *notConnectedImage;
93 |
94 | BOOL notInTheDock;
95 | }
96 | - (void)setup:(id)sender;
97 | - (void)applicationWillFinishLaunching:(NSNotification *)aNotification;
98 | - (void)applicationTerminated:(NSNotification *)aNotification;
99 | - (void)disconnect:(id)sender;
100 | - (void)_showAlert:(NSString *)title;
101 |
102 | - (void)quitMenu:(id)sender;
103 | - (void)aboutMenu:(id)sender;
104 |
105 | - (void)mouseDown:(MouseEvent)event0;
106 | - (void)mouseUp:(MouseEvent)event0;
107 | - (void)mouseMoveX:(MouseEvent)x Y:(MouseEvent)y;
108 | - (void)scrollWheelW:(MouseEvent)w Z:(MouseEvent)z;
109 | - (void)scrollWheelZ:(MouseEvent)z;
110 |
111 | - (void)addSourceToCurrentRunLoop;
112 | // Client interface for registering commands to process
113 | - (void)requestExitStreamThread;
114 | @end
115 |
116 |
117 | // These are the CFRunLoopSourceRef callback functions.
118 | void RunLoopSourceScheduleRoutine (void *info, CFRunLoopRef rl, CFStringRef mode);
119 | void RunLoopSourcePerformRoutine (void *info);
120 | void RunLoopSourceCancelRoutine (void *info, CFRunLoopRef rl, CFStringRef mode);
121 |
--------------------------------------------------------------------------------
/Mac OS X/English.lproj/Credits.rtf:
--------------------------------------------------------------------------------
1 | {\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf430
2 | {\fonttbl\f0\fswiss\fcharset0 Helvetica;}
3 | {\colortbl;\red255\green255\blue255;}
4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
5 |
6 | \f0\b\fs24 \cf0 Engineering:
7 | \b0 \
8 | Yoshihisa Kawamoto\
9 | Rui Paulo\
10 | \
11 |
12 | \b With special thanks to:
13 | \b0 \
14 | Iwan Smith\
15 | Justin Hawkwood\
16 | and RemotePad Discussion Forum Members\
17 | }
--------------------------------------------------------------------------------
/Mac OS X/English.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/Mac OS X/English.lproj/InfoPlist.strings
--------------------------------------------------------------------------------
/Mac OS X/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 | RemotePad Server.icns
11 | CFBundleIdentifier
12 | org.tenjin.${PRODUCT_NAME:identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | APPL
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 2.5
23 | NSMainNibFile
24 | MainMenu
25 | NSPrincipalClass
26 | NSApplication
27 | NSUIElement
28 | 0
29 | NSSupportsSuddenTermination
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Mac OS X/Makefile4dist:
--------------------------------------------------------------------------------
1 | SRC = Event.h \
2 | inputevent.h \
3 | Makefile \
4 | RemotePad\ Server.sln \
5 | RemotePad\ Server.vcproj \
6 | remotepad.c \
7 | remotepadwin.cpp
8 | DIR = RemotePad\ Server
9 |
10 | all: RemotePadServer-Source.tgz
11 |
12 | RemotePadServer-Source.tgz:
13 | rm -rf ${DIR}
14 | mkdir ${DIR}
15 | cp -p ${SRC} ${DIR}
16 | tar cvfz $@ ${DIR}
17 |
--------------------------------------------------------------------------------
/Mac OS X/RemotePad Server.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/Mac OS X/RemotePad Server.icns
--------------------------------------------------------------------------------
/Mac OS X/RemotePad Server.xcodeproj/TemplateIcon.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/Mac OS X/RemotePad Server.xcodeproj/TemplateIcon.icns
--------------------------------------------------------------------------------
/Mac OS X/RemotePad Server.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 45;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 3A166AF30E7F6B8F00001374 /* RemotePad Server.icns in Resources */ = {isa = PBXBuildFile; fileRef = 3A166AF20E7F6B8F00001374 /* RemotePad Server.icns */; };
11 | 3AB151190E7F5D0500FB4375 /* TCPServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AB151180E7F5D0500FB4375 /* TCPServer.m */; };
12 | 3AB1512C0E7F5D8B00FB4375 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AB1512B0E7F5D8B00FB4375 /* Carbon.framework */; };
13 | 3AB5FB580FA492B90027C02E /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3AB5FB560FA492B90027C02E /* MainMenu.xib */; };
14 | 3AB5FB5C0FA496E30027C02E /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */; };
15 | 3AB5FB5D0FA496E30027C02E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165FFE840EACC02AAC07 /* InfoPlist.strings */; };
16 | 3AB5FB5E0FA496E30027C02E /* RemotePad Server.icns in Resources */ = {isa = PBXBuildFile; fileRef = 3A166AF20E7F6B8F00001374 /* RemotePad Server.icns */; };
17 | 3AB5FB5F0FA496E30027C02E /* pointer.png in Resources */ = {isa = PBXBuildFile; fileRef = 5631BFD70F2A2FD80042B665 /* pointer.png */; };
18 | 3AB5FB600FA496E30027C02E /* pointer-notconnected.png in Resources */ = {isa = PBXBuildFile; fileRef = 3AE7727B0F6108460021B2DE /* pointer-notconnected.png */; };
19 | 3AB5FB610FA496E30027C02E /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3AB5FB560FA492B90027C02E /* MainMenu.xib */; };
20 | 3AB5FB630FA496E30027C02E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4B0FDCFA73011CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
21 | 3AB5FB640FA496E30027C02E /* TCPServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AB151180E7F5D0500FB4375 /* TCPServer.m */; };
22 | 3AB5FB650FA496E30027C02E /* AppController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5650583E0F2A0A220067B358 /* AppController.m */; };
23 | 3AB5FB670FA496E30027C02E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
24 | 3AB5FB680FA496E30027C02E /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AB1512B0E7F5D8B00FB4375 /* Carbon.framework */; };
25 | 3AE7727C0F6108460021B2DE /* pointer-notconnected.png in Resources */ = {isa = PBXBuildFile; fileRef = 3AE7727B0F6108460021B2DE /* pointer-notconnected.png */; };
26 | 5631BFD80F2A2FD80042B665 /* pointer.png in Resources */ = {isa = PBXBuildFile; fileRef = 5631BFD70F2A2FD80042B665 /* pointer.png */; };
27 | 5650583F0F2A0A220067B358 /* AppController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5650583E0F2A0A220067B358 /* AppController.m */; };
28 | 8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */; };
29 | 8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165FFE840EACC02AAC07 /* InfoPlist.strings */; };
30 | 8D15AC320486D014006FF6A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4B0FDCFA73011CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
31 | 8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
32 | /* End PBXBuildFile section */
33 |
34 | /* Begin PBXFileReference section */
35 | 089C1660FE840EACC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; };
36 | 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; };
37 | 13E42FBA07B3F13500E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; };
38 | 2A37F4B0FDCFA73011CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
39 | 2A37F4BAFDCFA73011CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = English; path = English.lproj/Credits.rtf; sourceTree = ""; };
40 | 2A37F4C4FDCFA73011CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; };
41 | 2A37F4C5FDCFA73011CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; };
42 | 32DBCF750370BD2300C91783 /* RemotePad Server_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RemotePad Server_Prefix.pch"; sourceTree = ""; };
43 | 3A166AF20E7F6B8F00001374 /* RemotePad Server.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "RemotePad Server.icns"; sourceTree = ""; };
44 | 3A166AF50E7F6C6300001374 /* icon.xcf */ = {isa = PBXFileReference; lastKnownFileType = file; path = icon.xcf; sourceTree = ""; };
45 | 3A949A2F0F6391910069CD1D /* Version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Version.h; path = ../Common/Version.h; sourceTree = SOURCE_ROOT; };
46 | 3AB151170E7F5D0500FB4375 /* TCPServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TCPServer.h; sourceTree = ""; };
47 | 3AB151180E7F5D0500FB4375 /* TCPServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TCPServer.m; sourceTree = ""; };
48 | 3AB1512B0E7F5D8B00FB4375 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = ""; };
49 | 3AB5FB570FA492B90027C02E /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = ""; };
50 | 3AB5FB6C0FA496E30027C02E /* RemotePad Server.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "RemotePad Server.app"; sourceTree = BUILT_PRODUCTS_DIR; };
51 | 3AD7F5680F2C007F00CD6BF7 /* Event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Event.h; path = ../Common/Event.h; sourceTree = SOURCE_ROOT; };
52 | 3AD7F5690F2C00A500CD6BF7 /* inputevent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = inputevent.h; path = ../Common/inputevent.h; sourceTree = SOURCE_ROOT; };
53 | 3AE7727B0F6108460021B2DE /* pointer-notconnected.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "pointer-notconnected.png"; sourceTree = ""; };
54 | 3AF6AE0C0F11A049005EDBB2 /* Makefile4dist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Makefile4dist; sourceTree = ""; };
55 | 5631BFD70F2A2FD80042B665 /* pointer.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pointer.png; sourceTree = ""; };
56 | 5650583D0F2A0A220067B358 /* AppController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppController.h; sourceTree = ""; };
57 | 5650583E0F2A0A220067B358 /* AppController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppController.m; sourceTree = ""; };
58 | 8D15AC360486D014006FF6A4 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
59 | 8D15AC370486D014006FF6A4 /* RemotePad Server.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "RemotePad Server.app"; sourceTree = BUILT_PRODUCTS_DIR; };
60 | /* End PBXFileReference section */
61 |
62 | /* Begin PBXFrameworksBuildPhase section */
63 | 3AB5FB660FA496E30027C02E /* Frameworks */ = {
64 | isa = PBXFrameworksBuildPhase;
65 | buildActionMask = 2147483647;
66 | files = (
67 | 3AB5FB670FA496E30027C02E /* Cocoa.framework in Frameworks */,
68 | 3AB5FB680FA496E30027C02E /* Carbon.framework in Frameworks */,
69 | );
70 | runOnlyForDeploymentPostprocessing = 0;
71 | };
72 | 8D15AC330486D014006FF6A4 /* Frameworks */ = {
73 | isa = PBXFrameworksBuildPhase;
74 | buildActionMask = 2147483647;
75 | files = (
76 | 8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */,
77 | 3AB1512C0E7F5D8B00FB4375 /* Carbon.framework in Frameworks */,
78 | );
79 | runOnlyForDeploymentPostprocessing = 0;
80 | };
81 | /* End PBXFrameworksBuildPhase section */
82 |
83 | /* Begin PBXGroup section */
84 | 1058C7A6FEA54F5311CA2CBB /* Linked Frameworks */ = {
85 | isa = PBXGroup;
86 | children = (
87 | 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */,
88 | );
89 | name = "Linked Frameworks";
90 | sourceTree = "";
91 | };
92 | 1058C7A8FEA54F5311CA2CBB /* Other Frameworks */ = {
93 | isa = PBXGroup;
94 | children = (
95 | 3AB1512B0E7F5D8B00FB4375 /* Carbon.framework */,
96 | 2A37F4C4FDCFA73011CA2CEA /* AppKit.framework */,
97 | 13E42FBA07B3F13500E4EEF1 /* CoreData.framework */,
98 | 2A37F4C5FDCFA73011CA2CEA /* Foundation.framework */,
99 | );
100 | name = "Other Frameworks";
101 | sourceTree = "";
102 | };
103 | 19C28FB0FE9D524F11CA2CBB /* Products */ = {
104 | isa = PBXGroup;
105 | children = (
106 | 8D15AC370486D014006FF6A4 /* RemotePad Server.app */,
107 | 3AB5FB6C0FA496E30027C02E /* RemotePad Server.app */,
108 | );
109 | name = Products;
110 | sourceTree = "";
111 | };
112 | 2A37F4AAFDCFA73011CA2CEA /* RemotePad Server */ = {
113 | isa = PBXGroup;
114 | children = (
115 | 2A37F4ABFDCFA73011CA2CEA /* Classes */,
116 | 2A37F4AFFDCFA73011CA2CEA /* Other Sources */,
117 | 2A37F4B8FDCFA73011CA2CEA /* Resources */,
118 | 2A37F4C3FDCFA73011CA2CEA /* Frameworks */,
119 | 19C28FB0FE9D524F11CA2CBB /* Products */,
120 | 3A1A616B0E835FD4002C5A80 /* Windows Sources */,
121 | 3A166BC80E7F6CC000001374 /* X11 Sources */,
122 | );
123 | name = "RemotePad Server";
124 | sourceTree = "";
125 | };
126 | 2A37F4ABFDCFA73011CA2CEA /* Classes */ = {
127 | isa = PBXGroup;
128 | children = (
129 | 3AB151170E7F5D0500FB4375 /* TCPServer.h */,
130 | 3AB151180E7F5D0500FB4375 /* TCPServer.m */,
131 | 5650583D0F2A0A220067B358 /* AppController.h */,
132 | 5650583E0F2A0A220067B358 /* AppController.m */,
133 | );
134 | name = Classes;
135 | sourceTree = "";
136 | };
137 | 2A37F4AFFDCFA73011CA2CEA /* Other Sources */ = {
138 | isa = PBXGroup;
139 | children = (
140 | 3A949A2F0F6391910069CD1D /* Version.h */,
141 | 2A37F4B0FDCFA73011CA2CEA /* main.m */,
142 | 32DBCF750370BD2300C91783 /* RemotePad Server_Prefix.pch */,
143 | );
144 | name = "Other Sources";
145 | sourceTree = "";
146 | };
147 | 2A37F4B8FDCFA73011CA2CEA /* Resources */ = {
148 | isa = PBXGroup;
149 | children = (
150 | 3AD7F5690F2C00A500CD6BF7 /* inputevent.h */,
151 | 5631BFD70F2A2FD80042B665 /* pointer.png */,
152 | 3AE7727B0F6108460021B2DE /* pointer-notconnected.png */,
153 | 3A166AF50E7F6C6300001374 /* icon.xcf */,
154 | 3AD7F5680F2C007F00CD6BF7 /* Event.h */,
155 | 3A166AF20E7F6B8F00001374 /* RemotePad Server.icns */,
156 | 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */,
157 | 8D15AC360486D014006FF6A4 /* Info.plist */,
158 | 089C165FFE840EACC02AAC07 /* InfoPlist.strings */,
159 | 3AB5FB560FA492B90027C02E /* MainMenu.xib */,
160 | );
161 | name = Resources;
162 | sourceTree = "";
163 | };
164 | 2A37F4C3FDCFA73011CA2CEA /* Frameworks */ = {
165 | isa = PBXGroup;
166 | children = (
167 | 1058C7A6FEA54F5311CA2CBB /* Linked Frameworks */,
168 | 1058C7A8FEA54F5311CA2CBB /* Other Frameworks */,
169 | );
170 | name = Frameworks;
171 | sourceTree = "";
172 | };
173 | 3A166BC80E7F6CC000001374 /* X11 Sources */ = {
174 | isa = PBXGroup;
175 | children = (
176 | 3AF6AE0C0F11A049005EDBB2 /* Makefile4dist */,
177 | );
178 | name = "X11 Sources";
179 | sourceTree = "";
180 | };
181 | 3A1A616B0E835FD4002C5A80 /* Windows Sources */ = {
182 | isa = PBXGroup;
183 | children = (
184 | );
185 | name = "Windows Sources";
186 | sourceTree = "";
187 | };
188 | /* End PBXGroup section */
189 |
190 | /* Begin PBXNativeTarget section */
191 | 3AB5FB5A0FA496E30027C02E /* RemotePad Server 10.4 */ = {
192 | isa = PBXNativeTarget;
193 | buildConfigurationList = 3AB5FB690FA496E30027C02E /* Build configuration list for PBXNativeTarget "RemotePad Server 10.4" */;
194 | buildPhases = (
195 | 3AB5FB5B0FA496E30027C02E /* Resources */,
196 | 3AB5FB620FA496E30027C02E /* Sources */,
197 | 3AB5FB660FA496E30027C02E /* Frameworks */,
198 | );
199 | buildRules = (
200 | );
201 | dependencies = (
202 | );
203 | name = "RemotePad Server 10.4";
204 | productInstallPath = "$(HOME)/Applications";
205 | productName = "RemotePad Server";
206 | productReference = 3AB5FB6C0FA496E30027C02E /* RemotePad Server.app */;
207 | productType = "com.apple.product-type.application";
208 | };
209 | 8D15AC270486D014006FF6A4 /* RemotePad Server */ = {
210 | isa = PBXNativeTarget;
211 | buildConfigurationList = C05733C708A9546B00998B17 /* Build configuration list for PBXNativeTarget "RemotePad Server" */;
212 | buildPhases = (
213 | 8D15AC2B0486D014006FF6A4 /* Resources */,
214 | 8D15AC300486D014006FF6A4 /* Sources */,
215 | 8D15AC330486D014006FF6A4 /* Frameworks */,
216 | );
217 | buildRules = (
218 | );
219 | dependencies = (
220 | );
221 | name = "RemotePad Server";
222 | productInstallPath = "$(HOME)/Applications";
223 | productName = "RemotePad Server";
224 | productReference = 8D15AC370486D014006FF6A4 /* RemotePad Server.app */;
225 | productType = "com.apple.product-type.application";
226 | };
227 | /* End PBXNativeTarget section */
228 |
229 | /* Begin PBXProject section */
230 | 2A37F4A9FDCFA73011CA2CEA /* Project object */ = {
231 | isa = PBXProject;
232 | buildConfigurationList = C05733CB08A9546B00998B17 /* Build configuration list for PBXProject "RemotePad Server" */;
233 | compatibilityVersion = "Xcode 3.1";
234 | hasScannedForEncodings = 1;
235 | mainGroup = 2A37F4AAFDCFA73011CA2CEA /* RemotePad Server */;
236 | projectDirPath = "";
237 | projectRoot = "";
238 | targets = (
239 | 8D15AC270486D014006FF6A4 /* RemotePad Server */,
240 | 3AB5FB5A0FA496E30027C02E /* RemotePad Server 10.4 */,
241 | );
242 | };
243 | /* End PBXProject section */
244 |
245 | /* Begin PBXResourcesBuildPhase section */
246 | 3AB5FB5B0FA496E30027C02E /* Resources */ = {
247 | isa = PBXResourcesBuildPhase;
248 | buildActionMask = 2147483647;
249 | files = (
250 | 3AB5FB5C0FA496E30027C02E /* Credits.rtf in Resources */,
251 | 3AB5FB5D0FA496E30027C02E /* InfoPlist.strings in Resources */,
252 | 3AB5FB5E0FA496E30027C02E /* RemotePad Server.icns in Resources */,
253 | 3AB5FB5F0FA496E30027C02E /* pointer.png in Resources */,
254 | 3AB5FB600FA496E30027C02E /* pointer-notconnected.png in Resources */,
255 | 3AB5FB610FA496E30027C02E /* MainMenu.xib in Resources */,
256 | );
257 | runOnlyForDeploymentPostprocessing = 0;
258 | };
259 | 8D15AC2B0486D014006FF6A4 /* Resources */ = {
260 | isa = PBXResourcesBuildPhase;
261 | buildActionMask = 2147483647;
262 | files = (
263 | 8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */,
264 | 8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */,
265 | 3A166AF30E7F6B8F00001374 /* RemotePad Server.icns in Resources */,
266 | 5631BFD80F2A2FD80042B665 /* pointer.png in Resources */,
267 | 3AE7727C0F6108460021B2DE /* pointer-notconnected.png in Resources */,
268 | 3AB5FB580FA492B90027C02E /* MainMenu.xib in Resources */,
269 | );
270 | runOnlyForDeploymentPostprocessing = 0;
271 | };
272 | /* End PBXResourcesBuildPhase section */
273 |
274 | /* Begin PBXSourcesBuildPhase section */
275 | 3AB5FB620FA496E30027C02E /* Sources */ = {
276 | isa = PBXSourcesBuildPhase;
277 | buildActionMask = 2147483647;
278 | files = (
279 | 3AB5FB630FA496E30027C02E /* main.m in Sources */,
280 | 3AB5FB640FA496E30027C02E /* TCPServer.m in Sources */,
281 | 3AB5FB650FA496E30027C02E /* AppController.m in Sources */,
282 | );
283 | runOnlyForDeploymentPostprocessing = 0;
284 | };
285 | 8D15AC300486D014006FF6A4 /* Sources */ = {
286 | isa = PBXSourcesBuildPhase;
287 | buildActionMask = 2147483647;
288 | files = (
289 | 8D15AC320486D014006FF6A4 /* main.m in Sources */,
290 | 3AB151190E7F5D0500FB4375 /* TCPServer.m in Sources */,
291 | 5650583F0F2A0A220067B358 /* AppController.m in Sources */,
292 | );
293 | runOnlyForDeploymentPostprocessing = 0;
294 | };
295 | /* End PBXSourcesBuildPhase section */
296 |
297 | /* Begin PBXVariantGroup section */
298 | 089C165FFE840EACC02AAC07 /* InfoPlist.strings */ = {
299 | isa = PBXVariantGroup;
300 | children = (
301 | 089C1660FE840EACC02AAC07 /* English */,
302 | );
303 | name = InfoPlist.strings;
304 | sourceTree = "";
305 | };
306 | 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */ = {
307 | isa = PBXVariantGroup;
308 | children = (
309 | 2A37F4BAFDCFA73011CA2CEA /* English */,
310 | );
311 | name = Credits.rtf;
312 | sourceTree = "";
313 | };
314 | 3AB5FB560FA492B90027C02E /* MainMenu.xib */ = {
315 | isa = PBXVariantGroup;
316 | children = (
317 | 3AB5FB570FA492B90027C02E /* English */,
318 | );
319 | name = MainMenu.xib;
320 | sourceTree = "";
321 | };
322 | /* End PBXVariantGroup section */
323 |
324 | /* Begin XCBuildConfiguration section */
325 | 3AB5FB6A0FA496E30027C02E /* Debug */ = {
326 | isa = XCBuildConfiguration;
327 | buildSettings = {
328 | ALWAYS_SEARCH_USER_PATHS = NO;
329 | COPY_PHASE_STRIP = NO;
330 | GCC_DYNAMIC_NO_PIC = NO;
331 | GCC_ENABLE_FIX_AND_CONTINUE = YES;
332 | GCC_MODEL_TUNING = G5;
333 | GCC_OPTIMIZATION_LEVEL = 0;
334 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
335 | GCC_PREFIX_HEADER = "RemotePad Server_Prefix.pch";
336 | INFOPLIST_FILE = Info.plist;
337 | INSTALL_PATH = "$(HOME)/Applications";
338 | MACOSX_DEPLOYMENT_TARGET = 10.4;
339 | PRODUCT_NAME = "RemotePad Server";
340 | SDKROOT = macosx10.4;
341 | };
342 | name = Debug;
343 | };
344 | 3AB5FB6B0FA496E30027C02E /* Release */ = {
345 | isa = XCBuildConfiguration;
346 | buildSettings = {
347 | ALWAYS_SEARCH_USER_PATHS = NO;
348 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
349 | GCC_MODEL_TUNING = G5;
350 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
351 | GCC_PREFIX_HEADER = "RemotePad Server_Prefix.pch";
352 | INFOPLIST_FILE = Info.plist;
353 | INSTALL_PATH = "$(HOME)/Applications";
354 | MACOSX_DEPLOYMENT_TARGET = 10.4;
355 | PRODUCT_NAME = "RemotePad Server";
356 | SDKROOT = macosx10.4;
357 | };
358 | name = Release;
359 | };
360 | C05733C808A9546B00998B17 /* Debug */ = {
361 | isa = XCBuildConfiguration;
362 | buildSettings = {
363 | ALWAYS_SEARCH_USER_PATHS = NO;
364 | COPY_PHASE_STRIP = NO;
365 | GCC_DYNAMIC_NO_PIC = NO;
366 | GCC_ENABLE_FIX_AND_CONTINUE = YES;
367 | GCC_MODEL_TUNING = G5;
368 | GCC_OPTIMIZATION_LEVEL = 0;
369 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
370 | GCC_PREFIX_HEADER = "RemotePad Server_Prefix.pch";
371 | INFOPLIST_FILE = Info.plist;
372 | INSTALL_PATH = "$(HOME)/Applications";
373 | PRODUCT_NAME = "RemotePad Server";
374 | };
375 | name = Debug;
376 | };
377 | C05733C908A9546B00998B17 /* Release */ = {
378 | isa = XCBuildConfiguration;
379 | buildSettings = {
380 | ALWAYS_SEARCH_USER_PATHS = NO;
381 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
382 | GCC_MODEL_TUNING = G5;
383 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
384 | GCC_PREFIX_HEADER = "RemotePad Server_Prefix.pch";
385 | INFOPLIST_FILE = Info.plist;
386 | INSTALL_PATH = "$(HOME)/Applications";
387 | PRODUCT_NAME = "RemotePad Server";
388 | };
389 | name = Release;
390 | };
391 | C05733CC08A9546B00998B17 /* Debug */ = {
392 | isa = XCBuildConfiguration;
393 | buildSettings = {
394 | ARCHS = "$(ARCHS_STANDARD_32_BIT)";
395 | GCC_C_LANGUAGE_STANDARD = c99;
396 | GCC_OPTIMIZATION_LEVEL = 0;
397 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
398 | GCC_WARN_UNUSED_VARIABLE = YES;
399 | ONLY_ACTIVE_ARCH = YES;
400 | PREBINDING = NO;
401 | SDKROOT = macosx10.5;
402 | };
403 | name = Debug;
404 | };
405 | C05733CD08A9546B00998B17 /* Release */ = {
406 | isa = XCBuildConfiguration;
407 | buildSettings = {
408 | ADDITIONAL_SDKS = "";
409 | ARCHS = "$(ARCHS_STANDARD_32_BIT)";
410 | GCC_C_LANGUAGE_STANDARD = c99;
411 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
412 | GCC_WARN_UNUSED_VARIABLE = YES;
413 | PREBINDING = NO;
414 | SDKROOT = macosx10.5;
415 | };
416 | name = Release;
417 | };
418 | /* End XCBuildConfiguration section */
419 |
420 | /* Begin XCConfigurationList section */
421 | 3AB5FB690FA496E30027C02E /* Build configuration list for PBXNativeTarget "RemotePad Server 10.4" */ = {
422 | isa = XCConfigurationList;
423 | buildConfigurations = (
424 | 3AB5FB6A0FA496E30027C02E /* Debug */,
425 | 3AB5FB6B0FA496E30027C02E /* Release */,
426 | );
427 | defaultConfigurationIsVisible = 0;
428 | defaultConfigurationName = Release;
429 | };
430 | C05733C708A9546B00998B17 /* Build configuration list for PBXNativeTarget "RemotePad Server" */ = {
431 | isa = XCConfigurationList;
432 | buildConfigurations = (
433 | C05733C808A9546B00998B17 /* Debug */,
434 | C05733C908A9546B00998B17 /* Release */,
435 | );
436 | defaultConfigurationIsVisible = 0;
437 | defaultConfigurationName = Release;
438 | };
439 | C05733CB08A9546B00998B17 /* Build configuration list for PBXProject "RemotePad Server" */ = {
440 | isa = XCConfigurationList;
441 | buildConfigurations = (
442 | C05733CC08A9546B00998B17 /* Debug */,
443 | C05733CD08A9546B00998B17 /* Release */,
444 | );
445 | defaultConfigurationIsVisible = 0;
446 | defaultConfigurationName = Release;
447 | };
448 | /* End XCConfigurationList section */
449 | };
450 | rootObject = 2A37F4A9FDCFA73011CA2CEA /* Project object */;
451 | }
452 |
--------------------------------------------------------------------------------
/Mac OS X/RemotePad Server_Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'RemotePad Server' target in the 'RemotePad Server' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #endif
8 |
--------------------------------------------------------------------------------
/Mac OS X/TCPServer.h:
--------------------------------------------------------------------------------
1 | //
2 | // TCPServer.h
3 | // RemotePad Server
4 | //
5 | // Imported from an Apple's sample code WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/18.
7 | //
8 |
9 | /*
10 |
11 | File: TCPServer.h
12 | Abstract: A TCP server that listens on an arbitrary port.
13 |
14 | Version: 1.5
15 |
16 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
17 | ("Apple") in consideration of your agreement to the following terms, and your
18 | use, installation, modification or redistribution of this Apple software
19 | constitutes acceptance of these terms. If you do not agree with these terms,
20 | please do not use, install, modify or redistribute this Apple software.
21 |
22 | In consideration of your agreement to abide by the following terms, and subject
23 | to these terms, Apple grants you a personal, non-exclusive license, under
24 | Apple's copyrights in this original Apple software (the "Apple Software"), to
25 | use, reproduce, modify and redistribute the Apple Software, with or without
26 | modifications, in source and/or binary forms; provided that if you redistribute
27 | the Apple Software in its entirety and without modifications, you must retain
28 | this notice and the following text and disclaimers in all such redistributions
29 | of the Apple Software.
30 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
31 | to endorse or promote products derived from the Apple Software without specific
32 | prior written permission from Apple. Except as expressly stated in this notice,
33 | no other rights or licenses, express or implied, are granted by Apple herein,
34 | including but not limited to any patent rights that may be infringed by your
35 | derivative works or by other works in which the Apple Software may be
36 | incorporated.
37 |
38 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
39 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
40 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
42 | COMBINATION WITH YOUR PRODUCTS.
43 |
44 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
45 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
46 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
48 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
49 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
50 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 |
52 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
53 |
54 | */
55 |
56 | #import
57 |
58 | //CLASSES:
59 |
60 | @class TCPServer;
61 |
62 | //ERRORS:
63 |
64 | NSString * const TCPServerErrorDomain;
65 |
66 | typedef enum {
67 | kTCPServerCouldNotBindToIPv4Address = 1,
68 | kTCPServerCouldNotBindToIPv6Address = 2,
69 | kTCPServerNoSocketsAvailable = 3,
70 | } TCPServerErrorCode;
71 |
72 | //PROTOCOLS:
73 |
74 | @protocol TCPServerDelegate
75 | @optional
76 | - (void) serverDidEnableBonjour:(TCPServer*)server withName:(NSString*)name;
77 | - (void) server:(TCPServer*)server didNotEnableBonjour:(NSDictionary *)errorDict;
78 | - (void) didAcceptConnectionForServer:(TCPServer*)server inputStream:(NSInputStream *)istr outputStream:(NSOutputStream *)ostr;
79 | @end
80 |
81 | //CLASS INTERFACES:
82 |
83 | @interface TCPServer : NSObject {
84 | @private
85 | id delegate;
86 | uint16_t port;
87 | CFSocketRef _ipv4socket;
88 | NSNetService* netService;
89 | }
90 |
91 | - (BOOL)start:(NSError **)error;
92 | - (BOOL)stop;
93 | - (BOOL) enableBonjourWithDomain:(NSString*)domain applicationProtocol:(NSString*)protocol name:(NSString*)name; //Pass "nil" for the default local domain - Pass only the application protocol for "protocol" e.g. "myApp"
94 | - (void) disableBonjour;
95 | - (void)setDelegate:(id)obj;
96 | - (uint16_t) port;
97 |
98 | + (NSString*) bonjourTypeFromIdentifier:(NSString*)identifier;
99 |
100 | @end
101 |
--------------------------------------------------------------------------------
/Mac OS X/TCPServer.m:
--------------------------------------------------------------------------------
1 | //
2 | // TCPServer.m
3 | // RemotePad Server
4 | //
5 | // Imported from an Apple's sample code WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/18.
7 | //
8 |
9 | /*
10 |
11 | File: TCPServer.m
12 | Abstract: A TCP server that listens on an arbitrary port.
13 |
14 | Version: 1.5
15 |
16 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
17 | ("Apple") in consideration of your agreement to the following terms, and your
18 | use, installation, modification or redistribution of this Apple software
19 | constitutes acceptance of these terms. If you do not agree with these terms,
20 | please do not use, install, modify or redistribute this Apple software.
21 |
22 | In consideration of your agreement to abide by the following terms, and subject
23 | to these terms, Apple grants you a personal, non-exclusive license, under
24 | Apple's copyrights in this original Apple software (the "Apple Software"), to
25 | use, reproduce, modify and redistribute the Apple Software, with or without
26 | modifications, in source and/or binary forms; provided that if you redistribute
27 | the Apple Software in its entirety and without modifications, you must retain
28 | this notice and the following text and disclaimers in all such redistributions
29 | of the Apple Software.
30 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
31 | to endorse or promote products derived from the Apple Software without specific
32 | prior written permission from Apple. Except as expressly stated in this notice,
33 | no other rights or licenses, express or implied, are granted by Apple herein,
34 | including but not limited to any patent rights that may be infringed by your
35 | derivative works or by other works in which the Apple Software may be
36 | incorporated.
37 |
38 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
39 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
40 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
42 | COMBINATION WITH YOUR PRODUCTS.
43 |
44 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
45 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
46 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
48 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
49 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
50 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 |
52 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
53 |
54 | */
55 |
56 | #include
57 | #include
58 | #include
59 | //#include
60 |
61 | #import "TCPServer.h"
62 |
63 | #define kDefaultPort 5583
64 |
65 | NSString * const TCPServerErrorDomain = @"TCPServerErrorDomain";
66 |
67 | @implementation TCPServer
68 |
69 | - (id)delegate {
70 | return delegate;
71 | }
72 |
73 | - (void)setDelegate:(id)obj {
74 | delegate = obj;
75 | }
76 |
77 | - (NSNetService*)netService {
78 | return netService;
79 | }
80 |
81 | - (void)setNetService:(NSNetService*)obj {
82 | if (netService != obj) {
83 | [netService release];
84 | netService = [obj retain];
85 | }
86 | }
87 |
88 | - (uint16_t)port {
89 | return port;
90 | }
91 |
92 | - (void)setPort:(uint16_t)obj {
93 | port = obj;
94 | }
95 |
96 | - (id)init {
97 | return self;
98 | }
99 |
100 | - (void)dealloc {
101 | [self stop];
102 | [super dealloc];
103 | }
104 |
105 | - (void)handleNewConnectionFromAddress:(NSData *)addr inputStream:(NSInputStream *)istr outputStream:(NSOutputStream *)ostr {
106 | // if the delegate implements the delegate method, call it
107 | if (self.delegate && [self.delegate respondsToSelector:@selector(didAcceptConnectionForServer:inputStream:outputStream:)]) {
108 | [self.delegate didAcceptConnectionForServer:self inputStream:istr outputStream:ostr];
109 | }
110 | }
111 |
112 | // This function is called by CFSocket when a new connection comes in.
113 | // We gather some data here, and convert the function call to a method
114 | // invocation on TCPServer.
115 | static void TCPServerAcceptCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info) {
116 | TCPServer *server = (TCPServer *)info;
117 | if (kCFSocketAcceptCallBack == type) {
118 | // for an AcceptCallBack, the data parameter is a pointer to a CFSocketNativeHandle
119 | CFSocketNativeHandle nativeSocketHandle = *(CFSocketNativeHandle *)data;
120 | uint8_t name[SOCK_MAXADDRLEN];
121 | socklen_t namelen = sizeof(name);
122 | NSData *peer = nil;
123 | if (0 == getpeername(nativeSocketHandle, (struct sockaddr *)name, &namelen)) {
124 | peer = [NSData dataWithBytes:name length:namelen];
125 | }
126 | CFReadStreamRef readStream = NULL;
127 | CFWriteStreamRef writeStream = NULL;
128 | CFStreamCreatePairWithSocket(kCFAllocatorDefault, nativeSocketHandle, &readStream, &writeStream);
129 | if (readStream && writeStream) {
130 | CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
131 | CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
132 | [server handleNewConnectionFromAddress:peer inputStream:(NSInputStream *)readStream outputStream:(NSOutputStream *)writeStream];
133 | } else {
134 | // on any failure, need to destroy the CFSocketNativeHandle
135 | // since we are not going to use it any more
136 | close(nativeSocketHandle);
137 | }
138 | if (readStream) CFRelease(readStream);
139 | if (writeStream) CFRelease(writeStream);
140 | }
141 | }
142 |
143 | - (BOOL)start:(NSError **)error {
144 | CFSocketContext socketCtxt = {0, self, NULL, NULL, NULL};
145 | _ipv4socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, kCFSocketAcceptCallBack, (CFSocketCallBack)&TCPServerAcceptCallBack, &socketCtxt);
146 |
147 | if (NULL == _ipv4socket) {
148 | if (error) *error = [[NSError alloc] initWithDomain:TCPServerErrorDomain code:kTCPServerNoSocketsAvailable userInfo:nil];
149 | if (_ipv4socket) CFRelease(_ipv4socket);
150 | _ipv4socket = NULL;
151 | return NO;
152 | }
153 |
154 |
155 | int yes = 1;
156 | setsockopt(CFSocketGetNative(_ipv4socket), SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
157 |
158 | // set up the IPv4 endpoint; use port 0, so the kernel will choose an arbitrary port for us, which will be advertised using Bonjour
159 | struct sockaddr_in addr4;
160 | memset(&addr4, 0, sizeof(addr4));
161 | addr4.sin_len = sizeof(addr4);
162 | addr4.sin_family = AF_INET;
163 | addr4.sin_port = htons(kDefaultPort);
164 | addr4.sin_addr.s_addr = htonl(INADDR_ANY);
165 | NSData *address4 = [NSData dataWithBytes:&addr4 length:sizeof(addr4)];
166 |
167 | if (kCFSocketSuccess != CFSocketSetAddress(_ipv4socket, (CFDataRef)address4)) {
168 | if (error) *error = [[NSError alloc] initWithDomain:TCPServerErrorDomain code:kTCPServerCouldNotBindToIPv4Address userInfo:nil];
169 | if (_ipv4socket) CFRelease(_ipv4socket);
170 | _ipv4socket = NULL;
171 | return NO;
172 | }
173 |
174 | // now that the binding was successful, we get the port number
175 | // -- we will need it for the NSNetService
176 | NSData *addr = [(NSData *)CFSocketCopyAddress(_ipv4socket) autorelease];
177 | memcpy(&addr4, [addr bytes], [addr length]);
178 | self.port = ntohs(addr4.sin_port);
179 |
180 |
181 | // set up the run loop sources for the sockets
182 | CFRunLoopRef cfrl = CFRunLoopGetCurrent();
183 | CFRunLoopSourceRef source4 = CFSocketCreateRunLoopSource(kCFAllocatorDefault, _ipv4socket, 0);
184 | CFRunLoopAddSource(cfrl, source4, kCFRunLoopCommonModes);
185 | CFRelease(source4);
186 |
187 |
188 | return YES;
189 | }
190 |
191 | - (BOOL)stop {
192 | [self disableBonjour];
193 |
194 | if (_ipv4socket) {
195 | CFSocketInvalidate(_ipv4socket);
196 | CFRelease(_ipv4socket);
197 | _ipv4socket = NULL;
198 | }
199 |
200 |
201 | return YES;
202 | }
203 |
204 | - (BOOL) enableBonjourWithDomain:(NSString*)domain applicationProtocol:(NSString*)protocol name:(NSString*)name
205 | {
206 | if(![domain length])
207 | domain = @""; //Will use default Bonjour registration doamins, typically just ".local"
208 | if(![name length])
209 | name = @""; //Will use default Bonjour name, e.g. the name assigned to the device in iTunes
210 |
211 | if(!protocol || ![protocol length] || _ipv4socket == NULL)
212 | return NO;
213 |
214 |
215 | self.netService = [[NSNetService alloc] initWithDomain:domain type:protocol name:name port:self.port];
216 | if(self.netService == nil)
217 | return NO;
218 |
219 | [self.netService scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:(NSString*)kCFRunLoopCommonModes];
220 | [self.netService publish];
221 | [self.netService setDelegate:self];
222 |
223 | return YES;
224 | }
225 |
226 | /*
227 | Bonjour will not allow conflicting service instance names (in the same domain), and may have automatically renamed
228 | the service if there was a conflict. We pass the name back to the delegate so that the name can be displayed to
229 | the user.
230 | See http://developer.apple.com/networking/bonjour/faq.html for more information.
231 | */
232 |
233 | - (void)netServiceDidPublish:(NSNetService *)sender
234 | {
235 | if (self.delegate && [self.delegate respondsToSelector:@selector(serverDidEnableBonjour:withName:)])
236 | [self.delegate serverDidEnableBonjour:self withName:sender.name];
237 | }
238 |
239 | - (void)netService:(NSNetService *)sender didNotPublish:(NSDictionary *)errorDict
240 | {
241 | [super netServiceDidPublish:sender];
242 | if(self.delegate && [self.delegate respondsToSelector:@selector(server:didNotEnableBonjour:)])
243 | [self.delegate server:self didNotEnableBonjour:errorDict];
244 | }
245 |
246 | - (void) disableBonjour
247 | {
248 | if(self.netService) {
249 | [self.netService stop];
250 | [self.netService removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:(NSString*)kCFRunLoopCommonModes];
251 | self.netService = nil;
252 | }
253 | }
254 |
255 | - (NSString*) description
256 | {
257 | return [NSString stringWithFormat:@"<%@ = 0x%08X | port %d | netService = %@>", [self class], (long)self, self.port, self.netService];
258 | }
259 |
260 | + (NSString*) bonjourTypeFromIdentifier:(NSString*)identifier {
261 | if (![identifier length])
262 | return nil;
263 |
264 | return [NSString stringWithFormat:@"_%@._tcp.", identifier];
265 | }
266 |
267 | @end
268 |
--------------------------------------------------------------------------------
/Mac OS X/icon.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/Mac OS X/icon.xcf
--------------------------------------------------------------------------------
/Mac OS X/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // RemotePad Server
4 | //
5 | // Created by iKawamoto Yosihisa! on 08/09/16.
6 | // Copyright 2008, 2009 tenjin.org. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | int main(int argc, char *argv[])
12 | {
13 | return NSApplicationMain(argc, (const char **) argv);
14 | }
15 |
--------------------------------------------------------------------------------
/Mac OS X/pointer-notconnected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/Mac OS X/pointer-notconnected.png
--------------------------------------------------------------------------------
/Mac OS X/pointer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/Mac OS X/pointer.png
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | RemotePad for iPhone and RemotePad Server README
2 |
3 | This directory contains source files of RemotePad for iPhone, and
4 | RemotePad Server for Mac OS X, Windows and X11. The software
5 | 'RemotePad Server' is a server application for and used with
6 | 'RemotePad,' an iPhone/iPod touch application.
7 |
8 | RemotePad is an application that controls the mouse cursor
9 | of your desktop PC. This way, you can use your iPhone or
10 | iPod touch as a wireless touchpad. You can get RemotePad
11 | from the iTunes App Store.
12 |
13 | To compile and install RemotePad for iPhone or RemotePad Servers,
14 | please read a INSTALL file.
15 |
--------------------------------------------------------------------------------
/RemotePad/AppController.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppController.h
3 | // RemotePad
4 | //
5 | // Derived from an Apple's sample code AppController.h of WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/17.
7 | //
8 | /*
9 |
10 | File: AppController.h
11 | Abstract: UIApplication's delegate class, the central controller of the
12 | application.
13 |
14 | Version: 1.5
15 |
16 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
17 | ("Apple") in consideration of your agreement to the following terms, and your
18 | use, installation, modification or redistribution of this Apple software
19 | constitutes acceptance of these terms. If you do not agree with these terms,
20 | please do not use, install, modify or redistribute this Apple software.
21 |
22 | In consideration of your agreement to abide by the following terms, and subject
23 | to these terms, Apple grants you a personal, non-exclusive license, under
24 | Apple's copyrights in this original Apple software (the "Apple Software"), to
25 | use, reproduce, modify and redistribute the Apple Software, with or without
26 | modifications, in source and/or binary forms; provided that if you redistribute
27 | the Apple Software in its entirety and without modifications, you must retain
28 | this notice and the following text and disclaimers in all such redistributions
29 | of the Apple Software.
30 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
31 | to endorse or promote products derived from the Apple Software without specific
32 | prior written permission from Apple. Except as expressly stated in this notice,
33 | no other rights or licenses, express or implied, are granted by Apple herein,
34 | including but not limited to any patent rights that may be infringed by your
35 | derivative works or by other works in which the Apple Software may be
36 | incorporated.
37 |
38 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
39 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
40 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
42 | COMBINATION WITH YOUR PRODUCTS.
43 |
44 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
45 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
46 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
48 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
49 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
50 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 |
52 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
53 |
54 | */
55 |
56 | //#import "TapView.h" see EOF
57 | #import "BrowserViewController.h"
58 | #import "PickerViewController.h"
59 | #import "Picker.h"
60 | #import "TCPServer.h"
61 | #import "Event.h"
62 |
63 | @class TapViewController;
64 | @class SetupViewController;
65 |
66 | //CLASS INTERFACES:
67 |
68 | @interface AppController : NSObject
69 | {
70 | UIWindow* _window;
71 | TCPServer* _server;
72 | NSInputStream* _inStream;
73 | NSOutputStream* _outStream;
74 | BOOL _inReady;
75 | BOOL _outReady;
76 | TapViewController *tapViewController;
77 | SetupViewController *setupViewController;
78 | UINavigationController *navigationController;
79 | PickerViewController *pickerViewController;
80 | }
81 |
82 | - (void) showSetupView:(id)sender;
83 | - (void) send:(uint32_t)type with:(int32_t)value time:(NSTimeInterval)timestamp;
84 | - (void)setInputStream:(NSInputStream *)inputStream outputStream:(NSOutputStream *)outputStream;
85 | - (void) setup;
86 | - (void) closeStreams;
87 |
88 | @property (readonly) TapViewController *tapViewController;
89 |
90 | @end
91 |
--------------------------------------------------------------------------------
/RemotePad/AppController.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppController.m
3 | // RemotePad
4 | //
5 | // Derived from an Apple's sample code AppController.m of WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/17.
7 | //
8 | /*
9 |
10 | File: AppController.m
11 | Abstract: UIApplication's delegate class, the central controller of the
12 | application.
13 |
14 | Version: 1.5
15 |
16 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
17 | ("Apple") in consideration of your agreement to the following terms, and your
18 | use, installation, modification or redistribution of this Apple software
19 | constitutes acceptance of these terms. If you do not agree with these terms,
20 | please do not use, install, modify or redistribute this Apple software.
21 |
22 | In consideration of your agreement to abide by the following terms, and subject
23 | to these terms, Apple grants you a personal, non-exclusive license, under
24 | Apple's copyrights in this original Apple software (the "Apple Software"), to
25 | use, reproduce, modify and redistribute the Apple Software, with or without
26 | modifications, in source and/or binary forms; provided that if you redistribute
27 | the Apple Software in its entirety and without modifications, you must retain
28 | this notice and the following text and disclaimers in all such redistributions
29 | of the Apple Software.
30 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
31 | to endorse or promote products derived from the Apple Software without specific
32 | prior written permission from Apple. Except as expressly stated in this notice,
33 | no other rights or licenses, express or implied, are granted by Apple herein,
34 | including but not limited to any patent rights that may be infringed by your
35 | derivative works or by other works in which the Apple Software may be
36 | incorporated.
37 |
38 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
39 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
40 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
42 | COMBINATION WITH YOUR PRODUCTS.
43 |
44 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
45 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
46 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
48 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
49 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
50 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 |
52 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
53 |
54 | */
55 |
56 | #import "AppController.h"
57 | #import "TapView.h"
58 | #import "SetupViewController.h"
59 | #import "Constants.h"
60 |
61 | #include
62 |
63 | //INTERFACES:
64 |
65 | @interface AppController ()
66 | - (void) setup;
67 | - (void) presentPicker:(NSString*)name;
68 | @end
69 |
70 | //CLASS IMPLEMENTATIONS:
71 |
72 | @implementation AppController
73 |
74 | @synthesize tapViewController;
75 |
76 | - (void) _showAlert:(NSString*)title
77 | {
78 | UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:@"Check your networking configuration." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
79 | [alertView show];
80 | [alertView release];
81 | }
82 |
83 | - (void) applicationDidFinishLaunching:(UIApplication*)application
84 | {
85 | [application setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];
86 |
87 | //Create a full-screen window
88 | _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
89 | [_window setBackgroundColor:[UIColor darkGrayColor]];
90 |
91 | //Create a picker view
92 | pickerViewController = [[PickerViewController alloc] init];
93 | navigationController = [[UINavigationController alloc] initWithRootViewController:pickerViewController];
94 | [navigationController setNavigationBarHidden:YES animated:NO];
95 |
96 | //Create the tap views and add them to the view controller's view
97 | tapViewController = [[TapViewController alloc] init];
98 | [tapViewController resetAllStates:self];
99 |
100 | //Create the setup view
101 | setupViewController = [[SetupViewController alloc] init];
102 |
103 | [_window addSubview:navigationController.view];
104 |
105 | //Show the window
106 | [application setStatusBarHidden:NO animated:YES];
107 | [_window makeKeyAndVisible];
108 |
109 | [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)];
110 |
111 | //Create and advertise a new game and discover other availble games
112 | [self setup];
113 | }
114 | - (void)applicationWillTerminate:(UIApplication *)application {
115 | [[NSUserDefaults standardUserDefaults] synchronize];
116 | }
117 |
118 | - (void) dealloc
119 | {
120 | [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
121 |
122 | [self closeStreams];
123 | [_server release];
124 |
125 | [tapViewController release];
126 | [setupViewController release];
127 | [navigationController release];
128 | [pickerViewController release];
129 |
130 | [_window release];
131 |
132 | [super dealloc];
133 | }
134 |
135 | - (void) setup {
136 | [self closeStreams];
137 | [_server release];
138 |
139 | _server = [TCPServer new];
140 | [_server setDelegate:self];
141 | NSError* error;
142 | if(_server == nil || ![_server start:&error]) {
143 | NSLog(@"Failed creating server: %@", error);
144 | [self _showAlert:@"Failed creating server"];
145 | return;
146 | }
147 |
148 | //Start advertising to clients, passing nil for the name to tell Bonjour to pick use default name
149 | if(![_server enableBonjourWithDomain:@"local" applicationProtocol:[TCPServer bonjourTypeFromIdentifier:kBonjourIdentifier] name:nil]) {
150 | [self _showAlert:@"Failed advertising server"];
151 | return;
152 | }
153 |
154 | [self presentPicker:nil];
155 | }
156 |
157 | - (void) showSetupView:(id)sender {
158 | [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
159 | if (tapViewController.tapViewOrientation != UIInterfaceOrientationPortrait) {
160 | [tapViewController showToolbars:NO showStatusbar:NO temporal:YES];
161 | [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
162 | [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
163 | }
164 | [setupViewController adjustCellValues];
165 | [navigationController pushViewController:setupViewController animated:YES];
166 | }
167 |
168 | - (void) hideSetupView:(id)sender {
169 | [navigationController popViewControllerAnimated:YES];
170 | [tapViewController prepareTapView];
171 | [[UIAccelerometer sharedAccelerometer] setDelegate:tapViewController];
172 | }
173 |
174 | - (void) showTapView {
175 | [tapViewController resetAllStates:self];
176 | [navigationController pushViewController:tapViewController animated:YES];
177 | [tapViewController prepareTapView];
178 | [[UIAccelerometer sharedAccelerometer] setDelegate:tapViewController];
179 | }
180 |
181 | // Make sure to let the user know what name is being used for Bonjour advertisement.
182 | // This way, other players can browse for and connect to this game.
183 | // Note that this may be called while the alert is already being displayed, as
184 | // Bonjour may detect a name conflict and rename dynamically.
185 | - (void) presentPicker:(NSString*)name {
186 | [(Picker *)[pickerViewController view] setGameName:name];
187 | [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
188 | [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
189 | [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
190 | [navigationController popToRootViewControllerAnimated:YES];
191 | }
192 |
193 | // If we display an error or an alert that the remote disconnected, handle dismissal and return to setup
194 | - (void) alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
195 | {
196 | [self setup];
197 | }
198 |
199 | - (void)send:(uint32_t)type with:(int32_t)value time:(NSTimeInterval)timestamp {
200 | uint32_t tv_sec = (uint32_t)timestamp;
201 | MouseEvent event = {htonl(type), htonl(value), htonl(tv_sec), htonl((long)((timestamp-tv_sec)*1.0E9))};
202 |
203 | if (_outStream && [_outStream hasSpaceAvailable])
204 | if([_outStream write:(uint8_t *)&event maxLength:sizeof(MouseEvent)] == -1)
205 | [self _showAlert:@"Failed sending data to peer"];
206 | }
207 |
208 | - (void) openStreams
209 | {
210 | _inStream.delegate = self;
211 | [_inStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
212 | [_inStream open];
213 | _outStream.delegate = self;
214 | [_outStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
215 | [_outStream open];
216 | }
217 |
218 | - (void) closeStreams {
219 | [_inStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
220 | [_inStream close];
221 | [_inStream release];
222 | _inStream = nil;
223 | _inReady = NO;
224 |
225 | [_outStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
226 | [_outStream close];
227 | [_outStream release];
228 | _outStream = nil;
229 | _outReady = NO;
230 | }
231 |
232 | - (void) browserViewController:(BrowserViewController*)bvc didResolveInstance:(NSNetService*)netService
233 | {
234 | if (!netService) {
235 | [self setup];
236 | return;
237 | }
238 |
239 | if (![netService getInputStream:&_inStream outputStream:&_outStream]) {
240 | [self _showAlert:@"Failed connecting to server"];
241 | return;
242 | }
243 |
244 | [self openStreams];
245 | }
246 |
247 | - (void)setInputStream:(NSInputStream *)inputStream outputStream:(NSOutputStream *)outputStream {
248 | _inStream = inputStream;
249 | [_inStream retain];
250 | _outStream = outputStream;
251 | [_outStream retain];
252 |
253 | [self openStreams];
254 | }
255 |
256 | @end
257 |
258 | @implementation AppController (NSStreamDelegate)
259 |
260 | - (void) stream:(NSStream*)stream handleEvent:(NSStreamEvent)eventCode
261 | {
262 | UIAlertView* alertView;
263 | switch(eventCode) {
264 | case NSStreamEventOpenCompleted:
265 | {
266 | [_server release];
267 | _server = nil;
268 |
269 | if (stream == _inStream)
270 | _inReady = YES;
271 | else
272 | _outReady = YES;
273 |
274 | if (_inReady && _outReady) {
275 | [self showTapView];
276 |
277 | alertView = [[UIAlertView alloc] initWithTitle:@"Connected!" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Continue", nil];
278 | [alertView show];
279 | [alertView release];
280 | }
281 | break;
282 | }
283 | case NSStreamEventHasBytesAvailable:
284 | {
285 | if (stream == _inStream) {
286 | uint8_t b;
287 | unsigned int len = 0;
288 | len = [_inStream read:&b maxLength:sizeof(uint8_t)];
289 | if(!len) {
290 | if ([stream streamStatus] != NSStreamStatusAtEnd)
291 | [self _showAlert:@"Failed reading data from peer"];
292 | }
293 | }
294 | break;
295 | }
296 | case NSStreamEventEndEncountered:
297 | {
298 | UIAlertView* alertView;
299 |
300 | alertView = [[UIAlertView alloc] initWithTitle:@"Peer Disconnected!" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Continue", nil];
301 | [alertView show];
302 | [alertView release];
303 |
304 | break;
305 | }
306 | case NSStreamEventErrorOccurred:
307 | {
308 | NSError *theError = [stream streamError];
309 | UIAlertView *alertView;
310 | NSString *message = @"";
311 | if ([[theError domain] isEqualToString:NSPOSIXErrorDomain]) {
312 | switch ([theError code]) {
313 | case EAFNOSUPPORT:
314 | message = @"\nAdvice:\nPlease change the settings of your Firewall on your Mac to allow connections for the RemotePad Server.";
315 | break;
316 | case ETIMEDOUT:
317 | message = @"\nAdvice:\nPlease change the settings of your Windows Firewall on your PC to allow connections for the RemotePad Server.";
318 | break;
319 | }
320 | }
321 | [self closeStreams];
322 | alertView = [[UIAlertView alloc] initWithTitle:@"Error from stream!" message:[NSString stringWithFormat:@"System Message:\n%@%@", [theError localizedDescription], message] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Continue", nil];
323 | [alertView show];
324 | [alertView release];
325 | if (!_server)
326 | [self setup];
327 | break;
328 | }
329 | }
330 | }
331 |
332 | @end
333 |
334 | @implementation AppController (TCPServerDelegate)
335 |
336 | - (void) serverDidEnableBonjour:(TCPServer*)server withName:(NSString*)string
337 | {
338 | NSLog(@"%s", _cmd);
339 | [self presentPicker:string];
340 | }
341 |
342 | - (void)didAcceptConnectionForServer:(TCPServer*)server inputStream:(NSInputStream *)istr outputStream:(NSOutputStream *)ostr
343 | {
344 | if (_inStream || _outStream || server != _server)
345 | return;
346 |
347 | [_server release];
348 | _server = nil;
349 |
350 | _inStream = istr;
351 | [_inStream retain];
352 | _outStream = ostr;
353 | [_outStream retain];
354 |
355 | [self openStreams];
356 | }
357 |
358 | @end
359 |
--------------------------------------------------------------------------------
/RemotePad/Bonjour.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/Bonjour.png
--------------------------------------------------------------------------------
/RemotePad/BrowserViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // BrowserViewController.h
3 | // RemotePad
4 | //
5 | // Derived from an Apple's sample code BrowserViewController.h of WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/17.
7 | //
8 | /*
9 |
10 | File: BrowserViewController.h
11 | Abstract:
12 | View controller for the service instance list.
13 | This object manages a NSNetServiceBrowser configured to look for Bonjour
14 | services.
15 | It has an array of NSNetService objects that are displayed in a table view.
16 | When the service browser reports that it has discovered a service, the
17 | corresponding NSNetService is added to the array.
18 | When a service goes away, the corresponding NSNetService is removed from the
19 | array.
20 | Selecting an item in the table view asynchronously resolves the corresponding
21 | net service.
22 | When that resolution completes, the delegate is called with the corresponding
23 | NSNetService.
24 |
25 |
26 | Version: 1.5
27 |
28 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
29 | ("Apple") in consideration of your agreement to the following terms, and your
30 | use, installation, modification or redistribution of this Apple software
31 | constitutes acceptance of these terms. If you do not agree with these terms,
32 | please do not use, install, modify or redistribute this Apple software.
33 |
34 | In consideration of your agreement to abide by the following terms, and subject
35 | to these terms, Apple grants you a personal, non-exclusive license, under
36 | Apple's copyrights in this original Apple software (the "Apple Software"), to
37 | use, reproduce, modify and redistribute the Apple Software, with or without
38 | modifications, in source and/or binary forms; provided that if you redistribute
39 | the Apple Software in its entirety and without modifications, you must retain
40 | this notice and the following text and disclaimers in all such redistributions
41 | of the Apple Software.
42 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
43 | to endorse or promote products derived from the Apple Software without specific
44 | prior written permission from Apple. Except as expressly stated in this notice,
45 | no other rights or licenses, express or implied, are granted by Apple herein,
46 | including but not limited to any patent rights that may be infringed by your
47 | derivative works or by other works in which the Apple Software may be
48 | incorporated.
49 |
50 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
51 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
52 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
54 | COMBINATION WITH YOUR PRODUCTS.
55 |
56 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
57 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
58 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
60 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
61 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
62 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 |
64 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
65 |
66 | */
67 |
68 | #import
69 | #import
70 |
71 | @class BrowserViewController;
72 |
73 | @protocol BrowserViewControllerDelegate
74 | @required
75 | // This method will be invoked when the user selects one of the service instances from the list.
76 | // The ref parameter will be the selected (already resolved) instance or nil if the user taps the 'Cancel' button (if shown).
77 | - (void) browserViewController:(BrowserViewController*)bvc didResolveInstance:(NSNetService*)ref;
78 | @end
79 |
80 | @interface BrowserViewController : UITableViewController {
81 |
82 | @private
83 | id _delegate;
84 | NSString* _searchingForServicesString;
85 | NSString* _ownName;
86 | NSNetService* _ownEntry;
87 | BOOL _showDisclosureIndicators;
88 | NSMutableArray* _services;
89 | NSNetServiceBrowser* _netServiceBrowser;
90 | NSNetService* _currentResolve;
91 | NSTimer* _timer;
92 | BOOL _needsActivityIndicator;
93 | BOOL _initialWaitOver;
94 | UIImage *bonjourIcon;
95 | }
96 |
97 | @property (nonatomic, assign) id delegate;
98 | @property (nonatomic, copy) NSString* searchingForServicesString;
99 | @property (nonatomic, copy) NSString* ownName;
100 |
101 | - (id)initWithTitle:(NSString *)title showDisclosureIndicators:(BOOL)showDisclosureIndicators showCancelButton:(BOOL)showCancelButton;
102 | - (BOOL)searchForServicesOfType:(NSString *)type inDomain:(NSString *)domain;
103 | - (void)startDemoResolve;
104 |
105 | @end
106 |
--------------------------------------------------------------------------------
/RemotePad/BrowserViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // BroswerViewController.m
3 | // RemotePad
4 | //
5 | // Derived from an Apple's sample code BrowserViewController.m of WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/17.
7 | //
8 | /*
9 |
10 | File: BrowserViewController.m
11 | Abstract:
12 | View controller for the service instance list.
13 | This object manages a NSNetServiceBrowser configured to look for Bonjour
14 | services.
15 | It has an array of NSNetService objects that are displayed in a table view.
16 | When the service browser reports that it has discovered a service, the
17 | corresponding NSNetService is added to the array.
18 | When a service goes away, the corresponding NSNetService is removed from the
19 | array.
20 | Selecting an item in the table view asynchronously resolves the corresponding
21 | net service.
22 | When that resolution completes, the delegate is called with the corresponding
23 | NSNetService.
24 |
25 |
26 | Version: 1.5
27 |
28 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
29 | ("Apple") in consideration of your agreement to the following terms, and your
30 | use, installation, modification or redistribution of this Apple software
31 | constitutes acceptance of these terms. If you do not agree with these terms,
32 | please do not use, install, modify or redistribute this Apple software.
33 |
34 | In consideration of your agreement to abide by the following terms, and subject
35 | to these terms, Apple grants you a personal, non-exclusive license, under
36 | Apple's copyrights in this original Apple software (the "Apple Software"), to
37 | use, reproduce, modify and redistribute the Apple Software, with or without
38 | modifications, in source and/or binary forms; provided that if you redistribute
39 | the Apple Software in its entirety and without modifications, you must retain
40 | this notice and the following text and disclaimers in all such redistributions
41 | of the Apple Software.
42 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
43 | to endorse or promote products derived from the Apple Software without specific
44 | prior written permission from Apple. Except as expressly stated in this notice,
45 | no other rights or licenses, express or implied, are granted by Apple herein,
46 | including but not limited to any patent rights that may be infringed by your
47 | derivative works or by other works in which the Apple Software may be
48 | incorporated.
49 |
50 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
51 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
52 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
54 | COMBINATION WITH YOUR PRODUCTS.
55 |
56 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
57 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
58 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
60 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
61 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
62 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 |
64 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
65 |
66 | */
67 |
68 | #import "BrowserViewController.h"
69 |
70 | #define kProgressIndicatorSize 20.0
71 |
72 | // A category on NSNetService that's used to sort NSNetService objects by their name.
73 | @interface NSNetService (BrowserViewControllerAdditions)
74 | - (NSComparisonResult) localizedCaseInsensitiveCompareByName:(NSNetService*)aService;
75 | @end
76 |
77 | @implementation NSNetService (BrowserViewControllerAdditions)
78 | - (NSComparisonResult) localizedCaseInsensitiveCompareByName:(NSNetService*)aService {
79 | return [[self name] localizedCaseInsensitiveCompare:[aService name]];
80 | }
81 | @end
82 |
83 |
84 | @interface BrowserViewController()
85 | @property (nonatomic, retain, readwrite) NSNetService* ownEntry;
86 | @property (nonatomic, assign, readwrite) BOOL showDisclosureIndicators;
87 | @property (nonatomic, retain, readwrite) NSMutableArray* services;
88 | @property (nonatomic, retain, readwrite) NSNetServiceBrowser* netServiceBrowser;
89 | @property (nonatomic, retain, readwrite) NSNetService* currentResolve;
90 | @property (nonatomic, retain, readwrite) NSTimer* timer;
91 | @property (nonatomic, assign, readwrite) BOOL needsActivityIndicator;
92 | @property (nonatomic, assign, readwrite) BOOL initialWaitOver;
93 |
94 | - (void)stopCurrentResolve;
95 | - (void)initialWaitOver:(NSTimer*)timer;
96 | @end
97 |
98 | @implementation BrowserViewController
99 |
100 | @synthesize delegate = _delegate;
101 | @synthesize ownEntry = _ownEntry;
102 | @synthesize showDisclosureIndicators = _showDisclosureIndicators;
103 | @synthesize currentResolve = _currentResolve;
104 | @synthesize netServiceBrowser = _netServiceBrowser;
105 | @synthesize services = _services;
106 | @synthesize needsActivityIndicator = _needsActivityIndicator;
107 | @dynamic timer;
108 | @synthesize initialWaitOver = _initialWaitOver;
109 |
110 |
111 | - (id)initWithTitle:(NSString*)title showDisclosureIndicators:(BOOL)show showCancelButton:(BOOL)showCancelButton {
112 |
113 | if ((self = [super initWithStyle:UITableViewStylePlain])) {
114 | self.title = title;
115 | _services = [[NSMutableArray alloc] init];
116 | self.showDisclosureIndicators = show;
117 |
118 | if (showCancelButton) {
119 | // add Cancel button as the nav bar's custom right view
120 | UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
121 | initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAction)];
122 | self.navigationItem.rightBarButtonItem = addButton;
123 | [addButton release];
124 | }
125 |
126 | self.searchingForServicesString = @"Searching for servers...";
127 | bonjourIcon = [[UIImage imageNamed:@"Bonjour.png"] retain];
128 |
129 | // Make sure we have a chance to discover devices before showing the user that nothing was found (yet)
130 | [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(initialWaitOver:) userInfo:nil repeats:NO];
131 | }
132 |
133 | return self;
134 | }
135 |
136 | - (NSString *)searchingForServicesString {
137 | return _searchingForServicesString;
138 | }
139 |
140 | // Holds the string that's displayed in the table view during service discovery.
141 | - (void)setSearchingForServicesString:(NSString *)searchingForServicesString {
142 | if (_searchingForServicesString != searchingForServicesString) {
143 | [_searchingForServicesString release];
144 | _searchingForServicesString = [searchingForServicesString copy];
145 |
146 | // If there are no services, reload the table to ensure that searchingForServicesString appears.
147 | if ([self.services count] == 0) {
148 | [self.tableView reloadData];
149 | }
150 | }
151 | }
152 |
153 | - (NSString *)ownName {
154 | return _ownName;
155 | }
156 |
157 | // Holds the string that's displayed in the table view during service discovery.
158 | - (void)setOwnName:(NSString *)name {
159 | if (_ownName != name) {
160 | _ownName = [name copy];
161 |
162 | if (self.ownEntry)
163 | [self.services addObject:self.ownEntry];
164 |
165 | NSNetService* service;
166 |
167 | for (service in self.services) {
168 | if ([service.name isEqual:name]) {
169 | self.ownEntry = service;
170 | [_services removeObject:service];
171 | break;
172 | }
173 | }
174 |
175 | [self.tableView reloadData];
176 | }
177 | }
178 |
179 | // Creates an NSNetServiceBrowser that searches for services of a particular type in a particular domain.
180 | // If a service is currently being resolved, stop resolving it and stop the service browser from
181 | // discovering other services.
182 | - (BOOL)searchForServicesOfType:(NSString *)type inDomain:(NSString *)domain {
183 |
184 | [self stopCurrentResolve];
185 | [self.netServiceBrowser stop];
186 | [self.services removeAllObjects];
187 |
188 | NSNetServiceBrowser *aNetServiceBrowser = [[NSNetServiceBrowser alloc] init];
189 | if(!aNetServiceBrowser) {
190 | // The NSNetServiceBrowser couldn't be allocated and initialized.
191 | return NO;
192 | }
193 |
194 | aNetServiceBrowser.delegate = self;
195 | self.netServiceBrowser = aNetServiceBrowser;
196 | [aNetServiceBrowser release];
197 | [self.netServiceBrowser searchForServicesOfType:type inDomain:domain];
198 |
199 | [self.tableView reloadData];
200 | return YES;
201 | }
202 |
203 |
204 | - (NSTimer *)timer {
205 | return _timer;
206 | }
207 |
208 | // When this is called, invalidate the existing timer before releasing it.
209 | - (void)setTimer:(NSTimer *)newTimer {
210 | [_timer invalidate];
211 | [newTimer retain];
212 | [_timer release];
213 | _timer = newTimer;
214 | }
215 |
216 |
217 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
218 | return 1;
219 | }
220 |
221 |
222 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
223 | // If there are no services and searchingForServicesString is set, show one row to tell the user.
224 | NSUInteger count = [self.services count];
225 | if (count == 0 && self.searchingForServicesString && self.initialWaitOver)
226 | return 1;
227 |
228 | return count;
229 | }
230 |
231 |
232 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
233 |
234 | static NSString *tableCellIdentifier = @"UITableViewCell";
235 | UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:tableCellIdentifier];
236 | if (cell == nil) {
237 | cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:tableCellIdentifier] autorelease];
238 | }
239 |
240 | cell.image = bonjourIcon;
241 |
242 | NSUInteger count = [self.services count];
243 | if (count == 0 && self.searchingForServicesString) {
244 | // If there are no services and searchingForServicesString is set, show one row explaining that to the user.
245 | cell.text = self.searchingForServicesString;
246 | cell.textColor = [UIColor colorWithWhite:0.5 alpha:0.5];
247 | cell.accessoryType = UITableViewCellAccessoryNone;
248 | return cell;
249 | }
250 |
251 | // Set up the text for the cell
252 | NSNetService* service = [self.services objectAtIndex:indexPath.row];
253 | cell.text = [service name];
254 | cell.textColor = [UIColor blackColor];
255 | cell.accessoryType = self.showDisclosureIndicators ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
256 |
257 | // Note that the underlying array could have changed, and we want to show the activity indicator on the correct cell
258 | if (self.needsActivityIndicator && self.currentResolve == service) {
259 | if (!cell.accessoryView) {
260 | CGRect frame = CGRectMake(0.0, 0.0, kProgressIndicatorSize, kProgressIndicatorSize);
261 | UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithFrame:frame];
262 | [spinner startAnimating];
263 | spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
264 | [spinner sizeToFit];
265 | spinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
266 | UIViewAutoresizingFlexibleRightMargin |
267 | UIViewAutoresizingFlexibleTopMargin |
268 | UIViewAutoresizingFlexibleBottomMargin);
269 | cell.accessoryView = spinner;
270 | [spinner release];
271 | }
272 | } else if (cell.accessoryView) {
273 | cell.accessoryView = nil;
274 | }
275 |
276 | return cell;
277 | }
278 |
279 |
280 | - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
281 | // Ignore the selection if there are no services.
282 | if ([self.services count] == 0)
283 | return nil;
284 |
285 | return indexPath;
286 | }
287 |
288 |
289 | - (void)stopCurrentResolve {
290 |
291 | self.needsActivityIndicator = NO;
292 | self.timer = nil;
293 |
294 | [self.currentResolve stop];
295 | self.currentResolve = nil;
296 | }
297 |
298 |
299 | - (void)startDemoResolve {
300 | if (self.ownEntry == nil)
301 | return;
302 | [self stopCurrentResolve];
303 | self.currentResolve = self.ownEntry;
304 | [self.currentResolve setDelegate:self];
305 | [self.currentResolve resolveWithTimeout:0.0];
306 | }
307 |
308 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
309 | // If another resolve was running, stop it first
310 |
311 | [self stopCurrentResolve];
312 | self.currentResolve = [self.services objectAtIndex:indexPath.row];
313 |
314 | [self.currentResolve setDelegate:self];
315 | // Attempt to resolve the service. A value of 0.0 sets an unlimited time to resolve it. The user can
316 | // choose to cancel the resolve by selecting another service in the table view.
317 | [self.currentResolve resolveWithTimeout:0.0];
318 |
319 | // Make sure we give the user some feedback that the resolve is happening.
320 | // We will be called back asynchronously, so we don't want the user to think
321 | // we're just stuck.
322 | self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showWaiting:) userInfo:self.currentResolve repeats:NO];
323 | [self.tableView reloadData];
324 | }
325 |
326 | // If necessary, sets up state to show an activity indicator to let the user know that a resolve is occuring.
327 | - (void)showWaiting:(NSTimer*)timer {
328 |
329 | if (timer == self.timer) {
330 | [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
331 | NSNetService* service = (NSNetService*)[self.timer userInfo];
332 | if (self.currentResolve == service) {
333 | self.needsActivityIndicator = YES;
334 | [self.tableView reloadData];
335 | }
336 | }
337 | }
338 |
339 |
340 | - (void)initialWaitOver:(NSTimer*)timer {
341 | self.initialWaitOver= YES;
342 | if (![self.services count])
343 | [self.tableView reloadData];
344 | }
345 |
346 |
347 | - (void)sortAndUpdateUI {
348 | // Sort the services by name.
349 | [self.services sortUsingSelector:@selector(localizedCaseInsensitiveCompareByName:)];
350 | [self.tableView reloadData];
351 | }
352 |
353 |
354 | - (void)netServiceBrowser:(NSNetServiceBrowser*)netServiceBrowser didRemoveService:(NSNetService*)service moreComing:(BOOL)moreComing {
355 | // If a service went away, stop resolving it if it's currently being resolve,
356 | // remove it from the list and update the table view if no more events are queued.
357 |
358 | if (self.currentResolve && [service isEqual:self.currentResolve]) {
359 | [self stopCurrentResolve];
360 | }
361 | [self.services removeObject:service];
362 | if (self.ownEntry == service)
363 | self.ownEntry = nil;
364 |
365 | // If moreComing is NO, it means that there are no more messages in the queue from the Bonjour daemon, so we should update the UI.
366 | // When moreComing is set, we don't update the UI so that it doesn't 'flash'.
367 | if (!moreComing) {
368 | [self sortAndUpdateUI];
369 | }
370 | }
371 |
372 |
373 | - (void)netServiceBrowser:(NSNetServiceBrowser*)netServiceBrowser didFindService:(NSNetService*)service moreComing:(BOOL)moreComing {
374 | // If a service came online, add it to the list and update the table view if no more events are queued.
375 | if ([service.name isEqual:self.ownName])
376 | self.ownEntry = service;
377 | else
378 | [self.services addObject:service];
379 |
380 | // If moreComing is NO, it means that there are no more messages in the queue from the Bonjour daemon, so we should update the UI.
381 | // When moreComing is set, we don't update the UI so that it doesn't 'flash'.
382 | if (!moreComing) {
383 | [self sortAndUpdateUI];
384 | }
385 | }
386 |
387 |
388 | // This should never be called, since we resolve with a timeout of 0.0, which means indefinite
389 | - (void)netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict {
390 | [self stopCurrentResolve];
391 | [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
392 | [self.tableView reloadData];
393 | }
394 |
395 |
396 | - (void)netServiceDidResolveAddress:(NSNetService *)service {
397 | assert(service == self.currentResolve);
398 |
399 | [service retain];
400 | [self stopCurrentResolve];
401 | [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
402 |
403 | [self.delegate browserViewController:self didResolveInstance:service];
404 | [service release];
405 | }
406 |
407 |
408 | - (void)cancelAction {
409 | [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
410 | [self.delegate browserViewController:self didResolveInstance:nil];
411 | }
412 |
413 |
414 | - (void)dealloc {
415 | // Cleanup any running resolve and free memory
416 | [self stopCurrentResolve];
417 | self.services = nil;
418 | [self.netServiceBrowser stop];
419 | self.netServiceBrowser = nil;
420 | [_searchingForServicesString release];
421 | [_ownName release];
422 | [_ownEntry release];
423 |
424 | [super dealloc];
425 | }
426 |
427 |
428 | @end
429 |
--------------------------------------------------------------------------------
/RemotePad/ButtonBack.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/ButtonBack.png
--------------------------------------------------------------------------------
/RemotePad/ButtonCenter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/ButtonCenter.png
--------------------------------------------------------------------------------
/RemotePad/ButtonCenterHighlighted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/ButtonCenterHighlighted.png
--------------------------------------------------------------------------------
/RemotePad/ButtonLeft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/ButtonLeft.png
--------------------------------------------------------------------------------
/RemotePad/ButtonLeftHighlighted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/ButtonLeftHighlighted.png
--------------------------------------------------------------------------------
/RemotePad/ButtonRight.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/ButtonRight.png
--------------------------------------------------------------------------------
/RemotePad/ButtonRightHighlighted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/ButtonRightHighlighted.png
--------------------------------------------------------------------------------
/RemotePad/ButtonRounded.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/ButtonRounded.png
--------------------------------------------------------------------------------
/RemotePad/ButtonRounded.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/ButtonRounded.xcf
--------------------------------------------------------------------------------
/RemotePad/ButtonRoundedHighlighted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/ButtonRoundedHighlighted.png
--------------------------------------------------------------------------------
/RemotePad/Constants.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Constants.h
3 | * RemotePad
4 | *
5 | * Created by iKawamoto Yosihisa! on 08/09/04.
6 | * Copyright 2008, 2009 tenjin.org. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 |
31 | #import "Version.h"
32 |
33 | // application defaults keys
34 | #define kDefaultKeyVersion @"version"
35 | #define kDefaultKeyTopviewLocationX @"topviewLocationX"
36 | #define kDefaultKeyTopviewLocationY @"topviewLocationY"
37 | #define kDefaultKeyTopviewRelocationGesture @"topviewRelocationGesture"
38 | #define kDefaultKeyNumberOfButtons @"numberOfButtons"
39 | #define kDefaultKeyMouseMapLeftToRight @"leftPrimaryButton"
40 | #define kDefaultKeyNumberArrowKeyGesture @"numberArrowKeyGesture"
41 | #define kDefaultKeyArrowKeyGestureOneKey @"arrowKeyGestureOneKey"
42 | #define kDefaultKeyTwoFingersScroll @"twoFingerScroll"
43 | #define kDefaultKeyAllowHorizontalScroll @"horizontalScroll"
44 | #define kDefaultKeyClickByTap @"clickByTap"
45 | #define kDefaultKeyDragByTap @"dragByTap"
46 | #define kDefaultKeyDragByTapLock @"dragByTapLock"
47 | #define kDefaultKeyNumberToggleStatusbar @"numberToggleStatusbar"
48 | #define kDefaultKeyNumberToggleToolbars @"numberToggleToolbars"
49 | #define kDefaultKeyScrollWithMouse3 @"scrollWithMouse3"
50 | #define kDefaultKeyEnableAccelMouse @"enableAccelMouse"
51 | #define kDefaultKeyServerName @"serverName"
52 | #define kDefaultKeyTapViewOrientation @"tapviewOrientation"
53 | #define kDefaultKeyAutorotateOrientation @"autorotateOrientation"
54 | #define kDefaultKeyTwoFingersSecondary @"twoFingersSecondary"
55 | #define kDefaultKeyProhibitSleeping @"prohibitSleeping"
56 | #define kDefaultKeyTrackingSpeed @"trackingSpeed"
57 | #define kDefaultKeyScrollingSpeed @"scrollingSpeed"
58 | #define kDefaultKeyDoneInsecureKeyboardWarning @"doneInsecureKeyboardWarning"
59 | #define kDefaultKeyDoLabelsForMouseButtons @"doLabelsForMouseButtons"
60 | // application defaults values
61 | #define kDefaultVersion kVersionRemotePad
62 | #define kDefaultTopviewLocationX @"0"
63 | #define kDefaultTopviewLocationY @"20"
64 | #define kDefaultTopviewRelocationGesture @"YES"
65 | #define kDefaultNumberOfButtons @"3"
66 | #define kDefaultMouseMapLeftToRight @"YES"
67 | #define kDefaultNumberArrowKeyGesture @"0"
68 | #define kDefaultArrowKeyGestureOneKey @"NO"
69 | #define kDefaultTwoFingersScroll @"YES"
70 | #define kDefaultAllowHorizontalScroll @"YES"
71 | #define kDefaultClickByTap @"NO"
72 | #define kDefaultDragByTap @"YES"
73 | #define kDefaultDragByTapLock @"YES"
74 | #define kDefaultNumberToggleStatusbar @"1"
75 | #define kDefaultNumberToggleToolbars @"3"
76 | #define kDefaultScrollWithMouse3 @"NO"
77 | #define kDefaultEnableAccelMouse @"NO"
78 | #define kDefaultServerName @""
79 | #define kDefaultTapViewOrientation @"1"
80 | #define kDefaultAutorotateOrientation @"YES"
81 | #define kDefaultTwoFingersSecondary @"YES"
82 | #define kDefaultProhibitSleeping @"NO"
83 | #define kDefaultTrackingSpeed @"0"
84 | #define kDefaultScrollingSpeed @"0"
85 | #define kDefaultDoneInsecureKeyboardWarning @"NO"
86 | #define kDefaultDoLabelsForMouseButtons @"YES"
87 |
88 | // Bonjour constants
89 |
90 | // The Bonjour application protocol, which must:
91 | // 1) be no longer than 14 characters
92 | // 2) contain only lower-case letters, digits, and hyphens
93 | // 3) begin and end with lower-case letter or digit
94 | // It should also be descriptive and human-readable
95 | // See the following for more information:
96 | // http://developer.apple.com/networking/bonjour/faq.html
97 | #define kBonjourIdentifier @"remotepad"
98 | #define kDefaultPort 5583
99 |
100 |
101 | // Accelerometer constants
102 |
103 | // Constant for the number of times per second (Hertz) to sample acceleration.
104 | #define kAccelerometerFrequency 40
105 | // Constant for the high-pass filter.
106 | #define kFilteringFactor 0.1
107 | // misc
108 | #define kVerticalAccelerationFactor 12.0
109 | #define kHorizontalAccelerationFactor 8.0
110 | #define kAccelerationStabilityFactor 0.9
111 | #define kAccelerationReleaseFactor 0.8
112 | #define kAccelerationSmoothFactor 0.95
113 |
114 | // picker view constants
115 |
116 | #define kStatusBarHeight 20.0
117 | #define kOffset 5.0
118 |
119 |
120 | // tap view constants
121 |
122 | #define kOffsetDragBegins 50
123 | #define kButtonHeight 100
124 | #define kTapHoldInterval 0.3
125 | #define kOffsetMultiTapDrift 4
126 |
127 | // setup view constants
128 |
129 | // padding for margins
130 | #define kLeftMargin 20.0
131 | #define kTopMargin 20.0
132 | #define kRightMargin 20.0
133 | #define kBottomMargin 20.0
134 | #define kTweenMargin 10.0
135 |
136 | // control dimensions
137 | #define kSegmentedControlWidth 96.0
138 | #define kSegmentedControlWidthLong 280.0
139 | #define kSegmentedControlHeight 30.0
140 | #define kSwitchWidth 90.0
141 | #define kSwitchHeight 27.0
142 | #define kLabelHeight 20.0
143 | #define kToggleButtonItemWidth 90.0
144 | #define kSliderWidth 120.0
145 | #define kSliderHeight 30.0
146 |
147 | // keyboard constants
148 | #define kToggleKeyboardItemWidth 120.0
149 | #define kStatusKeyboardOffsetLand 160.0
150 | #define kStatusKeyboardOffsetPort 215.0
151 |
152 | // table row dimensions
153 | #define kUIRowSegmentHeight 40.0
154 | #define kUIRowSwitchHeight 40.0
155 | #define kUIRowButtonHeight 40.0
156 | #define kUIRowCommentHeight 20.0
157 | #define kUIRowLabelHeight 40.0
158 | #define kUIRowSliderHeight 40.0
159 |
160 | // view tag
161 | #define kTrackingSpeedTag 1
162 | #define kScrollingSpeedTag 2
163 | #define kDisconnectSessionTag 3
164 | #define kResetSecurityWarningsTag 4
165 |
166 | // slider steps
167 | #define kTrackingSpeedSteps 10
168 | #define kScrollingSpeedSteps 10
169 |
170 | // messages
171 | #define kInsecureKeyboardMessage @"This connection is not encrypted because this version of RemotePad does not support any encryption methods.\nBe sure not to enter private information like passwords, credit card numbers, or your secrets."
172 |
173 | // topview locations
174 | #define kTopviewLocationTop1 20
175 | #define kTopviewLocationTop2 0
176 | #define kTopviewLocationBottom1 -45
177 | #define kTopviewLocationBottom2 -1
178 |
--------------------------------------------------------------------------------
/RemotePad/Default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/Default.png
--------------------------------------------------------------------------------
/RemotePad/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIconFile
12 | icon.png
13 | CFBundleIdentifier
14 | com.yourcompany.${PRODUCT_NAME:identifier}
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | ${PRODUCT_NAME}
19 | CFBundlePackageType
20 | APPL
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1.5
25 | UIStatusBarHidden
26 |
27 | LSRequiresIPhoneOS
28 |
29 | UIRequiresPersistentWiFi
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/RemotePad/Picker.h:
--------------------------------------------------------------------------------
1 | //
2 | // Picker.h
3 | // RemotePad
4 | //
5 | // Derived from an Apple's sample code Picker.h of WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/17.
7 | //
8 | /*
9 |
10 | File: Picker.h
11 | Abstract:
12 | A view that displays both the currently advertised game name and a list of
13 | other games
14 | available on the local network (discovered & displayed by
15 | BrowserViewController).
16 |
17 |
18 | Version: 1.5
19 |
20 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
21 | ("Apple") in consideration of your agreement to the following terms, and your
22 | use, installation, modification or redistribution of this Apple software
23 | constitutes acceptance of these terms. If you do not agree with these terms,
24 | please do not use, install, modify or redistribute this Apple software.
25 |
26 | In consideration of your agreement to abide by the following terms, and subject
27 | to these terms, Apple grants you a personal, non-exclusive license, under
28 | Apple's copyrights in this original Apple software (the "Apple Software"), to
29 | use, reproduce, modify and redistribute the Apple Software, with or without
30 | modifications, in source and/or binary forms; provided that if you redistribute
31 | the Apple Software in its entirety and without modifications, you must retain
32 | this notice and the following text and disclaimers in all such redistributions
33 | of the Apple Software.
34 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
35 | to endorse or promote products derived from the Apple Software without specific
36 | prior written permission from Apple. Except as expressly stated in this notice,
37 | no other rights or licenses, express or implied, are granted by Apple herein,
38 | including but not limited to any patent rights that may be infringed by your
39 | derivative works or by other works in which the Apple Software may be
40 | incorporated.
41 |
42 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
43 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
44 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
46 | COMBINATION WITH YOUR PRODUCTS.
47 |
48 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
49 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
50 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
52 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
53 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
54 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 |
56 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
57 |
58 | */
59 |
60 | #import
61 | #import "BrowserViewController.h"
62 | #import "TCPServer.h"
63 | #import "Event.h"
64 |
65 | @interface Picker : UIView {
66 |
67 | @private
68 | UIButton *_gameNameLabel;
69 | BrowserViewController* _bvc;
70 | UILabel *messageLabel;
71 | NSTimer *gameNameLabelTimer;
72 | }
73 |
74 | @property (nonatomic, assign) id delegate;
75 | @property (nonatomic, copy) NSString* gameName;
76 |
77 | - (id)initWithFrame:(CGRect)frame type:(NSString *)type;
78 | - (void)setMessage:(NSString *)message;
79 |
80 | @end
81 |
--------------------------------------------------------------------------------
/RemotePad/Picker.m:
--------------------------------------------------------------------------------
1 | //
2 | // Picker.m
3 | // RemotePad
4 | //
5 | // Derived from an Apple's sample code Picker.m of WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/17.
7 | //
8 | /*
9 |
10 | File: Picker.m
11 | Abstract:
12 | A view that displays both the currently advertised game name and a list of
13 | other games
14 | available on the local network (discovered & displayed by
15 | BrowserViewController).
16 |
17 |
18 | Version: 1.5
19 |
20 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
21 | ("Apple") in consideration of your agreement to the following terms, and your
22 | use, installation, modification or redistribution of this Apple software
23 | constitutes acceptance of these terms. If you do not agree with these terms,
24 | please do not use, install, modify or redistribute this Apple software.
25 |
26 | In consideration of your agreement to abide by the following terms, and subject
27 | to these terms, Apple grants you a personal, non-exclusive license, under
28 | Apple's copyrights in this original Apple software (the "Apple Software"), to
29 | use, reproduce, modify and redistribute the Apple Software, with or without
30 | modifications, in source and/or binary forms; provided that if you redistribute
31 | the Apple Software in its entirety and without modifications, you must retain
32 | this notice and the following text and disclaimers in all such redistributions
33 | of the Apple Software.
34 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
35 | to endorse or promote products derived from the Apple Software without specific
36 | prior written permission from Apple. Except as expressly stated in this notice,
37 | no other rights or licenses, express or implied, are granted by Apple herein,
38 | including but not limited to any patent rights that may be infringed by your
39 | derivative works or by other works in which the Apple Software may be
40 | incorporated.
41 |
42 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
43 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
44 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
46 | COMBINATION WITH YOUR PRODUCTS.
47 |
48 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
49 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
50 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
52 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
53 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
54 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 |
56 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
57 |
58 | */
59 |
60 | #import "Picker.h"
61 | #import "AppController.h"
62 | #import "Constants.h"
63 |
64 | @interface Picker ()
65 | @property (nonatomic, retain, readwrite) BrowserViewController* bvc;
66 | @property (nonatomic, retain, readwrite) UIButton *gameNameLabel;
67 | @end
68 |
69 | @implementation Picker
70 |
71 | @synthesize bvc = _bvc;
72 | @synthesize gameNameLabel = _gameNameLabel;
73 |
74 | - (id)initWithFrame:(CGRect)frame type:(NSString*)type {
75 | if ((self = [super initWithFrame:frame])) {
76 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
77 | if (![defaults stringForKey:kDefaultKeyServerName]) {
78 | [defaults registerDefaults:[NSDictionary dictionaryWithObject:kDefaultServerName forKey:kDefaultKeyServerName]];
79 | }
80 | if ([defaults boolForKey:kDefaultKeyProhibitSleeping]) {
81 | [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
82 | }
83 | CGFloat runningY = kStatusBarHeight;
84 | self.bvc = [[BrowserViewController alloc] initWithTitle:nil showDisclosureIndicators:NO showCancelButton:NO];
85 | [self.bvc searchForServicesOfType:type inDomain:@"local"];
86 |
87 | self.opaque = YES;
88 | self.backgroundColor = [UIColor blackColor];
89 |
90 | UIImageView* img = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"bg.png"] stretchableImageWithLeftCapWidth:1.0 topCapHeight:25.0]];
91 | [self addSubview:img];
92 |
93 | runningY += kOffset;
94 | CGFloat width = self.bounds.size.width - 2 * kOffset;
95 |
96 | UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
97 | [label setTextAlignment:UITextAlignmentCenter];
98 | [label setFont:[UIFont boldSystemFontOfSize:15.0]];
99 | [label setTextColor:[UIColor whiteColor]];
100 | [label setShadowColor:[UIColor colorWithWhite:0.0 alpha:0.75]];
101 | [label setShadowOffset:CGSizeMake(1,1)];
102 | [label setBackgroundColor:[UIColor clearColor]];
103 | label.text = @"My name:";
104 | label.numberOfLines = 1;
105 | [label sizeToFit];
106 | label.frame = CGRectMake(kOffset, runningY, width, label.frame.size.height);
107 | [self addSubview:label];
108 |
109 | runningY += label.bounds.size.height;
110 | [label release];
111 |
112 | self.gameNameLabel = [UIButton buttonWithType:UIButtonTypeCustom];
113 | [self.gameNameLabel setFont:[UIFont boldSystemFontOfSize:24.0]];
114 | [self.gameNameLabel setLineBreakMode:UILineBreakModeTailTruncation];
115 | [self.gameNameLabel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
116 | [self.gameNameLabel setTitleShadowColor:[UIColor colorWithWhite:0.0 alpha:0.75] forState:UIControlStateNormal];
117 | [self.gameNameLabel setTitleShadowOffset:CGSizeMake(1,1)];
118 | [self.gameNameLabel setTitle:@"Default Name" forState:UIControlStateNormal];
119 | [self.gameNameLabel sizeToFit];
120 | [self.gameNameLabel setFrame:CGRectMake(kOffset, runningY, width, self.gameNameLabel.frame.size.height)];
121 | [self.gameNameLabel setTitle:@"" forState:UIControlStateNormal];
122 | [self.gameNameLabel addTarget:self action:@selector(startDemoModeWithDelay) forControlEvents:UIControlEventTouchDown];
123 | [self.gameNameLabel addTarget:self action:@selector(cancelDemoMode) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside|UIControlEventTouchCancel|UIControlEventTouchDragExit];
124 | [self addSubview:self.gameNameLabel];
125 |
126 | runningY += self.gameNameLabel.bounds.size.height + kOffset * 2;
127 |
128 | label = [[UILabel alloc] initWithFrame:CGRectZero];
129 | messageLabel = [label retain];
130 | [label setTextAlignment:UITextAlignmentCenter];
131 | [label setFont:[UIFont boldSystemFontOfSize:15.0]];
132 | [label setTextColor:[UIColor whiteColor]];
133 | [label setShadowColor:[UIColor colorWithWhite:0.0 alpha:0.75]];
134 | [label setShadowOffset:CGSizeMake(1,1)];
135 | [label setBackgroundColor:[UIColor clearColor]];
136 | [self setMessage:@""];
137 | [label sizeToFit];
138 | label.frame = CGRectMake(kOffset, runningY, width, label.frame.size.height);
139 | [self addSubview:label];
140 |
141 | runningY += label.bounds.size.height + 2;
142 | [label release];
143 |
144 | UITextField *serverName = [[UITextField alloc] initWithFrame:CGRectZero];
145 | [serverName setDelegate:self];
146 | [serverName setAutocorrectionType:UITextAutocorrectionTypeNo];
147 | [serverName setClearButtonMode:UITextFieldViewModeWhileEditing];
148 | [serverName setClearsOnBeginEditing:NO];
149 | [serverName setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
150 | [serverName setReturnKeyType:UIReturnKeyGo];
151 | [serverName setTextAlignment:UITextAlignmentCenter];
152 | [serverName setFont:[UIFont boldSystemFontOfSize:24.0]];
153 | [serverName setBorderStyle:UITextBorderStyleRoundedRect];
154 | [serverName setPlaceholder:@""];
155 | [serverName setText:[defaults stringForKey:kDefaultKeyServerName]];
156 | [serverName sizeToFit];
157 | serverName.frame = CGRectMake(kOffset, runningY, width, serverName.frame.size.height);
158 | [self addSubview:serverName];
159 |
160 | runningY += serverName.bounds.size.height + kOffset * 2;
161 | [serverName release];
162 |
163 | label = [[UILabel alloc] initWithFrame:CGRectZero];
164 | [label setTextAlignment:UITextAlignmentCenter];
165 | [label setFont:[UIFont boldSystemFontOfSize:15.0]];
166 | [label setTextColor:[UIColor whiteColor]];
167 | [label setShadowColor:[UIColor colorWithWhite:0.0 alpha:0.75]];
168 | [label setShadowOffset:CGSizeMake(1,1)];
169 | [label setBackgroundColor:[UIColor clearColor]];
170 | label.text = @"Or, select RemotePad servers:";
171 | [label sizeToFit];
172 | label.frame = CGRectMake(kOffset, runningY, width, label.frame.size.height);
173 | [self addSubview:label];
174 |
175 | runningY += label.bounds.size.height + 2;
176 | [label release];
177 |
178 | [img setFrame:CGRectMake(0, kStatusBarHeight, self.bounds.size.width, runningY)];
179 | [img release];
180 |
181 | [self.bvc.view setFrame:CGRectMake(0, runningY, self.bounds.size.width, self.bounds.size.height - runningY)];
182 | [self addSubview:self.bvc.view];
183 |
184 | }
185 | [gameNameLabelTimer invalidate];
186 | gameNameLabelTimer = nil;
187 |
188 | return self;
189 | }
190 |
191 |
192 | - (void)dealloc {
193 | // Cleanup any running resolve and free memory
194 | [self.bvc release];
195 | [self.gameNameLabel release];
196 | [messageLabel release];
197 |
198 | [super dealloc];
199 | }
200 |
201 |
202 | - (id)delegate {
203 | return self.bvc.delegate;
204 | }
205 |
206 |
207 | - (void)setDelegate:(id)delegate {
208 | [self.bvc setDelegate:delegate];
209 | }
210 |
211 | - (NSString *)gameName {
212 | return [self.gameNameLabel titleForState:UIControlStateNormal];
213 | }
214 |
215 | - (void)setGameName:(NSString *)string {
216 | [self.gameNameLabel setTitle:string forState:UIControlStateNormal];
217 | [self.bvc setOwnName:string];
218 | }
219 |
220 |
221 | - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
222 | NSString *serverString = [[textField text] stringByReplacingCharactersInRange:range withString:string];
223 | [[NSUserDefaults standardUserDefaults] setObject:serverString forKey:kDefaultKeyServerName];
224 | return YES;
225 | }
226 |
227 | - (BOOL)textFieldShouldClear:(UITextField *)textField {
228 | [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:kDefaultKeyServerName];
229 | return YES;
230 | }
231 |
232 | - (BOOL)textFieldShouldReturn:(UITextField *)textField {
233 | [textField resignFirstResponder];
234 | return YES;
235 | }
236 |
237 | - (void)textFieldDidEndEditing:(UITextField *)textField {
238 | NSMutableString *serverString = [NSMutableString stringWithString:[textField text]];
239 | if ([serverString replaceOccurrencesOfString:@" " withString:@"" options:0 range:NSMakeRange(0, [serverString length])]) {
240 | [[NSUserDefaults standardUserDefaults] setObject:serverString forKey:kDefaultKeyServerName];
241 | [textField setText:serverString];
242 | }
243 | if ([serverString length] == 0) {
244 | [self setMessage:@""];
245 | return;
246 | }
247 | NSRange separator = [serverString rangeOfString:@":" options:NSBackwardsSearch];
248 | NSInteger port;
249 | NSString *hostname;
250 | if (separator.location != NSNotFound) {
251 | hostname = [serverString substringToIndex:separator.location];
252 | port = [[serverString substringFromIndex:separator.location + separator.length] integerValue];
253 | if (port <= 0 || 65536 <= port) {
254 | [self setMessage:@"Invalid port number:"];
255 | return;
256 | }
257 | } else {
258 | hostname = serverString;
259 | port = kDefaultPort;
260 | }
261 | NSHost *host = [NSHost hostWithAddress:hostname];
262 | if (host == nil) {
263 | host = [NSHost hostWithName:hostname];
264 | if (host == nil) {
265 | [self setMessage:@"Invalid IP address or hostname:"];
266 | return;
267 | }
268 | }
269 | NSInputStream *inputStream;
270 | NSOutputStream *outputStream;
271 | [NSStream getStreamsToHost:host port:port inputStream:&inputStream outputStream:&outputStream];
272 | if (inputStream == nil || outputStream == nil) {
273 | [self setMessage:@"Cannot connect:"];
274 | } else {
275 | [self setMessage:@""];
276 | [(AppController *)[UIApplication sharedApplication].delegate setInputStream:inputStream outputStream:outputStream];
277 | }
278 | }
279 |
280 |
281 | - (void)setMessage:(NSString *)message {
282 | if (!message || [message isEqual:@""]) {
283 | [messageLabel setTextColor:[UIColor whiteColor]];
284 | [messageLabel setText:@"Enter server IP address or Hostname:"];
285 | } else {
286 | [messageLabel setTextColor:[UIColor redColor]];
287 | [messageLabel setText:message];
288 | }
289 | }
290 |
291 |
292 | - (void)startDemoModeWithDelay {
293 | [gameNameLabelTimer invalidate];
294 | gameNameLabelTimer = [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(startDemoMode:) userInfo:nil repeats:NO];
295 | }
296 |
297 | - (void)cancelDemoMode {
298 | [gameNameLabelTimer invalidate];
299 | gameNameLabelTimer = nil;
300 | }
301 |
302 | - (void)startDemoMode:(NSTimer*)theTimer {
303 | UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Demo start?" message:@"Do you want to start demo mode?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Start", nil];
304 | [alertView show];
305 | [alertView release];
306 | gameNameLabelTimer = nil;
307 | }
308 |
309 | - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
310 | if (buttonIndex == 1)
311 | [self.bvc startDemoResolve];
312 | }
313 |
314 | @end
315 |
--------------------------------------------------------------------------------
/RemotePad/PickerViewController.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PickerViewController.h
3 | * RemotePad
4 | *
5 | * Created by iKawamoto Yosihisa! on 08/09/05.
6 | * Copyright 2008, 2009 tenjin.org. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #import
31 |
32 |
33 | @interface PickerViewController : UIViewController {
34 |
35 | }
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/RemotePad/PickerViewController.m:
--------------------------------------------------------------------------------
1 | /*
2 | * PickerViewController.m
3 | * RemotePad
4 | *
5 | * Created by iKawamoto Yosihisa! on 08/09/05.
6 | * Copyright 2008, 2009 tenjin.org. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #import "AppController.h"
31 | #import "PickerViewController.h"
32 | #import "Picker.h"
33 | #import "TCPServer.h"
34 | #import "Constants.h"
35 |
36 | @implementation PickerViewController
37 |
38 | - (void)loadView {
39 | Picker *picker = [[Picker alloc] initWithFrame:[[UIScreen mainScreen] bounds] type:[TCPServer bonjourTypeFromIdentifier:kBonjourIdentifier]];
40 | picker.delegate = (AppController *)[UIApplication sharedApplication].delegate;
41 | self.view = picker;
42 | }
43 |
44 | /*
45 | If you need to do additional setup after loading the view, override viewDidLoad.
46 | - (void)viewDidLoad {
47 | }
48 | */
49 |
50 |
51 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
52 | // Return YES for supported orientations
53 | return (interfaceOrientation == UIInterfaceOrientationPortrait);
54 | }
55 |
56 |
57 | - (void)didReceiveMemoryWarning {
58 | [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
59 | // Release anything that's not essential, such as cached data
60 | }
61 |
62 |
63 | - (void)dealloc {
64 | [self.view release];
65 | [super dealloc];
66 | }
67 |
68 |
69 | @end
70 |
--------------------------------------------------------------------------------
/RemotePad/RemotePad_Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'RemotePad' target in the 'RemotePad' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #import
8 | #endif
9 |
--------------------------------------------------------------------------------
/RemotePad/SetupViewController.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SetupViewController.h
3 | * RemotePad
4 | *
5 | * Created by iKawamoto Yosihisa! on 08/08/27.
6 | * Copyright 2008, 2009 tenjin.org. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #import
31 | #import "AppController.h"
32 | #import "TapView.h"
33 |
34 | @interface SetupViewController : UIViewController {
35 | TapViewController *tapViewController;
36 | UITableView *setupTableView;
37 |
38 | UITableViewCell *connectionCell;
39 |
40 | UITableViewCell *numberOfButtonsCell;
41 | UITableViewCell *mouseMapLeftToRightCell;
42 | UITableViewCell *doLabelsForMouseButtonsCell;
43 |
44 | UITableViewCell *twoFingersScrollCell;
45 | UITableViewCell *allowHorizontalScrollCell;
46 | UITableViewCell *scrollWithMouse3Cell;
47 | UITableViewCell *scrollingSpeedCell;
48 |
49 | UITableViewCell *trackingSpeedCell;
50 |
51 | UITableViewCell *clickByTapCell;
52 | UITableViewCell *dragByTapCell;
53 | UITableViewCell *dragByTapLockCell;
54 | UITableViewCell *dragByTapLockCommentCell;
55 | UITableViewCell *twoFingersSecondaryCell;
56 | UITableViewCell *twoFingersSecondaryCommentCell;
57 |
58 | UITableViewCell *numberToggleStatusbarCell;
59 |
60 | UITableViewCell *numberArrowKeyGestureCell;
61 | UITableViewCell *numberArrowKeyGestureCommentCell;
62 | UITableViewCell *arrowKeyGestureOneKeyCell;
63 |
64 | UITableViewCell *enableAccelMouseCell;
65 | UITableViewCell *enableAccelMouseCommentCell;
66 |
67 | UITableViewCell *autorotateOrientationCell;
68 | UITableViewCell *prohibitSleepingCell;
69 |
70 | UITableViewCell *topviewLocationCell;
71 | UISegmentedControl *topviewLocationSegment;
72 | UITableViewCell *topviewRelocationGestureCell;
73 | UITableViewCell *topviewLocationCommentCell;
74 |
75 | UITableViewCell *resetSecurityWarningsCell;
76 |
77 | UITableViewCell *versionCell;
78 | }
79 |
80 | + (UILabel *)labelWithFrame:(CGRect)frame title:(NSString *)title;
81 | - (void)setButtonLocation:(CGPoint)value;
82 | - (void)adjustCellValues;
83 | - (void)setTopviewLocationValue;
84 |
85 | @end
86 |
--------------------------------------------------------------------------------
/RemotePad/TCPServer.h:
--------------------------------------------------------------------------------
1 | //
2 | // TCPServer.h
3 | // RemotePad
4 | //
5 | // Derived from an Apple's sample code TCPServer.h of WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/17.
7 | //
8 | /*
9 |
10 | File: TCPServer.h
11 | Abstract: A TCP server that listens on an arbitrary port.
12 |
13 | Version: 1.5
14 |
15 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
16 | ("Apple") in consideration of your agreement to the following terms, and your
17 | use, installation, modification or redistribution of this Apple software
18 | constitutes acceptance of these terms. If you do not agree with these terms,
19 | please do not use, install, modify or redistribute this Apple software.
20 |
21 | In consideration of your agreement to abide by the following terms, and subject
22 | to these terms, Apple grants you a personal, non-exclusive license, under
23 | Apple's copyrights in this original Apple software (the "Apple Software"), to
24 | use, reproduce, modify and redistribute the Apple Software, with or without
25 | modifications, in source and/or binary forms; provided that if you redistribute
26 | the Apple Software in its entirety and without modifications, you must retain
27 | this notice and the following text and disclaimers in all such redistributions
28 | of the Apple Software.
29 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
30 | to endorse or promote products derived from the Apple Software without specific
31 | prior written permission from Apple. Except as expressly stated in this notice,
32 | no other rights or licenses, express or implied, are granted by Apple herein,
33 | including but not limited to any patent rights that may be infringed by your
34 | derivative works or by other works in which the Apple Software may be
35 | incorporated.
36 |
37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
38 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
39 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
41 | COMBINATION WITH YOUR PRODUCTS.
42 |
43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
44 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
45 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
47 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
48 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
49 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 |
51 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
52 |
53 | */
54 |
55 | #import
56 |
57 | //CLASSES:
58 |
59 | @class TCPServer;
60 |
61 | //ERRORS:
62 |
63 | NSString * const TCPServerErrorDomain;
64 |
65 | typedef enum {
66 | kTCPServerCouldNotBindToIPv4Address = 1,
67 | kTCPServerCouldNotBindToIPv6Address = 2,
68 | kTCPServerNoSocketsAvailable = 3,
69 | } TCPServerErrorCode;
70 |
71 | //PROTOCOLS:
72 |
73 | @protocol TCPServerDelegate
74 | @optional
75 | - (void) serverDidEnableBonjour:(TCPServer*)server withName:(NSString*)name;
76 | - (void) server:(TCPServer*)server didNotEnableBonjour:(NSDictionary *)errorDict;
77 | - (void) didAcceptConnectionForServer:(TCPServer*)server inputStream:(NSInputStream *)istr outputStream:(NSOutputStream *)ostr;
78 | @end
79 |
80 | //CLASS INTERFACES:
81 |
82 | @interface TCPServer : NSObject {
83 | @private
84 | id _delegate;
85 | uint16_t _port;
86 | CFSocketRef _ipv4socket;
87 | NSNetService* _netService;
88 | }
89 |
90 | - (BOOL)start:(NSError **)error;
91 | - (BOOL)stop;
92 | - (BOOL) enableBonjourWithDomain:(NSString*)domain applicationProtocol:(NSString*)protocol name:(NSString*)name; //Pass "nil" for the default local domain - Pass only the application protocol for "protocol" e.g. "myApp"
93 | - (void) disableBonjour;
94 |
95 | @property(assign) id delegate;
96 |
97 | + (NSString*) bonjourTypeFromIdentifier:(NSString*)identifier;
98 |
99 | @end
100 |
--------------------------------------------------------------------------------
/RemotePad/TCPServer.m:
--------------------------------------------------------------------------------
1 | //
2 | // TCPServer.m
3 | // RemotePad
4 | //
5 | // Derived from an Apple's sample code TCPServer.m of WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/17.
7 | //
8 | /*
9 |
10 | File: TCPServer.m
11 | Abstract: A TCP server that listens on an arbitrary port.
12 |
13 | Version: 1.5
14 |
15 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
16 | ("Apple") in consideration of your agreement to the following terms, and your
17 | use, installation, modification or redistribution of this Apple software
18 | constitutes acceptance of these terms. If you do not agree with these terms,
19 | please do not use, install, modify or redistribute this Apple software.
20 |
21 | In consideration of your agreement to abide by the following terms, and subject
22 | to these terms, Apple grants you a personal, non-exclusive license, under
23 | Apple's copyrights in this original Apple software (the "Apple Software"), to
24 | use, reproduce, modify and redistribute the Apple Software, with or without
25 | modifications, in source and/or binary forms; provided that if you redistribute
26 | the Apple Software in its entirety and without modifications, you must retain
27 | this notice and the following text and disclaimers in all such redistributions
28 | of the Apple Software.
29 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
30 | to endorse or promote products derived from the Apple Software without specific
31 | prior written permission from Apple. Except as expressly stated in this notice,
32 | no other rights or licenses, express or implied, are granted by Apple herein,
33 | including but not limited to any patent rights that may be infringed by your
34 | derivative works or by other works in which the Apple Software may be
35 | incorporated.
36 |
37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
38 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
39 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
41 | COMBINATION WITH YOUR PRODUCTS.
42 |
43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
44 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
45 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
47 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
48 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
49 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 |
51 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
52 |
53 | */
54 |
55 | #include
56 | #include
57 | #include
58 | #include
59 |
60 | #import "TCPServer.h"
61 | #import "Constants.h"
62 |
63 | NSString * const TCPServerErrorDomain = @"TCPServerErrorDomain";
64 |
65 | @interface TCPServer ()
66 | @property(nonatomic,retain) NSNetService* netService;
67 | @property(assign) uint16_t port;
68 | @end
69 |
70 | @implementation TCPServer
71 |
72 | @synthesize delegate=_delegate, netService=_netService, port=_port;
73 |
74 | - (id)init {
75 | return self;
76 | }
77 |
78 | - (void)dealloc {
79 | [self stop];
80 | [super dealloc];
81 | }
82 |
83 | - (void)handleNewConnectionFromAddress:(NSData *)addr inputStream:(NSInputStream *)istr outputStream:(NSOutputStream *)ostr {
84 | // if the delegate implements the delegate method, call it
85 | if (self.delegate && [self.delegate respondsToSelector:@selector(didAcceptConnectionForServer:inputStream:outputStream:)]) {
86 | [self.delegate didAcceptConnectionForServer:self inputStream:istr outputStream:ostr];
87 | }
88 | }
89 |
90 | // This function is called by CFSocket when a new connection comes in.
91 | // We gather some data here, and convert the function call to a method
92 | // invocation on TCPServer.
93 | static void TCPServerAcceptCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info) {
94 | TCPServer *server = (TCPServer *)info;
95 | if (kCFSocketAcceptCallBack == type) {
96 | // for an AcceptCallBack, the data parameter is a pointer to a CFSocketNativeHandle
97 | CFSocketNativeHandle nativeSocketHandle = *(CFSocketNativeHandle *)data;
98 | uint8_t name[SOCK_MAXADDRLEN];
99 | socklen_t namelen = sizeof(name);
100 | NSData *peer = nil;
101 | if (0 == getpeername(nativeSocketHandle, (struct sockaddr *)name, &namelen)) {
102 | peer = [NSData dataWithBytes:name length:namelen];
103 | }
104 | CFReadStreamRef readStream = NULL;
105 | CFWriteStreamRef writeStream = NULL;
106 | CFStreamCreatePairWithSocket(kCFAllocatorDefault, nativeSocketHandle, &readStream, &writeStream);
107 | if (readStream && writeStream) {
108 | CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
109 | CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
110 | [server handleNewConnectionFromAddress:peer inputStream:(NSInputStream *)readStream outputStream:(NSOutputStream *)writeStream];
111 | } else {
112 | // on any failure, need to destroy the CFSocketNativeHandle
113 | // since we are not going to use it any more
114 | close(nativeSocketHandle);
115 | }
116 | if (readStream) CFRelease(readStream);
117 | if (writeStream) CFRelease(writeStream);
118 | }
119 | }
120 |
121 | - (BOOL)start:(NSError **)error {
122 | CFSocketContext socketCtxt = {0, self, NULL, NULL, NULL};
123 | _ipv4socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, kCFSocketAcceptCallBack, (CFSocketCallBack)&TCPServerAcceptCallBack, &socketCtxt);
124 |
125 | if (NULL == _ipv4socket) {
126 | if (error) *error = [[NSError alloc] initWithDomain:TCPServerErrorDomain code:kTCPServerNoSocketsAvailable userInfo:nil];
127 | if (_ipv4socket) CFRelease(_ipv4socket);
128 | _ipv4socket = NULL;
129 | return NO;
130 | }
131 |
132 |
133 | int yes = 1;
134 | setsockopt(CFSocketGetNative(_ipv4socket), SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
135 |
136 | // set up the IPv4 endpoint; use port 0, so the kernel will choose an arbitrary port for us, which will be advertised using Bonjour
137 | struct sockaddr_in addr4;
138 | memset(&addr4, 0, sizeof(addr4));
139 | addr4.sin_len = sizeof(addr4);
140 | addr4.sin_family = AF_INET;
141 | addr4.sin_port = 0;
142 | addr4.sin_addr.s_addr = htonl(INADDR_ANY);
143 | NSData *address4 = [NSData dataWithBytes:&addr4 length:sizeof(addr4)];
144 |
145 | if (kCFSocketSuccess != CFSocketSetAddress(_ipv4socket, (CFDataRef)address4)) {
146 | if (error) *error = [[NSError alloc] initWithDomain:TCPServerErrorDomain code:kTCPServerCouldNotBindToIPv4Address userInfo:nil];
147 | if (_ipv4socket) CFRelease(_ipv4socket);
148 | _ipv4socket = NULL;
149 | return NO;
150 | }
151 |
152 | // now that the binding was successful, we get the port number
153 | // -- we will need it for the NSNetService
154 | NSData *addr = [(NSData *)CFSocketCopyAddress(_ipv4socket) autorelease];
155 | memcpy(&addr4, [addr bytes], [addr length]);
156 | self.port = ntohs(addr4.sin_port);
157 |
158 |
159 | // set up the run loop sources for the sockets
160 | CFRunLoopRef cfrl = CFRunLoopGetCurrent();
161 | CFRunLoopSourceRef source4 = CFSocketCreateRunLoopSource(kCFAllocatorDefault, _ipv4socket, 0);
162 | CFRunLoopAddSource(cfrl, source4, kCFRunLoopCommonModes);
163 | CFRelease(source4);
164 |
165 |
166 | return YES;
167 | }
168 |
169 | - (BOOL)stop {
170 | [self disableBonjour];
171 |
172 | if (_ipv4socket) {
173 | CFSocketInvalidate(_ipv4socket);
174 | CFRelease(_ipv4socket);
175 | _ipv4socket = NULL;
176 | }
177 |
178 |
179 | return YES;
180 | }
181 |
182 | - (BOOL) enableBonjourWithDomain:(NSString*)domain applicationProtocol:(NSString*)protocol name:(NSString*)name
183 | {
184 | if(![domain length])
185 | domain = @""; //Will use default Bonjour registration doamins, typically just ".local"
186 | if(![name length])
187 | name = @""; //Will use default Bonjour name, e.g. the name assigned to the device in iTunes
188 |
189 | if(!protocol || ![protocol length] || _ipv4socket == NULL)
190 | return NO;
191 |
192 |
193 | self.netService = [[NSNetService alloc] initWithDomain:domain type:protocol name:name port:self.port];
194 | if(self.netService == nil)
195 | return NO;
196 |
197 | [self.netService scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
198 | [self.netService publish];
199 | [self.netService setDelegate:self];
200 |
201 | return YES;
202 | }
203 |
204 | /*
205 | Bonjour will not allow conflicting service instance names (in the same domain), and may have automatically renamed
206 | the service if there was a conflict. We pass the name back to the delegate so that the name can be displayed to
207 | the user.
208 | See http://developer.apple.com/networking/bonjour/faq.html for more information.
209 | */
210 |
211 | - (void)netServiceDidPublish:(NSNetService *)sender
212 | {
213 | if (self.delegate && [self.delegate respondsToSelector:@selector(serverDidEnableBonjour:withName:)])
214 | [self.delegate serverDidEnableBonjour:self withName:sender.name];
215 | }
216 |
217 | - (void)netService:(NSNetService *)sender didNotPublish:(NSDictionary *)errorDict
218 | {
219 | [super netServiceDidPublish:sender];
220 | if(self.delegate && [self.delegate respondsToSelector:@selector(server:didNotEnableBonjour:)])
221 | [self.delegate server:self didNotEnableBonjour:errorDict];
222 | }
223 |
224 | - (void) disableBonjour
225 | {
226 | if(self.netService) {
227 | [self.netService stop];
228 | [self.netService removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
229 | self.netService = nil;
230 | }
231 | }
232 |
233 | - (NSString*) description
234 | {
235 | return [NSString stringWithFormat:@"<%@ = 0x%08X | port %d | netService = %@>", [self class], (long)self, self.port, self.netService];
236 | }
237 |
238 | + (NSString*) bonjourTypeFromIdentifier:(NSString*)identifier {
239 | if (![identifier length])
240 | return nil;
241 |
242 | return [NSString stringWithFormat:@"_%@._tcp.", identifier];
243 | }
244 |
245 | @end
246 |
--------------------------------------------------------------------------------
/RemotePad/TapView.h:
--------------------------------------------------------------------------------
1 | //
2 | // TapView.h
3 | // RemotePad
4 | //
5 | // Derived from an Apple's sample code TapView.h of WiTap.
6 | // Modified by iKawamoto Yosihisa! on 08/08/17.
7 | //
8 | /*
9 |
10 | File: TapView.h
11 | Abstract: UIView subclass that can highlight itself when locally or remotely
12 | tapped.
13 |
14 | Version: 1.5
15 |
16 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
17 | ("Apple") in consideration of your agreement to the following terms, and your
18 | use, installation, modification or redistribution of this Apple software
19 | constitutes acceptance of these terms. If you do not agree with these terms,
20 | please do not use, install, modify or redistribute this Apple software.
21 |
22 | In consideration of your agreement to abide by the following terms, and subject
23 | to these terms, Apple grants you a personal, non-exclusive license, under
24 | Apple's copyrights in this original Apple software (the "Apple Software"), to
25 | use, reproduce, modify and redistribute the Apple Software, with or without
26 | modifications, in source and/or binary forms; provided that if you redistribute
27 | the Apple Software in its entirety and without modifications, you must retain
28 | this notice and the following text and disclaimers in all such redistributions
29 | of the Apple Software.
30 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used
31 | to endorse or promote products derived from the Apple Software without specific
32 | prior written permission from Apple. Except as expressly stated in this notice,
33 | no other rights or licenses, express or implied, are granted by Apple herein,
34 | including but not limited to any patent rights that may be infringed by your
35 | derivative works or by other works in which the Apple Software may be
36 | incorporated.
37 |
38 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
39 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
40 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
42 | COMBINATION WITH YOUR PRODUCTS.
43 |
44 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
45 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
46 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
48 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
49 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
50 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 |
52 | Copyright (C) 2008 Apple Inc. All Rights Reserved.
53 |
54 | */
55 |
56 | #import
57 | #import "Event.h"
58 | #import "Constants.h"
59 |
60 | @class AppController;
61 |
62 |
63 | typedef struct {
64 | UITouch *touch;
65 | CGPoint tapLocation;
66 | CGRect nonDragArea;
67 | // for button click
68 | UIButton *button;
69 | BOOL dragMode;
70 | BOOL twoFingersClick;
71 | BOOL postponedClick;
72 | // for multi-fingers click
73 | NSTimeInterval timestamp;
74 | int numFingers;
75 | UITouchPhase phase;
76 | } MouseTap;
77 |
78 | typedef struct {
79 | BOOL valid;
80 | BOOL stopping;
81 | BOOL enabled;
82 | UIAccelerationValue ax;
83 | UIAccelerationValue ay;
84 | UIAccelerationValue az;
85 | UIAccelerationValue vx;
86 | UIAccelerationValue vy;
87 | UIAccelerationValue vz;
88 | double stability;
89 | } AccelValues;
90 |
91 | //CLASS INTERFACES:
92 |
93 | @interface TapViewController : UIViewController
94 | {
95 | AppController *appc;
96 | CGPoint start;
97 | MouseTap mouse1Tap, mouse2Tap, mouse3Tap, topviewTap, arrowKeyTap, multiFingersTap;
98 | int numTouches;
99 | UIView *topview;
100 | UIToolbar *bottombar;
101 | BOOL hiddenStatusbar;
102 | BOOL hiddenToolbars;
103 | BOOL hiddenKeyboard;
104 | UIImage *buttonLeftImage, *buttonLeftHighlightedImage;
105 | UIImage *buttonRightImage, *buttonRightHighlightedImage;
106 | UIImage *buttonCenterImage, *buttonCenterHighlightedImage;
107 | UIImage *buttonRoundedImage, *buttonRoundedHighlightedImage;
108 | CGPoint prevDelta;
109 | BOOL dragByTapDragMode;
110 | NSTimer *clickTimer;
111 | UITouch *clickTimerTouch;
112 | UITextField *keyboardField;
113 | UIAlertView *insecureKeyboardWarningDialog;
114 | NSTimer *insecureKeyboardWarningTimer;
115 | int insecureKeyboardWarningCount;
116 | //config value
117 | CGPoint topviewLocation;
118 | BOOL topviewRelocationGesture;
119 | int numberOfButtons;
120 | BOOL mouseMapLeftToRight;
121 | int numberArrowKeyGesture;
122 | BOOL arrowKeyGestureOneKey;
123 | BOOL twoFingersScroll;
124 | BOOL allowHorizontalScroll;
125 | BOOL clickByTap;
126 | BOOL dragByTap;
127 | BOOL dragByTapLock;
128 | int numberToggleStatusbar;
129 | int numberToggleToolbars;
130 | BOOL scrollWithMouse3;
131 | AccelValues currAccel;
132 | BOOL enableAccelMouse;
133 | UIInterfaceOrientation tapViewOrientation;
134 | BOOL autorotateOrientation;
135 | BOOL twoFingersSecondary;
136 | BOOL prohibitSleeping;
137 | int trackingSpeed;
138 | int scrollingSpeed;
139 | BOOL doneInsecureKeyboardWarning;
140 | BOOL doLabelsForMouseButtons;
141 | }
142 |
143 | - (void)resetAllStates:(id)applicationControllerDelegate;
144 | - (void)toggleStatusbars;
145 | - (void)showToolbars:(BOOL)show temporal:(BOOL)temporally;
146 | - (void)showToolbars:(BOOL)showToolbars showStatusbar:(BOOL)showStatusbar temporal:(BOOL)temporally;
147 | - (void)prepareToolbarsAndStatusbar;
148 | - (void)setNumberOfButtons:(int)val;
149 | - (void)setMouseMapLeftToRight:(BOOL)isLeftToRight;
150 | - (void)setNumberOfButtons:(int)val mouseMapLeftToRight:(BOOL)isLeftToRight;
151 | - (void)setProhibitSleeping:(BOOL)value;
152 | - (CGPoint)getTopviewLocation;
153 | - (void)registerDefaults;
154 | - (void)readDefaults;
155 | - (void)prepareTapView;
156 | - (void)showInsecureKeyboardWarning;
157 | - (void)insecureKeyboardWarningCountDown:(NSTimer*)timer;
158 | - (void)setDoLabelsForMouseButtons:(BOOL)value;
159 |
160 | @property (nonatomic,retain) AppController *appc;
161 | @property (readonly) UIView *topview;
162 | @property CGPoint topviewLocation;
163 | @property BOOL topviewRelocationGesture;
164 | @property (readonly) int numberOfButtons;
165 | @property (readonly) BOOL mouseMapLeftToRight;
166 | @property int numberArrowKeyGesture;
167 | @property BOOL arrowKeyGestureOneKey;
168 | @property BOOL twoFingersScroll;
169 | @property BOOL allowHorizontalScroll;
170 | @property BOOL clickByTap;
171 | @property BOOL dragByTap;
172 | @property BOOL dragByTapLock;
173 | @property int numberToggleStatusbar;
174 | @property BOOL scrollWithMouse3;
175 | @property BOOL enableAccelMouse;
176 | @property UIInterfaceOrientation tapViewOrientation;
177 | @property BOOL autorotateOrientation;
178 | @property BOOL twoFingersSecondary;
179 | @property (readonly) BOOL prohibitSleeping;
180 | @property int trackingSpeed;
181 | @property int scrollingSpeed;
182 | @property BOOL doneInsecureKeyboardWarning;
183 | @property (readonly) BOOL doLabelsForMouseButtons;
184 |
185 | @end
186 |
--------------------------------------------------------------------------------
/RemotePad/adhoc-Entitlements.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | get-task-allow
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/RemotePad/bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/bg.png
--------------------------------------------------------------------------------
/RemotePad/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/icon.png
--------------------------------------------------------------------------------
/RemotePad/icon.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/icon.xcf
--------------------------------------------------------------------------------
/RemotePad/itunes.txt:
--------------------------------------------------------------------------------
1 | RemotePad is an open source application that controls the mouse cursor of your desktop PC. This way, you can use your iPhone or iPod touch as a wireless touchpad! -*-coding:utf-8-*-
2 |
3 | FEATURES:
4 | • Mouse control with a virtual touchpad.
5 | • Software keyboard for ascii text inputs.
6 | • Server support for major platforms, namely, Mac OS X, Windows, Linux and BSD.
7 | • Bonjour (Zeroconf) server detection under Mac OS X.
8 | • Customizable appearence and behaviour.
9 | • Landscape mode.
10 | • Two finger vertical and horizontal scrolling.
11 | • Mouse control via acceleromenter.
12 | • Send arrow keys.
13 | • BSD-style licensed source codes.
14 |
15 | ADDITIONAL REQUIREMENTS:
16 | • Computer running a version of the RemotePad Server
17 | (free download from http://www.tenjin.org/RemotePad/downloads.html)
18 | • WiFi connection
19 |
20 | WHAT'S NEW IN THIS VERSION:
21 | • Many bug fixes
22 | • Servers were also improved and bugs fixed.
23 |
--------------------------------------------------------------------------------
/RemotePad/largeicon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/RemotePad/largeicon.jpg
--------------------------------------------------------------------------------
/RemotePad/main.m:
--------------------------------------------------------------------------------
1 | /*
2 | * main.m
3 | * RemotePad
4 | *
5 | * Created by iKawamoto Yosihisa! on 08/08/13.
6 | * Copyright 2008, 2009 tenjin.org. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #import
31 |
32 | int main(int argc, char *argv[]) {
33 |
34 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
35 | int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
36 | [pool release];
37 | return retVal;
38 | }
39 |
--------------------------------------------------------------------------------
/Windows/RemotePad Server.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * RemotePad Server.cpp
3 | * RemotePad Server
4 | *
5 | * Created by iKawamoto Yosihisa! on 09/03/11.
6 | * Copyright 2009 tenjin.org. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #if !defined(SD_BOTH)
39 | #define SD_BOTH 2
40 | #endif
41 | #include "RemotePad Server.h"
42 |
43 | #define WM_TRAYMENU (WM_USER + 1)
44 | #define WM_NETWORK (WM_USER + 2)
45 |
46 | typedef enum {
47 | statusNotConnected = 0,
48 | statusConnected
49 | } connStatus;
50 | typedef enum {
51 | trayIconNotConnected = 0,
52 | trayIconConnected
53 | } connTrayIcon;
54 | typedef struct {
55 | HWND hWnd;
56 | SOCKET socket;
57 | } ArgList;
58 | typedef unsigned long uint32_t;
59 | typedef long int32_t;
60 | struct timespec {
61 | __time32_t tv_sec;
62 | long tv_nsec;
63 | };
64 | #include "Event.h"
65 | #include "Version.h"
66 |
67 | #define kMaxLoadString 128
68 | #define kWidthMin 320
69 | #define kHeightMin 300
70 | #define kTrayId 101
71 | #define kNumIPAddresses 8
72 | #define kNumButtons 5
73 | #define kDefaultPort 5583
74 | #define kNumTrayIcons 2
75 | #define kMessageValue 180
76 | #define kMessageHeight 20
77 | #define kMessageSpace 10
78 |
79 | HINSTANCE hInst;
80 | TCHAR szWindowClass[kMaxLoadString];
81 | TCHAR szTitle[kMaxLoadString];
82 | TCHAR szTitleWin[kMaxLoadString];
83 | TCHAR szVersion[kMaxLoadString];
84 | TCHAR szIPAddresses[kMaxLoadString];
85 | TCHAR szPort[kMaxLoadString];
86 | TCHAR szStatus[kMaxLoadString];
87 | TCHAR szCannotDetect[kMaxLoadString];
88 | TCHAR szConnected[kMaxLoadString];
89 | TCHAR szNotConnected[kMaxLoadString];
90 | NOTIFYICONDATA trayIcon[kNumTrayIcons];
91 | BOOL bInTray;
92 | SOCKADDR_IN addrList[kNumIPAddresses];
93 | int numAddrs;
94 | int flagButtonDown[kNumButtons] = {MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_XDOWN, MOUSEEVENTF_XDOWN};
95 | int flagButtonUp[kNumButtons] = {MOUSEEVENTF_LEFTUP, MOUSEEVENTF_RIGHTUP, MOUSEEVENTF_MIDDLEUP, MOUSEEVENTF_XUP, MOUSEEVENTF_XUP};
96 | int dataXButton[kNumButtons] = {0, 0, 0, XBUTTON1, XBUTTON2};
97 | int connectionStatus;
98 |
99 | LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
100 | INT_PTR CALLBACK About(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
101 | void DisplayWindow(HWND hWnd);
102 | void RepaintWindow(HWND hWnd);
103 | void CreateTrayIcons(HWND hWnd, PNOTIFYICONDATA pTrayIcon);
104 | void DisplayTrayMenu(HWND hWnd);
105 | void HideInTray(HWND hWnd, BOOL hide);
106 | void HandleKeyEvent(MouseEvent event);
107 | void SimulateKeyWithUnichar(MouseEvent event);
108 | SOCKET CreateSocket(HWND hWnd);
109 | void ListAddresses();
110 | SOCKET AcceptSocket(HWND hWnd, SOCKET serverSocket);
111 | void CloseSocket(HWND hWnd, SOCKET clientSocket);
112 | void StreamThread(void *args);
113 |
114 | int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
115 | LoadString(hInstance, IDC_REMOTEPADSERVER, szWindowClass, kMaxLoadString);
116 | LoadString(hInstance, IDS_APP_TITLE, szTitle, kMaxLoadString);
117 | LoadString(hInstance, IDS_APP_TITLE_WIN, szTitleWin, kMaxLoadString);
118 | LoadString(hInstance, IDS_VERSION, szVersion, kMaxLoadString);
119 | LoadString(hInstance, IDS_IP_ADDRESSES, szIPAddresses, kMaxLoadString);
120 | LoadString(hInstance, IDS_PORT, szPort, kMaxLoadString);
121 | LoadString(hInstance, IDS_STATUS, szStatus, kMaxLoadString);
122 | LoadString(hInstance, IDS_CANNOT_DETECT, szCannotDetect, kMaxLoadString);
123 | LoadString(hInstance, IDS_CONNECTED, szConnected, kMaxLoadString);
124 | LoadString(hInstance, IDS_NOT_CONNECTED, szNotConnected, kMaxLoadString);
125 |
126 | if (!hPrevInstance) {
127 | WNDCLASSEX wcex;
128 | wcex.cbSize = sizeof(WNDCLASSEX);
129 | wcex.style = CS_HREDRAW | CS_VREDRAW;
130 | wcex.lpfnWndProc = WndProc;
131 | wcex.cbClsExtra = 0;
132 | wcex.cbWndExtra = 0;
133 | wcex.hInstance = hInstance;
134 | wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REMOTEPADSERVER));
135 | wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_CONNECTED));
136 | wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
137 | wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
138 | wcex.lpszMenuName = MAKEINTRESOURCE(IDC_REMOTEPADSERVER);
139 | wcex.lpszClassName = szWindowClass;
140 | if (!RegisterClassEx(&wcex))
141 | return FALSE;
142 | }
143 |
144 | HWND hWnd;
145 | hInst = hInstance;
146 | hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, kWidthMin, kHeightMin, NULL, NULL, hInstance, NULL);
147 | if (!hWnd)
148 | return FALSE;
149 |
150 | ShowWindow(hWnd, nCmdShow);
151 | if (nCmdShow == SW_SHOWMINNOACTIVE) {
152 | ShowWindow(hWnd, SW_HIDE);
153 | bInTray = TRUE;
154 | } else {
155 | UpdateWindow(hWnd);
156 | bInTray = FALSE;
157 | }
158 |
159 | CreateTrayIcons(hWnd, trayIcon);
160 | Shell_NotifyIcon(NIM_ADD, &trayIcon[trayIconNotConnected]);
161 |
162 | HACCEL hAccelTable;
163 | hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_REMOTEPADSERVER));
164 |
165 | MSG msg;
166 | while (GetMessage(&msg, NULL, 0, 0)) {
167 | if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
168 | TranslateMessage(&msg);
169 | DispatchMessage(&msg);
170 | }
171 | }
172 |
173 | return msg.wParam;
174 | }
175 |
176 | LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
177 | int wmId, wmEvent;
178 | LPMINMAXINFO minInfo;
179 | static SOCKET serverSocket;
180 | static SOCKET clientSocket;
181 |
182 | switch (message) {
183 | case WM_CREATE:
184 | serverSocket = CreateSocket(hWnd);
185 | connectionStatus = statusNotConnected;
186 | EnableMenuItem(GetMenu(hWnd), IDM_DISCONNECT, MF_BYCOMMAND | MF_GRAYED);
187 | ListAddresses();
188 | break;
189 | case WM_NETWORK:
190 | switch (WSAGETSELECTEVENT(lParam)) {
191 | case FD_ACCEPT:
192 | clientSocket = AcceptSocket(hWnd, serverSocket);
193 | break;
194 | case FD_CLOSE:
195 | if (connectionStatus == statusConnected)
196 | CloseSocket(hWnd, clientSocket);
197 | break;
198 | }
199 | break;
200 | case WM_COMMAND:
201 | wmId = LOWORD(wParam);
202 | wmEvent = HIWORD(wParam);
203 | switch (wmId) {
204 | case IDM_ABOUT:
205 | DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
206 | break;
207 | case IDM_EXIT:
208 | Shell_NotifyIcon(NIM_DELETE, &trayIcon[trayIconNotConnected]);
209 | DestroyWindow(hWnd);
210 | break;
211 | case IDM_TRAY:
212 | HideInTray(hWnd, TRUE);
213 | break;
214 | case IDM_DISCONNECT:
215 | if (connectionStatus == statusConnected)
216 | CloseSocket(hWnd, clientSocket);
217 | break;
218 | case IDM_OPEN:
219 | HideInTray(hWnd, FALSE);
220 | break;
221 | default:
222 | return DefWindowProc(hWnd, message, wParam, lParam);
223 | }
224 | break;
225 | case WM_GETMINMAXINFO:
226 | minInfo = (LPMINMAXINFO)lParam;
227 | minInfo->ptMinTrackSize.x = kWidthMin;
228 | minInfo->ptMinTrackSize.y = kHeightMin;
229 | break;
230 | case WM_PAINT:
231 | DisplayWindow(hWnd);
232 | break;
233 | case WM_SYSCOMMAND:
234 | if (wParam == SC_MINIMIZE)
235 | HideInTray(hWnd, TRUE);
236 | else
237 | return DefWindowProc(hWnd, message, wParam, lParam);
238 | break;
239 | case WM_CLOSE:
240 | HideInTray(hWnd, TRUE);
241 | break;
242 | case WM_DESTROY:
243 | PostQuitMessage(0);
244 | break;
245 | case WM_TRAYMENU:
246 | if (wParam == kTrayId) {
247 | switch (lParam) {
248 | case WM_RBUTTONDOWN:
249 | DisplayTrayMenu(hWnd);
250 | break;
251 | case WM_LBUTTONDBLCLK:
252 | HideInTray(hWnd, !bInTray);
253 | break;
254 | default:
255 | break;
256 | }
257 | }
258 | break;
259 | default:
260 | return DefWindowProc(hWnd, message, wParam, lParam);
261 | }
262 | return 0;
263 | }
264 |
265 | INT_PTR CALLBACK About(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
266 | switch (message) {
267 | case WM_INITDIALOG:
268 | return (INT_PTR)TRUE;
269 | case WM_COMMAND:
270 | if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
271 | EndDialog(hWnd, LOWORD(wParam));
272 | return (INT_PTR)TRUE;
273 | }
274 | break;
275 | }
276 | return (INT_PTR)FALSE;
277 | }
278 |
279 | void DisplayWindow(HWND hWnd) {
280 | HDC hdc;
281 | PAINTSTRUCT ps;
282 | RECT rect;
283 | RECT labelRect;
284 | RECT valueRect;
285 | TCHAR buf[kMaxLoadString];
286 |
287 | hdc = BeginPaint(hWnd, &ps);
288 |
289 | GetClientRect(hWnd, &rect);
290 | labelRect.top = rect.top + 20;
291 | labelRect.left = rect.left + 20;
292 | labelRect.right = rect.right - 20;
293 | labelRect.bottom = rect.bottom;
294 | valueRect.top = labelRect.top;
295 | valueRect.left = kMessageValue;
296 | valueRect.right = rect.right - 20;
297 | valueRect.bottom = rect.bottom;
298 | DrawText(hdc, szTitleWin, -1, &labelRect, DT_WORDBREAK);
299 |
300 | labelRect.top += kMessageHeight + kMessageSpace * 2;
301 | valueRect.top += kMessageHeight + kMessageSpace * 2;
302 | DrawText(hdc, szVersion, -1, &labelRect, DT_WORDBREAK);
303 | wsprintf(buf, L"%S", kVersionWindows);
304 | DrawText(hdc, buf, -1, &valueRect, DT_WORDBREAK);
305 |
306 | labelRect.top += kMessageHeight + kMessageSpace;
307 | valueRect.top += kMessageHeight + kMessageSpace;
308 | DrawText(hdc, szIPAddresses, -1, &labelRect, DT_WORDBREAK);
309 | if (numAddrs) {
310 | for (int i = 0; i < numAddrs; i++) {
311 | wsprintf(buf, L"%S", inet_ntoa(addrList[i].sin_addr));
312 | DrawText(hdc, buf, -1, &valueRect, DT_WORDBREAK);
313 | labelRect.top += kMessageHeight;
314 | valueRect.top += kMessageHeight;
315 | }
316 | } else {
317 | DrawText(hdc, szCannotDetect, -1, &valueRect, DT_WORDBREAK);
318 | labelRect.top += kMessageHeight;
319 | valueRect.top += kMessageHeight;
320 | }
321 |
322 | labelRect.top += kMessageSpace;
323 | valueRect.top += kMessageSpace;
324 | DrawText(hdc, szPort, -1, &labelRect, DT_WORDBREAK);
325 | wsprintf(buf, L"%d", kDefaultPort);
326 | DrawText(hdc, buf, -1, &valueRect, DT_WORDBREAK);
327 |
328 | labelRect.top += kMessageHeight + kMessageSpace;
329 | valueRect.top += kMessageHeight + kMessageSpace;
330 | DrawText(hdc, szStatus, -1, &labelRect, DT_WORDBREAK);
331 | DrawText(hdc, (connectionStatus == statusConnected) ? szConnected : szNotConnected, -1, &valueRect, DT_WORDBREAK);
332 |
333 | EndPaint(hWnd, &ps);
334 | }
335 |
336 | void RepaintWindow(HWND hWnd) {
337 | RECT rect;
338 |
339 | GetClientRect(hWnd, &rect);
340 | InvalidateRect(hWnd, &rect, true);
341 | UpdateWindow(hWnd);
342 | }
343 |
344 | void CreateTrayIcons(HWND hWnd, PNOTIFYICONDATA pTrayIcon) {
345 | pTrayIcon[trayIconNotConnected].cbSize = sizeof(NOTIFYICONDATA);
346 | pTrayIcon[trayIconNotConnected].hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_NOTCONNECTED));
347 | pTrayIcon[trayIconNotConnected].hWnd = hWnd;
348 | pTrayIcon[trayIconNotConnected].uCallbackMessage = WM_TRAYMENU;
349 | pTrayIcon[trayIconNotConnected].uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
350 | pTrayIcon[trayIconNotConnected].uID = kTrayId;
351 | LoadString(hInst, IDS_APP_TITLE, pTrayIcon[trayIconNotConnected].szTip, kMaxLoadString);
352 | pTrayIcon[trayIconConnected].cbSize = sizeof(NOTIFYICONDATA);
353 | pTrayIcon[trayIconConnected].hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_CONNECTED));
354 | pTrayIcon[trayIconConnected].hWnd = hWnd;
355 | pTrayIcon[trayIconConnected].uCallbackMessage = WM_TRAYMENU;
356 | pTrayIcon[trayIconConnected].uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
357 | pTrayIcon[trayIconConnected].uID = kTrayId;
358 | LoadString(hInst, IDS_APP_TITLE, pTrayIcon[trayIconConnected].szTip, kMaxLoadString);
359 | return;
360 | }
361 |
362 | void DisplayTrayMenu(HWND hWnd) {
363 | HMENU hMenu, hSubMenu;
364 | POINT point;
365 |
366 | hMenu = LoadMenu(hInst, L"IDC_TRAYMENU");
367 | hSubMenu = GetSubMenu(hMenu, 0);
368 | if (connectionStatus == statusConnected)
369 | EnableMenuItem(hSubMenu, IDM_DISCONNECT, MF_BYCOMMAND | MF_ENABLED);
370 | else
371 | EnableMenuItem(hSubMenu, IDM_DISCONNECT, MF_BYCOMMAND | MF_GRAYED);
372 | GetCursorPos(&point);
373 | SetForegroundWindow(hWnd);
374 | TrackPopupMenu(hSubMenu, TPM_BOTTOMALIGN, point.x, point.y, 0, hWnd, NULL);
375 | DestroyMenu(hMenu);
376 | return;
377 | }
378 |
379 | void HideInTray(HWND hWnd, BOOL hide) {
380 | if (hide) {
381 | ShowWindow(hWnd, SW_MINIMIZE);
382 | ShowWindow(hWnd, SW_HIDE);
383 | } else {
384 | ShowWindow(hWnd, SW_SHOW);
385 | ShowWindow(hWnd, SW_NORMAL);
386 | SetForegroundWindow(hWnd);
387 | }
388 | bInTray = hide;
389 | }
390 |
391 | SOCKET CreateSocket(HWND hWnd) {
392 | WSADATA wsaData;
393 | if (WSAStartup(MAKEWORD(2, 1), &wsaData) != 0)
394 | return INVALID_SOCKET;
395 |
396 | SOCKET s;
397 | if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
398 | return INVALID_SOCKET;
399 |
400 | int yes = 1;
401 | setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&yes, sizeof(yes));
402 |
403 | SOCKADDR_IN server;
404 | memset(&server, 0, sizeof(server));
405 | server.sin_family = AF_INET;
406 | server.sin_port = htons(kDefaultPort);
407 | server.sin_addr.s_addr = htonl(INADDR_ANY);
408 |
409 | if (bind(s, (SOCKADDR *)&server, sizeof(server)) == SOCKET_ERROR)
410 | return INVALID_SOCKET;
411 |
412 | if (listen(s, 0) == SOCKET_ERROR)
413 | return INVALID_SOCKET;
414 |
415 | if (WSAAsyncSelect(s, hWnd, WM_NETWORK, FD_ACCEPT|FD_CLOSE) == SOCKET_ERROR)
416 | return INVALID_SOCKET;
417 |
418 | return s;
419 | }
420 |
421 | void ListAddresses() {
422 | char sHostName[256];
423 | int i = 0;
424 | if (gethostname(sHostName, sizeof(sHostName)) == 0) {
425 | PHOSTENT pHostEnt;
426 | if ((pHostEnt = gethostbyname(sHostName)) != NULL) {
427 | for (i = 0; pHostEnt->h_addr_list[i] && i < kNumIPAddresses; i++) {
428 | memcpy(&addrList[i].sin_addr, pHostEnt->h_addr_list[i], pHostEnt->h_length);
429 | }
430 | }
431 | }
432 | numAddrs = i;
433 | return;
434 | }
435 |
436 | SOCKET AcceptSocket(HWND hWnd, SOCKET serverSocket) {
437 | SOCKET clientSocket;
438 | SOCKADDR clientSockAddr;
439 | int clientSockLen;
440 |
441 | clientSockLen = sizeof(clientSockAddr);
442 | clientSocket = accept(serverSocket, &clientSockAddr, &clientSockLen);
443 | WSAAsyncSelect(clientSocket, hWnd, 0, 0);
444 | ULONG nonBlocking = 0;
445 | ioctlsocket(clientSocket, FIONBIO, &nonBlocking);
446 |
447 | connectionStatus = statusConnected;
448 | RepaintWindow(hWnd);
449 | Shell_NotifyIcon(NIM_MODIFY, &trayIcon[trayIconConnected]);
450 | EnableMenuItem(GetMenu(hWnd), IDM_DISCONNECT, MF_BYCOMMAND | MF_ENABLED);
451 |
452 | ArgList args;
453 | args.hWnd = hWnd;
454 | args.socket = clientSocket;
455 | _beginthread(StreamThread, 0, &args);
456 |
457 | return clientSocket;
458 | }
459 |
460 | void CloseSocket(HWND hWnd, SOCKET clientSocket) {
461 | shutdown(clientSocket, SD_BOTH);
462 | closesocket(clientSocket);
463 | connectionStatus = statusNotConnected;
464 | RepaintWindow(hWnd);
465 | Shell_NotifyIcon(NIM_MODIFY, &trayIcon[trayIconNotConnected]);
466 | EnableMenuItem(GetMenu(hWnd), IDM_DISCONNECT, MF_BYCOMMAND | MF_GRAYED);
467 | return;
468 | }
469 |
470 | void StreamThread(void *args) {
471 | HWND hWnd = ((ArgList *)args)->hWnd;
472 | SOCKET clientSocket = ((ArgList *)args)->socket;
473 | static MouseEvent event, prevevent;
474 | int button;
475 |
476 | int timeout = 5*1000; //ms
477 | setsockopt(clientSocket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout));
478 |
479 | MouseEvent versionEvent = {htonl(EVENT_VERSION), htonl(kVersionWindowsCurrent), 0, 0};
480 | send(clientSocket, (const char *)&versionEvent, sizeof(versionEvent), 0);
481 |
482 | while (TRUE) {
483 | int recvsize = recv(clientSocket, (char *)&event, sizeof(event), 0);
484 | if (recvsize == sizeof(event)) {
485 | event.type = ntohl(event.type);
486 | event.value = ntohl(event.value);
487 | event.tv_sec = ntohl(event.tv_sec);
488 | event.tv_nsec = ntohl(event.tv_nsec);
489 |
490 | switch (event.type) {
491 | case EVENT_MOUSE_DELTA_X:
492 | break;
493 | case EVENT_MOUSE_DELTA_Y:
494 | if (prevevent.type == EVENT_MOUSE_DELTA_X)
495 | mouse_event(MOUSEEVENTF_MOVE, prevevent.value, event.value, 0, 0);
496 | break;
497 | case EVENT_MOUSE_DELTA_W:
498 | mouse_event( MOUSEEVENTF_HWHEEL, 0, 0, event.value, 0 );
499 | break;
500 | case EVENT_MOUSE_DELTA_Z:
501 | mouse_event( MOUSEEVENTF_WHEEL, 0, 0, -event.value, 0 );
502 | break;
503 | case EVENT_MOUSE_DOWN:
504 | button = MouseNumber(event.value);
505 | if (button < 0 || kNumButtons <= button)
506 | button = 0;
507 | mouse_event(flagButtonDown[button], 0, 0, dataXButton[button], 0 );
508 | break;
509 | case EVENT_MOUSE_UP:
510 | button = MouseNumber(event.value);
511 | if (button < 0 || kNumButtons <= button)
512 | button = 0;
513 | mouse_event(flagButtonUp[button], 0, 0, dataXButton[button], 0 );
514 | break;
515 | case EVENT_KEY_DOWN:
516 | HandleKeyEvent(event);
517 | break;
518 | case EVENT_KEY_UP:
519 | HandleKeyEvent(event);
520 | break;
521 | case EVENT_ASCII:
522 | SimulateKeyWithUnichar(event);
523 | break;
524 | default:
525 | break;
526 | }
527 | prevevent = event;
528 |
529 | //sending a ACK packet for the winsock 200ms problem
530 | MouseEvent nullEvent = {htonl(EVENT_NULL), 0, 0, 0};
531 | send(clientSocket, (const char *)&nullEvent, sizeof(nullEvent), 0);
532 | } else if (recvsize == 0) {
533 | connectionStatus = statusNotConnected;
534 | break;
535 | } else if (recvsize == SOCKET_ERROR) {
536 | int errorno = WSAGetLastError();
537 | if (errorno == WSAETIMEDOUT) {
538 | // sending a keep-alive packet
539 | MouseEvent nullEvent = {htonl(EVENT_NULL), 0, 0, 0};
540 | send(clientSocket, (const char *)&nullEvent, sizeof(nullEvent), 0);
541 | } else {
542 | connectionStatus = errorno;
543 | break;
544 | }
545 | }
546 | }
547 |
548 | RepaintWindow(hWnd);
549 | Shell_NotifyIcon(NIM_MODIFY, &trayIcon[trayIconNotConnected]);
550 | EnableMenuItem(GetMenu(hWnd), IDM_DISCONNECT, MF_BYCOMMAND | MF_GRAYED);
551 |
552 | shutdown(clientSocket, SD_BOTH);
553 | closesocket(clientSocket);
554 |
555 | _endthread();
556 | return;
557 | }
558 |
559 | void HandleKeyEvent(MouseEvent event) {
560 | unsigned int keycode = LOBYTE(event.value);
561 | byte winKeycode = 0;
562 | switch (keycode) {
563 | case kKeycodeLeft:
564 | winKeycode = VK_LEFT;
565 | break;
566 | case kKeycodeUp:
567 | winKeycode = VK_UP;
568 | break;
569 | case kKeycodeRight:
570 | winKeycode = VK_RIGHT;
571 | break;
572 | case kKeycodeDown:
573 | winKeycode = VK_DOWN;
574 | break;
575 | case kKeycodeBackSpace:
576 | winKeycode = VK_BACK;
577 | break;
578 | case kKeycodeReturn:
579 | winKeycode = VK_RETURN;
580 | break;
581 | default:
582 | MessageBeep(MB_OK);
583 | return;
584 | break;
585 | }
586 | if (event.type == EVENT_KEY_DOWN) {
587 | keybd_event(winKeycode, 0, 0, 0);
588 | } else {
589 | keybd_event(winKeycode, 0, KEYEVENTF_KEYUP, 0);
590 | }
591 | return;
592 | }
593 |
594 | void SimulateKeyWithUnichar(MouseEvent event) {
595 | unsigned int charCode = event.value, mod = 0;
596 | short winKeycode = VkKeyScan(charCode);
597 | if (winKeycode != -1) {
598 | byte bKey = LOBYTE(winKeycode), bMod = HIBYTE(winKeycode);
599 | if (bKey == '\r')
600 | bMod = 0;
601 | if (bMod) {
602 | if (bMod & kWinModifierShift)
603 | keybd_event(VK_SHIFT, 0, 0, 0);
604 | if (bMod & kWinModifierControl)
605 | keybd_event(VK_CONTROL, 0, 0, 0);
606 | if (bMod & kWinModifierAlternate)
607 | keybd_event(VK_MENU, 0, 0, 0);
608 | }
609 | keybd_event(bKey, 0, 0, 0);
610 | if (bMod) {
611 | if (bMod & kWinModifierShift)
612 | keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
613 | if (bMod & kWinModifierControl)
614 | keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
615 | if (bMod & kWinModifierAlternate)
616 | keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
617 | }
618 | keybd_event(bKey, 0, KEYEVENTF_KEYUP, 0);
619 | } else {
620 | MessageBeep(MB_OK);
621 | }
622 | return;
623 | }
624 |
--------------------------------------------------------------------------------
/Windows/RemotePad Server.h:
--------------------------------------------------------------------------------
1 | /*
2 | * RemotePad Server.h
3 | * RemotePad Server
4 | *
5 | * Created by iKawamoto Yosihisa! on 09/03/11.
6 | * Copyright 2009 tenjin.org. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #define IDS_APP_TITLE 103
31 | #define IDS_APP_TITLE_WIN 104
32 | #define IDS_VERSION 105
33 | #define IDS_IP_ADDRESSES 106
34 | #define IDS_PORT 107
35 | #define IDS_STATUS 108
36 | #define IDS_CANNOT_DETECT 109
37 | #define IDS_CONNECTED 110
38 | #define IDS_NOT_CONNECTED 111
39 |
40 | #define IDR_MAINFRAME 128
41 | #define IDD_REMOTEPADSERVER_DIALOG 102
42 | #define IDD_ABOUTBOX 103
43 | #define IDM_ABOUT 104
44 | #define IDM_EXIT 105
45 | #define IDM_TRAY 110
46 | #define IDM_OPEN 111
47 | #define IDM_DISCONNECT 113
48 | #define IDI_REMOTEPADSERVER 107
49 | #define IDI_NOTCONNECTED 108
50 | #define IDI_CONNECTED 112
51 | #define IDC_REMOTEPADSERVER 102
52 | #define IDC_MYICON 2
53 | #ifndef IDC_STATIC
54 | #define IDC_STATIC -1
55 | #endif
56 |
--------------------------------------------------------------------------------
/Windows/RemotePad Server.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/Windows/RemotePad Server.ico
--------------------------------------------------------------------------------
/Windows/RemotePad Server.rc:
--------------------------------------------------------------------------------
1 | /*
2 | * RemotePad Server.rc
3 | * RemotePad Server
4 | *
5 | * Created by iKawamoto Yosihisa! on 09/03/11.
6 | * Copyright 2009 tenjin.org. All rights reserved.
7 | *
8 | * Redistribution and use in source and binary forms, with or without
9 | * modification, are permitted provided that the following conditions
10 | * are met:
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the distribution.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE TENJIN.ORG AND CONTRIBUTORS
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TENJIN.ORG
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #include "RemotePad Server.h"
31 | #include
32 |
33 | IDI_REMOTEPADSERVER ICON "RemotePad Server.ico"
34 | IDI_NOTCONNECTED ICON "icon-notconnected.ico"
35 | IDI_CONNECTED ICON "icon-connected.ico"
36 |
37 | IDC_REMOTEPADSERVER MENU
38 | BEGIN
39 | POPUP "&File"
40 | BEGIN
41 | MENUITEM "&Hide", IDM_TRAY
42 | MENUITEM "&Disconnect", IDM_DISCONNECT
43 | MENUITEM "E&xit", IDM_EXIT
44 | END
45 | POPUP "&Help"
46 | BEGIN
47 | MENUITEM "&About ...", IDM_ABOUT
48 | END
49 | END
50 |
51 | IDC_TRAYMENU MENU
52 | BEGIN
53 | POPUP "dummy"
54 | BEGIN
55 | MENUITEM "&Restore", IDM_OPEN
56 | MENUITEM "&Disconnect", IDM_DISCONNECT
57 | MENUITEM "E&xit", IDM_EXIT
58 | END
59 | END
60 |
61 | IDC_REMOTEPADSERVER ACCELERATORS
62 | BEGIN
63 | "?", IDM_ABOUT, ASCII, ALT
64 | "/", IDM_ABOUT, ASCII, ALT
65 | END
66 |
67 | IDD_ABOUTBOX DIALOGEX 0, 0, 180, 62
68 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
69 | CAPTION "About RemotePad Server"
70 | FONT 8, "MS Shell Dlg"
71 | BEGIN
72 | ICON IDI_REMOTEPADSERVER,IDC_STATIC,14,14,21,20
73 | LTEXT "RemotePad Server, Version 2.0",IDC_STATIC,42,14,134,8,SS_NOPREFIX
74 | LTEXT "Copyright (C) 2009 tenjin.org",IDC_STATIC,42,26,114,8
75 | DEFPUSHBUTTON "OK",IDOK,113,41,50,14,WS_GROUP
76 | END
77 |
78 | STRINGTABLE
79 | BEGIN
80 | IDC_REMOTEPADSERVER "REMOTEPADSERVER"
81 | IDS_APP_TITLE "RemotePad Server"
82 | IDS_APP_TITLE_WIN "RemotePad Server for Windows"
83 | IDS_VERSION "Version:"
84 | IDS_IP_ADDRESSES "Server IP addresses:"
85 | IDS_PORT "Port:"
86 | IDS_STATUS "Connection status:"
87 | IDS_CANNOT_DETECT "cannot detect"
88 | IDS_CONNECTED "connected"
89 | IDS_NOT_CONNECTED "not connected"
90 | END
91 |
--------------------------------------------------------------------------------
/Windows/RemotePad Server.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 10.00
3 | # Visual C++ Express 2008
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RemotePad Server", "RemotePad Server.vcproj", "{B4140637-F5DD-428B-A7C7-F6333EDEC4F8}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Release|Win32 = Release|Win32
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {B4140637-F5DD-428B-A7C7-F6333EDEC4F8}.Debug|Win32.ActiveCfg = Debug|Win32
13 | {B4140637-F5DD-428B-A7C7-F6333EDEC4F8}.Debug|Win32.Build.0 = Debug|Win32
14 | {B4140637-F5DD-428B-A7C7-F6333EDEC4F8}.Release|Win32.ActiveCfg = Release|Win32
15 | {B4140637-F5DD-428B-A7C7-F6333EDEC4F8}.Release|Win32.Build.0 = Release|Win32
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/Windows/RemotePad Server.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
53 |
56 |
59 |
62 |
71 |
74 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
129 |
132 |
135 |
138 |
149 |
152 |
156 |
159 |
162 |
165 |
168 |
171 |
172 |
173 |
174 |
175 |
176 |
181 |
184 |
185 |
186 |
191 |
194 |
195 |
198 |
199 |
202 |
203 |
204 |
209 |
212 |
213 |
216 |
217 |
220 |
221 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
--------------------------------------------------------------------------------
/Windows/icon-connected.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/Windows/icon-connected.ico
--------------------------------------------------------------------------------
/Windows/icon-notconnected.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/Windows/icon-notconnected.ico
--------------------------------------------------------------------------------
/Windows/icon.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ussjoin/remotepad/3c024d93062864e9b665ce19a31095e1e6a480fe/Windows/icon.xcf
--------------------------------------------------------------------------------
/X11/Imakefile:
--------------------------------------------------------------------------------
1 | NAME = remotepad
2 | SRCS = $(NAME).c ucs2keysym.c
3 | OBJS = $(NAME).o ucs2keysym.o
4 | CFLAGS = -I ../Common
5 | LOCAL_LIBRARIES = -lX11 -lXtst -lm
6 | BINDIR = /usr/local/bin
7 | ComplexProgramTargetNoMan($(NAME))
8 |
--------------------------------------------------------------------------------
/X11/Makefile:
--------------------------------------------------------------------------------
1 | CC= gcc
2 | CFLAGS= -g -O2 -l/usr/X11R6/include -l/usr/X11R7/include -I/usr/X11/include -I../Common
3 | LDFLAGS= -L/usr/X11R6/lib -L/usr/X11R7/lib -L/usr/X11/lib -lXtst -lX11 -lm
4 | exec_prefix= ${prefix}
5 | prefix= /usr/local
6 | BINDIR= ${exec_prefix}/bin
7 |
8 | PROGNAME= remotepad
9 | OBJS= $(PROGNAME).o ucs2keysym.o
10 |
11 | all: $(PROGNAME)
12 |
13 | $(PROGNAME): $(OBJS)
14 | $(CC) $(LDFLAGS) -o $(PROGNAME) $(OBJS)
15 |
16 | .c.o:
17 | $(CC) $(CFLAGS) -c -o $@ $^$(.ALLSRC)
18 |
19 | install: $(PROGNAME)
20 | cp $(PROGNAME) $(BINDIR)
21 |
22 | clean:
23 | rm -f $(PROGNAME) $(OBJS)
24 |
25 | distclean:
26 | rm -rf $(PROGNAME) $(OBJS) config.h config.log config.status Makefile.bak autom4te.cache .deps
27 |
--------------------------------------------------------------------------------
/X11/Makefile.in:
--------------------------------------------------------------------------------
1 | CC= @CC@
2 | CFLAGS= @CFLAGS@ @X_CFLAGS@ -I../Common
3 | LDFLAGS= @X_LIBS@ @LIBS@
4 | exec_prefix= @exec_prefix@
5 | prefix= @prefix@
6 | BINDIR= @bindir@
7 |
8 | PROGNAME= remotepad
9 | OBJS= $(PROGNAME).o ucs2keysym.o
10 |
11 | all: $(PROGNAME)
12 |
13 | $(PROGNAME): $(OBJS)
14 | $(CC) $(LDFLAGS) -o $(PROGNAME) $(OBJS)
15 |
16 | .c.o:
17 | $(CC) $(CFLAGS) -c -o $@ $^$(.ALLSRC)
18 |
19 | install: $(PROGNAME)
20 | cp $(PROGNAME) $(BINDIR)
21 |
22 | clean:
23 | rm -f $(PROGNAME) $(OBJS)
24 |
25 | distclean:
26 | rm -rf $(PROGNAME) $(OBJS) config.h config.log config.status Makefile.bak autom4te.cache .deps
27 |
--------------------------------------------------------------------------------
/X11/config.h.in:
--------------------------------------------------------------------------------
1 | /* config.h.in. Generated from configure.ac by autoheader. */
2 |
3 | /* Define to 1 if you have the header file. */
4 | #undef HAVE_INTTYPES_H
5 |
6 | /* Define to 1 if you have the `m' library (-lm). */
7 | #undef HAVE_LIBM
8 |
9 | /* Define to 1 if you have the `X11' library (-lX11). */
10 | #undef HAVE_LIBX11
11 |
12 | /* Define to 1 if you have the `Xtst' library (-lXtst). */
13 | #undef HAVE_LIBXTST
14 |
15 | /* Define to 1 if you have the header file. */
16 | #undef HAVE_MEMORY_H
17 |
18 | /* Define to 1 if you have the header file. */
19 | #undef HAVE_STDINT_H
20 |
21 | /* Define to 1 if you have the header file. */
22 | #undef HAVE_STDLIB_H
23 |
24 | /* Define to 1 if you have the header file. */
25 | #undef HAVE_STRINGS_H
26 |
27 | /* Define to 1 if you have the header file. */
28 | #undef HAVE_STRING_H
29 |
30 | /* Define to 1 if `sa_len' is member of `struct sockaddr'. */
31 | #undef HAVE_STRUCT_SOCKADDR_SA_LEN
32 |
33 | /* Define to 1 if you have the header file. */
34 | #undef HAVE_SYS_STAT_H
35 |
36 | /* Define to 1 if you have the header file. */
37 | #undef HAVE_SYS_TYPES_H
38 |
39 | /* Define to 1 if you have the header file. */
40 | #undef HAVE_UNISTD_H
41 |
42 | /* Define to the address where bug reports for this package should be sent. */
43 | #undef PACKAGE_BUGREPORT
44 |
45 | /* Define to the full name of this package. */
46 | #undef PACKAGE_NAME
47 |
48 | /* Define to the full name and version of this package. */
49 | #undef PACKAGE_STRING
50 |
51 | /* Define to the one symbol short name of this package. */
52 | #undef PACKAGE_TARNAME
53 |
54 | /* Define to the version of this package. */
55 | #undef PACKAGE_VERSION
56 |
57 | /* Define to 1 if you have the ANSI C header files. */
58 | #undef STDC_HEADERS
59 |
60 | /* Define to 1 if the X Window System is missing or not being used. */
61 | #undef X_DISPLAY_MISSING
62 |
--------------------------------------------------------------------------------
/X11/configure.ac:
--------------------------------------------------------------------------------
1 | AC_INIT(remotepad.c)
2 | AC_PROG_CC
3 | AC_PATH_XTRA
4 | AC_CHECK_LIB(m, sqrt)
5 | CPPFLAGS="$CPPFLAGS $X_CFLAGS"
6 | AC_CHECK_MEMBERS([struct sockaddr.sa_len],,,[
7 | #include
8 | #include
9 | ])
10 | AC_CHECK_HEADER(X11/Xlib.h, AC_CHECK_LIB(X11, XOpenDisplay, , AC_MSG_ERROR([X Window System is required.]), $X_LIBS), AC_MSG_ERROR([X Window System is required.]))
11 | AC_CHECK_HEADER(X11/extensions/XTest.h, AC_CHECK_LIB(Xtst, XTestQueryExtension, , AC_MSG_ERROR([XTest extension development library is required. Please install a package libXtst-dev or libXtst-devel or x11/libXtst.]), $X_LIBS), AC_MSG_ERROR([XTest extension development library is required. Please install a package libXtst-dev or libXtst-devel or x11/libXtst.]))
12 | AC_CONFIG_HEADER(config.h)
13 | AC_CONFIG_FILES(Makefile)
14 | AC_OUTPUT
15 |
--------------------------------------------------------------------------------
/X11/remotepad.c:
--------------------------------------------------------------------------------
1 | /*
2 | * remotepad.c
3 | * RemotePad Server
4 | *
5 | * Derived from itp-server.c
6 | * Modified by iKawamoto Yosihisa! on 08/09/05.
7 | * Copyright 2008, 2009 tenjin.org. All rights reserved.
8 | *
9 | */
10 |
11 | /*
12 | * =====================================================================================
13 | *
14 | * Filename: itp-server.c
15 | *
16 | * Description: itp-server --listens for a itp client and accepts mouse requests..
17 | *
18 | * Version: 1.0
19 | * Created: 02/18/2008 09:18:12 PM
20 | *
21 | * Author: Will Dietz (WD), wdietz2@uiuc.edu
22 | * Company: dtzTech
23 | *
24 | * =====================================================================================
25 | */
26 |
27 | /*
28 | This file is part of iTouchpad.
29 |
30 | iTouchpad is free software: you can redistribute it and/or modify
31 | it under the terms of the GNU General Public License as published by
32 | the Free Software Foundation, either version 3 of the License, or
33 | (at your option) any later version.
34 |
35 | iTouchpad is distributed in the hope that it will be useful,
36 | but WITHOUT ANY WARRANTY; without even the implied warranty of
37 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 | GNU General Public License for more details.
39 |
40 | You should have received a copy of the GNU General Public License
41 | along with iTouchpad. If not, see .
42 |
43 | */
44 |
45 | #include
46 | #include
47 | #include
48 | #include
49 | #include
50 | #include
51 | #include
52 | #include
53 | #include
54 | #include
55 | #include
56 | #include
57 | #include
58 | #include
59 | #include
60 | #include
61 | #include
62 | #include
63 |
64 | #include "config.h"
65 | #include "inputevent.h"
66 | #include "Event.h"
67 | #include "Version.h"
68 |
69 | #define SCROLL_AMT 40
70 | #define BUTTON_SCROLL_UP Button5
71 | #define BUTTON_SCROLL_DOWN Button4
72 |
73 | #define NButtons 5
74 | int ButtonNumber[NButtons] = {Button1, Button3, Button2, Button4, Button5};
75 |
76 | #if !defined(INADDR_LOOPBACK)
77 | #define INADDR_LOOPBACK (uint32_t)0x7f000001
78 | #endif
79 |
80 | KeySym *keyboardMapping;
81 | int minKeycode, maxKeycode;
82 | int keysymsPerKeycode;
83 |
84 | typedef int SOCKET;
85 |
86 |
87 | /*-----------------------------------------------------------------------------
88 | * Local method declarations
89 | *-----------------------------------------------------------------------------*/
90 | void handleKeyEvent( Display * dpy, MouseEvent *pEvent );
91 | void simulateKeyWithUnichar(Display *dpy, MouseEvent *pEvent);
92 | KeySym ucs2keysym(long ucs);
93 | int findInterfaceAddresses(SOCKET sockfd);
94 |
95 | int main( int argc, char ** argv)
96 | {
97 | MouseEvent event, prevevent;
98 | MouseEvent *pEvent = &event;
99 | prevevent.type = EVENT_NULL;
100 | prevevent.value = 0;
101 |
102 | Display *dpy; /* X server connection */
103 | Window win;
104 | XWindowAttributes winattr;
105 | int xtest_major_version = 0;
106 | int xtest_minor_version = 0;
107 | int dummy;
108 |
109 | SOCKET s, s_accept;
110 | struct sockaddr_in s_add; //from anyone!
111 | struct sockaddr s_client;
112 | socklen_t s_client_size = sizeof( struct sockaddr );
113 | int port = PORT;
114 | int recvsize;
115 |
116 | int button, yDelta = 0, yTmp;
117 |
118 | printf("RemotePad Server for X11 version %s\n", kVersionX11);
119 | printf("Application launched.\n");
120 |
121 | /*
122 | * Open the display using the $DISPLAY environment variable to locate
123 | * the X server. See Section 2.1.
124 | */
125 | if ((dpy = XOpenDisplay(NULL)) == NULL) {
126 | printf("%s: can't open DISPLAY: %s\n", argv[0], XDisplayName(NULL));
127 | exit(1);
128 | }
129 |
130 | Bool success = XTestQueryExtension(dpy, &dummy, &dummy,
131 | &xtest_major_version, &xtest_minor_version);
132 | if(success == False || xtest_major_version < 2 ||
133 | (xtest_major_version <= 2 && xtest_minor_version < 2))
134 | {
135 | printf("XTEST extension not supported\n");
136 | exit(1);
137 | }
138 |
139 | /*
140 | * create a small unmapped window on a screen just so xdm can use
141 | * it as a handle on which to killclient() us.
142 | */
143 | win = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, 0, (XSetWindowAttributes*)0);
144 |
145 | /*
146 | * get keyboard mapping to detect modifier keys for each keysym
147 | */
148 | XDisplayKeycodes(dpy, &minKeycode, &maxKeycode);
149 | int keycodeCount = maxKeycode - minKeycode + 1;
150 | keyboardMapping = XGetKeyboardMapping(dpy, minKeycode, keycodeCount, &keysymsPerKeycode);
151 |
152 | //network stuff
153 | //configure socket
154 | if ( ( s = socket( PF_INET, SOCK_STREAM, 0 ) ) == -1 )
155 | {
156 | perror ( "Failed to create socket :(" );
157 | exit( 2 );
158 |
159 | }
160 |
161 | int yes = 1;
162 | setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
163 | memset( &s_add, 0, sizeof( struct sockaddr_in ) );
164 | s_add.sin_family = AF_INET;
165 | s_add.sin_port = htons( port );
166 | s_add.sin_addr.s_addr = INADDR_ANY;
167 |
168 | if ( bind( s, (struct sockaddr * )&s_add, sizeof( struct sockaddr_in ) ) == -1 )
169 | {
170 | perror( "Failed to bind socket" );
171 | exit( 2 );
172 | }
173 |
174 | if( listen( s , 1 ) )
175 | {
176 | perror( "Can't listen!" );
177 | exit( 2 );
178 | }
179 |
180 | while( 1 )
181 | {
182 | if(!findInterfaceAddresses(s))
183 | printf("waiting for clients\n");
184 |
185 | struct timeval tv;
186 | while (1) {
187 | fd_set fdset;
188 | FD_ZERO(&fdset);
189 | FD_SET(s, &fdset);
190 | tv.tv_sec = 5;
191 | tv.tv_usec = 0;
192 | select(s+1, &fdset, NULL, NULL, &tv);
193 | if (FD_ISSET(s, &fdset))
194 | break;
195 | // sending a keep-alive event for an X server
196 | XGetWindowAttributes(dpy, win, &winattr);
197 | }
198 |
199 | s_accept = accept( s, &s_client, &s_client_size );
200 |
201 | if ( s_accept == -1 )
202 | {
203 | perror( "failed to accept!" );
204 | return -1;
205 | } else {
206 | printf("Connected!\n");
207 | }
208 |
209 | tv.tv_sec = 5;
210 | tv.tv_usec = 0;
211 | setsockopt(s_accept, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(tv));
212 |
213 | gettimeofday(&tv, NULL);
214 | MouseEvent versionEvent = {htonl(EVENT_VERSION), htonl(kVersionX11Current), htonl(tv.tv_sec), htonl(tv.tv_usec*1000)};
215 | send(s_accept, (void *)&versionEvent, sizeof(MouseEvent), 0);
216 |
217 | while( 1 )
218 | {
219 | recvsize = recv( s_accept, pEvent, sizeof( MouseEvent ), MSG_WAITALL );
220 | if ( recvsize == sizeof( MouseEvent ) )//got data
221 | {
222 | event.type = ntohl(event.type);
223 | event.value = ntohl(event.value);
224 | event.tv_sec = ntohl(event.tv_sec);
225 | event.tv_nsec = ntohl(event.tv_nsec);
226 |
227 | switch( event.type )
228 | {
229 |
230 | case EVENT_MOUSE_DELTA_X:
231 | // following event should be EVENT_MOUSE_DELTA_Y
232 | break;
233 | case EVENT_MOUSE_DELTA_Y:
234 | // printf( "move: %d, %d!\n", pEvent->move_info.dx, pEvent->move_info.dy );
235 | if (prevevent.type == EVENT_MOUSE_DELTA_X) {
236 | XTestFakeRelativeMotionEvent( dpy, prevevent.value, event.value, 0 );
237 | } else {
238 | // printf( "stray event EVENT_MOUSE_DELTA_Y\n" );
239 | }
240 |
241 | break;
242 | case EVENT_MOUSE_DELTA_W:
243 | //no x-scrolling :-/
244 | break;
245 | case EVENT_MOUSE_DELTA_Z:
246 | //no x-scrolling :-/
247 | yDelta += event.value;
248 | if ( yDelta < 0 )//down
249 | {
250 | button = BUTTON_SCROLL_DOWN;
251 | yTmp = - yDelta;
252 | }
253 | else
254 | {
255 | button = BUTTON_SCROLL_UP;
256 | yTmp = yDelta;
257 | }
258 |
259 | // send as many clicks as necessary (ty synergy for this)
260 | for( ; yTmp >= SCROLL_AMT; yTmp -= SCROLL_AMT )
261 | {
262 | XTestFakeButtonEvent( dpy, button, 1, 0 );
263 | XTestFakeButtonEvent( dpy, button, 0, 0 );
264 | }
265 |
266 | //fix yTmp:
267 | if ( yDelta < 0 )//we were scrolling down
268 | {
269 | yDelta = -yTmp;
270 | }
271 | else
272 | {
273 | yDelta = yTmp;
274 | }
275 |
276 | break;
277 |
278 | case EVENT_MOUSE_DOWN:
279 | //printf( "mouse down: %d", pEvent->button_info.button );
280 | button = ButtonNumber[MouseNumber(event.value) % NButtons];
281 | XTestFakeButtonEvent( dpy, button, 1, 0 );
282 | break;
283 |
284 | case EVENT_MOUSE_UP:
285 | //printf( "mouse up: %d", pEvent->button_info.button );
286 | button = ButtonNumber[MouseNumber(event.value) % NButtons];
287 | XTestFakeButtonEvent( dpy, button, 0, 0 );
288 | break;
289 |
290 | case EVENT_KEY_UP:
291 | case EVENT_KEY_DOWN:
292 | handleKeyEvent( dpy, pEvent );
293 | break;
294 |
295 | case EVENT_ASCII:
296 | simulateKeyWithUnichar(dpy, pEvent);
297 | break;
298 |
299 | default:
300 | //printf( "unknown message type: %d\n", event.type );
301 | break;
302 | }
303 | prevevent = event;
304 |
305 | XFlush( dpy );
306 |
307 | }
308 | else if ( recvsize > 0 )
309 | {
310 | // printf( "partial recv!\n" );
311 | }
312 | else if ( recvsize == 0 )
313 | {
314 | //connection terminated
315 | close( s_accept );
316 | break; //exit this while loop, wait for another connection
317 | }
318 | else if (errno == EAGAIN) {
319 | // sending a keep-alive event for an X server
320 | XGetWindowAttributes(dpy, win, &winattr);
321 | // sending a keep-alive packet
322 | struct timeval tv;
323 | gettimeofday(&tv, NULL);
324 | MouseEvent event = {htonl(EVENT_NULL), 0, htonl(tv.tv_sec), htonl(tv.tv_usec*1000)};
325 | send(s_accept, (void *)&event, sizeof(event), 0);
326 | }
327 | else
328 | {
329 | perror( "error in recv" );
330 | shutdown(s_accept, SHUT_RDWR);
331 | close(s_accept);
332 | break;
333 | }
334 | }
335 |
336 | printf("Disconnected!\n");
337 |
338 | }
339 |
340 | //shouldn't get here!
341 |
342 | return 0;
343 | }
344 |
345 | void handleKeyEvent(Display * dpy, MouseEvent *pEvent) {
346 | unsigned int keycode = pEvent->value & 0xff;
347 | int keysym;
348 | switch (keycode) {
349 | case kKeycodeLeft:
350 | keysym = XK_Left;
351 | break;
352 | case kKeycodeRight:
353 | keysym = XK_Right;
354 | break;
355 | case kKeycodeDown:
356 | keysym = XK_Down;
357 | break;
358 | case kKeycodeUp:
359 | keysym = XK_Up;
360 | break;
361 | case kKeycodeBackSpace:
362 | keysym = XK_BackSpace;
363 | break;
364 | case kKeycodeReturn:
365 | keysym = XK_Return;
366 | break;
367 | default:
368 | XBell(dpy, 100);
369 | return;
370 | break;
371 | }
372 | KeyCode x11Keycode = XKeysymToKeycode(dpy, keysym);
373 | if (x11Keycode != 0) {
374 | XTestFakeKeyEvent(dpy, x11Keycode, pEvent->type == EVENT_KEY_DOWN, 0);
375 | }
376 | }
377 |
378 | void simulateKeyWithUnichar(Display *dpy, MouseEvent *pEvent) {
379 | #define kNumModifierKeyState 4
380 | uint32_t modifierKeyStates[kNumModifierKeyState] = {0, kX11ModifierShift, kX11ModifierMod1, kX11ModifierShift | kX11ModifierMod1};
381 | KeySym keysym = ucs2keysym(pEvent->value);
382 | KeyCode x11Keycode = XKeysymToKeycode(dpy, keysym);
383 | if (x11Keycode != 0) {
384 | int modifierIndex = 0;
385 | for (modifierIndex = 0; modifierIndex < kNumModifierKeyState; modifierIndex++)
386 | if (keyboardMapping[(x11Keycode - minKeycode) * keysymsPerKeycode + modifierIndex] == keysym)
387 | break;
388 | if (modifierIndex == kNumModifierKeyState)
389 | modifierIndex = 0;
390 | KeyCode shiftKeycode = 0, mod1Keycode = 0;
391 | if (modifierKeyStates[modifierIndex] & kX11ModifierShift) {
392 | shiftKeycode = XKeysymToKeycode(dpy, XK_Shift_L);
393 | if (shiftKeycode == 0)
394 | shiftKeycode = XKeysymToKeycode(dpy, XK_Shift_R);
395 | }
396 | if (modifierKeyStates[modifierIndex] & kX11ModifierMod1)
397 | mod1Keycode = XKeysymToKeycode(dpy, XK_Mode_switch);
398 | if (shiftKeycode)
399 | XTestFakeKeyEvent(dpy, shiftKeycode, True, 0);
400 | if (mod1Keycode)
401 | XTestFakeKeyEvent(dpy, mod1Keycode, True, 0);
402 | XTestFakeKeyEvent(dpy, x11Keycode, True, 0);
403 | if (shiftKeycode)
404 | XTestFakeKeyEvent(dpy, shiftKeycode, False, 0);
405 | if (mod1Keycode)
406 | XTestFakeKeyEvent(dpy, mod1Keycode, False, 0);
407 | XTestFakeKeyEvent(dpy, x11Keycode, False, 0);
408 | }
409 | }
410 |
411 | int findInterfaceAddresses(SOCKET sockfd) {
412 | struct ifconf ifc;
413 | struct ifreq *ifr, ifrcopy;
414 | int lastlen = 0;
415 | int len = 32 * sizeof(struct ifreq);
416 | char *buf, addr[128], *ptr;
417 | for (;;) {
418 | buf = malloc(len);
419 | if (buf == NULL)
420 | return 0; // not found
421 | ifc.ifc_len = len;
422 | ifc.ifc_buf = buf;
423 | if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
424 | if (errno != EINVAL || lastlen != 0) {
425 | free(buf);
426 | return 0; // not found
427 | }
428 | } else {
429 | if (ifc.ifc_len == lastlen)
430 | break;
431 | lastlen = ifc.ifc_len;
432 | }
433 | len = len * 2;
434 | free(buf);
435 | }
436 | int result = 0; // not found
437 | char *or = "enter ";
438 | for (ptr = buf; ptr < buf + ifc.ifc_len; ) {
439 | ifr = (struct ifreq *)ptr;
440 | #if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
441 | len = (sizeof(struct sockaddr) > ifr->ifr_addr.sa_len) ? sizeof(struct sockaddr) : ifr->ifr_addr.sa_len;
442 | #else
443 | len = sizeof(struct sockaddr);
444 | #endif
445 | ptr += sizeof(ifr->ifr_name) + len;
446 | if (ifr->ifr_addr.sa_family != AF_INET)
447 | continue;
448 | ifrcopy = *ifr;
449 | ioctl(sockfd, SIOCGIFFLAGS, &ifrcopy);
450 | if ((ifrcopy.ifr_flags & IFF_UP) == 0)
451 | continue;
452 | struct sockaddr_in *sin = (struct sockaddr_in *)&ifrcopy.ifr_addr;
453 | if (sin->sin_addr.s_addr != htonl(INADDR_LOOPBACK)) {
454 | printf("%s%s ", or, inet_ntop(AF_INET, &sin->sin_addr, addr, sizeof(addr)));
455 | result = 1; // found
456 | or = "or ";
457 | }
458 | }
459 | if (result)
460 | printf("in your iPhone/iPod touch.\n");
461 | free(buf);
462 | return result;
463 | }
464 |
--------------------------------------------------------------------------------