Skip to content

Commit

Permalink
Add shortcut to spawn file explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
hgruniaux committed May 23, 2024
1 parent 77016d8 commit a1faa03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 9 additions & 3 deletions binuser/explorer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#define INDENT 20
#define TITLE_BAR_HEIGHT 30
#define PADDING 20

static sys_window_t* window = NULL;

Expand Down Expand Up @@ -64,8 +65,8 @@ static void draw_dir(sys_window_t* window, const char* path) {

static void draw(sys_window_t* window) {
current_idx = 0;
current_x = 20;
current_y = TITLE_BAR_HEIGHT + 20;
current_x = PADDING + 10;
current_y = TITLE_BAR_HEIGHT + PADDING;
draw_dir(window, "/");
sys_window_present(window);
}
Expand All @@ -86,7 +87,12 @@ static void handle_key_event(sys_key_event_t event) {
draw(window);
break;
case SYS_KEY_ENTER:
sys_spawn(current_path);
if (current_is_file) {
if (!SYS_IS_OK(sys_spawn(current_path)))
sys_print("Failed to spawn the selected item (probably not an ELF program)");
} else {
sys_print("The current selected item is not a file");
}
break;
default:
break;
Expand Down
13 changes: 13 additions & 0 deletions kernel/wm/window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "hardware/framebuffer.hpp"
#include "hardware/timer.hpp"
#include "libk/log.hpp"
#include "task/task_manager.hpp"
#include "wm/window.hpp"

#include <algorithm>
Expand Down Expand Up @@ -547,6 +548,7 @@ bool WindowManager::handle_key_event(sys_key_event_t event) {
if (m_focus_window != nullptr)
set_window_geometry(m_focus_window, Rect::from_pos_and_size(0, 0, m_screen_width, m_screen_height));
return true;
// SYS_KEY_A instead of SYS_KEY_Q because of AZERTY <-> QWERTY layouts
case SYS_KEY_A: // Alt+Q -> close window
if (m_focus_window != nullptr) {
sys_message_t message = {};
Expand All @@ -555,9 +557,20 @@ bool WindowManager::handle_key_event(sys_key_event_t event) {
}

return true;
// SYS_KEY_SEMI_COLON instead of SYS_KEY_M because of AZERTY <-> QWERTY layouts
case SYS_KEY_SEMI_COLON: // Alt+M -> mosaic layout
mosaic_layout();
return true;
case SYS_KEY_E: { // Alt+E -> spawn the file explorer
auto explorer = TaskManager::get().create_task("/bin/explorer");
if (explorer == nullptr) {
LOG_ERROR("Failed to spawn the file explorer");
return true;
}

TaskManager::get().wake_task(explorer);
return true;
}
default:
return false;
}
Expand Down

0 comments on commit a1faa03

Please sign in to comment.