Debian Codegraph @

moonlight-theme/plymouth/moonlight.script

raw
1 # moonlight.script - boot splash using script plugin
2 #
3 # Copyright (C) 2009 Canonical Ltd.
4 # Copyright © 2010-2016 Aurélien Couderc <[email protected]>
5 # Copyright © 2014-2018 Juliette Taka <[email protected]>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21 # Written by: Alberto Milone <[email protected]>
22 #
23 # Based on the example provided with the "script plugin" written by:
24 # Charlie Brej <[email protected]>
25 #
26 # Moonlight theme scripting by Juliette Taka BELIN and Aurélien COUDERC
27
28
29 #------------------------------- Constants -----------------------------------------
30 NB_SCALE_STEPS = 70;
31 NB_REFRESHS_BETWEEN_ANIMS = 3;
32
33 DEBIAN_POS_PCT.y = 0.60; # Debian image position in % of screen height
34 DEBIAN_HEIGHT_PCT = 0.06; # Debian image height in % of smallest screen dimension
35
36 LOGO_CENTER_PCT.x = 0.5; # Debian swirl image position in % of screen height & width
37 LOGO_CENTER_PCT.y = 0.38;
38 LOGO_SIZE_PCT = 0.28; # Debian swirl image size in % of smallest screen dimension
39
40 SUPPORT_CENTER_PCT.x = 0.47; # Logo support position in % of screen height & width
41 SUPPORT_CENTER_PCT.y = 0.4;
42 SUPPORT_HEIGHT_PCT = 0.4; # height in % of smallest screen dimension
43
44 GLOW_SIZE_PCT = 0.3;
45
46 #------------------------------- Globals -------------------------------------------
47 # are we currently prompting for a password?
48 prompt_active = 0;
49
50 # Globals to share progress time / percent with intersted functions
51 progress_time = 0;
52 progress_pct = 0;
53
54 # Variables for glow rotation animation
55 #anim_start_time = NULL;
56 #anim_status = "stopped";
57 refresh_iter = 0;
58 anim_iter = 0;
59
60 #-----------------------------Text-image functions----------------------------
61
62 # Set the text colour in (rgb / 256)
63 text_colour.red = 1.0;
64 text_colour.green = 1.0;
65 text_colour.blue = 1.0;
66
67 # Tinted text #988592
68 tinted_text_colour.red = 1.0;
69 tinted_text_colour.green = 1.0;
70 tinted_text_colour.blue = 1.0;
71
72 # Action Text - #ffffff - RGB 255 255 255
73 action_text_colour.red = 1.0;
74 action_text_colour.green = 1.0;
75 action_text_colour.blue = 1.0;
76
77 # Orange - #ff4012 - RGB 255 64 18
78 debugsprite = Sprite();
79 debugsprite_bottom = Sprite();
80 debugsprite_bottom.SetPosition(0, (Window.GetHeight (0) - 20), 1);
81 debugsprite_medium = Sprite();
82 debugsprite_medium.SetPosition(0, (Window.GetHeight (0) - 100), 1);
83
84 # General purpose function to create text
85 fun WriteText (text, colour) {
86 image = Image.Text (text, colour.red, colour.green, colour.blue);
87 return image;
88 }
89
90 fun ImageFromText (text) {
91 image = WriteText (text, text_colour);
92 return image;
93 }
94
95 fun ImageFromTintedText (text) {
96 image = WriteText (text, tinted_text_colour);
97 return image;
98 }
99
100 fun ImageFromActionText (text) {
101 image = WriteText (text, action_text_colour);
102 return image;
103 }
104
105 fun Debug(text) {
106 debugsprite.SetImage(ImageFromText (text));
107 }
108
109 fun DebugBottom(text) {
110 debugsprite_bottom.SetImage(ImageFromText (text));
111 }
112
113 fun DebugMedium(text) {
114 debugsprite_medium.SetImage(ImageFromText (text));
115 }
116
117 #Debug("Window.GetHeight(0) = " + Window.GetHeight(0));
118 fun TextYOffset() {
119 local.y;
120 local.text_height;
121 local.min_height;
122
123 # Put the 1st line below the logo + some spacing
124 y = debian_sprite.GetY() + debian.GetHeight();
125 #Debug("y = " + y);
126
127 text_height = first_line_height * 7.5;
128 min_height = window_max.height;
129 #Debug("text_height=" + text_height + "; min_height=" + min_height);
130
131 if (y + text_height > min_height)
132 y = min_height - text_height;
133
134 return y;
135 }
136
137
138 #----------------------------- Screen/window setup ---------------------------
139 # Compute screen/image ratio and scale the background accordingly
140 window_max.width = Window.GetX() * 2 + Window.GetWidth();
141 window_max.height = Window.GetY() * 2 + Window.GetHeight();
142 screen_ratio = window_max.width / window_max.height;
143 small_dimension = Math.Min(window_max.width, window_max.height);
144 #Debug("Window.GetX():" + Window.GetX() + ", Window.GetY():" + Window.GetY());
145 #Debug("Window is [" + window_max.width + ";" + window_max.height + "], ratio=" + screen_ratio);
146
147 debian_height = small_dimension * DEBIAN_HEIGHT_PCT;
148 debian_pos.y = window_max.height * DEBIAN_POS_PCT.y - debian_height/2;
149 logo_size = small_dimension * LOGO_SIZE_PCT;
150 logo_center.x = window_max.width * LOGO_CENTER_PCT.x;
151 logo_center.y = window_max.height * LOGO_CENTER_PCT.y;
152
153 glow_size = small_dimension * GLOW_SIZE_PCT;
154
155 #Debug("Logo center at [" + logo_center.x + ";" + logo_center.y + "], size=" + logo_size + "px");
156
157 logo_pos.x = logo_center.x - logo_size/2;
158 logo_pos.y = logo_center.y - logo_size/2;
159
160 glow_pos.x = logo_center.x - glow_size/2;
161 glow_pos.y = logo_center.y - glow_size/2;
162 glow_anim_scale = 0;
163
164 support_size = small_dimension * SUPPORT_HEIGHT_PCT;
165 support_center.x = window_max.width * SUPPORT_CENTER_PCT.x;
166 support_center.y = window_max.height * SUPPORT_CENTER_PCT.y;
167 support_pos.x = support_center.x - support_size/2;
168 support_pos.y = support_center.y - support_size/2;
169
170
171 #------------------------------- Background ----------------------------------------
172 bg_image = Image("background.png");
173 bg_image_ratio = bg_image.GetWidth() / bg_image.GetHeight();
174 if (screen_ratio > bg_image_ratio)
175 bg_scale_factor = window_max.width / bg_image.GetWidth();
176 else
177 bg_scale_factor = window_max.height / bg_image.GetHeight();
178 scaled_bg_image = bg_image.Scale(bg_image.GetWidth() * bg_scale_factor,
179 bg_image.GetHeight() * bg_scale_factor);
180
181 # Display background
182 bg_sprite = Sprite(scaled_bg_image);
183 bg_sprite.SetPosition(Window.GetX() + Window.GetWidth() / 2 - scaled_bg_image.GetWidth() / 2,
184 Window.GetY() + Window.GetHeight() / 2 - scaled_bg_image.GetHeight() / 2,
185 -1000);
186
187 #------------------------------- Debian ----------------------------------------------
188 debian = Image("debian.png");
189 # Target same height as logo
190 debian_scale_factor = debian_height / debian.GetHeight();
191 debian = debian.Scale(debian.GetWidth() * debian_scale_factor,
192 debian.GetHeight() * debian_scale_factor);
193 debian_sprite = Sprite(debian);
194 debian_sprite.SetPosition(window_max.width / 2 - debian.GetWidth() / 2,
195 debian_pos.y,
196 -80);
197
198 #------------------------------- Logo ----------------------------------------------
199 logo = Image("logo_in_circle.png");
200 logo_scale_factor = logo_size / logo.GetWidth();
201 logo = logo.Scale(logo.GetWidth() * logo_scale_factor,
202 logo.GetHeight() * logo_scale_factor);
203 logo_to_top_edge = Window.GetHeight() * 0.3;
204 logo_sprite = Sprite(logo);
205 logo_sprite.SetPosition(logo_pos.x, logo_pos.y, -50);
206
207 #------------------------------- Glow ----------------------------------------------
208
209 logo_glow = Image("glow.png");
210 logo_glow_scale_factor = 0.85;
211 logo_glow = logo_glow.Scale(logo_glow.GetWidth() * logo_glow_scale_factor,
212 logo_glow.GetHeight() * logo_glow_scale_factor);
213 logo_glow_sprite = Sprite(logo_glow);
214 logo_glow_sprite.SetPosition(logo_sprite.GetX() + 0.5*logo.GetWidth() - 0.5*logo_glow.GetWidth(),
215 logo_sprite.GetY() + 0.5*logo.GetHeight() - 0.5*logo_glow.GetHeight(), -80);
216 # logo_glow_sprite.Scale(glow_anim_scale,glow_anim_scale);
217
218 glow_step = 0.02;
219 glow_minOp = 0.25;
220 glow_maxOp = 0.6;
221
222 logo_glow_sprite.SetOpacity(glow_minOp);
223
224 #------------------------------- Support ----------------------------------------------
225 support = Image("support.png");
226 support_scale_factor = support_size / support.GetWidth();
227 support = support.Scale(support.GetWidth() * support_scale_factor,
228 support.GetHeight() * support_scale_factor);
229 support_sprite = Sprite(support);
230 support_sprite.SetPosition(support_pos.x, support_pos.y - logo.GetHeight(), -80);
231
232
233 #------------------------------- Star ----------------------------------------------
234 star = Image("star.png");
235 star_sprite0 = Sprite(star);
236 star_sprite0.SetPosition(0.2 * Window.GetWidth(), 0.2 * Window.GetHeight(), -80);
237 star_sprite1 = Sprite(star);
238 star_sprite1.SetPosition(0.8 * Window.GetWidth(), 0.3 * Window.GetHeight(), -80);
239 star_sprite2 = Sprite(star);
240 star_sprite2.SetPosition(0.7 * Window.GetWidth(), 0.5 * Window.GetHeight(), -80);
241 star_sprite3 = Sprite(star);
242 star_sprite3.SetPosition(0.1 * Window.GetWidth(), 0.65 * Window.GetHeight(), -80);
243
244 star_step = 0.01;
245 star_minOp = 0.05;
246 star_maxOp = 0.8;
247
248 #------------------------------String functions-------------------------------
249
250 # This is the equivalent for strstr()
251 fun StringString(string, substring) {
252 start = 0;
253 while (String(string).CharAt (start)) {
254 walk = 0;
255 while (String(substring).CharAt (walk) == String(string).CharAt (start + walk) ) {
256 walk++;
257 if (!String(substring).CharAt (walk)) return start;
258 }
259 start++;
260 }
261
262 return NULL;
263 }
264
265 fun StringLength (string) {
266 index = 0;
267 while (String(string).CharAt(index)) index++;
268 return index;
269 }
270
271 fun StringCopy (source, beginning, end) {
272 local.destination = "";
273 for (index = beginning; ( ( (end == NULL) || (index <= end) ) && (String(source).CharAt(index)) ); index++) {
274 local.destination += String(source).CharAt(index);
275 }
276
277 return local.destination;
278 }
279
280 fun StringReplace (source, pattern, replacement) {
281 local.found = StringString(source, pattern);
282 if (local.found == NULL)
283 return source;
284
285 local.new_string = StringCopy (source, 0, local.found - 1) +
286 replacement +
287 StringCopy (source, local.found + StringLength(pattern), NULL);
288
289 return local.new_string;
290 }
291
292 # it makes sense to use it only for
293 # numbers up to 100
294 fun StringToInteger (str) {
295 int = -1;
296 for (i=0; i<=100; i++) {
297 if (i+"" == str) {
298 int = i;
299 break;
300 }
301 }
302 return int;
303 }
304
305 #-----------------------------------------------------------------------------
306 # Top background colour
307 # #489291 --> 0.282, 0.572, 0.569
308 # New background colour
309 # #0a3649 --> 0.039, 0.212, 0.286
310 #
311 Window.SetBackgroundTopColor (0.282, 0.572, 0.569); # Nice colour on top of the screen fading to
312 Window.SetBackgroundBottomColor (0.039, 0.212, 0.286); # an equally nice colour on the bottom
313
314 bits_per_pixel = Window.GetBitsPerPixel ();
315 # TODO need to handle 16 colors ?
316 #if (bits_per_pixel == 4) {
317 # logo_filename = "debian.png";
318 # progress_dot_off_filename = "progress_dot_off16.png";
319 # progress_dot_on_filename = "progress_dot_on16.png";
320 # password_dot_filename = "password_dot.png";
321 # password_field_filename = "password_field16.png";
322 #} else {
323 # logo_filename = "debian.png";
324 # progress_dot_off_filename = "progress_dot_off.png";
325 # progress_dot_on_filename = "progress_dot_on.png";
326 password_dot_filename = "password_dot.png";
327 password_field_filename = "password_field.png";
328 #}
329
330 message_notification[0].image = ImageFromTintedText ("");
331 message_notification[1].image = ImageFromTintedText ("");
332 fsck_notification.image = ImageFromActionText ("");
333
334 status = "normal";
335
336 # use a fixed string with ascending and descending stems to calibrate the
337 # bounding box for the first message, so the messages below don't move up
338 # and down according to *their* height.
339 first_line_height = ImageFromTintedText ("AfpqtM").GetHeight();
340
341 # if the user has a 640x480 or 800x600 display, we can't quite fit everything
342 # (including passphrase prompts) with the target spacing, so scoot the text up
343 # a bit if needed.
344 top_of_the_text = TextYOffset();
345
346
347 #-------------------------------Progress Indicator-----------------------------
348 # Implement in boot progress callback
349 fun animate_progress_indicator (time, progress) {
350 progress_time = time;
351 progress_pct = progress;
352
353 #Debug ("mode = " + Plymouth.GetMode() + ", progress_time = " + progress_time + ", progress_pct = " + progress_pct);
354
355 }
356
357
358 #-----------------------------------------Label utility functions---------------------
359
360 # label should be either a string or NULL
361 # Images for n lines will be created and returned as items of the
362 # message_label array
363 #
364 fun get_message_label (label, is_fake, is_action_line) {
365 #Debug("Get Label position");
366 local.message_label;
367
368 if (is_fake)
369 # Create a fake label so as to get the y coordinate of
370 # a standard-length label.
371 local.message_image = ImageFromTintedText ("This is a fake message");
372 else
373 local.message_image = (is_action_line) && ImageFromActionText (label) || ImageFromTintedText (label);
374
375 message_label.width = message_image.GetWidth ();
376 message_label.height = message_image.GetHeight ();
377
378 # Center the line horizontally
379 message_label.x = Window.GetX () + Window.GetWidth () / 2 - message_label.width / 2;
380
381 message_label.y = top_of_the_text;
382
383 # Put the 2nd line below the fsck line
384 if (is_action_line) {
385 local.fsck_label.y = message_label.y + (first_line_height + first_line_height / 2);
386 message_label.y = local.fsck_label.y + (first_line_height * 1.5);
387 }
388
389 #Debug("action label x = " + message_label.x + " y = " + message_label.y );
390
391 # message_debug = "msg_x = " + message_label.x + " msg_y = " + message_label.y +
392 # "msg_width = " + message_label.width + " msg_height = " +
393 # message_label.height + " message = " + label;
394 # Debug(message_debug);
395
396 return message_label;
397
398 }
399
400 # Create an fsck label and/or get its position
401 fun get_fsck_label (label, is_fake) {
402 # Debug("Get Label position");
403 local.fsck_label = global.progress_label;
404
405 if (is_fake)
406 fsck_label.image = ImageFromTintedText ("This is a fake message");
407 else
408 fsck_label.image = ImageFromTintedText (label);
409
410 fsck_label.width = fsck_label.image.GetWidth ();
411 fsck_label.height = fsck_label.image.GetHeight ();
412
413 # Centre the label horizontally
414 fsck_label.x = Window.GetX () + Window.GetWidth () / 2 - fsck_label.width / 2;
415
416 local.first_label = get_message_label (label, 1, 0);
417
418 # Place the label below the 1st message line
419 fsck_label.y = local.first_label.y + local.first_label.height + (local.first_label.height / 2);
420
421 # message_debug = "msg_x = " + fsck_label.x + " msg_y = " + fsck_label.y +
422 # "msg_width = " + fsck_label.width + " msg_height = " +
423 # fsck_label.height + " message = " + label;
424 # Debug(message_debug);
425
426 return fsck_label;
427 }
428
429 #-----------------------------------------Message stuff --------------------------------
430 #
431
432 # Set up a message label
433 #
434 # NOTE: this is called when doing something like 'plymouth message "hello world"'
435 #
436 fun setup_message (message_text, x, y, z, index) {
437 #DebugMedium("Message setup: " + message_text);
438 global.message_notification[index].image = (index) && ImageFromActionText (message_text) || ImageFromTintedText (message_text);
439
440 # Set up the text message, if any
441 message_notification[index].x = x;
442 message_notification[index].y = y;
443 message_notification[index].z = z;
444
445 message_notification[index].sprite = Sprite ();
446 message_notification[index].sprite.SetImage (message_notification[index].image);
447 message_notification[index].sprite.SetX (message_notification[index].x);
448 message_notification[index].sprite.SetY (message_notification[index].y);
449 message_notification[index].sprite.SetZ (message_notification[index].z);
450
451 }
452
453 fun show_message (index) {
454 if (global.message_notification[index].sprite) global.message_notification[index].sprite.SetOpacity(1);
455 }
456
457 fun hide_message (index) {
458 if (global.message_notification[index].sprite) global.message_notification[index].sprite.SetOpacity(0);
459 }
460
461
462
463
464 # the callback function is called when new message should be displayed.
465 # First arg is message to display.
466 fun message_callback (message)
467 {
468 # Debug("Message callback");
469 is_fake = 0;
470 if (!message || (message == "")) is_fake = 1;
471
472 local.substring = "keys:";
473
474 # Look for the "keys:" prefix
475 local.keys = StringString(message, local.substring);
476
477 local.is_action_line = (keys != NULL);
478 #Debug("keys " + local.keys + " substring length = " + StringLength(local.substring));
479
480 # Get the message without the "keys:" prefix
481 if (keys != NULL)
482 message = StringCopy (message, keys + StringLength(local.substring), NULL);
483
484 # Get the message without the "fsckd-cancel-msg" prefix as we don't support i18n
485 substring = "fsckd-cancel-msg:";
486 keys = StringString(message, substring);
487 if (keys != NULL)
488 message = StringCopy(message, keys + StringLength(substring), NULL);
489
490 local.label.is_fake = is_fake;
491 label = get_message_label(message, is_fake, is_action_line);
492 label.z = 10000;
493
494 setup_message (message, label.x, label.y, label.z, is_action_line);
495 if (prompt_active && local.is_action_line)
496 hide_message (is_action_line);
497 else
498 show_message (is_action_line);
499
500 }
501
502
503 #-----------------------------------------Display Password stuff -----------------------
504 #
505
506 fun password_dialogue_setup (message_label) {
507 #Debug("Password dialog setup");
508
509 local.entry;
510 local.bullet_image;
511
512 bullet_image = Image (password_dot_filename);
513 entry.image = Image (password_field_filename);
514
515 # Hide the normal labels
516 prompt_active = 1;
517 if (message_notification[1].sprite) hide_message (1);
518
519 # Set the prompt label
520 label = get_message_label(message_label, 0, 1);
521 label.z = 10000;
522
523 setup_message (message_label, label.x, label.y, label.z, 2);
524 show_message (2);
525
526 # Set up the text entry which contains the bullets
527 entry.sprite = Sprite ();
528 entry.sprite.SetImage (entry.image);
529
530 # Centre the box horizontally
531 entry.x = Window.GetX () + Window.GetWidth () / 2 - entry.image.GetWidth () / 2;
532
533 # Put the entry below the second label.
534 entry.y = message_notification[2].y + label.height * 1.5;
535
536 #DebugMedium("entry x = " + entry.x + ", y = " + entry.y);
537 entry.z = 10000;
538 entry.sprite.SetX (entry.x);
539 entry.sprite.SetY (entry.y);
540 entry.sprite.SetZ (entry.z);
541
542 global.password_dialogue = local;
543 }
544
545 fun password_dialogue_opacity (opacity) {
546 #Debug("Setting password dialog opacity to " + opacity);
547 global.password_dialogue.opacity = opacity;
548 local = global.password_dialogue;
549
550 # You can make the box translucent with a float
551 # entry.sprite.SetOpacity (0.3);
552 entry.sprite.SetOpacity (opacity);
553 label.sprite.SetOpacity (opacity);
554
555 if (bullets) {
556 for (index = 0; bullets[index]; index++) {
557 bullets[index].sprite.SetOpacity (opacity);
558 }
559 }
560 }
561
562
563 # The callback function is called when the display should display a password dialogue.
564 # First arg is prompt string, the second is the number of bullets.
565 fun display_password_callback (prompt, bullets) {
566 #Debug("Password dialog setup");
567
568 global.status = "password";
569 if (!global.password_dialogue) password_dialogue_setup(prompt);
570 password_dialogue_opacity (1);
571 bullet_width = password_dialogue.bullet_image.GetWidth();
572 bullet_y = password_dialogue.entry.y +
573 password_dialogue.entry.image.GetHeight () / 2 -
574 password_dialogue.bullet_image.GetHeight () / 2;
575 margin = bullet_width;
576 spaces = Math.Int( (password_dialogue.entry.image.GetWidth () - (margin * 2)) / (bullet_width / 2 ) );
577 #DebugMedium ("spaces = " + spaces + ", bullets = " + bullets);
578 bullets_area.width = margin + spaces * (bullet_width / 2);
579 bullets_area.x = Window.GetX () + Window.GetWidth () / 2 - bullets_area.width / 2;
580 #DebugBottom ("pwd_entry (x,y) = " + password_dialogue.entry.x + "," + password_dialogue.entry.y
581 # + "), bullets_area.x = " + bullets_area.x + ", bullets_area.width = " + bullets_area.width);
582 if (bullets > spaces)
583 bullets = spaces;
584 for (index = 0; password_dialogue.bullets[index] || index < bullets; index++){
585 if (!password_dialogue.bullets[index]) {
586 password_dialogue.bullets[index].sprite = Sprite ();
587 password_dialogue.bullets[index].sprite.SetImage (password_dialogue.bullet_image);
588 password_dialogue.bullets[index].x = bullets_area.x + # password_dialogue.entry.x + margin +
589 index * bullet_width / 2;
590 password_dialogue.bullets[index].sprite.SetX (password_dialogue.bullets[index].x);
591 password_dialogue.bullets[index].y = bullet_y;
592 password_dialogue.bullets[index].sprite.SetY (password_dialogue.bullets[index].y);
593 password_dialogue.bullets[index].z = password_dialogue.entry.z + 1;
594 password_dialogue.bullets[index].sprite.SetZ (password_dialogue.bullets[index].z);
595 }
596
597 password_dialogue.bullets[index].sprite.SetOpacity (0);
598
599 if (index < bullets) {
600 password_dialogue.bullets[index].sprite.SetOpacity (1);
601 }
602 }
603 }
604
605 Plymouth.SetDisplayPasswordFunction (display_password_callback);
606
607 Plymouth.SetMessageFunction (message_callback);
608
609 Plymouth.SetBootProgressFunction (animate_progress_indicator);
610
611 # Plymouth.SetBootProgressFunction: the callback function is called with two numbers, the progress (between 0 and 1) and the time spent booting so far
612 # Plymouth.SetRootMountedFunction: the callback function is called when a new root is mounted
613 # Plymouth.SetKeyboardInputFunction: the callback function is called with a string containing a new character entered on the keyboard
614
615 #----------------------------------------- FSCK Counter --------------------------------
616
617 # Initialise the counter
618 fun init_fsck_count () {
619 # The number of fsck checks in this cycle
620 global.counter.total = 0;
621 # The number of fsck checks already performed + the current one
622 global.counter.current = 1;
623 # The previous fsck
624 global.counter.last = 0;
625 }
626
627 # Increase the total counter
628 fun increase_fsck_count () {
629 global.counter.total++;
630 }
631
632 fun increase_current_fsck_count () {
633 global.counter.last = global.counter.current++;
634 }
635
636 # Clear the counter
637 fun clear_fsck_count () {
638 global.counter = NULL;
639 init_fsck_count ();
640 }
641
642 #----------------------------------------- Progress Label ------------------------------
643
644
645 # Change the opacity level of a progress label
646 #
647 # opacity = 1 -> show
648 # opacity = 0 -> hide
649 # opacity = 0.3 (or any other float) -> translucent
650 #
651 fun set_progress_label_opacity (opacity) {
652 # the label
653 progress_label.sprite.SetOpacity (opacity);
654
655 # Make the slot available again when hiding the bar
656 # So that another bar can take its place
657 if (opacity == 0) {
658 progress_label.is_available = 1;
659 progress_label.device = "";
660 }
661 }
662
663 # Set up a new Progress Bar
664 #
665 # TODO: Make it possible to reuse (rather than recreate) a bar
666 # if .is_available = 1. Ideally this would just reset the
667 # label, the associated
668 # device and the image size of the sprite.
669
670 fun init_progress_label (device, status_string) {
671 # Make the slot unavailable
672 global.progress_label.is_available = 0;
673 progress_label.progress = 0;
674 progress_label.device = device;
675 progress_label.status_string = status_string;
676 }
677
678 # See if the progress label is keeping track of the fsck
679 # of "device"
680 #
681 fun device_has_progress_label (device) {
682 #DebugBottom ("label device = " + progress_label.device + " checking device " + device);
683 return (progress_label.device == device);
684 }
685
686 # Update the Progress bar which corresponds to index
687 #
688 fun update_progress_label (progress) {
689 # If progress is NULL then we just refresh the label.
690 # This happens when only counter.total has changed.
691 if (progress != NULL) {
692 progress_label.progress = progress;
693
694 #Debug("device " + progress_label.device + " progress " + progress);
695
696 # If progress >= 100% hide the label and make it available again
697 if (progress >= 100) {
698 set_progress_label_opacity (0);
699
700 # See if we any other fsck check is complete
701 # and, if so, hide the progress bars and the labels
702 on_fsck_completed ();
703
704 return 0;
705 }
706 }
707 # Update progress label here
708 #
709 # FIXME: the queue logic from this theme should really be moved into mountall
710 # instead of using string replacement to deal with localised strings.
711 label = StringReplace (progress_label.status_string[0], "%1$d", global.counter.current);
712 label = StringReplace (label, "%2$d", global.counter.total);
713 label = StringReplace (label, "%3$d", progress_label.progress);
714 label = StringReplace (label, "%%", "%");
715
716 progress_label = get_fsck_label (label, 0);
717 #progress_label.progress = progress;
718
719 progress_label.sprite = Sprite (progress_label.image);
720
721 # Set up the bar
722 progress_label.sprite.SetPosition(progress_label.x, progress_label.y, 1);
723
724 set_progress_label_opacity (1);
725
726 }
727
728 # Refresh the label so as to update counters
729 fun refresh_progress_label () {
730 update_progress_label (NULL);
731 }
732
733 #----------------------------------------- FSCK Queue ----------------------------------
734
735 # Initialise the fsck queue
736 fun init_queue () {
737 global.fsck_queue[0].device;
738 global.fsck_queue[0].progress;
739 global.fsck_queue.counter = 0;
740 global.fsck_queue.biggest_item = 0;
741 }
742
743 fun clear_queue () {
744 global.fsck_queue = NULL;
745 init_queue ();
746 }
747
748 # Return either the device index in the queue or -1
749 fun queue_look_up_by_device (device) {
750 for (i=0; i <= fsck_queue.biggest_item; i++) {
751 if ((fsck_queue[i]) && (fsck_queue[i].device == device))
752 return i;
753 }
754 return -1;
755 }
756
757 # Keep track of an fsck process in the queue
758 fun add_fsck_to_queue (device, progress) {
759 # Look for an empty slot in the queue
760 for (i=0; global.fsck_queue[i].device; i++) {
761 continue;
762 }
763 local.index = i;
764
765 # Set device and progress
766 global.fsck_queue[local.index].device = device;
767 global.fsck_queue[local.index].progress = progress;
768
769 # Increase the queue counter
770 global.fsck_queue.counter++;
771
772 # Update the max index of the array for iterations
773 if (local.index > global.fsck_queue.biggest_item)
774 global.fsck_queue.biggest_item = local.index;
775
776 #DebugMedium ("Adding " + device + " at " + local.index);
777 }
778
779 fun is_queue_empty () {
780 return (fsck_queue.counter == 0);
781 }
782
783 fun is_progress_label_available () {
784 return (progress_label.is_available == 1);
785 }
786
787
788 # This should cover the case in which the fsck checks in
789 # the queue are completed before the ones showed in the
790 # progress label
791 fun on_queued_fsck_completed () {
792 if (!is_queue_empty ())
793 return;
794
795 # Hide the extra label, if any
796 #if (progress_bar.extra_label.sprite)
797 # progress_bar.extra_label.sprite.SetOpacity(0);
798 }
799
800 fun remove_fsck_from_queue (index) {
801 # Free memory which was previously allocated for
802 # device and progress
803 global.fsck_queue[index].device = NULL;
804 global.fsck_queue[index].progress = NULL;
805
806 # Decrease the queue counter
807 global.fsck_queue.counter--;
808
809 # See if there are other processes in the queue
810 # if not, clear the extra_label
811 on_queued_fsck_completed ();
812 }
813
814 fun on_fsck_completed () {
815 # We have moved on to tracking the next fsck
816 increase_current_fsck_count ();
817
818 if (!is_progress_label_available ())
819 return;
820
821 if (!is_queue_empty ())
822 return;
823
824 # Hide the progress label
825 if (progress_label.sprite)
826 progress_label.sprite.SetOpacity (0);
827
828 # Clear the queue
829 clear_queue ();
830
831 # Clear the fsck counter
832 clear_fsck_count ();
833 }
834
835 # Update an fsck process that we keep track of in the queue
836 fun update_progress_in_queue (index, device, progress) {
837 # If the fsck is complete, remove it from the queue
838 if (progress >= 100) {
839 remove_fsck_from_queue (index);
840 on_queued_fsck_completed ();
841 return;
842 }
843
844 global.fsck_queue[index].device = device;
845 global.fsck_queue[index].progress = progress;
846
847 }
848
849 # TODO: Move it to some function
850 # Create an empty queue
851 #init_queue ();
852
853
854 #----------------------------------------- FSCK Functions ------------------------------
855
856
857 # Either add a new bar for fsck checks or update an existing bar
858 #
859 # NOTE: no more than "progress_bar.max_number" bars are allowed
860 #
861 fun fsck_check (device, progress, status_string) {
862
863 # The 1st time this will take place
864 if (!global.progress_label) {
865 # Increase the fsck counter
866 increase_fsck_count ();
867
868 # Set up a new label for the check
869 init_progress_label (device, status_string);
870 update_progress_label (progress);
871
872 return;
873 }
874
875
876 if (device_has_progress_label (device)) {
877 # Update the progress of the existing label
878 update_progress_label (progress);
879 }
880 else {
881 # See if there's already a slot in the queue for the device
882 local.queue_device_index = queue_look_up_by_device(device);
883
884 # See if the progress_label is available
885 if (progress_label.is_available) {
886
887 # local.my_string = "available index " + local.available_index + " progress_bar counter is " + progress_bar.counter;
888 # Debug(local.my_string);
889
890
891 # If the fsck check for the device was in the queue, then
892 # remove it from the queue
893 if (local.queue_device_index >= 0) {
894 remove_fsck_from_queue (index);
895 }
896 else {
897 # Increase the fsck counter
898 increase_fsck_count ();
899 }
900
901 # local.my_string += local.message;
902 #Debug("setting new label for device " + device + " progress " + progress);
903
904 # Set up a new label for the check
905 init_progress_label (device, status_string);
906 update_progress_label (progress);
907
908 }
909 # If the progress_label is not available
910 else {
911
912 # If the fsck check for the device is already in the queue
913 # just update its progress in the queue
914 if (local.queue_device_index >= 0) {
915 #DebugMedium("Updating queue at " + local.queue_device_index + " for device " + device);
916 update_progress_in_queue (local.queue_device_index, device, progress);
917 }
918 # Otherwise add the check to the queue
919 else {
920 #DebugMedium("Adding device " + device + " to queue at " + local.queue_device_index);
921 add_fsck_to_queue (device, progress);
922
923 # Increase the fsck counter
924 increase_fsck_count ();
925
926 refresh_progress_label ();
927 }
928
929 }
930 }
931
932 # if (!is_queue_empty ()) {
933 # DebugBottom("Extra label for "+ device);
934 #}
935 # else {
936 # DebugBottom("No extra label for " + device + ". 1st Device in the queue "+ fsck_queue[0].device + " counter = " + global.fsck_queue.counter);
937 # }
938 }
939
940
941 #-----------------------------------------Update Status stuff --------------------------
942 #
943 # The update_status_callback is what we can use to pass plymouth whatever we want so
944 # as to make use of features which are available only in this program (as opposed to
945 # being available for any theme for the script plugin).
946 #
947 # Example:
948 #
949 # Thanks to the current implementation, some scripts can call "plymouth --update=fsck:sda1:40"
950 # and this program will know that 1) we're performing and fsck check, 2) we're checking sda1,
951 # 3) the program should set the label progress to 40%
952 #
953 # Other features can be easily added by parsing the string that we pass plymouth with "--update"
954 #
955 fun update_status_callback (status) {
956 # Debug(status);
957 if (!status) return;
958
959 string_it = 0;
960 update_strings[string_it] = "";
961
962 for (i=0; (String(status).CharAt(i) != ""); i++) {
963 local.temp_char = String(status).CharAt(i);
964 if (temp_char != ":")
965 update_strings[string_it] += temp_char;
966 else
967 update_strings[++string_it] = "";
968 }
969
970 # my_string = update_strings[0] + " " + update_strings[1] + " " + update_strings[2];
971 # Debug(my_string);
972 # Let's assume that we're dealing with these strings fsck:sda1:40
973 if ((string_it >= 2) && (update_strings[0] == "fsck")) {
974
975 device = update_strings[1];
976 progress = update_strings[2];
977 status_string[0] = update_strings[3]; # "Checking disk %1$d of %2$d (%3$d %% complete)"
978 if (!status_string[0])
979 status_string[0] = "Checking disk %1$d of %2$d (%3$d %% complete)";
980
981 if ((device != "") && (progress != "")) {
982 progress = StringToInteger (progress);
983
984 # Make sure that the fsck_queue is initialised
985 if (!global.fsck_queue)
986 init_queue ();
987
988 # Make sure that the fsck counter is initialised
989 if (!global.counter)
990 init_fsck_count ();
991
992 # if (!global.progress_bar.extra_label.sprite)
993 # create_extra_fsck_label ();
994
995 # Keep track of the fsck check
996 fsck_check (device, progress, status_string);
997 }
998
999 }
1000
1001 # systemd-fsckd pass fsckd:<number_devices>:<progress>:<l10n_string>
1002 if (update_strings[0] == "fsckd") {
1003 number_devices = StringToInteger(update_strings[1]);
1004
1005 if (number_devices > 0) {
1006 label = update_strings[3];
1007
1008 progress_label = get_fsck_label (label, 0);
1009 progress_label.sprite = Sprite (progress_label.image);
1010 progress_label.sprite.SetPosition(progress_label.x, progress_label.y, 1);
1011 progress_label.sprite.SetOpacity (1);
1012 } else {
1013 if (progress_label.sprite)
1014 progress_label.sprite.SetOpacity (0);
1015 }
1016 }
1017
1018 }
1019 Plymouth.SetUpdateStatusFunction (update_status_callback);
1020
1021 #-----------------------------------------Display Question stuff -----------------------
1022 #
1023 # TODO: Implement this if needed
1024 #
1025 # The callback function is called when the display should display a question dialogue.
1026 # First arg is prompt string, the second is the entry contents.
1027 #fun display_question_callback (prompt_string, entry_contents)
1028 #{
1029 # time++;
1030 #}
1031 #
1032 #Plymouth.SetDisplayQuestionFunction (display_question_callback);
1033
1034 fun scale_glow_img(source_img, current_step, nb_steps) {
1035
1036 sin = Math.Sin(current_step*0.2)*0.2;
1037 glow_anim_scale = Math.Abs(sin) + 0.8;
1038
1039 scaled_image = source_img.Scale(logo_glow.GetWidth() * glow_anim_scale,
1040 logo_glow.GetHeight() * glow_anim_scale);
1041 return scaled_image;
1042 }
1043
1044 fun update_glow_anim () {
1045 # if (global.anim_start_time != global.progress_time && global.anim_status != "running") {
1046 # global.anim_start_time = global.progress_time;
1047 # global.anim_iter = 0;
1048 # global.anim_status = "running";
1049 # }
1050 #
1051 # if (global.anim_status == "running") {
1052 # iter_img = global.logo_glow[global.anim_iter];
1053 # if (iter_img == NULL) {
1054 # # Generate scaled image for the glow behind the logo on demand.
1055 # iter_img = scale_glow_img(logo_glow[0], global.anim_iter, NB_SCALE_STEPS);
1056 # global.logo_glow[global.anim_iter] = iter_img;
1057 # }
1058 # global.logo_glow_sprite.SetImage(iter_img);
1059 # global.logo_glow_sprite.SetX(logo_center.x - logo_glow_sprite.GetImage().GetWidth()/2);
1060 # global.logo_glow_sprite.SetY(logo_center.y - logo_glow_sprite.GetImage().GetHeight()/2);
1061
1062 op = global.logo_glow_sprite.GetOpacity();
1063 newOp = op + global.glow_step;
1064 if(newOp < global.glow_minOp)
1065 {
1066 global.glow_step = -global.glow_step;
1067 newOp = global.glow_minOp;
1068 }
1069 else if(newOp > global.glow_maxOp)
1070 {
1071 global.glow_step = -global.glow_step;
1072 newOp = global.glow_maxOp;
1073 }
1074 global.logo_glow_sprite.SetOpacity(newOp);
1075
1076 global.anim_iter++;
1077
1078 if (global.anim_iter >= NB_SCALE_STEPS) {
1079 global.anim_iter = 0;
1080 }
1081 # }
1082 }
1083
1084 fun update_star_anim (star_sprite, speed) {
1085 # if (global.anim_status == "running") {
1086
1087 x = star_sprite.GetX();
1088 newX = x - 30 * speed;
1089 if(newX < -star_sprite.GetImage().GetWidth())
1090 {
1091 # loop from the left to the right
1092 newX = Window.GetWidth() + star_sprite.GetImage().GetWidth();
1093 }
1094 star_sprite.SetX(newX);
1095
1096 op = star_sprite.GetOpacity();
1097 newOp = op + global.star_step * speed;
1098 if(newOp < global.star_minOp)
1099 {
1100 global.star_step = -global.star_step;
1101 newOp = global.star_minOp;
1102 }
1103 else if(newOp > global.star_maxOp)
1104 {
1105 global.star_step = -global.star_step;
1106 newOp = global.star_maxOp;
1107 }
1108
1109 star_sprite.SetOpacity(newOp);
1110
1111 # }
1112 }
1113
1114 #-----------------------------------------Refresh stuff --------------------------------
1115 #
1116 # Calling Plymouth.SetRefreshFunction with a function will set that function to be
1117 # called up to 50 times every second, e.g.
1118 #
1119 # NOTE: if a refresh function is not set, Plymouth doesn't seem to be able to update
1120 # the screen correctly
1121 #
1122 fun refresh_callback ()
1123 {
1124 global.refresh_iter++;
1125 if (global.refresh_iter == NB_REFRESHS_BETWEEN_ANIMS) {
1126 global.refresh_iter = 0;
1127 update_glow_anim();
1128 update_star_anim(global.star_sprite0, 1.0);
1129 update_star_anim(global.star_sprite1, 2.0);
1130 update_star_anim(global.star_sprite2, 1.5);
1131 update_star_anim(global.star_sprite3, 0.7);
1132 }
1133 #DebugBottom ("refresh_iter=" + refresh_iter + "; anim_status=" + anim_status + "; anim_start_time=" + anim_start_time + "; anim_iter=" + anim_iter);
1134 }
1135 Plymouth.SetRefreshFunction (refresh_callback);
1136
1137
1138 #-----------------------------------------Display Normal stuff -----------------------
1139 #
1140 # The callback function is called when the display should return to normal
1141 fun display_normal_callback ()
1142 {
1143 global.status = "normal";
1144 if (global.password_dialogue) {
1145 password_dialogue_opacity (0);
1146 global.password_dialogue = NULL;
1147 if (message_notification[2].sprite) hide_message(2);
1148 prompt_active = 0;
1149 }
1150
1151 if (message_notification[1].sprite) {
1152 show_message (1);
1153 }
1154
1155 }
1156
1157 Plymouth.SetDisplayNormalFunction (display_normal_callback);
1158
1159
1160 #----------------------------------------- Quit --------------------------------
1161
1162 fun quit_callback ()
1163 {
1164 }
1165
1166 Plymouth.SetQuitFunction(quit_callback);
1167
1168
1169