https://github.com/rajveermalviya/gamen
Cross-platform GUI window creation & management library in Go
https://github.com/rajveermalviya/gamen
android go golang linux wayland win32 xcb
Last synced: about 1 year ago
JSON representation
Cross-platform GUI window creation & management library in Go
- Host: GitHub
- URL: https://github.com/rajveermalviya/gamen
- Owner: rajveermalviya
- License: apache-2.0
- Archived: true
- Created: 2022-07-31T06:25:19.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-02-23T08:22:57.000Z (over 2 years ago)
- Last Synced: 2025-04-13T13:23:39.580Z (about 1 year ago)
- Topics: android, go, golang, linux, wayland, win32, xcb
- Language: Go
- Homepage:
- Size: 1000 KB
- Stars: 119
- Watchers: 4
- Forks: 7
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# gamen
[](https://pkg.go.dev/github.com/rajveermalviya/gamen)
[](https://matrix.to/#/#gamen:matrix.org)
`gamen` is cross-platform GUI window creation and management library in Go. It natively supports Windows, Linux, Android and Web. on Linux both X11 (via xcb) and Wayland are supported.
`gamen` provides consistent api for creating and managing GUI windows across different platforms. `gamen` also lets you handle events generated by platform window via callbacks. `gamen` is fairly low level, it provides platform native window handles for graphics APIs like OpenGL and Vulkan to initialize from, `gamen` by itself doesn't provide you a drawing primitive you have to use a library like [`go-webgpu`](https://github.com/rajveermalviya/go-webgpu) or similar.
`gamen` has a callback based api for handling events i.e it doesn't do queueing (except for web backend) by itself. Because most of the backends already do internal queueing of events, doing it again inside the library can introduce unnecessary latency. Also this keep api flexible, a separate library can introduce event queue on top of `gamen` for easier developer experience.
## usage
```go
package main
import (
"runtime"
"github.com/rajveermalviya/gamen/display"
)
func init() {
runtime.LockOSThread()
}
func main() {
d, err := display.NewDisplay()
if err != nil {
panic(err)
}
defer d.Destroy()
w, err := display.NewWindow(d)
if err != nil {
panic(err)
}
defer w.Destroy()
w.SetCloseRequestedCallback(func() { d.Destroy() })
for {
if !d.Poll() {
break
}
// render()
}
}
```
check out more examples under [`examples/`](./examples/) dir
examples `wgpu_poll` and `wgpu_wait` shows how to use the event loop for a Game and a GUI respectively. Though an ideal client will switch between `Poll` and `Wait`. (GUI temporarily showing an animation)
## dependencies
### windows
windows (win32) backend **does not** use CGO, i.e **does not** require a C toolchain, only Go compiler is enough
### linux
resulting binaries shouldn't require any dependency to be installed by the users. Even developers don't need to install any distro packages (it just works!), because required headers are vendored and all libraries are dynamically loaded.
### android
android backend uses [`game-activity`](https://developer.android.com/games/agdk/game-activity).
[`tsukuru`](https://github.com/rajveermalviya/tsukuru) should be used to help with dependency resolution and building the android app.
```shell
# make sure you have android sdk installed
# connect your device and setup adb connection / run android emulator
go install github.com/rajveermalviya/tsukuru/cmd/tsukuru@latest
tsukuru run apk ./examples/hello
```
### web
web backend uses `syscall/js` package.
[`tsukuru`](https://github.com/rajveermalviya/tsukuru) can be used to help with automatically building wasm and copying `wasm_exec.js` & `wasm_exec.html` from `$GOROOT` to a directory and spinning up a local file server for you.
```shell
go install github.com/rajveermalviya/tsukuru/cmd/tsukuru@latest
tsukuru run wasm ./examples/hello
```
## features
an incomplete list of features in no particular order that are supported or that we want to support but aren't currently.
| feature | win32 | xcb | wayland | android | web |
| ------------------------------ | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
| window initialization | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| handles for OpenGL init | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| handles for Vulkan WSI | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| show window with decorations | :heavy_check_mark: | :heavy_check_mark: | :exclamation: [#2] | :heavy_check_mark: | **N/A** |
| window decorations toggle | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | **N/A** |
| window resizing events | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | **N/A** |
| resize window programmatically | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | **N/A** | **N/A** |
| window transparency | :x: | :x: | :x: | :x: | :x: |
| window maximization toggle | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | **N/A** | **N/A** |
| window minimization | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | **N/A** | **N/A** |
| window minimum size | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | **N/A** | **N/A** |
| window maximum size | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | **N/A** | **N/A** |
| fullscreen toggle | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| HiDPI support | :x: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| popups | :x: | :x: | :x: | **N/A** | **N/A** |
| monitor list | :x: | :x: | :x: | :x: | :x: |
| video mode query | :x: | :x: | :x: | :x: | :x: |
| mouse events | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | **N/A** | :heavy_check_mark: |
| cursor locking | :x: | :x: | :x: | :x: | :x: |
| cursor confining | :x: | :x: | :x: | :x: | :x: |
| cursor icon | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | **N/A** | :heavy_check_mark: |
| cursor hittest | :x: | :x: | :x: | **N/A** | :x: |
| touch events | :x: | :x: | :x: | :heavy_check_mark: | :x: |
| keyboard events | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| drag window with cursor | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | **N/A** | **N/A** |
| drag & drop | :x: | :x: | :x: | **N/A** | :x: |
| raw device events | :x: | :x: | :x: | :x: | :x: |
| gamepad/joystick events | :x: | :x: | :x: | :x: | :x: |
| ime | :x: | :x: | :x: | :x: | :x: |
| clipboard | :x: | :x: | :x: | :x: | :x: |
| theme change events | :x: | :x: | :x: | :x: | :x: |
[#2]: https://github.com/rajveermalviya/gamen/issues/2
(as you can see there are many :x:s so any help will be greatly appreciated)
Note: for macos/ios support see [#1](https://github.com/rajveermalviya/gamen/issues/1)
## contact
join [matrix room](https://matrix.to/#/#gamen:matrix.org)
## thanks
`gamen`'s api is a mix of glfw and winit and some terminologies from Wayland.
- glfw - https://github.com/glfw/glfw
- winit - https://github.com/rust-windowing/winit