Skip to content

Commit

Permalink
Merge branch 'feature' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ruittenb committed Oct 2, 2024
2 parents bb89328 + d3a2e6e commit c03ef83
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1.6.13: Fixed switching spaces when clicking to the right of a fullscreen space
1.6.12: Update name in preferences when it changes.
1.6.11: Fix restart numbering by desktop
1.6.10: More friendly error dialog
Expand Down
Binary file modified Images/Preferences-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/Preferences-4a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/Preferences-4b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The meaning of the icons from left to right are:

<img src="Images/Preferences-4a.png" width="66%" height="auto">

The style and the name of a space can be changed in preferences (shown above). A space is named by selecting the space from the dropdown, typing a name up to 4 characters and clicking the 'Update name' button.
The style and the name of a space can be changed in preferences (shown above). A space is named by selecting the space from the dropdown and editing its name (up to 4 characters).

If the icon fails to update, you can choose to force a refresh of the icon using a custom keyboard shortcut or allow Spaceman to refresh them automatically every 5 seconds by enabling 'Refresh spaces in background'.

Expand All @@ -60,6 +60,8 @@ Note that only the first ten spaces will have shortcut keys assigned.
For extra spaces, switching will not be available; the status bar icon will flash if
selected, and the menu option will be disabled.

Switching is also not supported for fullscreen spaces.

**For switching to work successfully, the following things need to be configured:**

