feat: desktop - use MTK menu for desktop right-click menu

This commit is contained in:
2026-08-07 10:55:38 +02:00
parent 9eb21eb3e3
commit 0e1601be74
9 changed files with 83 additions and 99 deletions
+38 -41
View File
@@ -163,7 +163,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
if (route_fullscreen_external_mouse(ds, ev, mx, my, buttons, prev)) {
ds->app_menu_open = false;
ds->ctx_menu_open = false;
gui::mtk::context_menu_close(ds->ctx_menu);
ds->vol_popup_open = false;
ds->net_popup_open = false;
ds->wifi_popup_open = false;
@@ -176,41 +176,33 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
}
// Handle context menu clicks
if (ds->ctx_menu_open) {
if (left_pressed) {
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;
if (cmx + CTX_MENU_W > ds->screen_w) cmx = ds->screen_w - CTX_MENU_W;
if (cmy + cmh > ds->screen_h) cmy = ds->screen_h - cmh;
if (ds->ctx_menu.open) {
gui::mtk::ContextMenuItem ctx_items[DESKTOP_CTX_COUNT];
desktop_ctx_menu_items(ctx_items);
int action = gui::mtk::context_menu_handle_mouse(
ds->ctx_menu, ctx_items, DESKTOP_CTX_COUNT, mx, my, buttons, prev,
ds->screen_w, ds->screen_h, DESKTOP_CTX_MENU_W, DESKTOP_CTX_ITEM_H);
Rect ctx_rect = {cmx, cmy, CTX_MENU_W, cmh};
if (ctx_rect.contains(mx, my)) {
int rel_y = my - cmy - 4;
int item_idx = rel_y / CTX_ITEM_H;
if (item_idx >= 0 && item_idx < CTX_ITEM_COUNT) {
ds->ctx_menu_open = false;
switch (item_idx) {
case 0: open_terminal(ds); break;
case 1: open_filemanager(ds); break;
case 2: desktop_launch_builtin(ds, DESKTOP_BUILTIN_SYSTEM_CONFIGURATION); break;
case 3: desktop_launch_builtin(ds, DESKTOP_BUILTIN_SLEEP); break;
case 4: desktop_launch_builtin(ds, DESKTOP_BUILTIN_REBOOT); break;
case 5: desktop_launch_builtin(ds, DESKTOP_BUILTIN_SHUTDOWN); break;
}
return;
}
}
ds->ctx_menu_open = false;
switch (action) {
case DESKTOP_CTX_TERMINAL: open_terminal(ds); return;
case DESKTOP_CTX_FILES: open_filemanager(ds); return;
case DESKTOP_CTX_SETTINGS:
desktop_launch_builtin(ds, DESKTOP_BUILTIN_SYSTEM_CONFIGURATION);
return;
}
if (right_pressed) {
ds->ctx_menu_open = false;
case DESKTOP_CTX_SLEEP:
desktop_launch_builtin(ds, DESKTOP_BUILTIN_SLEEP);
return;
case DESKTOP_CTX_REBOOT:
desktop_launch_builtin(ds, DESKTOP_BUILTIN_REBOOT);
return;
case DESKTOP_CTX_SHUTDOWN:
desktop_launch_builtin(ds, DESKTOP_BUILTIN_SHUTDOWN);
return;
default: break;
}
// A click outside the menu just dismisses it; plain motion (CONSUMED)
// falls through so window hover and drags keep working.
if (action == gui::mtk::CONTEXT_MENU_DISMISSED) return;
}
// Check for ongoing window drags first
@@ -542,7 +534,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
ds->net_popup_open = false;
ds->wifi_popup_open = false;
ds->vol_popup_open = false;
ds->ctx_menu_open = false;
gui::mtk::context_menu_close(ds->ctx_menu);
return;
}
@@ -553,7 +545,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
ds->app_menu_open = false;
ds->net_popup_open = false;
ds->wifi_popup_open = false;
ds->ctx_menu_open = false;
gui::mtk::context_menu_close(ds->ctx_menu);
return;
}
@@ -563,7 +555,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
ds->app_menu_open = false;
ds->vol_popup_open = false;
ds->wifi_popup_open = false;
ds->ctx_menu_open = false;
gui::mtk::context_menu_close(ds->ctx_menu);
return;
}
@@ -573,7 +565,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
ds->app_menu_open = false;
ds->vol_popup_open = false;
ds->net_popup_open = false;
ds->ctx_menu_open = false;
gui::mtk::context_menu_close(ds->ctx_menu);
return;
}
// Window indicator buttons
@@ -725,7 +717,7 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
}
ds->app_menu_open = false;
ds->ctx_menu_open = false;
gui::mtk::context_menu_close(ds->ctx_menu);
ds->vol_popup_open = false;
}
@@ -792,9 +784,14 @@ void gui::desktop_handle_mouse(DesktopState* ds) {
}
}
if (!on_window) {
ds->ctx_menu_open = true;
ds->ctx_menu_x = mx;
ds->ctx_menu_y = my;
gui::mtk::context_menu_open(ds->ctx_menu, mx, my);
// Pin the menu inside the screen up front so hit-testing and
// drawing agree on where it landed.
Rect r = gui::mtk::context_menu_rect(ds->ctx_menu, DESKTOP_CTX_COUNT,
ds->screen_w, ds->screen_h,
DESKTOP_CTX_MENU_W, DESKTOP_CTX_ITEM_H);
ds->ctx_menu.x = r.x;
ds->ctx_menu.y = r.y;
ds->app_menu_open = false;
ds->net_popup_open = false;
ds->wifi_popup_open = false;
@@ -823,7 +820,7 @@ void gui::desktop_handle_keyboard(DesktopState* ds, const montauk::abi::KeyEvent
montauk::win_sendevent(win->ext_win_id, &ev);
ds->launcher_open = false;
ds->app_menu_open = false;
ds->ctx_menu_open = false;
gui::mtk::context_menu_close(ds->ctx_menu);
return;
}