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

Cross Platform WinHandler #13

Closed
rylev opened this issue Jan 29, 2019 · 2 comments
Closed

Cross Platform WinHandler #13

rylev opened this issue Jan 29, 2019 · 2 comments

Comments

@rylev
Copy link
Collaborator

rylev commented Jan 29, 2019

With #11 drawing will be cross platform. The question is then "what next?". I propose we next try to make WinHandler cross platform. WinHandler is the trait that defines how to respond to window events like painting, size changes and keyboard/mouse events.

Here's a list of items that need to be addressed:

  • WinHandler::connect takes a WindowHandle which has a weak reference to a WindowState which is highly Windows specific as it has a reference to HWND and WndProc. connect stores the WindowHandle on the state's LayoutContext. The handle is used for the following: invalidating widgets, closing the window, file dialog, converting physical pixels to px units, getting the current dpi. Perhaps this can all be abstracted away in a trait that is made concrete in a similar way that we do with piet-common
  • The various keyboard handlers take modifier keys which can be different on different platforms. We could solve this the same way web APIs do: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState
  • Realted to the first issue: WinHandler::mouse, WinHandler::mouse_move and WinHandler::size all use the windows specific WindowHandle that is stored on the UiState's LayoutContext
  • WinHandler::destroy calls the windows specific win_main::request_quit()

Thoughts on how to abstract WindowHandle and how to handle modifier keys?

@raphlinus
Copy link
Contributor

I'll just dump a few thoughts, as I haven't gone through all issues.

First, I think of this problem as morphing druid-win-shell into druid-shell, and shedding Windows dependencies in the process. Since the WinHandler trait is the main point of interface, it's much the same thing, but not entirely. Likely WindowState and WindowHandle will become opaque types.

I'm not sure whether to use a trait-made-concrete (like RenderContext, also gfx-hal is a model of this pattern), or just different impls. One model for the latter is the filesystem in the Rust std lib. One good reason to use the trait is to enable generic code that can use multiple impls, perhaps in the same binary. I think that will be much less important at the "shell" level than drawing.

Keyboard and mouse constants are an issue. I think basing them on the web is a very good idea, as this is well-trodden terrain.

Exactly what should implement the request_quit method is a good question. We don't really have an object that represents application scope (as opposed to window), but almost certainly we will need it for other things (access to preferences comes to mind). Probably a good time to create that now.

One other thought. Windows uses "dpi" where 96 is nominal, but I think I would rather use a dpi scale where 1.0 is nominal. On Windows, dpi scale = dpi / 96, but on other platforms this wouldn't be strictly true. I also tend to talk about px units, using roughly the same definition as the Web. (Terminology for this is really confusing, on Mac these are called "points", not to be confused with the print unit of the same name).

raphlinus added a commit that referenced this issue Feb 13, 2019
As part of platform independence, rename druid-win-shell to remove the
reference to a specific platform.

Also fixes druid-shell examples, which were slightly broken.

Normalizes line endings to LF (not CRLF).

Part of #13
raphlinus added a commit that referenced this issue Feb 13, 2019
All the windows specific code is now in the windows subdir. The goal of
this patch is to preserve druid-shell function on windows, and have it
compile (with basically no functionality) on mac.

Part of #13
@raphlinus
Copy link
Contributor

Closing this, as we've been cross platform for a while, and I think all other relevant details are captured in other issues.

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

No branches or pull requests

2 participants