From 12ab314b2098904d5184e203155e764b540014c5 Mon Sep 17 00:00:00 2001 From: Albert Graef <aggraef@gmail.com> Date: Sun, 6 Sep 2020 21:38:52 +0200 Subject: [PATCH] Fix the findbox regression, part 2. This gets rid of some race conditions in the find operation, by ensuring that edit mode is only updated *after* mapping a subpatch window. This bug manifested itself when searching for objects in subpatches which are not visible at the time the find operation gets invoked. In this case, on the GUI side we both have to create the subpatch window and put it in edit mode. In the previous implementation these two operations would be executed separately and asynchronously. The end result was that usually the latter operation setting the edit mode in the GUI would win out, and the edit mode would later get overwritten again when the window was created. We fixed that race condition by ensuring that the engine is queried for its current edit mode status after creating a canvas window. The engine replies with a call to gui_canvas_set_editmode() in the GUI and thus the edit mode in the GUI now properly reflects the status in the engine after a window is mapped. TL;DR: This fix should now make sure that edit mode on the GUI side reflects that of the engine at all times. --- pd/nw/pd_canvas.js | 2 +- pd/nw/pdgui.js | 7 +++++++ pd/src/g_canvas.c | 2 ++ pd/src/g_canvas.h | 1 + pd/src/g_editor.c | 8 ++++++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js index 9e074b544..60278d79f 100644 --- a/pd/nw/pd_canvas.js +++ b/pd/nw/pd_canvas.js @@ -1323,7 +1323,7 @@ function register_window_id(cid, attr_array) { // Initialize the zoom level to the value retrieved from the patch, if any. nw.Window.get().zoomLevel = attr_array.zoom; pdgui.canvas_map(cid); // side-effect: triggers gui_canvas_get_scroll - pdgui.canvas_set_editmode(cid, attr_array.editmode); + pdgui.canvas_query_editmode(cid); // For now, there is no way for the cord inspector to be turned on by // default. But if this changes we need to set its menu item checkbox // accordingly here diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index ffcc1f526..90289fd21 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -1302,6 +1302,13 @@ function gui_canvas_set_editmode(cid, state) { canvas_set_editmode(cid, state); } +// ask the engine about the current edit mode +function canvas_query_editmode(cid) { + pdsend(cid, "query-editmode"); +} + +exports.canvas_query_editmode = canvas_query_editmode; + function update_grid(grid) { // Update the grid background of all canvas windows when the corresponding // option in the gui prefs changes. diff --git a/pd/src/g_canvas.c b/pd/src/g_canvas.c index 86f355928..303ecd14b 100644 --- a/pd/src/g_canvas.c +++ b/pd/src/g_canvas.c @@ -2717,6 +2717,8 @@ void g_canvas_setup(void) gensym("vis"), A_FLOAT, A_NULL); class_addmethod(canvas_class, (t_method)glist_menu_open, gensym("menu-open"), A_NULL); + class_addmethod(canvas_class, (t_method)canvas_query_editmode, + gensym("query-editmode"), A_NULL); class_addmethod(canvas_class, (t_method)canvas_map, gensym("map"), A_FLOAT, A_NULL); class_addmethod(canvas_class, (t_method)canvas_dirty, diff --git a/pd/src/g_canvas.h b/pd/src/g_canvas.h index ab053d08d..00df6a8b3 100644 --- a/pd/src/g_canvas.h +++ b/pd/src/g_canvas.h @@ -564,6 +564,7 @@ EXTERN void canvas_resortoutlets(t_canvas *x); EXTERN void canvas_free(t_canvas *x); EXTERN void canvas_updatewindowlist( void); EXTERN void canvas_editmode(t_canvas *x, t_floatarg yesplease); +EXTERN void canvas_query_editmode(t_canvas *x); EXTERN int canvas_isabstraction(t_canvas *x); EXTERN int canvas_istable(t_canvas *x); EXTERN int canvas_showtext(t_canvas *x); diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c index 06a773db6..e7334d69b 100644 --- a/pd/src/g_editor.c +++ b/pd/src/g_editor.c @@ -8049,6 +8049,14 @@ void canvas_editmode(t_canvas *x, t_floatarg fyesplease) } } +void canvas_query_editmode(t_canvas *x) +{ + int edit = /*!glob_ctrl && */x->gl_edit; + gui_vmess("gui_canvas_set_editmode", "xi", + glist_getcanvas(x), + edit); +} + // jsarlo void canvas_magicglass(t_canvas *x, t_floatarg fyesplease) { -- GitLab