From: Scott Worley Date: Thu, 23 Feb 2023 03:39:16 +0000 (-0800) Subject: GTK project's Hello World X-Git-Url: http://git.scottworley.com/batteryviewer/commitdiff_plain/79ac753b684a82d2acddb865d50d941525b5706d?ds=sidebyside GTK project's Hello World --- 79ac753b684a82d2acddb865d50d941525b5706d diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b83fcf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +batteryviewer +result diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..20e658b --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +prefix = /usr/local +exec_prefix = $(prefix) +bindir = $(exec_prefix)/bin +INSTALL = install -D +INSTALL_PROGRAM = $(INSTALL) + +batteryviewer: batteryviewer.c + gcc $(shell pkg-config --cflags gtk4) -o $@ $< $(shell pkg-config --libs gtk4) + +all: batteryviewer + +install: + $(INSTALL_PROGRAM) batteryviewer $(bindir)/batteryviewer + +clean: + rm batteryviewer + +.PHONY: all clean install diff --git a/batteryviewer.c b/batteryviewer.c new file mode 100644 index 0000000..4a1a850 --- /dev/null +++ b/batteryviewer.c @@ -0,0 +1,32 @@ +#include + +static void print_hello(GtkWidget *widget, gpointer data) { + g_print("Hello World\n"); +} + +static void activate(GtkApplication *app, gpointer user_data) { + GtkWidget *window; + GtkWidget *button; + + window = gtk_application_window_new(app); + gtk_window_set_title(GTK_WINDOW(window), "Window"); + gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); + + button = gtk_button_new_with_label("Hello World"); + g_signal_connect(button, "clicked", G_CALLBACK(print_hello), NULL); + gtk_window_set_child(GTK_WINDOW(window), button); + + gtk_window_present(GTK_WINDOW(window)); +} + +int main(int argc, char **argv) { + GtkApplication *app; + int status; + + app = gtk_application_new("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); + status = g_application_run(G_APPLICATION(app), argc, argv); + g_object_unref(app); + + return status; +} diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..577f8f3 --- /dev/null +++ b/default.nix @@ -0,0 +1,16 @@ +let + batteryviewer = { lib, stdenv, gtk4, pkg-config, }: + stdenv.mkDerivation { + pname = "batteryviewer"; + version = "0.1"; + + src = lib.cleanSource ./.; + + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ gtk4 ]; + + makeFlags = [ "prefix=$(out)" ]; + }; +in { pkgs ? import { }, }: { + batteryviewer = pkgs.callPackage batteryviewer { }; +}