- Spaceman needs authorization for Accessibility:
Expand Down
12 changes: 8 additions & 4 deletions Spaceman.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
E70587F32C80A5DA00D9B729 /* ShortcutHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = E70587F22C80A5DA00D9B729 /* ShortcutHelper.swift */; };
E70587F52C827E5600D9B729 /* exportOptions.plist in Resources */ = {isa = PBXBuildFile; fileRef = E70587F42C827E5600D9B729 /* exportOptions.plist */; };
E70587F72C864C8A00D9B729 /* SpaceNameCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = E70587F62C864C8A00D9B729 /* SpaceNameCache.swift */; };
E73504B42CAD14BE007F62B5 /* IconWidth.swift in Sources */ = {isa = PBXBuildFile; fileRef = E73504B32CAD14BE007F62B5 /* IconWidth.swift */; };
E7A066232C7F65F1002DFC52 /* SpaceSwitcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A066222C7F65F1002DFC52 /* SpaceSwitcher.swift */; };
E7B0862F2C8980130016C851 /* OSVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7B0862E2C8980130016C851 /* OSVersion.swift */; };
E7DA73A62CA6E74D00212836 /* LayoutMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7DA73A52CA6E74D00212836 /* LayoutMode.swift */; };
Expand Down Expand Up @@ -45,6 +46,7 @@
E70587F22C80A5DA00D9B729 /* ShortcutHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShortcutHelper.swift; sourceTree = "<group>"; };
E70587F42C827E5600D9B729 /* exportOptions.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = exportOptions.plist; sourceTree = "<group>"; };
E70587F62C864C8A00D9B729 /* SpaceNameCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpaceNameCache.swift; sourceTree = "<group>"; };
E73504B32CAD14BE007F62B5 /* IconWidth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconWidth.swift; sourceTree = "<group>"; };
E7A066222C7F65F1002DFC52 /* SpaceSwitcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpaceSwitcher.swift; sourceTree = "<group>"; };
E7B0862E2C8980130016C851 /* OSVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSVersion.swift; sourceTree = "<group>"; };
E7DA73A52CA6E74D00212836 /* LayoutMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutMode.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -179,6 +181,7 @@
isa = PBXGroup;
children = (
E7DA73A72CA6E7A700212836 /* GuiSize.swift */,
E73504B32CAD14BE007F62B5 /* IconWidth.swift */,
E7DA73A92CA8C09300212836 /* KeySet.swift */,
E7DA73A52CA6E74D00212836 /* LayoutMode.swift */,
E873350D256B5F0F0012586E /* Space.swift */,
Expand Down Expand Up @@ -295,6 +298,7 @@
files = (
E873350E256B5F0F0012586E /* Space.swift in Sources */,
4C02BD6F2C0894F500F07491 /* RefreshCommand.swift in Sources */,
E73504B42CAD14BE007F62B5 /* IconWidth.swift in Sources */,
E7B0862F2C8980130016C851 /* OSVersion.swift in Sources */,
E8E2AEF8257CB4D700319BBC /* PreferencesViewModel.swift in Sources */,
E7A066232C7F65F1002DFC52 /* SpaceSwitcher.swift in Sources */,
Expand Down Expand Up @@ -461,7 +465,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.6.12;
CURRENT_PROJECT_VERSION = 1.6.13;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Spaceman/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand All @@ -476,7 +480,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.6.12;
MARKETING_VERSION = 1.6.13;
PRODUCT_BUNDLE_IDENTIFIER = dev.ruittenb.Spaceman;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -495,7 +499,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.6.12;
CURRENT_PROJECT_VERSION = 1.6.13;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Spaceman/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand All @@ -510,7 +514,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.6.12;
MARKETING_VERSION = 1.6.13;
PRODUCT_BUNDLE_IDENTIFIER = dev.ruittenb.Spaceman;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
28 changes: 16 additions & 12 deletions Spaceman/Helpers/IconCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import Foundation

class IconCreator {
private let defaults = UserDefaults.standard
private let leftMargin = CGFloat(7) /* FIXME determine actual left margin */
private var displayCount = 1
private var iconSize = NSSize(width: 0, height: 0)
private var gapWidth = CGFloat.zero
private var displayGapWidth = CGFloat.zero
private var layoutMode = LayoutMode.normal

public var sizes: GuiSize!
public var widths: [CGFloat] = []
public var iconWidths: [IconWidth] = []

func getIcon(for spaces: [Space]) -> NSImage {
layoutMode = PreferencesView().layoutMode
Expand Down Expand Up @@ -176,8 +177,8 @@ class IconCreator {
return newIcons
}

func getIconsWithDisplayProps(icons: [NSImage], spaces: [Space]) -> [(NSImage, Bool)] {
var iconsWithDisplayProperties = [(NSImage, Bool)]()
func getIconsWithDisplayProps(icons: [NSImage], spaces: [Space]) -> [(NSImage, Bool, Bool)] {
var iconsWithDisplayProperties = [(NSImage, Bool, Bool)]()
var currentDisplayID = spaces[0].displayID
displayCount = 1

Expand All @@ -198,13 +199,13 @@ class IconCreator {
}
}

iconsWithDisplayProperties.append((icons[index], nextSpaceIsOnDifferentDisplay))
iconsWithDisplayProperties.append((icons[index], nextSpaceIsOnDifferentDisplay, spaces[index].isFullScreen))
}

return iconsWithDisplayProperties
}

func mergeIcons(_ iconsWithDisplayProperties: [(image: NSImage, nextSpaceOnDifferentDisplay: Bool)]) -> NSImage {
func mergeIcons(_ iconsWithDisplayProperties: [(image: NSImage, nextSpaceOnDifferentDisplay: Bool, isFullScreen: Bool)]) -> NSImage {
let numIcons = iconsWithDisplayProperties.count
let combinedIconWidth = CGFloat(iconsWithDisplayProperties.reduce(0) { (result, icon) in
result + icon.image.size.width
Expand All @@ -215,24 +216,27 @@ class IconCreator {
let image = NSImage(size: NSSize(width: totalWidth, height: iconSize.height))

image.lockFocus()
var x = CGFloat.zero
widths = [x]
var left = CGFloat.zero
var right: CGFloat
iconWidths = []
for icon in iconsWithDisplayProperties {
icon.image.draw(
at: NSPoint(x: x, y: 0),
at: NSPoint(x: left, y: 0),
from: NSRect.zero,
operation: NSCompositingOperation.sourceOver,
fraction: 1.0)
if icon.nextSpaceOnDifferentDisplay {
x += icon.image.size.width + displayGapWidth
right = left + icon.image.size.width + displayGapWidth
} else {
x += icon.image.size.width + gapWidth
right = left + icon.image.size.width + gapWidth
}
widths.append(x + 4) /* TODO FIXME left margin */
if !icon.isFullScreen {
iconWidths.append(IconWidth(left: left + leftMargin, right: right + leftMargin))
}
left = right
}
image.isTemplate = true
image.unlockFocus()
widths.removeLast()

return image
}
Expand Down
11 changes: 7 additions & 4 deletions Spaceman/Helpers/SpaceSwitcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ class SpaceSwitcher {
}
}

func switchUsingLocation(widths: [CGFloat], horizontal: CGFloat, onError: () -> Void) {
var index = 0
while index < widths.count && horizontal > widths[index] {
index += 1
func switchUsingLocation(iconWidths: [IconWidth], horizontal: CGFloat, onError: () -> Void) {
var index: Int = -1
for i in 0 ..< iconWidths.count {
if horizontal >= iconWidths[i].left && horizontal < iconWidths[i].right {
index = i + 1
break
}
}
switchToSpace(spaceNumber: index, onError: onError)
}
Expand Down
13 changes: 13 additions & 0 deletions Spaceman/Model/IconWidth.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// IconWidth.swift
// Spaceman
//
// Created by René Uittenbogaard on 02/10/2024.
//

import Foundation

struct IconWidth: Codable {
let left: CGFloat
let right: CGFloat
}
2 changes: 2 additions & 0 deletions Spaceman/Spaceman.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<false/>
<key>com.apple.security.automation.apple-events</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
Expand Down
2 changes: 1 addition & 1 deletion Spaceman/View/StatusBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class StatusBar: NSObject, NSMenuDelegate {
let locationInButton = sbButton.convert(event.locationInWindow, from: sbButton)

self.spaceSwitcher.switchUsingLocation(
widths: self.iconCreator.widths,
iconWidths: self.iconCreator.iconWidths,
horizontal: locationInButton.x,
onError: self.flashStatusBar)
} else {
Expand Down

0 comments on commit c03ef83

Please sign in to comment.