├── LICENSE ├── Makefile ├── README.md ├── config.h ├── lightdm-tiny-greeter.c └── lightdm-tiny-greeter.desktop /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, Tobias Heilig 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 3. The name of the authors may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 19 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 24 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 26 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 28 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PREFIX = /usr 2 | CC = gcc 3 | RM = rm -f 4 | 5 | CFLAGS = -std=c99 -pedantic -Wall -O2 6 | PKGS = `pkg-config --libs --cflags gtk+-3.0 liblightdm-gobject-1 gmodule-export-2.0` 7 | LIBS = `pkg-config --libs gtk+-3.0 liblightdm-gobject-1 gmodule-export-2.0` 8 | 9 | TARGET = lightdm-tiny-greeter 10 | 11 | .PHONY: clean all install uninstall 12 | 13 | 14 | all: $(TARGET) 15 | 16 | $(TARGET): lightdm-tiny-greeter.o 17 | $(CC) -o $@ $^ $(LIBS) 18 | 19 | lightdm-tiny-greeter.o: lightdm-tiny-greeter.c config.h 20 | $(CC) $(CFLAGS) -c $^ $(PKGS) 21 | 22 | install: 23 | $(shell mkdir -p /usr/share/xgreeters) 24 | cp lightdm-tiny-greeter.desktop /usr/share/xgreeters/lightdm-tiny-greeter.desktop 25 | cp lightdm-tiny-greeter $(PREFIX)/bin/lightdm-tiny-greeter 26 | 27 | uninstall: 28 | $(RM) /usr/share/xgreeters/lightdm-tiny-greeter.desktop 29 | $(RM) $(PREFIX)/bin/lightdm-tiny-greeter 30 | 31 | clean: 32 | $(RM) *.o 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LightDM Tiny Greeter 2 | 3 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/2dbb11ae343f46e79a8f577a74670f10)](https://www.codacy.com/app/off-world/lightdm-tiny-greeter?utm_source=github.com&utm_medium=referral&utm_content=off-world/lightdm-tiny-greeter&utm_campaign=Badge_Grade) 4 | 5 | A tiny yet customizable GTK3 LightDM Greeter with focus on code and minimalism. 6 | 7 | ![default](https://i.imgur.com/yFMcb4o.png) 8 | 9 | ## Installation 10 | 11 | ```bash 12 | git clone https://github.com/tobiohlala/lightdm-tiny-greeter 13 | cd lightdm-tiny-greeter 14 | make 15 | sudo make install 16 | ``` 17 | 18 | ## Configuration 19 | 20 | All configuration and customization goes into `config.h` prior compilation. 21 | 22 | | Variable | Meaning | 23 | |-----------|-----------------------------------------------------------------------------------------| 24 | | user_text | text when prompting for login | 25 | | pass_text | text when prompting for password | 26 | | session | session to start (name of a desktop-entry located in /usr/share/xsessions) | 27 | | style | UI styling via [CSS](https://developer.gnome.org/gtk3/stable/chap-css-overview.html) | 28 | | ui | UI definition via [XML](https://developer.gnome.org/pygtk/stable/class-gtkbuilder.html) | 29 | 30 | ## Setup 31 | 32 | /etc/lightdm/lightdm.conf 33 | ```config 34 | [Seat:*] 35 | ... 36 | greeter-session=lightdm-tiny-greeter 37 | ``` 38 | 39 | ## Dependencies 40 | 41 | - `glib` `libglib-2.0` 42 | - `gtk3` `libgtk-3 (>= 3.22)` 43 | - `lightdm` `liblightdm-gobject-1 (>= 1.19.1)` 44 | 45 | ## Showcase 46 | 47 | ![screenshot1](https://i.imgur.com/YtiGpey.png) 48 | [#1](https://gist.github.com/off-world/573ea3b79829fb31ce7b27c337e62926) 49 | 50 | ![screenshot2](https://i.imgur.com/TxCElXF.png) 51 | [#2](https://gist.github.com/off-world/fd4c5b183dc6e0e4d3ada95131969a45) 52 | 53 | ![screenshot3](https://i.imgur.com/Ay56rA3.png) 54 | [#3](https://gist.github.com/off-world/ad853fb1faca2c6c67b332ff3d3a7a21) 55 | 56 | ![screenshot4](https://i.imgur.com/Ci9RJ0y.png) 57 | [#4](https://gist.github.com/alaughlin/f7eac0c88d2939428dcd2ffb67353f1a) 58 | 59 | ![screenshot5](https://i.imgur.com/7lSF0gC.png) 60 | [#5](https://gist.github.com/off-world/f0d1e6eb52d2a53584d7f5ba11599a73) 61 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Login prompt text */ 4 | static const char *user_text = "Username"; 5 | /* Password prompt text */ 6 | static const char *pass_text = "Password"; 7 | /* Session name */ 8 | static const char *session = "default"; 9 | /* GTK UI CSS */ 10 | static const gchar *style = 11 | "window {" 12 | "background-color: #262626;" 13 | "}" 14 | "window * {" 15 | "font: 16px \"DejaVu Sans Mono\";" 16 | "}" 17 | "label {" 18 | "color: white;" 19 | "margin-right: 15px;" 20 | "}" 21 | "entry {" 22 | "background-color: white;" 23 | "border-radius: 10px;" 24 | "box-shadow: 1px 1px white inset;" 25 | "}" 26 | "#message_label {" 27 | "color: red;" 28 | "margin-top: 25px;" 29 | "font-size: 14px;" 30 | "}"; 31 | /* GTK UI XML*/ 32 | static const gchar *ui = 33 | "" 34 | "" 35 | "" 36 | "" 37 | "login_window" 38 | "False" 39 | "False" 40 | "False" 41 | "False" 42 | "" 43 | "" 44 | "" 45 | "" 46 | "" 47 | "login_box" 48 | "True" 49 | "False" 50 | "center" 51 | "True" 52 | "vertical" 53 | "" 54 | "" 55 | "prompt_box" 56 | "True" 57 | "False" 58 | "15" 59 | "True" 60 | "" 61 | "" 62 | "prompt_label" 63 | "True" 64 | "False" 65 | "end" 66 | "" 67 | "" 68 | "False" 69 | "True" 70 | "0" 71 | "" 72 | "" 73 | "" 74 | "" 75 | "prompt_entry" 76 | "True" 77 | "True" 78 | "start" 79 | "False" 80 | "15" 81 | "False" 82 | "False" 83 | "" 84 | "" 85 | "" 86 | "False" 87 | "True" 88 | "1" 89 | "" 90 | "" 91 | "" 92 | "" 93 | "False" 94 | "True" 95 | "0" 96 | "" 97 | "" 98 | "" 99 | "" 100 | "message_label" 101 | "True" 102 | "False" 103 | "center" 104 | "25" 105 | "50" 106 | "" 107 | "" 108 | "False" 109 | "True" 110 | "1" 111 | "" 112 | "" 113 | "" 114 | "" 115 | "" 116 | ""; 117 | -------------------------------------------------------------------------------- /lightdm-tiny-greeter.c: -------------------------------------------------------------------------------- 1 | /** 2 | * lightdm-tiny-greeter.c 3 | * 4 | * Copyright (c) 2018, Tobias Heilig 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the authors may not be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS 20 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 29 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | **/ 31 | 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "config.h" 38 | 39 | 40 | static LightDMGreeter *greeter; 41 | 42 | 43 | /* GTK components */ 44 | static GtkWidget *login_window; 45 | static GtkLabel *prompt_label; 46 | static GtkEntry *prompt_entry; 47 | static GtkLabel *message_label; 48 | 49 | 50 | /* GtkEntry activate callback */ 51 | static void 52 | login_cb () 53 | { 54 | 55 | gtk_label_set_text (message_label, ""); 56 | 57 | if (lightdm_greeter_get_is_authenticated (greeter)) { 58 | // authentication completed - start session 59 | lightdm_greeter_start_session_sync (greeter, session, NULL); 60 | } else if (lightdm_greeter_get_in_authentication (greeter)) { 61 | // authentication in progress - send password 62 | lightdm_greeter_respond (greeter, gtk_entry_get_text (prompt_entry), NULL); 63 | } else { 64 | // authentication request - send username 65 | lightdm_greeter_authenticate (greeter, gtk_entry_get_text (prompt_entry), NULL); 66 | } 67 | 68 | } 69 | 70 | 71 | /* LightDM show-message callback */ 72 | static void 73 | show_message_cb (LightDMGreeter *ldm, const gchar *text, LightDMPromptType type) 74 | { 75 | 76 | gtk_label_set_text (message_label, text); 77 | 78 | } 79 | 80 | 81 | /* LightDM show-prompt callback */ 82 | static void 83 | show_prompt_cb (LightDMGreeter *ldm, const gchar *text, LightDMPromptType type) 84 | { 85 | 86 | gtk_label_set_text (prompt_label, type == LIGHTDM_PROMPT_TYPE_SECRET ? pass_text : user_text); 87 | gtk_entry_set_text (prompt_entry, ""); 88 | gtk_entry_set_visibility (prompt_entry, type == LIGHTDM_PROMPT_TYPE_SECRET ? 0 : 1); 89 | 90 | } 91 | 92 | 93 | /* LightDM authentication-complete callback */ 94 | static void 95 | authentication_complete_cb (LightDMGreeter *ldm) 96 | { 97 | 98 | if (!lightdm_greeter_get_is_authenticated (ldm)) { 99 | gtk_label_set_text (message_label, "Authentication Failure."); 100 | 101 | } else if (!lightdm_greeter_start_session_sync (ldm, session, NULL)) { 102 | gtk_label_set_text (message_label, "Failed to start session."); 103 | 104 | } 105 | 106 | lightdm_greeter_authenticate (ldm, NULL, NULL); 107 | 108 | } 109 | 110 | 111 | int 112 | main (int argc, char **argv) 113 | { 114 | 115 | GtkCssProvider *provider; 116 | GtkBuilder *builder; 117 | GdkScreen *screen; 118 | GdkDisplay *display; 119 | GdkMonitor *monitor; 120 | GdkRectangle geometry; 121 | GMainLoop *main_loop; 122 | 123 | 124 | gtk_init (&argc, &argv); 125 | 126 | 127 | provider = gtk_css_provider_new (); 128 | 129 | // load style sheet 130 | display = gdk_display_get_default (); 131 | screen = gdk_display_get_default_screen (display); 132 | gtk_style_context_add_provider_for_screen ( 133 | screen, 134 | GTK_STYLE_PROVIDER (provider), 135 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); 136 | gtk_css_provider_load_from_data (provider, style, -1, NULL); 137 | 138 | 139 | builder = gtk_builder_new (); 140 | 141 | // load user interface 142 | gtk_builder_add_from_string (builder, ui, -1, NULL); 143 | 144 | // get components 145 | login_window = GTK_WIDGET (gtk_builder_get_object (builder, "login_window")); 146 | prompt_label = GTK_LABEL (gtk_builder_get_object (builder, "prompt_label")); 147 | prompt_entry = GTK_ENTRY (gtk_builder_get_object (builder, "prompt_entry")); 148 | message_label = GTK_LABEL (gtk_builder_get_object (builder, "message_label")); 149 | 150 | // connect gtk signals 151 | g_signal_connect (prompt_entry, "activate", G_CALLBACK (login_cb), NULL); 152 | 153 | // show window 154 | monitor = gdk_display_get_primary_monitor (display); 155 | gdk_monitor_get_geometry (monitor, &geometry); 156 | gtk_window_set_default_size (GTK_WINDOW (login_window), geometry.width, geometry.height); 157 | 158 | gtk_widget_show (login_window); 159 | gtk_entry_grab_focus_without_selecting (prompt_entry); 160 | 161 | 162 | greeter = lightdm_greeter_new (); 163 | 164 | // connect lightdm signals 165 | g_signal_connect (greeter, "show-prompt", G_CALLBACK (show_prompt_cb), NULL); 166 | g_signal_connect (greeter, "show-message", G_CALLBACK (show_message_cb), NULL); 167 | g_signal_connect (greeter, "authentication-complete", G_CALLBACK (authentication_complete_cb), NULL); 168 | 169 | // connect to lightdm daemon 170 | if (!lightdm_greeter_connect_to_daemon_sync (greeter, NULL)) 171 | return EXIT_FAILURE; 172 | 173 | // start authentication 174 | lightdm_greeter_authenticate (greeter, NULL, NULL); 175 | 176 | 177 | main_loop = g_main_loop_new (NULL, 0); 178 | 179 | // start main loop 180 | g_main_loop_run (main_loop); 181 | 182 | 183 | return EXIT_SUCCESS; 184 | 185 | } 186 | 187 | -------------------------------------------------------------------------------- /lightdm-tiny-greeter.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=LightDM Tiny Greeter 3 | Comment=Tiny GTK3 LightDM Greeter 4 | Exec=lightdm-tiny-greeter 5 | Type=Application 6 | 7 | --------------------------------------------------------------------------------