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) all: $(TARGETS)
clean: clean:
$(RM) $(TARGETS) $(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 %: %.c
$(CC) -o $@ $(CFLAGS) $@.c $(CC) -o $@ $(CFLAGS) $@.c

View File

@ -1,36 +1,70 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.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 *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); 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 static void
activate(GtkApplication *app, gpointer user_data){ activate(GtkApplication *app, gpointer user_data){
GtkWidget *box;
GtkWidget *button; GtkWidget *button;
int c; int c;
char *s;
GtkWidget *window; GtkWidget *window;
window = gtk_application_window_new(app); window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "Bitch"); gtk_window_set_title(GTK_WINDOW(window), "Bitch");
gtk_window_set_default_size(GTK_WINDOW(window), 720, 1440); gtk_window_set_default_size(GTK_WINDOW(window), DEFAULT_H, DEFAULT_V);
g_print("bitch: stdin: reading...\n");
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(;;){ for(;;){
if(fgets(buf, sizeof(buf) / sizeof(*buf), stdin) == NULL){ if(fgets(buf, sizeof(buf) / sizeof(*buf), stdin) == NULL){
if(feof(stdin)) if(ferror(stdin) != 0)
g_print("bitch: stdin: reached EOF\n", argv0); g_print("%s: stdin: file read error\n", argv0);
else if(ferror(stdin) != 0)
g_print("bitch: stdin: file read error\n", argv0);
break; break;
} }
button = gtk_button_new_with_label(buf); if((s = strchr(buf, '\n')) == NULL) /* flush */
g_signal_connect(button, "clicked", G_CALLBACK(button_pressed), NULL);
gtk_window_set_child(GTK_WINDOW(window), button);
if(strchr(buf, '\n') == NULL) /* flush */
while((c = getc(stdin)) != '\n' && c != EOF); 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)); gtk_window_present(GTK_WINDOW(window));
return; return;
@ -44,15 +78,3 @@ button_pressed(GtkWidget *button, gpointer data){
return; 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;
}