Go bindings for GTK3

gotk3 GoDoc

Build Status

The gotk3 project provides Go bindings for GTK 3 and dependent projects. Each component is given its own subdirectory, which is used as the import path for the package. Partial binding support for the following libraries is currently implemented:

  • GTK 3 (3.12 and later)
  • GDK 3 (3.12 and later)
  • GLib 2 (2.36 and later)
  • Cairo (1.10 and later)

Care has been taken for memory management to work seamlessly with Go's garbage collector without the need to use or understand GObject's floating references.

for better understanding see package reference documation

On Linux, see which version your distribution has here with the search terms:

  • libgtk-3
  • libglib2
  • libgdk-pixbuf2

Sample Use

The following example can be found in Examples.

package main

import (
    "github.com/gotk3/gotk3/gtk"
    "log"
)

func main() {
    // Initialize GTK without parsing any command line arguments.
    gtk.Init(nil)

    // Create a new toplevel window, set its title, and connect it to the
    // "destroy" signal to exit the GTK main loop when it is destroyed.
    win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
    if err != nil {
        log.Fatal("Unable to create window:", err)
    }
    win.SetTitle("Simple Example")
    win.Connect("destroy", func() {
        gtk.MainQuit()
    })

    // Create a new label widget to show in the window.
    l, err := gtk.LabelNew("Hello, gotk3!")
    if err != nil {
        log.Fatal("Unable to create label:", err)
    }

    // Add the label to the window.
    win.Add(l)

    // Set the default window size.
    win.SetDefaultSize(800, 600)

    // Recursively show all widgets contained in this window.
    win.ShowAll()

    // Begin executing the GTK main loop.  This blocks until
    // gtk.MainQuit() is run.
    gtk.Main()
}

To build the example:

$ go build example.go

To build this example with older gtk version you should use gtk_3_10 tag:

$ go build -tags gtk_3_10 example.go

Example usage

package main

import (
    "log"
    "os"

    "github.com/gotk3/gotk3/glib"
    "github.com/gotk3/gotk3/gtk"
)

// Simple Gtk3 Application written in go.
// This application creates a window on the application callback activate.
// More GtkApplication info can be found here -> https://wiki.gnome.org/HowDoI/GtkApplication

func main() {
    // Create Gtk Application, change appID to your application domain name reversed.
    const appID = "org.gtk.example"
    application, err := gtk.ApplicationNew(appID, glib.APPLICATION_FLAGS_NONE)
    // Check to make sure no errors when creating Gtk Application
    if err != nil {
        log.Fatal("Could not create application.", err)
    }
    // Application signals available
    // startup -> sets up the application when it first starts
    // activate -> shows the default first window of the application (like a new document). This corresponds to the application being launched by the desktop environment.
    // open -> opens files and shows them in a new window. This corresponds to someone trying to open a document (or documents) using the application from the file browser, or similar.
    // shutdown ->  performs shutdown tasks
    // Setup Gtk Application callback signals
    application.Connect("activate", func() { onActivate(application) })
    // Run Gtk application
    os.Exit(application.Run(os.Args))
}

// Callback signal from Gtk Application
func onActivate(application *gtk.Application) {
    // Create ApplicationWindow
    appWindow, err := gtk.ApplicationWindowNew(application)
    if err != nil {
        log.Fatal("Could not create application window.", err)
    }
    // Set ApplicationWindow Properties
    appWindow.SetTitle("Basic Application.")
    appWindow.SetDefaultSize(400, 400)
    appWindow.Show()
}
package main

import (
    "log"
    "os"

    "github.com/gotk3/gotk3/glib"
    "github.com/gotk3/gotk3/gtk"
)

// Simple Gtk3 Application written in go.
// This application creates a window on the application callback activate.
// More GtkApplication info can be found here -> https://wiki.gnome.org/HowDoI/GtkApplication

func main() {
    // Create Gtk Application, change appID to your application domain name reversed.
    const appID = "org.gtk.example"
    application, err := gtk.ApplicationNew(appID, glib.APPLICATION_FLAGS_NONE)
    // Check to make sure no errors when creating Gtk Application
    if err != nil {
        log.Fatal("Could not create application.", err)
    }

    // Application signals available
    // startup -> sets up the application when it first starts
    // activate -> shows the default first window of the application (like a new document). This corresponds to the application being launched by the desktop environment.
    // open -> opens files and shows them in a new window. This corresponds to someone trying to open a document (or documents) using the application from the file browser, or similar.
    // shutdown ->  performs shutdown tasks
    // Setup activate signal with a closure function.
    application.Connect("activate", func() {
        // Create ApplicationWindow
        appWindow, err := gtk.ApplicationWindowNew(application)
        if err != nil {
            log.Fatal("Could not create application window.", err)
        }
        // Set ApplicationWindow Properties
        appWindow.SetTitle("Basic Application.")
        appWindow.SetDefaultSize(400, 400)
        appWindow.Show()
    })
    // Run Gtk application
    application.Run(os.Args)
}

Documentation

Each package's internal go doc style documentation can be viewed online without installing this package by using the GoDoc site (links to cairo, glib, gdk, and gtk documentation).

You can also view the documentation locally once the package is installed with the godoc tool by running godoc -http=":6060" and pointing your browser to http://localhost:6060/pkg/github.com/gotk3/gotk3

Installation

gotk3 currently requires GTK 3.6-3.24, GLib 2.36-2.46, and Cairo 1.10 or 1.12. A recent Go (1.8 or newer) is also required.

For detailed instructions see the wiki pages: installation

Using deprecated features

