Page 1 of 1

[PB 6.21] Canvas Gadget #PB_EventType_Resize unreliable

Posted: Wed Aug 20, 2025 12:38 pm
by macros
Under Kubuntu Linux 25.04 with a plasma X11 or Wayland session the Resize event does not work as it should.
Under the GTK subsystem it fires in most cases, but not all of them. Especially when enlarging a windows slowly the event does not fire.
Unter the QT subsystem the event does not fire at all.

Below a sample code which works under a Windows 10 VM:

Code: Select all

Procedure RedrawCallback()
  StartVectorDrawing(CanvasVectorOutput(0))
  w=VectorOutputWidth()
  h=VectorOutputHeight()
  VectorSourceCircularGradient(w/2, h/2, (w+h)/2)
  VectorSourceGradientColor(RGBA(255, 255, 255, 255), 0.0)
  VectorSourceGradientColor(RGBA(0, 0, 0, 255), 1.0)
  FillVectorOutput()
  StopVectorDrawing()
EndProcedure

OpenWindow(0,0,0,400,400,"#PB_EventType_Resize Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget)
CanvasGadget(0,5,5,390,390)
BindGadgetEvent(0, @RedrawCallback(),#PB_EventType_Resize) 
RedrawCallback() ; fill the canvas with an initial gradient

SetWindowColor(0,$ff)
Repeat
  event=WaitWindowEvent()
  If #PB_Event_SizeWindow
      ResizeGadget(0,5,5,WindowWidth(0)-10,WindowHeight(0)-10)
  EndIf
Until event=#PB_Event_CloseWindow
The code should always show a circular gradient centered in the canvas and filling it.
Example picture of the behavior under GTK:
Image
The gadget has been resized as can be seen from the white background, the gradient has not been redrawn.
Under QT the CanvasGadget does not receive a single PB_EventType_Resize.

The canvas gadget itself is correctly resized as evident by the red border showing the window background color.

Re: [PB 6.21] Canvas Gadget #PB_EventType_Resize unreliable

Posted: Wed Aug 20, 2025 1:33 pm
by mk-soft
Is probably an old mistake with the gadget resise event in Linux. But I didn't notice because I always re-drain in Event Size Window.
But you can bind the event yourself under Linux

Code: Select all

Procedure RedrawCanvas()
  If StartVectorDrawing(CanvasVectorOutput(0))
    w=VectorOutputWidth()
    h=VectorOutputHeight()
    VectorSourceCircularGradient(w/2, h/2, (w+h)/2)
    VectorSourceGradientColor(RGBA(255, 255, 255, 255), 0.0)
    VectorSourceGradientColor(RGBA(0, 0, 0, 255), 1.0)
    FillVectorOutput()
    StopVectorDrawing()
  EndIf
EndProcedure

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ProcedureC _drawcanvas_0 (*self, *event.GdkEventConfigure, user_data)
    Debug "signal configure-event - " + *event\x + "," + *event\y + " / " + *event\width + "," + *event\height
    RedrawCanvas()
  EndProcedure
CompilerEndIf

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0)
  ResizeGadget(0, 5, 5, dx-10, dy-10)
;  RedrawCanvas()
EndProcedure

If OpenWindow(0,0,0,400,400,"#PB_EventType_Resize Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget)
  SetWindowColor(0,$ff)
  CanvasGadget(0,5,5,390,390)
  RedrawCanvas()
  
  BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Linux
    Define signal_connect_conf_gd_0 = g_signal_connect_(GadgetID(0), "configure-event", @_drawcanvas_0(), 0)
  CompilerElse
    BindGadgetEvent(0, @RedrawCanvas(), #PB_EventType_Resize)
  CompilerEndIf
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
EndIf

Re: [PB 6.21] Canvas Gadget #PB_EventType_Resize unreliable

Posted: Wed Aug 20, 2025 2:12 pm
by macros
Thank you, that is a great solution for now and should help the developers to fix the issue under GTK.

Also it seems I had forgotten that you can bind single #PB_EventTypes to procedures. Thanks for pointing me at it, I simplified the sample code a bit.

Unfortunately a solution for qt is not as simple because of its C++ nature if I am not mistaken. I haven't fiddled around much yet with calling native APIs under Linux. Never had to with PureBasic :mrgreen: