Initial test with X11 on Haxe!

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:


import cpp.UInt32;
import cpp.Int32;
import cpp.UInt64;

extern private class XDisplay {}
typedef Display = cpp.Pointer<XDisplay>;

extern private class XID {}
typedef Drawable = XID;
typedef Window = Drawable;

extern class Xlib
    public static inline final NONE:UInt64 = 0;

    static public function OpenDisplay(display_name:String):Display;

    static public function CloseDisplay(display:Display):Void;

    static public function DefaultScreen(display:Display):Int32;

    static public function RootWindow(display:Display, screen_number:Int32):Window;

    static public function CreateSimpleWindow(display:Display, parent:Window, x:Int32, y:Int32, w:UInt32, h:UInt32, border_width:UInt32, border:UInt64, background:UInt64):Window;

    static public function Pending(display:Display):Int32;

    static public function MapWindow(display:Display, window:Window):Int32;

    static public function DestroyWindow(display:Display, window:Window):Void;

    static public function StoreName(display:Display, window:Window, window_title:String):Int32;

    <target id='haxe'>
       <lib name='-lX11' if='linux'/>

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);

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


PS: Please help me! I have problem with creating library because it throws error like src/Main.hx:6: characters 20-27 : Missing ;

I feel annoying that. Because I want create library with haxelib.json but it seems nothing find like i have tried to haxelib dev x11 x11 ← current directory from x11 and I want import to Main.hx but it seems failed. why???

Please help me. I have already readden creating library then it looks nothing successfully.

but I already imported for dependencies:

    "dependencies": {

It doesn’t work if I import cpp.Pointer;
then it shows error underline under vscode but why?

But why???

Can I have to know how do I fix if I make haxe library for haxelib.


cpp.Pointer is underlined because

  • your build target is not cpp
  • you use import or using after a declaration