By default, deprecated GTK features are not included in the build.

By specifying the e.g. build tag gtk_3_20, any feature deprecated in GTK 3.20 or earlier will NOT be available. To enable deprecated features in the build, add the tag gtk_deprecated. Example:

$ go build -tags "gtk_3_10 gtk_deprecated" example.go

The same goes for

  • gdk-pixbuf: gdk_pixbuf_deprecated

TODO

  • Add bindings for all of GTK functions
  • Add tests for each implemented binding
  • See the next steps: wiki page and add your suggestion

License

Package gotk3 is licensed under the liberal ISC License.

Actually if you use gotk3, then gotk3 is statically linked into your application (with the ISC licence). The system libraries (e.g. GTK+, GLib) used via cgo use dynamic linking.

Owner
gotk3
golang binding for gtk3
gotk3
Comments
  • Fixifaces

    Fixifaces

    This PR adds interfaces for all functionality and changes everything to work with interfaces. It also puts all constants into a separate package as well. The goal is to make it possible to create a completely interface based implementation so that you can then inject the GTK/GDK/GLib/Pango/Cairo implementation in one single place, making it possible to write well tested implementations of gui's.

    This fixes #90.

    Important - this PR will break clients. For most clients it shouldn't be very bad to update, and I firmly believe this will allow users to build better applications using gotk3.

    Thoughts?

  • CSS load from resource and add gresource_* functions

    CSS load from resource and add gresource_* functions

    Added basic GResource methods:

    GTK

    • gtk_css_provider_load_from_resource()

    GIO

    • g_resource_load()
    • g_resource_new_from_data()
    • g_resources_register()
    • g_resources_unregister()
    • g_resources_enumerate_children()

    Also added Go module for this library

  • Windows Installation seems broken

    Windows Installation seems broken

    Hello,

    in my opinion the windows installation process isn't working anymore as there are some download links who don't work anymore. Any way to simplify this? Thank you in advance

  • Cross compile instructions need to be updated

    Cross compile instructions need to be updated

    The instructions on compiling for Windows during cross compilation seems to be outdated. For example the yaourt program is dead and not used anymore so it makes it more difficult to get everything built correctly. It would be great if the cross compilation instructions could be updated with better instructions and being more up to date.

  • [BUG] App sometimes crashes with cgo error

    [BUG] App sometimes crashes with cgo error

    Describe the bug

    Most of the time my app runs well, but at some rare time it crashes by itself, even when there is no user interaction.

    To Reproduce

    Launch the app, let it run, without user action. At random time it crashes.

    Error messages

    MEMORY-ERROR: myapp[779]: GSlice: assertion failed: sinfo->n_allocated > 0 SIGABRT: abort PC=0x7f378e36ce97 m=0 sigcode=18446744073709551610

    goroutine 0 [idle]: runtime: unknown pc 0x7f378e36ce97 stack: frame={sp:0x7ffef7d1be60, fp:0x0} stack=[0x7ffef751da88,0x7ffef7d1cac0) 00007ffef7d1bd60: 00000000017a1720 00007f378f6d1e25 00007ffef7d1bd70: 0000000000000000 0000000000000000 00007ffef7d1bd80: 000001e500000018 0000000000000000 00007ffef7d1bd90: 00007ffef7d1bd90 00007ffef7d1bd90 00007ffef7d1bda0: 0000000300000001 e615fc57432f0800 00007ffef7d1bdb0: 3ff0000000000000 0000000001da6650 00007ffef7d1bdc0: 00007ffef7d1bec0 e615fc57432f0800 00007ffef7d1bdd0: 0000000001b16080 0000000001da34d0 00007ffef7d1bde0: 00007ffef7d1bee0 0000000000000000 00007ffef7d1bdf0: 0000000001b16080 00007ffef7d1bf00 00007ffef7d1be00: 00007ffef7d1be10 00007f37900788b4 00007ffef7d1be10: 0000000001da3b10 00007f378f71541d 00007ffef7d1be20: 00007ffef7d1bee0 00007f378a4cd68c 00007ffef7d1be30: 000000000222a990 00007f378a4cd68c 00007ffef7d1be40: 0000000001c91df0 e615fc57432f0800 00007ffef7d1be50: 00007ffef7d1bf50 e615fc57432f0800 00007ffef7d1be60: <0000000000000000 000000003ccf0201 00007ffef7d1be70: 0000000000000000 0000000000000000 00007ffef7d1be80: 00000000017e2090 000000003ccf0201 00007ffef7d1be90: 0000000000000000 00007f378a4cdd38 00007ffef7d1bea0: 0000000000000000 00000000017e3158 00007ffef7d1beb0: 0000000000000020 00000001017e3158 00007ffef7d1bec0: 0000000000000000 0000000000000020 00007ffef7d1bed0: 00000000017e2104 0000000000001000 00007ffef7d1bee0: fffffffe7fffffff ffffffffffffffff 00007ffef7d1bef0: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf00: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf10: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf20: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf30: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf40: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf50: ffffffffffffffff ffffffffffffffff runtime: unknown pc 0x7f378e36ce97 stack: frame={sp:0x7ffef7d1be60, fp:0x0} stack=[0x7ffef751da88,0x7ffef7d1cac0) 00007ffef7d1bd60: 00000000017a1720 00007f378f6d1e25 00007ffef7d1bd70: 0000000000000000 0000000000000000 00007ffef7d1bd80: 000001e500000018 0000000000000000 00007ffef7d1bd90: 00007ffef7d1bd90 00007ffef7d1bd90 00007ffef7d1bda0: 0000000300000001 e615fc57432f0800 00007ffef7d1bdb0: 3ff0000000000000 0000000001da6650 00007ffef7d1bdc0: 00007ffef7d1bec0 e615fc57432f0800 00007ffef7d1bdd0: 0000000001b16080 0000000001da34d0 00007ffef7d1bde0: 00007ffef7d1bee0 0000000000000000 00007ffef7d1bdf0: 0000000001b16080 00007ffef7d1bf00 00007ffef7d1be00: 00007ffef7d1be10 00007f37900788b4 00007ffef7d1be10: 0000000001da3b10 00007f378f71541d 00007ffef7d1be20: 00007ffef7d1bee0 00007f378a4cd68c 00007ffef7d1be30: 000000000222a990 00007f378a4cd68c 00007ffef7d1be40: 0000000001c91df0 e615fc57432f0800 00007ffef7d1be50: 00007ffef7d1bf50 e615fc57432f0800 00007ffef7d1be60: <0000000000000000 000000003ccf0201 00007ffef7d1be70: 0000000000000000 0000000000000000 00007ffef7d1be80: 00000000017e2090 000000003ccf0201 00007ffef7d1be90: 0000000000000000 00007f378a4cdd38 00007ffef7d1bea0: 0000000000000000 00000000017e3158 00007ffef7d1beb0: 0000000000000020 00000001017e3158 00007ffef7d1bec0: 0000000000000000 0000000000000020 00007ffef7d1bed0: 00000000017e2104 0000000000001000 00007ffef7d1bee0: fffffffe7fffffff ffffffffffffffff 00007ffef7d1bef0: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf00: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf10: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf20: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf30: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf40: ffffffffffffffff ffffffffffffffff 00007ffef7d1bf50: ffffffffffffffff ffffffffffffffff

    goroutine 1 [syscall]: runtime.cgocall(0x920d30, 0xc000199c20, 0xc00007b920) /usr/share/golang/src/runtime/cgocall.go:133 +0x5b fp=0xc000199bf0 sp=0xc000199bb8 pc=0x47bb8b github.com/gotk3/gotk3/glib._Cfunc_g_application_run(0x17b81a0, 0x0, 0x17bbb60, 0x0) go-build368422021/b011/_cgo_gotypes.go:1426 +0x4d fp=0xc000199c20 sp=0xc000199bf0 pc=0x5c9f8d github.com/gotk3/gotk3/glib.(*Application).Run.func4(0xc00007b920, 0x0, 0x0, 0x0, 0x17bbb60, 0x17bbb60) third_party/go/src/github.com/gotk3/gotk3/glib/application.go:185 +0x94 fp=0xc000199c58 sp=0xc000199c20 pc=0x5ddae4 github.com/gotk3/gotk3/glib.(*Application).Run(0xc00007b920, 0x0, 0x0, 0x0, 0x0) third_party/go/src/github.com/gotk3/gotk3/glib/application.go:185 +0x187 fp=0xc000199d10 sp=0xc000199c58 pc=0x5d1b37

    Environment:

    gtk3 version: 'cb2aa31c619474273939afe1ea7c83c1ee82fbc9' go version: '1.14.1' os: 'Ubuntu 20.04'

  • Build fails with GTK 3.22

    Build fails with GTK 3.22

    I'm running on debian, with GTK packages:

    $ dpkg -l libgtk-3\*
    Desired=Unknown/Install/Remove/Purge/Hold
    | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
    |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
    ||/ Name                              Version               Architecture          Description
    +++-=================================-=====================-=====================-========================================================================
    ii  libgtk-3-0:amd64                  3.22.11-1             amd64                 GTK+ graphical user interface library
    ii  libgtk-3-bin                      3.22.11-1             amd64                 programs for the GTK+ graphical user interface library
    ii  libgtk-3-common                   3.22.11-1             all                   common files for the GTK+ graphical user interface library
    ii  libgtk-3-dev:amd64                3.22.11-1             amd64                 development files for the GTK+ library
    

    The build fails as follows:

    $ go get -v -tags gtk_3_22 github.com/gotk3/gotk3/gtk
    github.com/gotk3/gotk3/glib
    github.com/gotk3/gotk3/cairo
    github.com/gotk3/gotk3/gdk
    github.com/gotk3/gotk3/pango
    github.com/gotk3/gotk3/gtk
    # github.com/gotk3/gotk3/gtk
    cgo-gcc-prolog: In function ‘_cgo_ec24e68943f7_Cfunc_gtk_widget_override_background_color’:
    cgo-gcc-prolog:305:2: warning: ‘gtk_widget_override_background_color’ is deprecated [-Wdeprecated-declarations]
    In file included from /usr/include/gtk-3.0/gtk/gtkapplication.h:27:0,
                     from /usr/include/gtk-3.0/gtk/gtkwindow.h:33,
                     from /usr/include/gtk-3.0/gtk/gtkdialog.h:32,
                     from /usr/include/gtk-3.0/gtk/gtkaboutdialog.h:30,
                     from /usr/include/gtk-3.0/gtk/gtk.h:31,
                     from ../../go/src/github.com/gotk3/gotk3/gtk/gtk_since_3_20.go:8:
    /usr/include/gtk-3.0/gtk/gtkwidget.h:1148:14: note: declared here
     void         gtk_widget_override_background_color (GtkWidget     *widget,
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # github.com/gotk3/gotk3/gtk
    cgo-gcc-prolog: In function ‘_cgo_ec24e68943f7_Cfunc_gtk_widget_override_font’:
    cgo-gcc-prolog:617:2: warning: ‘gtk_widget_override_font’ is deprecated [-Wdeprecated-declarations]
    In file included from /usr/include/gtk-3.0/gtk/gtkapplication.h:27:0,
                     from /usr/include/gtk-3.0/gtk/gtkwindow.h:33,
                     from /usr/include/gtk-3.0/gtk/gtkdialog.h:32,
                     from /usr/include/gtk-3.0/gtk/gtkaboutdialog.h:30,
                     from /usr/include/gtk-3.0/gtk/gtk.h:31,
                     from ../../go/src/github.com/gotk3/gotk3/gtk/label.go:6:
    /usr/include/gtk-3.0/gtk/gtkwidget.h:1153:14: note: declared here
     void         gtk_widget_override_font             (GtkWidget                  *widget,
                  ^~~~~~~~~~~~~~~~~~~~~~~~
    # github.com/gotk3/gotk3/gtk
    ../../go/src/github.com/gotk3/gotk3/gtk/gtk_since_3_20.go:66: cannot use (*C.gchar)(cstr) (type *C.gchar) as type *C.char in argument to func literal
    ../../go/src/github.com/gotk3/gotk3/gtk/gtk_since_3_20.go:71: cannot use (func literal)(v.native()) (type *C.char) as type *C.gchar in argument to stringReturn
    ../../go/src/github.com/gotk3/gotk3/gtk/gtk_since_3_20.go:190: cannot use (*C.gchar)(cstr) (type *C.gchar) as type *C.char in argument to func literal
    ../../go/src/github.com/gotk3/gotk3/gtk/gtk_since_3_20.go:195: cannot use (func literal)(v.native()) (type *C.char) as type *C.gchar in argument to stringReturn
    ../../go/src/github.com/gotk3/gotk3/gtk/gtk_since_3_20.go:202: cannot use (*C.gchar)(cstr) (type *C.gchar) as type *C.char in argument to func literal
    ../../go/src/github.com/gotk3/gotk3/gtk/gtk_since_3_20.go:207: cannot use (func literal)(v.native()) (type *C.char) as type *C.gchar in argument to stringReturn
    ../../go/src/github.com/gotk3/gotk3/gtk/gtk_since_3_20.go:212: cannot use _Cfunc_CString(color) (type *C.char) as type *C.gchar in argument to _Cfunc_gdk_rgba_parse
    

    The behavior is the same with and without -tags gtk_3_22.

  • fatal error: unexpected signal during runtime execution

    fatal error: unexpected signal during runtime execution

    Describe the bug gtk.ImageNewFromFile (and gtk.ImageNewFromPixbuf()) gives a fatal error. I have tried several different jpg:s and png:s.

    To Reproduce

    package main
    
    import (
    	"fmt"
    	"github.com/gotk3/gotk3/gdk"
    	"github.com/gotk3/gotk3/gtk"
    )
    
    func main() {
    	imagePath := "/home/per/temp/Best.png"
    	image, err := gtk.ImageNewFromFile(imagePath)
    	if err!=nil {
    		panic(err)
    	}
    	fmt.Println(image.GetAllocation())
    }
    

    Expected behavior No error message

    Error messages GOROOT=/usr/lib/go #gosetup GOPATH=/home/per/go #gosetup /usr/lib/go/bin/go build -o /home/per/code/test/test -gcflags all=-N -l . #gosetup /var/lib/snapd/snap/goland/106/plugins/go/lib/dlv/linux/dlv --listen=0.0.0.0:41703 --headless=true --api-version=2 --check-go-version=false --only-same-user=false exec /home/per/code/test/test -- API server listening at: [::]:41703

    (process:90209): Gtk-CRITICAL **: 18:57:50.140: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

    (process:90209): Gtk-CRITICAL **: 18:57:50.142: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

    (process:90209): Gtk-CRITICAL **: 18:57:50.142: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed fatal error: unexpected signal during runtime execution [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x7fdbd1350c1c]

    runtime stack: runtime.throw(0x6cb5b9, 0x2a) /usr/lib/go/src/runtime/panic.go:1116 +0x72 runtime.sigpanic() /usr/lib/go/src/runtime/signal_unix.go:704 +0x269

    goroutine 1 [syscall]: runtime.cgocall(0x5b6ad0, 0xc00010ddf8, 0x1f99920) /usr/lib/go/src/runtime/cgocall.go:133 +0x5b fp=0xc00010ddc8 sp=0xc00010dd90 pc=0x47e03b github.com/gotk3/gotk3/gtk._Cfunc_gtk_image_new_from_pixbuf(0x1f99920, 0x0) _cgo_gotypes.go:14924 +0x4a fp=0xc00010ddf8 sp=0xc00010ddc8 pc=0x55908a github.com/gotk3/gotk3/gtk.ImageNewFromPixbuf.func1(0xc000010038, 0x0) /home/per/go/pkg/mod/github.com/gotk3/[email protected]/gtk/gtk.go:5281 +0x73 fp=0xc00010de40 sp=0xc00010ddf8 pc=0x577133 github.com/gotk3/gotk3/gtk.ImageNewFromPixbuf(0xc000010038, 0x0, 0x0, 0x0) /home/per/go/pkg/mod/github.com/gotk3/[email protected]/gtk/gtk.go:5281 +0x45 fp=0xc00010de88 sp=0xc00010de40 pc=0x569d45 main.main() /home/per/code/test/main.go:15 +0x135 fp=0xc00010df88 sp=0xc00010de88 pc=0x585d35 runtime.main() /usr/lib/go/src/runtime/proc.go:204 +0x1cf fp=0xc00010dfe0 sp=0xc00010df88 pc=0x4b790f runtime.goexit() /usr/lib/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc00010dfe8 sp=0xc00010dfe0 pc=0x4e9fe1

    Debugger finished with exit code 0

    Environment: gtk3 version: 3.24.23-4 go version: 1.15.3 os: Manjaro (Cinnamon)

    Additional information Because of #670, I am currently running on the master branch instead of 0.5.0. Maybe this is my problem? Maybe I should not run on go 1.15.3, and then use the 0.5.0 (or older) release instead?

    go.mod:

    module test
    
    go 1.15
    
    require (
    	github.com/gotk3/gotk3 v0.5.1-0.20201028052159-952547abf55a
    )
    
  • [BUG] Fails to build under Go 1.16

    [BUG] Fails to build under Go 1.16

    I’m running Ubuntu 20.04 with GTK 3.24:

    $ lsb_release -dcr
    Description:	Ubuntu 20.04.2 LTS
    Release:	20.04
    Codename:	focal
    
    $ dpkg -l | grep libgtk-3-dev
    ii  libgtk-3-dev:amd64                         3.24.20-0ubuntu1                      amd64        development files for the GTK library
    

    On a fresh checkout of gotk3:

    $ git clone https://github.com/gotk3/gotk3.git
    
    $ cd gotk3/
    
    $ git rev-parse HEAD
    3091555944e560d3aadcf6bbe84080ebdc52a502
    

    I can build the library with Go 1.15:

    $ go version
    go version go1.15.7 linux/amd64
    
    $ go build github.com/gotk3/gotk3/gtk
    

    but not with Go 1.16:

    $ go version
    go version go1.16rc1 linux/amd64
    
    $ go build github.com/gotk3/gotk3/gtk
    gtk/accel.go:272:5: val.accel_flags undefined (type _Ctype_struct__GtkAccelKey has no field or method accel_flags)
    gtk/accel.go:285:22: obj.accel_flags undefined (type *_Ctype_struct__GtkAccelKey has no field or method accel_flags)
    
  • Application.GetWindows() raises an error

    Application.GetWindows() raises an error

    I have been trying to re-write all C examples from GTK docs in Go. I ran into a problem when I tried to re-write an example that uses an Application with glib.APPLICATION_HANDLES_OPEN.

    To reproduce the error:

    package main
    
    import (
      "os"
      "github.com/gotk3/gotk3/gtk"
      "github.com/gotk3/gotk3/glib"
      "fmt"
    )
    
    func exampleAppActivate(app *gtk.Application) {
      win, _ := gtk.ApplicationWindowNew(app)
      win.Present()
    }
    
    func exampleAppOpen(app *gtk.Application, files unsafe.Pointer, gInt int, hint string) {
      var win *gtk.ApplicationWindow
       windows := app.GetWindows()
      if windows != nil && windows.Length() != 0 {
        win = (windows.Data()).(*gtk.ApplicationWindow)
      } else {
        win, _ = gtk.ApplicationWindowNew(app)
      } 
      // Some code to actually open the file
      win.Present()
    }
    
    func main() {
      app, _ := gtk.ApplicationNew("com.github.twistedhardware.gtk.example-4", glib.APPLICATION_HANDLES_OPEN)
      app.Connect("activate", exampleAppActivate)
      app.Connect("open", exampleAppOpen)
      status := app.Run(os.Args)
      fmt.Println(status)
    }
    

    If you compile the application and run it without passing a file to the application, it runs just fine because it does not invoke exampleAppOpen.

    To actually reproduce the error:

    $ go build
    $ ./example-4 some-file-name
    

    Then you will get this error:

    fatal error: runtime.SetFinalizer: pointer not in allocated block
    
    goroutine 1 [running, locked to thread]:
    runtime.throw(0x819904, 0x34)
    	/usr/local/go/src/runtime/panic.go:617 +0x72 fp=0xc0000a36b8 sp=0xc0000a3688 pc=0x48eff2
    runtime.SetFinalizer(0x7a6ea0, 0x0, 0x76a080, 0x81a3a8)
    	/usr/local/go/src/runtime/mfinal.go:353 +0x767 fp=0xc0000a37a0 sp=0xc0000a36b8 pc=0x47ba77
    github.com/gotk3/gotk3/gtk.(*Application).GetWindows(0xc000084420, 0xc000084540)
    	/home/abdullah/go/src/github.com/gotk3/gotk3/gtk/application.go:154 +0x89 fp=0xc0000a37e0 sp=0xc0000a37a0 pc=0x5ae729
    main.exampleAppOpen(0xc000084420, 0x2e493b0, 0x1, 0x0, 0x0)
    	/home/abdullah/go/src/github.com/twistedhardware/gtk/example-4/main.go:18 +0x2f fp=0xc0000a3818 sp=0xc0000a37e0 pc=0x71911f
    runtime.call64(0xc000084450, 0x81ae50, 0xc000084540, 0x2800000028)
    	/usr/local/go/src/runtime/asm_amd64.s:520 +0x3b fp=0xc0000a3868 sp=0xc0000a3818 pc=0x4b70cb
    reflect.Value.call(0x783fe0, 0x81ae50, 0x13, 0x811597, 0x4, 0xc000090120, 0x4, 0x4, 0x1080900, 0x0, ...)
    	/usr/local/go/src/reflect/value.go:447 +0x461 fp=0xc0000a3a88 sp=0xc0000a3868 pc=0x4d9671
    reflect.Value.Call(0x783fe0, 0x81ae50, 0x13, 0xc000090120, 0x4, 0x4, 0x1080900, 0x98, 0x476665)
    	/usr/local/go/src/reflect/value.go:308 +0xa4 fp=0xc0000a3af0 sp=0xc0000a3a88 pc=0x4d90f4
    github.com/gotk3/gotk3/glib.goMarshal(0x2d11530, 0x0, 0x4, 0x7ffdcbdc4990, 0x7ffdcbdc4910, 0x0)
    	/home/abdullah/go/src/github.com/gotk3/gotk3/glib/glib.go:233 +0x6f7 fp=0xc0000a3c68 sp=0xc0000a3af0 pc=0x521357
    github.com/gotk3/gotk3/glib._cgoexpwrap_8c39c85f7640_goMarshal(0x2d11530, 0x0, 0x4, 0x7ffdcbdc4990, 0x7ffdcbdc4910, 0x0)
    	_cgo_gotypes.go:4254 +0x5b fp=0xc0000a3ca8 sp=0xc0000a3c68 pc=0x51ee1b
    runtime.call64(0x0, 0x7ffdcbdc46b0, 0x7ffdcbdc4750, 0x30)
    	/usr/local/go/src/runtime/asm_amd64.s:520 +0x3b fp=0xc0000a3cf8 sp=0xc0000a3ca8 pc=0x4b70cb
    runtime.cgocallbackg1(0x0)
    	/usr/local/go/src/runtime/cgocall.go:314 +0x177 fp=0xc0000a3d70 sp=0xc0000a3cf8 pc=0x467c07
    runtime.cgocallbackg(0x0)
    	/usr/local/go/src/runtime/cgocall.go:191 +0xc5 fp=0xc0000a3dd8 sp=0xc0000a3d70 pc=0x4679f5
    runtime.cgocallback_gofunc(0x4678bf, 0x719770, 0xc0000a3e68, 0xc0000a3e58)
    	/usr/local/go/src/runtime/asm_amd64.s:773 +0x9b fp=0xc0000a3df8 sp=0xc0000a3dd8 pc=0x4b861b
    runtime.asmcgocall(0x719770, 0xc0000a3e68)
    	/usr/local/go/src/runtime/asm_amd64.s:620 +0x42 fp=0xc0000a3e00 sp=0xc0000a3df8 pc=0x4b84b2
    runtime.cgocall(0x719770, 0xc0000a3e68, 0xc000084390)
    	/usr/local/go/src/runtime/cgocall.go:131 +0x7f fp=0xc0000a3e38 sp=0xc0000a3e00 pc=0x4678bf
    github.com/gotk3/gotk3/glib._Cfunc_g_application_run(0x2d0f140, 0x2, 0x2d0ef60, 0x0)
    	_cgo_gotypes.go:1222 +0x4d fp=0xc0000a3e68 sp=0xc0000a3e38 pc=0x519f8d
    github.com/gotk3/gotk3/glib.(*Application).Run.func4(0xc000084390, 0xc00000e0a0, 0x2, 0x2, 0x2d0ef60, 0x2d11530)
    	/home/abdullah/go/src/github.com/gotk3/gotk3/glib/application.go:202 +0xa6 fp=0xc0000a3ea8 sp=0xc0000a3e68 pc=0x5289e6
    github.com/gotk3/gotk3/glib.(*Application).Run(0xc000084390, 0xc00000e0a0, 0x2, 0x2, 0x0)
    	/home/abdullah/go/src/github.com/gotk3/gotk3/glib/application.go:202 +0x13e fp=0xc0000a3f10 sp=0xc0000a3ea8 pc=0x51f6fe
    main.main()
    	/home/abdullah/go/src/github.com/twistedhardware/gtk/example-4/main.go:32 +0x127 fp=0xc0000a3f98 sp=0xc0000a3f10 pc=0x7192e7
    runtime.main()
    	/usr/local/go/src/runtime/proc.go:200 +0x20c fp=0xc0000a3fe0 sp=0xc0000a3f98 pc=0x49095c
    runtime.goexit()
    	/usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc0000a3fe8 sp=0xc0000a3fe0 pc=0x4b8d61
    
  • Unable to build when importing gotk3/gotk3

    Unable to build when importing gotk3/gotk3

    I have libgtk-3-dev version 3.12.2 installed on Ubuntu 14.04, but when I run go build main.go I get the following output:

    # github.com/gotk3/gotk3/gtk
    could not determine kind of name for C.gtk_application_get_actions_for_accel
    could not determine kind of name for C.gtk_application_get_menu_by_id
    could not determine kind of name for C.gtk_application_prefers_app_menu
    

    Do you have any suggestions?

  • Miss merged PR

    Miss merged PR

    Describe the bug #826 This PR should not have been merged !!! It contains "bad / misplaced" implementation of binding_dup_source and binding_dup_target

    // Retrieves the GObject instance used as the source of the binding
    func (v *Binding) GetSource() *Object {
    // 	obj := C.g_binding_get_source(v.native())
    	obj := C.g_binding_dup_source(v.native())
    	if obj == nil {
    		return nil
    	}
    	return wrapObject(unsafe.Pointer(obj))
    }
    

    that will create compilation error.

    Hi, ~~@MJacred~~ @andre-hub, You have merged a bad pull request, can you reverse it please. The #828 is the correct implementation https://github.com/gotk3/gotk3/commit/73371d7038f2874484dbc01d90ae4081f3504e3b

  • [Project question] Image Draw

    [Project question] Image Draw

    Hello Everybody!

    I would like draw a image to canvas, but I don't understand how could to do this :( (load a image file, and draw it to a position) Can I ask a complete example, please?

    BR, Peter

  • [Feature] more usable doc navigability

    [Feature] more usable doc navigability

    For larger packages the godoc generated "Index" section is most unhelpful. This is especailly true of gotk3's documentation. I have found that Alt+F pops up a search dialog which helps a bit, but again that lists everything rather than just the main items.

    There are three separate ways this could be improved:

    1. For types with methods, show, e.g., " type BmpImage" with no methods, unless the user clicks the triangle in which case it becomes "▼ type BmpImage" with all the methods shown (as now).
    2. When there are more than some threshold number of functions (or methods) — say 7, where the first word is the same (e.g., func Draw(), func DrawArc(...), ..., func DrawYxLine3(...)), use the same technique as decribed above in 1.
    3. For the Alt+F popup search just list the types and not their methods. These changes would make navigation much easier.

    I suggested these changes to the Go devs but they aren't going to do them: github issue.

    So maybe there'd be some way of producing more navigable docs specifically for gotk3?

    It would also be nice to see some more gotk3 examples, ideally more complete ones (e.g., a contacts or addressbook app which is a typical GUI "hello" kind of example or a very simple icon editor); and of course, it would be nice to see gotk3 versions of the 7guis.

  • [BUG] won't install

    [BUG] won't install

    I have a fresh Debian 11 install. I have installed Go 1.19 using the binary. I installed the libgtk-3-dev libcairo2-dev libglib2.0-dev libraries as per the installation doc. However, I could not install the bindings:

    mark@debianvm:~$ pkg-config --modversion gtk+-3.0
    3.24.24
    mark@debianvm:~$ go get -tags gtk_3_24 github.com/gotk3/gotk3/gtk
    go: go.mod file not found in current directory or any parent directory.
    	'go get' is no longer supported outside a module.
    	To build and install a command, use 'go install' with a version,
    	like 'go install example.com/cmd@latest'
    	For more information, see https://golang.org/doc/go-get-install-deprecation
    	or run 'go help get' or 'go help install'.
    mark@debianvm:~$ go install github.com/gotk3/gotk3/gtk
    go: 'go install' requires a version when current directory is not in a module
    	Try 'go install github.com/gotk3/gotk3/gtk@latest' to install the latest version
    mark@debianvm:~$ go install github.com/gotk3/gotk3/gtk@latest
    go: downloading github.com/gotk3/gotk3 v0.6.1
    package github.com/gotk3/gotk3/gtk is not a main package
    mark@debianvm:~$ go install github.com/gotk3/gotk3@latest
    go: github.com/gotk3/gotk3@latest: module github.com/gotk3/gotk3@latest found (v0.6.1), but does not contain package github.com/gotk3/gotk3
    mark@debianvm:~$ go install github.com/gotk3@latest
    go: github.com/gotk3@latest: invalid github.com import path "github.com/gotk3"
    
  • [Project question] How to avoid rebuilding gtk every time?

    [Project question] How to avoid rebuilding gtk every time?

    Every time I create a new project that uses gotk3 vscode will compile it from scratch and it takes a bit of time, is there a way to cache built package at the system/installation level? By looking at the process tree it seems like gopls is doing it...

  • [BUG] Window.SetIcon seems to not work on macOS

    [BUG] Window.SetIcon seems to not work on macOS

    Describe the bug

    Method GtkWindow.SetIconFromFile seems to have no effect or just silently fails without returning error.

    To Reproduce

    win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
    error := win.SetIconFromFile("icon.png")
    
    if error != nil {
      log.Fatal("Failed to load icon ", error)
    }
    

    Expected behavior

    Icon showing up properly on taskbar or non-nil method return value.

    Error messages

    None.

    Environment:

    gtk3 version: 3.24.34 go version: go version go1.19.3 darwin/arm64 os: macOS Ventura 13.0.1 (22A400)

    Additional context

    Deprecation warning on runtime:

    # github.com/gotk3/gotk3/glib
    cgo-gcc-prolog:71:35: warning: 'g_binding_get_source' is deprecated: Use 'g_binding_dup_source' instead [-Wdeprecated-declarations]
    /opt/homebrew/Cellar/glib/2.74.0/include/glib-2.0/gobject/gbinding.h:114:1: note: 'g_binding_get_source' has been explicitly marked deprecated here
    /opt/homebrew/Cellar/glib/2.74.0/include/glib-2.0/glib/gversionmacros.h:1079:49: note: expanded from macro 'GLIB_DEPRECATED_IN_2_68_FOR'
    /opt/homebrew/Cellar/glib/2.74.0/include/glib-2.0/glib/gmacros.h:1243:32: note: expanded from macro 'GLIB_DEPRECATED_FOR'
    /opt/homebrew/Cellar/glib/2.74.0/include/glib-2.0/glib/gmacros.h:1211:44: note: expanded from macro 'G_DEPRECATED_FOR'
    cgo-gcc-prolog:107:35: warning: 'g_binding_get_target' is deprecated: Use 'g_binding_dup_target' instead [-Wdeprecated-declarations]
    /opt/homebrew/Cellar/glib/2.74.0/include/glib-2.0/gobject/gbinding.h:118:1: note: 'g_binding_get_target' has been explicitly marked deprecated here
    /opt/homebrew/Cellar/glib/2.74.0/include/glib-2.0/glib/gversionmacros.h:1079:49: note: expanded from macro 'GLIB_DEPRECATED_IN_2_68_FOR'
    /opt/homebrew/Cellar/glib/2.74.0/include/glib-2.0/glib/gmacros.h:1243:32: note: expanded from macro 'GLIB_DEPRECATED_FOR'
    /opt/homebrew/Cellar/glib/2.74.0/include/glib-2.0/glib/gmacros.h:1211:44: note: expanded from macro 'G_DEPRECATED_FOR'
    
  • Loading jpeg or png image from a web API

    Loading jpeg or png image from a web API

    Does anyone know of any example code that shows how to load a jpeg or png file from a web API?

    I now how to obtain the url containing the file name from the API, but I do not know how to load the image into the user interface.

    I suspect that the solution would involve some combination of gtk.Image, gdk.Pixbuf, and and possibly gio.MemoryInputStream.

wsmgr-for-i3 is a Go GTK3 program to manage i3 workspaces.
wsmgr-for-i3  is a Go GTK3 program to manage i3 workspaces.

wsmgr-for-i3 wsmgr-for-i3 (workspace manager for i3) is a Go GTK3 program to manage i3 workspaces. It allows you to re-order and re-name workspaces ea

Nov 5, 2022
A rewrite of DrPetter's sfxr in Go and GTK3

gosfxr This is a rewrite of DrPetter's sfxr in Go and GTK3 that only exists because I wanted to get my feet wet with UI development in Go. Please refe

Dec 27, 2021
Basic Go bindings for FLTK

Go FLTK This is a simple go wrapper for FLTK2, which I did to support my Go version of Ober (based on Acme), Gober. It's very small and should be fair

Mar 12, 2022
qt5 bindings for go

#go-qt5 ##Before you start This is a fork of visualfc's qt4 bindings, and several critical bugs are inherited along the way. Until these bugs are fixe

Jan 1, 2023
Tcl/Tk Go bindings

Tcl/Tk Go bindings. VERSION NOTICE Recently Tcl/Tk 8.6 were released. I use them as a default, if you still have Tcl/Tk 8.5 use `go get -tags tcl85

Nov 21, 2022
Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development

Go bindings for Sciter Check this page for other language bindings (Delphi / D / Go / .NET / Python / Rust). Attention The ownership of project is tra

Dec 23, 2022
:traffic_light: Go bindings for libappindicator3 C library

go-appindicator Go bindings for libappindicator3 C library. Libappindicator is a library to allow applications to export a menu into the Unity Menu ba

Jun 19, 2022
Go bindings for GLFW 3

GLFW 3.3 for Go Installation GLFW C library source is included and built automatically as part of the Go package. But you need to make sure you have d

Dec 27, 2022
gobbi is a set of generated Go bindings for gtk et al.

gobbi gobject bindings gobbi is a set of generated Go bindings for gobject based libraries. There are bindings, with varying degrees of completeness,

May 6, 2022
This project provides Go bindings for nuklear.h — a small ANSI C GUI library.
This project provides Go bindings for nuklear.h — a small ANSI C GUI library.

Nuklear Package nk provides Go bindings for nuklear.h — a small ANSI C gui library. See github.com/vurtun/nuklear. All the binding code has automatica

Jan 1, 2023
A GTK4 bindings generator for Go.

gotk4 A GTK4 bindings generator for Go. Progress tracker: https://github.com/diamondburned/gotk4/issues/2 All generated packages are in pkg/. The gene

Jan 6, 2023
Golang bindings for XCGUI, Windows GUI library, DirectUI design idea.
Golang bindings for XCGUI, Windows GUI library, DirectUI design idea.

XCGUI 项目文档 帮助文档 程序示例 介绍 English | 简体中文 DirectUI设计思想: 在窗口内没有子窗口,界面元素都是逻辑上的区域(无HWND句柄,安全,灵活), 所有UI元素都是自主开发(不受系统限制), 更加灵活的实现各种程序界面,满足不同用户的需求.

Dec 22, 2022
Go bindings for divideon/xvc

go-xvc [WIP] Go bindings for divideon/xvc Requirements requires xvc install on your system $ git clone https://github.com/divideon/xvc.git $ cd xvc $

Feb 7, 2022
Go bindings for GTK3

gotk3 The gotk3 project provides Go bindings for GTK 3 and dependent projects. Each component is given its own subdirectory, which is used as the impo

Jan 6, 2023
GTK3-based dock for sway
GTK3-based dock for sway

nwg-dock Fully configurable (w/ command line arguments and css) dock, written in Go, aimed exclusively at sway Wayland compositor. It features pinned

Dec 23, 2022
wsmgr-for-i3 is a Go GTK3 program to manage i3 workspaces.
wsmgr-for-i3  is a Go GTK3 program to manage i3 workspaces.

wsmgr-for-i3 wsmgr-for-i3 (workspace manager for i3) is a Go GTK3 program to manage i3 workspaces. It allows you to re-order and re-name workspaces ea

Nov 5, 2022
A rewrite of DrPetter's sfxr in Go and GTK3

gosfxr This is a rewrite of DrPetter's sfxr in Go and GTK3 that only exists because I wanted to get my feet wet with UI development in Go. Please refe

Dec 27, 2021
libsox bindings for go

gosox "SoX − Sound eXchange, the Swiss Army knife of audio manipulation" Go bindings for the libsox sound library For more information and documentati

Nov 22, 2022
Go bindings for the PortAudio audio I/O library

portaudio This package provides an interface to the PortAudio audio I/O library. See the package documentation for details. To build this package you

Jan 1, 2023
Go bindings for libportmidi

portmidi Want to output to an MIDI device or listen your MIDI device as an input? This package contains Go bindings for PortMidi. libportmidi (v. 217)

Dec 25, 2022