Skip to content

Commit

Permalink
initial new UI, add reset option
Browse files Browse the repository at this point in the history
  • Loading branch information
vgmoose committed Dec 27, 2020
1 parent 4b456a1 commit 6d64807
Show file tree
Hide file tree
Showing 16 changed files with 325 additions and 105 deletions.
30 changes: 30 additions & 0 deletions GlassController/ActionRowView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import SwiftUI

struct ActionRowView: View {
var body: some View {
HStack(alignment: .center) {
HStack() {
VStack(alignment: .leading) {
Text("5 Finger Swipe Down")
.fontWeight(.bold)
.truncationMode(.tail)
Text("Global Gesture (Anywhere)")
.font(.caption)
.opacity(0.75)
.truncationMode(.middle)
}
Spacer()
Text("⌃⌘⌥M")
.font(.system(size: 20))
.frame(minWidth: 100)
}.frame(maxWidth: 350)
}
}
}


struct ActionRowView_Previews: PreviewProvider {
static var previews: some View {
ActionRowView()
}
}
11 changes: 11 additions & 0 deletions GlassController/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
58 changes: 58 additions & 0 deletions GlassController/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions GlassController/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
37 changes: 37 additions & 0 deletions GlassController/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import SwiftUI

let food = ["Spaghetti", "Cheese Burger", "Pizza", "Fried Rice", "Spaghetti", "Cheese Burger", "Pizza", "Fried Rice"]

func delete(index: IndexSet) {
print("Deleted")
}

