Recent

Author Topic: Playing with GTK-server  (Read 274 times)

Roland57

  • Hero Member
  • *****
  • Posts: 624
    • msegui.net
Playing with GTK-server
« on: July 22, 2026, 10:11:06 am »
Hello everybody.

I discovered yesterday the GTK-server by Peter van Eerten and found it was a very interesting and impressive project.

I translated to Pascal the Lua Unix FIFO demo. It wasn't very difficult, but I was glad to see that it works.  :)

Code: Pascal  [Select][+][-]
  1. program demo_fifo;
  2.  
  3. {$MODE objfpc}{$H+}
  4.  
  5. uses
  6.   SysUtils, Classes, Process;
  7.  
  8. const
  9.   CFile = '/tmp/demo.pascal';
  10.  
  11. function gtk(const s: string): string;
  12. var
  13.   f: textfile;
  14. begin
  15.   AssignFile(f, CFile);
  16.   Append(f);
  17.   WriteLn(f, s);
  18.   CloseFile(f);
  19.  
  20.   result := EmptyStr;
  21.   AssignFile(f, CFile);
  22.   Reset(f);
  23.   ReadLn(f, result);
  24.   CloseFile(f);
  25. end;
  26.  
  27. var
  28.   LWindow, LTable, LButton, LLabel, LEvent: string;
  29.   LProcess: TProcess;
  30.  
  31. begin
  32.   LProcess:= TProcess.Create(nil);
  33.   LProcess.Executable :='/usr/local/bin/gtk-server-gtk2';
  34.   LProcess.Parameters.Add('-fifo=' + CFile);
  35.   LProcess.Parameters.Add('-detach');
  36.   LProcess.Options := LProcess.Options + [poWaitOnExit];
  37.   LProcess.Execute;
  38.  
  39.   gtk('gtk_init NULL NULL');
  40.   LWindow := gtk('gtk_window_new 0');
  41.   gtk('gtk_widget_set_usize ' + LWindow + ' 300 100');
  42.   gtk('gtk_window_set_title ' + LWindow + ' "Pascal demo for GTK-server"');
  43.   gtk('gtk_window_set_position ' + LWindow + ' 1');
  44.   LTable := gtk('gtk_table_new 20 20 1');
  45.   gtk('gtk_container_add ' + LWindow + ' ' + LTable);
  46.   LButton := gtk('gtk_button_new_with_label "Quit"');
  47.   gtk('gtk_table_attach_defaults ' + LTable + ' ' + LButton + ' 12 19 12 19');
  48.   LLabel:= gtk('gtk_label_new "Hello from Free Pascal!"');
  49.   gtk('gtk_table_attach_defaults ' + LTable + ' ' + LLabel + ' 1 15 1 10');
  50.   gtk('gtk_widget_show_all ' + LWindow);
  51.  
  52.   repeat
  53.     LEvent := gtk('gtk_server_callback wait');
  54.   until (LEvent = LButton) or (LEvent = LWindow);
  55.  
  56.   gtk('gtk_server_exit');
  57. end.

I would like to explore further how GTK-server works, and maybe write other more complete and up-to-date demos. (The demo above only works with gtk-server-gtk2).

Please contribute, if you feel interested. For me, I have almost zero knowledge about this topic.  :)
« Last Edit: July 22, 2026, 10:20:04 am by Roland57 »
My projects are on Codeberg.

robert rozee

  • Sr. Member
  • ****
  • Posts: 401
Re: Playing with GTK-server
« Reply #1 on: July 23, 2026, 12:52:46 pm »
what size is the binary /usr/local/bin/gtk-server-gtk2? i am interested in the idea of statically linking it (as a library) with a small non-gui ELF binary to potentially create very small GUI utilities.


cheers,
rob   :-)

Roland57

  • Hero Member
  • *****
  • Posts: 624
    • msegui.net
Re: Playing with GTK-server
« Reply #2 on: July 23, 2026, 05:48:53 pm »
The file size here is 131 KB.

I saw in the documentation that there is an option to build GTK-server as shared library, but didn't yet tried.
My projects are on Codeberg.

 

TinyPortal © 2005-2018