zkxs / simple-crosshair-overlay

A simple and performant crosshair overlay
GNU General Public License v3.0
18 stars 4 forks source link

MacOS Support #3

Open zkxs opened 1 year ago

zkxs commented 1 year ago

Simple Crosshair Overlay should mostly work on MacOS, but I don't have access to a system to test that on and I'm very doubtful it will work out of the box without any platform specific tweaks.

Homework for me:

Homework for you, dear reader:

If anyone gives this a try I recommend starting the program from a terminal, so when it inevitably crashes you can capture the backtrace for us to analyze.

TartanBeardy commented 8 months ago

Hi I have followed the instructions, installed Rust, and it downloaded and installed. Now what do I do? How do I run it?

zkxs commented 8 months ago

Hi, thanks for being the first person to try it on Mac. I'm not sure which set of instructions you followed. If it was the "Installing from Source" section, you should be able to just run simple-crosshair-overlay as a command in your terminal.

akilegaspi commented 6 months ago

Hi, thanks for the work @zkxs:

Here's the exception I get when running the binary and also building from source.

thread 'main' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.10/src/platform_impl/macos/event_loop.rs:200:13:
`winit` requires control over the principal class. You must create the event loop before other parts of your application initialize NSApplication
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
akilegaspi commented 6 months ago

Submitted a PR regarding the exception I mentioned here #52

zkxs commented 6 months ago

52 is merged and included in release 1.1.3. Please let me know if it works on Mac with this change: I'd like to make note of any known issues (or lack thereof) in the readme.

akilegaspi commented 6 months ago

Works on Mac except the crosshair is not on a transparent layer but black layer, I haven't figured out yet how to fix it

zkxs commented 6 months ago

Hmm, I've only got a couple of ideas:

  1. On Windows, I found that the window behavior is very sensitive to the order in which I set window settings, especially that some can only be changed after the window is already visible. You can see in init_window the aftermath of me fighting with Windows for a while to get things working as desired. I wouldn't be surprised if MacOS has similar things going on. Don't be afraid to totally reorder everything I'm doing in that function and see if it changes anything. In particular, try removing the .with_visible(false) call and see if anything happens.
  2. Windows expects ARGB with premultiplied alpha. I don't know if Mac expects this pixel format, so I currently am using my best-guess and giving it ARGB with normal alpha (no premultiplication). If this is affecting you then with the default red + crosshair the background would be transparent as expected, but the red crosshair would be fully opaque instead of the intended 70% opaque. If you suspect that it might need premultiplied alpha, try out this change I've put on a new macos-premultiply-alpha branch. If MacOS wants a different pixel format than 32-bit ARGB then things are gonna get complicated.
  3. Winit has some mac-specific WindowBuilder functions you might want to experiment with to see if they do anything useful. You can see where I use some of the Windows-specific functions here if you want to add a similar block for MacOS.