rust rewrite finished maybe?
This commit is contained in:
parent
08a90cdf07
commit
2999921e29
|
@ -0,0 +1,495 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "atk"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "444daefa55f229af145ea58d77efd23725024ee1f6f3102743709aa6b18c663e"
|
||||
dependencies = [
|
||||
"atk-sys",
|
||||
"bitflags",
|
||||
"glib",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atk-sys"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e552c1776737a4c80110d06b36d099f47c727335f9aaa5d942a72b6863a8ec6f"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
|
||||
[[package]]
|
||||
name = "cairo-rs"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "157049ba9618aa3a61c39d5d785102c04d3b1f40632a706c621a9aedc21e6084"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cairo-sys-rs",
|
||||
"glib",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cairo-sys-rs"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff65ba02cac715be836f63429ab00a767d48336efc5497c5637afb53b4f14d63"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d"
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a"
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6"
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7"
|
||||
dependencies = [
|
||||
"proc-macro-hack",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-macro",
|
||||
"futures-task",
|
||||
"pin-utils",
|
||||
"proc-macro-hack",
|
||||
"proc-macro-nested",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gdk"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbe5e8772fc0865c52460cdd7a59d7d47700f44d9809d1dd00eecceb769a7589"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cairo-rs",
|
||||
"cairo-sys-rs",
|
||||
"gdk-pixbuf",
|
||||
"gdk-sys",
|
||||
"gio",
|
||||
"gio-sys",
|
||||
"glib",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"pango",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gdk-pixbuf"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e248220c46b329b097d4b158d2717f8c688f16dd76d0399ace82b3e98062bdd7"
|
||||
dependencies = [
|
||||
"gdk-pixbuf-sys",
|
||||
"gio",
|
||||
"gio-sys",
|
||||
"glib",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gdk-pixbuf-sys"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8991b060a9e9161bafd09bf4a202e6fd404f5b4dd1a08d53a1e84256fb34ab0"
|
||||
dependencies = [
|
||||
"gio-sys",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gdk-sys"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6adf679e91d1bff0c06860287f80403e7db54c2d2424dce0a470023b56c88fbb"
|
||||
dependencies = [
|
||||
"cairo-sys-rs",
|
||||
"gdk-pixbuf-sys",
|
||||
"gio-sys",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"pango-sys",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gio"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0cd10f9415cce39b53f8024bf39a21f84f8157afa52da53837b102e585a296a5"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-util",
|
||||
"gio-sys",
|
||||
"glib",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gio-sys"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fad225242b9eae7ec8a063bb86974aca56885014672375e5775dc0ea3533911"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glib"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40fb573a09841b6386ddf15fd4bc6655b4f5b106ca962f57ecaecde32a0061c0"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-executor",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glib-sys"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95856f3802f446c05feffa5e24859fe6a183a7cb849c8449afc35c86b1e316e2"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gobject-sys"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31d1a804f62034eccf370006ccaef3708a71c31d561fee88564abe71177553d9"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gtk"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87e1e8d70290239c668594002d1b174fcc7d7ef5d26670ee141490ede8facf8f"
|
||||
dependencies = [
|
||||
"atk",
|
||||
"bitflags",
|
||||
"cairo-rs",
|
||||
"cairo-sys-rs",
|
||||
"cc",
|
||||
"gdk",
|
||||
"gdk-pixbuf",
|
||||
"gdk-pixbuf-sys",
|
||||
"gdk-sys",
|
||||
"gio",
|
||||
"gio-sys",
|
||||
"glib",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"gtk-sys",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"pango",
|
||||
"pango-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gtk-sys"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53def660c7b48b00b510c81ef2d2fbd3c570f1527081d8d7947f471513e1a4c1"
|
||||
dependencies = [
|
||||
"atk-sys",
|
||||
"cairo-sys-rs",
|
||||
"gdk-pixbuf-sys",
|
||||
"gdk-sys",
|
||||
"gio-sys",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"pango-sys",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
|
||||
|
||||
[[package]]
|
||||
name = "libhandy"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2aa9f5620e4143358bcd645fe7d7d27b974ed9148cbdd490bc811813899afa07"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"gdk",
|
||||
"gdk-sys",
|
||||
"gio",
|
||||
"gio-sys",
|
||||
"glib",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"gtk",
|
||||
"gtk-sys",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"libhandy-sys",
|
||||
"pango",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libhandy-sys"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d707af842e918719b71af0ac6cf31d1843f6e8a4d1e9c733b998d8d482e60446"
|
||||
dependencies = [
|
||||
"gdk",
|
||||
"gdk-sys",
|
||||
"gio",
|
||||
"gio-sys",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"gtk-sys",
|
||||
"libc",
|
||||
"pango-sys",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "light-dm-sys"
|
||||
version = "0.0.1"
|
||||
source = "git+https://raatty.club:3000/raatty/lightdm-rs.git#a3c669583bb932e2b25372048b1e9dbda1f10e11"
|
||||
dependencies = [
|
||||
"gio-sys",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lightdm"
|
||||
version = "0.1.0"
|
||||
source = "git+https://raatty.club:3000/raatty/lightdm-rs.git#a3c669583bb932e2b25372048b1e9dbda1f10e11"
|
||||
dependencies = [
|
||||
"gio",
|
||||
"gio-sys",
|
||||
"glib",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"light-dm-sys",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lightdm-mobile-greeter"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gdk",
|
||||
"gtk",
|
||||
"libhandy",
|
||||
"lightdm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b"
|
||||
|
||||
[[package]]
|
||||
name = "pango"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e9c6b728f1be8edb5f9f981420b651d5ea30bdb9de89f1f1262d0084a020577"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"glib",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"pango-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pango-sys"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86b93d84907b3cf0819bff8f13598ba72843bee579d5ebc2502e4b0367b4be7d"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-nested"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e946095f9d3ed29ec38de908c22f95d9ac008e424c7bcae54c75a79c527c694"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
10
Cargo.toml
10
Cargo.toml
|
@ -5,5 +5,13 @@ authors = ["Raatty <me@raatty.club>"]
|
|||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
libhandy = "0.5.0"
|
||||
gdk = "0.12.1"
|
||||
gtk = "0.8.1"
|
||||
lightdm = { git = "https://raatty.club:3000/raatty/lightdm-rs.git"}
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
opt-level = "z"
|
5
Makefile
5
Makefile
|
@ -4,7 +4,6 @@ DATADIR ?= $(PREFIX)/share
|
|||
CONFDIR = /etc
|
||||
|
||||
install:
|
||||
sed "s#%DATADIR%#$(DATADIR)#" lightdm-mobile-greeter.py > lightdm-mobile-greeter
|
||||
install -Dm755 lightdm-mobile-greeter -t $(DESTDIR)$(BINDIR)
|
||||
install -Dm644 style.css interface.ui -t $(DESTDIR)$(DATADIR)/lightdm-mobile-greeter
|
||||
RUSTFLAGS="-C link-arg=-s" cargo build --release
|
||||
install -Dm755 target/release/lightdm-mobile-greeter -t $(DESTDIR)$(BINDIR)
|
||||
install -Dm644 lightdm-mobile-greeter.desktop -t $(DESTDIR)$(DATADIR)/xgreeters
|
208
src/main.rs
208
src/main.rs
|
@ -1,3 +1,209 @@
|
|||
use gdk;
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
use libhandy;
|
||||
use lightdm;
|
||||
use lightdm::{GreeterExt, SessionExt, UserExt, UserListExt};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
if gtk::init().is_err() {
|
||||
println!("failed to init GTK");
|
||||
return;
|
||||
}
|
||||
libhandy::Keypad::new(true, true);
|
||||
let builder = gtk::Builder::new_from_string(include_str!("../interface.ui"));
|
||||
let handler = Rc::new(RefCell::new(Handler::new()));
|
||||
{
|
||||
let mut handler_borrowed = handler.borrow_mut();
|
||||
handler_borrowed.get_objects(&builder);
|
||||
handler_borrowed.set_username();
|
||||
handler_borrowed.setup_greeter(handler.clone());
|
||||
handler_borrowed.setup_de_select(handler.clone());
|
||||
}
|
||||
let handler_builder_clone = handler.clone();
|
||||
builder.connect_signals(move |_, name| {
|
||||
let h_login_cb_clone = handler_builder_clone.clone();
|
||||
let h_backspace_clone = handler_builder_clone.clone();
|
||||
let h_de_popover_clone = handler_builder_clone.clone();
|
||||
match name {
|
||||
"on_destry" => Box::new(|_| {
|
||||
gtk::main_quit();
|
||||
None
|
||||
}),
|
||||
"login_cb" => Box::new(move |_| {
|
||||
let handler = h_login_cb_clone.borrow();
|
||||
let pin_entry = handler.pin_entry.as_ref().expect("no pin_entry");
|
||||
handler
|
||||
.greeter
|
||||
.as_ref()
|
||||
.expect("no greeter")
|
||||
.respond(&pin_entry.get_text())
|
||||
.ok();
|
||||
pin_entry.set_text("");
|
||||
None
|
||||
}),
|
||||
"backspace" => Box::new(move |_| {
|
||||
let handler = h_backspace_clone.borrow();
|
||||
let pin_entry = handler.pin_entry.as_ref().expect("no pin_entry");
|
||||
let length = pin_entry.get_length();
|
||||
if length <= 0 {
|
||||
return None;
|
||||
}
|
||||
pin_entry.delete_text(length - 1, Some(1));
|
||||
None
|
||||
}),
|
||||
"de_popover" => Box::new(move |_| {
|
||||
h_de_popover_clone
|
||||
.borrow()
|
||||
.de_select
|
||||
.as_ref()
|
||||
.expect("popover not found")
|
||||
.popup();
|
||||
None
|
||||
}),
|
||||
_ => panic!("unknown signal"),
|
||||
}
|
||||
});
|
||||
let window: gtk::Window = builder
|
||||
.get_object("greeter_window")
|
||||
.expect("window not found");
|
||||
{
|
||||
let display = gdk::Display::get_default().expect("cant get display");
|
||||
let monitor = display.get_monitor(0).expect("cant get monitor");
|
||||
let screen_size = monitor.get_geometry();
|
||||
window.set_size_request(screen_size.width, screen_size.height);
|
||||
let container: gtk::Box = builder.get_object("container").expect("cant get container");
|
||||
container.set_size_request(
|
||||
(screen_size.width as f32 * 0.8) as i32,
|
||||
(screen_size.height as f32 * 0.8) as i32,
|
||||
);
|
||||
let style = gtk::CssProvider::new();
|
||||
style
|
||||
.load_from_data(include_bytes!("../style.css"))
|
||||
.expect("failed to load style");
|
||||
gtk::StyleContext::add_provider_for_screen(
|
||||
&gdk::Screen::get_default().expect("cant get screen"),
|
||||
&style,
|
||||
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
);
|
||||
}
|
||||
window.show();
|
||||
gtk::main();
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Handler {
|
||||
user: Option<String>,
|
||||
session: Option<String>,
|
||||
greeter: Option<lightdm::Greeter>,
|
||||
pin_entry: Option<gtk::EntryBuffer>,
|
||||
pmpt_label: Option<gtk::Label>,
|
||||
msg_label: Option<gtk::Label>,
|
||||
de_select: Option<gtk::Popover>,
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
fn get_objects(&mut self, builder: >k::Builder) {
|
||||
self.pin_entry = builder.get_object("entry_buffer");
|
||||
self.pmpt_label = builder.get_object("prompt_label");
|
||||
self.msg_label = builder.get_object("message_label");
|
||||
self.de_select = builder.get_object("de_select");
|
||||
}
|
||||
|
||||
fn set_username(&mut self) {
|
||||
if let Some(user_list) = lightdm::UserList::get_instance() {
|
||||
if let Some(name) = user_list.get_users().first().unwrap().get_name() {
|
||||
let name_str = Box::<str>::from(name);
|
||||
self.user = Some(String::from(name_str));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_greeter(&mut self, handler: Rc<RefCell<Self>>) {
|
||||
let greeter = lightdm::Greeter::new();
|
||||
let handler_auth_clone = handler.clone();
|
||||
greeter.connect_authentication_complete(move |greeter| {
|
||||
let handler_borrowed = handler_auth_clone.borrow();
|
||||
if greeter.get_is_authenticated() {
|
||||
greeter
|
||||
.start_session_sync(Some(&handler_borrowed.session.clone().unwrap()))
|
||||
.ok();
|
||||
} else {
|
||||
greeter
|
||||
.authenticate(Some(&handler_borrowed.user.clone().unwrap()))
|
||||
.ok();
|
||||
}
|
||||
});
|
||||
let handler_msg_clone = handler.clone();
|
||||
greeter.connect_show_message(move |_, msg, _| {
|
||||
handler_msg_clone
|
||||
.borrow_mut()
|
||||
.msg_label
|
||||
.as_ref()
|
||||
.expect("no msg label")
|
||||
.set_text(msg);
|
||||
});
|
||||
let handler_prmpt_clone = handler.clone();
|
||||
greeter.connect_show_prompt(move |_, msg, _| {
|
||||
handler_prmpt_clone
|
||||
.borrow_mut()
|
||||
.pmpt_label
|
||||
.as_ref()
|
||||
.expect("no msg label")
|
||||
.set_text(msg);
|
||||
});
|
||||
greeter.connect_to_daemon_sync().ok();
|
||||
greeter.authenticate(Some(&self.user.clone().unwrap())).ok();
|
||||
self.greeter = Some(greeter);
|
||||
}
|
||||
|
||||
fn setup_de_select(&self, handler: Rc<RefCell<Self>>) {
|
||||
{
|
||||
let mut handler_borrowed = handler.borrow_mut();
|
||||
let session = handler_borrowed
|
||||
.greeter
|
||||
.as_ref()
|
||||
.expect("wheres the greeter at")
|
||||
.get_default_session_hint()
|
||||
.expect("no default session");
|
||||
handler_borrowed.session = Some(String::from(session));
|
||||
}
|
||||
let first_handler = handler.clone();
|
||||
let vbox = gtk::BoxBuilder::new()
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.visible(true)
|
||||
.build();
|
||||
let sessions_raw = lightdm::functions::get_sessions();
|
||||
let mut sessions = sessions_raw.iter().map(|s| {
|
||||
(
|
||||
String::from(s.get_name().expect("no name")),
|
||||
String::from(s.get_key().expect("no key")),
|
||||
)
|
||||
});
|
||||
let (name, key) = sessions.next().expect("no session");
|
||||
let first = gtk::RadioButtonBuilder::new().label(&name).build();
|
||||
first.connect_toggled(move |_| {
|
||||
first_handler.borrow_mut().session = Some(key.clone());
|
||||
});
|
||||
vbox.add(&first);
|
||||
for (name, key) in sessions {
|
||||
let handler_clone = handler.clone();
|
||||
let key_clone = key.clone();
|
||||
let rb = gtk::RadioButton::new_with_label_from_widget(&first, &name);
|
||||
rb.connect_toggled(move |_| {
|
||||
handler_clone.borrow_mut().session = Some(key.clone());
|
||||
});
|
||||
vbox.add(&rb);
|
||||
if self.session.clone().expect("session not found") == key_clone {
|
||||
rb.set_active(true);
|
||||
}
|
||||
}
|
||||
self.de_select.as_ref().expect("no de select").add(&vbox);
|
||||
vbox.show_all()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue