From 526ba71d571b42d4d71209969473a5b1e1d5938a Mon Sep 17 00:00:00 2001 From: rasmus Date: Tue, 16 Dec 2025 19:50:53 +0100 Subject: [PATCH] Holy shit it actually worked lol --- Desktop_Test/Desktop_Test.ino | 2 +- Desktop_Test/window_manager.cpp | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Desktop_Test/Desktop_Test.ino b/Desktop_Test/Desktop_Test.ino index 4036063..bebb341 100644 --- a/Desktop_Test/Desktop_Test.ino +++ b/Desktop_Test/Desktop_Test.ino @@ -67,7 +67,7 @@ void setup() { .y_offset = 5, .width = 25, .height = 25, - .action = WindowAction::CLOSE, + .action = WindowAction::MINIMIZE, }; std::vector wdec; diff --git a/Desktop_Test/window_manager.cpp b/Desktop_Test/window_manager.cpp index ee86b3d..94c7312 100644 --- a/Desktop_Test/window_manager.cpp +++ b/Desktop_Test/window_manager.cpp @@ -1,3 +1,4 @@ +#include "window.h" #include "GLOBALS.h" #include "window_manager.h" #include @@ -56,12 +57,19 @@ void WindowManager::draw_window(const Window& window) { // Decorations tft->draw_box(window.x + 3, window.y + 3, window.width - 6, 30, window.foreground_color); - // Close button - tft->draw_box(window.x + 6, window.y + 5, 25, 25, COL_RED); - // Minimize button - tft->draw_box(window.x + 6 + 30, window.y + 5, 25, 25, COL_LIGHT_GREY); + for (auto it = window.window_decorations.begin(); it != window.window_decorations.end(); ++it) { + if (it->action == WindowAction::CLOSE) { + // Close button + tft->draw_box(window.x + it->x_offset, window.y + it->y_offset, it->height, it->width, COL_RED); + } + if (it->action == WindowAction::MINIMIZE) { + // Minimize button + tft->draw_box(window.x + it->x_offset, window.y + it->y_offset, it->height, it->width, COL_LIGHT_GREY); + } + } + // Window title tft->draw_text(window.x + 6 + 65, window.y + 10, window.title.c_str()); @@ -86,9 +94,20 @@ int WindowManager::handle_window_click(const CLICK_EVENT& event) { if (event.x >= window.x && event.x <= (window.x + window.width) && event.y >= window.y && event.y <= (window.y + window.height)) { - if (window.focused) return -1; + Serial.println("lol"); - + for (auto it = window.window_decorations.begin(); it != window.window_decorations.end(); ++it) { + int x = window.x + it->x_offset; + int y = window.y + it->y_offset; + Serial.printf("x: %i y: %i\n", x, y); + if (event.x >= x && event.x <= (x + it->width) && event.y >= y && event.y <= (y + it->height) && it->action == WindowAction::CLOSE) { + Serial.println("lollllll"); + close_window(window.id); + return window.id; + } + } + + if (window.focused) return -1; // Unfocus all windows for (auto& win : windows) {