Hello everyone, how are you?
I made initial with cpp on Ubuntu 22.04 and I expect that X11 works fine on without hxcpp. It works fine like in C++/C and It can bind with @:native()
and makes simply.
I expect that haxe works more then C#. Is it correctly? Since I have big problem with C# DLLImport with forcing structures with void*. C# can’t do for XRectangle* or XRectangle[] like in XDrawRectangles()
I don’t know how does haxe work? I will test soon…
Code: Example:
package;
import cpp.UInt32;
import cpp.Int32;
import cpp.UInt64;
@:native("Display")
@:include("/usr/include/X11/Xlib.h")
extern private class XDisplay {}
typedef Display = cpp.Pointer<XDisplay>;
@:native("XID")
@:include("/usr/include/X11/Xlib.h")
extern private class XID {}
@:native("Drawable")
@:include("/usr/include/X11/Xlib.h")
typedef Drawable = XID;
@:native("Window")
@:include("/usr/include/X11/Xlib.h")
typedef Window = Drawable;
@:include("/usr/include/X11/Xlib.h")
extern class Xlib
{
public static inline final NONE:UInt64 = 0;
@:native("XOpenDisplay")
static public function OpenDisplay(display_name:String):Display;
@:native("XCloseDisplay")
static public function CloseDisplay(display:Display):Void;
@:native("XDefaultScreen")
static public function DefaultScreen(display:Display):Int32;
@:native("XRootWindow")
static public function RootWindow(display:Display, screen_number:Int32):Window;
@:native("XCreateSimpleWindow")
static public function CreateSimpleWindow(display:Display, parent:Window, x:Int32, y:Int32, w:UInt32, h:UInt32, border_width:UInt32, border:UInt64, background:UInt64):Window;
@:native("XPending")
static public function Pending(display:Display):Int32;
@:native("XMapWindow")
static public function MapWindow(display:Display, window:Window):Int32;
@:native("XDestroyWindow")
static public function DestroyWindow(display:Display, window:Window):Void;
@:native("XStoreName")
static public function StoreName(display:Display, window:Window, window_title:String):Int32;
}
@:buildXml("
<target id='haxe'>
<lib name='-lX11' if='linux'/>
</target>
")
class Main
{
static var display:Display = null;
static var screen_number:Int32;
static var main_window:Window = null;
public static function main():Void
{
display = Xlib.OpenDisplay(null);
if (display == null)
{
trace("Error: Initializing display of X11");
}
screen_number = Xlib.DefaultScreen(display);
var root:Window = Xlib.RootWindow(display, screen_number);
main_window = Xlib.CreateSimpleWindow(display, root, 100, 100, 400, 320, 10, 0xffff0000, 0xffff5500);
if (main_window == null)
{
trace("Error: creating window of X11");
}
Xlib.StoreName(display, main_window, "Haxe X11!");
trace("Wohoo! X11 Window on Haxe!");
while (Xlib.Pending(display) == 0)
{
Xlib.MapWindow(display, main_window);
}
Xlib.CloseDisplay(display);
}
}
and build.hxml:
-cp src
-main Main
-lib hxcpp
-cpp build/haxe_x11
Type haxe build.hxm
and it runs like charm.
Enjoy your happy coding on Ubuntu, OpenSuse or Distros