From 1e3abc2271f24c80f357b21a6d18b7e8d56f1fc7 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 20 Jan 2024 12:57:38 -0300 Subject: [PATCH] Make middle click close tabs --- src/df/gfx/df_gfx.c | 10 ++++++++++ src/ui/ui_core.c | 31 +++++++++++++++++++++++++++++++ src/ui/ui_core.h | 1 + 3 files changed, 42 insertions(+) diff --git a/src/df/gfx/df_gfx.c b/src/df/gfx/df_gfx.c index 64e659c6..087c268d 100644 --- a/src/df/gfx/df_gfx.c +++ b/src/df/gfx/df_gfx.c @@ -5344,6 +5344,11 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D ui_ctx_menu_open(ws->tab_ctx_menu_key, sig.box->key, v2f32(0, sig.box->rect.y1-sig.box->rect.y0)); ws->tab_ctx_menu_view = df_handle_from_view(view); } + else if(sig.middle_clicked) + { + DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_CloseTab)); + } } } } @@ -5768,6 +5773,11 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D ui_ctx_menu_open(ws->tab_ctx_menu_key, sig.box->key, v2f32(0, sig.box->rect.y1 - sig.box->rect.y0)); ws->tab_ctx_menu_view = df_handle_from_view(view); } + else if(sig.middle_clicked) + { + DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_CloseTab)); + } if(sig.released) { df_panel_notify_mutation(ws, panel); diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 7e9760de..e50c65ce 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -2262,6 +2262,8 @@ ui_signal_from_box(UI_Box *box) //- rjf: gather events OS_Event *left_press = 0; OS_Event *left_release = 0; + OS_Event *middle_press = 0; + OS_Event *middle_release = 0; OS_Event *right_press = 0; OS_Event *right_release = 0; for(OS_Event *evt = ui_state->events->first; evt != 0; evt = evt->next) @@ -2276,6 +2278,14 @@ ui_signal_from_box(UI_Box *box) { left_release = evt; } + if(middle_press == 0 && evt->kind == OS_EventKind_Press && evt->key == OS_Key_MiddleMouseButton) + { + middle_press = evt; + } + if(middle_release == 0 && evt->kind == OS_EventKind_Release && evt->key == OS_Key_MiddleMouseButton) + { + middle_release = evt; + } if(right_press == 0 && evt->kind == OS_EventKind_Press && evt->key == OS_Key_RightMouseButton) { right_press = evt; @@ -2374,6 +2384,27 @@ ui_signal_from_box(UI_Box *box) ui_state->active_box_key[Side_Min] = ui_key_zero(); } + // n12: active management (middle click) + if(!disabled && + ui_key_match(ui_state->hot_box_key, box->key) && + ui_key_match(ui_state->active_box_key[Side_Min], ui_key_zero()) && + middle_press != 0) + { + os_eat_event(ui_state->events, middle_press); + result.pressed = 1; + ui_state->active_box_key[Side_Min] = box->key; + } + else if(!disabled && + ui_key_match(ui_state->active_box_key[Side_Min], box->key) && + middle_release != 0) + { + os_eat_event(ui_state->events, middle_release); + result.released = 1; + result.middle_clicked = mouse_is_over; + ui_state->hot_box_key = mouse_is_over ? box->key : ui_key_zero(); + ui_state->active_box_key[Side_Min] = ui_key_zero(); + } + // rjf: active management (right click) if(!disabled && ui_key_match(ui_state->hot_box_key, box->key) && diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 4e642629..3359d733 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -327,6 +327,7 @@ struct UI_Signal B8 clicked :1; B8 keyboard_clicked :1; B8 double_clicked :1; + B8 middle_clicked :1; B8 right_clicked :1; B8 pressed :1; B8 released :1;