diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c065a75aa..223442fd28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,6 @@ jobs: - { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, } - { target: x86_64-apple-darwin, os: macos-latest, } - { target: x86_64-apple-ios, os: macos-latest, } - - { target: armv7-apple-ios, os: macos-latest, } - { target: aarch64-apple-ios, os: macos-latest, } - { target: aarch64-linux-android, os: ubuntu-latest, } # We're using Windows rather than Ubuntu to run the wasm tests because caching cargo-web diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a489f5e82..8aff94bb46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +# 0.21.0 (2020-02-04) + +- On Windows, fixed "error: linking with `link.exe` failed: exit code: 1120" error on older versions of windows. +- On macOS, fix set_minimized(true) works only with decorations. - On macOS, add `hide_application` to `EventLoopWindowTarget` via a new `EventLoopWindowTargetExtMacOS` trait. `hide_application` will hide the entire application by calling `-[NSApplication hide: nil]`. - On macOS, fix not sending ReceivedCharacter event for specific keys combinations. - On macOS, fix `CursorMoved` event reporting the cursor position using logical coordinates. @@ -17,6 +21,7 @@ - **Breaking:** Unified all functions to return the same error type, `winit_types::error::Error`. - **Breaking:** `Window::set_fullscreen` now returns an `Result<(), Error>` instead of panicking or doing nothing silently. - On X11, if the RandR extension is not present, winit will no longer panic. Instead it will return the list of X11 screens, augmenting it with information from Xinerama if present. +- **Breaking:** On Wayland, the `WaylandTheme` struct has been replaced with a `Theme` trait, allowing for extra configuration # 0.20.0 (2020-01-05) diff --git a/Cargo.toml b/Cargo.toml index 3bb45e8c56..8e5a107f66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "winit" -version = "0.20.0" +version = "0.21.0" authors = ["The winit contributors", "Pierre Krieger "] description = "Cross-platform window creation library." edition = "2018" diff --git a/README.md b/README.md index 0312b20a87..fbbdc69f95 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ```toml [dependencies] -winit = "0.20.0" +winit = "0.21.0" ``` ## [Documentation](https://docs.rs/winit) diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 81271f9a07..1a9f5dcf14 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -5,6 +5,7 @@ use std::os::raw::c_void; use winit_types::dpi::LogicalSize; use crate::{ + dpi::LogicalSize, event_loop::{EventLoop, EventLoopWindowTarget}, monitor::MonitorHandle, window::{Window, WindowBuilder}, diff --git a/src/platform/unix.rs b/src/platform/unix.rs index 09a8159819..482cbe8b27 100644 --- a/src/platform/unix.rs +++ b/src/platform/unix.rs @@ -6,7 +6,7 @@ use glutin_interface::{ GbmWindowParts, NativeDisplay, NativeWindow, NativeWindowSource, RawDisplay, RawWindow, Seal, WaylandWindowParts, X11WindowParts, }; -use smithay_client_toolkit::window::{ButtonState, Theme}; +use smithay_client_toolkit::window::{ButtonState as SCTKButtonState, Theme as SCTKTheme}; use winit_types::dpi::{PhysicalSize, Size}; use winit_types::error::{Error, ErrorType}; @@ -23,74 +23,6 @@ use crate::platform_impl::{ pub use crate::platform_impl::x11::util::WindowType as XWindowType; -/// Theme for wayland client side decorations -/// -/// Colors must be in ARGB8888 format -pub struct WaylandTheme { - /// Primary color when the window is focused - pub primary_active: [u8; 4], - /// Primary color when the window is unfocused - pub primary_inactive: [u8; 4], - /// Secondary color when the window is focused - pub secondary_active: [u8; 4], - /// Secondary color when the window is unfocused - pub secondary_inactive: [u8; 4], - /// Close button color when hovered over - pub close_button_hovered: [u8; 4], - /// Close button color - pub close_button: [u8; 4], - /// Close button color when hovered over - pub maximize_button_hovered: [u8; 4], - /// Maximize button color - pub maximize_button: [u8; 4], - /// Minimize button color when hovered over - pub minimize_button_hovered: [u8; 4], - /// Minimize button color - pub minimize_button: [u8; 4], -} - -struct WaylandThemeObject(WaylandTheme); - -impl Theme for WaylandThemeObject { - fn get_primary_color(&self, active: bool) -> [u8; 4] { - if active { - self.0.primary_active - } else { - self.0.primary_inactive - } - } - - // Used for division line - fn get_secondary_color(&self, active: bool) -> [u8; 4] { - if active { - self.0.secondary_active - } else { - self.0.secondary_inactive - } - } - - fn get_close_button_color(&self, state: ButtonState) -> [u8; 4] { - match state { - ButtonState::Hovered => self.0.close_button_hovered, - _ => self.0.close_button, - } - } - - fn get_maximize_button_color(&self, state: ButtonState) -> [u8; 4] { - match state { - ButtonState::Hovered => self.0.maximize_button_hovered, - _ => self.0.maximize_button, - } - } - - fn get_minimize_button_color(&self, state: ButtonState) -> [u8; 4] { - match state { - ButtonState::Hovered => self.0.minimize_button_hovered, - _ => self.0.minimize_button, - } - } -} - /// Additional methods on `EventLoopWindowTarget` that are specific to Unix. pub trait EventLoopWindowTargetExtUnix { /// True if the `EventLoopWindowTarget` uses Wayland. @@ -358,7 +290,7 @@ pub trait WindowExtUnix { fn wayland_display(&self) -> Option<*mut raw::c_void>; /// Sets the color theme of the client side window decorations on wayland - fn set_wayland_theme(&self, theme: WaylandTheme); + fn set_wayland_theme(&self, theme: T); /// Check if the window is ready for drawing /// @@ -427,9 +359,9 @@ impl WindowExtUnix for Window { } #[inline] - fn set_wayland_theme(&self, theme: WaylandTheme) { + fn set_wayland_theme(&self, theme: T) { match self.window { - LinuxWindow::Wayland(ref w) => w.set_theme(WaylandThemeObject(theme)), + LinuxWindow::Wayland(ref w) => w.set_theme(WaylandTheme(theme)), _ => {} } } @@ -546,3 +478,96 @@ impl MonitorHandleExtUnix for MonitorHandle { self.inner.x11_screen() } } + +/// Wrapper for implementing SCTK's theme trait. +struct WaylandTheme(T); + +pub trait Theme: Send + 'static { + /// Primary color of the scheme. + fn primary_color(&self, window_active: bool) -> [u8; 4]; + + /// Secondary color of the scheme. + fn secondary_color(&self, window_active: bool) -> [u8; 4]; + + /// Color for the close button. + fn close_button_color(&self, status: ButtonState) -> [u8; 4]; + + /// Icon color for the close button, defaults to the secondary color. + #[allow(unused_variables)] + fn close_button_icon_color(&self, status: ButtonState) -> [u8; 4] { + self.secondary_color(true) + } + + /// Background color for the maximize button. + fn maximize_button_color(&self, status: ButtonState) -> [u8; 4]; + + /// Icon color for the maximize button, defaults to the secondary color. + #[allow(unused_variables)] + fn maximize_button_icon_color(&self, status: ButtonState) -> [u8; 4] { + self.secondary_color(true) + } + + /// Background color for the minimize button. + fn minimize_button_color(&self, status: ButtonState) -> [u8; 4]; + + /// Icon color for the minimize button, defaults to the secondary color. + #[allow(unused_variables)] + fn minimize_button_icon_color(&self, status: ButtonState) -> [u8; 4] { + self.secondary_color(true) + } +} + +impl SCTKTheme for WaylandTheme { + fn get_primary_color(&self, active: bool) -> [u8; 4] { + self.0.primary_color(active) + } + + fn get_secondary_color(&self, active: bool) -> [u8; 4] { + self.0.secondary_color(active) + } + + fn get_close_button_color(&self, status: SCTKButtonState) -> [u8; 4] { + self.0.close_button_color(ButtonState::from_sctk(status)) + } + + fn get_close_button_icon_color(&self, status: SCTKButtonState) -> [u8; 4] { + self.0.close_button_color(ButtonState::from_sctk(status)) + } + + fn get_maximize_button_color(&self, status: SCTKButtonState) -> [u8; 4] { + self.0.maximize_button_color(ButtonState::from_sctk(status)) + } + + fn get_maximize_button_icon_color(&self, status: SCTKButtonState) -> [u8; 4] { + self.0 + .maximize_button_icon_color(ButtonState::from_sctk(status)) + } + + fn get_minimize_button_color(&self, status: SCTKButtonState) -> [u8; 4] { + self.0.minimize_button_color(ButtonState::from_sctk(status)) + } + + fn get_minimize_button_icon_color(&self, status: SCTKButtonState) -> [u8; 4] { + self.0 + .minimize_button_icon_color(ButtonState::from_sctk(status)) + } +} + +pub enum ButtonState { + /// Button is being hovered over by pointer. + Hovered, + /// Button is not being hovered over by pointer. + Idle, + /// Button is disabled. + Disabled, +} + +impl ButtonState { + fn from_sctk(button_state: SCTKButtonState) -> Self { + match button_state { + SCTKButtonState::Hovered => Self::Hovered, + SCTKButtonState::Idle => Self::Idle, + SCTKButtonState::Disabled => Self::Disabled, + } + } +} diff --git a/src/platform_impl/linux/wayland/window.rs b/src/platform_impl/linux/wayland/window.rs index 542fb0686a..6976093d20 100644 --- a/src/platform_impl/linux/wayland/window.rs +++ b/src/platform_impl/linux/wayland/window.rs @@ -492,9 +492,10 @@ impl WindowStore { for window in &mut self.windows { let opt_arc = window.frame.upgrade(); let mut opt_mutex_lock = opt_arc.as_ref().map(|m| m.lock().unwrap()); + let mut size = { *window.size.lock().unwrap() }; f(WindowStoreForEach { newsize: window.newsize.take(), - size: &mut *(window.size.lock().unwrap()), + size: &mut size, prev_dpi: window.current_dpi, new_dpi: window.new_dpi, closed: window.closed, @@ -503,6 +504,7 @@ impl WindowStore { wid: make_wid(&window.surface), frame: opt_mutex_lock.as_mut().map(|m| &mut **m), }); + *window.size.lock().unwrap() = size; if let Some(dpi) = window.new_dpi.take() { window.current_dpi = dpi; } diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index b31b535f13..9d83eaa790 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -151,10 +151,14 @@ fn create_window( let mut masks = if !attrs.decorations && !screen.is_some() { // Resizable UnownedWindow without a titlebar or borders // if decorations is set to false, ignore pl_attrs - NSWindowStyleMask::NSBorderlessWindowMask | NSWindowStyleMask::NSResizableWindowMask + NSWindowStyleMask::NSBorderlessWindowMask + | NSWindowStyleMask::NSResizableWindowMask + | NSWindowStyleMask::NSMiniaturizableWindowMask } else if pl_attrs.titlebar_hidden { // if the titlebar is hidden, ignore other pl_attrs - NSWindowStyleMask::NSBorderlessWindowMask | NSWindowStyleMask::NSResizableWindowMask + NSWindowStyleMask::NSBorderlessWindowMask + | NSWindowStyleMask::NSResizableWindowMask + | NSWindowStyleMask::NSMiniaturizableWindowMask } else { // default case, resizable window with titlebar and titlebar buttons NSWindowStyleMask::NSClosableWindowMask