Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Input style keys survive a restart (#147): the style's defaults reach actions registered after it is applied
islandmed3c06cf62c37d
diff --git a/changes/fix-input-style-startup.md b/changes/fix-input-style-startup.mdnew file mode 100644index 00000000..edc4ba73--- /dev/null+++ b/changes/fix-input-style-startup.md@@ -0,0 +1,15 @@+---+whats_new: **Input style keys after a restart**: the Blender, Classic and Maya styles keep every key when SculptForge+ starts again (F for the Size slider in the Blender style, 9 for a Snapshot with the Classic keys).+fixed: The input style's keys for the Size slider, the Material picker and Save Snapshot came back as the Classic+ defaults after a restart (Blender style: F no longer showed the Size slider, S and M opened the Size slider and the+ Material picker) until the style was picked again in Preferences > Input; your own rebinds were not affected+ (#147, thanks @Velisariy).+testers:+ - Any OS: Preferences > Input > Blender; quit and reopen; hover the model and press F: the Size slider opens.+ - Any OS: Classic, rebind Size at cursor in Controls (F1); quit and reopen: your key is kept, M opens the Material picker.+---+Cause: ui.json is read (and the style applied) before the actions are registered; the Library's actions+(LibraryBrowser.cpp) are registered last and brought back their own defaults. ActionRegistry now remembers the+style's defaults and applies them when an action is added. The UI test's `restart` re-registers those actions as a+start does (tests/ui/input_style_restart.sfui), so it fails without the fix.diff --git a/src/app/Actions.cpp b/src/app/Actions.cppindex 107e5e19..7680247c 100644--- a/src/app/Actions.cpp+++ b/src/app/Actions.cpp@@ -204,6 +204,8 @@ std::vector<std::string> chordKeys(std::string_view chord) {void ActionRegistry::add(Action a) {++revision_;+ for (const auto& [id, chord] : styleDefaults_)+ if (id == a.id) a.shortcut = chord;for (auto& existing : actions_)if (existing.id == a.id) {existing = std::move(a);@@ -259,6 +261,9 @@ bool ActionRegistry::handleKey(SDL_Keycode key, SDL_Keymod mods) {}void ActionRegistry::setDefaultShortcut(std::string_view id, std::string chord) {+ auto it = std::find_if(styleDefaults_.begin(), styleDefaults_.end(), [&](const auto& d) { return d.first == id; });+ if (it == styleDefaults_.end()) styleDefaults_.emplace_back(std::string(id), chord);+ else it->second = chord;for (auto& a : actions_)if (a.id == id && a.shortcut != chord) {a.shortcut = std::move(chord);diff --git a/src/app/Actions.h b/src/app/Actions.hindex 09057b80..9ef0b404 100644--- a/src/app/Actions.h+++ b/src/app/Actions.h@@ -59,7 +59,8 @@ public:std::string shortcutText(std::string_view id) const; // effective chord after user overridesvoid setShortcut(std::string_view id, std::string chord); // user override ("" clears)// Changes an action's default chord (Preferences > Input switches between the classic and SculptForge- // defaults); user overrides still win.+ // defaults); user overrides still win. Remembered for an action added later (#147: the style is applied+ // before every action is registered, and add() would otherwise bring back the action's own default).void setDefaultShortcut(std::string_view id, std::string chord);Json overridesToJson() const;void overridesFromJson(const Json& j);@@ -87,6 +88,7 @@ private:const std::vector<Chord>& chordsOf(size_t index) const;std::vector<Action> actions_;std::vector<std::pair<std::string, std::string>> overrides_; // id -> chord+ std::vector<std::pair<std::string, std::string>> styleDefaults_; // id -> chord, from setDefaultShortcutstd::vector<std::string> recent_;unsigned revision_ = 0;mutable unsigned chordsRevision_ = ~0u;diff --git a/src/app/App.h b/src/app/App.hindex 0dcea562..be6436f0 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -1903,6 +1903,7 @@ private:// Falloff (U / I / O), the classic mask and face group keys, Shift-constrained straight strokes and the// Shift+click, release Shift, drag roll.void registerInputActions();+ void registerLibraryActions(); // the Library's and pickers' actions (LibraryBrowser.cpp)void applyInputStyle(); // the style's default shortcuts (1-0 brushes or 9 QuickSave; I = RGB or Intensity)bool classicStyle() const { return uiPrefs_.inputStyle == 0; }bool blenderStyle() const { return uiPrefs_.inputStyle == 2; }diff --git a/src/app/Config.cpp b/src/app/Config.cppindex edac560a..8afebc2c 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -977,6 +977,7 @@ void App::restartPrefsForTest(const std::string& uiJson) {std::string err;if (fileExists(uiConfigPath()) && !readUiConfig(uiConfigPath(), err, true)) status_ = err;applyInputStyle();+ registerLibraryActions(); // as at a start: registered after the style is applied (#147)layoutBaseline_ = layoutKey();prefsSavedKey_ = prefsKey();prefsSaveAt_ = 0.0;diff --git a/src/app/LibraryBrowser.cpp b/src/app/LibraryBrowser.cppindex 7a7553f5..d413ce47 100644--- a/src/app/LibraryBrowser.cpp+++ b/src/app/LibraryBrowser.cpp@@ -1186,6 +1186,16 @@ void App::initLibraryBrowser() {return ok;});+ registerLibraryActions();++ // classic opens the Library at startup on the Project tab (never in tests, renders or recordings).+ if (uiPrefs_.libraryAtStartup && interactive() && options_.uiTest.empty() && options_.openPath.empty() &&+ !options_.blender)+ libraryBrowser_.show(LibraryTab::Project);+}++// After initActions (and after the input style was first applied): the style's keys still reach them (#147).+void App::registerLibraryActions() {auto add = [this](const char* id, const char* label, const char* icon, const char* palette, const char* shortcut,const char* description, std::function<void()> run, std::function<bool()> checked = nullptr) {Action a;@@ -1231,11 +1241,6 @@ void App::initLibraryBrowser() {"status bar names the file. Material sets its size (twice the view by default), shape (the view's, 1:1, ""16:9, 9:16, 4:3) and format (PNG or JPG).",[this] { runSaveRender(); });-- // classic opens the Library at startup on the Project tab (never in tests, renders or recordings).- if (uiPrefs_.libraryAtStartup && interactive() && options_.uiTest.empty() && options_.openPath.empty() &&- !options_.blender)- libraryBrowser_.show(LibraryTab::Project);}void App::drawLibraryBrowserUi() {diff --git a/tests/test_actions.cpp b/tests/test_actions.cppindex ebe3614a..e097c235 100644--- a/tests/test_actions.cpp+++ b/tests/test_actions.cpp@@ -67,6 +67,23 @@ TEST(action_registry_keys_and_overrides) {CHECK(reg.recent().size() == 2 && reg.recent()[0] == "edit.undo");}+TEST(action_registry_style_default_before_add) {+ // #147: the input style is applied at startup before every action is registered; one added afterwards keeps+ // the style's key, not its own default, and a user override still wins.+ ActionRegistry reg;+ reg.setDefaultShortcut("ui.size_popup", "F");+ reg.add({"ui.size_popup", "Size at cursor", nullptr, "", "Draw", "S", "", [] {}, nullptr, nullptr});+ CHECK(reg.shortcutText("ui.size_popup") == "F");+ reg.add({"ui.size_popup", "Size at cursor", nullptr, "", "Draw", "S", "", [] {}, nullptr, nullptr}); // again+ CHECK(reg.shortcutText("ui.size_popup") == "F");+ reg.setDefaultShortcut("ui.size_popup", "S"); // the style changes+ CHECK(reg.shortcutText("ui.size_popup") == "S");+ reg.setShortcut("ui.size_popup", "Ctrl+Alt+S");+ reg.setDefaultShortcut("ui.size_popup", "F");+ reg.add({"ui.size_popup", "Size at cursor", nullptr, "", "Draw", "S", "", [] {}, nullptr, nullptr});+ CHECK(reg.shortcutText("ui.size_popup") == "Ctrl+Alt+S");+}+TEST(action_registry_commands) {CommandRegistry commands;ActionRegistry reg;diff --git a/tests/ui/data/prefs/ui_input_style_blender.json b/tests/ui/data/prefs/ui_input_style_blender.jsonnew file mode 100644index 00000000..73f38142--- /dev/null+++ b/tests/ui/data/prefs/ui_input_style_blender.json@@ -0,0 +1,9 @@+{+ "version": 1,+ "shortcuts": {+ "file.quicksave": "Ctrl+Alt+9"+ },+ "prefs": {+ "inputStyle": "blender"+ }+}diff --git a/tests/ui/data/prefs/ui_input_style_classic.json b/tests/ui/data/prefs/ui_input_style_classic.jsonnew file mode 100644index 00000000..88910717--- /dev/null+++ b/tests/ui/data/prefs/ui_input_style_classic.json@@ -0,0 +1,9 @@+{+ "version": 1,+ "shortcuts": {+ "ui.size_popup": "Ctrl+Alt+S"+ },+ "prefs": {+ "inputStyle": "classic"+ }+}diff --git a/tests/ui/data/prefs/ui_input_style_maya.json b/tests/ui/data/prefs/ui_input_style_maya.jsonnew file mode 100644index 00000000..8bcce989--- /dev/null+++ b/tests/ui/data/prefs/ui_input_style_maya.json@@ -0,0 +1,9 @@+{+ "version": 1,+ "shortcuts": {+ "view.reset": "Ctrl+Alt+H"+ },+ "prefs": {+ "inputStyle": "maya"+ }+}diff --git a/tests/ui/data/prefs/ui_input_style_sculptforge.json b/tests/ui/data/prefs/ui_input_style_sculptforge.jsonnew file mode 100644index 00000000..36baec8a--- /dev/null+++ b/tests/ui/data/prefs/ui_input_style_sculptforge.json@@ -0,0 +1,9 @@+{+ "version": 1,+ "shortcuts": {+ "ui.picker.material": "Ctrl+Alt+M"+ },+ "prefs": {+ "inputStyle": "sculptforge"+ }+}diff --git a/tests/ui/input_style_restart.sfui b/tests/ui/input_style_restart.sfuinew file mode 100644index 00000000..ac3a5c85--- /dev/null+++ b/tests/ui/input_style_restart.sfui@@ -0,0 +1,53 @@+# The input style's keys survive a restart (#147, @Velisariy: Blender style, F showed the Size slider until SculptForge+# was quit and reopened). ui.json is read before the actions are registered, and the Library's (S Size, M Material,+# 9 Snapshot) come last: each style's keys reach them anyway, and the artist's own rebinds still win. One ui.json per+# style, each with one rebind (data/prefs/ui_input_style_*.json).++# --- Blender: F is the Size slider, M the Mask brush, no Material key; the rebound Snapshot key stays.+restart data/prefs/ui_input_style_blender.json+wait 0.2+run new_sphere+expect_value input_style == 2+expect_shortcut ui.size_popup F+expect_shortcut ui.picker.material+expect_shortcut mask.brush M+expect_shortcut view.frame Home+expect_shortcut brush.smooth S+expect_shortcut file.quicksave Ctrl+Alt+9+expect_value shortcut_conflicts == 0+hover_window 0.5 0.5+key f+expect_value size_popup_open == 1+key escape+expect_value size_popup_open == 0++# --- Classic sculpting keys: S Size (rebound here: Ctrl+Alt+S), M Material, 9 Snapshot.+restart data/prefs/ui_input_style_classic.json+wait 0.2+expect_value input_style == 0+expect_shortcut ui.size_popup Ctrl+Alt+S+expect_shortcut ui.picker.material M+expect_shortcut file.quicksave 9+expect_shortcut view.frame F+expect_value shortcut_conflicts == 0++# --- SculptForge: S Size, 1-0 brushes, no Snapshot key; the rebound Material key stays.+restart data/prefs/ui_input_style_sculptforge.json+wait 0.2+expect_value input_style == 1+expect_shortcut ui.size_popup S+expect_shortcut ui.picker.material Ctrl+Alt+M+expect_shortcut file.quicksave+expect_shortcut brush.standard 1+expect_value shortcut_conflicts == 0++# --- Maya: the Classic sculpting keys plus Alt+F; the rebound Reset view key stays.+restart data/prefs/ui_input_style_maya.json+wait 0.2+expect_value input_style == 3+expect_shortcut ui.size_popup S+expect_shortcut ui.picker.material M+expect_shortcut file.quicksave 9+expect_shortcut view.frame_selected Alt+F / Numpad .+expect_shortcut view.reset Ctrl+Alt+H+expect_value shortcut_conflicts == 0