Skip to content

Commit

Permalink
Fixed Stuff in Windows Manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
desfreng committed May 22, 2024
1 parent 44a7338 commit 44a87a6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion kernel/memory/kernel_internal_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bool memory_impl::init() {
}

const size_t nb_pages = libk::div_round_down(_contiguous_stop - _contiguous_start + 1, PAGE_SIZE);
const size_t nb_used_page = libk::div_round_up(PageAlloc::memory_needed(nb_pages), PAGE_SIZE);
const size_t nb_used_page = libk::div_round_up(ContiguousPageAllocator::memory_needed(nb_pages), PAGE_SIZE);

PhysicalPA contiguous_physical_memory;
if (!allocate_pages(_lin_alloc, nb_used_page, &contiguous_physical_memory)) {
Expand Down
21 changes: 13 additions & 8 deletions kernel/wm/window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ void WindowManager::destroy_window(Window* window) {

window->get_task()->unregister_window(window);

const auto it = std::find(m_windows.begin(), m_windows.end(), window);
m_windows.erase(it);

if (m_focus_window == window) {
// Unfocus the window.
unfocus_window(window);
}

const auto it = std::find(m_windows.begin(), m_windows.end(), window);
m_windows.erase(it);

--m_window_count;
delete window;

Expand Down Expand Up @@ -219,11 +219,15 @@ void WindowManager::unfocus_window(Window* window) {
Window* new_focus_window = nullptr;
for (auto* w : m_windows) {
// TODO: give focus to the nearest window (according to depth).
if (w != window)
w = new_focus_window;
if (w != window && w->is_visible())
new_focus_window = w;
}

m_focus_window = nullptr;

if (new_focus_window == nullptr)
return;

focus_window(new_focus_window);
}

Expand Down Expand Up @@ -536,19 +540,20 @@ bool WindowManager::handle_key_event(sys_key_event_t event) {
move_focus_window_down();
return true;
case SYS_KEY_F: // Alt+F -> toggle fullscreen
// TODO: better fullscreen support (for example, when focus out, the window should not be fullscreen anymore)
// TODO: better fullscreen support (for example, when focus out, the window should not be
// fullscreen anymore)
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;
case SYS_KEY_Q: // Alt+Q -> close window
case SYS_KEY_A: // Alt+Q -> close window
if (m_focus_window != nullptr) {
sys_message_t message = {};
message.id = SYS_MSG_CLOSE;
post_message(m_focus_window, message);
}

return true;
case SYS_KEY_M: // Alt+M -> mosaic layout
case SYS_KEY_SEMI_COLON: // Alt+M -> mosaic layout
mosaic_layout();
return true;
default:
Expand Down
2 changes: 1 addition & 1 deletion usr/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main() {
sys_print("Failed to spawn " program); \
} while (0)

// LAUNCH("/usr/bin/credits");
LAUNCH("/usr/bin/credits");
LAUNCH("/usr/bin/slides");

while (true)
Expand Down
4 changes: 4 additions & 0 deletions usr/slides.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ static const char* get_slide_path(int idx) {

static uint8_t* load_slide_image(int idx, int* buffer_length) {
const char* path = get_slide_path(idx);
sys_print("Loading...");
sys_print(path);
sys_file_t* file = sys_open_file(path, SYS_FM_READ);
if (file == NULL)
return NULL;
Expand All @@ -107,6 +109,8 @@ static uint8_t* load_slide_image(int idx, int* buffer_length) {
*buffer_length = file_size;

sys_close_file(file);
sys_print("Done.");

return buffer;
}

Expand Down

0 comments on commit 44a87a6

Please sign in to comment.