-
Notifications
You must be signed in to change notification settings - Fork 4
/
fbsplash_funcs.c
213 lines (170 loc) · 3.71 KB
/
fbsplash_funcs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* fbsplash.c
*
* fbsplash (framebuffer splash) splash method support
*
* Copyright (C) 2007 Alon Bar-Lev <[email protected]>
*
* This file is released under the GPLv2.
*
*/
#include "config.h"
#ifdef CONFIG_FBSPLASH
#include <string.h>
#include <stdio.h>
#include <fbsplash.h>
#include <syscall.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#include "swsusp.h"
#include "splash.h"
#include "fbsplash_funcs.h"
extern char fbsplash_theme[];
static struct fbspl_theme *theme;
static int was_silent;
static int have_input;
static int force_verbose;
int fbsplashfuncs_open(int mode)
{
fbspl_cfg_t *cfg;
int have_render = 0;
int ret = 0;
cfg = fbsplash_lib_init((mode==SPL_RESUME) ? fbspl_resume : fbspl_suspend);
if (!cfg) {
ret = -1;
goto cleanup;
}
cfg->verbosity = FBSPL_VERB_QUIET;
fbsplash_parse_kcmdline(false);
if (strlen(fbsplash_theme))
fbsplash_acc_theme_set(fbsplash_theme);
if (fbsplashr_init(false)) {
ret = -3;
goto cleanup;
}
have_render = 1;
theme = fbsplashr_theme_load();
if (!theme) {
ret = -4;
goto cleanup;
}
was_silent = fbsplash_is_silent();
if (!was_silent) {
fbsplash_set_silent();
}
fbsplashr_tty_silent_init(true);
fbsplashr_tty_silent_update();
fbsplashr_message_set(theme,
(mode==SPL_RESUME) ? "Resuming..." : "Suspending..." );
fbsplashr_render_screen(theme, true, false, was_silent ? FBSPL_EFF_NONE : FBSPL_EFF_FADEIN);
have_input = !fbsplashr_input_init();
cleanup:
if (ret) {
if (have_input) {
fbsplashr_input_cleanup();
have_input = 0;
}
if (have_render) {
fbsplashr_cleanup();
have_render = 0;
}
if (cfg) {
fbsplash_lib_cleanup();
cfg = NULL;
}
}
return ret;
}
int fbsplashfuncs_finish(void)
{
if (have_input) {
fbsplashr_input_cleanup();
have_input = 0;
}
if (fbsplash_is_silent()) {
fbsplashr_render_screen(theme, true, false, was_silent ? FBSPL_EFF_NONE : FBSPL_EFF_FADEOUT);
}
fbsplashr_tty_silent_cleanup();
if (!was_silent && fbsplash_is_silent())
fbsplash_set_verbose(0);
fbsplashr_theme_free(theme);
theme = NULL;
fbsplashr_cleanup();
fbsplash_lib_cleanup();
return 0;
}
int fbsplashfuncs_progress(int p)
{
static int old = 0;
if (p < old || p - old >= 10) {
old = p;
fbsplashr_progress_set(theme, FBSPL_PROGRESS_MAX/100*p);
if (fbsplash_is_silent())
fbsplashr_render_screen(theme, true, false, FBSPL_EFF_NONE);
}
return 0;
}
void fbsplashfuncs_read_password(char *buf, int vrfy)
{
#if CONFIG_ENCRYPT
char *pass;
if (fbsplash_is_silent())
fbsplash_set_verbose(0);
do {
do {
pass = getpass("Passphrase please (must be non-empty): ");
} while (strlen(pass) == 0 || strlen(pass) >= PASS_SIZE);
strcpy(buf, pass);
if (vrfy)
pass = getpass("Verify passphrase: ");
} while (vrfy && strcmp(buf, pass));
if (!force_verbose) {
fbsplash_set_silent();
fbsplashr_tty_silent_update();
}
#endif
}
int fbsplashfuncs_dialog(const char *prompt)
{
int c;
if (fbsplash_is_silent())
fbsplash_set_verbose(0);
printf("%s", prompt);
c = getchar();
if (!force_verbose) {
fbsplash_set_silent();
fbsplashr_tty_silent_update();
}
return c;
}
char fbsplashfuncs_key_pressed(void)
{
if (!have_input)
return 0;
else {
char c;
c = (char)fbsplashr_input_getkey(false);
/*
* Well... maybe someday it will work...
* But currently we cannot switch to different vt
*/
if (c == KEY_V) {
force_verbose = !force_verbose;
if (force_verbose)
fbsplash_set_verbose(0);
else
fbsplash_set_silent();
return 0;
} else {
return c;
}
}
}
void fbsplashfuncs_set_caption(const char *message)
{
fbsplashr_message_set(theme, message);
if (fbsplash_is_silent())
fbsplashr_render_screen(theme, true, false, FBSPL_EFF_NONE);
}
#endif