From 4f7aba8aa34fbb4817f41dacdbe1ce37459b7f2c Mon Sep 17 00:00:00 2001 From: rasmus Date: Thu, 18 Dec 2025 16:14:27 +0100 Subject: [PATCH] Temp commit before rewriting the window- and desktop manager --- Desktop_Test/Desktop_Test.ino | 7 ++++++- Desktop_Test/GLOBALS.h | 12 ++++++++++++ Desktop_Test/desktop.h | 12 +++++++++++- Desktop_Test/desktop_hander.cpp | 7 ++++++- Desktop_Test/desktop_hander.h | 1 + Desktop_Test/event_manager.cpp | 5 +++-- Desktop_Test/event_manager.h | 4 ++-- Desktop_Test/input_manager.cpp | 5 ----- Desktop_Test/window.h | 1 + Desktop_Test/window_manager.cpp | 22 ++++++++++++++++++++-- Desktop_Test/window_manager.h | 1 + 11 files changed, 63 insertions(+), 14 deletions(-) diff --git a/Desktop_Test/Desktop_Test.ino b/Desktop_Test/Desktop_Test.ino index 5590bd9..f50f480 100644 --- a/Desktop_Test/Desktop_Test.ino +++ b/Desktop_Test/Desktop_Test.ino @@ -4,6 +4,7 @@ #include "tft_handler.h" #include "event_manager.h" #include "GLOBALS.h" +#include "global_queue.h" #include WindowManager* wm; @@ -41,6 +42,8 @@ void setup() { // Initialize event manager (creates dispatcher task) EventManager::getInstance().init(); + + initGlobalQueue(); // Initialize components (they subscribe to events) im->init(_display_state, th); @@ -83,6 +86,7 @@ void setup() { .background_color = 0xbdf7, .foreground_color = COL_DARK_BLUE, .focused = false, + .minimized = false, .title = "Hello World!", .window_decorations = wdec, }; @@ -97,6 +101,7 @@ void setup() { .background_color = 0xbdf7, .foreground_color = COL_DARK_BLUE, .focused = true, + .minimized = false, .title = "Second Window", .window_decorations = wdec, }; @@ -114,5 +119,5 @@ void loop() { _display_state->update_display.store(false); } - delay(5); + delay(0); } \ No newline at end of file diff --git a/Desktop_Test/GLOBALS.h b/Desktop_Test/GLOBALS.h index 2d71628..a07bdec 100644 --- a/Desktop_Test/GLOBALS.h +++ b/Desktop_Test/GLOBALS.h @@ -16,6 +16,18 @@ struct CLICK_EVENT { CLICK_EVENTS event; }; +enum class ApplicationEventState { + NONE = 0, + CREATED = 1, + CLOSED = 2, +}; + +struct APPLICATION_EVENT { + int id; + ApplicationEventState state; + char title[64]; +}; + struct DISPLAY_STATE { std::atomic update_display; }; \ No newline at end of file diff --git a/Desktop_Test/desktop.h b/Desktop_Test/desktop.h index 226f790..d8e3036 100644 --- a/Desktop_Test/desktop.h +++ b/Desktop_Test/desktop.h @@ -1,5 +1,15 @@ #pragma once -#include "WString.h" +#include + +struct TaskBarItem { + int id; + int place_x; + int place_y; + int icon_size_x; + int icon_size_y; + bool focused; + std::string name; +}; struct Desktop_Item { int id; diff --git a/Desktop_Test/desktop_hander.cpp b/Desktop_Test/desktop_hander.cpp index 9b64aaf..7f31bb7 100644 --- a/Desktop_Test/desktop_hander.cpp +++ b/Desktop_Test/desktop_hander.cpp @@ -1,11 +1,12 @@ #include "desktop_hander.h" +#include "global_queue.h" #include "tft_handler.h" void Desktop_Hander::init(TFT_Handler* th, DISPLAY_STATE* ds) { tft = th; display_state = ds; - // Subscribe to events + // Subscribe to click events EventManager::getInstance().subscribe(this); // Create desktop items @@ -52,6 +53,10 @@ void Desktop_Hander::draw_task_bar(int color) { // Button tft->draw_box(6, 298, 50, 18, color); + + for (TaskBarItem item : task_bar_items) { + + } } void Desktop_Hander::draw_desktop_Item(Desktop_Item desktop_item) { diff --git a/Desktop_Test/desktop_hander.h b/Desktop_Test/desktop_hander.h index 383b372..6e888c5 100644 --- a/Desktop_Test/desktop_hander.h +++ b/Desktop_Test/desktop_hander.h @@ -9,6 +9,7 @@ class Desktop_Hander : public IEventListener { private: TFT_Handler* tft; DISPLAY_STATE* display_state; + std::vector task_bar_items; std::vector items; int handle_desktop_click(CLICK_EVENT event); diff --git a/Desktop_Test/event_manager.cpp b/Desktop_Test/event_manager.cpp index af205a8..a2a8f92 100644 --- a/Desktop_Test/event_manager.cpp +++ b/Desktop_Test/event_manager.cpp @@ -1,3 +1,4 @@ +#include "GLOBALS.h" #include "event_manager.h" void EventManager::init() { @@ -5,7 +6,7 @@ void EventManager::init() { } void EventManager::publish(const CLICK_EVENT& event) { - xQueueSend(_event_queue, &event, 0); + xQueueSend(_click_event_queue, &event, 0); } void EventManager::subscribe(IEventListener* listener) { @@ -24,7 +25,7 @@ void EventManager::dispatch_task(void* pvParameters) { CLICK_EVENT event; for (;;) { - if (xQueueReceive(self->_event_queue, &event, portMAX_DELAY)) { + if (xQueueReceive(self->_click_event_queue, &event, portMAX_DELAY)) { // Dispatch to all listeners for (auto* listener : self->_listeners) { listener->on_click_event(event); diff --git a/Desktop_Test/event_manager.h b/Desktop_Test/event_manager.h index 02f76aa..f9f89a7 100644 --- a/Desktop_Test/event_manager.h +++ b/Desktop_Test/event_manager.h @@ -17,12 +17,12 @@ public: class EventManager { private: - QueueHandle_t _event_queue; + QueueHandle_t _click_event_queue; std::vector _listeners; TaskHandle_t _dispatcher_task; EventManager() { - _event_queue = xQueueCreate(10, sizeof(CLICK_EVENT)); + _click_event_queue = xQueueCreate(10, sizeof(CLICK_EVENT)); } EventManager(const EventManager&) = delete; diff --git a/Desktop_Test/input_manager.cpp b/Desktop_Test/input_manager.cpp index abeee6a..27a72d9 100644 --- a/Desktop_Test/input_manager.cpp +++ b/Desktop_Test/input_manager.cpp @@ -51,22 +51,18 @@ void InputManager::handle_button_press(int buttonIndex) { mi.x = (mi.x + 5 > 476) ? 476 : mi.x + 5; needs_redraw = true; break; - case 1: mi.y = (mi.y + 5 > 316) ? 316 : mi.y + 5; needs_redraw = true; break; - case 2: mi.y = (mi.y - 5 < 0) ? 0 : mi.y - 5; needs_redraw = true; break; - case 3: mi.x = (mi.x - 5 < 0) ? 0 : mi.x - 5; needs_redraw = true; break; - case 4: // Click { CLICK_EVENT event = { @@ -77,7 +73,6 @@ void InputManager::handle_button_press(int buttonIndex) { EventManager::getInstance().publish(event); } break; - case 5: // Right click { CLICK_EVENT event = { diff --git a/Desktop_Test/window.h b/Desktop_Test/window.h index c23d82a..c9a56b7 100644 --- a/Desktop_Test/window.h +++ b/Desktop_Test/window.h @@ -27,6 +27,7 @@ struct Window { int background_color; int foreground_color; bool focused; + bool minimized; std::string title; std::vector window_decorations; }; \ No newline at end of file diff --git a/Desktop_Test/window_manager.cpp b/Desktop_Test/window_manager.cpp index afcb644..69acc78 100644 --- a/Desktop_Test/window_manager.cpp +++ b/Desktop_Test/window_manager.cpp @@ -1,13 +1,14 @@ #include "window.h" #include "GLOBALS.h" #include "window_manager.h" +#include "global_queue.h" #include void WindowManager::init(TFT_Handler* th, DISPLAY_STATE* ds) { tft = th; display_state = ds; - // Subscribe to events + // Subscribe to click events EventManager::getInstance().subscribe(this); } @@ -33,6 +34,16 @@ void WindowManager::close_window(int window_id) { } } +void WindowManager::minimize_window(int window_id) { + for (auto it = windows.begin(); it != windows.end(); ++it) { + if (it->id == window_id) { + it->minimized = true; + display_state->update_display.store(true); + break; + } + } +} + void WindowManager::draw_all() { tft->start_draw(); for (const auto& win : windows) { @@ -42,6 +53,8 @@ void WindowManager::draw_all() { } void WindowManager::draw_window(Window window) { + if (window.minimized) return; + // Outer shadow tft->draw_rect(window.x, window.y, window.width + 2, window.height + 2, 1, 0x0000); @@ -97,11 +110,16 @@ int WindowManager::handle_window_click(CLICK_EVENT event) { 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) { close_window(window.id); return window.id; } + + if (event.x >= x && event.x <= (x + it->width) && event.y >= y && event.y <= (y + it->height) && it->action == WindowAction::MINIMIZE) { + minimize_window(window.id); + return window.id; + } } if (window.focused) return -1; diff --git a/Desktop_Test/window_manager.h b/Desktop_Test/window_manager.h index 5fa2a75..7b9d0d4 100644 --- a/Desktop_Test/window_manager.h +++ b/Desktop_Test/window_manager.h @@ -25,6 +25,7 @@ public: void init(TFT_Handler* th, DISPLAY_STATE* ds); void create_window(Window window); void close_window(int window_id); + void minimize_window(int window_id); void draw_all(); void draw_window(Window window);