Skip to content
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

feat: custom canvas sizes for improved Windows cursor resizing #62

Merged
merged 6 commits into from
May 23, 2024

Conversation

ful1e5
Copy link
Owner

@ful1e5 ful1e5 commented May 21, 2024

This PR allows cursor bitmap re-canvasing by specifying sizes using the cursor_size:canvas_size format.

Caveats

  • To utilize canvasing in config files, all sizes must be passed in List[string] format in both config files and Python code.

Using the library:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from clickgen.parser import open_blob


if __name__ == "__main__":
    # ...

    open_blob(pngs, hotspot=(100, 100), sizes=["24:32", "32"])  # ✅ Correct [CANVASING]
    open_blob(pngs, hotspot=(100, 100), sizes=["24", "32"])     # ✅ Correct [NORMAL]
    open_blob(pngs, hotspot=(100, 100), sizes=[24, 32])         # ✅ Correct [NORMAL]

    open_blob(pngs, hotspot=(100, 100), sizes=["24", 32])       # ❌ Error [NORMAL]
    open_blob(pngs, hotspot=(100, 100), sizes=["24:32", 32])    # ❌ Error [CANVASING]

Using the clickgen CLI:

clickgen samples/pngs/pointer.png -x 10 -y 10 -s "22:32" "24" "32" -p x11   # ✅ Correct [CANVASING]
clickgen samples/pngs/pointer.png -x 10 -y 10 -s "22" "24" "32" -p x11      # ✅ Correct [NORMAL]
clickgen samples/pngs/pointer.png -x 10 -y 10 -s 22 24 32 -p x11            # ✅ Correct [NORMAL]

clickgen samples/pngs/pointer.png -x 10 -y 10 -s "22" 24 32 -p x11          # ✅ Correct [NORMAL]
clickgen samples/pngs/pointer.png -x 10 -y 10 -s "22:32" 24 32 -p x11       # ✅ Correct [CANVASING]

Using the ctgen CLI:

ctgen samples/sample.toml -s "22:32" "24" "32" -p x11   # ✅ Correct [CANVASING]
ctgen samples/sample.toml -s "22" "24" "32" -p x11      # ✅ Correct [NORMAL]
ctgen samples/sample.toml -s 22 24 32 -p x11            # ✅ Correct [NORMAL]

ctgen samples/sample.toml -s "22" 24 32 -p x11          # ✅ Correct [NORMAL]
ctgen samples/sample.toml -s "22:32" 24 32 -p x11       # ✅ Correct [CANVASING]

Using the config files

TOML config
# ...

[cursors]
[cursors.fallback_settings]
x11_sizes = [16, 20, 24, 28, 32, 40, 48, 56, 64, 72, 80, 88, 96]

win_sizes = ['24:32', '32', '48', '64', '96']         # ✅ Correct [CANVASING]
win_sizes = ['24', '32', '48', '64', '96']            # ✅ Correct [NORMAL]
win_sizes = [24, 32, 48, 64, 96]                      # ✅ Correct [NORMAL]

win_sizes = ['24', 32, 48, 64, 96]                    # ❌ Error [NORMAL]
win_sizes = ['24:32', 32, 48, 64, 96]                 # ❌ Error [CANVASING]

[cursors.pointer1]
png = 'pointer.png'
win_name = 'Default'
x11_name = 'pointer1'
x11_symlinks = ['link1']
x11_sizes = [24, 32]

# ...
JSON config
{
    // ...

    "cursors": {
        "fallback_settings": {
            "x11_sizes": [16, 20, 24, 28, 32, 40, 48, 56, 64, 72, 80, 88, 96],
            "win_sizes": ["24:32", "32", "48", "64", "96"]         // ✅ Correct [CANVASING]
            "win_sizes": ["24", "32", "48", "64", "96"],           // ✅ Correct [NORMAL]
            "win_sizes": [24, 32, 48, 64, 96],                     // ✅ Correct [NORMAL]

            "win_sizes": ["24", 32, 48, 64, 96],                   // ❌ Error [NORMAL]
            "win_sizes": ["24:32", 32, 48, 64, 96]                 // ❌ Error [CANVASING]
        },
        "pointer1": {
            "png": "pointer.png",
            "win_name": "Default",
            "x11_name": "pointer1",
            "x11_symlinks": ["link1"],
            "x11_sizes": [24, 32]
        }

        // ...
    },
}
YAML config
# ...

cursors:
  fallback_settings:
    x11_sizes: [16, 20, 24, 28, 32, 40, 48, 56, 64, 72, 80, 88, 96]

    win_sizes: ['24:32', '32', '48', '64', '96']         # ✅ Correct [CANVASING]
    win_sizes: ['24', '32', '48', '64', '96']            # ✅ Correct [NORMAL]
    win_sizes: [24, 32, 48, 64, 96]                      # ✅ Correct [NORMAL]

    win_sizes: ['24', 32, 48, 64, 96]                    # ❌ Error [NORMAL]
    win_sizes: ['24:32', 32, 48, 64, 96]                 # ❌ Error [CANVASING]

  pointer1:
    png: 'pointer.png'
    win_name: 'Default'
    x11_name: 'pointer1'
    x11_symlinks: ['link1']
    x11_sizes: [24, 32]

  # ...

Copy link

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5bc1a49) to head (16d4f24).

Additional details and impacted files
@@             Coverage Diff             @@
##             main       #62      +/-   ##
===========================================
+ Coverage   99.64%   100.00%   +0.35%     
===========================================
  Files          15        15              
  Lines         563       581      +18     
===========================================
+ Hits          561       581      +20     
+ Misses          2         0       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ful1e5 ful1e5 merged commit 30a8d5a into main May 23, 2024
28 checks passed
@ful1e5 ful1e5 deleted the feat/custom-canvas-sizes branch May 23, 2024 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant