Page MenuHome

Read the 'directionInvertedFromDevice' property and push it to the event system
ClosedPublic

Authored by Yevgeny Makarov (jenkm) on Oct 31 2020, 9:54 PM.

Details

Summary

Read the directionInvertedFromDevice property and push it to the event system.

This allows us to remove the "Trackpad Natural" use preference,
see the explanation in D8550: Trackpad: change the default of "Trackpad Natural" preference.

Diff Detail

Repository
rB Blender

Event Timeline

Yevgeny Makarov (jenkm) requested review of this revision.Oct 31 2020, 9:54 PM
Yevgeny Makarov (jenkm) created this revision.

And these, I'm not sure where to put it.

/**
 * User may change the scroll behavior, and the deltas are automatically inverted. 
 * These functions return the absolute deltas, swipe up/right gives positive values.
 */

int WM_absolute_delta_x(const wmEvent *event)
{
  int dx = event->x - event->prevx;

  if (!event->inverted) {
    dx = -dx;
  }

  return dx;
}

int WM_absolute_delta_y(const wmEvent *event)
{
  int dy = event->y - event->prevy;

  if (!event->inverted) {
    dy = -dy;
  }

  return dy;
}

An automatic solution and getting rid of the preference entirely is great.

These functions would go in wm_event_query.c and would have the WM_event prefix like other functions there.

Would you prefer a different name?

WM_event_absolute_scroll_delta_x(event);
WM_event_absolute_delta_x(event);
WM_event_abs_delta_x(event);

The name "absolute delta" is a bit confusing, that sounds like the absolute value of a delta.

I think it would be best to combine all the proposed change relates to this in one patch. This change, removal of the user preferences, and changes to operators. Because I'm confused about how it all is supposed to work together.

Maybe the cleanest API would be to make wmEvent work like NSEvent. Use absolute coordinates for x, y, prevx and prevy, and then also add a deltax and deltay that may be inverted.

Yevgeny Makarov (jenkm) updated this revision to Diff 30627.EditedNov 2 2020, 7:41 PM

Currently USER_TRACKPAD_NATURAL is only used in two places, ui_pan_to_scroll and for 3d view rotation. See in this patch.


I further use it in several places in my patches, in these ways:

float dx = event->prevx - event->x;
if (U.uiflag2 & USER_TRACKPAD_NATURAL) {
  dx = -dx;
}

https://developer.blender.org/D8675

const int invert = (U.uiflag2 & USER_TRACKPAD_NATURAL) ? 1 : -1;
const float fac = 0.005 * invert * (event->y - event->prevy);

https://developer.blender.org/D8811
https://developer.blender.org/D8812

const bool user_zoom_invert = (U.uiflag & USER_ZOOM_INVERT) != 0;
const bool user_trackpad_natural = (U.uiflag2 & USER_TRACKPAD_NATURAL) != 0;

if (user_zoom_invert != user_trackpad_natural) {
  delta *= -1;
}

https://developer.blender.org/D8522
https://developer.blender.org/D8527


Use absolute coordinates for x, y, prevx and prevy, and then also add a deltax and deltay that may be inverted.

It looks good, but it will change the current behavior of the event->prevy and the delta (event->y - event->prevy), so it will need to be rechecked everywhere and replaced with event->deltay if needed. And it will break compatibility, I guess.

As an alternative to the event->is_natural_direction and WM_event_natural_delta_x(), WM_event_natural_delta_y(),
it can be the opposite, event->natural_deltax, event->natural_deltay.

Renaming.

event->is_natural_direction

WM_event_natural_delta_x()
WM_event_natural_delta_y()

@Brecht Van Lommel (brecht) You might also want to take a look at how this will work for Windows. D7660 D8028

Ok, the current apprach is fine then if it's the simpler change overall. We can always further refactor it later.

The patch looks good from a quick glance at the code, but I need to test it still.

This revision was not accepted when it landed; it landed in state Needs Review.Nov 9 2020, 1:51 PM
This revision was automatically updated to reflect the committed changes.