TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The Story Behind Fenster

72 pointsby hamdouni8 months ago

8 comments

Lerc8 months ago
This has popped up because<p>Microui+fenster=Small GUI <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41477446">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41477446</a><p>Was posted in the last day.<p>In that thread I suggested that API compatibility would be the way to go for more esoteric platforms, Since there&#x27;s already comments here about BSD and Android targets.<p>All you need is<p><pre><code> struct fenster { const char *title; &#x2F;* window title *&#x2F; const int width; &#x2F;* window width *&#x2F; const int height; &#x2F;* window height *&#x2F; uint32_t *buf; &#x2F;* window pixels, 24-bit RGB, row by row, pixel by pixel *&#x2F; int keys[256]; &#x2F;* keys are mostly ASCII, but arrows are 17..20 *&#x2F; int mod; &#x2F;* mod is 4 bits mask, ctrl=1, shift=2, alt=4, meta=8 *&#x2F; int x; &#x2F;* mouse X coordinate *&#x2F; int y; &#x2F;* mouse Y coordinate *&#x2F; int mouse; &#x2F;* 0 = no buttons pressed, 1 = left button pressed *&#x2F; }; int fenster_open(struct fenster *f) int fenster_loop(struct fenster *f) void fenster_close(struct fenster *f) void fenster_sleep(int ms) int64_t fenster_time() fenster_pixel(f, x, y) uint32_t px = fenster_pixel(f, x, y); </code></pre> A bit more for audio, but that&#x27;s really it&#x27;s own little API<p>As a mimimal API for doing interactive apps, it&#x27;s hard to beat. I can see hobbyists who make their own operating systems taking advantage of this to get things working quickly.
felipefar8 months ago
Nice work! It wouldn&#x27;t be much work to support Android with this library and keep the single source file, since the addition of native_app_glue. It&#x27;d require just an AndroidManifest.xml, and the API communication can be done by calling the functions provided by the NDK or in the worst case by calling JNI.
immibis8 months ago
You might want to use CLOCK_MONOTONIC on POSIX or changing the system time will screw up the refresh rate or freeze the window completely.
评论 #41485700 未加载
unwind8 months ago
Very nice and very straight-forward. I really liked the part on getting &quot;Doom&quot; to run, impressive how easy such porting is now!<p>Any low-level C is kind of catnip for the old SO-powered part of my brain, but did not spend a lot of time and got a lot of confidence.i did find this bug:<p><pre><code> memset(f-&gt;buf, rgb, f-&gt;width*f-&gt;height*sizeoof(*f-&gt;buf)); </code></pre> This will not work to set a color in the general case (`rgb` is `uint32_t`) since `memset()` only uses the lower `CHAR_BIT` bits of the value, it is setting the memory byte by byte. For black or white it will work! :)
onetom8 months ago
Would it work on NetBSD&#x2F;OpenBSD&#x2F;FreeBSD&#x2F;GhostBSD too?<p>Because if it does, it would worth mentioning it in the readme.<p>In Plan 9, Rio, the window manager, does a similar thing; it exposes a framebuffer to the process running in a window, simply as the &#x2F;dev&#x2F;draw device file, iirc.
mrpippy8 months ago
In the Mac&#x2F;AppKit implementation it would be interesting to try using wantsUpdateLayer: and updateLayer: instead of drawRect. That should be more efficient.
password43218 months ago
TIL: <i>Our goal here is to have a framebuffer for a single window that would run and look the same on Linux, Windows and macOS.</i><p>Basically re-implementing enough SDL from scratch to run Doom, nice!
igtztorrero8 months ago
WASN + Fester, for Browser, it is possible?