Skip to content

Commit

Permalink
v3.0.0 - collection support (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serpentiel authored Jan 21, 2024
2 parents d440b01 + 709c651 commit 70d61fd
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 205 deletions.
1 change: 0 additions & 1 deletion .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ jobs:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: EndBug/latest-tag@latest
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
37 changes: 0 additions & 37 deletions betterglobekey.rb

This file was deleted.

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
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/Serpentiel/betterglobekey

go 1.19
go 1.21

require (
github.com/robotn/gohook v0.41.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
go.uber.org/fx v1.20.1
go.uber.org/zap v1.26.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)

Expand All @@ -18,7 +18,7 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand All @@ -28,9 +28,9 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/vcaesar/keycode v0.10.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/dig v1.17.0 // indirect
go.uber.org/dig v1.17.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
27 changes: 19 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robotn/gohook v0.41.0 h1:h1vK3w/UQpq0YkIiGnxm9Awv85W54esL0/NUYGueggo=
github.com/robotn/gohook v0.41.0/go.mod h1:FedpuAkVqzM5t67L5fcf3hSSCUDO9cM5YkWCw1U+nuc=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
Expand Down Expand Up @@ -53,25 +61,28 @@ github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSW
github.com/vcaesar/keycode v0.10.1 h1:0DesGmMAPWpYTCYddOFiCMKCDKgNnwiQa2QXindVUHw=
github.com/vcaesar/keycode v0.10.1/go.mod h1:JNlY7xbKsh+LAGfY2j4M3znVrGEm5W1R8s/Uv6BJcfQ=
github.com/vcaesar/tt v0.20.0 h1:9t2Ycb9RNHcP0WgQgIaRKJBB+FrRdejuaL6uWIHuoBA=
github.com/vcaesar/tt v0.20.0/go.mod h1:GHPxQYhn+7OgKakRusH7KJ0M5MhywoeLb8Fcffs/Gtg=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI=
go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU=
go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc=
go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
go.uber.org/fx v1.20.1 h1:zVwVQGS8zYvhh9Xxcu4w1M6ESyeMzebzj2NbSayZ4Mk=
go.uber.org/fx v1.20.1/go.mod h1:iSYNbHf2y55acNCwCXKx7LbWb5WG1Bnue5RDXz1OREg=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
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: {}
Loading

0 comments on commit 70d61fd

Please sign in to comment.