15 releases (5 breaking)

new 0.7.0-beta1 Sep 19, 2024
0.5.1 Aug 17, 2024
0.3.0-beta2 Jul 31, 2024

#716 in GUI

Download history 1/week @ 2024-06-11 159/week @ 2024-06-18 2/week @ 2024-06-25 146/week @ 2024-07-23 344/week @ 2024-07-30 279/week @ 2024-08-06 330/week @ 2024-08-13 9/week @ 2024-08-20 270/week @ 2024-09-03 6/week @ 2024-09-10

291 downloads per month

MIT license

175KB
3.5K SLoC

sessionlock binding for iced

Crates.io

iced-layershell provides binding for iced and sessionlock.

Session lock is the wayland protocol for lock. This protocol is supported in river, sway and etc. We use it make a beautiful lock program in twenty. You can also use it to build your sessionlock. This will become very easy to use our crate with pam crate.

The smallest example is like

use iced::widget::{button, column, text, text_input};
use iced::{event, Alignment, Command, Element, Event, Length, Theme};

use iced_sessionlock::actions::UnLockAction;
use iced_sessionlock::settings::Settings;
use iced_sessionlock::MultiApplication;

pub fn main() -> Result<(), iced_sessionlock::Error> {
    Counter::run(Settings::default())
}

struct Counter {
    value: i32,
    text: String,
}

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

impl MultiApplication for Counter {
    type Message = Message;
    type Flags = ();
    type Theme = Theme;
    type Executor = iced::executor::Default;

    fn new(_flags: ()) -> (Self, Command<Message>) {
        (
            Self {
                value: 0,
                text: "eee".to_string(),
            },
            Command::none(),
        )
    }

    fn namespace(&self) -> String {
        String::from("Counter - Iced")
    }

    fn subscription(&self) -> iced::Subscription<Self::Message> {
        event::listen().map(Message::IcedEvent)
    }

    fn update(&mut self, message: Message) -> Command<Message> {
        match message {
            Message::IcedEvent(event) => {
                println!("hello {event:?}");
                Command::none()
            }
            Message::IncrementPressed => {
                self.value += 1;
                Command::none()
            }
            Message::DecrementPressed => {
                self.value -= 1;
                Command::none()
            }
            Message::TextInput(text) => {
                self.text = text;
                Command::none()
            }
            Message::Lock => Command::single(UnLockAction.into()),
        }
    }

    fn view(&self, _id: iced::window::Id) -> Element<Message> {
        //println!("{:?}, {}", _id, self.value);
        column![
            button("Increment").on_press(Message::IncrementPressed),
            button("Lock").on_press(Message::Lock),
            text(self.value).size(50),
            text_input("hello", &self.text)
                .on_input(Message::TextInput)
                .padding(10),
            button("Decrement").on_press(Message::DecrementPressed)
        ]
        .padding(20)
        .align_items(Alignment::Center)
        .width(Length::Fill)
        .height(Length::Fill)
        .into()
    }
}

For more example, please take a look at exwlshelleventloop

Dependencies

~28–43MB
~768K SLoC