diff options
| author | Aargh Rai <aargh.rai+git@gmail.com> | 2025-10-05 23:59:43 +0530 |
|---|---|---|
| committer | Aargh Rai <aargh.rai+git@gmail.com> | 2025-10-05 23:59:43 +0530 |
| commit | a1ff11b11c4a83a19839c4c50c7a1f6cb0a09670 (patch) | |
| tree | 9ac2ccd11adde02f33e14d95123ad3d85ef5bac8 /hypr | |
| parent | 26164919defb8318b5fd8c79378b5586f042b939 (diff) | |
zoom
Diffstat (limited to 'hypr')
| -rw-r--r-- | hypr/hypr-zoom/.github/workflows/main.yml | 33 | ||||
| -rwxr-xr-x | hypr/hypr-zoom/exec.sh | 8 | ||||
| -rw-r--r-- | hypr/hypr-zoom/go.mod | 5 | ||||
| -rw-r--r-- | hypr/hypr-zoom/go.sum | 2 | ||||
| -rwxr-xr-x | hypr/hypr-zoom/hypr-zoom | bin | 0 -> 2887449 bytes | |||
| -rw-r--r-- | hypr/hypr-zoom/hypr-zoom.go | 143 | ||||
| -rw-r--r-- | hypr/hypr-zoom/readme.md | 104 | ||||
| -rw-r--r-- | hypr/hyprland/keybinds.conf | 2 |
8 files changed, 297 insertions, 0 deletions
diff --git a/hypr/hypr-zoom/.github/workflows/main.yml b/hypr/hypr-zoom/.github/workflows/main.yml new file mode 100644 index 0000000..ab277d7 --- /dev/null +++ b/hypr/hypr-zoom/.github/workflows/main.yml @@ -0,0 +1,33 @@ +name: Build and upliad artifact + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23' + + - name: Build + run: go build -v -o hypr-zoom ./hypr-zoom.go # Specify the output binary name + + - name: Delete Previous artifact + uses: geekyeggo/delete-artifact@v5 + with: + name: hypr-zoom + failOnError: false + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: hypr-zoom + path: hypr-zoom diff --git a/hypr/hypr-zoom/exec.sh b/hypr/hypr-zoom/exec.sh new file mode 100755 index 0000000..d83b73e --- /dev/null +++ b/hypr/hypr-zoom/exec.sh @@ -0,0 +1,8 @@ +file="~/.config/hypr/hypr-zoom/hypr-zoom" +if [ -f "$file" ]; then + ./hypr-zoom -duration=10 -steps=50 -interp=Linear +else + cd ~/.config/hypr/hypr-zoom/ + go build -o hypr-zoom + ./hypr-zoom -duration=10 -steps=50 -interp=Linear +fi diff --git a/hypr/hypr-zoom/go.mod b/hypr/hypr-zoom/go.mod new file mode 100644 index 0000000..32db86a --- /dev/null +++ b/hypr/hypr-zoom/go.mod @@ -0,0 +1,5 @@ +module hypr-zoom + +go 1.22.5 + +require github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 // indirect diff --git a/hypr/hypr-zoom/go.sum b/hypr/hypr-zoom/go.sum new file mode 100644 index 0000000..8254f11 --- /dev/null +++ b/hypr/hypr-zoom/go.sum @@ -0,0 +1,2 @@ +github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 h1:VRIbnDWRmAh5yBdz+J6yFMF5vso1It6vn+WmM/5l7MA= +github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776/go.mod h1:9wvnDu3YOfxzWM9Cst40msBF1C2UdQgDv962oTxSuMs= diff --git a/hypr/hypr-zoom/hypr-zoom b/hypr/hypr-zoom/hypr-zoom Binary files differnew file mode 100755 index 0000000..35d4224 --- /dev/null +++ b/hypr/hypr-zoom/hypr-zoom diff --git a/hypr/hypr-zoom/hypr-zoom.go b/hypr/hypr-zoom/hypr-zoom.go new file mode 100644 index 0000000..d77606c --- /dev/null +++ b/hypr/hypr-zoom/hypr-zoom.go @@ -0,0 +1,143 @@ +package main + +import ( + "flag" + "fmt" + "math" + "os/exec" + "strconv" + "strings" + "time" + + "github.com/fogleman/ease" +) + +type EasingFunction func(t float64) float64 +type InterpolatorFunc func(s, e, t float64) float64 + +// Linear interpolation function +func lerp(start, end, t float64) float64 { + return start + t*(end-start) +} + +func logInterp(start, end, t float64) float64 { + if t == 0 { + return start + } + return start + (end-start)*(math.Log(t+1)/math.Log(2)) +} + +// Main animation loop +func zoom(duration int, steps int, startValue, endValue float64, easingFunc EasingFunction, interInterpolatorFunc InterpolatorFunc) { + interval := float64(duration) / float64(steps) / 1000 + + for i := 0; i <= steps; i++ { + t := float64(i) / float64(steps) + easedT := easingFunc(t) + interpolatedValue := interInterpolatorFunc(startValue, endValue, easedT) + + _ = exec.Command("hyprctl", "keyword", "cursor:zoom_factor", fmt.Sprintf("%f", interpolatedValue)).Run() + time.Sleep(time.Duration(interval * float64(time.Second))) + } +} + +// Execute a shell command and return its output as a string +func executeCommand(command string) (string, error) { + output, err := exec.Command("bash", "-c", command).Output() + if err != nil { + return "", err + } + return string(output), nil +} + +func main() { + output, err := executeCommand("hyprctl getoption cursor:zoom_factor | grep 'float:' | awk '{print $2}' | tr -d '[:space:]'") + if err != nil { + fmt.Println("Error getting initial zoom factor:", err) + return + } + + duration := flag.Int("duration", 500, "Duration of the animation in milliseconds") + steps := flag.Int("steps", 100, "Number of steps in the animation") + easing := flag.String("easing", "InOutExpo", "Easing function to use") + easingOut := flag.String("easingOut", "", "Easing function to use for zoom-out (optional)") + targetZoom := flag.Float64("target", 2.0, "Zoom Target") + interpolator := flag.String("interp", "Log", "Animation interpolator function") + force := flag.Bool("force", false, "Forcing target parameter even if zoom is not equal to 1") + flag.Parse() + + initialZoom, err := strconv.ParseFloat(strings.TrimSpace(output), 64) + if err != nil { + fmt.Println("Error parsing initial zoom factor:", err) + return + } + + if *steps <= 0 { + fmt.Println("Error: `steps` must be greater than 0.") + return + } + + easingFunctions := map[string]EasingFunction{ + "Linear": ease.Linear, + "InQuad": ease.InQuad, + "OutQuad": ease.OutQuad, + "InOutQuad": ease.InOutQuad, + "InCubic": ease.InCubic, + "OutCubic": ease.OutCubic, + "InOutCubic": ease.InOutCubic, + "InQuart": ease.InQuart, + "OutQuart": ease.OutQuart, + "InOutQuart": ease.InOutQuart, + "InQuint": ease.InQuint, + "OutQuint": ease.OutQuint, + "InOutQuint": ease.InOutQuint, + "InSine": ease.InSine, + "OutSine": ease.OutSine, + "InOutSine": ease.InOutSine, + "InExpo": ease.InExpo, + "OutExpo": ease.OutExpo, + "InOutExpo": ease.InOutExpo, + "InCirc": ease.InCirc, + "OutCirc": ease.OutCirc, + "InOutCirc": ease.InOutCirc, + // "InElastic": ease.InElastic, + // "OutElastic": ease.OutElastic, + // "InOutElastic": ease.InOutElastic, + "InBack": ease.InBack, + "OutBack": ease.OutBack, + "InOutBack": ease.InOutBack, + "InBounce": ease.InBounce, + "OutBounce": ease.OutBounce, + "InOutBounce": ease.InOutBounce, + "InSquare": ease.InSquare, + "OutSquare": ease.OutSquare, + "InOutSquare": ease.InOutSquare, + } + + interpolatorFunctions := map[string]InterpolatorFunc{ + "Log": logInterp, + "Linear": lerp, + } + + interpolatorFunc, exists := interpolatorFunctions[*interpolator] + if !exists { + fmt.Println("Unknown interpolator function:", *interpolator, "Set to default") + interpolatorFunc = interpolatorFunctions["Log"] + } + + easingFunction, exists := easingFunctions[*easing] + if !exists { + fmt.Println("Unknown easing function:", *easing, "Set to default") + easingFunction = easingFunctions["InOutExpo"] + } + + if (initialZoom > 1 && !*force) { + *targetZoom = 1.0 + _, exists := easingFunctions[*easingOut] + if exists { + easingFunction = easingFunctions[*easingOut] + } + } + + zoom(*duration, *steps, initialZoom, *targetZoom, easingFunction, interpolatorFunc) +} diff --git a/hypr/hypr-zoom/readme.md b/hypr/hypr-zoom/readme.md new file mode 100644 index 0000000..ab938ad --- /dev/null +++ b/hypr/hypr-zoom/readme.md @@ -0,0 +1,104 @@ +# hypr-zoom + +`hypr-zoom` is a command-line tool written in Go that smoothly animates the Hyprland cursor zoom-factor changes using variety of easing functions. +It simply uses the `hyprctl` command to adjust the cursor zoom-factor and the ease library for animation interpolation. + +## Why ? +Hyprland cursor zoom factor changes happen instantly, which can feel ood since Hyprland has cool animations. This little CLI solves that. + +## Features + +- Smoothly animates cursor zoom-factor using a variety of easing and interpolation functions. +- Configurable animation duration and steps. + +## Installation +install from aur: [hypr-zoom](https://aur.archlinux.org/packages/hypr-zoom) + +Grab from release or : +1. Clone the repository: + ```sh + git clone https://github.com/FaqihS/hypr-zoom.git + cd hypr-zoom + ``` + +2. Build the project: + ```sh + go build -o hypr-zoom + ``` + +## Usage + +The `hypr-zoom` command has several flags to configure the animation: + +- `-duration`: Duration of the animation in milliseconds (default: 500) +- `-steps`: Number of steps in the animation (default: 100) +- `-easing`: Easing function to use for the animation (default: InOutExpo) +- `-easingOut`: Easing function to use for the zoom-out animation (optional) +- `-target`: Target zoom factor (default: 2.0) +- `-interp`: Interpolation Function used for animation(default: Log) +- `-force` : Forcing target parameter (default: false) + +### Example + +```sh +hypr-zoom -easing=InOutExpo -duration=500 -steps=60 -target=1.2 +``` + +This command will animate the zoom factor to 1.2 using the InOutExpo easing function over 500 milliseconds with 60 steps. + +```sh +hypr-zoom -easing=OutBack -easingOut=OutExpo +``` + +This command will animate the zoom factor using the OutBack easing function when zooming-in and OutExpo when zooming-out. + +> [!WARNING] +> Adjust duration and steps wisely. + +### Supported Easing Functions +The following easing functions are supported: + +- Linear +- InQuad, OutQuad, InOutQuad +- InCubic, OutCubic, InOutCubic +- InQuart, OutQuart, InOutQuart +- InQuint, OutQuint, InOutQuint +- InSine, OutSine, InOutSine +- InExpo, OutExpo, InOutExpo +- InCirc, OutCirc, InOutCirc +- InBack, OutBack, InOutBack +- InBounce, OutBounce, InOutBounce +- InSquare, OutSquare, InOutSquare + +For animation preview [see here](https://github.com/fogleman/ease). + +### Supported Interpolation function +- Linear +- Log (Logarithmic) + +## Showcase +### Default+Linear +```sh +hypr-zoom -interp=Linear +``` +https://github.com/user-attachments/assets/261aff62-955f-49e6-9a7b-c5f714389dc4 +### InOutCubic +```sh +hypr-zoom -easing=InOutCubic -interp=Linear +``` +https://github.com/user-attachments/assets/622d4a4b-b805-495d-8178-ad5e130279c2 +### OutBack-Inback +```sh +hypr-zoom -duration=600 -steps=150 -easing=OutBack -easingOut=InBack -interp=Linear +``` +https://github.com/user-attachments/assets/de4f2924-b5e8-43a8-9bbf-6f1ac795687c + + + + +## Contributing +Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes. Although i'm not real Go Dev :p + +## Acknowledgements +- [fogleman/ease](https://github.com/fogleman/ease) - Easing functions library used in this project. +- [Hyprland](https://hyprland.org) diff --git a/hypr/hyprland/keybinds.conf b/hypr/hyprland/keybinds.conf index bb36b2e..dc70d7c 100644 --- a/hypr/hyprland/keybinds.conf +++ b/hypr/hyprland/keybinds.conf @@ -75,3 +75,5 @@ bindl = ,XF86AudioPrev, exec, playerctl previous # Special OMEN key bindel = ,code:157, exec, $llm + +bind = $mainMod, equal, exec, ~/.config/hypr/hypr-zoom/exec.sh |
