diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9459169 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +PREFIX ?= /usr/local +BINDIR ?= $(PREFIX)/bin +DATADIR ?= $(PREFIX)/share +CONFDIR = /etc + +install: + sed "s/%DATADIR%/\/usr\/share/" 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 + install -Dm644 lightdm-mobile-greeter.desktop -t $(DESTDIR)$(DATADIR)/xgreeters \ No newline at end of file diff --git a/interface.ui b/interface.ui new file mode 100644 index 0000000..e431b5c --- /dev/null +++ b/interface.ui @@ -0,0 +1,105 @@ + + + + + + + + + True + + + True + + + True + False + vertical + center + center + True + True + 12 + + + True + prompt label + + + + + True + True + False + 12 + 12 + False + entry_buffer + GTK_INPUT_PURPOSE_PIN + 0.5 + False + True + True + + + + + True + False + fill + fill + 12 + 12 + True + False + delete_btn + pin_entry + + + + + + True + + + True + Login + + + + False + True + end + + + + + + + True + message label + + + + + + + + + + + + True + True + False + + + + True + edit-clear-symbolic + + + + diff --git a/lightdm-mobile-greeter b/lightdm-mobile-greeter deleted file mode 100644 index 3300868..0000000 --- a/lightdm-mobile-greeter +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/python3 -import gi - -gi.require_version("Gtk", "3.0") -gi.require_version("Handy", "0.0") -#gi.require_version("LightDM", 0.0) -from gi.repository import Gtk, Handy, LightDM, Gdk - -# main window -window = Gtk.Window() -window.connect("destroy", Gtk.main_quit) -display = Gdk.Display.get_default() -monitor = display.get_monitor(0) -screen_size = monitor.get_geometry() -window.set_size_request(screen_size.width, screen_size.height) -# window.set_resizable(False) - -# scrollable view -scroll = Gtk.ScrolledWindow(visible=True) -window.add(scroll) -viewport = Gtk.Viewport(visible=True) -scroll.add(viewport) - -# collomn box -container = Gtk.Box( - visible=True, - can_focus=False, - orientation="vertical", - halign="center", - valign="center", - hexpand=True, - vexpand=True, - spacing=12 -) -container.set_size_request(screen_size.width * 0.9, screen_size.height * 0.9) -viewport.add(container) - -# entry buffer -entry_buffer = Gtk.EntryBuffer() - - -# backspace -def backspace(btn): - length = entry_buffer.get_length() - if length <= 0: - # theres no text left to delete - return - text = entry_buffer.get_text() - print(text) - entry_buffer.delete_text(length - 1, 1) - text2 = entry_buffer.get_text() - print(text2) - - -delete_btn = Gtk.Button(visible=True, can_focus=True, focus_on_click=False) -db_img = Gtk.Image(visible=True, icon_name="edit-clear-symbolic") -delete_btn.add(db_img) -delete_btn.connect("clicked", backspace) - -# entry -pin_entry = Gtk.Entry( - visible=True, - can_focus=False, - has_frame=False, - margin_top=12, - margin_bottom=12, - visibility=False, - buffer=entry_buffer, - input_purpose=Gtk.InputPurpose.PIN, - xalign=0.5, - caps_lock_warning=False, - hexpand=True, - vexpand=True, -) -container.add(pin_entry) - -# keypad -keypad = Handy.Keypad( - visible=True, - can_focus=False, - halign="fill", - valign="fill", - margin_top=12, - margin_bottom=12, - only_digits=True, - show_symbols=False, - right_action=delete_btn, - entry=pin_entry, -) -container.add(keypad) - -# greeter -greeter = LightDM.Greeter() - - -def login_clicked(btn): -# greeter.authenticate("demo") - greeter.respond(pin_entry.get_text()) - if greeter.get_is_authenticated(): - greeter.start_session_sync(None) - - -# login button -login_btn = Gtk.Button(label="Login", visible=True) -login_btn.connect("clicked", login_clicked) -container.add(login_btn) - -# prompt label -prompt_label = Gtk.Label(visible=True) -container.add(prompt_label) - -# message label -message_label = Gtk.Label(visible=True) -container.add(message_label) - - -greeter.connect( - "authentication-complete", - lambda g: g.get_is_authenticated() and g.start_session_sync(None), -) -greeter.connect("show-message", lambda g, m, pt: message_label.set_text(m)) -greeter.connect("show-prompt", lambda g, m, t: prompt_label.set_text(m)) -greeter.connect_sync() -greeter.authenticate("demo") - -window.show() -window.fullscreen() -Gtk.main() diff --git a/lightdm-mobile-greeter.py b/lightdm-mobile-greeter.py new file mode 100644 index 0000000..4086e27 --- /dev/null +++ b/lightdm-mobile-greeter.py @@ -0,0 +1,72 @@ +#!/usr/bin/python3 +import gi +from gi.repository import Gtk, Gdk, Handy, LightDM +import json + + +class Config: + def __init__(self): + with open("/etc/lightdm_mobile_greeter.json") as f: + j = json.load(f) + self.user = j["user"] + + +class Handler: + def __init__(self, builder: Gtk.Builder): + self.pin_entry = builder.get_object("entry_buffer") + self.greeter = LightDM.Greeter() + self.greeter.connect("authentication-complete", self.auth_complete) + self.greeter.connect("show-message", self.show_msg) + self.greeter.connect("show-prompt", self.show_prompt) + self.pmpt_label = builder.get_object("prompt_label") + self.msg_label = builder.get_object("message_label") + self.greeter.connect_sync() + self.conf = Config() + self.greeter.authenticate(self.conf.user) + + def on_destry(self, window): + Gtk.main_quit() + + def login_cb(self, login_btn): + self.greeter.respond(self.pin_entry.get_text()) + self.pin_entry.set_text("", 0) + + def backspace(self, del_btn): + length = self.pin_entry.get_length() + if length <= 0: + return + self.pin_entry.delete_text(length - 1, 1) + + def auth_complete(self, greeter): + if greeter.get_is_authenticated(): + greeter.start_session_sync(None) + else: + greeter.authenticate(self.conf.user) + + def show_msg(self, greeter, text, type): + self.msg_label.set_text(text) + + def show_prompt(self, greeter, text, type): + self.pmpt_label.set_text(text) + + +Handy.Keypad() +builder: Gtk.Builder = Gtk.Builder.new_from_file( + "%DATADIR%/lightdm-mobile-greeter/interface.ui" +) +handler = Handler(builder) +builder.connect_signals(handler) +window: Gtk.Window = builder.get_object("greeter_window") +display = Gdk.Display.get_default() +monitor = display.get_monitor(0) +screen_size = monitor.get_geometry() +window.set_size_request(screen_size.width, screen_size.height) +container = builder.get_object("container") +container.set_size_request(screen_size.width * 0.8, screen_size.height * 0.8) +style: Gtk.CssProvider = Gtk.CssProvider() +style.load_from_path("%DATADIR%/lightdm-mobile-greeter/style.css") +Gtk.StyleContext.add_provider_for_screen( + Gdk.Screen.get_default(), style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION +) +window.show() +Gtk.main() diff --git a/style.css b/style.css new file mode 100644 index 0000000..1274c9f --- /dev/null +++ b/style.css @@ -0,0 +1,34 @@ +window * { + background: none; + color: greenyellow; + box-shadow: none; + text-decoration: none; +} + +window { + background-color: black; +} + +button { + border: 0; + background: none; + outline-style: dashed; + margin: 0; + border-width: 2px; + padding: 16px 36px; +} +.keypad button { + padding: 16px 16px; +} +label { + font-weight: bold; +} + +button:active { + background-color: greenyellow; + color: black; +} + +button:active label { + color: black; +}