-
Notifications
You must be signed in to change notification settings - Fork 26
feat: Implement system power management with Ctrl+Alt+Del and Ctrl+Alt+Esc #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,16 +262,21 @@ FS_RESULT FAT32FS::open_file(const char* path, file* descriptor){ | |
| if (!buf) return FS_RESULT_NOTFOUND; | ||
| descriptor->id = reserve_fd_id(); | ||
| descriptor->size = buf_ptr.size; | ||
| open_files.add(reserve_fd_id(), buf); | ||
| open_files.add(descriptor->id, buf); | ||
| //TODO: go back to using a linked list, and a static id for the file, ideally global for system | ||
| return FS_RESULT_SUCCESS; | ||
| } | ||
|
|
||
| size_t FAT32FS::read_file(file *descriptor, void* buf, size_t size){ | ||
| void* file = open_files[descriptor->id]; | ||
| //TODO: keep track of file size and limit copy to only that or less | ||
| memcpy(buf, file, size); | ||
| return size; | ||
| if (!file) { | ||
| kprintf("[FAT32] File not found in open_files for id %x", descriptor->id); | ||
| return 0; | ||
| } | ||
| // Limit to actual file size | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the improvement, but please keep the original TODO comment. We're not guaranteed that descriptor->size is the correct size, since it can be modified externally
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code itself is fine, it's just about remembering to properly implement this later on
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I will return to this section. |
||
| size_t read_size = size > descriptor->size ? descriptor->size : size; | ||
| memcpy(buf, file, read_size); | ||
| return read_size; | ||
| } | ||
|
|
||
| sizedptr FAT32FS::list_entries_handler(FAT32FS *instance, f32file_entry *entry, char *filename, const char *seek) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,17 +9,66 @@ | |
| #include "math/math.h" | ||
| #include "std/string.h" | ||
| #include "syscalls/syscalls.h" | ||
| #include "process/syscall.h" // For SYS_POWEROFF | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments (in the whole PR) are largely unnecessary. The code is self explanatory
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll keep that comment in mind. |
||
| #include "power.h" // For power_off() | ||
|
|
||
|
|
||
|
|
||
| // Check if the keypress contains the Ctrl+Alt+Del combination | ||
| bool is_ctrl_alt_del(keypress *kp) { | ||
| // Check for any CTRL modifier (left or right) | ||
| bool has_ctrl = (kp->modifier & (KEY_MOD_LCTRL | KEY_MOD_RCTRL)) != 0; | ||
| // Check for any ALT modifier (left or right) | ||
| bool has_alt = (kp->modifier & (KEY_MOD_LALT | KEY_MOD_RALT)) != 0; | ||
|
|
||
| if (!has_ctrl || !has_alt) { | ||
| return false; | ||
| } | ||
|
|
||
| // Check for Delete key in any of the key slots | ||
| for (int i = 0; i < 6; i++) { | ||
| if (kp->keys[i] == KEY_DELETE) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| // Check if the keypress contains the Ctrl+Alt+ESC combination | ||
| bool is_ctrl_alt_esc(keypress *kp) { | ||
| // Check for any CTRL modifier (left or right) | ||
| bool has_ctrl = (kp->modifier & (KEY_MOD_LCTRL | KEY_MOD_RCTRL)) != 0; | ||
| // Check for any ALT modifier (left or right) | ||
| bool has_alt = (kp->modifier & (KEY_MOD_LALT | KEY_MOD_RALT)) != 0; | ||
|
|
||
| if (!has_ctrl || !has_alt) { | ||
| return false; | ||
| } | ||
|
|
||
| // Check for ESC key in any of the key slots | ||
| for (int i = 0; i < 6; i++) { | ||
| if (kp->keys[i] == KEY_ESC) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| int login_screen(){ | ||
| sys_focus_current(); | ||
| sys_set_secure(true); | ||
| char* buf = (char*)malloc(256); | ||
| int len = 0; | ||
| keypress old_kp; | ||
| bool ctrl_alt_del_pressed = false; | ||
| bool ctrl_alt_esc_pressed = false; | ||
| const char* name = BOOTSCREEN_TEXT; | ||
| string title = string_l(name); | ||
| string subtitle = string_l("Login"); | ||
| gpu_clear(BG_COLOR); | ||
| // Shutdown hint position | ||
| int button_padding = 10; | ||
|
|
||
| while (1) | ||
| { | ||
| gpu_size screen_size = gpu_get_screen_size(); | ||
|
|
@@ -31,13 +80,50 @@ int login_screen(){ | |
| int yo = screen_middle.y; | ||
| int height = char_size * 2; | ||
|
|
||
| // Draw title and subtitle | ||
| gpu_draw_string(title, (gpu_point){screen_middle.x - ((title.length/2) * char_size), yo - char_size*9}, scale, 0xFFFFFFFF); | ||
| gpu_draw_string(subtitle, (gpu_point){screen_middle.x - ((subtitle.length/2) * char_size), yo - char_size*6}, scale, 0xFFFFFFFF); | ||
|
|
||
| // Draw password input field | ||
| gpu_fill_rect((gpu_rect){{xo,yo - char_size/2}, {screen_size.width / 3, height}},BG_COLOR+0x111111); | ||
| gpu_draw_string(s, (gpu_point){xo, yo}, scale, 0xFFFFFFFF); | ||
|
|
||
| // Draw shutdown hint | ||
| string shutdown_hint = string_l("Press Ctrl+Alt+Del to shutdown"); | ||
| gpu_draw_string(shutdown_hint, | ||
| (gpu_point){screen_size.width - (shutdown_hint.length * char_size) - button_padding, | ||
| screen_size.height - char_size - button_padding}, | ||
| 1, 0x888888); // Gray text | ||
|
|
||
| keypress kp; | ||
| if (sys_read_input_current(&kp)){ | ||
|
|
||
| // Check for Ctrl+Alt+Del to shutdown | ||
| if (is_ctrl_alt_del(&kp)) { | ||
| if (!ctrl_alt_del_pressed) { | ||
| ctrl_alt_del_pressed = true; | ||
| kprintf("\nShutting down system...\n"); | ||
| power_off(); | ||
| // If power_off() returns (which it shouldn't), just continue | ||
| continue; | ||
| } | ||
| } else { | ||
| ctrl_alt_del_pressed = false; | ||
| } | ||
|
|
||
| // Check for Ctrl+Alt+ESC to reboot | ||
| if (is_ctrl_alt_esc(&kp)) { | ||
| if (!ctrl_alt_esc_pressed) { | ||
| ctrl_alt_esc_pressed = true; | ||
| kprintf("\nRebooting system...\n"); | ||
| reboot(); | ||
| // If reboot() returns (which it shouldn't), just continue | ||
| continue; | ||
| } | ||
| } else { | ||
| ctrl_alt_esc_pressed = false; | ||
| } | ||
|
|
||
| for (int i = 0; i < 6; i++){ | ||
| char key = kp.keys[i]; | ||
| if (hid_keycode_to_char[(uint8_t)key]){ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,17 +121,19 @@ void Desktop::activate_current(){ | |
| kprintf("[LAUNCHER] Wrong executable format. Must be .elf"); | ||
| return; | ||
| } | ||
| kprintf("[LAUNCHER] File path %s",(uintptr_t)entries[index].path); | ||
| file fd; | ||
| open_file(entries[index].path, &fd); | ||
| char *file = (char*)malloc(fd.size); | ||
| if (read_file(&fd, file, fd.size) != fd.size){ | ||
| kprintf("[LAUNCHER] Failed to read full elf file"); | ||
| return; | ||
| } | ||
| active_proc = load_elf_file(entries[index].name, file); | ||
| char *file_data = (char*)malloc(fd.size); | ||
| size_t bytes_read = read_file(&fd, file_data, fd.size); | ||
| if (bytes_read != fd.size){ | ||
| free(file_data, fd.size); | ||
|
|
||
| return; // Skip if read failed | ||
| } else { | ||
| active_proc = load_elf_file(entries[index].name, file_data); | ||
| } | ||
|
|
||
| if (!active_proc){ | ||
| kprintf("[LAUNCHER] Failed to read ELF file"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the error messages shown here, since they're the only indication of what went wrong
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
| return; | ||
| } | ||
| process_active = true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These paths should not be hardcoded. Check your $PATH to ensure you have them there, as this will break for other users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My development operating system is OpenSUSE TW and that's why I use it that way, but I'll migrate to Manjaro in a few days. After that, I shouldn't have the problem anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to switch distros to make this work, just need to add
/usr/sbinto your path like:for when doing development, or put that in your
~/.bashrcor equivalent to make it happen automatically. You could probably also just symlink/usr/sbin/mkfs.fatinto a directory that is in yourPATHif you didn't want to accidentally be able to run other stuff from/usr/sbin, though it shouldn't matter since you'd need to be root to do anything dangerous anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @codebrainz.
I known this issue regarding mkfs.fat, but i have other issue with QEMU and SDL options in OpenSUSE TW.
That's why I would like to change to Manjaro.