Skip to content

feat(settings): schema-driven serialization and window state persistence#330

Merged
lc-soft merged 2 commits into
developfrom
copilot/pr2
Jun 12, 2026
Merged

feat(settings): schema-driven serialization and window state persistence#330
lc-soft merged 2 commits into
developfrom
copilot/pr2

Conversation

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Adds schema-driven config serialization and persistent window state management on top of the settings infrastructure introduced in #329.

Architecture

  • ini_doc (new): generic INI document with get/set for int/bool/string and section iteration
  • setting_field (new): setting_field_def_t schema + DEFINE_SETTING_{INT,BOOL}_FIELD macros; out-of-range or missing values fall back to defaults and are rewritten to file on flush
  • lcui_settings.c: refactored as a base module exposing ini_doc_t* access and two callback lists (deserialize on load, serialize on flush), without reverse dependencies on concrete modules
  • lcui_rendering.c / lcui_window_state.c: own their state and register callbacks during module init

Public API

Settings lifecycle (include/LCUI/settings/base.h)

  • bool lcui_settings_is_loaded(void);
  • bool lcui_settings_load(void);
  • bool lcui_settings_flush(void);
  • void lcui_settings_unload(void);

Rendering (include/LCUI/settings/rendering.h)

  • bool lcui_get_rendering(lcui_rendering_settings_t *out);
  • bool lcui_set_rendering(const lcui_rendering_settings_t *in);

Fields: fps_cap, parallel_threads, paint_flashing. Out-of-range values are rejected.

Window state (include/LCUI/settings/window_state.h)

  • bool lcui_get_window_state(const char *id, lcui_window_state_t *out);
  • bool lcui_set_window_state(const char *id, const lcui_window_state_t *in);
  • bool lcui_bind_window_state(ui_widget_t *widget, const char *id);

Fields: x, y, width, height, maximized, stored under [window.<id>] sections. Invalid or out-of-bounds sections are dropped from file on flush.

App identification (include/LCUI/app.h)

  • bool lcui_set_app_id(const char *app_id); � reverse-domain format recommended, e.g. "com.example.myapp". Allowed characters: alphanumeric, ., _, -.

PTK changes

  • New PTK_EVENT_CREATE event dispatched after native window creation, enabling deferred state restore for display-mode switches that rebuild the window
  • Added ptk_window_get_position / ptk_window_set_maximized / ptk_window_is_maximized for geometry and maximized-state access
  • X11 backend queries and sets maximized state via _NET_WM_STATE with _NET_WM_STATE_MAXIMIZED_HORZ and _NET_WM_STATE_MAXIMIZED_VERT
  • Win32 backend tracks window position in the driver struct

Test coverage (new test_settings suite)

  • Rendering settings round-trip, validation, and flush normalization
  • Window state round-trip, missing-section handling, invalid-section removal, id validation
  • Binding flow: deferred resize before window creation, restore on create, save on close
  • Integration tests verify settings persist across load/unload cycles

Examples

// Rendering
lcui_rendering_settings_t r = {
    .fps_cap = 144,
    .parallel_threads = 8,
    .paint_flashing = true
};
lcui_set_rendering(&r);
// Window state: bind a widget to a persistent id
lcui_bind_window_state(widget, "main");

The widget is resized to the saved dimensions immediately (before native window creation), and the new window has geometry/maximized applied once the PTK_EVENT_CREATE fires. On PTK_EVENT_CLOSE, the current state is saved back to [window.main].

// Manual get/set
lcui_window_state_t state = {
    .x = 120, .y = 80,
    .width = 960, .height = 640,
    .maximized = false
};
lcui_set_window_state("main", &state);
lcui_window_state_t out;
lcui_get_window_state("main", &out);
// App identity
lcui_set_app_id("com.example.myapp");
lcui_settings_load();  // reads $XDG_CONFIG_HOME/com.example.myapp/settings.ini

Copilot AI changed the title [WIP] feat: add persistent window state management and settings binding feat: add persistent window state management and settings binding Jun 8, 2026
Copilot AI requested a review from lc-soft June 8, 2026 11:49

