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

Inset Mac OS traffic lights #513

Merged
merged 29 commits into from
Oct 26, 2023
Merged

Inset Mac OS traffic lights #513

merged 29 commits into from
Oct 26, 2023

Conversation

haasal
Copy link
Contributor

@haasal haasal commented Aug 3, 2022

What kind of change does this PR introduce?

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

Important: There still exist artifacts when resizing the window because the traffic lights are set just after the window has already been drawn.

@haasal haasal requested a review from a team as a code owner August 3, 2022 16:10
@haasal haasal marked this pull request as draft August 3, 2022 16:10
@haasal haasal changed the title Inset Inset Mac OS traffic lights Aug 3, 2022
@haasal haasal marked this pull request as ready for review August 6, 2022 11:13
@morajabi
Copy link

Thanks for this awesome PR! I had tried doing this only to fail at the "resize" artifacts: #494 Reading your solution made it clear. I should close that issue then.

@PhotonQuantum
Copy link

PhotonQuantum commented Sep 15, 2022

This feature is fantastic!

However, I noticed a strange behavior: the hover effect still shows when I move the cursor to the "original" position of traffic lights. The electron implementation doesn't seem like have this behavior. I dug into its code but failed to find a solution.

Update: strangely, the problem goes away if I resize the window.

@tr3ysmith
Copy link

tr3ysmith commented Jan 18, 2023

Hey what's the status of this? I really would like to be able to apply inset on the traffic lights without work arounds

@haasal
Copy link
Contributor Author

haasal commented Jan 20, 2023

Hi, me too. But I know really little about Tao. If this gets merged then we still have to implement it somehow into tauri.
Could someone review this please?

@wusyong
Copy link
Member

wusyong commented Jan 23, 2023

The implementation seems fine to me. But I'm not sure if it's good to merge now.
@amrbashir Do you think winit can accept this?
Btw you can get the raw window handle to change it yourself if you can't wait for it any longer.

@amrbashir
Copy link
Member

there is a good chance they may not accept but lets go ahead and merge this and if they didn't accept it upstream, we can implement it directly in tauri

examples/macos_traffic_lights.rs Outdated Show resolved Hide resolved
src/platform/macos.rs Outdated Show resolved Hide resolved
src/platform/macos.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/window.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/window.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/window.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/window.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/window.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/window.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/window.rs Outdated Show resolved Hide resolved
@haasal
Copy link
Contributor Author

haasal commented Apr 6, 2023

I'm sorry this has taken so long. I didn't really have time to work on this. I will document the function and delete the example these days. I hope it's not to late to merge?

@haasal haasal requested a review from amrbashir April 28, 2023 11:11
Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

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

Looks fine to me, however I'll hand this to @wusyong and @JonasKruckenberg (since you were interested in this)

@amrbashir
Copy link
Member

Please rebase the PR to fix the conflicts and add a change file

@JonasKruckenberg
Copy link
Member

I'll review this tomorrow, it's a super important imo and this or has been open wayy too long 😉 let's get this over the finish line

@haasal
Copy link
Contributor Author

haasal commented May 3, 2023

Maybe it's important to add that I couldn't test the changes since my MacBook broke 🥺. If one of you could do that it would be amazing

@JonasKruckenberg
Copy link
Member

After testing this PR now, I feel LogicalSize makes no sense here, the way you currently call the method is as such

                                      // WTH means width here? and height?
.with_traffic_light_inset(LogicalSize { width: 10, height: 20 });

@JonasKruckenberg
Copy link
Member

Okay a few other observations:

  1. While this does successfully inset the traffic lights, it does not increase the draggable area size
  2. When resizing the window, it looses the inset

The second one really is a dealbreaker right now, I guess we need to implement a delegate and stuff just like electron does as well

@haasal
Copy link
Contributor Author

haasal commented May 3, 2023

Okay a few other observations:

1. While this does successfully inset the traffic lights, it does not increase the draggable area size

2. When resizing the window, it looses the inset

The second one really is a dealbreaker right now, I guess we need to implement a delegate and stuff just like electron does as well

I don't know if you fixed it already in that commit, but when I tested it with my supplied example the inset was persistent during resizing of the window.

@JonasKruckenberg
Copy link
Member

JonasKruckenberg commented May 3, 2023

I don't know if you fixed it already in that commit, but when I tested it with my supplied example the inset was persistent during resizing of the window.

Okay yes my bad, calling the set_traffic_light_inset method after the RedrawRequested event got fired fixes the artifacts.

My only question @haasal is why the with_traffic_light_inset method exists if it's not really doing what the user expects. This feels like misleading api design

@JonasKruckenberg
Copy link
Member

@amrbashir I added back the example, since it's indeed needed to use the method correctly (it's not enough to just call it once but it needs to be called after RedrawRequested)

@haasal
Copy link
Contributor Author

haasal commented May 3, 2023

Yeah that was the reason I made the example. I already tried implementing this in Tauri itself using the raw window handle but I couldn't get rid of these artifacts. Do you think this method can now be used in tauri without causing artifacts?

@haasal
Copy link
Contributor Author

haasal commented May 3, 2023

My only question @haasal is why the with_traffic_light_inset method exists if it's not really doing what the user expects. This feels like misleading api design

I don't know how to implement it instead. This whole thing gave me big headaches because I couldn't find a way to set the inset without having to call the method in some weird way. If you have any idea how to do this without having to call the method after RedrawRequested it would be great!

@amrbashir
Copy link
Member

I still don't see why the example is needed since tao should already handle that internally and not require users to keep calling it in RedrawRequested

@JonasKruckenberg
Copy link
Member

I still don't see why the example is needed since tao should already handle that internally and not require users to keep calling it in RedrawRequested

then we should change it to behave that way

@haasal
Copy link
Contributor Author

haasal commented May 3, 2023

I really would like to get this over with but as said earlier I don't really know how. If you know how to directly inject something into the "window draw pipeline" (I.e. how to automatically call my inset-method/function without requiring the user to do some weird setup) I could take a look at it

@amrbashir
Copy link
Member

@haasal you need add an inset field on the ViewState struct here

pub(super) struct ViewState {
and your new function set_traffic_light_inset sets this field, then in draw_rect
extern "C" fn draw_rect(this: &Object, _sel: Sel, rect: NSRect) {
you have access to the state where you can read it and re-position the tarffic lights

@haasal
Copy link
Contributor Author

haasal commented Oct 26, 2023

@wusyong I didn't do anything like this before and I don't want to mess up even worse. Do you mean pulling from upstream onto my dev branch and then merging with all of my contributions squashed into one commit? Wouldn't this negate all my commit messages?

haasal and others added 25 commits October 26, 2023 16:16
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Example not needed

Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Deleted outdated TODO

Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
The set_traffic_light_offset() method on window was removed and only the builder function now has to be called to set the offset. No more manual event handling is needed.

Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
the example is no longer needed as the api design is now clear and only one method call is needed to set the inset

Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
the set_traffic_light_position on window will now work as expected. I.e. only one call is necessary

Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Also unified the api to always use inset instead of position

Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Signed-off-by: amrbashir <amr.bashir2015@gmail.com>
Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

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

I guess it is ready for merge now, @wusyong would you mind testing and merge?

@wusyong wusyong merged commit f7e4991 into tauri-apps:dev Oct 26, 2023
9 checks passed
@haasal haasal deleted the inset branch October 26, 2023 14:32
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.

7 participants