11 #include <linux/input.h>
15 #include <libtwin/twin.h>
16 #include <libtwin/twin_linux_mouse.h>
17 #include <libtwin/twin_png.h>
18 #include <libtwin/twin_jpeg.h>
20 #include "petitboot.h"
21 #include "petitboot-paths.h"
24 #include <libtwin/twin_x11.h>
25 static twin_x11_t *pboot_x11;
27 #include <libtwin/twin_fbdev.h>
28 static twin_fbdev_t *pboot_fbdev;
31 static twin_screen_t *pboot_screen;
33 #define PBOOT_INITIAL_MESSAGE \
34 "video hack: 0=default 1=720p 2=1080i 3=1080p"
36 #define PBOOT_LEFT_PANE_SIZE 160
37 #define PBOOT_LEFT_PANE_COLOR 0x80000000
38 #define PBOOT_LEFT_LINE_COLOR 0xff000000
40 #define PBOOT_LEFT_FOCUS_WIDTH 80
41 #define PBOOT_LEFT_FOCUS_HEIGHT 80
42 #define PBOOT_LEFT_FOCUS_XOFF 40
43 #define PBOOT_LEFT_FOCUS_YOFF 40
44 #define PBOOT_LEFT_FOCUS_XRAD (6 * TWIN_FIXED_ONE)
45 #define PBOOT_LEFT_FOCUS_YRAD (6 * TWIN_FIXED_ONE)
47 #define PBOOT_RIGHT_FOCUS_XOFF 20
48 #define PBOOT_RIGHT_FOCUS_YOFF 60
49 #define PBOOT_RIGHT_FOCUS_HEIGHT 80
50 #define PBOOT_RIGHT_FOCUS_XRAD (6 * TWIN_FIXED_ONE)
51 #define PBOOT_RIGHT_FOCUS_YRAD (6 * TWIN_FIXED_ONE)
53 #define PBOOT_LEFT_ICON_WIDTH 64
54 #define PBOOT_LEFT_ICON_HEIGHT 64
55 #define PBOOT_LEFT_ICON_XOFF 50
56 #define PBOOT_LEFT_ICON_YOFF 50
57 #define PBOOT_LEFT_ICON_STRIDE 100
59 #define PBOOT_RIGHT_OPTION_LMARGIN 30
60 #define PBOOT_RIGHT_OPTION_RMARGIN 30
61 #define PBOOT_RIGHT_OPTION_TMARGIN 70
62 #define PBOOT_RIGHT_OPTION_HEIGHT 64
63 #define PBOOT_RIGHT_OPTION_STRIDE 100
64 #define PBOOT_RIGHT_TITLE_TEXT_SIZE (30 * TWIN_FIXED_ONE)
65 #define PBOOT_RIGHT_SUBTITLE_TEXT_SIZE (18 * TWIN_FIXED_ONE)
66 #define PBOOT_RIGHT_TITLE_XOFFSET 80
67 #define PBOOT_RIGHT_TITLE_YOFFSET 30
68 #define PBOOT_RIGHT_SUBTITLE_XOFFSET 100
69 #define PBOOT_RIGHT_SUBTITLE_YOFFSET 50
70 #define PBOOT_RIGHT_BADGE_XOFFSET 2
71 #define PBOOT_RIGHT_BADGE_YOFFSET 0
74 #define PBOOT_RIGHT_TITLE_COLOR 0xff000000
75 #define PBOOT_RIGHT_SUBTITLE_COLOR 0xff400000
77 #define PBOOT_FOCUS_COLOR 0x10404040
79 #define PBOOT_STATUS_PANE_COLOR 0x60606060
80 #define PBOOT_STATUS_PANE_HEIGHT 20
81 #define PBOOT_STATUS_PANE_XYMARGIN 20
82 #define PBOOT_STATUS_TEXT_MARGIN 10
83 #define PBOOT_STATUS_TEXT_SIZE (16 * TWIN_FIXED_ONE)
84 #define PBOOT_STATUS_TEXT_COLOR 0xff000000
86 typedef struct _pboot_option pboot_option_t;
87 typedef struct _pboot_device pboot_device_t;
102 twin_pixmap_t *badge;
105 pboot_option_t options[PBOOT_MAX_OPTION];
108 static twin_pixmap_t *pboot_cursor;
109 static int pboot_cursor_hx;
110 static int pboot_cursor_hy;
112 static pboot_device_t *pboot_devices[PBOOT_MAX_DEV];
113 static int pboot_dev_count;
114 static int pboot_dev_sel = -1;
115 static int pboot_focus_lpane = 1;
117 typedef struct _pboot_lpane {
118 twin_window_t *window;
119 twin_rect_t focus_box;
126 typedef struct _pboot_rpane {
127 twin_window_t *window;
128 twin_rect_t focus_box;
135 typedef struct _pboot_spane {
136 twin_window_t *window;
140 static pboot_lpane_t *pboot_lpane;
141 static pboot_rpane_t *pboot_rpane;
142 static pboot_spane_t *pboot_spane;
144 static int pboot_vmode_change = -1;
146 /* XXX move to twin */
147 static inline twin_bool_t twin_rect_intersect(twin_rect_t r1,
150 return !(r1.left > r2.right ||
151 r1.right < r2.left ||
152 r1.top > r2.bottom ||
156 static void pboot_draw_option_cache(pboot_device_t *dev, pboot_option_t *opt,
164 px = twin_pixmap_create(TWIN_ARGB32, opt->box.right - opt->box.left,
165 opt->box.bottom - opt->box.top);
169 /* Fill background */
170 twin_fill(px, 0x00000000, TWIN_SOURCE, 0, 0, px->width, px->height);
172 /* Allocate a path for drawing */
173 path = twin_path_create();
177 /* TEST - Bounding rectangle */
178 twin_path_rectangle(path, 0, 0,
179 twin_int_to_fixed(px->width),
180 twin_int_to_fixed(px->height));
181 twin_paint_path(px, PBOOT_RIGHT_TITLE_COLOR, path);
182 twin_path_empty(path);
183 twin_fill(px, 0x00000000, TWIN_SOURCE, 2, 2,
184 px->width - 3, px->height - 3);
188 twin_path_set_font_size(path, PBOOT_RIGHT_TITLE_TEXT_SIZE);
189 twin_path_set_font_style(path, TWIN_TEXT_UNHINTED);
190 tx = twin_int_to_fixed(PBOOT_RIGHT_TITLE_XOFFSET);
191 ty = twin_int_to_fixed(PBOOT_RIGHT_TITLE_YOFFSET);
192 twin_path_move (path, tx, ty);
193 twin_path_utf8 (path, opt->title);
194 twin_paint_path (px, PBOOT_RIGHT_TITLE_COLOR, path);
195 twin_path_empty (path);
198 twin_path_set_font_size(path, PBOOT_RIGHT_SUBTITLE_TEXT_SIZE);
199 twin_path_set_font_style(path, TWIN_TEXT_UNHINTED);
200 tx = twin_int_to_fixed(PBOOT_RIGHT_SUBTITLE_XOFFSET);
201 ty = twin_int_to_fixed(PBOOT_RIGHT_SUBTITLE_YOFFSET);
202 twin_path_move (path, tx, ty);
203 twin_path_utf8 (path, opt->subtitle);
204 twin_paint_path (px, PBOOT_RIGHT_SUBTITLE_COLOR, path);
205 twin_path_empty (path);
211 src.source_kind = TWIN_PIXMAP;
212 src.u.pixmap = opt->badge;
214 twin_composite(px, PBOOT_RIGHT_BADGE_XOFFSET,
215 PBOOT_RIGHT_BADGE_YOFFSET,
216 &src, 0, 0, NULL, 0, 0, TWIN_OVER,
217 opt->badge->width, opt->badge->height);
222 twin_path_destroy(path);
225 static void pboot_rpane_draw(twin_window_t *window)
227 twin_pixmap_t *px = window->pixmap;
228 pboot_rpane_t *rpane = window->client_data;
231 twin_fixed_t x, y, w, h;
234 /* Fill background */
235 twin_fill(px, 0x00000000, TWIN_SOURCE, 0, 0, px->width, px->height);
237 /* Nothing to draw, return */
238 if (pboot_dev_sel < 0)
241 /* Create a path for use later */
242 path = twin_path_create();
246 if (rpane->focus_curindex >= 0 &&
247 twin_rect_intersect(rpane->focus_box, px->clip)) {
248 x = twin_int_to_fixed(rpane->focus_box.left + 2);
249 y = twin_int_to_fixed(rpane->focus_box.top + 2);
250 w = twin_int_to_fixed(rpane->focus_box.right -
251 rpane->focus_box.left - 4);
252 h = twin_int_to_fixed(rpane->focus_box.bottom -
253 rpane->focus_box.top - 4);
254 twin_path_rounded_rectangle(path, x, y, w, h,
255 PBOOT_RIGHT_FOCUS_XRAD,
256 PBOOT_RIGHT_FOCUS_YRAD);
257 if (!pboot_focus_lpane)
258 twin_paint_path(px, PBOOT_FOCUS_COLOR, path);
260 twin_paint_stroke(px, PBOOT_FOCUS_COLOR, path,
264 /* Get device and iterate through options */
265 dev = pboot_devices[pboot_dev_sel];
266 for (i = 0; i < dev->option_count; i++) {
267 pboot_option_t *opt = &dev->options[i];
270 if (opt->title == NULL)
272 if (!twin_rect_intersect(opt->box, px->clip))
274 if (opt->cache == NULL)
275 pboot_draw_option_cache(dev, opt, i);
277 src.source_kind = TWIN_PIXMAP;
278 src.u.pixmap = opt->cache;
280 twin_composite(px, opt->box.left, opt->box.top,
281 &src, 0, 0, NULL, 0, 0, TWIN_OVER,
282 opt->box.right - opt->box.left,
283 opt->box.bottom - opt->box.top);
287 twin_path_destroy(path);
290 static twin_time_t pboot_rfocus_timeout (twin_time_t now, void *closure)
292 int dir = 1, dist, pos;
293 const int accel[11] = { 7, 4, 2, 1, 1, 1, 1, 2, 3, 4, 5 };
295 dist = abs(pboot_rpane->focus_target - pboot_rpane->focus_start);
296 dir = dist > 5 ? 5 : dist;
297 pos = pboot_rpane->focus_target - (int)pboot_rpane->focus_box.top;
305 twin_window_damage(pboot_rpane->window,
306 pboot_rpane->focus_box.left,
307 pboot_rpane->focus_box.top,
308 pboot_rpane->focus_box.right,
309 pboot_rpane->focus_box.bottom);
311 pboot_rpane->focus_box.top += dir;
312 pboot_rpane->focus_box.bottom += dir;
314 twin_window_damage(pboot_rpane->window,
315 pboot_rpane->focus_box.left,
316 pboot_rpane->focus_box.top,
317 pboot_rpane->focus_box.right,
318 pboot_rpane->focus_box.bottom);
320 twin_window_queue_paint(pboot_rpane->window);
322 return accel[(pos * 10) / dist];
325 static void pboot_set_rfocus(int index)
329 if (pboot_dev_sel < 0 || pboot_dev_sel >= pboot_dev_count)
331 dev = pboot_devices[pboot_dev_sel];
332 if (index < 0 || index >= dev->option_count)
335 pboot_rpane->focus_start = pboot_rpane->focus_box.top;
336 pboot_rpane->focus_target = PBOOT_RIGHT_FOCUS_YOFF +
337 PBOOT_RIGHT_OPTION_STRIDE * index;
338 pboot_rpane->focus_curindex = index;
340 twin_set_timeout(pboot_rfocus_timeout, 0, NULL);
343 static void pboot_select_rpane(void)
345 if (pboot_focus_lpane == 0)
347 pboot_focus_lpane = 0;
349 twin_screen_set_active(pboot_screen, pboot_rpane->window->pixmap);
351 twin_window_damage(pboot_lpane->window,
352 pboot_lpane->focus_box.left,
353 pboot_lpane->focus_box.top,
354 pboot_lpane->focus_box.right,
355 pboot_lpane->focus_box.bottom);
357 twin_window_damage(pboot_rpane->window,
358 pboot_rpane->focus_box.left,
359 pboot_rpane->focus_box.top,
360 pboot_rpane->focus_box.right,
361 pboot_rpane->focus_box.bottom);
363 twin_window_queue_paint(pboot_lpane->window);
364 twin_window_queue_paint(pboot_rpane->window);
369 static void pboot_select_lpane(void)
371 if (pboot_focus_lpane == 1)
373 pboot_focus_lpane = 1;
375 twin_screen_set_active(pboot_screen, pboot_lpane->window->pixmap);
377 twin_window_damage(pboot_lpane->window,
378 pboot_lpane->focus_box.left,
379 pboot_lpane->focus_box.top,
380 pboot_lpane->focus_box.right,
381 pboot_lpane->focus_box.bottom);
383 twin_window_damage(pboot_rpane->window,
384 pboot_rpane->focus_box.left,
385 pboot_rpane->focus_box.top,
386 pboot_rpane->focus_box.right,
387 pboot_rpane->focus_box.bottom);
389 twin_window_queue_paint(pboot_lpane->window);
390 twin_window_queue_paint(pboot_rpane->window);
393 static void pboot_rpane_mousetrack(twin_coord_t x, twin_coord_t y)
399 if (pboot_dev_sel < 0 || pboot_dev_sel >= pboot_dev_count)
401 dev = pboot_devices[pboot_dev_sel];
403 if (y < PBOOT_RIGHT_OPTION_TMARGIN)
405 candidate = (y - PBOOT_RIGHT_OPTION_TMARGIN) /
406 PBOOT_RIGHT_OPTION_STRIDE;
407 if (candidate >= dev->option_count) {
411 if (candidate == pboot_rpane->mouse_target)
413 opt = &dev->options[candidate];
414 if (x < opt->box.left || x > opt->box.right ||
415 y < opt->box.top || y > opt->box.bottom) {
420 /* Ok, so now, we know the mouse hit an icon that wasn't the same
421 * as the previous one, we trigger a focus change
423 pboot_set_rfocus(candidate);
426 pboot_rpane->mouse_target = candidate;
429 static void pboot_choose_option(void)
431 pboot_device_t *dev = pboot_devices[pboot_dev_sel];
432 pboot_option_t *opt = &dev->options[pboot_rpane->focus_curindex];
434 LOG("Selected device %s\n", opt->title);
436 /* Give user feedback, make sure errors and panics will be seen */
437 pboot_exec_option(opt->data);
440 static twin_bool_t pboot_rpane_event (twin_window_t *window,
443 /* filter out all mouse events */
444 switch(event->kind) {
446 case TwinEventMotion:
448 pboot_select_rpane();
449 pboot_rpane_mousetrack(event->u.pointer.x, event->u.pointer.y);
451 case TwinEventButtonDown:
452 pboot_select_rpane();
453 pboot_rpane_mousetrack(event->u.pointer.x, event->u.pointer.y);
454 pboot_choose_option();
455 case TwinEventButtonUp:
457 case TwinEventKeyDown:
458 switch(event->u.key.key) {
460 pboot_set_rfocus(pboot_rpane->focus_curindex - 1);
463 pboot_set_rfocus(pboot_rpane->focus_curindex + 1);
466 pboot_select_lpane();
469 pboot_choose_option();
481 int pboot_add_option(int devindex, const char *title,
482 const char *subtitle, twin_pixmap_t *badge, void *data)
489 if (devindex < 0 || devindex >= pboot_dev_count)
491 dev = pboot_devices[devindex];
493 if (dev->option_count >= PBOOT_MAX_OPTION)
495 index = dev->option_count++;
496 opt = &dev->options[index];
498 opt->title = malloc(strlen(title) + 1);
499 strcpy(opt->title, title);
502 opt->subtitle = malloc(strlen(subtitle) + 1);
503 strcpy(opt->subtitle, subtitle);
505 opt->subtitle = NULL;
510 width = pboot_rpane->window->pixmap->width -
511 (PBOOT_RIGHT_OPTION_LMARGIN + PBOOT_RIGHT_OPTION_RMARGIN);
513 opt->box.left = PBOOT_RIGHT_OPTION_LMARGIN;
514 opt->box.right = opt->box.left + width;
515 opt->box.top = PBOOT_RIGHT_OPTION_TMARGIN +
516 index * PBOOT_RIGHT_OPTION_STRIDE;
517 opt->box.bottom = opt->box.top + PBOOT_RIGHT_OPTION_HEIGHT;
524 static void pboot_set_device_select(int sel)
526 LOG("%s: %d -> %d\n", __FUNCTION__, pboot_dev_sel, sel);
527 if (sel == pboot_dev_sel || sel >= pboot_dev_count)
530 pboot_rpane->focus_curindex = -1;
531 pboot_rpane->mouse_target = -1;
532 pboot_rpane->focus_box.top = -2*PBOOT_RIGHT_FOCUS_HEIGHT;
533 pboot_rpane->focus_box.bottom = pboot_rpane->focus_box.top +
534 PBOOT_RIGHT_FOCUS_HEIGHT;
535 twin_window_damage(pboot_rpane->window, 0, 0,
536 pboot_rpane->window->pixmap->width,
537 pboot_rpane->window->pixmap->height);
538 twin_window_queue_paint(pboot_rpane->window);
541 static void pboot_create_rpane(void)
543 pboot_rpane = calloc(1, sizeof(pboot_rpane_t));
546 pboot_rpane->window = twin_window_create(pboot_screen, TWIN_ARGB32,
548 PBOOT_LEFT_PANE_SIZE, 0,
549 pboot_screen->width -
550 PBOOT_LEFT_PANE_SIZE,
551 pboot_screen->height);
552 assert(pboot_rpane->window);
554 pboot_rpane->window->draw = pboot_rpane_draw;
555 pboot_rpane->window->event = pboot_rpane_event;
556 pboot_rpane->window->client_data = pboot_rpane;
558 pboot_rpane->focus_curindex = -1;
559 pboot_rpane->focus_box.left = PBOOT_RIGHT_FOCUS_XOFF;
560 pboot_rpane->focus_box.top = -2*PBOOT_RIGHT_FOCUS_HEIGHT;
561 pboot_rpane->focus_box.right = pboot_rpane->window->pixmap->width -
562 2 * PBOOT_RIGHT_FOCUS_XOFF;
563 pboot_rpane->focus_box.bottom = pboot_rpane->focus_box.top +
564 PBOOT_RIGHT_FOCUS_HEIGHT;
565 pboot_rpane->mouse_target = -1;
566 twin_window_show(pboot_rpane->window);
567 twin_window_queue_paint(pboot_rpane->window);
571 static twin_time_t pboot_lfocus_timeout (twin_time_t now, void *closure)
573 int dir = 1, dist, pos;
574 const int accel[11] = { 7, 4, 2, 1, 1, 1, 1, 2, 3, 4, 5 };
576 dist = abs(pboot_lpane->focus_target - pboot_lpane->focus_start);
577 pos = pboot_lpane->focus_target - (int)pboot_lpane->focus_box.top;
579 pboot_set_device_select(pboot_lpane->focus_curindex);
586 twin_window_damage(pboot_lpane->window,
587 pboot_lpane->focus_box.left,
588 pboot_lpane->focus_box.top,
589 pboot_lpane->focus_box.right,
590 pboot_lpane->focus_box.bottom);
592 pboot_lpane->focus_box.top += dir;
593 pboot_lpane->focus_box.bottom += dir;
595 twin_window_damage(pboot_lpane->window,
596 pboot_lpane->focus_box.left,
597 pboot_lpane->focus_box.top,
598 pboot_lpane->focus_box.right,
599 pboot_lpane->focus_box.bottom);
601 twin_window_queue_paint(pboot_lpane->window);
603 return accel[(pos * 10) / dist];
606 static void pboot_set_lfocus(int index)
608 if (index >= pboot_dev_count)
611 pboot_lpane->focus_start = pboot_lpane->focus_box.top;
614 pboot_lpane->focus_target = 0 - PBOOT_LEFT_FOCUS_HEIGHT;
616 pboot_lpane->focus_target = PBOOT_LEFT_FOCUS_YOFF +
617 PBOOT_LEFT_ICON_STRIDE * index;
619 pboot_lpane->focus_curindex = index;
621 twin_set_timeout(pboot_lfocus_timeout, 0, NULL);
624 static void pboot_lpane_mousetrack(twin_coord_t x, twin_coord_t y)
627 twin_coord_t icon_top;
629 if (x < PBOOT_LEFT_ICON_XOFF ||
630 x > (PBOOT_LEFT_ICON_XOFF + PBOOT_LEFT_ICON_WIDTH))
632 if (y < PBOOT_LEFT_ICON_YOFF)
634 candidate = (y - PBOOT_LEFT_ICON_YOFF) / PBOOT_LEFT_ICON_STRIDE;
635 if (candidate >= pboot_dev_count) {
639 if (candidate == pboot_lpane->mouse_target)
641 icon_top = PBOOT_LEFT_ICON_YOFF +
642 candidate * PBOOT_LEFT_ICON_STRIDE;
643 if (y > (icon_top + PBOOT_LEFT_ICON_HEIGHT)) {
648 /* Ok, so now, we know the mouse hit an icon that wasn't the same
649 * as the previous one, we trigger a focus change
651 pboot_set_lfocus(candidate);
654 pboot_lpane->mouse_target = candidate;
657 static twin_bool_t pboot_lpane_event (twin_window_t *window,
660 /* filter out all mouse events */
661 switch(event->kind) {
663 case TwinEventMotion:
665 pboot_select_lpane();
666 pboot_lpane_mousetrack(event->u.pointer.x, event->u.pointer.y);
668 case TwinEventButtonDown:
669 case TwinEventButtonUp:
671 case TwinEventKeyDown:
672 switch(event->u.key.key) {
674 if (pboot_lpane->focus_curindex > 0)
676 pboot_lpane->focus_curindex - 1);
679 pboot_set_lfocus(pboot_lpane->focus_curindex + 1);
682 pboot_select_rpane();
694 static void pboot_quit(void)
699 twin_bool_t pboot_event_filter(twin_screen_t *screen,
702 switch(event->kind) {
704 case TwinEventMotion:
706 case TwinEventButtonDown:
707 case TwinEventButtonUp:
708 if (pboot_cursor != NULL)
709 twin_screen_set_cursor(pboot_screen, pboot_cursor,
713 case TwinEventKeyDown:
714 /* Gross hack for video modes, need something better ! */
715 switch(event->u.key.key) {
717 pboot_vmode_change = 0; /* auto */
721 pboot_vmode_change = 3; /* 720p */
725 pboot_vmode_change = 4; /* 1080i */
729 pboot_vmode_change = 5; /* 1080p */
734 twin_screen_set_cursor(pboot_screen, NULL, 0, 0);
742 static void pboot_lpane_draw(twin_window_t *window)
744 twin_pixmap_t *px = window->pixmap;
745 pboot_lpane_t *lpane = window->client_data;
747 twin_fixed_t x, y, w, h;
750 /* Fill background */
751 twin_fill(px, PBOOT_LEFT_PANE_COLOR, TWIN_SOURCE,
752 0, 0, px->width, px->height);
754 /* Create a path for use later */
755 path = twin_path_create();
758 /* Draw right line if needed */
759 if (px->clip.right > (PBOOT_LEFT_PANE_SIZE - 4)) {
760 x = twin_int_to_fixed(PBOOT_LEFT_PANE_SIZE - 4);
761 y = twin_int_to_fixed(px->height);
762 twin_path_rectangle(path, x, 0, 0x40000, y);
763 twin_paint_path(px, PBOOT_LEFT_LINE_COLOR, path);
764 twin_path_empty(path);
768 if (lpane->focus_curindex >= 0 &&
769 twin_rect_intersect(lpane->focus_box, px->clip)) {
770 x = twin_int_to_fixed(lpane->focus_box.left + 2);
771 y = twin_int_to_fixed(lpane->focus_box.top + 2);
772 w = twin_int_to_fixed(lpane->focus_box.right -
773 lpane->focus_box.left - 4);
774 h = twin_int_to_fixed(lpane->focus_box.bottom -
775 lpane->focus_box.top - 4);
776 twin_path_rounded_rectangle(path, x, y, w, h,
777 PBOOT_LEFT_FOCUS_XRAD,
778 PBOOT_LEFT_FOCUS_YRAD);
779 if (pboot_focus_lpane)
780 twin_paint_path(px, PBOOT_FOCUS_COLOR, path);
782 twin_paint_stroke(px, PBOOT_FOCUS_COLOR, path,
787 for (i = 0; i < pboot_dev_count; i++) {
788 pboot_device_t *dev = pboot_devices[i];
791 if (!twin_rect_intersect(dev->box, px->clip))
794 src.source_kind = TWIN_PIXMAP;
795 src.u.pixmap = dev->badge;
797 twin_composite(px, dev->box.left, dev->box.top,
798 &src, 0, 0, NULL, 0, 0, TWIN_OVER,
799 dev->box.right - dev->box.left,
800 dev->box.bottom - dev->box.top);
805 twin_path_destroy(path);
808 static void pboot_create_lpane(void)
810 pboot_lpane = calloc(1, sizeof(pboot_lpane_t));
813 pboot_lpane->window = twin_window_create(pboot_screen, TWIN_ARGB32,
815 0, 0, PBOOT_LEFT_PANE_SIZE,
816 pboot_screen->height);
817 assert(pboot_lpane->window);
819 pboot_lpane->window->draw = pboot_lpane_draw;
820 pboot_lpane->window->event = pboot_lpane_event;
821 pboot_lpane->window->client_data = pboot_lpane;
822 pboot_lpane->focus_curindex = -1;
823 pboot_lpane->focus_box.left = PBOOT_LEFT_FOCUS_XOFF;
824 pboot_lpane->focus_box.top = -2*PBOOT_LEFT_FOCUS_HEIGHT;
825 pboot_lpane->focus_box.right = pboot_lpane->focus_box.left +
826 PBOOT_LEFT_FOCUS_WIDTH;
827 pboot_lpane->focus_box.bottom = pboot_lpane->focus_box.top +
828 PBOOT_LEFT_FOCUS_HEIGHT;
829 pboot_lpane->mouse_target = -1;
830 twin_window_show(pboot_lpane->window);
831 twin_window_queue_paint(pboot_lpane->window);
834 static void pboot_spane_draw(twin_window_t *window)
836 twin_pixmap_t *px = window->pixmap;
837 pboot_spane_t *spane = window->client_data;
841 /* Fill background */
842 twin_fill(px, PBOOT_STATUS_PANE_COLOR, TWIN_SOURCE,
843 0, 0, px->width, px->height);
845 path = twin_path_create();
848 twin_path_set_font_size(path, PBOOT_STATUS_TEXT_SIZE);
849 twin_path_set_font_style(path, TWIN_TEXT_UNHINTED);
850 tx = twin_int_to_fixed(PBOOT_STATUS_TEXT_MARGIN);
851 ty = twin_int_to_fixed(PBOOT_STATUS_PANE_HEIGHT - 2);
852 twin_path_move (path, tx, ty);
853 twin_path_utf8 (path, spane->text);
854 twin_paint_path (px, PBOOT_STATUS_TEXT_COLOR, path);
856 twin_path_destroy(path);
859 void pboot_message(const char *message)
861 if (pboot_spane->text)
862 free(pboot_spane->text);
863 pboot_spane->text = strdup(message);
864 twin_window_damage(pboot_spane->window,
866 pboot_spane->window->pixmap->width,
867 pboot_spane->window->pixmap->height);
868 twin_window_queue_paint(pboot_spane->window);
871 static void pboot_create_spane(void)
873 pboot_spane = calloc(1, sizeof(pboot_spane_t));
876 pboot_spane->window = twin_window_create(pboot_screen, TWIN_ARGB32,
878 PBOOT_LEFT_PANE_SIZE +
879 PBOOT_STATUS_PANE_XYMARGIN,
880 pboot_screen->height -
881 PBOOT_STATUS_PANE_HEIGHT,
882 pboot_screen->width -
883 PBOOT_LEFT_PANE_SIZE -
884 2*PBOOT_STATUS_PANE_XYMARGIN,
885 PBOOT_STATUS_PANE_HEIGHT);
886 assert(pboot_spane->window);
888 pboot_spane->window->draw = pboot_spane_draw;
889 pboot_spane->window->client_data = pboot_spane;
890 pboot_spane->text = strdup(PBOOT_INITIAL_MESSAGE);
891 twin_window_show(pboot_spane->window);
892 twin_window_queue_paint(pboot_spane->window);
895 int pboot_add_device(const char *dev_id, const char *name,
896 twin_pixmap_t *pixmap)
901 if (pboot_dev_count >= PBOOT_MAX_DEV)
904 index = pboot_dev_count++;
906 dev = malloc(sizeof(*dev));
907 memset(dev, 0, sizeof(*dev));
908 dev->id = malloc(strlen(dev_id) + 1);
909 strcpy(dev->id, dev_id);
911 dev->box.left = PBOOT_LEFT_ICON_XOFF;
912 dev->box.right = dev->box.left + PBOOT_LEFT_ICON_WIDTH;
913 dev->box.top = PBOOT_LEFT_ICON_YOFF +
914 PBOOT_LEFT_ICON_STRIDE * index;
915 dev->box.bottom = dev->box.top + PBOOT_LEFT_ICON_HEIGHT;
917 pboot_devices[index] = dev;
919 twin_window_damage(pboot_lpane->window,
920 dev->box.left, dev->box.top,
921 dev->box.right, dev->box.bottom);
922 twin_window_queue_paint(pboot_lpane->window);
927 int pboot_remove_device(const char *dev_id)
929 int i, new_dev_index;
930 pboot_device_t *dev = NULL;
932 /* find the matching device */
933 for (i = 0; i < pboot_dev_count; i++) {
934 if (!strcmp(pboot_devices[i]->id, dev_id)) {
935 dev = pboot_devices[i];
943 /* select the newly-focussed device */
944 if (i == pboot_dev_count - 1)
945 new_dev_index = i - 1;
947 new_dev_index = i + 1;
949 memmove(pboot_devices + i, pboot_devices + i + 1,
950 sizeof(*pboot_devices) * (pboot_dev_count + i - 1));
952 pboot_devices[--pboot_dev_count] = NULL;
954 pboot_set_device_select(new_dev_index);
955 twin_window_damage(pboot_lpane->window,
956 dev->box.left, dev->box.top,
957 dev->box.right, dev->box.bottom);
958 twin_window_queue_paint(pboot_lpane->window);
960 /* todo: free device & options */
965 static void pboot_make_background(void)
967 twin_pixmap_t *filepic, *scaledpic;
968 const char *background_path;
970 /* Set background pixmap */
971 LOG("loading background...");
972 background_path = artwork_pathname("background.jpg");
973 filepic = twin_jpeg_to_pixmap(background_path, TWIN_ARGB32);
974 LOG("%s\n", filepic ? "ok" : "failed");
979 if (pboot_screen->height == filepic->height &&
980 pboot_screen->width == filepic->width)
984 twin_operand_t srcop;
986 scaledpic = twin_pixmap_create(TWIN_ARGB32,
988 pboot_screen->height);
989 if (scaledpic == NULL) {
990 twin_pixmap_destroy(filepic);
993 sx = twin_fixed_div(twin_int_to_fixed(filepic->width),
994 twin_int_to_fixed(pboot_screen->width));
995 sy = twin_fixed_div(twin_int_to_fixed(filepic->height),
996 twin_int_to_fixed(pboot_screen->height));
998 twin_matrix_scale(&filepic->transform, sx, sy);
999 srcop.source_kind = TWIN_PIXMAP;
1000 srcop.u.pixmap = filepic;
1001 twin_composite(scaledpic, 0, 0, &srcop, 0, 0,
1002 NULL, 0, 0, TWIN_SOURCE,
1003 pboot_screen->width, pboot_screen->height);
1004 twin_pixmap_destroy(filepic);
1007 twin_screen_set_background(pboot_screen, scaledpic);
1010 #define PS3FB_IOCTL_SETMODE _IOW('r', 1, int)
1011 #define PS3FB_IOCTL_GETMODE _IOR('r', 2, int)
1013 static void exitfunc(void)
1017 twin_fbdev_destroy(pboot_fbdev);
1019 if (pboot_vmode_change != -1) {
1020 int fd = open("/dev/fb0", O_RDWR);
1022 ioctl(fd, PS3FB_IOCTL_SETMODE,
1023 (unsigned long)&pboot_vmode_change);
1029 static void sigint(int sig)
1035 static void usage(const char *progname)
1037 fprintf(stderr, "Usage: %s [-u] [-h]\n", progname);
1040 int main(int argc, char **argv)
1043 int udev_trigger = 0;
1046 c = getopt(argc, argv, "u::h");
1056 return EXIT_SUCCESS;
1058 fprintf(stderr, "Unknown option '%c'\n", c);
1060 return EXIT_FAILURE;
1065 signal(SIGINT, sigint);
1068 pboot_x11 = twin_x11_create(XOpenDisplay(0), 1024, 768);
1069 if (pboot_x11 == NULL) {
1070 perror("failed to create x11 screen !\n");
1073 pboot_screen = pboot_x11->screen;
1075 /* Create screen and mouse drivers */
1076 pboot_fbdev = twin_fbdev_create(-1, SIGUSR1);
1077 if (pboot_fbdev == NULL) {
1078 perror("failed to create fbdev screen !\n");
1081 pboot_screen = pboot_fbdev->screen;
1082 twin_linux_mouse_create(NULL, pboot_screen);
1084 if (pboot_fbdev != NULL) {
1085 char *cursor_path = artwork_pathname("cursor");
1086 pboot_cursor = twin_load_X_cursor(cursor_path, 2,
1089 if (pboot_cursor == NULL)
1091 twin_get_default_cursor(&pboot_cursor_hx,
1096 /* Set background pixmap */
1097 pboot_make_background();
1099 /* Init more stuffs */
1100 pboot_create_lpane();
1101 pboot_create_rpane();
1102 pboot_create_spane();
1104 if (!pboot_start_device_discovery(udev_trigger)) {
1105 LOG("Couldn't start device discovery!\n");
1109 pboot_set_lfocus(0);
1110 twin_screen_set_active(pboot_screen, pboot_lpane->window->pixmap);
1111 pboot_screen->event_filter = pboot_event_filter;
1113 /* Console switch */
1116 twin_fbdev_activate(pboot_fbdev);
1119 /* Process events */