How to make gtk apps

C Gtk example

example from https://developer.gnome.org/gtk3/stable/gtk-getting-started.html#id-1.2.3.5

‘‘‘c #include <gtk/gtk.h>

static void activate (GtkApplication* app, gpointer user_data) { GtkWidget *window;

window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), “Window”); gtk_window_set_default_size (GTK_WINDOW (window), 400, 400); gtk_widget_show_all (window); }

int main (int argc, char **argv) { GtkApplication *app; int status;

app = gtk_application_new (“org.gtk.example”, G_APPLICATION_FLAGS_NONE); g_signal_connect (app, “activate”, G_CALLBACK (activate), NULL); status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app);

return status; } '’’

gcc `pkg-config --cflags gtk+-3.0` -o example-0 example-0.c `pkg-config --libs gtk+-3.0` 

List c packages then can be used for including in compile line

pkg-config --list-all

List a package name to find

pkg-config --list-all | grep packagename

Go Gtk example

Example from https://github.com/gotk3/gotk3

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("Window")
		appWindow.SetDefaultSize(400, 400)
		appWindow.Show()
	})
	// Run Gtk application
	application.Run(os.Args)
}

go build

Vala Gtk example

valac --pkg gtk+-3.0 gtk-sync-sample.vala
Share