Skip to content

Commit

Permalink
Merge pull request #786 from firelizzard18/glarea-set-error
Browse files Browse the repository at this point in the history
Implement GLArea.SetError
  • Loading branch information
andre-hub committed Jun 6, 2021
2 parents 3c26d4f + fd57267 commit fff1ae1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
16 changes: 16 additions & 0 deletions glib/quark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package glib

import (
"unsafe"
)

// #include <glib.h>
import "C"

// QuarkFromString is a wrapper around g_quark_from_string().
func QuarkFromString(str string) Quark {
cstr := (*C.gchar)(C.CString(str))
defer C.free(unsafe.Pointer(cstr))

return Quark(C.g_quark_from_string(cstr))
}
14 changes: 12 additions & 2 deletions gtk/glarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func (v *GLArea) SetRequiredVersion(major, minor int) {
}

// TODO:
// void gtk_gl_area_set_error (GtkGLArea *area, const GError *error);
// gtk_gl_area_set_has_alpha().
// gtk_gl_area_get_has_alpha().

Expand Down Expand Up @@ -171,7 +170,7 @@ func (v *GLArea) AttachBuffers() {
C.gtk_gl_area_attach_buffers(v.native())
}

// GError* gtk_gl_area_get_error (GtkGLArea *area);
// GetError is a wrapper around gtk_gl_area_get_error().
func (v *GLArea) GetError() error {
var err *C.GError = nil
err = C.gtk_gl_area_get_error(v.native())
Expand All @@ -181,3 +180,14 @@ func (v *GLArea) GetError() error {
}
return nil
}

// SetError is a wrapper around gtk_gl_area_set_error().
func (v *GLArea) SetError(domain glib.Quark, code int, err error) {
cstr := (*C.gchar)(C.CString(err.Error()))
defer C.free(unsafe.Pointer(cstr))

gerr := C.g_error_new_literal(C.GQuark(domain), C.gint(code), cstr)
defer C.g_error_free(gerr)

C.gtk_gl_area_set_error(v.native(), gerr)
}

0 comments on commit fff1ae1

Please sign in to comment.