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

iced_sessionlock macro for Message enums + some clippy lint fixes #67

Merged
merged 5 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 23 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
[workspace]
resolver = "2"
members = [
"layershellev",
"iced_layershell",
"iced_layershell_macros",
"iced_sessionlock",
"starcolorkeyboard",
"sessionlockev",
"waycrate_xkbkeycode",
"iced_examples/*",
"layershellev",
"iced_layershell",
"iced_layershell_macros",
"iced_sessionlock",
"iced_sessionlock_macros",
"starcolorkeyboard",
"sessionlockev",
"waycrate_xkbkeycode",
"iced_examples/*",
]

[workspace.package]
authors = [
"Decodertalkers <[email protected]>",
"Aakash Sen Sharma <[email protected]>",
"Decodertalkers <[email protected]>",
tukanoidd marked this conversation as resolved.
Show resolved Hide resolved
"Aakash Sen Sharma <[email protected]>",
]
edition = "2021"
version = "0.8.0"
Expand All @@ -38,28 +39,28 @@ thiserror = "1.0.63"
wayland-client = { version = "0.31.5" }

wayland-protocols = { version = "0.32.3", default-features = false, features = [
"unstable",
"staging",
"client",
"unstable",
"staging",
"client",
] }

wayland-cursor = "0.31.5"

wayland-protocols-wlr = { version = "0.3.3", default-features = false, features = [
"client",
"client",
] }

wayland-protocols-misc = { version = "0.3.3", features = ["client"] }
wayland-backend = { version = "0.3.6", features = ["client_system"] }

sctk = { package = "smithay-client-toolkit", version = "0.18.1", features = [
"calloop",
"calloop",
] }

calloop = "0.14.0"

rwh_05 = { package = "raw-window-handle", version = "0.5.2", features = [
"std",
"std",
] }
rwh_06 = { package = "raw-window-handle", version = "0.6", features = ["std"] }

Expand All @@ -81,3 +82,9 @@ memmap2 = "0.9.4"

tracing = "0.1.40"
futures = "0.3.30"

