Skip to content

Commit

Permalink
feat: collection support
Browse files Browse the repository at this point in the history
  • Loading branch information
Serpentiel committed Jan 21, 2024
1 parent 4eb015e commit 709c651
Show file tree
Hide file tree
Showing 9 changed files with 292 additions and 154 deletions.
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!-- ### Security -->

## [3.0.0] - 2024-01-21

### Added

- add support for input source collections, allowing users to group and cycle through different sets of input sources
- introduce dynamic starting behavior, enabling the utility to begin with the currently active input source upon initialization

### Changed

- update the configuration structure to accommodate collections of input sources, replacing the previous primary and additional input sources configuration
- modify the Double Press Mode to switch between different input source collections
- adjust the Single Press Mode to cycle through input sources within the current collection
- move Homebrew tap and `betterglobekey.rb` formula to `Serpentiel/homebrew-tools`

### Removed

- remove the distinction between primary and additional input sources in the configuration, in favor of the new collection-based approach

### Fixed

- fix an issue where the utility would not start from the currently active input source

## [2.1.1] - 2023-04-05

### Changed
Expand Down Expand Up @@ -113,7 +135,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- initial release

[unreleased]: https://github.com/Serpentiel/betterglobekey/compare/v2.1.1...HEAD
[unreleased]: https://github.com/Serpentiel/betterglobekey/compare/v3.0.0...HEAD
[3.0.0]: https://github.com/Serpentiel/betterglobekey/releases/tag/v3.0.0
[2.1.1]: https://github.com/Serpentiel/betterglobekey/releases/tag/v2.1.1
[2.1.0]: https://github.com/Serpentiel/betterglobekey/releases/tag/v2.1.0
[2.0.1]: https://github.com/Serpentiel/betterglobekey/releases/tag/v2.0.1
Expand Down
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,45 @@ experience, and I sincerely hope that one day Apple is going to make it this way

## Getting Started

The utility replaces the default behavior of the Globe key and adds two new modes to it:
The utility enhances the functionality of the Globe key by introducing two distinct modes of operation and starting
from the currently active input source:

1. **Single Press Mode**

Single press mode is the mode that is activated when the Globe key is pressed once.
Single press mode is activated when the Globe key is pressed once.

Single press mode cycles between your primary input sources—I believe most of the users out there will not even need
the other available mode as it is probably only useful if you have more than average amount of input sources.
In this mode, the utility cycles through a collection of input sources. Each press of the Globe key switches to the
next input source within the current collection.

Single press mode uses the input sources defined in the config's `input_sources.primary` array.
The collections of input sources are defined in the configuration under `input_sources`. Each key-value pair within
this map represents a named collection of input sources. For example:

2. **Double Press Mode**
```yaml
input_sources:
foo:
- com.apple.keylayout.US
- com.apple.keylayout.Russian
bar:
- com.apple.keylayout.Finnish
- com.apple.keylayout.Ukrainian
- com.apple.inputmethod.Kotoeri.RomajiTyping.Japanese
```
Upon initialization, the utility determines the current active input source and starts from that particular source
within its respective collection.
Double press mode is the mode that is activated when the Globe key is double pressed.
2. **Double Press Mode**
Double press mode cycles between your additional input sources. If you use multiple input sources, you
probably use only several input sources frequently—you might consider putting those that you use the least under
additional input sources.
Double press mode is activated when the Globe key is double-pressed.
Double press mode uses the input sources defined in the config's `input_sources.additional` array.
In this mode, the utility switches between different collections of input sources. Each double press of the Globe
key cycles to the next collection in the configuration.
Double press maximum delay is also configurable in the config's `double_press.maximum_delay` property.
The maximum time interval between the first and second press that is considered a double press can be configured
in the `double_press.maximum_delay` property. This delay is specified in milliseconds.

> **N.B.** This is not working as designed at the moment—this is supposed to open the original input source popup, but
> implementing it requires some reverse engineering. There is probably a function in macOS private API that can be used
> to open the popup.
These enhancements aim to provide a more versatile and user-friendly experience for managing multiple input sources,
especially for users who frequently switch between different languages or keyboard layouts.

### Prerequisites

Expand All @@ -115,7 +128,7 @@ The utility replaces the default behavior of the Globe key and adds two new mode
- Install the utility via [Homebrew](https://brew.sh):

```bash
brew tap Serpentiel/betterglobekey https://github.com/Serpentiel/betterglobekey.git
brew tap Serpentiel/tools
brew install betterglobekey
```

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"os"

"github.com/Serpentiel/betterglobekey/internal/eventhandler"
"github.com/Serpentiel/betterglobekey/internal/pkg/eventhandler"
"github.com/Serpentiel/betterglobekey/internal/provide"
"github.com/Serpentiel/betterglobekey/pkg/logger"
hook "github.com/robotn/gohook"
Expand Down
40 changes: 23 additions & 17 deletions internal/assets/.betterglobekey.example.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
# logger defines the parameters for the logger.
# Logger settings
logger:
# path is the path to the log file.
# Path to the log file
path: betterglobekey.log

# retain defines the parameters for log file retention.
# Log file retention settings
retain:
# days is the number of days to retain log files.
# Number of days to retain log files
days: 30

# copies is the number of log files to retain.
# Number of log files to retain
copies: 3

# double_press defines double press configuration options.
# Configuration options for double press of the Globe key
double_press:
# maximum_delay is the maximum time in milliseconds between the first and second press of the Globe key to be
# considered a double press.
# Maximum time (in milliseconds) between first and second press to consider as a double press
maximum_delay: 250

# input_sources defines the input sources to be used when the Globe key is pressed.
input_sources:
# primary defines the primary input sources. This is used when the Globe key has not been double pressed.
primary: []

# additional defines the additional input sources. This is used when the Globe key has been double pressed.
additional: []
# Input sources configuration
#
# Each key-value pair within the 'input_sources' map represents a named collection of input sources.
# Single press of the Globe key cycles through input sources within the current collection.
# Double press of the Globe key switches between these collections.
#
# Example configuration:
# input_sources:
# foo:
# - com.apple.keylayout.US
# - com.apple.keylayout.Russian
# bar:
# - com.apple.keylayout.Finnish
# - com.apple.keylayout.Ukrainian
# - com.apple.inputmethod.Kotoeri.RomajiTyping.Japanese
input_sources: {}
119 changes: 0 additions & 119 deletions internal/eventhandler/fnkeyhandler.go

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 709c651

Please sign in to comment.