1
0

bitch(1) finished

This commit is contained in:
dtb 2022-10-01 18:49:36 -04:00
parent ba603793a2
commit 63236f9e36
2 changed files with 46 additions and 32 deletions

View File

@ -5,14 +5,6 @@ TARGETS = bitch
all: $(TARGETS)
clean:
$(RM) $(TARGETS)
naughty:
$(CC) -g `pkg-config --cflags gtk4` `pkg-config --libs gtk4` \
-D APPLICATION_NAME=\"org.trinity.bitch\" bitch.c -o bitch
nice:
$(CC) -g `pkg-config --cflags gtk4` `pkg-config --libs gtk4` \
-D APPLICATION_NAME=\"org.trinity.project\" bitch.c -o project
%: %.c
$(CC) -o $@ $(CFLAGS) $@.c

View File

@ -1,36 +1,70 @@
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h> /* Written for GTK 4 */
/* Written for Gtk4 */
#include <gtk/gtk.h>
#define BUF 100
/* Pinephone dimensions */
#define DEFAULT_H 720
#define DEFAULT_V 1440
static char *argv0;
static char buf[100];
static char buf[BUF];
static void activate(GtkApplication *app, gpointer user_data);
static void button_pressed(GtkWidget *button, gpointer data);
int main(int argc, char *argv[]){
GtkApplication *app;
int status;
argv0 = argv[0];
app = gtk_application_new(
"org.trinity.femaledog", 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;
}
static void
activate(GtkApplication *app, gpointer user_data){
GtkWidget *box;
GtkWidget *button;
int c;
char *s;
GtkWidget *window;
window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "Bitch");
gtk_window_set_default_size(GTK_WINDOW(window), 720, 1440);
g_print("bitch: stdin: reading...\n");
gtk_window_set_default_size(GTK_WINDOW(window), DEFAULT_H, DEFAULT_V);
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_halign(box, GTK_ALIGN_CENTER);
gtk_widget_set_valign(box, GTK_ALIGN_CENTER);
gtk_window_set_child(GTK_WINDOW(window), box);
for(;;){
if(fgets(buf, sizeof(buf) / sizeof(*buf), stdin) == NULL){
if(feof(stdin))
g_print("bitch: stdin: reached EOF\n", argv0);
else if(ferror(stdin) != 0)
g_print("bitch: stdin: file read error\n", argv0);
if(ferror(stdin) != 0)
g_print("%s: stdin: file read error\n", argv0);
break;
}
button = gtk_button_new_with_label(buf);
g_signal_connect(button, "clicked", G_CALLBACK(button_pressed), NULL);
gtk_window_set_child(GTK_WINDOW(window), button);
if(strchr(buf, '\n') == NULL) /* flush */
if((s = strchr(buf, '\n')) == NULL) /* flush */
while((c = getc(stdin)) != '\n' && c != EOF);
else
*s = '\0';
button = gtk_button_new_with_label(buf);
g_signal_connect(
button, "clicked", G_CALLBACK(button_pressed), NULL
);
gtk_box_append(GTK_BOX(box), button);
}
gtk_window_present(GTK_WINDOW(window));
return;
@ -44,15 +78,3 @@ button_pressed(GtkWidget *button, gpointer data){
return;
}
int main(int argc, char *argv[]){
GtkApplication *app;
int status;
argv0 = argv[0];
app = gtk_application_new("org.trinity.femaledog", 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;
}