Coder Social home page Coder Social logo

rust-windowing / winit Goto Github PK

View Code? Open in Web Editor NEW
4.4K 60.0 860.0 9.84 MB

Window handling library in pure Rust

Home Page: https://docs.rs/winit/

License: Apache License 2.0

Rust 100.00%
rust windowing android ios macos wasm wayland windows x11 gui

winit's Introduction

winit - Cross-platform window creation and management in Rust

Crates.io Docs.rs Master Docs CI Status

[dependencies]
winit = "0.29.15"

For features within the scope of winit, see FEATURES.md.

For features outside the scope of winit, see Are we GUI Yet? and Are we game yet?, depending on what kind of project you're looking to do.

Contact Us

Join us in our Matrix room. If you don't get an answer there, try Libera.Chat.

The maintainers have a meeting every friday at UTC 15. The meeting notes can be found here.

Usage

Winit is a window creation and management library. It can create windows and lets you handle events (for example: the window being resized, a key being pressed, a mouse movement, etc.) produced by the window.

Winit is designed to be a low-level brick in a hierarchy of libraries. Consequently, in order to show something on the window you need to use the platform-specific getters provided by winit, or another library.

MSRV Policy

This crate's Minimum Supported Rust Version (MSRV) is 1.70. Changes to the MSRV will be accompanied by a minor version bump.

As a tentative policy, the upper bound of the MSRV is given by the following formula:

min(sid, stable - 3)

Where sid is the current version of rustc provided by Debian Sid, and stable is the latest stable version of Rust. This bound may be broken in case of a major ecosystem shift or a security vulnerability.

The exception is for the Android platform, where a higher Rust version must be used for certain Android features. In this case, the MSRV will be capped at the latest stable version of Rust minus three. This inconsistency is not reflected in Cargo metadata, as it is not powerful enough to expose this restriction.

All crates in the rust-windowing organizations have the same MSRV policy.

Platform-specific usage

Check out the winit::platform module for platform-specific usage.

winit's People

Contributors

amrbashir avatar arturkovacs avatar brendanzab avatar chrisduerr avatar daxpedda avatar elinorbgr avatar felixrabe avatar fkaa avatar francesca64 avatar frewsxcv avatar gw3583 avatar hecrj avatar jwilm avatar kchibisov avatar madsmtm avatar marijns95 avatar maroider avatar mitchmindtree avatar msiglreith avatar murarth avatar notgull avatar osspial avatar ozkriff avatar paulrouget avatar pedrocr avatar rib avatar rukai avatar ryanisaacg avatar tomaka avatar vberger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

winit's Issues

RFC: Switch to a futures-compatible API

Winit's and glutin's current API look like this:

impl Window {
    pub fn wait_events(&self) -> impl Iterator<Item = Event> { ... }
    pub fn poll_events(&self) -> impl Iterator<Item = Event> { ... }
}

I suggest that instead you'd have to register your window to what's called an events loop. Then, you'd call a method on the events loop to run it. Running the events loop would process events received by the operating system, and call a callback previously registered on the window.

This is essentially the same approach as the future-rs library, except that we're not using future-rs directly because it's not totally stable. I'd like to eventually publish winit 1.0 (in, like, the next nine months or so), and it's unlikely that future-rs publishes its 1.0 before winit.

Example usage with the new API (just to give an overview, the details are not important at the moment):

let events_loop = EventsLoop::new();
let window = WindowBuilder::new().with_title("hello").build(&events_loop).unwrap();
window.set_callback(|event| match event { ... });

loop {
    events_loop.run_once();     // calls the closure passed to set_callback earlier
}

I've always been a bit wary about callbacks because they are often too "magical", like you don't know which thread calls them and at what moment. But the fact that it's the run() method of the events loop that calls the callbacks means that it's a good design in my opinion.

This approach would have some benefits over the current system:

  • In the implementation we can decouple the Window object in Rust from the actual window. The actual window could be stored in the EventsLoop for example.
  • Right now on Windows winit spawns a background thread for events handling ; this could be removed.
  • We can force the EventsLoop to run on the main thread for OSX while still allowing the Window objects to be shared between threads. This has been a huge safety hole in glutin since the beginning.
  • The set_resize_callback function of MacOS would be gone.
  • The WindowProxy would be gone in favor of an "EventsLoopProxy".
  • We can later register other kinds of callbacks to the events loop, for example a callback when a monitoring is plugged in or removed that is not tied to particular window.
  • This design is also more appropriate for emscripten in glutin, as emscripten/javascript are based on callbacks and not on preemptive multitasking.

How to handle MouseWheel when both pixel and line deltas are available ?

In some cases (if the compositor supports it), the wayland backend can have access to both LineDelta and PixelDelta values for a given scroll event.

In this case, what should be done ?

  • generate only the PixelDelta event ?
  • generate only the LineDelta event ?
  • generate both ?
  • modify the MouseWheel event so that it may provide both values ?

Window example on wayland creates 0x0 pixels window

It looks like winit doesn't resize wayland window after start (resize_callback function have not been called).
I've checked glutin example on wayland and it works well. Then I checked the difference beetween api/wayland/window.rs in winit and glutin and found out that there is no resize calls in winit. For example: glutin and winit. It seems to me that there should be some code to resize surface, but I haven't find any API in wayland-client to do so.

Add method to close window

You provided a possibility to create/show/hide/resize window:
pub fn hide(&self) { self.window.hide() }
But I sure that 'pub fn close' method is also can be provided.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.