Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make middle click close tabs #88

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/df/gfx/df_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_CloseTab));
}
}
}
}
Expand Down Expand Up @@ -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(&params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_CloseTab));
}
if(sig.released)
{
df_panel_notify_mutation(ws, panel);
Expand Down
31 changes: 31 additions & 0 deletions src/ui/ui_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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) &&
Expand Down
1 change: 1 addition & 0 deletions src/ui/ui_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down