SayoriOS 0.3.3

parallel_desktop.c
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"
6 #include "drv/cmos.h"
7 #include "drv/input/keyboard.h"
8 #include "io/ports.h"
9 #include "mem/vmm.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"
15
16 extern Window_t* focused;
17
18 void eki_start();
19
20 char time_for_label[] = "--:--:--";
21 char label_for_memory[32] = {0};
22 char label_for_fps[8] = {0};
23
24 void make_time_string(char* out) {
25 sayori_time_t time = get_time();
26
27 uint8_t h = time.hours;
28 uint8_t m = time.minutes;
29 uint8_t s = time.seconds;
30
31 sprintf(out, "%02d:%02d:%02d", h, m, s);
32 }
33
34 void shutdown_system_activity_real() {
35 Window_t* progwin = window_new("Shutting down...");
36
37 progwin->x = 20;
38 progwin->y = 20;
39
40 progwin->width = 500;
41 progwin->height = 160;
42
43 Widget_t* progress = new_widget_progress();
44
45 progress->x = 10;
46 progress->y = 10;
47
48 progress->width = 400;
49 progress->height = 30;
50
51 ((Widget_Progress_t*)progress->custom_widget_data)->current = 0;
52
53 window_add_widget(progwin, progress);
54
55 Widget_t* lab = new_widget_label("Getting ready to shutdown...", 10, 70, 0x00ffff);
56
57 window_add_widget(progwin, lab);
58
59 progwin->state = DISPLAYING;
60
61 size_t tst = timestamp();
62
63 while(1) {
64 // if(timestamp() - tst > 100) {
65 // tst = timestamp();
66 //
67 // ((Widget_Progress_t*)progress->custom_widget_data)->current++;
68 // }
69 if(timestamp() - tst > 11000) {
70 break;
71 } else if(timestamp() - tst > 9000) {
72 ((Widget_Progress_t *) progress->custom_widget_data)->current = 90;
73 ((Widget_Label_t*)lab->custom_widget_data)->label = "Destroying FS objects...";
74 } else if(timestamp() - tst > 5000) {
75 ((Widget_Progress_t*)progress->custom_widget_data)->current = 50;
76 ((Widget_Label_t*)lab->custom_widget_data)->label = "Synchronizing data to disks...";
77 } else if(timestamp() - tst > 3500) {
78 ((Widget_Progress_t*)progress->custom_widget_data)->current = 40;
79 ((Widget_Label_t*)lab->custom_widget_data)->label = "Flushing logs...";
80 } else if(timestamp() - tst > 2500) {
81 ((Widget_Progress_t*)progress->custom_widget_data)->current = 20;
82 ((Widget_Label_t*)lab->custom_widget_data)->label = "Notifying services...";
83 } else if(timestamp() - tst > 1000) {
84 ((Widget_Progress_t*)progress->custom_widget_data)->current = 10;
85 ((Widget_Label_t*)lab->custom_widget_data)->label = "Destroying FS objects...";
86 }
87 }
88
89 shutdown();
90 }
91
92 void shutdown_system_activity() {
93 thread_create(
94 get_current_proc(),
95 shutdown_system_activity_real,
96 512,
97 true,
98 false
99 );
100 }
101
102 void parallel_desktop_start() {
103 size_t frames = 0;
104
105 qemu_log("Reached init...");
106 set_cursor_enabled(false);
107 keyboardctl(KEYBOARD_ECHO, false);
108
109 log_window_manager_state();
110
111 // ROOT WINDOW
112
113 Window_t* root_window = window_new(0);
114 root_window->x = 0;
115 root_window->y = 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;
121
122 qemu_log("Root window! at %x", root_window);
123
124 Widget_t* wallpaper = new_widget_image("R:\\Sayori\\bg.tga");
125 window_add_widget(root_window, wallpaper);
126
127 qemu_log("Wallpaper for it...");
128
129 // TASKBAR
130
131 Window_t* taskbar = window_new("taskbar");
132 taskbar->x = 0;
133 taskbar->height = 30;
134 taskbar->y = getScreenHeight() - taskbar->height;
135 taskbar->width = getScreenWidth();
136
137 taskbar->with_title_bar = false;
138 taskbar->closable = false;
139 taskbar->canvas_bgcolor = 0x777777;
140
141
142 // TASKBAR: TIME
143
144 qemu_log("Creating time label");
145
146 Widget_t* time_label = new_widget_label(time_for_label,
147 taskbar->width - 8 * 8 - 8,
148 (taskbar->height - 16) / 2,
149 0x000000
150 );
151
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,
155 0x000000
156 );
157
158 uint8_t seconds_old = get_time().seconds;
159
160 Widget_t* fps_label = new_widget_label(label_for_fps,
161 32,
162 (taskbar->height - 16) / 2,
163 0x000000
164 );
165
166 // // ((Widget_Label_t*)(widget->custom_widget_data))->color = 0x404040;
167
168 window_add_widget(taskbar, time_label);
169 window_add_widget(taskbar, memory_label);
170 window_add_widget(taskbar, fps_label);
171
172 // TEST WINDOW
173
174 qemu_log("Creating test window");
175
176 Window_t* window = window_new("Untitled");
177 window->x = 100;
178 window->y = 100;
179 window->width = 300;
180 window->height = 300;
181
182 focused = window;
183
184 qemu_log("Untitled window");
185
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;
192
193 qemu_log("Button for it...");
194
195 window_add_widget(window, hello_button);
196
197 Widget_t* sh_btn = new_widget_button("Shutdown system", 0xff0000, 0x000000);
198 sh_btn->x = 50;
199 sh_btn->y = 80;
200 sh_btn->width += 20;
201 sh_btn->height += 15;
202 sh_btn->on_click = shutdown_system_activity;
203
204 qemu_log("Button for it...");
205
206 window_add_widget(window, sh_btn);
207
208 root_window->state = DISPLAYING;
209 taskbar->state = DISPLAYING;
210 window->state = DISPLAYING;
211
212 qemu_log("Start...");
213
214 for(;;) {
215 if(getCharRaw() == 129) {
216 gui_restore();
217 break;
218 }
219
220 make_time_string(time_for_label);
221 gui_render();
222
223 sprintf(label_for_memory, "%d kB used", system_heap.used_memory / 1024);
224
225 frames++;
226 if(get_time().seconds != seconds_old) {
227 sprintf(label_for_fps, "%d FPS", frames);
228
229 frames = 0;
230 seconds_old = get_time().seconds;
231 }
232 }
233
234 qemu_log("Loop exit");
235
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");
242
243 set_cursor_enabled(true);
244
245 qemu_log("Exit successfully!!!");
246
247 clean_tty_screen();
248
249 tty_printf("Memory allocation info written to COM1 (debug) port!!!");
250 log_window_manager_state();
251
252 keyboardctl(KEYBOARD_ECHO, true);
253 }
get_time
sayori_time_t get_time()
Считывает время и передает в удобной структуре
Definition: cmos.c:144
strlen
size_t strlen(const char *str)
Возращает длину строки
Definition: string.c:88
get_current_proc
volatile process_t * get_current_proc(void)
Получить текущий обработчик процесса
Definition: scheduler.c:125
Widget_Label
Definition: widget_label.h:8
Widget_Progress
Definition: widget_progress.h:7
Widget
Definition: widget.h:12
Window
Definition: window.h:25
sayori_time
Definition: cmos.h:5
shutdown
void shutdown()
Выключение устройства
Definition: system.c:64