2017-06-22 05:10:23 +10:00
//! Winit allows you to build a window on as many platforms as possible.
2014-08-03 04:49:48 +10:00
//!
//! # Building a window
2014-09-04 19:38:33 +10:00
//!
2017-01-29 01:33:54 +11:00
//! Before you can build a window, you first need to build an `EventsLoop`. This is done with the
//! `EventsLoop::new()` function. Example:
2014-09-04 19:38:33 +10:00
//!
2017-01-29 01:33:54 +11:00
//! ```no_run
//! use winit::EventsLoop;
//! let events_loop = EventsLoop::new();
//! ```
//!
//! Once this is done there are two ways to create a window:
//!
//! - Calling `Window::new(&events_loop)`.
//! - Calling `let builder = WindowBuilder::new()` then `builder.build(&events_loop)`.
2014-08-03 04:49:48 +10:00
//!
2018-05-21 00:47:22 +10:00
//! The first way is the simplest way and will give you default values for everything.
2014-08-03 04:49:48 +10:00
//!
2016-11-03 19:49:19 +11:00
//! The second way allows you to customize the way your window will look and behave by modifying
//! the fields of the `WindowBuilder` object before you create the window.
2014-10-05 04:17:02 +11:00
//!
2016-11-03 19:49:19 +11:00
//! # Events handling
2014-10-05 04:17:02 +11:00
//!
2017-01-29 01:33:54 +11:00
//! Once a window has been created, it will *generate events*. For example whenever the user moves
//! the window, resizes the window, moves the mouse, etc. an event is generated.
//!
2018-07-28 04:59:53 +10:00
//! The events generated by a window can be retrieved from the `EventsLoop` the window was created
2017-01-29 01:33:54 +11:00
//! with.
//!
//! There are two ways to do so. The first is to call `events_loop.poll_events(...)`, which will
2018-07-28 04:59:53 +10:00
//! retrieve all the events pending on the windows and immediately return after no new event is
2017-01-29 01:33:54 +11:00
//! available. You usually want to use this method in application that render continuously on the
//! screen, such as video games.
//!
//! ```no_run
2017-06-08 00:12:41 +10:00
//! use winit::{Event, WindowEvent};
2018-06-15 09:42:18 +10:00
//! use winit::dpi::LogicalSize;
2017-01-29 01:33:54 +11:00
//! # use winit::EventsLoop;
2017-06-08 00:12:41 +10:00
//! # let mut events_loop = EventsLoop::new();
2017-01-29 01:33:54 +11:00
//!
//! loop {
//! events_loop.poll_events(|event| {
//! match event {
2018-06-15 09:42:18 +10:00
//! Event::WindowEvent {
//! event: WindowEvent::Resized(LogicalSize { width, height }),
//! ..
//! } => {
//! println!("The window was resized to {}x{}", width, height);
2017-01-29 01:33:54 +11:00
//! },
//! _ => ()
//! }
//! });
//! }
//! ```
//!
//! The second way is to call `events_loop.run_forever(...)`. As its name tells, it will run
2017-06-20 21:25:53 +10:00
//! forever unless it is stopped by returning `ControlFlow::Break`.
2017-01-29 01:33:54 +11:00
//!
//! ```no_run
2017-06-08 00:12:41 +10:00
//! use winit::{ControlFlow, Event, WindowEvent};
2017-01-29 01:33:54 +11:00
//! # use winit::EventsLoop;
2017-06-08 00:12:41 +10:00
//! # let mut events_loop = EventsLoop::new();
2017-01-29 01:33:54 +11:00
//!
//! events_loop.run_forever(|event| {
//! match event {
2018-04-25 06:20:40 +10:00
//! Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
//! println!("The close button was pressed; stopping");
2017-06-20 21:25:53 +10:00
//! ControlFlow::Break
2017-01-29 01:33:54 +11:00
//! },
2017-06-08 00:12:41 +10:00
//! _ => ControlFlow::Continue,
2017-01-29 01:33:54 +11:00
//! }
//! });
//! ```
//!
//! If you use multiple windows, the `WindowEvent` event has a member named `window_id`. You can
//! compare it with the value returned by the `id()` method of `Window` in order to know which
//! window has received the event.
2014-10-05 04:17:02 +11:00
//!
2016-11-03 19:49:19 +11:00
//! # Drawing on the window
//!
//! Winit doesn't provide any function that allows drawing on a window. However it allows you to
2018-07-28 04:59:53 +10:00
//! retrieve the raw handle of the window (see the `os` module for that), which in turn allows you
2016-11-03 19:49:19 +11:00
//! to create an OpenGL/Vulkan/DirectX/Metal/etc. context that will draw on the window.
2014-10-05 04:17:02 +11:00
//!
2014-08-03 04:49:48 +10:00
2018-06-15 09:42:18 +10:00
#[ allow(unused_imports) ]
2015-04-03 17:33:51 +11:00
#[ macro_use ]
extern crate lazy_static ;
2014-07-27 18:55:37 +10:00
extern crate libc ;
2018-07-02 01:01:46 +10:00
#[ macro_use ]
extern crate log ;
2018-05-08 07:36:21 +10:00
#[ cfg(feature = " icon_loading " ) ]
extern crate image ;
2014-07-27 18:55:37 +10:00
2014-12-02 04:24:15 +11:00
#[ cfg(target_os = " windows " ) ]
extern crate winapi ;
2015-06-05 23:38:21 +10:00
#[ cfg(any(target_os = " macos " , target_os = " ios " )) ]
2015-03-22 16:31:32 +11:00
#[ macro_use ]
extern crate objc ;
#[ cfg(target_os = " macos " ) ]
2014-10-04 23:49:39 +10:00
extern crate cocoa ;
#[ cfg(target_os = " macos " ) ]
extern crate core_foundation ;
2014-11-05 04:03:38 +11:00
#[ cfg(target_os = " macos " ) ]
2015-06-04 14:13:18 +10:00
extern crate core_graphics ;
2018-07-17 00:25:27 +10:00
#[ cfg(any(target_os = " linux " , target_os = " dragonfly " , target_os = " freebsd " , target_os = " netbsd " , target_os = " openbsd " )) ]
2015-05-07 21:20:25 +10:00
extern crate x11_dl ;
2018-07-17 00:25:27 +10:00
#[ cfg(any(target_os = " linux " , target_os = " dragonfly " , target_os = " freebsd " , target_os = " netbsd " , target_os = " openbsd " )) ]
X11: General cleanup (#491)
* X11: General cleanup
This is almost entirely internal changes, and as usual, doesn't actually
fix any problems people have complained about.
- `XSetInputFocus` can't be called before the window is visible. This
was previously handled by looping (with a sleep) and querying for the
window's state until it was visible. Now we use `XIfEvent`, which blocks
until we receive `VisibilityNotify`. Note that this can't be replaced
with an `XSync` (I tried).
- We now call `XSync` at the end of window creation and check for
errors, assuring that broken windows are never returned. When creating
invisible windows, this is the only time the output buffer is flushed
during the entire window creation process (AFAIK). For visible windows,
`XIfEvent` will generally flush, but window creation has overall been
reduced to the minimum number of flushes.
- `check_errors().expect()` has been a common pattern throughout the
backend, but it seems that people (myself included) didn't make a
distinction between using it after synchronous requests and asynchronous
requests. Now we only use it after async requests if we flush first,
though this still isn't correct (since the request likely hasn't been
processed yet). The only real solution (besides forcing a sync *every
time*) is to handle asynchronous errors *asynchronously*. For future
work, I plan on adding logging, though I don't plan on actually
*handling* those errors; that's more of something to hope for in the
hypothetical async/await XCB paradise.
- We now flush whenever it makes sense to. `util::Flusher` was added to
force contributors to be aware of the output buffer.
- `Window::get_position`, `Window::get_inner_position`,
`Window::get_inner_size`, and `Window::get_outer_size` previously all
required *several* round-trips. On my machine, it took an average of
around 80µs. They've now been reduced to one round-trip each, which
reduces my measurement to 16µs. This was accomplished simply by caching
the frame extents, which are expensive to calculate (due to various
queries and heuristics), but change infrequently and predictably. I
still recommend that application developers use these methods sparingly
and generally prefer storing the values from `Resized`/`Moved`, as
that's zero overhead.
- The above change enabled me to change the `Moved` event to supply
window positions, rather than client area positions. Additionally, we no
longer generate `Moved` for real (as in, not synthetic)
`ConfigureNotify` events. Real `ConfigureNotify` events contain
positions relative to the parent window, which are typically constant
and useless. Since that position would be completely different from the
root-relative positions supplied by synthetic `ConfigureNotify` events
(which are the vast majority of them), that meant real `ConfigureNotify`
events would *always* be detected as the position having changed, so the
resultant `Moved` was multiple levels of misleading. In practice, this
meant a garbage `Moved` would be sent every time the window was resized;
now a resize has to actually change the window's position to be
accompanied by `Moved`.
- Every time we processed an `XI_Enter` event, we would leak 4 bytes via
`util::query_pointer` (`XIQueryPointer`). `XIButtonState` contains a
dynamically-allocated mask field which we weren't freeing. As this event
occurs with fairly high frequency, long-running applications could
easily accumulate substantial leaks. `util::PointerState::drop` now
takes care of this.
- The `util` module has been split up into several sub-modules, as it
was getting rather lengthy. This accounts for a significant part of this
diff, unfortunately.
- Atoms are now cached. Xlib caches them too, so `XInternAtom` wouldn't
typically be a round-trip anyway, but the added complexity is
negligible.
- Switched from `std::sync::Mutex` to `parking_lot::Mutex` (within this
backend). There appears to be no downside to this, but if anyone finds
one, this would be easy to revert.
- The WM name and supported hints are now global to the application, and
are updated upon `ReparentNotify`, which should detect when the WM was
replaced (assuming a reparenting WM was involved, that is). Previously,
these values were per-window and would never update, meaning replacing
the WM could potentially lead to (admittedly very minor) problems.
- The result of `Window2::create_empty_cursor` will now only be used if
it actually succeeds.
- `Window2::load_cursor` no longer re-allocates the cursor name.
- `util::lookup_utf8` previously allocated a 16-byte buffer on the heap.
Now it allocates a 1024-byte buffer on the stack, and falls back to
dynamic allocation if the buffer is too small. This base buffer size is
admittedly gratuitous, but less so if you're using IME.
- `with_c_str` was finally removed.
- Added `util::Format` enum to help prevent goofs when dealing with
format arguments.
- `util::get_property`, something I added way back in my first winit PR,
only calculated offsets correctly for `util::Format::Char`. This was
concealed by the accomodating buffer size, as it would be very rare for
the offset to be needed; however, testing with a buffer size of 1,
`util::Format::Long` would read from the same offset multiple times, and
`util::Format::Short` would miss data. This function now works correctly
for all formats, relying on the simple fact that the offset increases by
the buffer size on each iteration. We also account for the extra byte
that `XGetWindowProperty` allocates at the end of the buffer, and copy
data from the buffer instead of moving it and taking ownership of the
pointer.
- Drag and drop now reliably works in release mode. This is presumably
related to the `util::get_property` changes.
- `util::change_property` now exists, which should make it easier to add
features in the future.
- The `EventsLoop` device map is no longer in a mutex.
- `XConnection` now implements `Debug`.
- Valgrind no longer complains about anything related to winit (with
either the system allocator or jemalloc, though "not having valgrind
complain about jemalloc" isn't something to strive for).
* X11: Add better diagnostics when initialization fails
* X11: Handle XIQueryDevice failure
* X11: Use correct types in error handler
2018-05-03 23:15:49 +10:00
extern crate parking_lot ;
2018-07-17 00:25:27 +10:00
#[ cfg(any(target_os = " linux " , target_os = " dragonfly " , target_os = " freebsd " , target_os = " netbsd " , target_os = " openbsd " )) ]
2017-12-13 22:22:03 +11:00
extern crate percent_encoding ;
2018-08-02 05:22:14 +10:00
#[ cfg(any(target_os = " linux " , target_os = " dragonfly " , target_os = " freebsd " , target_os = " netbsd " , target_os = " openbsd " )) ]
2018-05-06 03:36:34 +10:00
extern crate smithay_client_toolkit as sctk ;
2014-10-04 23:49:39 +10:00
2018-06-15 09:42:18 +10:00
pub ( crate ) use dpi ::* ; // TODO: Actually change the imports throughout the codebase.
2014-07-30 21:11:49 +10:00
pub use events ::* ;
2017-09-01 19:04:57 +10:00
pub use window ::{ AvailableMonitorsIter , MonitorId } ;
2018-05-08 07:36:21 +10:00
pub use icon ::* ;
2014-08-13 22:52:12 +10:00
2018-06-15 09:42:18 +10:00
pub mod dpi ;
2014-07-27 20:59:45 +10:00
mod events ;
2018-05-08 07:36:21 +10:00
mod icon ;
2018-06-15 09:42:18 +10:00
mod platform ;
mod window ;
2014-07-28 04:38:27 +10:00
2015-09-26 02:04:55 +10:00
pub mod os ;
2016-11-03 19:49:19 +11:00
/// Represents a window.
2015-09-26 02:04:55 +10:00
///
/// # Example
///
2016-11-03 19:49:19 +11:00
/// ```no_run
2017-06-08 00:12:41 +10:00
/// use winit::{Event, EventsLoop, Window, WindowEvent, ControlFlow};
2017-01-29 01:33:54 +11:00
///
2017-06-08 00:12:41 +10:00
/// let mut events_loop = EventsLoop::new();
2017-01-29 01:33:54 +11:00
/// let window = Window::new(&events_loop).unwrap();
2015-09-26 02:04:55 +10:00
///
2017-01-29 01:33:54 +11:00
/// events_loop.run_forever(|event| {
/// match event {
2018-04-25 06:20:40 +10:00
/// Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
2017-06-20 21:25:53 +10:00
/// ControlFlow::Break
2017-01-29 01:33:54 +11:00
/// },
2017-06-08 00:12:41 +10:00
/// _ => ControlFlow::Continue,
2015-09-26 02:04:55 +10:00
/// }
2017-01-29 01:33:54 +11:00
/// });
2015-09-26 02:04:55 +10:00
/// ```
pub struct Window {
2017-09-07 01:32:24 +10:00
window : platform ::Window ,
2017-01-29 01:00:17 +11:00
}
2017-02-03 19:13:11 +11:00
/// Identifier of a window. Unique for each window.
///
/// Can be obtained with `window.id()`.
///
/// Whenever you receive an event specific to a window, this event contains a `WindowId` which you
/// can then compare to the ids of your windows.
#[ derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash) ]
pub struct WindowId ( platform ::WindowId ) ;
2017-04-23 06:52:35 +10:00
/// Identifier of an input device.
///
/// Whenever you receive an event arising from a particular input device, this event contains a `DeviceId` which
/// identifies its origin. Note that devices may be virtual (representing an on-screen cursor and keyboard focus) or
/// physical. Virtual devices typically aggregate inputs from multiple physical devices.
#[ derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash) ]
pub struct DeviceId ( platform ::DeviceId ) ;
2018-07-28 04:59:53 +10:00
/// Provides a way to retrieve events from the system and from the windows that were registered to
2017-09-18 03:59:36 +10:00
/// the events loop.
2017-05-25 02:29:51 +10:00
///
2017-09-18 03:59:36 +10:00
/// An `EventsLoop` can be seen more or less as a "context". Calling `EventsLoop::new()`
/// initializes everything that will be required to create windows. For example on Linux creating
/// an events loop opens a connection to the X or Wayland server.
2017-06-22 05:10:23 +10:00
///
2017-09-18 03:59:36 +10:00
/// To wake up an `EventsLoop` from a another thread, see the `EventsLoopProxy` docs.
2017-10-19 05:40:21 +11:00
///
/// Note that the `EventsLoop` cannot be shared accross threads (due to platform-dependant logic
/// forbiding it), as such it is neither `Send` nor `Sync`. If you need cross-thread access, the
/// `Window` created from this `EventsLoop` _can_ be sent to an other thread, and the
/// `EventsLoopProxy` allows you to wakeup an `EventsLoop` from an other thread.
2017-01-29 01:00:17 +11:00
pub struct EventsLoop {
2017-06-02 21:19:45 +10:00
events_loop : platform ::EventsLoop ,
2017-10-19 05:40:21 +11:00
_marker : ::std ::marker ::PhantomData < * mut ( ) > // Not Send nor Sync
2017-06-02 21:19:45 +10:00
}
/// Returned by the user callback given to the `EventsLoop::run_forever` method.
///
/// Indicates whether the `run_forever` method should continue or complete.
#[ derive(Copy, Clone, Debug, PartialEq, Eq) ]
pub enum ControlFlow {
/// Continue looping and waiting for events.
Continue ,
2017-06-20 21:25:53 +10:00
/// Break from the event loop.
Break ,
2017-01-29 01:00:17 +11:00
}
impl EventsLoop {
/// Builds a new events loop.
2017-09-18 03:59:36 +10:00
///
/// Usage will result in display backend initialisation, this can be controlled on linux
/// using an environment variable `WINIT_UNIX_BACKEND`. Legal values are `x11` and `wayland`.
/// If it is not set, winit will try to connect to a wayland connection, and if it fails will
/// fallback on x11. If this variable is set with any other value, winit will panic.
2017-01-29 01:00:17 +11:00
pub fn new ( ) -> EventsLoop {
EventsLoop {
2017-06-02 21:19:45 +10:00
events_loop : platform ::EventsLoop ::new ( ) ,
2017-10-19 05:40:21 +11:00
_marker : ::std ::marker ::PhantomData ,
2017-01-29 01:00:17 +11:00
}
}
2017-09-18 03:59:36 +10:00
/// Returns the list of all the monitors available on the system.
2017-09-01 19:04:57 +10:00
///
// Note: should be replaced with `-> impl Iterator` once stable.
#[ inline ]
pub fn get_available_monitors ( & self ) -> AvailableMonitorsIter {
let data = self . events_loop . get_available_monitors ( ) ;
AvailableMonitorsIter { data : data . into_iter ( ) }
}
/// Returns the primary monitor of the system.
#[ inline ]
pub fn get_primary_monitor ( & self ) -> MonitorId {
MonitorId { inner : self . events_loop . get_primary_monitor ( ) }
}
2017-01-29 01:33:54 +11:00
/// Fetches all the events that are pending, calls the callback function for each of them,
/// and returns.
2017-01-29 01:00:17 +11:00
#[ inline ]
2017-06-02 21:19:45 +10:00
pub fn poll_events < F > ( & mut self , callback : F )
2017-01-29 01:00:17 +11:00
where F : FnMut ( Event )
{
self . events_loop . poll_events ( callback )
}
2017-09-18 03:59:36 +10:00
/// Calls `callback` every time an event is received. If no event is available, sleeps the
/// current thread and waits for an event. If the callback returns `ControlFlow::Break` then
/// `run_forever` will immediately return.
2018-06-15 09:42:18 +10:00
///
/// # Danger!
///
/// The callback is run after *every* event, so if its execution time is non-trivial the event queue may not empty
/// at a sufficient rate. Rendering in the callback with vsync enabled **will** cause significant lag.
2017-01-29 01:00:17 +11:00
#[ inline ]
2017-06-02 21:19:45 +10:00
pub fn run_forever < F > ( & mut self , callback : F )
where F : FnMut ( Event ) -> ControlFlow
2017-01-29 01:00:17 +11:00
{
self . events_loop . run_forever ( callback )
}
2017-01-29 01:09:01 +11:00
2017-05-25 02:29:51 +10:00
/// Creates an `EventsLoopProxy` that can be used to wake up the `EventsLoop` from another
/// thread.
pub fn create_proxy ( & self ) -> EventsLoopProxy {
EventsLoopProxy {
2017-05-25 23:19:13 +10:00
events_loop_proxy : self . events_loop . create_proxy ( ) ,
2017-05-25 02:29:51 +10:00
}
}
}
2017-05-25 23:19:13 +10:00
/// Used to wake up the `EventsLoop` from another thread.
2017-10-26 05:03:57 +11:00
#[ derive(Clone) ]
2017-05-25 23:19:13 +10:00
pub struct EventsLoopProxy {
events_loop_proxy : platform ::EventsLoopProxy ,
}
2017-05-25 02:29:51 +10:00
impl EventsLoopProxy {
/// Wake up the `EventsLoop` from which this proxy was created.
///
/// This causes the `EventsLoop` to emit an `Awakened` event.
2017-05-25 23:19:13 +10:00
///
/// Returns an `Err` if the associated `EventsLoop` no longer exists.
pub fn wakeup ( & self ) -> Result < ( ) , EventsLoopClosed > {
self . events_loop_proxy . wakeup ( )
}
}
/// The error that is returned when an `EventsLoopProxy` attempts to wake up an `EventsLoop` that
/// no longer exists.
#[ derive(Debug, Copy, Clone, PartialEq, Eq, Hash) ]
pub struct EventsLoopClosed ;
impl std ::fmt ::Display for EventsLoopClosed {
fn fmt ( & self , f : & mut std ::fmt ::Formatter ) -> std ::fmt ::Result {
write! ( f , " {} " , std ::error ::Error ::description ( self ) )
}
}
impl std ::error ::Error for EventsLoopClosed {
fn description ( & self ) -> & str {
" Tried to wake up a closed `EventsLoop` "
2017-05-25 02:29:51 +10:00
}
2015-09-26 02:04:55 +10:00
}
2016-04-29 09:30:44 +10:00
/// Object that allows you to build windows.
2016-05-23 16:17:31 +10:00
#[ derive(Clone) ]
2016-09-20 02:53:28 +10:00
pub struct WindowBuilder {
2016-04-29 09:30:44 +10:00
/// The attributes to use to create the window.
pub window : WindowAttributes ,
2016-11-03 19:49:19 +11:00
// Platform-specific configuration. Private.
2016-04-29 09:30:44 +10:00
platform_specific : platform ::PlatformSpecificWindowBuilderAttributes ,
}
2014-11-06 02:42:18 +11:00
/// Error that can happen while creating a window or a headless renderer.
2017-08-24 11:52:06 +10:00
#[ derive(Debug, Clone) ]
2014-11-06 02:42:18 +11:00
pub enum CreationError {
OsError ( String ) ,
2015-07-21 03:43:36 +10:00
/// TODO: remove this error
2014-12-29 01:53:24 +11:00
NotSupported ,
2014-11-06 02:42:18 +11:00
}
2015-01-24 12:50:06 +11:00
impl CreationError {
fn to_string ( & self ) -> & str {
2015-02-22 10:07:35 +11:00
match * self {
2015-03-26 05:57:38 +11:00
CreationError ::OsError ( ref text ) = > & text ,
2015-02-22 10:07:35 +11:00
CreationError ::NotSupported = > " Some of the requested attributes are not supported " ,
2014-11-06 02:42:18 +11:00
}
}
}
2015-01-24 12:50:06 +11:00
impl std ::fmt ::Display for CreationError {
fn fmt ( & self , formatter : & mut std ::fmt ::Formatter ) -> Result < ( ) , std ::fmt ::Error > {
formatter . write_str ( self . to_string ( ) )
}
}
impl std ::error ::Error for CreationError {
fn description ( & self ) -> & str {
self . to_string ( )
2015-09-20 16:42:32 +10:00
}
2015-12-19 21:24:09 +11:00
}
2017-09-25 23:58:59 +10:00
/// Describes the appearance of the mouse cursor.
2016-08-18 04:42:45 +10:00
#[ derive(Debug, Copy, Clone, PartialEq) ]
2015-01-13 11:22:37 +11:00
pub enum MouseCursor {
/// The platform-dependent default cursor.
Default ,
/// A simple crosshair.
Crosshair ,
/// A hand (often used to indicate links in web browsers).
Hand ,
/// Self explanatory.
Arrow ,
/// Indicates something is to be moved.
Move ,
/// Indicates text that may be selected or edited.
Text ,
/// Program busy indicator.
Wait ,
/// Help indicator (often rendered as a "?")
Help ,
/// Progress indicator. Shows that processing is being done. But in contrast
/// with "Wait" the user may still interact with the program. Often rendered
2015-01-26 14:28:12 +11:00
/// as a spinning beach ball, or an arrow with a watch or hourglass.
2015-01-13 11:22:37 +11:00
Progress ,
/// Cursor showing that something cannot be done.
NotAllowed ,
ContextMenu ,
Cell ,
VerticalText ,
Alias ,
Copy ,
NoDrop ,
Grab ,
Grabbing ,
AllScroll ,
ZoomIn ,
ZoomOut ,
/// Indicate that some edge is to be moved. For example, the 'SeResize' cursor
/// is used when the movement starts from the south-east corner of the box.
EResize ,
NResize ,
NeResize ,
NwResize ,
SResize ,
SeResize ,
SwResize ,
WResize ,
EwResize ,
NsResize ,
NeswResize ,
NwseResize ,
ColResize ,
RowResize ,
}
2018-05-29 21:48:47 +10:00
impl Default for MouseCursor {
fn default ( ) -> Self {
MouseCursor ::Default
}
}
2015-09-21 17:15:53 +10:00
/// Attributes to use when creating a window.
2018-06-15 09:42:18 +10:00
#[ derive(Debug, Clone) ]
2015-09-21 17:15:53 +10:00
pub struct WindowAttributes {
/// The dimensions of the window. If this is `None`, some platform-specific dimensions will be
/// used.
///
/// The default is `None`.
2018-06-15 09:42:18 +10:00
pub dimensions : Option < LogicalSize > ,
2015-09-21 17:15:53 +10:00
2015-11-09 22:13:52 +11:00
/// The minimum dimensions a window can be, If this is `None`, the window will have no minimum dimensions (aside from reserved).
2015-11-09 20:42:54 +11:00
///
/// The default is `None`.
2018-06-15 09:42:18 +10:00
pub min_dimensions : Option < LogicalSize > ,
2015-11-09 20:42:54 +11:00
2015-11-09 22:13:52 +11:00
/// The maximum dimensions a window can be, If this is `None`, the maximum will have no maximum or will be set to the primary monitor's dimensions by the platform.
2015-11-09 20:42:54 +11:00
///
/// The default is `None`.
2018-06-15 09:42:18 +10:00
pub max_dimensions : Option < LogicalSize > ,
2015-11-09 20:42:54 +11:00
2018-06-12 08:47:50 +10:00
/// Whether the window is resizable or not.
2018-06-03 00:51:24 +10:00
///
/// The default is `true`.
pub resizable : bool ,
2017-08-28 09:22:26 +10:00
/// Whether the window should be set as fullscreen upon creation.
2015-09-21 17:15:53 +10:00
///
/// The default is `None`.
2017-09-07 18:33:46 +10:00
pub fullscreen : Option < MonitorId > ,
2015-09-21 17:15:53 +10:00
/// The title of the window in the title bar.
///
2017-05-11 10:14:38 +10:00
/// The default is `"winit window"`.
2015-09-21 17:15:53 +10:00
pub title : String ,
2017-08-28 09:19:26 +10:00
/// Whether the window should be maximized upon creation.
///
/// The default is `false`.
pub maximized : bool ,
2015-09-21 17:15:53 +10:00
/// Whether the window should be immediately visible upon creation.
///
/// The default is `true`.
pub visible : bool ,
/// Whether the the window should be transparent. If this is true, writing colors
/// with alpha values different than `1.0` will produce a transparent window.
///
/// The default is `false`.
pub transparent : bool ,
/// Whether the window should have borders and bars.
///
/// The default is `true`.
pub decorations : bool ,
2018-05-21 00:24:05 +10:00
/// Whether the window should always be on top of other windows.
///
/// The default is `false`.
pub always_on_top : bool ,
2018-05-08 07:36:21 +10:00
/// The window icon.
///
/// The default is `None`.
pub window_icon : Option < Icon > ,
2017-11-05 21:21:57 +11:00
/// [iOS only] Enable multitouch,
/// see [multipleTouchEnabled](https://developer.apple.com/documentation/uikit/uiview/1622519-multipletouchenabled)
2015-09-21 17:15:53 +10:00
pub multitouch : bool ,
}
impl Default for WindowAttributes {
2015-09-21 22:42:05 +10:00
#[ inline ]
2015-09-21 17:15:53 +10:00
fn default ( ) -> WindowAttributes {
WindowAttributes {
dimensions : None ,
2015-11-09 20:42:54 +11:00
min_dimensions : None ,
max_dimensions : None ,
2018-06-03 00:51:24 +10:00
resizable : true ,
2017-05-11 10:14:38 +10:00
title : " winit window " . to_owned ( ) ,
2017-08-28 09:19:26 +10:00
maximized : false ,
2017-09-07 18:33:46 +10:00
fullscreen : None ,
2015-09-21 17:15:53 +10:00
visible : true ,
transparent : false ,
decorations : true ,
2018-05-21 00:24:05 +10:00
always_on_top : false ,
2018-05-08 07:36:21 +10:00
window_icon : None ,
2015-09-21 17:15:53 +10:00
multitouch : false ,
}
}
}