@lc-soft lc-soft left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 按照审核意见做修改。

Comment thread src/lcui_settings.c Outdated
Comment thread src/lcui_settings.c Outdated
Comment thread src/lcui_settings.c Outdated
Comment thread src/lcui_settings.c Outdated
Comment thread src/lcui_settings.c Outdated
Comment thread src/lcui_settings.c Outdated

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 按照审核意见做修改。

已按审核意见完成调整,最新提交:3cceafa。

Copilot AI requested a review from lc-soft June 8, 2026 13:16

@lc-soft lc-soft left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 修改。

Comment thread tests/integration/test_settings.c Outdated
Comment thread src/lcui_settings.c

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 修改。

已修改,提交:3371dc6、3c47c0e。

Copilot AI requested a review from lc-soft June 8, 2026 14:06

@lc-soft lc-soft left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/settings/rendering.c Outdated
Comment thread src/settings/rendering.c Outdated
Comment thread src/lcui_settings.c Outdated
Comment thread src/settings/window_state.c Outdated
Comment thread src/settings/window_state.c Outdated
Comment thread src/settings/window_state.c Outdated
Comment thread src/settings/window_state.c Outdated

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

已修改,提交:9db7483。

Copilot AI requested a review from lc-soft June 9, 2026 11:13

@lc-soft lc-soft left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/lcui_window_state.c
Comment thread src/lcui_settings.c Outdated

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

已修改,提交:95512dc、07f93b2、e80636e。

Copilot AI requested a review from lc-soft June 9, 2026 11:49

@lc-soft lc-soft left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 按评审意见做修改。改完后总结变更内容,并解释各项变更的理由。

Comment thread include/LCUI/settings.h Outdated
Comment thread include/LCUI/settings.h Outdated
Comment thread src/lcui_settings.h
Comment thread src/lcui_settings.c Outdated
Comment thread src/lcui_rendering.c Outdated
Comment thread src/lcui_rendering.c Outdated

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 按评审意见做修改。改完后总结变更内容,并解释各项变更的理由。

已按评审意见修改,最新提交:9a7fe1d。

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.93197% with 221 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.70%. Comparing base (7264d24) to head (6b24c29).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
src/lcui_window_state.c 68.16% 46 Missing and 32 partials ⚠️
src/ini_doc.c 69.44% 43 Missing and 23 partials ⚠️
lib/ptk/src/linux/x11app.c 59.70% 19 Missing and 8 partials ⚠️
src/lcui_settings.c 79.24% 8 Missing and 14 partials ⚠️
lib/ptk/src/linux/fbapp.c 0.00% 15 Missing ⚠️
src/setting_field.c 80.55% 2 Missing and 5 partials ⚠️
src/lcui_rendering.c 83.33% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #330      +/-   ##
===========================================
+ Coverage    62.99%   63.70%   +0.71%     
===========================================
  Files          195      199       +4     
  Lines        18573    19112     +539     
  Branches      2481     2598     +117     
===========================================
+ Hits         11700    12176     +476     
+ Misses        5950     5946       -4     
- Partials       923      990      +67     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Per-window state with [window.<id>] sections in settings.ini
- Settings module split into rendering and window_state subsystems
- Schema-driven (de)serialization with DEFINE_SETTING_INT/BOOL_FIELD macros
- Listener-based change notification via deserialize/serialize callbacks
- Integration tests for get/set, validation, and bind/restore lifecycle
@lc-soft lc-soft changed the title feat: add persistent window state management and settings binding feat(settings): schema-driven serialization and window state persistence Jun 12, 2026
@lc-soft lc-soft marked this pull request as ready for review June 12, 2026 14:37
- Use project-local clang-format from node_modules/.bin instead of system
  PATH to avoid version mismatches between CI and development environments
- Print clang-format version and binary path in CI logs for debugging
- Add format:check script to package.json so `npm run format:check` works
- Add `needs: format` to build job so formatting failures block the build
  and don't waste CI resources
@lc-soft lc-soft merged commit 812b80b into develop Jun 12, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants