Keymaps: take into account DPI for tweak/drag/pie thresholds.

The intention is to fix a too low default threshold on high DPI screen.
Users with high DPI screens that have increased the threshold to fix this
or liked the lower threshold will need to lower it again.

This is still somewhat of a guess, ideally this would be based on the
physical distance travalled, and maybe different per type of input device.
However we do not have access to this information, and hope this gives a
better default.
This commit is contained in:
2018-11-21 19:25:13 +01:00
parent e8b9ff78dc
commit 0a3cf08364
5 changed files with 14 additions and 12 deletions

View File

@@ -1721,7 +1721,7 @@ static bool ui_but_drag_init(
/* prevent other WM gestures to start while we try to drag */
WM_gestures_remove(C);
if (ABS(data->dragstartx - event->x) + ABS(data->dragstarty - event->y) > U.dragthreshold) {
if (ABS(data->dragstartx - event->x) + ABS(data->dragstarty - event->y) > U.dragthreshold * U.dpi_fac) {
button_activate_state(C, but, BUTTON_STATE_EXIT);
data->cancel = true;
@@ -8691,7 +8691,7 @@ float ui_block_calc_pie_segment(uiBlock *block, const float event_xy[2])
len = normalize_v2_v2(block->pie_data.pie_dir, seg2);
if (len < U.pie_menu_threshold * U.pixelsize)
if (len < U.pie_menu_threshold * U.dpi_fac)
block->pie_data.flags |= UI_PIE_INVALID_DIR;
else
block->pie_data.flags &= ~UI_PIE_INVALID_DIR;
@@ -9409,7 +9409,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle
but = ui_but_find_active_in_region(menu->region);
if (but && (U.pie_menu_confirm > 0) &&
(dist >= U.pie_menu_threshold + U.pie_menu_confirm))
(dist >= U.dpi_fac * (U.pie_menu_threshold + U.pie_menu_confirm)))
{
if (but)
return ui_but_pie_menu_apply(C, menu, but, true);
@@ -9436,7 +9436,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle
/* here instead, we use the offset location to account for the initial direction timeout */
if ((U.pie_menu_confirm > 0) &&
(dist >= U.pie_menu_threshold + U.pie_menu_confirm))
(dist >= U.dpi_fac * (U.pie_menu_threshold + U.pie_menu_confirm)))
{
block->pie_data.flags |= UI_PIE_GESTURE_END_WAIT;
copy_v2_v2(block->pie_data.last_pos, event_xy);

View File

@@ -2957,7 +2957,7 @@ static void ui_litem_layout_root_radial(uiLayout *litem)
ui_item_size(item, &itemw, &itemh);
ui_item_position(item, x - itemw / 2, y + U.pixelsize * (U.pie_menu_threshold + 9.0f), itemw, itemh);
ui_item_position(item, x - itemw / 2, y + U.dpi_fac * (U.pie_menu_threshold + 9.0f), itemw, itemh);
}
}

View File

@@ -4566,8 +4566,8 @@ void ui_draw_pie_center(uiBlock *block)
float *pie_dir = block->pie_data.pie_dir;
float pie_radius_internal = U.pixelsize * U.pie_menu_threshold;
float pie_radius_external = U.pixelsize * (U.pie_menu_threshold + 7.0f);
float pie_radius_internal = U.dpi_fac * U.pie_menu_threshold;
float pie_radius_external = U.dpi_fac * (U.pie_menu_threshold + 7.0f);
int subd = 40;
@@ -4609,8 +4609,8 @@ void ui_draw_pie_center(uiBlock *block)
immUnbindProgram();
if (U.pie_menu_confirm > 0 && !(block->pie_data.flags & (UI_PIE_INVALID_DIR | UI_PIE_CLICK_STYLE))) {
float pie_confirm_radius = U.pixelsize * (pie_radius_internal + U.pie_menu_confirm);
float pie_confirm_external = U.pixelsize * (pie_radius_internal + U.pie_menu_confirm + 7.0f);
float pie_confirm_radius = U.dpi_fac * (pie_radius_internal + U.pie_menu_confirm);
float pie_confirm_external = U.dpi_fac * (pie_radius_internal + U.pie_menu_confirm + 7.0f);
const char col[4] = {btheme->tui.wcol_pie_menu.text_sel[0],
btheme->tui.wcol_pie_menu.text_sel[1],

View File

@@ -2612,8 +2612,9 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
if (wm_action_not_handled(action)) {
if (event->check_drag) {
wmWindow *win = CTX_wm_window(C);
if ((abs(event->x - win->eventstate->prevclickx)) >= U.tweak_threshold ||
(abs(event->y - win->eventstate->prevclicky)) >= U.tweak_threshold)
float tweak_threshold = U.tweak_threshold * U.dpi_fac;
if ((abs(event->x - win->eventstate->prevclickx)) >= tweak_threshold ||
(abs(event->y - win->eventstate->prevclicky)) >= tweak_threshold)
{
int x = event->x;
int y = event->y;

View File

@@ -130,7 +130,8 @@ int wm_gesture_evaluate(wmGesture *gesture)
rcti *rect = gesture->customdata;
int dx = BLI_rcti_size_x(rect);
int dy = BLI_rcti_size_y(rect);
if (abs(dx) + abs(dy) > U.tweak_threshold) {
float tweak_threshold = U.tweak_threshold * U.dpi_fac;
if (abs(dx) + abs(dy) > tweak_threshold) {
int theta = round_fl_to_int(4.0f * atan2f((float)dy, (float)dx) / (float)M_PI);
int val = EVT_GESTURE_W;