Skip to content

Commit

Permalink
fix menu bar, more new UI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vgmoose committed Oct 30, 2021
1 parent 93675b0 commit 300dfda
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 42 deletions.
4 changes: 4 additions & 0 deletions GlassCon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 2;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_ASSET_PATHS = "\"GlassController/Preview Content\"";
DEVELOPMENT_TEAM = 9UDT7LSCEF;
Expand All @@ -373,6 +374,7 @@
INFOPLIST_FILE = GlassController/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -426,6 +428,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 2;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = "\"GlassController/Preview Content\"";
DEVELOPMENT_TEAM = 9UDT7LSCEF;
Expand All @@ -444,6 +447,7 @@
INFOPLIST_FILE = GlassController/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = llc.newt.apps.glass;
Expand Down
19 changes: 15 additions & 4 deletions GlassController/ActionRowView.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import SwiftUI

struct ActionRowView: View {
let action: Action

init(action: Action) {
self.action = action
}

var body: some View {
HStack(alignment: .center) {
HStack() {
VStack(alignment: .leading) {
Text("5 Finger Swipe Down")
Text(action.activator.toString())
.fontWeight(.bold)
.truncationMode(.tail)
Text("Global Gesture (Anywhere)")
Text(action.context.toString())
.font(.caption)
.opacity(0.75)
.truncationMode(.middle)
}
Spacer()
Text("⌃⌘⌥M")
Text(action.result.toString())
.font(.system(size: 20))
.frame(minWidth: 100)
}.frame(maxWidth: 350)
Expand All @@ -25,6 +31,11 @@ struct ActionRowView: View {

struct ActionRowView_Previews: PreviewProvider {
static var previews: some View {
ActionRowView()
ActionRowView(
action: Action(
KeyBinding(10),
Gesture(Gesture.UP, 4)
)
)
}
}
22 changes: 16 additions & 6 deletions GlassController/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ func delete(index: IndexSet) {
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 {
Button(action: {
GlassDelegate.glassView!.showGlass()
}) {
Text("Touchpad Preview")
}.padding()
Button(action: {
NSWorkspace.shared.open(URL(string: "https://github.com/vgmoose/GlassController")!)
}) {
Text("Source Code")
}.padding()
}
HStack() {
Text("Select Profile")
// Dropdown(["hi", "no"])
Expand All @@ -23,7 +30,10 @@ struct ContentView: View {
.bold()
ScrollView(.horizontal) {
ForEach(food, id: \.self) { data in
ActionRowView().padding()
ActionRowView(action: Action(
KeyBinding(10),
Gesture(Gesture.UP, 4)
)).padding()
}
}
.padding()
Expand Down
6 changes: 5 additions & 1 deletion GlassController/GlassControllerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ struct GlassControllerApp: App {
@NSApplicationDelegateAdaptor(GlassDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
ZStack {
EmptyView()
}
.hidden()
// ContentView()
}
}
}
42 changes: 25 additions & 17 deletions GlassController/GlassDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class GlassDelegate : NSObject, NSApplicationDelegate
var glassEnabled = true

var menuBar: NSMenu?
var statusItem: NSStatusItem?

override init(){
super.init()
Expand Down Expand Up @@ -51,12 +52,17 @@ class GlassDelegate : NSObject, NSApplicationDelegate

func showPreviewWindow()
{
// window already being displayed, return
if previewWindow != nil { return }
// window already created, show it
if let pw = previewWindow {
pw.makeKeyAndOrderFront(nil)
return
}

let window = NSWindow(contentRect: frameRect, styleMask: [.titled, .closable], backing: .buffered, defer: false)
previewWindow = window;

window.isReleasedWhenClosed = false

view!.isHidden = false
view!.needsDisplay = true
window.contentView = view!
Expand All @@ -78,51 +84,53 @@ class GlassDelegate : NSObject, NSApplicationDelegate

func setupMenuBar()
{
menuBar = NSMenu()
menuBar = NSApplication.shared.mainMenu
let appMenuItem = NSMenuItem()
menuBar!.addItem(appMenuItem)

let appMenu = NSMenu()
enabledMenuButton.state = getActivationState()
enabledMenuButton.target = GlassPreferences.self
appMenu.addItem(enabledMenuButton)

let preferencesButton = NSMenuItem(title: "Preferences", action: #selector(GlassPreferences.showConfigWindow), keyEquivalent: "")
preferencesButton.target = GlassPreferences.self
appMenu.addItem(preferencesButton)

// let previewButton = NSMenuItem(title: "Touchpad Preview", action: #selector(glassView.showGlass), keyEquivalent: "")
// previewButton.target = glassView
// appMenu.addItem(previewButton)

appMenu.addItem(NSMenuItem.separator())

let selectors = [#selector(GlassPreferences.switchProfile1),
#selector(GlassPreferences.switchProfile2),
#selector(GlassPreferences.switchProfile3)]

for x in 0..<3 {
let item = NSMenuItem(title: GlassPreferences.slotNames[x], action: selectors[x], keyEquivalent: "")
item.target = GlassPreferences.self
profileItems.append(item)
appMenu.addItem(item)
}

appMenu.addItem(NSMenuItem.separator())


let item = NSMenuItem(title: "Restart", action: #selector(GlassPreferences.restartListeners), keyEquivalent: "")
item.target = GlassPreferences.self
appMenu.addItem(item)

appMenu.addItem(NSMenuItem(title: "Quit", action: Selector("terminate:"), keyEquivalent: ""))

appMenuItem.submenu = appMenu

let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
statusItem.button!.title = "🔳"
statusItem.button!.sizeToFit()
statusItem.menu = appMenu
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
statusItem!.button!.title = "🔳"
statusItem!.button!.sizeToFit()
statusItem!.isVisible = true
statusItem!.menu = appMenu

}

func applicationDidFinishLaunching(_ notification: Notification)
Expand All @@ -139,6 +147,6 @@ class GlassDelegate : NSObject, NSApplicationDelegate
NSApp.activate(ignoringOtherApps: true)

// hide the dock icon (same as LSUIElement true in Info.plist)
// NSApp.setActivationPolicy(.accessory)
NSApp.setActivationPolicy(.accessory)
}
}
4 changes: 2 additions & 2 deletions GlassController/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
Expand Down
33 changes: 21 additions & 12 deletions glass/GlassPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ class GlassPreferences : NSWindow, NSTableViewDelegate, NSTableViewDataSource
inner.addSubview(importB)

// the + and - buttons for actions
let controls = NSSegmentedControl()
controls.frame = NSMakeRect(0, 0, 100, 30)
controls.frame.origin = CGPoint(x: 5, y: 70)
controls.segmentCount = 2
controls.setLabel("+", forSegment: 0)
controls.setLabel("-", forSegment: 1)
controls.segmentStyle = .smallSquare
if #available(OSX 10.10.3, *) {
controls.trackingMode = .momentary
}
inner.addSubview(controls)
// let controls = NSSegmentedControl()
// controls.frame = NSMakeRect(0, 0, 100, 30)
// controls.frame.origin = CGPoint(x: 5, y: 70)
// controls.segmentCount = 2
// controls.setLabel("+", forSegment: 0)
// controls.setLabel("-", forSegment: 1)
// controls.segmentStyle = .smallSquare
// if #available(OSX 10.10.3, *) {
// controls.trackingMode = .momentary
// }
// inner.addSubview(controls)

// the current regions on the touchpad and action mappings
let tableContainer = NSScrollView(frame:NSMakeRect(0, 0, WIDTH, HEIGHT-100))
Expand All @@ -114,13 +114,21 @@ class GlassPreferences : NSWindow, NSTableViewDelegate, NSTableViewDataSource

func numberOfRows(in tableView: NSTableView) -> Int
{
return glassDelegate.view!.actions.count;
let count = glassDelegate.view!.actions.count
if count == 0 {
return 1
}
return count
}

func tableView(_ tableView: NSTableView,
objectValueFor tableColumn: NSTableColumn?,
row: Int) -> Any?
{
let count = glassDelegate.view!.actions.count
if count == 0 {
return "No actions exist in this profile. See the Readme for more information."
}
return glassDelegate.view!.actions[row].getValue((tableColumn?.identifier)!.rawValue)
}

Expand All @@ -137,6 +145,7 @@ class GlassPreferences : NSWindow, NSTableViewDelegate, NSTableViewDataSource
@objc static func showConfigWindow()
{
let window = GlassPreferences(GlassDelegate.singleton!)
window.isReleasedWhenClosed = false
window.cascadeTopLeft(from: NSMakePoint(20, 20))
window.title = "GlassCon Preferences"
window.makeKeyAndOrderFront(nil)
Expand Down

0 comments on commit 300dfda

Please sign in to comment.