1 #include "desktop/render.h"
2 #include "desktop/widget_button.h"
3 #include "desktop/widget_label.h"
4 #include "io/serial_port.h"
5 #include "lib/stdlib.h"
7 #include "drv/input/keyboard.h"
10 #include "lib/sprintf.h"
11 #include "desktop/widget_image.h"
12 #include "sys/scheduler.h"
13 #include "desktop/widget_progress.h"
14 #include "sys/timer.h"
20 char time_for_label[] =
"--:--:--";
21 char label_for_memory[32] = {0};
22 char label_for_fps[8] = {0};
24 void make_time_string(
char* out) {
27 uint8_t h = time.hours;
28 uint8_t m = time.minutes;
29 uint8_t s = time.seconds;
31 sprintf(out,
"%02d:%02d:%02d", h, m, s);
34 void shutdown_system_activity_real() {
35 Window_t* progwin = window_new(
"Shutting down...");
41 progwin->height = 160;
43 Widget_t* progress = new_widget_progress();
48 progress->width = 400;
49 progress->height = 30;
53 window_add_widget(progwin, progress);
55 Widget_t* lab = new_widget_label(
"Getting ready to shutdown...", 10, 70, 0x00ffff);
57 window_add_widget(progwin, lab);
59 progwin->state = DISPLAYING;
61 size_t tst = timestamp();
69 if(timestamp() - tst > 11000) {
71 }
else if(timestamp() - tst > 9000) {
73 ((
Widget_Label_t*)lab->custom_widget_data)->label =
"Destroying FS objects...";
74 }
else if(timestamp() - tst > 5000) {
76 ((
Widget_Label_t*)lab->custom_widget_data)->label =
"Synchronizing data to disks...";
77 }
else if(timestamp() - tst > 3500) {
79 ((
Widget_Label_t*)lab->custom_widget_data)->label =
"Flushing logs...";
80 }
else if(timestamp() - tst > 2500) {
82 ((
Widget_Label_t*)lab->custom_widget_data)->label =
"Notifying services...";
83 }
else if(timestamp() - tst > 1000) {
85 ((
Widget_Label_t*)lab->custom_widget_data)->label =
"Destroying FS objects...";
92 void shutdown_system_activity() {
95 shutdown_system_activity_real,
102 void parallel_desktop_start() {
105 qemu_log(
"Reached init...");
106 set_cursor_enabled(
false);
107 keyboardctl(KEYBOARD_ECHO,
false);
109 log_window_manager_state();
113 Window_t* root_window = window_new(0);
116 root_window->width = getScreenWidth();
117 root_window->height = getScreenHeight();
118 root_window->with_title_bar =
false;
119 root_window->closable =
false;
120 root_window->canvas_bgcolor = 0x404040;
122 qemu_log(
"Root window! at %x", root_window);
124 Widget_t* wallpaper = new_widget_image(
"R:\\Sayori\\bg.tga");
125 window_add_widget(root_window, wallpaper);
127 qemu_log(
"Wallpaper for it...");
131 Window_t* taskbar = window_new(
"taskbar");
133 taskbar->height = 30;
134 taskbar->y = getScreenHeight() - taskbar->height;
135 taskbar->width = getScreenWidth();
137 taskbar->with_title_bar =
false;
138 taskbar->closable =
false;
139 taskbar->canvas_bgcolor = 0x777777;
144 qemu_log(
"Creating time label");
146 Widget_t* time_label = new_widget_label(time_for_label,
147 taskbar->width - 8 * 8 - 8,
148 (taskbar->height - 16) / 2,
152 Widget_t* memory_label = new_widget_label(label_for_memory,
153 taskbar->width - 8 *
strlen(label_for_memory) - 256,
154 (taskbar->height - 16) / 2,
158 uint8_t seconds_old =
get_time().seconds;
160 Widget_t* fps_label = new_widget_label(label_for_fps,
162 (taskbar->height - 16) / 2,
168 window_add_widget(taskbar, time_label);
169 window_add_widget(taskbar, memory_label);
170 window_add_widget(taskbar, fps_label);
174 qemu_log(
"Creating test window");
176 Window_t* window = window_new(
"Untitled");
180 window->height = 300;
184 qemu_log(
"Untitled window");
186 Widget_t* hello_button = new_widget_button(
"Create test window", 0x00ff00, 0x000000);
187 hello_button->x = 50;
188 hello_button->y = 50;
189 hello_button->width += 20;
190 hello_button->height += 15;
191 hello_button->on_click = eki_start;
193 qemu_log(
"Button for it...");
195 window_add_widget(window, hello_button);
197 Widget_t* sh_btn = new_widget_button(
"Shutdown system", 0xff0000, 0x000000);
201 sh_btn->height += 15;
202 sh_btn->on_click = shutdown_system_activity;
204 qemu_log(
"Button for it...");
206 window_add_widget(window, sh_btn);
208 root_window->state = DISPLAYING;
209 taskbar->state = DISPLAYING;
210 window->state = DISPLAYING;
212 qemu_log(
"Start...");
215 if(getCharRaw() == 129) {
220 make_time_string(time_for_label);
223 sprintf(label_for_memory,
"%d kB used", system_heap.used_memory / 1024);
226 if(
get_time().seconds != seconds_old) {
227 sprintf(label_for_fps,
"%d FPS", frames);
234 qemu_log(
"Loop exit");
236 window_destroy(window);
237 qemu_log(
"Destroyed window");
238 window_destroy(taskbar);
239 qemu_log(
"Destroyed taskbar");
240 window_destroy(root_window);
241 qemu_log(
"Destroyed root_window");
243 set_cursor_enabled(
true);
245 qemu_log(
"Exit successfully!!!");
249 tty_printf(
"Memory allocation info written to COM1 (debug) port!!!");
250 log_window_manager_state();
252 keyboardctl(KEYBOARD_ECHO,
true);
sayori_time_t get_time()
Считывает время и передает в удобной структуре
size_t strlen(const char *str)
Возращает длину строки
volatile process_t * get_current_proc(void)
Получить текущий обработчик процесса
void shutdown()
Выключение устройства