feat: screenshot app improvement, WIndow Server supports full-screen overlay, Disks app UI improvements

This commit is contained in:
2026-05-10 10:45:05 +02:00
parent 69fc184a4e
commit 72e4fa080a
29 changed files with 1483 additions and 395 deletions
+91 -58
View File
@@ -9,22 +9,20 @@
#include <gui/mtk.hpp>
static mtk::Theme disks_theme() {
mtk::Theme theme = mtk::make_theme();
theme.window_bg = BG_COLOR;
theme.surface = TOOLBAR_BG;
theme.surface_alt = HEADER_BG;
theme.surface_hover = HOVER_BG;
theme.border = BORDER_COLOR;
theme.text = TEXT_COLOR;
theme.text_muted = FAINT_TEXT;
theme.text_subtle = DIM_TEXT;
theme.selection = HOVER_BG;
theme.accent_soft = HOVER_BG;
theme.disabled_bg = Color::from_rgb(0xF0, 0xF0, 0xF0);
mtk::Theme theme = mtk::make_theme(g_accent);
theme.selection = theme.accent_soft;
theme.disabled_bg = Color::from_rgb(0xE4, 0xE4, 0xE4);
theme.disabled_fg = Color::from_rgb(0x9A, 0x9A, 0x9A);
return theme;
}
static mtk::TableStyle partition_table_style(const mtk::Theme& theme) {
mtk::TableStyle style = mtk::make_table_style(theme);
style.row_selected_bg = theme.accent_soft;
style.row_hover_bg = mtk::mix(theme.window_bg, theme.accent, 12);
return style;
}
static bool mouse_in_rect(const Rect& rect) {
return rect.contains(g_state.mouse_x, g_state.mouse_y);
}
@@ -79,6 +77,13 @@ static void draw_centered_text(Canvas& c, int width, int y, const char* text, Co
c.text((width - tw) / 2, y, text, color);
}
static void draw_dialog_footer(Canvas& c, int dialog_w, int dialog_h, const mtk::Theme& theme) {
constexpr int FOOTER_H = 54;
int y = dialog_h - FOOTER_H;
c.fill_rect(0, y, dialog_w, FOOTER_H, theme.surface);
mtk::draw_separator(c, 0, y, dialog_w, theme);
}
static void render_toolbar(Canvas& c, const mtk::Theme& theme) {
auto& dt = g_state;
int fh = system_font_height();
@@ -98,21 +103,6 @@ static void render_toolbar(Canvas& c, const mtk::Theme& theme) {
c.text(8, (TOOLBAR_H - fh) / 2, "No disks detected", theme.text);
return;
}
bool has_sel = dt.selected_part >= 0;
Rect newpart = toolbar_newpart_button_rect();
Rect format = toolbar_format_button_rect();
Rect mount = toolbar_mount_button_rect();
Rect refresh = toolbar_refresh_button_rect();
mtk::draw_button(c, newpart, "New Part", mtk::BUTTON_PRIMARY,
toolbar_button_state(newpart, true), theme);
mtk::draw_button(c, format, "Format", mtk::BUTTON_TONAL,
toolbar_button_state(format, has_sel), theme);
mtk::draw_button(c, mount, "Mount", mtk::BUTTON_TONAL,
toolbar_button_state(mount, has_sel), theme);
mtk::draw_button(c, refresh, "Refresh", mtk::BUTTON_SECONDARY,
toolbar_button_state(refresh, true), theme);
}
static void render_content(Canvas& c, const mtk::Theme& theme) {
@@ -140,7 +130,7 @@ static void render_content(Canvas& c, const mtk::Theme& theme) {
y = partition_map_y();
Rect map_rect = {MAP_PAD, y, g_win_w - MAP_PAD * 2, MAP_H};
c.fill_rounded_rect(map_rect.x, map_rect.y, map_rect.w, map_rect.h, theme.radius_md, theme.surface_alt);
mtk::draw_rounded_frame(c, map_rect, theme.radius_md, theme.surface_alt, theme.border);
int part_indices[MAX_PARTS];
int nparts = get_disk_parts(part_indices, MAX_PARTS);
@@ -155,45 +145,60 @@ static void render_content(Canvas& c, const mtk::Theme& theme) {
if (part_x + part_w > map_rect.x + map_rect.w)
part_w = map_rect.x + map_rect.w - part_x;
Color col = part_colors[pi % NUM_PART_COLORS];
Rect segment = {part_x, map_rect.y + 3, part_w, MAP_H - 6};
if (pi == dt.selected_part) {
col = Color::from_rgb((col.r + 255) / 2,
(col.g + 255) / 2,
(col.b + 255) / 2);
c.fill_rounded_rect(segment.x - 1, segment.y - 1,
segment.w + 2, segment.h + 2,
theme.radius_sm, theme.accent);
}
c.fill_rounded_rect(part_x, map_rect.y + 2, part_w, MAP_H - 4, theme.radius_sm, col);
Color col = part_colors[pi % NUM_PART_COLORS];
c.fill_rounded_rect(segment.x, segment.y, segment.w, segment.h,
theme.radius_sm, col);
char label[8];
snprintf(label, sizeof(label), "%d", pi);
int label_w = text_width(label);
if (part_w > label_w + 4) {
c.text(part_x + (part_w - label_w) / 2,
c.text(segment.x + (segment.w - label_w) / 2,
map_rect.y + (MAP_H - fh) / 2,
label, WHITE);
label, theme.text_inverse);
}
}
}
y = partition_header_y();
c.fill_rect(0, y, g_win_w, HEADER_H, theme.surface_alt);
mtk::draw_separator(c, 0, y + HEADER_H - 1, g_win_w, theme);
int list_y = partition_list_y();
int list_bottom = g_win_h - STATUS_H;
int hovered_row = hovered_partition_row();
mtk::TableStyle table_style = partition_table_style(theme);
mtk::TableLayout table = {
{0, y, g_win_w, HEADER_H},
{0, list_y, g_win_w, list_bottom - list_y},
ITEM_H
};
int ty = y + (HEADER_H - fh) / 2;
int col_idx = 12;
int col_name = 40;
int col_type = g_win_w / 2 - 20;
int col_size = g_win_w - 160;
int col_lba = g_win_w - 80;
mtk::TableColumn cols[5] = {
{"#", col_idx, col_name - col_idx - 8},
{"Name", col_name, col_type - col_name - 10},
{"Type", col_type, col_size - col_type - 10},
{"Size", col_size, col_lba - col_size - 10},
{"LBA", col_lba, g_win_w - col_lba - 12},
};
c.text(col_idx, ty, "#", theme.text_subtle);
c.text(col_name, ty, "Name", theme.text_subtle);
c.text(col_type, ty, "Type", theme.text_subtle);
c.text(col_size, ty, "Size", theme.text_subtle);
c.text(col_lba, ty, "LBA", theme.text_subtle);
c.fill_rect(table.header.x, table.header.y, table.header.w, table.header.h,
table_style.header_bg);
c.hline(table.header.x, table.header.y + table.header.h - 1,
table.header.w, table_style.header_border);
int list_y = partition_list_y();
int list_bottom = g_win_h - STATUS_H;
int hovered_row = hovered_partition_row();
int ty = table.header.y + (table.header.h - fh) / 2;
for (int i = 0; i < 5; i++)
c.text(table.header.x + cols[i].x, ty, cols[i].label, table_style.header_text);
for (int pi = 0; pi < nparts; pi++) {
int row_y = list_y + pi * ITEM_H - dt.scroll_y;
@@ -202,11 +207,11 @@ static void render_content(Canvas& c, const mtk::Theme& theme) {
Rect row_rect = {0, row_y, g_win_w, ITEM_H};
if (pi == dt.selected_part) {
mtk::draw_list_row(c, row_rect, true, false, theme);
c.fill_rect(row_rect.x, row_rect.y, row_rect.w, row_rect.h,
table_style.row_selected_bg);
} else if (pi == hovered_row) {
c.fill_rect(row_rect.x, row_rect.y, row_rect.w, row_rect.h, theme.surface_hover);
} else {
mtk::draw_list_row(c, row_rect, false, (pi & 1) != 0, theme);
c.fill_rect(row_rect.x, row_rect.y, row_rect.w, row_rect.h,
table_style.row_hover_bg);
}
Montauk::PartInfo& p = dt.parts[part_indices[pi]];
@@ -216,17 +221,17 @@ static void render_content(Canvas& c, const mtk::Theme& theme) {
int ry = row_y + (ITEM_H - fh) / 2;
draw_text_fit(c, col_name, ry, p.name[0] ? p.name : "(unnamed)",
col_type - col_name - 10, theme.text);
cols[1].w, theme.text);
draw_text_fit(c, col_type, ry, p.typeName,
col_size - col_type - 10, theme.text_subtle);
cols[2].w, theme.text_subtle);
char sz[24];
format_disk_size(sz, sizeof(sz), p.sectorCount, disk.sectorSizeLog);
c.text(col_size, ry, sz, theme.text);
draw_text_fit(c, col_size, ry, sz, cols[3].w, theme.text);
char lba_str[24];
snprintf(lba_str, sizeof(lba_str), "%lu", (unsigned)p.startLba);
c.text(col_lba, ry, lba_str, theme.text_muted);
draw_text_fit(c, col_lba, ry, lba_str, cols[4].w, theme.text_muted);
}
if (nparts == 0)
@@ -238,13 +243,34 @@ static void render_status(Canvas& c, const mtk::Theme& theme) {
int fh = system_font_height();
int sy = g_win_h - STATUS_H;
c.fill_rect(0, sy, g_win_w, STATUS_H, theme.surface_alt);
c.fill_rect(0, sy, g_win_w, STATUS_H, theme.surface);
mtk::draw_separator(c, 0, sy, g_win_w, theme);
bool has_disks = dt.disk_count > 0;
bool has_sel = dt.selected_part >= 0;
int text_right = g_win_w - 16;
if (has_disks) {
Rect newpart = toolbar_newpart_button_rect();
Rect format = toolbar_format_button_rect();
Rect mount = toolbar_mount_button_rect();
Rect refresh = toolbar_refresh_button_rect();
text_right = newpart.x - 12;
mtk::draw_button(c, newpart, "New Part", mtk::BUTTON_PRIMARY,
toolbar_button_state(newpart, true), theme);
mtk::draw_button(c, format, "Format", mtk::BUTTON_TONAL,
toolbar_button_state(format, has_sel), theme);
mtk::draw_button(c, mount, "Mount", mtk::BUTTON_TONAL,
toolbar_button_state(mount, has_sel), theme);
mtk::draw_button(c, refresh, "Refresh", mtk::BUTTON_SECONDARY,
toolbar_button_state(refresh, true), theme);
}
if (dt.status[0]) {
uint64_t age = montauk::get_milliseconds() - dt.status_time;
Color color = age < 5000 ? theme.text : theme.text_muted;
c.text(8, sy + (STATUS_H - fh) / 2, dt.status, color);
draw_text_fit(c, 16, sy + (STATUS_H - fh) / 2, dt.status,
text_right - 16, color);
}
}
@@ -265,11 +291,14 @@ void render_format_window() {
for (int i = 0; i < NUM_FS_TYPES; i++) {
Rect option = format_option_rect(FMT_DLG_W, i);
if (i == dlg.selected_fs)
c.fill_rounded_rect(option.x, option.y, option.w, option.h, theme.radius_md, theme.accent_soft);
if (i == dlg.selected_fs) {
mtk::draw_rounded_frame(c, option, theme.radius_md,
theme.accent_soft, theme.accent_soft);
}
mtk::draw_radio(c, option, g_fsTypes[i].name, i == dlg.selected_fs, theme);
}
draw_dialog_footer(c, FMT_DLG_W, FMT_DLG_H, theme);
mtk::draw_modal_actions(c,
dialog_primary_button_rect(FMT_DLG_W, FMT_DLG_H), "Format",
mtk::BUTTON_DANGER,
@@ -294,11 +323,15 @@ void render_newpart_window() {
Color warn_color = dlg.will_init_gpt ? theme.danger : theme.text;
int warn_y = 12 + fh * 2 + 20;
Rect warn_panel = {16, warn_y - 8, NP_DLG_W - 32, fh * 2 + 20};
Color warn_bg = dlg.will_init_gpt ? theme.danger_soft : theme.surface_alt;
mtk::draw_rounded_frame(c, warn_panel, theme.radius_md, warn_bg, warn_bg);
draw_centered_text(c, NP_DLG_W, warn_y, dlg.warn_line1, warn_color);
draw_centered_text(c, NP_DLG_W, warn_y + fh + 4, dlg.warn_line2, warn_color);
const char* confirm_label = dlg.will_init_gpt ? "Initialize" : "Create";
mtk::ButtonVariant confirm_variant = dlg.will_init_gpt ? mtk::BUTTON_DANGER : mtk::BUTTON_PRIMARY;
draw_dialog_footer(c, NP_DLG_W, NP_DLG_H, theme);
mtk::draw_modal_actions(c,
dialog_primary_button_rect(NP_DLG_W, NP_DLG_H), confirm_label,
confirm_variant,