From 79ac753b684a82d2acddb865d50d941525b5706d Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Wed, 22 Feb 2023 19:39:16 -0800 Subject: [PATCH] GTK project's Hello World --- .gitignore | 2 ++ Makefile | 18 ++++++++++++++++++ batteryviewer.c | 32 ++++++++++++++++++++++++++++++++ default.nix | 16 ++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 batteryviewer.c create mode 100644 default.nix 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 { }; +} -- 2.44.1