diff options
-rw-r--r-- | intern/ghost/GHOST_Types.h | 2 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_EventTrackpad.h | 4 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemCocoa.mm | 26 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_userpref.py | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_userdef_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_userdef.c | 7 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 3 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_types.h | 4 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_query.c | 32 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 3 |
12 files changed, 70 insertions, 25 deletions
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h index 547be04ac86..a03b59d14b0 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -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 { diff --git a/intern/ghost/intern/GHOST_EventTrackpad.h b/intern/ghost/intern/GHOST_EventTrackpad.h index 3bbb29821a1..d4f9d0f2b55 100644 --- a/intern/ghost/intern/GHOST_EventTrackpad.h +++ b/intern/ghost/intern/GHOST_EventTrackpad.h @@ -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; } diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 19753bca2c7..c1c1070d346 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -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; diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py index 91871acfbc5..ce9543d7dc4 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -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") diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index fb5844d24f3..af71306cc3b 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -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) { diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index c16cd94d90d..f9de462813f 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -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; } diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index a9bd915ba48..f673b193a39 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -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; diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 2ae084d5a5d..1bfa8547ca4 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -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) diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index b81ef14f21c..fd0b99fb9ae 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -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 diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index a8d24205268..7fa2851cbf3 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -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; /** diff --git a/source/blender/windowmanager/intern/wm_event_query.c b/source/blender/windowmanager/intern/wm_event_query.c index db80296bdb8..a996796104b 100644 --- a/source/blender/windowmanager/intern/wm_event_query.c +++ b/source/blender/windowmanager/intern/wm_event_query.c @@ -423,6 +423,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 * \{ */ diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 071951abda3..bf970aa2034 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -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; } |