now works with motif, sort of
This commit is contained in:
parent
2de50f184b
commit
e1805936ef
|
@ -1,8 +1,18 @@
|
||||||
CFLAGS = -g -DGTK4=1 `pkg-config --cflags gtk4` `pkg-config --libs gtk4`
|
CFLAGS = -g
|
||||||
RM = rm -f
|
RM = rm -f
|
||||||
|
SOURCE = bitch.c
|
||||||
TARGETS = bitch
|
TARGETS = bitch
|
||||||
|
|
||||||
all: $(TARGETS)
|
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:
|
clean:
|
||||||
$(RM) $(TARGETS)
|
$(RM) $(TARGETS)
|
||||||
%: %.c
|
%: %.c
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h> /* stderr, atoi(3) */
|
#include <stdlib.h> /* stderr, atoi(3) */
|
||||||
|
#include <string.h> /* strchr(3) */
|
||||||
#include <sysexits.h> /* EX_USAGE */
|
#include <sysexits.h> /* EX_USAGE */
|
||||||
#include <unistd.h> /* getopt(3) */
|
#include <unistd.h> /* getopt(3) */
|
||||||
|
|
||||||
/* Written for Gtk4 */
|
|
||||||
#ifdef GTK4
|
#ifdef GTK4
|
||||||
# include <gtk/gtk.h>
|
# include <gtk/gtk.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MOTIF
|
||||||
|
# include <Xm/Xm.h>
|
||||||
|
# include <Xm/PushB.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define BUF 100
|
#define BUF 100
|
||||||
|
|
||||||
/* Pinephone dimensions as default */
|
/* Pinephone dimensions as default */
|
||||||
|
@ -19,6 +24,7 @@ static char buf[BUF];
|
||||||
static char f;
|
static char f;
|
||||||
static unsigned char shy = 0;
|
static unsigned char shy = 0;
|
||||||
|
|
||||||
|
static int fake_argc = 1;
|
||||||
static char *fake_argv[2] = { NULL, NULL };
|
static char *fake_argv[2] = { NULL, NULL };
|
||||||
|
|
||||||
#ifdef GTK4
|
#ifdef GTK4
|
||||||
|
@ -28,6 +34,15 @@ static void activate(GtkApplication *app, gpointer user_data);
|
||||||
static void button_pressed(GtkWidget *button, gpointer data);
|
static void button_pressed(GtkWidget *button, gpointer data);
|
||||||
#endif
|
#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 main(int argc, char *argv[]){
|
||||||
int c;
|
int c;
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
|
@ -69,9 +84,36 @@ Usage: %s (-rx)\n\
|
||||||
g_object_unref(app);
|
g_object_unref(app);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MOTIF
|
||||||
|
activate();
|
||||||
|
#endif
|
||||||
|
|
||||||
return status;
|
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
|
#ifdef GTK4
|
||||||
static void
|
static void
|
||||||
activate(GtkApplication *app, gpointer user_data){
|
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);
|
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrolledwindow), box);
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
if(fgets(buf, sizeof(buf) / sizeof(*buf), stdin) == NULL){
|
if(sip() == NULL)
|
||||||
if(ferror(stdin) != 0)
|
|
||||||
g_print("%s: stdin: file read error\n", argv0);
|
|
||||||
break;
|
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);
|
button = gtk_button_new_with_label(buf);
|
||||||
g_signal_connect(
|
g_signal_connect(
|
||||||
button, "clicked", G_CALLBACK(button_pressed), NULL
|
button, "clicked", G_CALLBACK(button_pressed), NULL
|
||||||
|
@ -134,4 +169,40 @@ button_pressed(GtkWidget *button, gpointer data){
|
||||||
return;
|
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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user