4
4
#include <assert.h>
5
5
#include <sys/wait.h>
6
6
#include <gtk/gtk.h>
7
+ #include <glib/gprintf.h>
7
8
8
9
#include "auth.h"
9
10
#include "window.h"
@@ -23,6 +24,7 @@ static char *gtk_theme = NULL;
23
24
static char * config_path = NULL ;
24
25
static char * style_path = NULL ;
25
26
static char * module_path = NULL ;
27
+ static char * background_path = NULL ;
26
28
27
29
static GOptionEntry main_entries [] = {
28
30
{ "daemonize" , 'd' , 0 , G_OPTION_ARG_NONE , & should_daemonize , "Detach from the controlling terminal after locking" , NULL },
@@ -34,6 +36,7 @@ static GOptionEntry config_entries[] = {
34
36
{ "gtk-theme" , 'g' , 0 , G_OPTION_ARG_STRING , & gtk_theme , "Set GTK theme" , NULL },
35
37
{ "style" , 's' , 0 , G_OPTION_ARG_FILENAME , & style_path , "Load CSS style file" , NULL },
36
38
{ "module" , 'm' , 0 , G_OPTION_ARG_FILENAME , & module_path , "Load gtklock module" , NULL },
39
+ { "background" , 'b' , 0 , G_OPTION_ARG_FILENAME , & background_path , "Load background" , NULL },
37
40
};
38
41
39
42
static GOptionEntry debug_entries [] = {
@@ -114,18 +117,40 @@ static void activate(GtkApplication *app, gpointer user_data) {
114
117
if (parent > 0 ) kill (parent , SIGINT );
115
118
}
116
119
117
- static void attach_custom_style (const char * path ) {
120
+ static void attach_style (const char * format , ...) G_GNUC_PRINTF (1 , 2 );
121
+ static void attach_style (const char * format , ...) {
118
122
GtkCssProvider * provider = gtk_css_provider_new ();
119
123
GError * err = NULL ;
124
+ va_list args ;
125
+ va_start (args , format );
126
+ char * buff = g_strdup_vprintf (format , args );
127
+ va_end (args );
120
128
121
- gtk_css_provider_load_from_path (provider , path , & err );
129
+ gtk_css_provider_load_from_data (provider , buff , -1 , & err );
122
130
if (err != NULL ) {
123
131
g_warning ("Style loading failed: %s" , err -> message );
124
132
g_error_free (err );
125
133
} else {
126
134
gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
127
135
GTK_STYLE_PROVIDER (provider ), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION );
128
136
}
137
+
138
+ g_object_unref (provider );
139
+ g_free (buff );
140
+ }
141
+
142
+ static void attach_custom_style (const char * path ) {
143
+ GtkCssProvider * provider = gtk_css_provider_new ();
144
+ GError * err = NULL ;
145
+
146
+ gtk_css_provider_load_from_path (provider , path , & err );
147
+ if (err != NULL ) {
148
+ g_warning ("Custom style loading failed: %s" , err -> message );
149
+ g_error_free (err );
150
+ } else {
151
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
152
+ GTK_STYLE_PROVIDER (provider ), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1 );
153
+ }
129
154
g_object_unref (provider );
130
155
}
131
156
@@ -191,8 +216,22 @@ int main(int argc, char **argv) {
191
216
gtklock -> use_layer_shell = !no_layer_shell ;
192
217
gtklock -> use_input_inhibit = !no_input_inhibit ;
193
218
219
+ if (background_path != NULL ) {
220
+ GFile * file = g_file_new_for_path (background_path );
221
+ char * path = g_file_get_path (file );
222
+ g_object_unref (file );
223
+ attach_style (
224
+ "window { "
225
+ "background-color: black;"
226
+ "background-image: url(\"%s\");"
227
+ "background-size: 100%% 100%%;"
228
+ "}" ,
229
+ path
230
+ );
231
+ }
232
+
194
233
if (style_path == NULL ) style_path = xdg_get_config_path ("style.css" );
195
- if (style_path ) {
234
+ if (style_path != NULL ) {
196
235
attach_custom_style (style_path );
197
236
free (style_path );
198
237
}
0 commit comments