diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 853dfccc626..9224f612510 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -551,6 +551,7 @@ class _draw_tool_settings_context_mode:
row.prop(brush.curves_sculpt_settings, "density_mode", text="", expand=True)
row = layout.row(align=True)
row.prop(brush.curves_sculpt_settings, "minimum_distance")
+ row.operator_context = 'INVOKE_REGION_WIN'
row.operator("sculpt_curves.min_distance_edit", text="", icon='DRIVER_DISTANCE')
row = layout.row(align=True)
row.enabled = brush.curves_sculpt_settings.density_mode != 'REMOVE'
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
index 32a6a7a9b0f..716f757ef52 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
@@ -906,8 +906,18 @@ static void SCULPT_CURVES_OT_select_grow(wmOperatorType *ot)
namespace min_distance_edit {
+/**
+ * There is a bug with the OPTYPE_DEPENDS_ON_CURSOR where the draw callback from
+ * WM_paint_cursor* has the wrong context (the region is the header, not the viewport). */
+#define HACK_CURSOR_CTX_UI
+
static bool min_distance_edit_poll(bContext *C)
{
+#ifndef HACK_CURSOR_CTX_UI
+ if (!CTX_wm_region_view3d(C)) {
+ return false;
+ }
+#endif
Object *ob = CTX_data_active_object(C);
if (ob == nullptr) {
return false;
@@ -948,12 +958,20 @@ struct MinDistanceEditData {
/** The operator uses a new cursor, but the existing cursors should be restored afterwards. */
ListBase orig_paintcursors;
void *cursor;
+#ifdef HACK_CURSOR_CTX_UI
+ ARegion *region;
+ RegionView3D *rv3d;
+#endif
};
static int calculate_points_per_side(bContext *C, MinDistanceEditData &op_data)
{
Scene *scene = CTX_data_scene(C);
+#ifndef HACK_CURSOR_CTX_UI
ARegion *region = CTX_wm_region(C);
+#else
+ ARegion *region = op_data.region;
+#endif
const float min_distance = op_data.brush->curves_sculpt_settings->minimum_distance;
float brush_radius = BKE_brush_size_get(scene, op_data.brush);
@@ -1035,8 +1053,13 @@ static void min_distance_edit_draw(bContext *C, int UNUSED(x), int UNUSED(y), vo
GPU_matrix_push_projection();
GPU_blend(GPU_BLEND_ALPHA);
- RegionView3D *rv3d = CTX_wm_region_view3d(C);
+#ifndef HACK_CURSOR_CTX_UI
ARegion *region = CTX_wm_region(C);
+ RegionView3D *rv3d = CTX_wm_region_view3d(C);
+#else
+ ARegion *region = op_data.region;
+ RegionView3D *rv3d = op_data.rv3d;
+#endif
wmWindow *win = CTX_wm_window(C);
/* It does the same as: `view3d_operator_needs_opengl(C);`. */
@@ -1171,9 +1194,16 @@ static int min_distance_edit_invoke(bContext *C, wmOperator *op, const wmEvent *
op_data->orig_paintcursors = wm->paintcursors;
BLI_listbase_clear(&wm->paintcursors);
- /* Add minimum distance paint cursor. */
+/* Add minimum distance paint cursor. */
+#ifndef HACK_CURSOR_CTX_UI
+ op_data->cursor = WM_paint_cursor_activate(
+ SPACE_VIEW3D, RGN_TYPE_WINDOW, op->type->poll, min_distance_edit_draw, op_data);
+#else
+ op_data->region = CTX_wm_region(C);
+ op_data->rv3d = CTX_wm_region_view3d(C);
op_data->cursor = WM_paint_cursor_activate(
SPACE_TYPE_ANY, RGN_TYPE_ANY, op->type->poll, min_distance_edit_draw, op_data);
+#endif
WM_event_add_modal_handler(C, op);
ED_region_tag_redraw(region);