Handmade Hero»Forums»Code
Shazan Shums
159 posts
Some day I will make quality software. Programming FTW.
What api to use in Linux??
Edited by Shazan Shums on
Linux has many APIs in different flavours.what to use please help? I use manjaro linux-i3wm if it helps.
Mārtiņš Možeiko
2562 posts / 2 projects
What api to use in Linux??
Edited by Mārtiņš Možeiko on
API for what?
For reading files? open/read/close syscalls.
For allocating memory? malloc/free for heap or mmap/munmap for virtual memory
For UI? For basic windows use X11 or xcb. For GUI toolkits - GTK or Qt.
For 3D API? OpenGL or Vulkan.
For joystick input? read /dev/input* devices.
For accessing network? sockets.

Manjaro or no-manjaro doesn't matter. Distribution is just a collection of libraries, applications, package manager & stuff. Kernel and core libraries are more or less the same.
Shazan Shums
159 posts
Some day I will make quality software. Programming FTW.
What api to use in Linux??
X11 or xcb?
Mārtiņš Možeiko
2562 posts / 2 projects
What api to use in Linux??
Edited by Mārtiņš Možeiko on
It doesn't really matter. Both are API are more or less ok. And both of them talks with same X Windowing System.

Nowadays X11 is implemented on top of xcb.

Some API is easier with X11, but some with XCB. For example, unicode symbol handling is easier with X11. With xcb you'll need to do more work, or use other libraries like libxkbcommon.

To use OpenGL you'll need access to X11 display handle, so with pure xcb API you cannot use OpenGL. But there exists API functions to get xcb connection from X11 display or other way around.

Vulkan can work directly with xcb or x11 API, or both of them depending on implementation. So same situation as with GL. Somtimes you'll need to convert xcb handle to x11 or other way around.

There exists more modern API's like Wayland, but I would say that support for all distributions for it is not there yet.
David Butler
81 posts / 1 project
I love pretty much anything technical, whether it be programming, networking, hacking or electronics.
What api to use in Linux??
Edited by David Butler on
msmshazan
X11 or xcb?


I think this means "Xlib vs XCB" ? or are you meaning implementing X11 Directly (handmade style/ from scratch)

XLib and XCB are both libraries that implement X11 clients.

Distributions are pushing Wayland lately, which many believe will replace X11, But Wayland has a backward compatible layer for X11 support.

I would use XCB on Linux, actually, I would probably use SDL on Linux. It depends.

XCB is a newer than Xlib with a focus on being asynchronous.

Also, for Audio, It seems the standard for desktop GNU/Linux distributions to use Pulse Audio, or if you are embedded (non desktop) use ALSA. If you use SDL, then it will try auto-detect what the right thing to do is. (use Pulse Audio if its there, then ALSA, then OSS)

Also as a side note, if you just want to interface with the kernel directly, and not go though the X Server at all, you can use the KMS/DRI APIs, this is best for embedded applications or single purpose machines, because only one application can have that level of access at a time.

There are so many APIs because there are so many different use cases. Not all of them do the same.

Also, for GUI toolkits, I highly recommend just implementing Nuklear or Dear IMgui over OpenGL, its a little bit of work to get started, but a solution like that has a lot less baggage than using GTK or QT.