feat: screenshot app improvement, WIndow Server supports full-screen overlay, Disks app UI improvements
This commit is contained in:
@@ -240,93 +240,103 @@ void gui::desktop_compose(DesktopState* ds) {
|
||||
}
|
||||
}
|
||||
|
||||
// Draw panel on top
|
||||
desktop_draw_panel(ds);
|
||||
|
||||
// Draw app menu if open
|
||||
if (ds->app_menu_open) {
|
||||
desktop_draw_app_menu(ds);
|
||||
bool topFullscreen = false;
|
||||
for (int i = ds->window_count - 1; i >= 0; i--) {
|
||||
if (ds->windows[i].state == WIN_MINIMIZED || ds->windows[i].state == WIN_CLOSED)
|
||||
continue;
|
||||
topFullscreen = desktop_window_fullscreen(&ds->windows[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
// Draw network popup if open
|
||||
if (ds->net_popup_open) {
|
||||
desktop_draw_net_popup(ds);
|
||||
}
|
||||
if (!topFullscreen) {
|
||||
// Draw panel on top
|
||||
desktop_draw_panel(ds);
|
||||
|
||||
// Draw volume popup if open
|
||||
if (ds->vol_popup_open) {
|
||||
desktop_draw_vol_popup(ds);
|
||||
}
|
||||
|
||||
// Draw right-click context menu if open
|
||||
if (ds->ctx_menu_open) {
|
||||
static constexpr int CTX_MENU_W = 180;
|
||||
static constexpr int CTX_ITEM_H = 36;
|
||||
static constexpr int CTX_ITEM_COUNT = 6;
|
||||
int cmx = ds->ctx_menu_x;
|
||||
int cmy = ds->ctx_menu_y;
|
||||
int cmh = CTX_ITEM_H * CTX_ITEM_COUNT + 8;
|
||||
|
||||
// Clamp to screen
|
||||
if (cmx + CTX_MENU_W > sw) cmx = sw - CTX_MENU_W;
|
||||
if (cmy + cmh > sh) cmy = sh - cmh;
|
||||
|
||||
ensure_filemanager_icons_loaded(ds);
|
||||
|
||||
draw_shadow(fb, cmx, cmy, CTX_MENU_W, cmh, 4, colors::SHADOW);
|
||||
fill_rounded_rect(fb, cmx, cmy, CTX_MENU_W, cmh, 8, colors::MENU_BG);
|
||||
draw_rect(fb, cmx, cmy, CTX_MENU_W, cmh, colors::BORDER);
|
||||
|
||||
struct CtxItem { const char* label; SvgIcon* icon; };
|
||||
CtxItem ctx_items[CTX_ITEM_COUNT] = {
|
||||
{ "Terminal", &ds->icon_terminal },
|
||||
{ "Files", &ds->icon_filemanager },
|
||||
{ "System Configuration", &ds->icon_system_configuration_menu },
|
||||
{ "Sleep", &ds->icon_sleep },
|
||||
{ "Reboot", &ds->icon_reboot },
|
||||
{ "Shutdown", &ds->icon_shutdown },
|
||||
};
|
||||
|
||||
int mmx = ds->mouse.x;
|
||||
int mmy = ds->mouse.y;
|
||||
|
||||
for (int i = 0; i < CTX_ITEM_COUNT; i++) {
|
||||
int iy = cmy + 4 + i * CTX_ITEM_H;
|
||||
Rect item_r = {cmx + 4, iy, CTX_MENU_W - 8, CTX_ITEM_H};
|
||||
|
||||
if (item_r.contains(mmx, mmy)) {
|
||||
fill_rounded_rect(fb, item_r.x, item_r.y, item_r.w, item_r.h, 4, colors::MENU_HOVER);
|
||||
}
|
||||
|
||||
int icon_x = item_r.x + 8;
|
||||
int icon_y = item_r.y + (CTX_ITEM_H - 20) / 2;
|
||||
if (ctx_items[i].icon && ctx_items[i].icon->pixels) {
|
||||
fb.blit_alpha(icon_x, icon_y, ctx_items[i].icon->width, ctx_items[i].icon->height, ctx_items[i].icon->pixels);
|
||||
}
|
||||
|
||||
int tx = icon_x + 28;
|
||||
int ty = item_r.y + (CTX_ITEM_H - system_font_height()) / 2;
|
||||
draw_text(fb, tx, ty, ctx_items[i].label, colors::TEXT_COLOR);
|
||||
// Draw app menu if open
|
||||
if (ds->app_menu_open) {
|
||||
desktop_draw_app_menu(ds);
|
||||
}
|
||||
}
|
||||
|
||||
if (ds->launcher_open) {
|
||||
desktop_draw_launcher(ds);
|
||||
}
|
||||
// Draw network popup if open
|
||||
if (ds->net_popup_open) {
|
||||
desktop_draw_net_popup(ds);
|
||||
}
|
||||
|
||||
// Draw snap preview overlay while dragging to screen edge
|
||||
for (int i = 0; i < ds->window_count; i++) {
|
||||
Window* win = &ds->windows[i];
|
||||
if (win->dragging) {
|
||||
int dmx = ds->mouse.x;
|
||||
if (dmx <= 0) {
|
||||
fb.fill_rect_alpha(0, PANEL_HEIGHT, sw / 2, sh - PANEL_HEIGHT,
|
||||
Color::from_rgba(0x33, 0x77, 0xCC, 0x30));
|
||||
} else if (dmx >= sw - 1) {
|
||||
fb.fill_rect_alpha(sw / 2, PANEL_HEIGHT, sw / 2, sh - PANEL_HEIGHT,
|
||||
Color::from_rgba(0x33, 0x77, 0xCC, 0x30));
|
||||
// Draw volume popup if open
|
||||
if (ds->vol_popup_open) {
|
||||
desktop_draw_vol_popup(ds);
|
||||
}
|
||||
|
||||
// Draw right-click context menu if open
|
||||
if (ds->ctx_menu_open) {
|
||||
static constexpr int CTX_MENU_W = 180;
|
||||
static constexpr int CTX_ITEM_H = 36;
|
||||
static constexpr int CTX_ITEM_COUNT = 6;
|
||||
int cmx = ds->ctx_menu_x;
|
||||
int cmy = ds->ctx_menu_y;
|
||||
int cmh = CTX_ITEM_H * CTX_ITEM_COUNT + 8;
|
||||
|
||||
// Clamp to screen
|
||||
if (cmx + CTX_MENU_W > sw) cmx = sw - CTX_MENU_W;
|
||||
if (cmy + cmh > sh) cmy = sh - cmh;
|
||||
|
||||
ensure_filemanager_icons_loaded(ds);
|
||||
|
||||
draw_shadow(fb, cmx, cmy, CTX_MENU_W, cmh, 4, colors::SHADOW);
|
||||
fill_rounded_rect(fb, cmx, cmy, CTX_MENU_W, cmh, 8, colors::MENU_BG);
|
||||
draw_rect(fb, cmx, cmy, CTX_MENU_W, cmh, colors::BORDER);
|
||||
|
||||
struct CtxItem { const char* label; SvgIcon* icon; };
|
||||
CtxItem ctx_items[CTX_ITEM_COUNT] = {
|
||||
{ "Terminal", &ds->icon_terminal },
|
||||
{ "Files", &ds->icon_filemanager },
|
||||
{ "System Configuration", &ds->icon_system_configuration_menu },
|
||||
{ "Sleep", &ds->icon_sleep },
|
||||
{ "Reboot", &ds->icon_reboot },
|
||||
{ "Shutdown", &ds->icon_shutdown },
|
||||
};
|
||||
|
||||
int mmx = ds->mouse.x;
|
||||
int mmy = ds->mouse.y;
|
||||
|
||||
for (int i = 0; i < CTX_ITEM_COUNT; i++) {
|
||||
int iy = cmy + 4 + i * CTX_ITEM_H;
|
||||
Rect item_r = {cmx + 4, iy, CTX_MENU_W - 8, CTX_ITEM_H};
|
||||
|
||||
if (item_r.contains(mmx, mmy)) {
|
||||
fill_rounded_rect(fb, item_r.x, item_r.y, item_r.w, item_r.h, 4, colors::MENU_HOVER);
|
||||
}
|
||||
|
||||
int icon_x = item_r.x + 8;
|
||||
int icon_y = item_r.y + (CTX_ITEM_H - 20) / 2;
|
||||
if (ctx_items[i].icon && ctx_items[i].icon->pixels) {
|
||||
fb.blit_alpha(icon_x, icon_y, ctx_items[i].icon->width, ctx_items[i].icon->height, ctx_items[i].icon->pixels);
|
||||
}
|
||||
|
||||
int tx = icon_x + 28;
|
||||
int ty = item_r.y + (CTX_ITEM_H - system_font_height()) / 2;
|
||||
draw_text(fb, tx, ty, ctx_items[i].label, colors::TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
if (ds->launcher_open) {
|
||||
desktop_draw_launcher(ds);
|
||||
}
|
||||
|
||||
// Draw snap preview overlay while dragging to screen edge
|
||||
for (int i = 0; i < ds->window_count; i++) {
|
||||
Window* win = &ds->windows[i];
|
||||
if (win->dragging) {
|
||||
int dmx = ds->mouse.x;
|
||||
if (dmx <= 0) {
|
||||
fb.fill_rect_alpha(0, PANEL_HEIGHT, sw / 2, sh - PANEL_HEIGHT,
|
||||
Color::from_rgba(0x33, 0x77, 0xCC, 0x30));
|
||||
} else if (dmx >= sw - 1) {
|
||||
fb.fill_rect_alpha(sw / 2, PANEL_HEIGHT, sw / 2, sh - PANEL_HEIGHT,
|
||||
Color::from_rgba(0x33, 0x77, 0xCC, 0x30));
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,7 +349,8 @@ void gui::desktop_compose(DesktopState* ds) {
|
||||
cur_style = cursor_for_edge(win->resize_edge);
|
||||
break;
|
||||
}
|
||||
if (win->state == WIN_MINIMIZED || win->state == WIN_CLOSED || win->state == WIN_MAXIMIZED)
|
||||
if (win->state == WIN_MINIMIZED || win->state == WIN_CLOSED ||
|
||||
win->state == WIN_MAXIMIZED || desktop_window_fullscreen(win))
|
||||
continue;
|
||||
if (win->frame.contains(ds->mouse.x, ds->mouse.y)) {
|
||||
ResizeEdge edge = hit_test_resize_edge(win->frame, ds->mouse.x, ds->mouse.y);
|
||||
@@ -354,7 +365,7 @@ void gui::desktop_compose(DesktopState* ds) {
|
||||
if (cur_style == CURSOR_ARROW && ds->focused_window >= 0) {
|
||||
Window* fwin = &ds->windows[ds->focused_window];
|
||||
if (fwin->external && fwin->ext_cursor > 0) {
|
||||
Rect cr = fwin->content_rect();
|
||||
Rect cr = desktop_content_rect(fwin);
|
||||
if (cr.contains(ds->mouse.x, ds->mouse.y)) {
|
||||
if (fwin->ext_cursor == 1) cur_style = CURSOR_RESIZE_H;
|
||||
else if (fwin->ext_cursor == 2) cur_style = CURSOR_RESIZE_V;
|
||||
|
||||
@@ -112,6 +112,16 @@ inline int menu_add_external(const char* label, const char* binary, SvgIcon* ico
|
||||
// Forward Declarations (internal functions)
|
||||
// ============================================================================
|
||||
|
||||
inline bool desktop_window_fullscreen(const gui::Window* win) {
|
||||
return win && win->external && (win->ext_flags & Montauk::WIN_FLAG_FULLSCREEN);
|
||||
}
|
||||
|
||||
inline gui::Rect desktop_content_rect(const gui::Window* win) {
|
||||
return desktop_window_fullscreen(win)
|
||||
? win->frame
|
||||
: win->content_rect();
|
||||
}
|
||||
|
||||
// window.cpp
|
||||
gui::ResizeEdge hit_test_resize_edge(const gui::Rect& f, int mx, int my);
|
||||
gui::CursorStyle cursor_for_edge(gui::ResizeEdge edge);
|
||||
|
||||
+156
-87
@@ -94,6 +94,47 @@ static void handle_lock_keyboard(DesktopState* ds, const Montauk::KeyEvent& key)
|
||||
}
|
||||
}
|
||||
|
||||
static void forward_external_mouse(gui::Window* win,
|
||||
const gui::MouseEvent& ev,
|
||||
int mx,
|
||||
int my,
|
||||
uint8_t buttons,
|
||||
uint8_t prev) {
|
||||
gui::Rect cr = desktop_content_rect(win);
|
||||
Montauk::WinEvent wev;
|
||||
montauk::memset(&wev, 0, sizeof(wev));
|
||||
wev.type = 1; // mouse
|
||||
wev.mouse.x = mx - cr.x;
|
||||
wev.mouse.y = my - cr.y;
|
||||
wev.mouse.scroll = ev.scroll;
|
||||
wev.mouse.buttons = buttons;
|
||||
wev.mouse.prev_buttons = prev;
|
||||
montauk::win_sendevent(win->ext_win_id, &wev);
|
||||
}
|
||||
|
||||
static bool route_fullscreen_external_mouse(gui::DesktopState* ds,
|
||||
const gui::MouseEvent& ev,
|
||||
int mx,
|
||||
int my,
|
||||
uint8_t buttons,
|
||||
uint8_t prev) {
|
||||
for (int i = ds->window_count - 1; i >= 0; i--) {
|
||||
gui::Window* win = &ds->windows[i];
|
||||
if (win->state == gui::WIN_MINIMIZED || win->state == gui::WIN_CLOSED)
|
||||
continue;
|
||||
if (!desktop_window_fullscreen(win))
|
||||
return false;
|
||||
|
||||
if (i != ds->window_count - 1) {
|
||||
gui::desktop_raise_window(ds, i);
|
||||
win = &ds->windows[ds->window_count - 1];
|
||||
}
|
||||
forward_external_mouse(win, ev, mx, my, buttons, prev);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Desktop Mouse Handling
|
||||
// ============================================================================
|
||||
@@ -104,11 +145,6 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ds->launcher_open) {
|
||||
desktop_handle_launcher_mouse(ds);
|
||||
return;
|
||||
}
|
||||
|
||||
int mx = ds->mouse.x;
|
||||
int my = ds->mouse.y;
|
||||
uint8_t buttons = ds->mouse.buttons;
|
||||
@@ -125,6 +161,19 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
ev.prev_buttons = prev;
|
||||
ev.scroll = ds->mouse.scrollDelta;
|
||||
|
||||
if (route_fullscreen_external_mouse(ds, ev, mx, my, buttons, prev)) {
|
||||
ds->app_menu_open = false;
|
||||
ds->ctx_menu_open = false;
|
||||
ds->vol_popup_open = false;
|
||||
ds->net_popup_open = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ds->launcher_open) {
|
||||
desktop_handle_launcher_mouse(ds);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle context menu clicks
|
||||
if (ds->ctx_menu_open) {
|
||||
if (left_pressed) {
|
||||
@@ -183,7 +232,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
win->frame = {0, PANEL_HEIGHT, ds->screen_w / 2, ds->screen_h - PANEL_HEIGHT};
|
||||
win->state = WIN_MAXIMIZED;
|
||||
if (!win->external) {
|
||||
Rect cr = win->content_rect();
|
||||
Rect cr = desktop_content_rect(win);
|
||||
if (cr.w != win->content_w || cr.h != win->content_h) {
|
||||
if (win->content) montauk::free(win->content);
|
||||
win->content_w = cr.w;
|
||||
@@ -192,7 +241,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
montauk::memset(win->content, 0xFF, cr.w * cr.h * 4);
|
||||
}
|
||||
} else {
|
||||
Rect cr = win->content_rect();
|
||||
Rect cr = desktop_content_rect(win);
|
||||
Montauk::WinEvent rev;
|
||||
montauk::memset(&rev, 0, sizeof(rev));
|
||||
rev.type = 2;
|
||||
@@ -205,7 +254,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
win->frame = {ds->screen_w / 2, PANEL_HEIGHT, ds->screen_w / 2, ds->screen_h - PANEL_HEIGHT};
|
||||
win->state = WIN_MAXIMIZED;
|
||||
if (!win->external) {
|
||||
Rect cr = win->content_rect();
|
||||
Rect cr = desktop_content_rect(win);
|
||||
if (cr.w != win->content_w || cr.h != win->content_h) {
|
||||
if (win->content) montauk::free(win->content);
|
||||
win->content_w = cr.w;
|
||||
@@ -214,7 +263,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
montauk::memset(win->content, 0xFF, cr.w * cr.h * 4);
|
||||
}
|
||||
} else {
|
||||
Rect cr = win->content_rect();
|
||||
Rect cr = desktop_content_rect(win);
|
||||
Montauk::WinEvent rev;
|
||||
montauk::memset(&rev, 0, sizeof(rev));
|
||||
rev.type = 2;
|
||||
@@ -271,7 +320,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
win->resizing = false;
|
||||
// Reallocate content buffer if dimensions changed (skip for external)
|
||||
if (!win->external) {
|
||||
Rect cr = win->content_rect();
|
||||
Rect cr = desktop_content_rect(win);
|
||||
if (cr.w != win->content_w || cr.h != win->content_h) {
|
||||
if (win->content) montauk::free(win->content);
|
||||
win->content_w = cr.w;
|
||||
@@ -281,7 +330,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
}
|
||||
win->dirty = true;
|
||||
} else {
|
||||
Rect cr = win->content_rect();
|
||||
Rect cr = desktop_content_rect(win);
|
||||
Montauk::WinEvent rev;
|
||||
montauk::memset(&rev, 0, sizeof(rev));
|
||||
rev.type = 2;
|
||||
@@ -505,92 +554,94 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
Window* win = &ds->windows[i];
|
||||
if (win->state == WIN_MINIMIZED || win->state == WIN_CLOSED) continue;
|
||||
|
||||
// Check close button
|
||||
Rect close_r = win->close_btn_rect();
|
||||
if (close_r.contains(mx, my)) {
|
||||
desktop_close_window(ds, i);
|
||||
return;
|
||||
}
|
||||
if (!desktop_window_fullscreen(win)) {
|
||||
// Check close button
|
||||
Rect close_r = win->close_btn_rect();
|
||||
if (close_r.contains(mx, my)) {
|
||||
desktop_close_window(ds, i);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check minimize button
|
||||
Rect min_r = win->min_btn_rect();
|
||||
if (min_r.contains(mx, my)) {
|
||||
win->state = WIN_MINIMIZED;
|
||||
if (ds->focused_window == i) {
|
||||
ds->focused_window = -1;
|
||||
for (int j = ds->window_count - 1; j >= 0; j--) {
|
||||
if (ds->windows[j].state == WIN_NORMAL || ds->windows[j].state == WIN_MAXIMIZED) {
|
||||
ds->focused_window = j;
|
||||
ds->windows[j].focused = true;
|
||||
break;
|
||||
// Check minimize button
|
||||
Rect min_r = win->min_btn_rect();
|
||||
if (min_r.contains(mx, my)) {
|
||||
win->state = WIN_MINIMIZED;
|
||||
if (ds->focused_window == i) {
|
||||
ds->focused_window = -1;
|
||||
for (int j = ds->window_count - 1; j >= 0; j--) {
|
||||
if (ds->windows[j].state == WIN_NORMAL || ds->windows[j].state == WIN_MAXIMIZED) {
|
||||
ds->focused_window = j;
|
||||
ds->windows[j].focused = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Check maximize button
|
||||
Rect max_r = win->max_btn_rect();
|
||||
if (max_r.contains(mx, my)) {
|
||||
if (win->state == WIN_MAXIMIZED) {
|
||||
win->frame = win->saved_frame;
|
||||
win->state = WIN_NORMAL;
|
||||
} else {
|
||||
win->saved_frame = win->frame;
|
||||
win->frame = {0, PANEL_HEIGHT, ds->screen_w, ds->screen_h - PANEL_HEIGHT};
|
||||
win->state = WIN_MAXIMIZED;
|
||||
}
|
||||
// Reallocate content buffer for local windows only
|
||||
if (!win->external) {
|
||||
Rect cr = win->content_rect();
|
||||
if (cr.w != win->content_w || cr.h != win->content_h) {
|
||||
if (win->content) montauk::free(win->content);
|
||||
win->content_w = cr.w;
|
||||
win->content_h = cr.h;
|
||||
win->content = (uint32_t*)montauk::alloc(cr.w * cr.h * 4);
|
||||
montauk::memset(win->content, 0xFF, cr.w * cr.h * 4);
|
||||
// Check maximize button
|
||||
Rect max_r = win->max_btn_rect();
|
||||
if (max_r.contains(mx, my)) {
|
||||
if (win->state == WIN_MAXIMIZED) {
|
||||
win->frame = win->saved_frame;
|
||||
win->state = WIN_NORMAL;
|
||||
} else {
|
||||
win->saved_frame = win->frame;
|
||||
win->frame = {0, PANEL_HEIGHT, ds->screen_w, ds->screen_h - PANEL_HEIGHT};
|
||||
win->state = WIN_MAXIMIZED;
|
||||
}
|
||||
} else {
|
||||
Rect cr = win->content_rect();
|
||||
Montauk::WinEvent rev;
|
||||
montauk::memset(&rev, 0, sizeof(rev));
|
||||
rev.type = 2;
|
||||
rev.resize.w = cr.w;
|
||||
rev.resize.h = cr.h;
|
||||
montauk::win_sendevent(win->ext_win_id, &rev);
|
||||
// Reallocate content buffer for local windows only
|
||||
if (!win->external) {
|
||||
Rect cr = desktop_content_rect(win);
|
||||
if (cr.w != win->content_w || cr.h != win->content_h) {
|
||||
if (win->content) montauk::free(win->content);
|
||||
win->content_w = cr.w;
|
||||
win->content_h = cr.h;
|
||||
win->content = (uint32_t*)montauk::alloc(cr.w * cr.h * 4);
|
||||
montauk::memset(win->content, 0xFF, cr.w * cr.h * 4);
|
||||
}
|
||||
} else {
|
||||
Rect cr = desktop_content_rect(win);
|
||||
Montauk::WinEvent rev;
|
||||
montauk::memset(&rev, 0, sizeof(rev));
|
||||
rev.type = 2;
|
||||
rev.resize.w = cr.w;
|
||||
rev.resize.h = cr.h;
|
||||
montauk::win_sendevent(win->ext_win_id, &rev);
|
||||
}
|
||||
desktop_raise_window(ds, i);
|
||||
return;
|
||||
}
|
||||
desktop_raise_window(ds, i);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check resize edges (before titlebar drag, so corner grabs work)
|
||||
if (win->state != WIN_MAXIMIZED) {
|
||||
ResizeEdge edge = hit_test_resize_edge(win->frame, mx, my);
|
||||
if (edge != RESIZE_NONE) {
|
||||
// Check resize edges (before titlebar drag, so corner grabs work)
|
||||
if (win->state != WIN_MAXIMIZED) {
|
||||
ResizeEdge edge = hit_test_resize_edge(win->frame, mx, my);
|
||||
if (edge != RESIZE_NONE) {
|
||||
desktop_raise_window(ds, i);
|
||||
int new_idx = ds->window_count - 1;
|
||||
ds->windows[new_idx].resizing = true;
|
||||
ds->windows[new_idx].resize_edge = edge;
|
||||
ds->windows[new_idx].resize_start_frame = ds->windows[new_idx].frame;
|
||||
ds->windows[new_idx].resize_start_mx = mx;
|
||||
ds->windows[new_idx].resize_start_my = my;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check titlebar (start drag)
|
||||
Rect tb = win->titlebar_rect();
|
||||
if (tb.contains(mx, my)) {
|
||||
desktop_raise_window(ds, i);
|
||||
int new_idx = ds->window_count - 1;
|
||||
ds->windows[new_idx].resizing = true;
|
||||
ds->windows[new_idx].resize_edge = edge;
|
||||
ds->windows[new_idx].resize_start_frame = ds->windows[new_idx].frame;
|
||||
ds->windows[new_idx].resize_start_mx = mx;
|
||||
ds->windows[new_idx].resize_start_my = my;
|
||||
ds->windows[new_idx].dragging = true;
|
||||
ds->windows[new_idx].drag_offset_x = mx - ds->windows[new_idx].frame.x;
|
||||
ds->windows[new_idx].drag_offset_y = my - ds->windows[new_idx].frame.y;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check titlebar (start drag)
|
||||
Rect tb = win->titlebar_rect();
|
||||
if (tb.contains(mx, my)) {
|
||||
desktop_raise_window(ds, i);
|
||||
int new_idx = ds->window_count - 1;
|
||||
ds->windows[new_idx].dragging = true;
|
||||
ds->windows[new_idx].drag_offset_x = mx - ds->windows[new_idx].frame.x;
|
||||
ds->windows[new_idx].drag_offset_y = my - ds->windows[new_idx].frame.y;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check content area
|
||||
Rect cr = win->content_rect();
|
||||
Rect cr = desktop_content_rect(win);
|
||||
if (cr.contains(mx, my)) {
|
||||
desktop_raise_window(ds, i);
|
||||
int new_idx = ds->window_count - 1;
|
||||
@@ -630,7 +681,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
if (!left_pressed && ds->focused_window >= 0) {
|
||||
Window* win = &ds->windows[ds->focused_window];
|
||||
if (win->state != WIN_MINIMIZED && win->state != WIN_CLOSED) {
|
||||
Rect cr = win->content_rect();
|
||||
Rect cr = desktop_content_rect(win);
|
||||
// Forward if mouse is over content (hover/move) or button is held/released (drag continuity)
|
||||
if (cr.contains(mx, my) || left_held || left_released) {
|
||||
if (win->external) {
|
||||
@@ -655,7 +706,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
// Handle scroll events on focused window
|
||||
if (ev.scroll != 0 && ds->focused_window >= 0) {
|
||||
Window* win = &ds->windows[ds->focused_window];
|
||||
Rect cr = win->content_rect();
|
||||
Rect cr = desktop_content_rect(win);
|
||||
if (cr.contains(mx, my)) {
|
||||
if (win->external) {
|
||||
Montauk::WinEvent wev;
|
||||
@@ -696,12 +747,30 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
|
||||
}
|
||||
|
||||
void gui::desktop_handle_keyboard(DesktopState* ds, const Montauk::KeyEvent& key) {
|
||||
if (desktop_handle_launcher_keyboard(ds, key)) {
|
||||
if (ds->screen_locked) {
|
||||
handle_lock_keyboard(ds, key);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ds->screen_locked) {
|
||||
handle_lock_keyboard(ds, key);
|
||||
for (int i = ds->window_count - 1; i >= 0; i--) {
|
||||
Window* win = &ds->windows[i];
|
||||
if (win->state == WIN_MINIMIZED || win->state == WIN_CLOSED)
|
||||
continue;
|
||||
if (!desktop_window_fullscreen(win))
|
||||
break;
|
||||
|
||||
Montauk::WinEvent ev;
|
||||
montauk::memset(&ev, 0, sizeof(ev));
|
||||
ev.type = 0; // key
|
||||
ev.key = key;
|
||||
montauk::win_sendevent(win->ext_win_id, &ev);
|
||||
ds->launcher_open = false;
|
||||
ds->app_menu_open = false;
|
||||
ds->ctx_menu_open = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (desktop_handle_launcher_keyboard(ds, key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -419,6 +419,7 @@ bool desktop_poll_external_windows(DesktopState* ds) {
|
||||
if (ds->windows[i].external && ds->windows[i].ext_win_id == extId) {
|
||||
found = true;
|
||||
bool remapRequested = false;
|
||||
bool wasFullscreen = desktop_window_fullscreen(&ds->windows[i]);
|
||||
uint64_t currentVa = (uint64_t)(uintptr_t)ds->windows[i].content;
|
||||
if (ds->windows[i].content_w != extWins[e].width ||
|
||||
ds->windows[i].content_h != extWins[e].height) {
|
||||
@@ -436,6 +437,26 @@ bool desktop_poll_external_windows(DesktopState* ds) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (ds->windows[i].ext_flags != extWins[e].flags) {
|
||||
ds->windows[i].ext_flags = extWins[e].flags;
|
||||
bool isFullscreen = desktop_window_fullscreen(&ds->windows[i]);
|
||||
if (isFullscreen) {
|
||||
if (!wasFullscreen) ds->windows[i].saved_frame = ds->windows[i].frame;
|
||||
ds->windows[i].frame = {0, 0, ds->screen_w, ds->screen_h};
|
||||
ds->windows[i].state = WIN_NORMAL;
|
||||
} else if (wasFullscreen) {
|
||||
ds->windows[i].frame = ds->windows[i].saved_frame;
|
||||
ds->windows[i].state = WIN_NORMAL;
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
if (desktop_window_fullscreen(&ds->windows[i]) &&
|
||||
(ds->windows[i].frame.x != 0 || ds->windows[i].frame.y != 0 ||
|
||||
ds->windows[i].frame.w != ds->screen_w || ds->windows[i].frame.h != ds->screen_h)) {
|
||||
ds->windows[i].frame = {0, 0, ds->screen_w, ds->screen_h};
|
||||
ds->windows[i].state = WIN_NORMAL;
|
||||
changed = true;
|
||||
}
|
||||
// Update dirty flag and cursor
|
||||
if (extWins[e].dirty) {
|
||||
ds->windows[i].dirty = true;
|
||||
@@ -524,6 +545,12 @@ bool desktop_poll_external_windows(DesktopState* ds) {
|
||||
win->app_data = nullptr;
|
||||
win->external = true;
|
||||
win->ext_win_id = extId;
|
||||
win->ext_cursor = extWins[e].cursor;
|
||||
win->ext_flags = extWins[e].flags;
|
||||
if (desktop_window_fullscreen(win)) {
|
||||
win->frame = {0, 0, ds->screen_w, ds->screen_h};
|
||||
win->state = WIN_NORMAL;
|
||||
}
|
||||
|
||||
// Unfocus previous window
|
||||
if (ds->focused_window >= 0 && ds->focused_window < ds->window_count) {
|
||||
|
||||
@@ -39,6 +39,8 @@ int gui::desktop_create_window(DesktopState* ds, const char* title, int x, int y
|
||||
win->app_data = nullptr;
|
||||
win->external = false;
|
||||
win->ext_win_id = -1;
|
||||
win->ext_cursor = 0;
|
||||
win->ext_flags = 0;
|
||||
|
||||
// Unfocus previous window
|
||||
if (ds->focused_window >= 0 && ds->focused_window < ds->window_count) {
|
||||
@@ -131,50 +133,53 @@ void gui::desktop_draw_window(DesktopState* ds, int idx) {
|
||||
int y = win->frame.y;
|
||||
int w = win->frame.w;
|
||||
int h = win->frame.h;
|
||||
bool fullscreen = desktop_window_fullscreen(win);
|
||||
|
||||
// Draw shadow
|
||||
if (ds->settings.show_shadows)
|
||||
draw_shadow(fb, x, y, w, h, SHADOW_SIZE, colors::SHADOW);
|
||||
if (!fullscreen) {
|
||||
// Draw shadow
|
||||
if (ds->settings.show_shadows)
|
||||
draw_shadow(fb, x, y, w, h, SHADOW_SIZE, colors::SHADOW);
|
||||
|
||||
// Draw window body
|
||||
fb.fill_rect(x, y, w, h, colors::WINDOW_BG);
|
||||
// Draw window body
|
||||
fb.fill_rect(x, y, w, h, colors::WINDOW_BG);
|
||||
|
||||
// Draw titlebar
|
||||
Color tb_bg = win->focused ? colors::TITLEBAR_BG : Color::from_rgb(0xE8, 0xE8, 0xE8);
|
||||
fb.fill_rect(x, y, w, TITLEBAR_HEIGHT, tb_bg);
|
||||
// Draw titlebar
|
||||
Color tb_bg = win->focused ? colors::TITLEBAR_BG : Color::from_rgb(0xE8, 0xE8, 0xE8);
|
||||
fb.fill_rect(x, y, w, TITLEBAR_HEIGHT, tb_bg);
|
||||
|
||||
// Draw border
|
||||
draw_rect(fb, x, y, w, h, colors::BORDER);
|
||||
// Titlebar bottom separator
|
||||
draw_hline(fb, x, y + TITLEBAR_HEIGHT - 1, w, colors::BORDER);
|
||||
// Draw border
|
||||
draw_rect(fb, x, y, w, h, colors::BORDER);
|
||||
// Titlebar bottom separator
|
||||
draw_hline(fb, x, y + TITLEBAR_HEIGHT - 1, w, colors::BORDER);
|
||||
|
||||
// Draw window buttons (macOS style: close, minimize, maximize)
|
||||
Rect close_r = win->close_btn_rect();
|
||||
Rect min_r = win->min_btn_rect();
|
||||
Rect max_r = win->max_btn_rect();
|
||||
// Draw window buttons (macOS style: close, minimize, maximize)
|
||||
Rect close_r = win->close_btn_rect();
|
||||
Rect min_r = win->min_btn_rect();
|
||||
Rect max_r = win->max_btn_rect();
|
||||
|
||||
fill_circle(fb, close_r.x + BTN_RADIUS, close_r.y + BTN_RADIUS, BTN_RADIUS, colors::CLOSE_BTN);
|
||||
fill_circle(fb, min_r.x + BTN_RADIUS, min_r.y + BTN_RADIUS, BTN_RADIUS, colors::MIN_BTN);
|
||||
fill_circle(fb, max_r.x + BTN_RADIUS, max_r.y + BTN_RADIUS, BTN_RADIUS, colors::MAX_BTN);
|
||||
fill_circle(fb, close_r.x + BTN_RADIUS, close_r.y + BTN_RADIUS, BTN_RADIUS, colors::CLOSE_BTN);
|
||||
fill_circle(fb, min_r.x + BTN_RADIUS, min_r.y + BTN_RADIUS, BTN_RADIUS, colors::MIN_BTN);
|
||||
fill_circle(fb, max_r.x + BTN_RADIUS, max_r.y + BTN_RADIUS, BTN_RADIUS, colors::MAX_BTN);
|
||||
|
||||
// Draw title text centered in titlebar (after buttons)
|
||||
int title_x = x + 12 + 44 + BTN_RADIUS * 2 + 12; // after buttons
|
||||
int title_y = y + (TITLEBAR_HEIGHT - system_font_height()) / 2;
|
||||
int title_w = text_width(win->title);
|
||||
// Center in remaining space
|
||||
int remaining_w = w - (title_x - x) - 12;
|
||||
if (remaining_w > title_w) {
|
||||
title_x += (remaining_w - title_w) / 2;
|
||||
}
|
||||
draw_text(fb, title_x, title_y, win->title, colors::TEXT_COLOR);
|
||||
// Draw title text centered in titlebar (after buttons)
|
||||
int title_x = x + 12 + 44 + BTN_RADIUS * 2 + 12; // after buttons
|
||||
int title_y = y + (TITLEBAR_HEIGHT - system_font_height()) / 2;
|
||||
int title_w = text_width(win->title);
|
||||
// Center in remaining space
|
||||
int remaining_w = w - (title_x - x) - 12;
|
||||
if (remaining_w > title_w) {
|
||||
title_x += (remaining_w - title_w) / 2;
|
||||
}
|
||||
draw_text(fb, title_x, title_y, win->title, colors::TEXT_COLOR);
|
||||
|
||||
// Call app draw callback to render content (skip during resize — buffer is old size)
|
||||
if (win->on_draw && !win->resizing) {
|
||||
win->on_draw(win, fb);
|
||||
// Call app draw callback to render content (skip during resize — buffer is old size)
|
||||
if (win->on_draw && !win->resizing) {
|
||||
win->on_draw(win, fb);
|
||||
}
|
||||
}
|
||||
|
||||
// Blit content buffer to framebuffer (clip to actual buffer size during resize)
|
||||
Rect cr = win->content_rect();
|
||||
Rect cr = desktop_content_rect(win);
|
||||
if (win->content) {
|
||||
if (win->external && (cr.w != win->content_w || cr.h != win->content_h)) {
|
||||
// Nearest-neighbor scale for external windows (fixed-size shared buffer)
|
||||
|
||||
Reference in New Issue
Block a user