Skip to content

Commit

Permalink
wayland: Make sctk-adwaita optional
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed May 2, 2022
1 parent ab55e95 commit e1b75d0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ default-target = "x86_64-unknown-linux-gnu"
targets = ["i686-pc-windows-msvc", "x86_64-pc-windows-msvc", "i686-unknown-linux-gnu", "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "wasm32-unknown-unknown"]

[features]
default = ["x11", "wayland", "wayland-dlopen"]
default = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"]
x11 = ["x11-dl", "mio", "percent-encoding", "parking_lot"]
wayland = ["wayland-client", "wayland-protocols", "sctk", "sctk-adwaita"]
wayland = ["wayland-client", "wayland-protocols", "sctk"]
wayland-dlopen = ["sctk/dlopen", "wayland-client/dlopen"]
wayland-csd-adwaita = ["sctk-adwaita"]

[dependencies]
instant = { version = "0.1", features = ["wasm-bindgen"] }
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/wayland/seat/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use sctk::reexports::protocols::unstable::pointer_constraints::v1::client::zwp_c

use sctk::seat::pointer::{ThemeManager, ThemedPointer};
use sctk::window::Window;
use sctk_adwaita::AdwaitaFrame;

use crate::event::ModifiersState;
use crate::platform_impl::wayland::event_loop::WinitState;
use crate::platform_impl::wayland::window::WinitFrame;
use crate::window::CursorIcon;

mod data;
Expand Down Expand Up @@ -157,7 +157,7 @@ impl WinitPointer {
}
}

pub fn drag_window(&self, window: &Window<FallbackFrame>) {
pub fn drag_window(&self, window: &Window<WinitFrame>) {
// WlPointer::setart_interactive_move() expects the last serial of *any*
// pointer event (compare to set_cursor()).
window.start_interactive_move(&self.seat, self.latest_serial.get());
Expand Down
11 changes: 9 additions & 2 deletions src/platform_impl/linux/wayland/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use sctk::reexports::calloop;

use raw_window_handle::WaylandHandle;
use sctk::window::Decorations;
use sctk_adwaita::{AdwaitaFrame, FrameConfig};

use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError};
Expand All @@ -29,6 +28,11 @@ pub mod shim;

use shim::{WindowHandle, WindowRequest, WindowUpdate};

#[cfg(feature = "sctk-adwaita")]
pub type WinitFrame = sctk_adwaita::AdwaitaFrame;
#[cfg(not(feature = "sctk-adwaita"))]
pub type WinitFrame = sctk::window::FallbackFrame;

pub struct Window {
/// Window id.
window_id: WindowId,
Expand Down Expand Up @@ -106,7 +110,7 @@ impl Window {
let theme_manager = event_loop_window_target.theme_manager.clone();
let mut window = event_loop_window_target
.env
.create_window::<AdwaitaFrame, _>(
.create_window::<WinitFrame, _>(
surface.clone(),
Some(theme_manager),
(width, height),
Expand Down Expand Up @@ -141,7 +145,10 @@ impl Window {
.map_err(|_| os_error!(OsError::WaylandMisc("failed to create window.")))?;

// Set CSD frame config
#[cfg(feature = "sctk-adwaita")]
if let Some(theme) = platform_attributes.csd_theme {
use sctk_adwaita::FrameConfig;

let config = match theme {
Theme::Light => FrameConfig::light(),
Theme::Dark => FrameConfig::dark(),
Expand Down
30 changes: 19 additions & 11 deletions src/platform_impl/linux/wayland/window/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use sctk::reexports::protocols::staging::xdg_activation::v1::client::xdg_activat

use sctk::environment::Environment;
use sctk::window::{Decorations, Window};
use sctk_adwaita::{AdwaitaFrame, FrameConfig};

use crate::dpi::{LogicalPosition, LogicalSize};

Expand All @@ -22,6 +21,8 @@ use crate::platform_impl::wayland::seat::text_input::TextInputHandler;
use crate::platform_impl::wayland::WindowId;
use crate::window::{CursorIcon, Theme, UserAttentionType};

use super::WinitFrame;

/// A request to SCTK window from Winit window.
#[derive(Debug, Clone)]
pub enum WindowRequest {
Expand Down Expand Up @@ -147,7 +148,7 @@ impl WindowUpdate {
/// and react to events.
pub struct WindowHandle {
/// An actual window.
pub window: Window<AdwaitaFrame>,
pub window: Window<WinitFrame>,

/// The current size of the window.
pub size: Arc<Mutex<LogicalSize<u32>>>,
Expand Down Expand Up @@ -186,7 +187,7 @@ pub struct WindowHandle {
impl WindowHandle {
pub fn new(
env: &Environment<WinitEnv>,
window: Window<AdwaitaFrame>,
window: Window<WinitFrame>,
size: Arc<Mutex<LogicalSize<u32>>>,
pending_window_requests: Arc<Mutex<Vec<WindowRequest>>>,
) -> Self {
Expand Down Expand Up @@ -423,14 +424,21 @@ pub fn handle_window_requests(winit_state: &mut WinitState) {
window_update.refresh_frame = true;
}
WindowRequest::CsdThemeVariant(theme) => {
let config = match theme {
Theme::Light => FrameConfig::light(),
Theme::Dark => FrameConfig::dark(),
};
window_handle.window.set_frame_config(config);

let window_update = window_updates.get_mut(window_id).unwrap();
window_update.refresh_frame = true;
#[cfg(feature = "sctk-adwaita")]
{
use sctk_adwaita::FrameConfig;

let config = match theme {
Theme::Light => FrameConfig::light(),
Theme::Dark => FrameConfig::dark(),
};
window_handle.window.set_frame_config(config);

let window_update = window_updates.get_mut(window_id).unwrap();
window_update.refresh_frame = true;
}
#[cfg(not(feature = "sctk-adwaita"))]
let _ = theme;
}
WindowRequest::Resizeable(resizeable) => {
window_handle.window.set_resizable(resizeable);
Expand Down

0 comments on commit e1b75d0

Please sign in to comment.