1
0

8 Commits

Author SHA1 Message Date
34df640d5d theming documentation 2020-09-20 08:53:59 +12:00
e0beba1b89 styling maybe fixed 2020-09-20 08:36:19 +12:00
e29ec82802 custom styling maybe? 2020-09-16 21:52:26 +12:00
4c7a51cacc os release thingy at bottom 2020-07-16 09:20:03 +00:00
914e62493a seperated build and install steps in Makefile 2020-05-17 11:16:08 +12:00
c566c508ae now tested and working 2020-04-27 08:47:49 +00:00
b0db4805a8 possibly unnessessary borrow muts removed 2020-04-27 13:11:34 +12:00
e49db66883 remove optimisations 2020-04-27 11:59:17 +12:00
6 changed files with 86 additions and 22 deletions

View File

@@ -12,6 +12,4 @@ gtk = "0.8.1"
lightdm = { git = "https://raatty.club:3000/raatty/lightdm-rs.git"}
[profile.release]
codegen-units = 1
panic = "abort"
opt-level = "z"

View File

@@ -3,7 +3,9 @@ BINDIR ?= $(PREFIX)/bin
DATADIR ?= $(PREFIX)/share
CONFDIR = /etc
install:
RUSTFLAGS="-C link-arg=-s" cargo build --release
target/release/lightdm-mobile-greeter: src/main.rs
cargo build --release
build: target/release/lightdm-mobile-greeter
install: build
install -Dm755 target/release/lightdm-mobile-greeter -t $(DESTDIR)$(BINDIR)
install -Dm644 lightdm-mobile-greeter.desktop -t $(DESTDIR)$(DATADIR)/xgreeters

View File

@@ -14,3 +14,6 @@ lightdm.conf
greeter-session=lightdm-mobile-greeter
user-session=<THE CHOSEN DE TO LAUNCH AFTER SUCCESSFUL LOGIN>
```
## Theming
If you have a file at `/etc/lightdm/lightdm_mobile_greeter.css` styling will be read from it falling back to the backed in styling, checkout style.css to get ideas on what to change

View File

@@ -77,7 +77,10 @@
<child>
<object class="GtkLabel" id="message_label">
<property name="visible">True</property>
<property name="label"></property>
<property name="label"></property>
<style>
<class name="msg"/>
</style>
</object>
</child>
</object>

View File

@@ -5,7 +5,10 @@ use libhandy;
use lightdm;
use lightdm::{GreeterExt, SessionExt, UserExt, UserListExt};
use std::cell::RefCell;
use std::io::prelude::*;
use std::path::*;
use std::rc::Rc;
use std::{fs, io};
fn main() {
if gtk::init().is_err() {
@@ -22,6 +25,22 @@ fn main() {
handler_borrowed.setup_greeter(handler.clone());
handler_borrowed.setup_de_select(handler.clone());
}
{
let handler_borrowed = handler.borrow();
if let Ok(os_str) = pretty_name() {
handler_borrowed
.msg_label
.as_ref()
.expect("no msg label")
.set_text(&os_str);
}
}
{
let handler_borrowed = handler.borrow();
let greeter = handler_borrowed.greeter.as_ref().expect("no greeter");
let user = handler_borrowed.user.as_ref().expect("no user");
greeter.authenticate(Some(&user)).ok();
}
let handler_builder_clone = handler.clone();
builder.connect_signals(move |_, name| {
let h_login_cb_clone = handler_builder_clone.clone();
@@ -80,14 +99,27 @@ fn main() {
(screen_size.height as f32 * 0.8) as i32,
);
let style = gtk::CssProvider::new();
let screen = gdk::Screen::get_default().expect("cant get screen");
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"),
&screen,
&style,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
let custom_conf = Path::new("/etc/lightdm/lightdm_mobile_greeter.css");
if custom_conf.exists() {
let style2 = gtk::CssProvider::new();
if let Some(path) = custom_conf.to_str() {
style2.load_from_path(path).expect("failed to load style2");
}
gtk::StyleContext::add_provider_for_screen(
&screen,
&style2,
gtk::STYLE_PROVIDER_PRIORITY_USER,
)
}
}
window.show();
gtk::main();
@@ -142,7 +174,7 @@ impl Handler {
let handler_msg_clone = handler.clone();
greeter.connect_show_message(move |_, msg, _| {
handler_msg_clone
.borrow_mut()
.borrow()
.msg_label
.as_ref()
.expect("no msg label")
@@ -151,29 +183,26 @@ impl Handler {
let handler_prmpt_clone = handler.clone();
greeter.connect_show_prompt(move |_, msg, _| {
handler_prmpt_clone
.borrow_mut()
.borrow()
.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>>) {
fn setup_de_select(&mut self, handler: Rc<RefCell<Self>>) {
{
let mut handler_borrowed = handler.borrow_mut();
let session = handler_borrowed
let session = self
.greeter
.as_ref()
.expect("wheres the greeter at")
.get_default_session_hint()
.expect("no default session");
handler_borrowed.session = Some(String::from(session));
self.session = Some(String::from(session));
}
let first_handler = handler.clone();
let vbox = gtk::BoxBuilder::new()
.orientation(gtk::Orientation::Vertical)
.visible(true)
@@ -187,23 +216,47 @@ impl Handler {
});
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());
});
let mut keys = Vec::new();
let mut rbs = Vec::new();
keys.push(key);
rbs.push(first.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());
});
keys.push(key);
rbs.push(rb.clone());
vbox.add(&rb);
if self.session.clone().expect("session not found") == key_clone {
rb.set_active(true);
}
}
let keys_iter = keys.iter();
for (rb, key) in rbs.iter().zip(keys_iter) {
let handler_clone = handler.clone();
let key_clone = key.clone();
rb.connect_toggled(move |_| {
handler_clone.borrow_mut().session = Some(key_clone.clone());
});
}
self.de_select.as_ref().expect("no de select").add(&vbox);
vbox.show_all()
}
}
fn pretty_name() -> Result<String, io::Error> {
let file = fs::File::open("/etc/os-release")?;
let contents = io::BufReader::new(file);
for line_opt in contents.lines() {
let line = line_opt?;
if line.starts_with("PRETTY_NAME=") {
if let Some(name) = line.split("=").skip(1).next() {
return Ok(name.trim_matches('"').to_string());
};
}
}
Err(io::Error::new(
io::ErrorKind::NotFound,
"I tried my best :)",
))
}

View File

@@ -51,3 +51,8 @@ popover {
popover radiobutton {
padding: 1em;
}
.msg {
font-size: 1.5em;
padding: 1em;
}