pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.6k stars 519 forks source link

Conflict with IUP library #1092

Closed robertlzj closed 3 years ago

robertlzj commented 3 years ago

For the basic example iup-3.XX_Examples.zip\iup\html\examples\Lua\dialog.lua. Test version 3.XX by 3.25, works fine, will show a dialog expected. Test 3.27, works only half times, shows a extra application with title "G" in windows bar but has no window (size 0?), then maybe the target dialog shows. Test 3.30, almost fails. Shows the "G" window only. Could close the "G" window anytime.

Test using lua[53].exe directly, works correctly (shows only the expect dialog).

dictionary/struct:

ZeroBraneStudio-master\bin iup.dll ZeroBraneStudio-master\bin\clibs53 iuplua53.dll environment: LUA_CPATH_5_3=;;C:\ProgramFiles\ZeroBraneStudio-master\bin\clibs53\?53.dll;C:\ProgramFiles\ZeroBraneStudio-master\bin\clibs53\?.dll; or rename to "iuplua.dll".

pkulchenko commented 3 years ago

@robertlzj, this seems to be a duplicate of #80 (at least that ticket describes a very similar problem). Try adding unhidewindow.IupDialog = 1 to the IDE config.

robertlzj commented 3 years ago
  1. After unhidewindow.IupDialog = 1 and unhideanywindow = true, not work all the time (result not change).
  2. The more complex code function, the higher fail rate, I even think maybe there is some timeout when mapping in iup.
  3. And "G" windows is always there now.
  4. Window class is still IupDialog I checked when dialog displayed. ~Maybe other class exists in some case, so it's not show?~ tried unhideanywindow = true.
  5. map_cb, show_cb of iup describe dialog returns no error.
  6. And this not happen before version 3.25. (even after 3.25 console lua53.exe works fine most times, without "G" window)
  7. It's related with time, if in debug, wait some time at breakpoint (on iup.MainLoop()), then after some second suspende, window may display.
pkulchenko commented 3 years ago

@robertlzj, can you try with the following patch:

diff --git a/src/editor/output.lua b/src/editor/output.lua
index 5a53578c..44dacd53 100644
--- a/src/editor/output.lua
+++ b/src/editor/output.lua
@@ -189,6 +189,7 @@ local function unHideWindow(pidAssign)
     for _,win in pairs(wins) do
       -- win:get_class_name() can return nil if the window is already gone
       -- between getting the list and this check.
+ide:Print(win:get_class_name())
       local action = ide.config.unhidewindow[win:get_class_name()]
         or (any and show or ignore)
       if action == show and not win:is_visible()

This shows this list for me (I'm using pre-3.25 version):

ConsoleWindowClass
IupDialog
ConsoleWindowClass
MSCTFIME UI
IME

You may see some other window class on this list that needs to be added to the unhidewindow list.

If this doesn't help, you may want to try the following patch:

diff --git a/interpreters/luabase.lua b/interpreters/luabase.lua
index 76a9587e..9548dd87 100644
--- a/interpreters/luabase.lua
+++ b/interpreters/luabase.lua
@@ -71,7 +71,7 @@ return {
     end

     -- CommandLineRun(cmd,wdir,tooutput,nohide,stringcallback,uid,endcallback)
-    local pid = CommandLineRun(cmd,self:fworkdir(wfilename),true,false,nil,nil,
+    local pid = CommandLineRun(cmd,self:fworkdir(wfilename),true,true,nil,nil,
       function() if rundebug then wx.wxRemoveFile(filepath) end end)

     if (rundebug or version) and cpath then wx.wxSetEnv(envcpath, cpath) end

This will show all windows, which will obviously include the Lua console window that is likely to blink (and was the main reason for all this trickery on Windows).

robertlzj commented 3 years ago

The second patch success on Iup 3.30 on my script. Just a blink, and no "G" window keep.

Although, there is all the other test. The first patch using on Iup 3.27 for example\dialog.lua when display correct will get

ConsoleWindowClass ConsoleWindowClass IupDialog GDI+ Hook Window Class ConsoleWindowClass IME IME Or ConsoleWindowClass ConsoleWindowClass IupDialog GDI+ Hook Window Class ConsoleWindowClass MSCTFIME UI IME IME

On Iup 3.27 for other script when display un-correct will get

ConsoleWindowClass GDI+ Hook Window Class ConsoleWindowClass IME

On Iup3.27 for other script in debug mode (and wait on breakpoint to get higher success rate) when display correct will get

ConsoleWindowClass Debugging session started in .. IupDialog GDI+ Hook Window Class ConsoleWindowClass IME IME

Could not add unhidewindow.ConsoleWindowClass = 1, or there is only console window to show and in output.

On Iup 3.30 for example\dialog.lua, only half time success, showing:

ConsoleWindowClass GDI+ Hook Window Class ConsoleWindowClass IME Or ConsoleWindowClass ConsoleWindowClass IupDialog GDI+ Hook Window Class ConsoleWindowClass IME IME

bin\lua53.exe dofile[[C:\Users\RobertL\AppData\Local\Temp\Rar$DIa19380.40301\dialog.lua]] success without "G" window.

antonio.scuri author of Iup:

Iup initializes the COM library with some parameters. This occurs in IupOpen, or in the first require"iup" in Lua.

pkulchenko commented 3 years ago

@robertlzj, it looks like from your results that in those instances when "unhiding" didn't work, iupDialog windows didn't appear on the list of windows that were checked. I'm curious as to why that happened.

The process is launched quickly enough so the windows are shown/hidden without much delay, but at the same time it has to happen when the OS has a chance to create all the windows it needs and associate them with the process (via pid). Maybe in this case there is a small delay, which is causing that window not yet be fully registered when the windows are enumerated, which in turn is causing them to not be shown.

To test this, can you comment out line pid = nil -- indicate that unhiding is done (output.lua:200) to see if it will show the window in all cases (it may have some CPU impact, but I'm just interested in whether the window is going to be always shown).

robertlzj commented 3 years ago

Restore other modify on luabase.lua, output.lua. After comment, the dialog will shown correctly. Also the empty "G" title window shows which get focus. And all thing became a little slow before display.

pkulchenko commented 3 years ago

Ok, that's a good sign. Let's try this diff then (you can remove the earlier one):

diff --git a/src/editor/output.lua b/src/editor/output.lua
index 5a53578c..dbc25e7c 100644
--- a/src/editor/output.lua
+++ b/src/editor/output.lua
@@ -196,7 +196,11 @@ local function unHideWindow(pidAssign)
         -- use show_async call (ShowWindowAsync) to avoid blocking the IDE
         -- if the app is busy or is being debugged
         win:show_async(action == show and winapi.SW_SHOW or winapi.SW_HIDE)
-        pid = nil -- indicate that unhiding is done
+        -- indicate that unhiding is done, but make sure to check
+        -- late enough for all windows to get created
+        if ide:GetTime() - ((customprocs[pid] or {}).started or 0) > 1 then
+          pid = nil
+        end
       end
     end
   end

If this doesn't work, then increase 1s in the check to a larger number, but I suspect it should be enough.

robertlzj commented 3 years ago

Yes, it works. And I found "G" window is GDI, could hide it using unhidewindow['GDI+ Hook Window Class'] = 2 in user.lua.

pkulchenko commented 3 years ago

ok, pushed the changes (including the GDI+ window fix (so you can remove it from user.lua). Let me know if you notice any issues.