282 lines
8.7 KiB
C++
282 lines
8.7 KiB
C++
/*
|
|
* desktop.hpp
|
|
* MontaukOS desktop state and compositor declarations
|
|
* Copyright (c) 2026 Daniel Hammer
|
|
*/
|
|
|
|
#pragma once
|
|
#include "gui/gui.hpp"
|
|
#include "gui/framebuffer.hpp"
|
|
#include "gui/svg.hpp"
|
|
#include "gui/window.hpp"
|
|
#include "gui/widgets.hpp"
|
|
#include "gui/mtk/widgets.hpp"
|
|
#include "gui/terminal.hpp"
|
|
#include <Api/Syscall.hpp>
|
|
#include <montauk/keyboard.h>
|
|
|
|
namespace gui {
|
|
|
|
static constexpr int MAX_WINDOWS = 32;
|
|
static constexpr int PANEL_HEIGHT = 32;
|
|
|
|
enum DesktopItemSection : uint8_t {
|
|
DESKTOP_ITEM_SECTION_HIDDEN = 0,
|
|
DESKTOP_ITEM_SECTION_APPS,
|
|
DESKTOP_ITEM_SECTION_SETTINGS,
|
|
};
|
|
|
|
enum DesktopItemLaunchKind : uint8_t {
|
|
DESKTOP_ITEM_LAUNCH_EXECUTABLE = 0,
|
|
DESKTOP_ITEM_LAUNCH_BUILTIN,
|
|
};
|
|
|
|
// Launchable desktop item discovered from an app manifest or supplied by the
|
|
// desktop's built-in registry.
|
|
struct DesktopItem {
|
|
char id[48];
|
|
char name[48];
|
|
char binary_path[128];
|
|
char icon_path[128];
|
|
char category[24];
|
|
SvgIcon icon;
|
|
DesktopItemSection section;
|
|
DesktopItemLaunchKind launch_kind;
|
|
int builtin_id;
|
|
bool menu_visible;
|
|
bool launch_with_home;
|
|
bool admin_only;
|
|
};
|
|
|
|
enum LauncherItemKind : uint8_t {
|
|
LAUNCHER_ITEM_EXTERNAL_APP = 0,
|
|
LAUNCHER_ITEM_BUILTIN_FILES,
|
|
LAUNCHER_ITEM_COMMAND_REBOOT,
|
|
LAUNCHER_ITEM_COMMAND_SHUTDOWN,
|
|
LAUNCHER_ITEM_SPECIAL_FOLDER,
|
|
};
|
|
|
|
struct LauncherItem {
|
|
char name[64];
|
|
char category[48];
|
|
char path[128];
|
|
char search_text[192];
|
|
SvgIcon* icon;
|
|
LauncherItemKind kind;
|
|
int ref_index;
|
|
};
|
|
|
|
struct DesktopSettings {
|
|
// Background
|
|
bool bg_gradient; // true = gradient, false = solid
|
|
bool bg_image; // true = JPEG wallpaper
|
|
Color bg_solid; // solid background color
|
|
Color bg_grad_top; // gradient top color
|
|
Color bg_grad_bottom; // gradient bottom color
|
|
|
|
// Wallpaper (valid when bg_image == true)
|
|
char bg_image_path[128]; // VFS path to current wallpaper
|
|
uint32_t* bg_wallpaper; // scaled ARGB pixel buffer (screen-sized)
|
|
int bg_wallpaper_w; // scaled width
|
|
int bg_wallpaper_h; // scaled height
|
|
|
|
// Panel
|
|
Color panel_color; // panel background color
|
|
|
|
// Accent
|
|
Color accent_color; // buttons, highlights, active indicators
|
|
|
|
// Display
|
|
bool show_shadows; // window shadows on/off
|
|
bool clock_24h; // 24-hour clock format
|
|
int ui_scale; // 0=Small, 1=Default, 2=Large
|
|
int tz_offset_minutes; // timezone offset from UTC in minutes
|
|
};
|
|
|
|
struct DesktopState {
|
|
Framebuffer fb;
|
|
Window windows[MAX_WINDOWS];
|
|
int window_count;
|
|
int focused_window;
|
|
|
|
// Current user context
|
|
char current_user[32];
|
|
char home_dir[128]; // "0:/users/<username>"
|
|
char user_config_dir[128]; // "0:/users/<username>/config"
|
|
bool is_admin;
|
|
|
|
montauk::abi::MouseState mouse;
|
|
uint8_t prev_buttons;
|
|
|
|
bool app_menu_open;
|
|
bool launcher_open;
|
|
char launcher_query[64];
|
|
int launcher_query_len;
|
|
LauncherItem* launcher_items; // dynamically grown
|
|
int launcher_item_count;
|
|
int launcher_item_capacity;
|
|
int* launcher_results; // indices into launcher_items, same capacity
|
|
int launcher_result_count;
|
|
int launcher_selected;
|
|
int launcher_scroll;
|
|
bool super_left_down;
|
|
bool super_right_down;
|
|
|
|
SvgIcon icon_terminal;
|
|
SvgIcon icon_filemanager;
|
|
SvgIcon icon_appmenu;
|
|
SvgIcon icon_folder;
|
|
SvgIcon icon_file;
|
|
SvgIcon icon_network;
|
|
SvgIcon icon_go_up;
|
|
SvgIcon icon_go_back;
|
|
SvgIcon icon_go_forward;
|
|
SvgIcon icon_home;
|
|
SvgIcon icon_refresh;
|
|
SvgIcon icon_exec;
|
|
|
|
SvgIcon icon_folder_lg;
|
|
SvgIcon icon_file_lg;
|
|
SvgIcon icon_exec_lg;
|
|
SvgIcon icon_drive;
|
|
SvgIcon icon_drive_lg;
|
|
SvgIcon icon_drive_usb;
|
|
SvgIcon icon_drive_usb_lg;
|
|
SvgIcon icon_delete;
|
|
SvgIcon icon_copy;
|
|
SvgIcon icon_cut;
|
|
SvgIcon icon_paste;
|
|
SvgIcon icon_rename;
|
|
SvgIcon icon_folder_new;
|
|
SvgIcon icon_home_folder;
|
|
SvgIcon icon_home_folder_lg;
|
|
SvgIcon icon_apps;
|
|
SvgIcon icon_apps_lg;
|
|
SvgIcon icon_system_configuration_menu;
|
|
SvgIcon icon_system_configuration;
|
|
SvgIcon icon_system_configuration_lg;
|
|
|
|
// Special user folder icons (16x16 and 48x48)
|
|
static constexpr int SPECIAL_FOLDER_COUNT = 6;
|
|
SvgIcon icon_special_folder[SPECIAL_FOLDER_COUNT];
|
|
SvgIcon icon_special_folder_lg[SPECIAL_FOLDER_COUNT];
|
|
|
|
SvgIcon icon_settings;
|
|
SvgIcon icon_reboot;
|
|
SvgIcon icon_shutdown;
|
|
SvgIcon icon_sleep;
|
|
SvgIcon icon_logout;
|
|
|
|
SvgIcon icon_volume;
|
|
|
|
// Desktop items discovered from 0:/apps/ manifests (dynamically grown).
|
|
DesktopItem* desktop_items;
|
|
int desktop_item_count;
|
|
int desktop_item_capacity;
|
|
|
|
// Right-click menu on the desktop background (MTK context menu).
|
|
mtk::ContextMenuState ctx_menu;
|
|
|
|
bool net_popup_open;
|
|
montauk::abi::NetCfg cached_net_cfg;
|
|
uint64_t net_cfg_last_poll;
|
|
Rect net_icon_rect;
|
|
|
|
// Registered link-layer interfaces. The IP configuration is global to the
|
|
// stack, so the wired and wireless popups use `active` to decide which of
|
|
// them owns the address currently on screen.
|
|
static constexpr int MAX_NETIFS = 4;
|
|
montauk::abi::NetIfInfo netifs[MAX_NETIFS];
|
|
int netif_count;
|
|
bool eth_present;
|
|
|
|
// ---- Wi-Fi -------------------------------------------------------------
|
|
// The panel entry exists only when a supported adapter is present.
|
|
static constexpr int MAX_WIFI_NETWORKS = 32;
|
|
static constexpr int WIFI_SSID_CAP = 36;
|
|
static constexpr int WIFI_PSK_CAP = 72;
|
|
|
|
SvgIcon icon_wifi;
|
|
bool wifi_present;
|
|
bool wifi_popup_open;
|
|
Rect wifi_icon_rect;
|
|
montauk::abi::WifiInfo wifi_info;
|
|
montauk::abi::WifiNetwork wifi_networks[MAX_WIFI_NETWORKS];
|
|
int wifi_network_count;
|
|
uint64_t wifi_last_poll;
|
|
uint32_t wifi_scan_generation;
|
|
bool wifi_scanning;
|
|
int wifi_scroll; // first visible row of the list
|
|
bool wifi_boot_scan_started; // the automatic scan at startup
|
|
bool wifi_autoconnect_done; // saved-network join already tried
|
|
bool wifi_joining; // a join we started is in flight
|
|
bool wifi_dhcp_pending; // ask for a lease once the link is up
|
|
bool wifi_dhcp_waiting; // dhcp.elf running, no address yet
|
|
char wifi_joining_ssid[WIFI_SSID_CAP];
|
|
char wifi_status[96]; // last result line in the popup
|
|
uint64_t wifi_status_time;
|
|
|
|
|
|
bool vol_popup_open;
|
|
Rect vol_icon_rect;
|
|
int vol_level; // 0-100
|
|
bool vol_muted;
|
|
int vol_pre_mute; // volume before mute
|
|
bool vol_dragging; // slider drag in progress
|
|
uint64_t vol_last_poll;
|
|
uint64_t vol_serial; // last seen mixer state serial
|
|
int vol_output; // 0=HDA, 1=Bluetooth
|
|
int vol_bt_status; // A2DP state (>=2 means selectable)
|
|
|
|
// Temperature monitoring
|
|
static constexpr int MAX_THERMAL_ZONES = 8;
|
|
montauk::abi::ThermalInfo thermal_zones[MAX_THERMAL_ZONES];
|
|
int thermal_zone_count;
|
|
uint64_t thermal_last_poll;
|
|
Rect temp_icon_rect;
|
|
|
|
// Keyboard layouts. The desktop translates hardware scan codes before
|
|
// dispatching events, so embedded and external apps see the same layout.
|
|
montauk::keyboard::State keyboard;
|
|
Rect keyboard_layout_rect;
|
|
uint64_t keyboard_last_poll;
|
|
|
|
int screen_w, screen_h;
|
|
uint32_t* background_cache;
|
|
int background_cache_pitch;
|
|
bool background_cache_dirty;
|
|
|
|
// IDs of external windows we've sent a close event to but that haven't
|
|
// been destroyed yet by their owning process. Prevents the poll loop
|
|
// from re-creating them at the default position (visible flicker).
|
|
static constexpr int MAX_CLOSING = MAX_WINDOWS;
|
|
int closing_ext_ids[MAX_CLOSING];
|
|
int closing_ext_count;
|
|
|
|
DesktopSettings settings;
|
|
|
|
// Lock screen state
|
|
bool screen_locked;
|
|
char lock_password[64];
|
|
int lock_password_len;
|
|
char lock_error[128];
|
|
bool lock_show_error;
|
|
char lock_display_name[64];
|
|
SvgIcon icon_lock;
|
|
};
|
|
|
|
// Forward declarations - implemented in main.cpp
|
|
void desktop_init(DesktopState* ds);
|
|
void desktop_run(DesktopState* ds);
|
|
void desktop_compose(DesktopState* ds);
|
|
int desktop_create_window(DesktopState* ds, const char* title, int x, int y, int w, int h);
|
|
void desktop_close_window(DesktopState* ds, int idx);
|
|
void desktop_raise_window(DesktopState* ds, int idx);
|
|
void desktop_draw_panel(DesktopState* ds);
|
|
void desktop_draw_window(DesktopState* ds, int idx);
|
|
void desktop_handle_mouse(DesktopState* ds);
|
|
void desktop_handle_keyboard(DesktopState* ds, const montauk::abi::KeyEvent& key);
|
|
bool desktop_refresh_keyboard_layouts(DesktopState* ds, bool force);
|
|
|
|
} // namespace gui
|