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: load cursor from data #680

Merged
merged 4 commits into from
Apr 29, 2024

Conversation

Decodetalkers
Copy link
Contributor

@Decodetalkers Decodetalkers commented Dec 7, 2023

I want to add a way to load cursor from raw data

Copy link

codecov bot commented Dec 7, 2023

Codecov Report

Attention: Patch coverage is 0% with 39 lines in your changes are missing coverage. Please review.

Project coverage is 72.68%. Comparing base (ea03873) to head (610e93a).
Report is 4 commits behind head on master.

❗ Current head 610e93a differs from pull request most recent head 85585de. Consider uploading reports for the commit 85585de to get more accurate results

Files Patch % Lines
wayland-cursor/src/lib.rs 0.00% 39 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #680      +/-   ##
==========================================
- Coverage   76.16%   72.68%   -3.49%     
==========================================
  Files          45       48       +3     
  Lines        8153     7879     -274     
==========================================
- Hits         6210     5727     -483     
- Misses       1943     2152     +209     
Flag Coverage Δ
main 58.04% <0.00%> (-1.03%) ⬇️
test-- 78.08% <ø> (-2.99%) ⬇️
test--server_system 61.08% <ø> (-3.59%) ⬇️
test-client_system- 68.92% <ø> (-3.27%) ⬇️
test-client_system-server_system 51.32% <ø> (-3.64%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@elinorbgr
Copy link
Member

Thanks, that is interesting, however I'm not sure this design is the whole way we want to go.

As I understand, the goal is to allow an app to provide fallback cursor images by itself in case the system theme does not provide all the ones it needs.

The method you introduce directly creates a Cursor instance, storing its contents using the SHM pool of the theme, but without any other checks, nor inserting it into the internal state. As a result the user will have to keep the Cursor instance around themselves (as the CursorTheme does not store it) and check to use it whenever they need this particular cursor, to avoid reloading a new copy in memory every time.

I think a better approach would be to introduce a proper mechanism by which the user of wayland-cursor can specify a general fallback mechanism. A possible implementation of that would be to let the user provide a fallback Fn(&str) -> Cow<'static, [u8]> closure that would be invoked by load_cursor if the requested cursor was not found in the system theme. (The Cow<'static, [u8]> return type being used so that this closure could either return a reference to some cursor data bundled in the executable itself, or load the contents from disk in the app files.)

With such a fallback mechanism, later use of the CursorTheme would be transparent, and everything would "just work".

What do you think of this, would that cover your needs?

@Decodetalkers
Copy link
Contributor Author

Ok, I have made change. I also think that is bad.. so I am also thinking a better way..

@Decodetalkers Decodetalkers force-pushed the loadcursorfromdata branch 3 times, most recently from bf1e0b9 to 610e93a Compare December 9, 2023 08:42
Comment on lines 203 to 204
pub fn get_cursor_with_default_data<F>(&mut self, name: &str, fallback: F) -> Option<&Cursor>
where
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was rather thinking of defining the fallback closure one and for all as a standalone method of CursorTheme, so that the rest of the API does not need to change at all.

Or is having an independent closure for each time you retrieve the cursor, with all that error-processing machinery something that you need for your uses?

Copy link
Contributor Author

@Decodetalkers Decodetalkers Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emm, what do you mean , make the function out of CursorTheme? I am a little difficult to understand.. sorry

Copy link
Member

@elinorbgr elinorbgr Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was to add to CursorTheme a method like this:

pub fn set_fallback(&mut self, fb: impl FnMut(&str) -> Cow<'static, [u8]>) { /* ... */ }

that stores a fallback closure inside the CursorTheme, that would then be used internally by get_cursor() if the system theme does not provide the requested cursor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, I see

@Decodetalkers Decodetalkers force-pushed the loadcursorfromdata branch 3 times, most recently from e763992 to 7b16293 Compare December 19, 2023 06:14
@Shinyzenith
Copy link
Contributor

Hi gentle ping: @elinorbgr Can we get a review on this? 😄

Copy link
Member

@elinorbgr elinorbgr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long time, this kinda slipped outside of my radar...

LGTM overall, but:

  • the Fallback function should take a size as argument in addition to the cursor name, like the load_cursor, making it possible to have multiple sizes for the fallback cursor if desired
  • Could you expand the documentation of set_fallback() to make it clearer what that callback is supposed to do, and how it's meant to be used ?

@Decodetalkers
Copy link
Contributor Author

Decodetalkers commented Apr 11, 2024

Sorry for the long time, this kinda slipped outside of my radar...

LGTM overall, but:

* the `Fallback` function should take a size as argument in addition to the cursor name, like the `load_cursor`, making it possible to have multiple sizes for the fallback cursor if desired

* Could you expand the documentation of `set_fallback()` to make it clearer what that callback is supposed to do, and how it's meant to be used ?

Ok, is that ok? I have pushed another commit

@Decodetalkers
Copy link
Contributor Author

done @elinorbgr

Decodetalkers and others added 3 commits April 26, 2024 20:44
I want to add a function to load cursor from data
Co-authored-by: Elinor B. <3009227+elinorbgr@users.noreply.github.com>
@Decodetalkers Decodetalkers force-pushed the loadcursorfromdata branch 3 times, most recently from 2f1cc86 to 828c219 Compare April 26, 2024 13:02
@elinorbgr elinorbgr merged commit ff3b13d into Smithay:master Apr 29, 2024
10 of 12 checks passed
@Decodetalkers Decodetalkers deleted the loadcursorfromdata branch April 29, 2024 10:55
/// # Ok(theme)
/// # }
/// ```
pub fn set_callback<F>(&mut self, fallback: F)
Copy link
Contributor

@MarijnS95 MarijnS95 May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While patching up the docs, is it intentional that this is called set_callback() and not set_fallback() (where the fallback is a callback that provides a fallback value when called)?

This function name and docs exclusively speak of a callback, but the get_cursor() function "referencing it" exclusively speaks of fallback, which is confusing on the user end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh.. it is a mistake. can you make a pr for me? thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do it? I don't know what name you want to make this into.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_fallback, it was the author suggested. but then it become a mistake

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Decodetalkers done in #723!

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.

4 participants