macOS: follow system preference for natural trackpad scroll direction
And remove Blender preference, which was expected to be set to match the system preference for correct behavior. Instead just handle this automatically. Differential Revision: https://developer.blender.org/D9402
This commit is contained in:
parent
0c4d12986a
commit
055ed335a1
|
@ -470,6 +470,8 @@ typedef struct {
|
|||
GHOST_TInt32 deltaX;
|
||||
/** The y-delta (currently only for scroll subtype) of the trackpad event */
|
||||
GHOST_TInt32 deltaY;
|
||||
/** The delta is inverted from the device due to system preferences. */
|
||||
char isDirectionInverted;
|
||||
} GHOST_TEventTrackpadData;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -45,7 +45,8 @@ class GHOST_EventTrackpad : public GHOST_Event {
|
|||
GHOST_TInt32 x,
|
||||
GHOST_TInt32 y,
|
||||
GHOST_TInt32 deltaX,
|
||||
GHOST_TInt32 deltaY)
|
||||
GHOST_TInt32 deltaY,
|
||||
bool isDirectionInverted)
|
||||
: GHOST_Event(msec, GHOST_kEventTrackpad, window)
|
||||
{
|
||||
m_trackpadEventData.subtype = subtype;
|
||||
|
@ -53,6 +54,7 @@ class GHOST_EventTrackpad : public GHOST_Event {
|
|||
m_trackpadEventData.y = y;
|
||||
m_trackpadEventData.deltaX = deltaX;
|
||||
m_trackpadEventData.deltaY = deltaY;
|
||||
m_trackpadEventData.isDirectionInverted = isDirectionInverted;
|
||||
m_data = &m_trackpadEventData;
|
||||
}
|
||||
|
||||
|
|
|
@ -1716,8 +1716,14 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
|
|||
}
|
||||
window->clientToScreenIntern(mousePos.x, mousePos.y, x, y);
|
||||
|
||||
pushEvent(new GHOST_EventTrackpad(
|
||||
[event timestamp] * 1000, window, GHOST_kTrackpadEventScroll, x, y, dx, dy));
|
||||
pushEvent(new GHOST_EventTrackpad([event timestamp] * 1000,
|
||||
window,
|
||||
GHOST_kTrackpadEventScroll,
|
||||
x,
|
||||
y,
|
||||
dx,
|
||||
dy,
|
||||
[event isDirectionInvertedFromDevice]));
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -1731,15 +1737,22 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
|
|||
x,
|
||||
y,
|
||||
[event magnification] * 125.0 + 0.1,
|
||||
0));
|
||||
0,
|
||||
false));
|
||||
} break;
|
||||
|
||||
case NSEventTypeSmartMagnify: {
|
||||
NSPoint mousePos = [event locationInWindow];
|
||||
GHOST_TInt32 x, y;
|
||||
window->clientToScreenIntern(mousePos.x, mousePos.y, x, y);
|
||||
pushEvent(new GHOST_EventTrackpad(
|
||||
[event timestamp] * 1000, window, GHOST_kTrackpadEventSmartMagnify, x, y, 0, 0));
|
||||
pushEvent(new GHOST_EventTrackpad([event timestamp] * 1000,
|
||||
window,
|
||||
GHOST_kTrackpadEventSmartMagnify,
|
||||
x,
|
||||
y,
|
||||
0,
|
||||
0,
|
||||
false));
|
||||
} break;
|
||||
|
||||
case NSEventTypeRotate: {
|
||||
|
@ -1752,7 +1765,8 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
|
|||
x,
|
||||
y,
|
||||
[event rotation] * -5.0,
|
||||
0));
|
||||
0,
|
||||
false));
|
||||
}
|
||||
default:
|
||||
return GHOST_kFailure;
|
||||
|
|
|
@ -1489,7 +1489,6 @@ class USERPREF_PT_navigation_orbit(NavigationPanel, CenterAlignMixIn, Panel):
|
|||
bl_label = "Orbit & Pan"
|
||||
|
||||
def draw_centered(self, context, layout):
|
||||
import sys
|
||||
prefs = context.preferences
|
||||
inputs = prefs.inputs
|
||||
view = prefs.view
|
||||
|
@ -1505,9 +1504,6 @@ class USERPREF_PT_navigation_orbit(NavigationPanel, CenterAlignMixIn, Panel):
|
|||
|
||||
col.separator()
|
||||
|
||||
if sys.platform == "darwin":
|
||||
col.prop(inputs, "use_trackpad_natural", text="Natural Trackpad Direction")
|
||||
|
||||
col = layout.column(heading="Auto")
|
||||
col.prop(inputs, "use_auto_perspective", text="Perspective")
|
||||
col.prop(inputs, "use_mouse_depth_navigate", text="Depth")
|
||||
|
|
|
@ -504,7 +504,7 @@ bool ui_but_is_editing(const uiBut *but)
|
|||
void ui_pan_to_scroll(const wmEvent *event, int *type, int *val)
|
||||
{
|
||||
static int lastdy = 0;
|
||||
int dy = event->prevy - event->y;
|
||||
int dy = WM_event_absolute_delta_y(event);
|
||||
|
||||
/* This event should be originally from event->type,
|
||||
* converting wrong event into wheel is bad, see T33803. */
|
||||
|
@ -518,10 +518,6 @@ void ui_pan_to_scroll(const wmEvent *event, int *type, int *val)
|
|||
lastdy += dy;
|
||||
|
||||
if (abs(lastdy) > (int)UI_UNIT_Y) {
|
||||
if (U.uiflag2 & USER_TRACKPAD_NATURAL) {
|
||||
dy = -dy;
|
||||
}
|
||||
|
||||
*val = KM_PRESS;
|
||||
|
||||
if (dy > 0) {
|
||||
|
|
|
@ -998,7 +998,7 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
int event_xy[2];
|
||||
|
||||
if (event->type == MOUSEPAN) {
|
||||
if (U.uiflag2 & USER_TRACKPAD_NATURAL) {
|
||||
if (event->is_direction_inverted) {
|
||||
event_xy[0] = 2 * event->x - event->prevx;
|
||||
event_xy[1] = 2 * event->y - event->prevy;
|
||||
}
|
||||
|
|
|
@ -1073,7 +1073,7 @@ typedef enum eUserpref_UI_Flag {
|
|||
typedef enum eUserpref_UI_Flag2 {
|
||||
USER_UIFLAG2_UNUSED_0 = (1 << 0), /* cleared */
|
||||
USER_REGION_OVERLAP = (1 << 1),
|
||||
USER_TRACKPAD_NATURAL = (1 << 2),
|
||||
USER_UIFLAG2_UNUSED_2 = (1 << 2),
|
||||
USER_UIFLAG2_UNUSED_3 = (1 << 3), /* dirty */
|
||||
} eUserpref_UI_Flag2;
|
||||
|
||||
|
|
|
@ -5936,13 +5936,6 @@ static void rna_def_userdef_input(BlenderRNA *brna)
|
|||
RNA_def_property_range(prop, 0, 32);
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Wheel Scroll Lines", "Number of lines scrolled at a time with the mouse wheel");
|
||||
|
||||
prop = RNA_def_property(srna, "use_trackpad_natural", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "uiflag2", USER_TRACKPAD_NATURAL);
|
||||
RNA_def_property_ui_text(prop,
|
||||
"Trackpad Natural",
|
||||
"If your system uses 'natural' scrolling, this option keeps consistent "
|
||||
"trackpad usage throughout the UI");
|
||||
}
|
||||
|
||||
static void rna_def_userdef_keymap(BlenderRNA *brna)
|
||||
|
|
|
@ -857,6 +857,9 @@ void WM_event_ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4]);
|
|||
float WM_event_tablet_data(const struct wmEvent *event, int *pen_flip, float tilt[2]);
|
||||
bool WM_event_is_tablet(const struct wmEvent *event);
|
||||
|
||||
int WM_event_absolute_delta_x(const struct wmEvent *event);
|
||||
int WM_event_absolute_delta_y(const struct wmEvent *event);
|
||||
|
||||
#ifdef WITH_INPUT_IME
|
||||
bool WM_event_is_ime_switch(const struct wmEvent *event);
|
||||
#endif
|
||||
|
|
|
@ -595,6 +595,10 @@ typedef struct wmEvent {
|
|||
/** Ascii, unicode, mouse coords, angles, vectors, dragdrop info. */
|
||||
void *customdata;
|
||||
|
||||
/* True if the operating system inverted the delta x/y values and resulting
|
||||
* prev x/y values, for natural scroll direction. For absolute scroll direction,
|
||||
* the delta must be negated again. */
|
||||
char is_direction_inverted;
|
||||
} wmEvent;
|
||||
|
||||
/**
|
||||
|
|
|
@ -422,6 +422,38 @@ bool WM_event_is_tablet(const struct wmEvent *event)
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Event Scroll's Absolute Deltas
|
||||
*
|
||||
* User may change the scroll behavior, and the deltas are automatically inverted.
|
||||
* These functions return the absolute direction, swipe up/right gives positive values.
|
||||
*
|
||||
* \{ */
|
||||
|
||||
int WM_event_absolute_delta_x(const struct wmEvent *event)
|
||||
{
|
||||
int dx = event->x - event->prevx;
|
||||
|
||||
if (!event->is_direction_inverted) {
|
||||
dx = -dx;
|
||||
}
|
||||
|
||||
return dx;
|
||||
}
|
||||
|
||||
int WM_event_absolute_delta_y(const struct wmEvent *event)
|
||||
{
|
||||
int dy = event->y - event->prevy;
|
||||
|
||||
if (!event->is_direction_inverted) {
|
||||
dy = -dy;
|
||||
}
|
||||
|
||||
return dy;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Event IME Input Access
|
||||
* \{ */
|
||||
|
|
|
@ -4397,6 +4397,9 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
|
|||
event.prevx = event.x - pd->deltaX;
|
||||
event.prevy = event.y - (-pd->deltaY);
|
||||
|
||||
/* The direction is inverted from the device due to system preferences. */
|
||||
event.is_direction_inverted = pd->isDirectionInverted;
|
||||
|
||||
wm_event_add(win, &event);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue