From 081aaa6c5542155f0cddb402f74cf4b94c262da5 Mon Sep 17 00:00:00 2001 From: Sean Kim Date: Mon, 30 Jun 2025 23:01:10 +0200 Subject: [PATCH] Fix #140668: Toggle brush support doesn't work with tool selection Toggle support for brushes was added back in 4.5 with 9e1e9b0859ef055ce71b555f825c8caafd2a5559. The intent of this feature is to allow for easy switching between a specified brush upon using a hotkey. Whils this behavior works well in the case of switching between brushes, the initial implementation didn't account for using other non-brush tools. To fix this issue, when activating a tool, if it doesn't handle brushes, clear the last active brush. Pull Request: https://projects.blender.org/blender/blender/pulls/141161 --- .../windowmanager/intern/wm_toolsystem.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_toolsystem.cc b/source/blender/windowmanager/intern/wm_toolsystem.cc index 65bf1b650d1..19f9d4740fb 100644 --- a/source/blender/windowmanager/intern/wm_toolsystem.cc +++ b/source/blender/windowmanager/intern/wm_toolsystem.cc @@ -472,10 +472,20 @@ static void toolsystem_brush_sync_for_texture_paint(Main *bmain, } } } +static void toolsystem_brush_clear_paint_reference(Scene *scene, bToolRef *tref) +{ + const PaintMode paint_mode = BKE_paintmode_get_from_tool(tref); + Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode); + if (!paint) { + return; + } + + BKE_paint_previous_asset_reference_clear(paint); +} /** \} */ -static void toolsystem_ref_link(Main *bmain, WorkSpace *workspace, bToolRef *tref) +static void toolsystem_ref_link(Main *bmain, Scene *scene, WorkSpace *workspace, bToolRef *tref) { bToolRef_Runtime *tref_rt = tref->runtime; if (tref_rt->gizmo_group[0]) { @@ -500,6 +510,9 @@ static void toolsystem_ref_link(Main *bmain, WorkSpace *workspace, bToolRef *tre toolsystem_brush_activate_from_toolref(bmain, workspace, tref); toolsystem_brush_sync_for_texture_paint(bmain, workspace, tref); } + else { + toolsystem_brush_clear_paint_reference(scene, tref); + } } static void toolsystem_refresh_ref(const bContext *C, WorkSpace *workspace, bToolRef *tref) @@ -508,7 +521,7 @@ static void toolsystem_refresh_ref(const bContext *C, WorkSpace *workspace, bToo return; } /* Currently same operation. */ - toolsystem_ref_link(CTX_data_main(C), workspace, tref); + toolsystem_ref_link(CTX_data_main(C), CTX_data_scene(C), workspace, tref); } void WM_toolsystem_refresh(const bContext *C, WorkSpace *workspace, const bToolKey *tkey) { @@ -624,7 +637,7 @@ void WM_toolsystem_ref_set_from_runtime(bContext *C, tref->runtime->keymap_fallback[0] = '\0'; } - toolsystem_ref_link(bmain, workspace, tref); + toolsystem_ref_link(bmain, CTX_data_scene(C), workspace, tref); toolsystem_refresh_screen_from_active_tool(bmain, workspace, tref);