Skip to content

Commit 8b0d286

Browse files
committed
[Display][Menu] Fix rendering sync issues
1 parent 581bb80 commit 8b0d286

File tree

12 files changed

+68
-58
lines changed

12 files changed

+68
-58
lines changed

users/drashna/display/display.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "drashna.h"
55
#include "display.h"
6+
#include "display/menu/menu.h"
67

78
#if defined(OLED_ENABLE) && defined(CUSTOM_OLED_DRIVER)
89
# include "display/oled/oled_stuff.h"
@@ -132,11 +133,9 @@ void keyboard_post_init_display_driver(void) {
132133
#if defined(QUANTUM_PAINTER_ENABLE) || defined(OLED_ENABLE)
133134
userspace_runtime_state.menu_state = (menu_state_t){
134135
# ifdef DISPLAY_MENU_ENABLED_DEFAULT
135-
.dirty = true,
136136
.is_in_menu = true,
137137
.selected_child = 0x01,
138138
# else
139-
.dirty = false,
140139
.is_in_menu = false,
141140
.selected_child = 0xFF,
142141
# endif // DISPLAY_MENU_ENABLED_DEFAULT
@@ -202,8 +201,7 @@ void display_sendchar_hook(uint8_t c) {
202201
}
203202

204203
void display_rotate_screen(bool clockwise) {
205-
void display_menu_set_dirty(void);
206-
display_menu_set_dirty();
204+
display_menu_set_dirty(true);
207205
#if defined(DISPLAY_FULL_ROTATION_ENABLE)
208206
if (clockwise) {
209207
userspace_config.display.rotation = (userspace_config.display.rotation + 1) % 4;

users/drashna/display/display.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ ifeq ($(strip $(CUSTOM_QUANTUM_PAINTER_ENABLE)), yes)
7474
$(USER_PATH)/display/painter/graphics.qgf.c \
7575
$(USER_PATH)/display/painter/qp_render_menu.c
7676

77-
ifeq ($(strip $(DISPLAY_MENU_ENABLED_DEFAULT)), yes)
78-
OPT_DEFS += -DDISPLAY_MENU_ENABLED_DEFAULT
79-
endif
8077
ifeq ($(strip $(MULTITHREADED_PAINTER_ENABLE)), yes)
8178
OPT_DEFS += -DMULTITHREADED_PAINTER_ENABLE
8279
endif
@@ -99,10 +96,13 @@ endif
9996

10097
ifeq ($(strip $(DISPLAY_DRIVER_REQUIRED)), yes)
10198
DEFERRED_EXEC_ENABLE = yes
99+
OPT_DEFS += -DDISPLAY_DRIVER_ENABLE
102100
SRC += $(USER_PATH)/display/display.c \
103101
$(USER_PATH)/display/menu/menu.c
104102

105-
OPT_DEFS += -DDISPLAY_DRIVER_ENABLE
103+
ifeq ($(strip $(DISPLAY_MENU_ENABLED_DEFAULT)), yes)
104+
OPT_DEFS += -DDISPLAY_MENU_ENABLED_DEFAULT
105+
endif
106106
ifeq ($(strip $(DISPLAY_KEYLOGGER_ENABLE)), yes)
107107
OPT_DEFS += -DDISPLAY_KEYLOGGER_ENABLE
108108
endif

users/drashna/display/menu/menu.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#ifndef DISPLAY_MENU_TIMEOUT
1717
# define DISPLAY_MENU_TIMEOUT 30000
1818
#endif // !DISPLAY_MENU_TIMEOUT
19-
deferred_token menu_deferred_token = INVALID_DEFERRED_TOKEN;
20-
bool has_flushed_menu = true;
19+
menu_state_runtime_t menu_state_runtime = {.dirty = true, .has_rendered = false};
20+
deferred_token menu_deferred_token = INVALID_DEFERRED_TOKEN;
2121

2222
menu_entry_t *get_current_menu(void) {
2323
if (userspace_runtime_state.menu_state.menu_stack[0] == 0xFF) {
@@ -94,10 +94,9 @@ bool menu_handle_input(menu_input_t input) {
9494
}
9595
}
9696
} else if (selected->flags & menu_flag_is_value) {
97-
userspace_runtime_state.menu_state.dirty = true;
98-
return selected->child.menu_handler(menu_input_right);
97+
menu_state_runtime.dirty = true;
98+
return selected->child.menu_handler(menu_input_enter);
9999
}
100-
101100
return false;
102101
case menu_input_up:
103102
userspace_runtime_state.menu_state.selected_child =
@@ -112,7 +111,7 @@ bool menu_handle_input(menu_input_t input) {
112111
case menu_input_left:
113112
case menu_input_right:
114113
if (selected->flags & menu_flag_is_value) {
115-
userspace_runtime_state.menu_state.dirty = true;
114+
menu_state_runtime.dirty = true;
116115
return selected->child.menu_handler(input);
117116
}
118117
return false;
@@ -290,7 +289,7 @@ uint8_t get_menu_scroll_offset(menu_entry_t *menu, uint8_t visible_entries) {
290289
return l_scroll_offset;
291290
}
292291

293-
void display_menu_set_dirty(void) {
294-
has_flushed_menu = false;
295-
userspace_runtime_state.menu_state.dirty = true;
292+
void display_menu_set_dirty(bool state) {
293+
menu_state_runtime.dirty = state;
294+
menu_state_runtime.has_rendered = !state;
296295
}

users/drashna/display/menu/menu.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ typedef enum _menu_input_t {
2525
menu_input_right,
2626
} menu_input_t;
2727

28+
typedef struct PACKED {
29+
bool dirty : 1;
30+
bool has_rendered : 1;
31+
} menu_state_runtime_t;
32+
extern menu_state_runtime_t menu_state_runtime;
33+
2834
typedef struct _menu_entry_t {
2935
menu_flags_t flags;
3036
const char *text;
@@ -43,5 +49,5 @@ menu_entry_t *get_current_menu(void);
4349
menu_entry_t *get_selected_menu_item(void);
4450
bool menu_handle_input(menu_input_t input);
4551
bool process_record_menu(uint16_t keycode, keyrecord_t *record);
46-
void display_menu_set_dirty(void);
52+
void display_menu_set_dirty(bool state);
4753
uint8_t get_menu_scroll_offset(menu_entry_t *menu, uint8_t visible_entries);

users/drashna/display/oled/oled_render_menu.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "oled_driver.h"
77

88
#define snprintf_nowarn(...) (snprintf(__VA_ARGS__) < 0 ? abort() : (void)0)
9-
extern bool has_flushed_menu;
109

1110
bool oled_render_menu(uint8_t col, uint8_t line, uint8_t num_of_lines, bool is_left) {
1211
uint8_t scroll_offset = 0;
@@ -15,15 +14,15 @@ bool oled_render_menu(uint8_t col, uint8_t line, uint8_t num_of_lines, bool is_l
1514

1615
if (userspace_runtime_state.menu_state.is_in_menu != last_state) {
1716
last_state = userspace_runtime_state.menu_state.is_in_menu;
18-
userspace_runtime_state.menu_state.dirty = true;
19-
has_flushed_menu = false;
17+
menu_state_runtime.dirty = true;
2018
}
2119

22-
if (userspace_runtime_state.menu_state.dirty) {
20+
if (menu_state_runtime.dirty) {
2321
oled_set_cursor(col, line);
2422
for (uint8_t i = 0; i < num_of_lines; i++) {
2523
oled_advance_page(true);
2624
}
25+
menu_state_runtime.dirty = false;
2726
}
2827

2928
if (!(userspace_config.display.menu_render_side & (1 << (uint8_t)!is_left))) {

users/drashna/display/painter/ili9341_display.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,11 @@ __attribute__((weak)) void ili9341_draw_user(void) {
174174
bool rgb_redraw = false;
175175
# if defined(RGB_MATRIX_ENABLE)
176176
if (has_rgb_matrix_config_changed()) {
177-
display_menu_set_dirty();
178177
rgb_redraw = true;
179178
}
180179
# endif
181180
# if defined(RGBLIGHT_ENABLE)
182181
if (has_rgblight_config_changed()) {
183-
display_menu_set_dirty();
184182
rgb_redraw = true;
185183
}
186184
# endif

users/drashna/display/painter/ili9488_display.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,11 @@ __attribute__((weak)) void ili9488_draw_user(void) {
159159
bool rgb_redraw = false;
160160
# if defined(RGB_MATRIX_ENABLE)
161161
if (has_rgb_matrix_config_changed()) {
162-
display_menu_set_dirty();
163162
rgb_redraw = true;
164163
}
165164
# endif
166165
# if defined(RGBLIGHT_ENABLE)
167166
if (has_rgblight_config_changed()) {
168-
display_menu_set_dirty();
169167
rgb_redraw = true;
170168
}
171169
# endif

users/drashna/display/painter/painter.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
#if defined(CUSTOM_QUANTUM_PAINTER_ST7789_170X320)
2626
# include "display/painter/st7789_170x320.h"
2727
#endif // CUSTOM_QUANTUM_PAINTER_ST7789_170X320
28+
#if defined(RGB_MATRIX_ENABLE)
29+
# include "rgb/rgb_matrix_stuff.h"
30+
#endif // defined(RGB_MATRIX_ENABLE)
31+
#if defined(RGBLIGHT_ENABLE)
32+
# include "rgb/rgb_stuff.h"
33+
#endif // defined(RGBLIGHT_ENABLE)
2834
#ifdef RTC_ENABLE
2935
# include "features/rtc/rtc.h"
3036
#endif // RTC_ENABLE
@@ -1163,10 +1169,23 @@ void housekeeping_task_quantum_painter(void) {
11631169
static uint8_t last_second = 0xFF;
11641170
if (rtc_read_time_struct().second != last_second) {
11651171
last_second = rtc_read_time_struct().second;
1166-
display_menu_set_dirty();
1172+
display_menu_set_dirty(true);
11671173
}
11681174
}
11691175
#endif // RTC_ENABLE
1176+
if (menu_state_runtime.dirty) {
1177+
display_menu_set_dirty(true);
1178+
}
1179+
#if defined(RGB_MATRIX_ENABLE)
1180+
if (has_rgb_matrix_config_changed()) {
1181+
display_menu_set_dirty(true);
1182+
}
1183+
#endif
1184+
#if defined(RGBLIGHT_ENABLE)
1185+
if (has_rgblight_config_changed()) {
1186+
display_menu_set_dirty(true);
1187+
}
1188+
#endif
11701189
#ifndef MULTITHREADED_PAINTER_ENABLE
11711190
static uint32_t last_tick = 0;
11721191
uint32_t now = timer_read32();
@@ -1185,19 +1204,17 @@ void housekeeping_task_quantum_painter(void) {
11851204
# endif // CUSTOM_QUANTUM_PAINTER_ST7789_170X320
11861205
last_tick = now;
11871206
}
1188-
#endif // MULTITHREADED_PAINTER_ENABLE
1189-
extern bool has_flushed_menu;
1190-
if (!has_flushed_menu) {
1191-
has_flushed_menu = true;
1192-
userspace_runtime_state.menu_state.dirty = false;
1193-
}
1207+
#endif // MULTITHREADED_PAINTER_ENABLE
11941208
#if (QUANTUM_PAINTER_DISPLAY_TIMEOUT) > 0
11951209
if (is_keyboard_master() && (last_input_activity_elapsed() > QUANTUM_PAINTER_DISPLAY_TIMEOUT)) {
11961210
qp_backlight_disable();
11971211
} else {
11981212
qp_backlight_enable();
11991213
}
12001214
#endif
1215+
if (!menu_state_runtime.has_rendered && !menu_state_runtime.dirty) {
1216+
menu_state_runtime.has_rendered = true;
1217+
}
12011218
if (console_has_redrawn) {
12021219
console_log_needs_redraw = false;
12031220
}

users/drashna/display/painter/qp_render_menu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
#include "display/menu/menu.h"
55
#include "display/painter/painter.h"
66

7-
extern bool has_flushed_menu;
8-
97
bool painter_render_menu(painter_device_t display, painter_font_handle_t font, uint16_t start_x, uint16_t start_y,
108
uint16_t width, uint16_t height, bool is_thicc) {
119
static menu_state_t last_state;
1210
uint8_t scroll_offset = 0;
1311

14-
if (memcmp(&last_state, &userspace_runtime_state.menu_state, sizeof(menu_state_t)) == 0 && has_flushed_menu) {
12+
if (memcmp(&last_state, &userspace_runtime_state.menu_state, sizeof(menu_state_t)) == 0 &&
13+
menu_state_runtime.has_rendered) {
1514
return userspace_runtime_state.menu_state.is_in_menu;
1615
}
1716

17+
menu_state_runtime.dirty = false;
1818
memcpy(&last_state, &userspace_runtime_state.menu_state, sizeof(menu_state_t));
1919

2020
uint16_t render_width = width - start_x;

users/drashna/drashna_runtime.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ _Static_assert(sizeof(userspace_config_t) <= EECONFIG_USER_DATA_SIZE, "User EECO
9292
extern userspace_config_t userspace_config;
9393

9494
typedef struct PACKED {
95-
bool dirty;
9695
bool is_in_menu;
9796
uint8_t selected_child;
9897
uint8_t menu_stack[8];

0 commit comments

Comments
 (0)