Start program with x11 backend

Linux specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Start program with x11 backend

Post by mk-soft »

Since not everything runs under Wayland (default of Ubuntu 22.04), such as OpenGLGadget (gl_area not supported) or engine3d, you can change the gdk_backend to x11 for the application.

Also for the problem with the window sizes of PB. (Or use Workaround Wayland)

Update v1.01.2

Code: Select all

;-TOP by mk-soft, v1.01.2, 25.04.2022

Procedure StartProgramX11(Program.s, Parameters.s, WorkingDirectory.s = "", Exit = #False)
  Protected r1, SessionType.s, GdkBackend.s
  
  SessionType = GetEnvironmentVariable("XDG_SESSION_TYPE")
  GdkBackend = GetEnvironmentVariable("GDK_BACKEND")
  If SessionType <> "x11"
    If GdkBackend <> "x11"
      SetEnvironmentVariable("GDK_BACKEND", "x11")
    EndIf
  EndIf
  r1 = RunProgram(Program, Parameters, WorkingDirectory)
  If Exit
    End
  EndIf
  ProcedureReturn r1
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  Global dx, dy, info.s
  
  If GetEnvironmentVariable("XDG_SESSION_TYPE") <> "x11"
    If ProgramParameter(0) <> "x11"
      StartProgramX11(ProgramFilename(), "x11" , "", #True)
    EndIf
  EndIf
  
  info = "XDG_SESSION_TYPE: " + GetEnvironmentVariable("XDG_SESSION_TYPE") + #LF$
  info + "GDK_BACKEND: " + GetEnvironmentVariable("GDK_BACKEND")
  
  If OpenWindow(0, 100, 100, 400, 300, "GDK Backend X11", #PB_Window_SystemMenu)
    dx = WindowWidth(0)
    dy = WindowHeight(0)
    TextGadget(0, 10, 10, dx - 20, dy - 60, info)
    ButtonGadget(1, 10, dy - 50, 120, 30, "Button")
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
          
      EndSelect
    ForEver
    
  EndIf
  
CompilerEndIf
Last edited by mk-soft on Mon Apr 25, 2022 3:59 pm, edited 4 times in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Start program with x11 backend

Post by mk-soft »

Without setting the gdk_backend yourself, you can also start a program with it.

Code: Select all

;-TOP by mk-soft, v1.01.1, 25.04.2022

Procedure RunAsX11()
  Protected SessionType.s, GdkBackend.s
  Protected Program.s, Parameters.s, cnt, index
  
  cnt = CountProgramParameters()
  If cnt = 0
    Program = OpenFileRequester("Open Program", "", "", 0)
    If Program = ""
      ProcedureReturn 0
    EndIf
  Else
    Program = ProgramParameter(0)
    cnt - 1
    For index = 1 To cnt
      Parameters + ProgramParameter(index)
      If index < cnt
        Parameters + " "
      EndIf
    Next
  EndIf
  
  SessionType = GetEnvironmentVariable("XDG_SESSION_TYPE")
  GdkBackend = GetEnvironmentVariable("GDK_BACKEND")
  If SessionType <> "x11"
    If GdkBackend <> "x11"
      SetEnvironmentVariable("GDK_BACKEND", "x11")
    EndIf
  EndIf
  ProcedureReturn RunProgram(Program, Parameters, "")
EndProcedure

End RunAsX11()

For example, start the PureBasicIDE to test as x11 programs.

Purebasic-v600-X11.desktop
[Desktop Entry]
Type=Application
Icon=/home/michael/Apps/purebasic-v600/logo.png
Name=Purebasic v6.00 (x11)
Comment=Developer Utility
Exec=/home/michael/Apps/RunAsX11 "/home/michael/Apps/purebasic-v600/compilers/purebasic"
Path=/home/michael/Apps/purebasic-v600/compilers
StartupNotify=false
Terminal=false
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply