From 8634a43eceb4cab933655eeb979e375c14efe0bb Mon Sep 17 00:00:00 2001 From: Adam Pippin Date: Sat, 18 Apr 2020 21:35:25 -0700 Subject: [PATCH] Beginning of tiling wm --- UI.cpp | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++-- UI.h | 15 ++++++ watchos.ino | 41 ++++++++------ 3 files changed, 190 insertions(+), 18 deletions(-) diff --git a/UI.cpp b/UI.cpp index 454e034..b63a38f 100644 --- a/UI.cpp +++ b/UI.cpp @@ -1,22 +1,168 @@ #include #include "Kernel.h" +#include "UI.h" + +#define MAX_WINDOWS 8 + +struct Window *UI_get_window(int hwnd); +void base_window_callback(int hwnd, int x, int y, int width, int height); +void draw(int parent_hwnd, int x, int y, int width, int height); + +struct Window windows[MAX_WINDOWS]; +int next_hwnd = 1; int UI(int pid, unsigned int signal) { if (signal & SIGNAL_START) { Kernel_signal_mask(pid, SIGNAL_START | SIGNAL_STOP | SIGNAL_REDRAW); + windows[0].hwnd = next_hwnd++; + windows[0].hwnd_parent = 0; + windows[0].layout_mode = LAYOUT_MODE_SPLIT_VERTICAL; + windows[0].callback = &base_window_callback; } + if (signal & SIGNAL_STOP) { return 255; } + if (signal & SIGNAL_REDRAW) { - M5.Lcd.fillScreen(TFT_DARKGREY); - M5.Lcd.setRotation(3); - M5.Lcd.setTextColor(TFT_WHITE, TFT_DARKGREY); + for (int i=0; ihwnd == -1) + { + return; + } + + // Call callback on parent if available + if (parent_window->placeholder != true) + { + (*parent_window->callback)(parent_hwnd, x, y, width, height); + } + + // Count the number of children + int child_count = 0; + for (int i=0; ilayout_mode) + { + case LAYOUT_MODE_NONE: + { + Serial.printf("Layout mode: none\n"); + for (int i=0; ihwnd, x, y, width, height); + } + } + break; + case LAYOUT_MODE_SPLIT_VERTICAL: + { + Serial.printf("Layout mode: vertical\n"); + int child_width = width / child_count; + for (int i=0; ihwnd, x + (i * child_width), y, child_width, height); + } + } + break; + case LAYOUT_MODE_SPLIT_HORIZONTAL: + { + Serial.printf("Layout mode: horizontal\n"); + int child_height = height / child_count; + for (int i=0; ihwnd, x, y + (i * child_height), width, child_height); + } + } + break; + } +} + +void base_window_callback(int hwnd, int x, int y, int width, int height) +{ + M5.Lcd.fillScreen(TFT_DARKGREY); + M5.Lcd.setRotation(3); +} + +int UI_create_window(void (*callback)(int, int, int, int, int), int parent /* = 0 */, int zorder /* = 0 */, bool placeholder /* = true */) +{ + Window* window = UI_get_window(0); + if (window->hwnd == -1) + { + Kernel_panic("Cannot create window! Out of handles!"); + } + + window->hwnd = next_hwnd++; + window->hwnd_parent = parent; + window->placeholder = placeholder; + window->callback = callback; + return window->hwnd; +} + +void UI_set_layout_mode(int hwnd, int layout_mode) +{ + Window* window = UI_get_window(0); + if (window->hwnd == -1) + { + return; + } + window->layout_mode = layout_mode; +} + +struct Window *UI_get_window(int hwnd) +{ + for (int i=0; i