struct ContentView: View {
var body: some View {
Text("This app allows you to configure different actions (such as key bindings) depending on gestures/input from the touchpad.").padding()
Button(action: {
print("ello")
}) {
Text("License")
}.padding()
HStack() {
Text("Select Profile")
// Dropdown(["hi", "no"])
}
Text("Actions in this Profile")
.font(.system(size: 16))
.bold()
ScrollView(.horizontal) {
ForEach(food, id: \.self) { data in
ActionRowView().padding()
}
}
.padding()
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
10 changes: 10 additions & 0 deletions GlassController/GlassController.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>
10 changes: 10 additions & 0 deletions GlassController/GlassControllerApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SwiftUI

@main
struct GlassControllerApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
24 changes: 24 additions & 0 deletions GlassController/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions glass/GlassPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ class GlassPreferences : NSWindow, NSTableViewDelegate, NSTableViewDataSource
@objc static func switchProfile1() { GlassPreferences.switchProfileCommon(0) }
@objc static func switchProfile2() { GlassPreferences.switchProfileCommon(1) }
@objc static func switchProfile3() { GlassPreferences.switchProfileCommon(2) }

@objc static func restartListeners()
{
Process.launchedProcess(launchPath: Bundle.main.executablePath!, arguments: [])
NSApp.terminate(self)
}

static func loadProfileSlots() {

Expand Down
76 changes: 0 additions & 76 deletions glass/GlassView.swift
Original file line number Diff line number Diff line change
@@ -1,82 +1,6 @@
import Foundation
import AppKit

public func processTouchpadData(_ device: Int32, _ data: Optional<UnsafeMutablePointer<Finger>>, _ nFingers: Int32, _ timestamp: Double, _ frame: Int32) -> Int32
{
let fingers = Array(UnsafeBufferPointer(start: data, count: Int(nFingers)))

view.fingers = fingers
view.refresh()

// newly pressed value
var pressed:Set<Result> = Set()

var xAvg: Double = 0
var yAvg: Double = 0

// if it's the first region, send an S
for finger in fingers
{
let xpos = Double(finger.normalized.pos.x)
let ypos = Double(finger.normalized.pos.y)

for action in glassView.regions
{
let region = action.activator as! Region

if region.intersects(xpos, ypos, region.x, region.y - region.height, region.x + region.width, region.y)
&& action.context.valid()
{
pressed.insert(action.result)
}
}

xAvg += xpos
yAvg += ypos
}

xAvg /= Double(fingers.count)
yAvg /= Double(fingers.count)

// try to detect any gestures using the average of all the points
for action in glassView.gestures
{
let gesture = action.activator as! Gesture

// if the current conditions match the gesture
if gesture.matches(xAvg, yAvg, fingers.count) && action.context.valid()
{
pressed.insert(action.result)
}
}

// clone the newly pressed array to prepare for the subtractions below
let pressedClone = Set(pressed)

// remove the overlap of old pressed from the new, to get just the new
pressed.subtract(view.pressed)
let newlyPressed = pressed

// remove the overlap of new pressed from the old, to get just the old
view.pressed.subtract(pressedClone)
let newlyReleased = view.pressed

// press down any new keys that we saw
for key in newlyPressed {
view.sendKey(key, true)
}

// release any old keys that we didn't see
for key in newlyReleased {
view.sendKey(key, false)
}

// update which keys are down right nowsss
view.pressed = pressedClone

return 0;
}

class GlassView : NSView
{
var fingers: [Finger] = []
Expand Down
1 change: 1 addition & 0 deletions glass/MultitouchSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ typedef int (*MTContactCallbackFunction)(int,Finger*,int,double,int);
MTDeviceRef MTDeviceCreateDefault(void);
void MTRegisterContactFrameCallback(MTDeviceRef, MTContactCallbackFunction);
void MTDeviceStart(MTDeviceRef, int); // thanks comex
void MTDeviceStop(MTDeviceRef);
22 changes: 12 additions & 10 deletions glass/Results/KeyBinding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ class KeyBinding : Result

override func invoke(_ enabled: Bool)
{
let inputKeyCode = CGKeyCode(self.code)
let event = CGEvent(keyboardEventSource: nil, virtualKey: inputKeyCode, keyDown: enabled)
var modifiers: CGEventFlags = CGEventFlags(rawValue: 0)

for opt in self.opts
DispatchQueue.main.sync
{
modifiers.insert(self.resolveModifier(opt))
let inputKeyCode = CGKeyCode(self.code)
let event = CGEvent(keyboardEventSource: nil, virtualKey: inputKeyCode, keyDown: enabled)
var modifiers: CGEventFlags = CGEventFlags(rawValue: 0)

for opt in self.opts
{
modifiers.insert(self.resolveModifier(opt))
}

event!.flags = modifiers
event!.post(tap: .cghidEventTap)
}

event!.flags = modifiers
event!.post(tap: .cghidEventTap)

}

override func serialize() -> [String: Any]?
Expand Down
40 changes: 22 additions & 18 deletions glass/Results/MouseClick.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,29 @@ class MouseClick : Result
// we fire all at once here, don't care when teh gesture ends
return
}
let cur = CGEvent(source: nil);
let point = cur!.location;

let eventDown = CGEvent(mouseEventSource: nil, mouseType: .otherMouseDown, mouseCursorPosition: point, mouseButton: button)
let eventUp = CGEvent(mouseEventSource: nil, mouseType: .otherMouseUp, mouseCursorPosition: point, mouseButton: button)

DispatchQueue.main.sync
{
let cur = CGEvent(source: nil);
let point = cur!.location;

let eventDown = CGEvent(mouseEventSource: nil, mouseType: .otherMouseDown, mouseCursorPosition: point, mouseButton: button)
let eventUp = CGEvent(mouseEventSource: nil, mouseType: .otherMouseUp, mouseCursorPosition: point, mouseButton: button)


var modifiers: CGEventFlags = CGEventFlags(rawValue: 0)

for opt in self.opts
{
modifiers.insert(self.resolveModifier(opt))
}

eventDown!.flags = modifiers
eventDown!.post(tap: .cghidEventTap)

eventUp!.flags = modifiers
eventUp!.post(tap: .cghidEventTap)

var modifiers: CGEventFlags = CGEventFlags(rawValue: 0)

for opt in self.opts
{
modifiers.insert(self.resolveModifier(opt))
}

eventDown!.flags = modifiers
eventDown!.post(tap: .cghidEventTap)

eventUp!.flags = modifiers
eventUp!.post(tap: .cghidEventTap)
}

}

Expand Down
Loading

0 comments on commit 6d64807

Please sign in to comment.