diff --git a/bitch/Makefile b/bitch/Makefile index dbc151a..e7ef1eb 100644 --- a/bitch/Makefile +++ b/bitch/Makefile @@ -1,8 +1,18 @@ -CFLAGS = -g -DGTK4=1 `pkg-config --cflags gtk4` `pkg-config --libs gtk4` +CFLAGS = -g RM = rm -f +SOURCE = bitch.c TARGETS = bitch all: $(TARGETS) +motif: $(SOURCE) + $(CC) $(CFLAGS) -o $@ \ + -DMOTIF -I/usr/pkg/include/ -I/usr/X11R7/include/ \ + -L/usr/pkg/lib/ -L/usr/X11R7/lib -lXm -lX11 \ + $(SOURCE) +gtk4: $(SOURCE) + $(CC) $(CFLAGS) -o $@ \ + -DGTK4 `pkg-config --cflags gtk4` `pkg-config --libs gtk4` \ + $(SOURCE) clean: $(RM) $(TARGETS) %: %.c diff --git a/bitch/bitch.c b/bitch/bitch.c index a136b79..adc75c2 100644 --- a/bitch/bitch.c +++ b/bitch/bitch.c @@ -1,13 +1,18 @@ #include #include /* stderr, atoi(3) */ +#include /* strchr(3) */ #include /* EX_USAGE */ #include /* getopt(3) */ -/* Written for Gtk4 */ #ifdef GTK4 # include #endif +#ifdef MOTIF +# include +# include +#endif + #define BUF 100 /* Pinephone dimensions as default */ @@ -19,6 +24,7 @@ static char buf[BUF]; static char f; static unsigned char shy = 0; +static int fake_argc = 1; static char *fake_argv[2] = { NULL, NULL }; #ifdef GTK4 @@ -28,6 +34,15 @@ static void activate(GtkApplication *app, gpointer user_data); static void button_pressed(GtkWidget *button, gpointer data); #endif +#ifdef MOTIF +static XtAppContext app_context; + +static void activate(void); +static void button_pressed( + Widget w, XtPointer client_data, XmPushButtonCallbackStruct *cbs +); +#endif + int main(int argc, char *argv[]){ int c; extern char *optarg; @@ -69,9 +84,36 @@ Usage: %s (-rx)\n\ g_object_unref(app); #endif +#ifdef MOTIF + activate(); +#endif + return status; } +char * +sip(void){ + int c; + char *s; + + if(fgets(buf, sizeof(buf) / sizeof(*buf), stdin) == NULL){ + if(ferror(stdin) != 0) +#ifdef GTK4 + g_print +#else + printf +#endif + ("%s: stdin: file read error\n", argv0); + return NULL; + } + if((s = strchr(buf, '\n')) == NULL) /* flush */ + while((c = getc(stdin)) != '\n' && c != EOF); + else + *s = '\0'; + + return buf; +} + #ifdef GTK4 static void activate(GtkApplication *app, gpointer user_data){ @@ -96,15 +138,8 @@ activate(GtkApplication *app, gpointer user_data){ gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrolledwindow), box); for(;;){ - if(fgets(buf, sizeof(buf) / sizeof(*buf), stdin) == NULL){ - if(ferror(stdin) != 0) - g_print("%s: stdin: file read error\n", argv0); + if(sip() == NULL) break; - } - 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 @@ -134,4 +169,40 @@ button_pressed(GtkWidget *button, gpointer data){ return; } +#endif /* ifdef GTK4 */ + +#ifdef MOTIF +static void +activate(void){ + Widget button; + Widget top_wid; + + top_wid = XtVaAppInitialize( + &app_context, "Bitch", NULL, 0, &fake_argc, fake_argv, NULL, + NULL + ); + + for(;;){ + if(sip() == NULL) + break; + + button = XmCreatePushButton(top_wid, buf, NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, button_pressed, NULL); + } + + XtRealizeWidget(top_wid); + XtAppMainLoop(app_context); +} + +static void +button_pressed( + Widget w, + XtPointer client_data, + XmPushButtonCallbackStruct *cbs +){ + printf("pressed\n"); + if(shy) + XtAppSetExitFlag(app_context); +} #endif