-
Notifications
You must be signed in to change notification settings - Fork 31
Add a YAML config based configuration path. Adds alternative bindings for corner functions, max-height function and make larger/smaller #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
phoeagon
wants to merge
42
commits into
ahmetb:main
Choose a base branch
from
phoeagon:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
7cb9bf0
Update main.go: add ctrl-alt-[u|i|j|k] on resizing to 4 corners
phoeagon 6973c0a
Update main.go
phoeagon fb91abe
Update README.md
phoeagon 918f628
Update snap.go: add resize function and maxheight
phoeagon ecd0eb0
Update main.go
phoeagon ebd2e58
Update README.md
phoeagon aefbeb7
Update README.md: add max height hotkey
phoeagon 0f779f9
Update README.md: fix hotkey script on max height
phoeagon b745638
add a conf.go to load yaml config
phoeagon bb6713f
minor formatting fixes. removes some debug outputs
phoeagon a48be35
update README.me: include description of config.yaml
phoeagon b45e3cc
Create go.yml
phoeagon 41329a4
Update ci.yml
phoeagon 02a7228
Update ci.yml
phoeagon 09f1e37
Update ci.yml: switch new ways to set cache paths in ci.yml
phoeagon 33ac7fb
Update ci.yml: fix typo: use go 1.20 not 1.2
phoeagon 57f7b4d
Create release.yml: build and release
phoeagon 35d1945
Update release.yml
phoeagon 5df4a18
Update release.yml: fix ident
phoeagon db3b31e
Update release.yml: fix release setup
phoeagon 8bb6486
Update release.yml: test building for windows artifacts using ubuntu-…
phoeagon b5509ea
Update release.yml: set a tag upon input, which is required for the r…
phoeagon f816c52
Update release.yml: update to auto release
phoeagon bb90211
Update release.yml: remove zip. not necessary,
phoeagon d2b37d4
adds matching against more keys defined in keymap.go by name. also fi…
phoeagon e9aaa12
update README: explains a few more hotkeys
phoeagon 5d2a822
Update ci.yml: fix go-version to "1.20" instead of 1.20 suspecting in…
phoeagon 86fbf79
minor fix to satisfy gofmt -s -d .
phoeagon 17206ff
fix for go mod tidy
phoeagon 583d3b8
Update ci.yml: remove --skip-publish which is no longer supported
phoeagon aeca165
Update ci.yml: removes unrecognized flag
phoeagon dcce140
Update ci.yml: minor fix: merge env section
phoeagon 91acec0
update .goreleaser.yaml to v2 format
phoeagon a710b10
fix goreleaser.yaml: update to v2 format
phoeagon 6fa940b
updates RectangleWin to automatically emit a config yaml at %HOME%/.c…
phoeagon d51082b
Add a tray menu item to open editor on the config file in %HOME%. A c…
phoeagon 91b99e7
update github workflow: no longer release config.yaml because this ca…
phoeagon 8bcd939
updates to README: separate config.yaml specific hotkey to a differen…
phoeagon b0f8ddb
Merge branch 'ahmetb:main' into main
phoeagon 79f7683
minor fix: go has a different syntax on multiple cases going to the s…
phoeagon c10fffc
indentation fix to satisfy gofmt. somehow go fmt doesn't mind
phoeagon 349dcd9
Merge branch 'ahmetb:main' into main
phoeagon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # This workflow will build a golang project | ||
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
|
||
| name: Go | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "main" ] | ||
| pull_request: | ||
| branches: [ "main" ] | ||
|
|
||
| jobs: | ||
|
|
||
| build: | ||
| runs-on: windows-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: '1.20' | ||
|
|
||
| - name: Build | ||
| run: | | ||
| go env -w GOOS=windows | ||
| go build -ldflags -H=windowsgui . | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| name: Release | ||
| on: | ||
| push: | ||
| tags: | ||
| - "v*" | ||
|
|
||
| jobs: | ||
|
|
||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: '1.20' | ||
|
|
||
| - name: Build | ||
| run: | | ||
| go env -w GOOS=windows | ||
| GOOS=windows go build -ldflags -H=windowsgui . | ||
| mkdir build/ | ||
| mv RectangleWin.exe build/RectangleWin.exe | ||
|
|
||
| - name: Create GitHub Release | ||
| uses: fnkr/github-action-ghr@v1 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GHR_PATH: build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "errors" | ||
| "fmt" | ||
| "io/ioutil" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| ) | ||
| import ( | ||
| "github.com/davecgh/go-spew/spew" | ||
| "github.com/golobby/config/v3" | ||
| "github.com/golobby/config/v3/pkg/feeder" | ||
| "github.com/gonutz/w32/v2" | ||
| ) | ||
|
|
||
| type KeyBinding struct { | ||
| // A repeated value of key modifiers. | ||
| // Valid values include: | ||
| // SHIFT, ALT, CTRL, WIN (SUPER/META). | ||
| Modifier []string `yaml: "modifier"` | ||
| // When this is set, this overrides Modifier | ||
| ModifierCode []int32 | ||
| // Calculated bitwise OR result of modifiers | ||
| CombinedMod int32 | ||
| // Valid values are: | ||
| // A - Z, 0 - 9, UP_ARROW, =, - | ||
| // Anything not covered here could be set directly via KeyCode | ||
| Key string `yaml: "key"` | ||
| // Automatically converted from Key. | ||
| // When this is set, it overrides Key. | ||
| KeyCode int32 `yaml: "key_code"` | ||
| // The feature in RectangleWin to bind to. | ||
| // Valid values: | ||
| // moveToTop | ||
| // moveToBottom | ||
| // moveToLeft | ||
| // moveToRight | ||
| // moveToTopLeft | ||
| // moveToTopRight | ||
| // moveToBottomLeft | ||
| // moveToBottomRight | ||
| // makeSmaller | ||
| // makeLarger | ||
| // makeFullHeight | ||
| // | ||
| BindFeature string `yaml: "bindfeature"` | ||
| } | ||
|
|
||
| type Configuration struct { | ||
| Keybindings []KeyBinding `yaml: "key_binding"` | ||
| } | ||
|
|
||
| // This mini config is returned if we can't load a valid file | ||
| // and cannot write the detailed example yaml config.example.yaml | ||
| // into the expected path at %HOME% | ||
| var DEFAULT_CONF = Configuration{ | ||
| Keybindings: []KeyBinding{ | ||
| { | ||
| Modifier: []string{"Ctrl", "Alt"}, | ||
| Key: "UP_ARROW", | ||
| KeyCode: 0x26, | ||
| BindFeature: "moveToTop", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| //go:embed config.example.yaml | ||
| var configExampleYaml []byte | ||
|
|
||
| // Expected config path at %HOME%/.config/RectangleWin/config.yaml | ||
| var DEFAULT_CONF_PATH_PREFIX = ".config/RectangleWin/" | ||
| var DEFAULT_CONF_NAME = "config.yaml" | ||
|
|
||
| func convertModifier(keyName string) (int32, error) { | ||
| switch strings.ToLower(keyName) { | ||
| case "ctrl": | ||
| return MOD_CONTROL, nil | ||
| case "alt": | ||
| return MOD_ALT, nil | ||
| case "shift": | ||
| return MOD_SHIFT, nil | ||
| case "win", "meta", "super": | ||
| return MOD_WIN, nil | ||
| default: | ||
| return 0, errors.New("invalid keyname") | ||
| } | ||
| return 0, errors.New("unreachable") | ||
| } | ||
|
|
||
| func convertKeyCode(key string) (int32, error) { | ||
| k := strings.ToLower(key) | ||
| if len(k) == 1 { | ||
| if k[0] >= 'a' && k[0] <= 'z' { | ||
| return int32(k[0]) - 32, nil | ||
| } | ||
| if k[0] >= '0' && k[0] <= '9' { | ||
| return int32(k[0]), nil | ||
| } | ||
| } | ||
| switch k { | ||
| case "up_arrow": | ||
| return w32.VK_UP, nil | ||
| case "down_arrow": | ||
| return w32.VK_DOWN, nil | ||
| case "left_arrow": | ||
| return w32.VK_LEFT, nil | ||
| case "right_arrow": | ||
| return w32.VK_RIGHT, nil | ||
| case "-": | ||
| return 189, nil | ||
| case "=": | ||
| return 187, nil | ||
| } | ||
| for id, v := range keyNames { | ||
| lv := strings.ToLower(v) | ||
| if lv == k || lv == (k+" key") { | ||
| return int32(id), nil | ||
| } | ||
| } | ||
| return 0, errors.New("Unknown key") | ||
| } | ||
|
|
||
| func bitwiseOr(nums []int32) int32 { | ||
| if len(nums) == 0 { | ||
| return 0 | ||
| } | ||
| result := nums[0] | ||
| for _, n := range nums[1:] { | ||
| result |= n // bitwise OR | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| func getValidConfigPathOrCreate() string { | ||
| homeDir := os.Getenv("HOME") | ||
| if homeDir == "" { | ||
| homeDir = os.Getenv("USERPROFILE") | ||
| } | ||
| if homeDir == "" { | ||
| // Give up generating a valid path. | ||
| // read or write the conf in current folder. | ||
| return DEFAULT_CONF_NAME | ||
| } | ||
| configDir := filepath.Join(homeDir, DEFAULT_CONF_PATH_PREFIX) | ||
| err := os.MkdirAll(configDir, 0755) | ||
| if err != nil { | ||
| fmt.Printf("Error creating directory under user's home folder: %s", err) | ||
| // read or write the conf in current folder | ||
| return DEFAULT_CONF_NAME | ||
| } | ||
| configPath := filepath.Join(configDir, DEFAULT_CONF_NAME) | ||
| return configPath | ||
| } | ||
|
|
||
| func maybeDropExampleConfigFile(target string) { | ||
| // Check if the file exists, if not, create it with some content | ||
| if _, err := os.Stat(target); os.IsNotExist(err) { | ||
| // Create the file and write the sample content | ||
| err := ioutil.WriteFile(target, configExampleYaml, 0644) | ||
| if err != nil { | ||
| fmt.Println("Failed to create file created: %s %v", target, err) | ||
| } | ||
| fmt.Println("File created: %s", target) | ||
| } | ||
| } | ||
|
|
||
| func fetchConfiguration() Configuration { | ||
| spew.Dump(DEFAULT_CONF) | ||
| // Create a Configuration file. | ||
| myConfig := Configuration{} | ||
|
|
||
| // Yaml feeder | ||
| configFilePath := getValidConfigPathOrCreate() | ||
| maybeDropExampleConfigFile(configFilePath) | ||
| yamlFeeder := feeder.Yaml{Path: configFilePath} | ||
| c := config.New() | ||
| c.AddFeeder(yamlFeeder) | ||
| c.AddStruct(&myConfig) | ||
|
|
||
| err := c.Feed() | ||
| if err != nil { | ||
| fmt.Printf("warn: invalid config files found: %s %v\n", configFilePath, err) | ||
| return DEFAULT_CONF | ||
| } | ||
|
|
||
| for i := range myConfig.Keybindings { | ||
| if len(myConfig.Keybindings[i].ModifierCode) == 0 { | ||
| for _, mod := range myConfig.Keybindings[i].Modifier { | ||
| if modCode, err := convertModifier(mod); err == nil { | ||
| myConfig.Keybindings[i].ModifierCode = append(myConfig.Keybindings[i].ModifierCode, modCode) | ||
| } else { | ||
| fmt.Printf("warn: invalid key name %s", mod) | ||
| continue | ||
| } | ||
| } | ||
| } | ||
| myConfig.Keybindings[i].CombinedMod = bitwiseOr(myConfig.Keybindings[i].ModifierCode) | ||
| if myConfig.Keybindings[i].KeyCode == 0 { | ||
| if key, err := convertKeyCode(myConfig.Keybindings[i].Key); err == nil { | ||
| myConfig.Keybindings[i].KeyCode = key | ||
| } else { | ||
| fmt.Printf("warn: invalid key string %s", myConfig.Keybindings[i].Key) | ||
| continue | ||
| } | ||
| } | ||
| } | ||
| spew.Dump(myConfig) | ||
| return myConfig | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some major things I always wanted to do:
the path to config file is something well known, like
%HOME%/.config/rectanglewin/config.yamlthe program should create the default config file if it's missing (we can have a nice config file with inline comments etc).
the tray icon has an item called "Preferences" that launches a notepad.exe with the config file.
Stretch goal: I suspect we'll add new configs over time --we gotta find a way to update the config file with the "new" defaults the program ships with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. Updated the files (please see #14) to:
I think it may take more work to add a "reload" option in the context menu, due to this process registering hotkeys, which must happen after parent process quits, introducing needs for additional interprocess synchronization.