darling = { version = "0.20.10", features = ["suggestions"] }
manyhow = { version = "0.11.4", features = ["darling"] }
proc-macro2 = "1.0.86"
quote = "1.0.37"
syn = { version = "2.0.77", features = ["full"] }
4 changes: 2 additions & 2 deletions iced_layershell/src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ mod tests {
#[test]
fn test_namespace() {
let app = <MockSandbox as LayerShellSandbox>::new();
let _ = assert_eq!(LayerShellSandbox::namespace(&app), "MockSandbox");
assert_eq!(LayerShellSandbox::namespace(&app), "MockSandbox");
}

#[test]
fn test_scale_factor() {
let app = <MockSandbox as LayerShellSandbox>::new();
let _ = assert_eq!(LayerShellSandbox::scale_factor(&app), 2.0);
assert_eq!(LayerShellSandbox::scale_factor(&app), 2.0);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion iced_layershell/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mod tests {
assert!(settings.fonts.is_empty());
assert_eq!(settings.default_font, Font::default());
assert_eq!(settings.default_text_size, Pixels(16.0));
assert_eq!(settings.antialiasing, false);
assert!(!settings.antialiasing);
assert!(settings.virtual_keyboard_support.is_none());

// Test default layershellv settings
Expand Down
10 changes: 5 additions & 5 deletions iced_layershell_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ default = []
diagnostics = ["darling/diagnostics"]

[dependencies]
darling = { version = "0.20.10", features = ["suggestions"] }
manyhow = { version = "0.11.4", features = ["darling"] }
proc-macro2 = "1.0.86"
quote = "1.0.37"
syn = { version = "2.0.77", features = ["full"] }
darling.workspace = true
manyhow.workspace = true
proc-macro2.workspace = true
quote.workspace = true
syn.workspace = true
2 changes: 2 additions & 0 deletions iced_sessionlock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description = "sessionlock binding for iced"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
iced_sessionlock_macros = { path = "../iced_sessionlock_macros" }

iced.workspace = true
iced_renderer.workspace = true
iced_runtime.workspace = true
Expand Down
14 changes: 2 additions & 12 deletions iced_sessionlock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use iced::{event, Alignment, Element, Event, Length, Task as Command, Theme};
use iced_sessionlock::actions::UnLockAction;
use iced_sessionlock::settings::Settings;
use iced_sessionlock::MultiApplication;
use iced_sessionlock::to_session_message;

pub fn main() -> Result<(), iced_sessionlock::Error> {
Counter::run(Settings::default())
Expand All @@ -25,24 +26,13 @@ struct Counter {
text: String,
}

#[to_session_message]
#[derive(Debug, Clone)]
enum Message {
IncrementPressed,
DecrementPressed,
TextInput(String),
IcedEvent(Event),
UnLock,
}

// You need to impl the TryInto<UnLockAction, Error = Message> to tell the plugin which message is the platform message
impl TryInto<UnLockAction> for Message {
type Error = Self;
fn try_into(self) -> Result<UnLockAction, Self::Error> {
if let Self::UnLock = self {
return Ok(UnLockAction);
}
Err(self)
}
}

impl MultiApplication for Counter {
Expand Down
17 changes: 9 additions & 8 deletions iced_sessionlock/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
pub mod actions;
pub mod multi_window;
pub mod settings;

mod clipboard;
mod conversion;
mod error;
mod event;
pub mod multi_window;
mod proxy;

pub mod settings;
use iced::{Color, Element, Theme};
use iced_futures::Subscription;
use iced_runtime::Task;

use actions::UnLockAction;
use settings::Settings;
pub use iced_sessionlock_macros::to_session_message;

pub use error::Error;

use iced::{Color, Element, Theme};
use iced_futures::Subscription;
use iced_runtime::Task;
use actions::UnLockAction;
use settings::Settings;

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Appearance {
Expand Down Expand Up @@ -111,7 +113,6 @@ pub trait MultiApplication: Sized {
/// Returns the current `Style` of the [`Theme`].
///
/// [`Theme`]: Self::Theme

fn style(&self, theme: &Self::Theme) -> Appearance {
theme.default_style()
}
Expand Down
13 changes: 13 additions & 0 deletions iced_sessionlock/tests/macro_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use iced_sessionlock::to_session_message;

#[test]
fn test_macro() {
#[allow(dead_code)]
#[to_session_message]
#[derive(Debug, Clone)]
enum TestEnum {
TestA,
}
let e = TestEnum::UnLock;
let _ = e.clone();
}
28 changes: 28 additions & 0 deletions iced_sessionlock_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "iced_sessionlock_macros"
authors.workspace = true
edition.workspace = true
version.workspace = true
license.workspace = true
repository.workspace = true
description.workspace = true
keywords.workspace = true
readme.workspace = true

[lib]
proc-macro = true

[features]
default = []
# Only nightly
diagnostics = ["darling/diagnostics"]

[dependencies]
darling.workspace = true
manyhow.workspace = true
proc-macro2.workspace = true
quote.workspace = true
syn.workspace = true

[dev-dependencies]
iced_sessionlock.workspace = true
58 changes: 58 additions & 0 deletions iced_sessionlock_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use darling::{ast::Data, util::Ignored, FromDeriveInput};
use proc_macro2::TokenStream as TokenStream2;
use syn::{DeriveInput, Generics, Ident, Path, Variant, Visibility};

use quote::quote;

#[manyhow::manyhow]
#[proc_macro_attribute]
pub fn to_session_message(
_attr: TokenStream2,
input: TokenStream2,
) -> manyhow::Result<TokenStream2> {
let derive_input = syn::parse2::<DeriveInput>(input)?;
let attrs = &derive_input.attrs;
let MessageEnum {
vis,
ident,
generics,
data,
} = MessageEnum::from_derive_input(&derive_input)?;

let (impl_gen, ty_gen, where_gen) = generics.split_for_impl();
let variants = data.take_enum().unwrap();

let unlock_action: Path = syn::parse_quote!(iced_sessionlock::actions::UnLockAction);

let try_into = quote! {
impl #impl_gen TryInto<#unlock_action> for #ident #ty_gen #where_gen {
type Error = Self;

fn try_into(self) -> Result<#unlock_action, Self::Error> {
match self {
Self::UnLock => Ok(#unlock_action),
_ => Err(self)
}
}
}
};

Ok(quote! {
#(#attrs)*
#vis enum #ident #ty_gen #where_gen {
#(#variants,)*
UnLock
}

#try_into
})
}

#[derive(FromDeriveInput)]
#[darling(supports(enum_any))]
struct MessageEnum {
vis: Visibility,
ident: Ident,
generics: Generics,
data: Data<Variant, Ignored>,
}
2 changes: 1 addition & 1 deletion layershellev/examples/simplelayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() {
// surface outside region becomes transparent for input events
// To ignore all input events use region with (0,0) size
for x in ev.get_unit_iter() {
let region = compositor.create_region(&qh, ());
let region = compositor.create_region(qh, ());
region.add(0, 0, 0, 0);
x.get_wlsurface().set_input_region(Some(&region));
}
Expand Down
1 change: 1 addition & 0 deletions layershellev/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl Default for NewLayerShellSettings {
}
}
}

/// the return data
/// Note: when event is RequestBuffer, you must return WlBuffer
/// Note: when receive InitRequest, you can request to bind extra wayland-protocols. this time you
Expand Down