Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IME support. Fixes #370. #371

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build
on:
pull_request:
push:
branches: [ ci, master, latest, 3.3-stable ]
workflow_dispatch:
permissions:
statuses: write
contents: read

jobs:
build-linux-x11:
name: X11 (Linux)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt update
sudo apt install libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev libgl1-mesa-dev

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build
run: go build -v ./v3.4/glfw

- name: Vet
run: go vet ./v3.4/glfw


build-linux-full:
name: X11+Wayland (Linux)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt update
sudo apt install libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev wayland-protocols libwayland-dev libxkbcommon-dev libgl1-mesa-dev

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build
run: go build -v ./v3.4/glfw

build-macos-cocoa:
name: Cocoa (macOS)
runs-on: macos-latest
env:
MACOSX_DEPLOYMENT_TARGET: 10.8
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build
run: go build -v ./v3.4/glfw

build-windows-win32-vs2022:
name: Win32 (Windows, VS2022)
runs-on: windows-latest
env:
CFLAGS: /WX
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build
run: go build -v ./v3.4/glfw

13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GLFW 3.3 for Go [![Build Status](https://travis-ci.org/go-gl/glfw.svg?branch=master)](https://travis-ci.org/go-gl/glfw) [![GoDoc](https://godoc.org/github.com/go-gl/glfw/v3.3/glfw?status.svg)](https://godoc.org/github.com/go-gl/glfw/v3.3/glfw)
# GLFWFF 3.4 for Go [![Build Status](https://travis-ci.org/bjorndm/go-glfw.svg?branch=master)](https://travis-ci.org/bjorndm/go-glfw) [![GoDoc](https://godoc.org/github.com/bjorndm/go-glfw/v3.3/glfw?status.svg)](https://godoc.org/github.com/bjorndm/go-glfw/v3.3/glfw)

## Installation

Expand All @@ -13,7 +13,7 @@
* Go 1.4+ is required on Windows (otherwise you must use MinGW v4.8.1 exactly, see [Go issue 8811](https://github.com/golang/go/issues/8811)).

```
go get -u github.com/go-gl/glfw/v3.3/glfw
go get -u github.com/bjorndm/go-glfw/v3.4/glfw
```

### OpenGL ES
Expand All @@ -22,7 +22,7 @@ If your target system only provides an OpenGL ES implementation (true for some A
You do this by defining the appropriate build tags, e.g.

```
go get -u -tags=gles2 github.com/go-gl/glfw/v3.3/glfw
go get -u -tags=gles2 github.com/bjorndm/go-glfw/v3.4/glfw
```

Supported tags are `gles1`, `gles2`, `gles3` and `vulkan`.
Expand All @@ -35,7 +35,7 @@ package main

import (
"runtime"
"github.com/go-gl/glfw/v3.3/glfw"
"github.com/bjorndm/go-glfw/v3.4/glfw"
)

func init() {
Expand Down Expand Up @@ -68,6 +68,9 @@ func main() {

## Changelog

### GLFWFF 3.4 Specific Changes


### GLFW 3.3 Specific Changes
- Joystick functions now uses receivers instead of passing the joystick ID as argument.
- Vulkan methods are intentionally not implemented. `Window.Handle` can be used to create a Vulkan surface via the [this](https://github.com/vulkan-go/vulkan) package.
Expand Down Expand Up @@ -133,7 +136,7 @@ func main() {


### GLFW 3.2 Specfic Changes
- Easy `go get` installation. GLFW source code is now included in-repo and compiled in so you don't have to build GLFW on your own and distribute shared libraries. The revision of GLFW C library used is listed in [GLFW_C_REVISION.txt](https://github.com/go-gl/glfw/blob/master/v3.3/glfw/GLFW_C_REVISION.txt) file.
- Easy `go get` installation. GLFW source code is now included in-repo and compiled in so you don't have to build GLFW on your own and distribute shared libraries. The revision of GLFW C library used is listed in [GLFW_C_REVISION.txt](https://github.com/bjorndm/go-glfw/blob/master/v3.3/glfw/GLFW_C_REVISION.txt) file.
- The error callback is now set internally. Functions return an error with corresponding code and description (do a type assertion to glfw3.Error for accessing the variables) if the error is recoverable. If not a panic will occur.

* Added function `Window.SetSizeLimits`.
Expand Down
103 changes: 103 additions & 0 deletions scripts/grab-glfwff-upstream.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env bash

# This script fetches the glfw sources from upstream and verifies that the files
# committed are the same.

# Files we don't want in the downstream go-gl/glfw repository.
# Users can get these from upstream if needed.
excludes=(
--exclude=glfw-*/.appveyor.yml
--exclude=glfw-*/.github
--exclude=glfw-*/.gitignore
--exclude=glfw-*/.mailmap
--exclude=glfw-*/.travis.yml
--exclude=glfw-*/*.in
--exclude=glfw-*/CMake
--exclude=glfw-*/CMakeLists.txt
--exclude=glfw-*/docs
--exclude=glfw-*/examples
# Deleted later because it is needed for patches:
# --exclude=glfw-*/README.md
--exclude=glfw-*/CONTRIBUTORS.md
--exclude=glfw-*/src/*.in
--exclude=glfw-*/src/CMakeLists.txt
--exclude=glfw-*/tests
)

grab-upstream() {
local godir=$1
if [[ ! -d "$godir" ]]; then
echo "Run with top-level directory as working directory." 1>&2
exit 1
fi
local rev="$(cat "$godir"/GLFW_C_REVISION.txt)"
local target=$godir/glfw

rm -r "$target"
mkdir "$target"

curl -s -L "https://github.com/bjorndm/glfw/archive/${rev}.tar.gz" |
tar xz \
--strip-components=1 \
--directory="$target" \
"${excludes[@]}"

# Place a dummy go file in each directory.
find "$target/deps" "$target/include" "$target/src" -type d -print0 |
while IFS= read -r -d $'\0' D
do
cat > "$D"/dummy.go <<EOF
// +build required

// Package dummy prevents go tooling from stripping the c dependencies.
package dummy
EOF
done
}

# v3.4
{
grab-upstream v3.4/glfw

cat > v3.4/glfw/glfw/deps/dummy.go <<EOF
// +build required

// Package dummy prevents go tooling from stripping the c dependencies.
package dummy

import (
// Prevent go tooling from stripping out the c source files.
_ "github.com/go-gl/glfw/v3.4/glfw/glfw/deps/glad"
_ "github.com/go-gl/glfw/v3.4/glfw/glfw/deps/mingw"
_ "github.com/go-gl/glfw/v3.4/glfw/glfw/deps/vs2008"
)
EOF

scripts/generate-wayland-protocols.sh ./v3.4/glfw/glfw/src
sed -i 's|/\* Generated by wayland-scanner .* \*/|/* Generated by wayland-scanner */|' \
./*/glfw/glfw/src/wayland-*

rm v3.4/glfw/glfw/README.md

go generate ./v3.4/glfw/glfw_tree_rebuild.go
}

if test -n "$(git status --porcelain ./*/glfw)"; then

git status ./*/glfw

{
echo
echo "Tree is dirty after fetching GLFW_C_REVISION from upstream."
echo
echo "To fix this:"
echo " 1. Update GLFW_C_REVISION.txt, then:"
echo " 2. Run scripts/grab-upstream.sh from the top-level directory"
echo " 3. Submit the result as a pull request"
echo
echo "If you must apply patches, please do it in grab-upstream.sh so that"
echo "these patches are described programmatically."
echo
} 1>&2
exit 1
fi
1 change: 1 addition & 0 deletions v3.4/glfw/GLFW_C_REVISION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.4.1
53 changes: 53 additions & 0 deletions v3.4/glfw/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package glfw

/*
// Windows Build Tags
// ----------------
// GLFW Options:
#cgo windows CFLAGS: -D_GLFW_WIN32 -Iglfw/deps/mingw

// Linker Options:
#cgo windows LDFLAGS: -lgdi32

#cgo !gles2,windows LDFLAGS: -lopengl32
#cgo gles2,windows LDFLAGS: -lGLESv2

// Darwin Build Tags
// ----------------
// GLFW Options:
#cgo darwin CFLAGS: -D_GLFW_COCOA -Wno-deprecated-declarations

// Linker Options:
#cgo darwin LDFLAGS: -framework Cocoa -framework IOKit -framework CoreVideo

#cgo !gles2,darwin LDFLAGS: -framework OpenGL
#cgo gles2,darwin LDFLAGS: -lGLESv2

// Linux Build Tags
// ----------------
// GLFW Options:
#cgo linux,!wayland CFLAGS: -D_GLFW_X11
#cgo linux,wayland CFLAGS: -D_GLFW_WAYLAND

// Linker Options:
#cgo linux,!gles1,!gles2,!gles3,!vulkan LDFLAGS: -lGL
#cgo linux,gles1 LDFLAGS: -lGLESv1
#cgo linux,gles2 LDFLAGS: -lGLESv2
#cgo linux,gles3 LDFLAGS: -lGLESv3
#cgo linux,vulkan LDFLAGS: -lvulkan
#cgo linux,!wayland LDFLAGS: -lX11 -lXrandr -lXxf86vm -lXi -lXcursor -lm -lXinerama -ldl -lrt
#cgo linux,wayland LDFLAGS: -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon -lm -ldl -lrt

// BSD Build Tags
// ----------------
// GLFW Options:
#cgo freebsd,!wayland netbsd,!wayland openbsd pkg-config: x11 xau xcb xdmcp
#cgo freebsd,wayland netbsd,wayland pkg-config: wayland-client wayland-cursor wayland-egl epoll-shim
#cgo freebsd netbsd openbsd CFLAGS: -D_GLFW_HAS_DLOPEN
#cgo freebsd,!wayland netbsd,!wayland openbsd CFLAGS: -D_GLFW_X11 -D_GLFW_HAS_GLXGETPROCADDRESSARB
#cgo freebsd,wayland netbsd,wayland CFLAGS: -D_GLFW_WAYLAND

// Linker Options:
#cgo freebsd netbsd openbsd LDFLAGS: -lm
*/
import "C"
18 changes: 18 additions & 0 deletions v3.4/glfw/build_cgo_hack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build required

package glfw

// This file exists purely to prevent the golang toolchain from stripping
// away the c source directories and files when `go mod vendor` is used
// to populate a `vendor/` directory of a project depending on `go-gl/glfw`.
//
// How it works:
// - every directory which only includes c source files receives a dummy.go file.
// - every directory we want to preserve is included here as a _ import.
// - this file is given a build to exclude it from the regular build.
import (
// Prevent go tooling from stripping out the c source files.
_ "github.com/go-gl/glfw/v3.3/glfw/glfw/deps"
_ "github.com/go-gl/glfw/v3.3/glfw/glfw/include/GLFW"
_ "github.com/go-gl/glfw/v3.3/glfw/glfw/src"
)
21 changes: 21 additions & 0 deletions v3.4/glfw/c_glfw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package glfw

/*

#include "glfw/src/context.c"
#include "glfw/src/init.c"
#include "glfw/src/input.c"
#include "glfw/src/monitor.c"
#include "glfw/src/osmesa_context.c"
#include "glfw/src/platform.c"
#include "glfw/src/vulkan.c"
#include "glfw/src/window.c"

#include "glfw/src/null_init.c"
#include "glfw/src/null_joystick.c"
#include "glfw/src/null_monitor.c"
#include "glfw/src/null_window.c"


*/
import "C"
34 changes: 34 additions & 0 deletions v3.4/glfw/c_glfw_bsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//go:build freebsd || netbsd || openbsd
// +build freebsd netbsd openbsd

package glfw

/*
#ifdef _GLFW_WAYLAND
#include "glfw/src/wl_init.c"
#include "glfw/src/wl_monitor.c"
#include "glfw/src/wl_window.c"
#include "glfw/src/wayland-idle-inhibit-unstable-v1-client-protocol.c"
#include "glfw/src/wayland-pointer-constraints-unstable-v1-client-protocol.c"
#include "glfw/src/wayland-relative-pointer-unstable-v1-client-protocol.c"
#include "glfw/src/wayland-viewporter-client-protocol.c"
#include "glfw/src/wayland-xdg-decoration-unstable-v1-client-protocol.c"
#include "glfw/src/wayland-xdg-shell-client-protocol.c"
#endif
#ifdef _GLFW_X11
#include "glfw/src/x11_init.c"
#include "glfw/src/x11_monitor.c"
#include "glfw/src/x11_window.c"
#include "glfw/src/glx_context.c"
#endif
#include "glfw/src/null_joystick.c"
#include "glfw/src/posix_module.c"
#include "glfw/src/posix_poll.c"
#include "glfw/src/posix_time.c"
#include "glfw/src/posix_thread.c"
#include "glfw/src/xkb_unicode.c"
#include "glfw/src/egl_context.c"


*/
import "C"
17 changes: 17 additions & 0 deletions v3.4/glfw/c_glfw_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package glfw

/*
#cgo CFLAGS: -x objective-c
#include "glfw/src/cocoa_init.m"
#include "glfw/src/cocoa_joystick.m"
#include "glfw/src/cocoa_monitor.m"
#include "glfw/src/cocoa_window.m"
#include "glfw/src/cocoa_time.c"
#include "glfw/src/posix_module.c"
#include "glfw/src/posix_poll.c"
#include "glfw/src/posix_time.c"
#include "glfw/src/posix_thread.c"
#include "glfw/src/nsgl_context.m"
#include "glfw/src/egl_context.c"
*/
import "C"