]> git.scottworley.com Git - batteryviewer/commitdiff
GTK project's Hello World
authorScott Worley <scottworley@scottworley.com>
Thu, 23 Feb 2023 03:39:16 +0000 (19:39 -0800)
committerScott Worley <scottworley@scottworley.com>
Thu, 23 Feb 2023 03:39:16 +0000 (19:39 -0800)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
batteryviewer.c [new file with mode: 0644]
default.nix [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..3b83fcf
--- /dev/null
@@ -0,0 +1,2 @@
+batteryviewer
+result
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
index 0000000..4a1a850
--- /dev/null
@@ -0,0 +1,32 @@
+#include <gtk/gtk.h>
+
+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 (file)
index 0000000..577f8f3
--- /dev/null
@@ -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 <nixpkgs> { }, }: {
+  batteryviewer = pkgs.callPackage batteryviewer { };
+}