antiright-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Antiright-devel] antiright/xshell Makefile button.c button.h wid...


From: Jeffrey Bedard
Subject: [Antiright-devel] antiright/xshell Makefile button.c button.h wid...
Date: Mon, 23 Jul 2007 01:58:46 +0000

CVSROOT:        /sources/antiright
Module name:    antiright
Changes by:     Jeffrey Bedard <jefbed> 07/07/23 01:58:46

Modified files:
        xshell         : Makefile button.c button.h widget.c widget.h 
                         xshell.c xshell.h 

Log message:
        Sync, again.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/Makefile?cvsroot=antiright&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/button.c?cvsroot=antiright&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/button.h?cvsroot=antiright&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/widget.c?cvsroot=antiright&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/widget.h?cvsroot=antiright&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/xshell.c?cvsroot=antiright&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/xshell.h?cvsroot=antiright&r1=1.1&r2=1.2

Patches:
Index: Makefile
===================================================================
RCS file: /sources/antiright/antiright/xshell/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Makefile    10 Jun 2007 20:54:01 -0000      1.1
+++ Makefile    23 Jul 2007 01:58:46 -0000      1.2
@@ -23,18 +23,23 @@
 #
 ###############################################################################
 
-
 include ../config.mk
 
-PREFIX=/usr/local
-CC=gcc
+# The variables here tend to override the included values,
+# as they are GTK-specific.  
+
 INCLUDES=-I/usr/X11R6/include -I/usr/pkg/include
-CFLAGS+=$(INCLUDES) 
+CFLAGS=$(INCLUDES) 
+CFLAGS+=-Os
+CFLAGS+=-DXSH_DECORATE
+CFLAGS+=-DXSH_USE_GRADIENT
 #CFLAGS+=-DDEBUG -g3 -Wall -W
+#CFLAGS+=-DDEBUG_EVENTS
 LIBS=-L/usr/X11R6/lib -L/usr/pkg/lib -lX11
-LDFLAGS+=$(LIBS)
+LDFLAGS=$(LIBS)
 
-OBJECTS=xshell.o widget.o button.o 
+OBJECTS=xshell.o widget.o button.o arguments.o shell.o events.o decoration.o\
+       text.o layout.o
 
 all: xshell
 
@@ -42,7 +47,7 @@
        $(CC) -o xshell $(OBJECTS) $(LDFLAGS)
 
 clean:
-       rm -f *.o xshell
+       rm -f *.o xshell xshell.exe*
 
 install:
        cp xshell $(PREFIX)/bin

Index: button.c
===================================================================
RCS file: /sources/antiright/antiright/xshell/button.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- button.c    10 Jun 2007 20:54:01 -0000      1.1
+++ button.c    23 Jul 2007 01:58:46 -0000      1.2
@@ -23,28 +23,25 @@
 #include "xshell.h"
 
 static void
-draw_label(XWidget * button)
+draw_label(XShell * xsh, XWidget * button)
 {
-       XShell * xsh;
        XSHButtonData * data;
        char * label;
 
-       xsh=(XShell *)button->xsh;
        data=(XSHButtonData *)button->data;
        label=data->label;
-#ifdef DEBUG
-       assert(label);
-       assert(xsh->gui.display);
-       puts(label);
-#endif /* DEBUG */
+
        XDrawString(xsh->gui.display, button->window, xsh->gui.gc,
-               3, 12, label, strlen(label));
+               5, 12, label, strlen(label));
 }
 
 static void
 expose(XWidget * button)
 {
-       draw_label(button);
+#ifdef XSH_DECORATE
+       xsh_decorate(button, XSH_DECOR_OUT);
+#endif /* XSH_DECORATE */
+       draw_label((XShell *)(button->xsh), button);
 }
 
 static void
@@ -54,13 +51,17 @@
 
        XMSG("PRESSED");
        data=(XSHButtonData *)button->data;
+#ifdef XSH_DECORATE
+       xsh_decorate(button, XSH_DECOR_IN);
+#endif /* XSH_DECORATE */
+       draw_label((XShell *)(button->xsh), button);
        system(data->command);
 }
 
 static void
-key_press(XWidget * button)
+button_release(XWidget * button)
 {
-       button_press(button);
+       expose(button);
 }
 
 static void
@@ -69,37 +70,38 @@
        expose(button);
 }
 
-static void
-setup_events(XWidget * button)
-{
-       button->events.expose=&expose;
-       button->events.configure=&configure;
-       button->events.key_press=&key_press;
-       button->events.button_press=&button_press;
-}
+#define SETUP_BUTTON_EVENTS(button)\
+       button->events.expose=&expose;\
+       button->events.configure=&configure;\
+       button->events.key_press=NULL;\
+       button->events.button_press=&button_press;\
+       button->events.button_release=&button_release;
+
+#define XSH_G xsh->gui
+#define XSH_G_L XSH_G.layout
 
 void
-xshell_button_new(XShell * xsh, XWidget * parent, int x, int y,
-       const char * command)
+xshell_button_new(XShell * xsh, XWidget * parent, const char * command)
 {
        XWidget * button;
        XSHButtonData * data;
        char * label;
 
-       xshell_XWidget_new(xsh, parent, x, y, 100, 16);
-       button=xsh->gui.last_widget;
-       data=malloc(sizeof(XSHButtonData));
+       xshell_XWidget_new(xsh, parent, 
+               XSH_WIDGET_WIDTH*(XSH_G_L.column_count), 
+               XSH_WIDGET_HEIGHT*
+               ((XSH_G_L.row_count = 
+               XSH_G_L.row_count < XSH_G_L.max_row_count
+               ? XSH_G_L.row_count+1:0)-1), 
+               XSH_WIDGET_WIDTH, XSH_WIDGET_HEIGHT);
+       if(XSH_G_L.row_count==0)
+               XSH_G_L.column_count++;
+
+       button=XSH_G.last_widget;
+       button->data=data=malloc(sizeof(XSHButtonData));
        data->command=(char *)command;
-       label=strchr(command, '#');
-       if(label)
-       {
-               data->label=label+1;
-       }
-       else
-       {
-               data->label=(char *)command;
-       }
-       button->data=data;
-       setup_events(button);
+       data->label=(label=strchr(command, '#'))?label+1:(char*)command;
+       SETUP_BUTTON_EVENTS(button);
 }
 
+

Index: button.h
===================================================================
RCS file: /sources/antiright/antiright/xshell/button.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- button.h    10 Jun 2007 20:54:01 -0000      1.1
+++ button.h    23 Jul 2007 01:58:46 -0000      1.2
@@ -33,8 +33,9 @@
 typedef struct XSHButtonData XSHButtonData;
 
 void
-xshell_button_new(XShell * xsh, XWidget * parent, int x, int y,
+xshell_button_new(XShell * xsh, XWidget * parent,
        const char * command);
 
 #endif /* XSH_BUTTON_H */
 
+

Index: widget.c
===================================================================
RCS file: /sources/antiright/antiright/xshell/widget.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- widget.c    10 Jun 2007 20:54:01 -0000      1.1
+++ widget.c    23 Jul 2007 01:58:46 -0000      1.2
@@ -23,108 +23,47 @@
 
 #include "xshell.h"
 
-static XWidget *
-find_last_widget(XWidget * first)
+XShell *
+xsh_get_XShell_for_widget(XWidget * widget)
 {
-       XWidget * iter;
-
-       for(iter=first; iter->next; iter=iter->next);
-
-       return iter;
+       return (XShell *)(widget->xsh);
 }
 
-static void
-select_event(XWidget * iter, unsigned int event_type)
+Display *
+xsh_get_display_for_widget(XWidget * widget)
 {
-       switch(event_type)
-       {
-       case XSH_EXPOSE_EVENT:
-               XMSG("expose");
-               if(iter->events.expose)
-                       (iter->events.expose)(iter);
-               XMSG("expose done");
-               break;
-       case XSH_KEY_PRESS_EVENT:
-               XMSG("key press");
-               if(iter->events.key_press)
-                       (iter->events.key_press)(iter);
-               break;
-       case XSH_BUTTON_PRESS_EVENT:
-               XMSG("button press");
-               if(iter->events.button_press)
-                       (iter->events.button_press)(iter);
-               break;
-       case XSH_CONFIGURE_EVENT:
-               XMSG("configure");
-               if(iter->events.configure)
-                       (iter->events.configure)(iter);
-               break;
-       };
+       XShell * xsh;
 
-}
+       xsh=xsh_get_XShell_for_widget(widget);
 
-void
-xshell_foreach_XWidget(XWidget * head, unsigned int event_type, Window w)
-{
-       XWidget * iter;
-
-       XMSG("xshell_foreach_XWidget()");
-       iter=head;
-       while(iter)
-       {
-               XMSG("event received");
-#ifdef DEBUG
-               assert(iter);
-#endif /* DEBUG */
-               if(w!=iter->window)
-               {
-                       iter=iter->next;
-                       continue;
-               }
-               select_event(iter, event_type);
-               iter=iter->next;
-       }
-       XMSG("end xshell_foreach_XWidget()");
+       return xsh->gui.display;
 }
 
-static void
-nullify_widget_events(XWidget * widget)
-{
-       widget->events.expose=NULL;
-       widget->events.key_press=NULL;
-       widget->events.button_press=NULL;
-       widget->events.configure=NULL;
-}
+#define NULLIFY_WIDGET_MEMBERS(widget)\
+       widget->data=NULL;\
+       widget->next=NULL;\
+       xsh_nullify_widget_events(widget);\
 
-static void
-nullify_widget_members(XWidget * widget)
-{
-       widget->data=NULL;
-       nullify_widget_events(widget);
-}
 
-static void
-setup_widget_geometry(XWidget * widget, int width, int height, int x, int y)
-{
-       widget->geometry.x=x;
-       widget->geometry.y=y;
-       widget->geometry.width=width;
+#define SETUP_WIDGET_GEOMETRY(widget, width, height, x, y)\
+       widget->geometry.x=x;\
+       widget->geometry.y=y;\
+       widget->geometry.width=width;\
        widget->geometry.height=height;
-}
 
 static void
 initialize_widget_members(XWidget * widget, 
        int x, int y, int width, int height)
 {
-       nullify_widget_members(widget);
-       setup_widget_geometry(widget, width, height, x, y);
+       NULLIFY_WIDGET_MEMBERS(widget);
+       SETUP_WIDGET_GEOMETRY(widget, width, height, x, y);
 }
 
 static void
 setup_widget_window(XShell * xsh, XWidget * widget, XWidget * parent)
 {
        Display * dpy;
-       XSHGeometry * geometry;
+       XWindowAttributes * geometry;
                
        XMSG("create widget window");
        dpy=xsh->gui.display;
@@ -132,12 +71,31 @@
        widget->window=XCreateSimpleWindow(dpy, 
                parent ? parent->window : DefaultRootWindow(dpy), 
                geometry->x, geometry->y, 
-               geometry->width, geometry->height, 1,
-               xsh->gui.colors.white, xsh->gui.colors.black);
-       XSelectInput(dpy, widget->window, ButtonPressMask 
-               | ExposureMask | KeyPressMask | PropertyChangeMask);
-       XMSG("show widget window");
-       XMapWindow(dpy, widget->window);
+               geometry->width, geometry->height, 
+#ifdef DEBUG
+               1,
+#else /* not DEBUG */
+#ifdef XSH_DECORATE
+               0,
+#else /* not XSH_DECORATE */
+               1,
+#endif /* XSH_DECORATE */
+#endif /* DEBUG */
+#ifdef XSH_DECORATE
+               BlackPixel(dpy, DefaultScreen(dpy)),
+#else /* not XSH_DECORATE */
+               WhitePixel(dpy, DefaultScreen(dpy)),
+#endif /* XSH_DECORATE */
+               BlackPixel(dpy, DefaultScreen(dpy)));
+       {
+               long event_mask;
+
+               event_mask = ButtonPressMask | ButtonReleaseMask
+                       | ExposureMask | KeyPressMask;
+               if(widget->window == xsh->gui.widgets->window)
+                       event_mask |= StructureNotifyMask; 
+               XSelectInput(dpy, widget->window, event_mask);
+       }
 }
 
 void
@@ -146,23 +104,16 @@
 {
        XWidget * widget;
 
-       XMSG("xshell_XWidget_new()");
        widget=malloc(sizeof(XWidget));
        if(xsh->gui.widgets)
-       {
-               XMSG("xsh->gui.widgets");
-               XWidget * last;
-               
-               last=find_last_widget(xsh->gui.widgets);
-               last->next=widget;
-       }
+               xsh->gui.last_widget->next=widget;
        else
-       {
-               XMSG("!xsh->gui.widgets");
                xsh->gui.widgets=widget;
-       }
        initialize_widget_members(widget, x, y, width, height);
        widget->xsh=(void *)xsh;
        setup_widget_window(xsh, widget, parent);
        xsh->gui.last_widget=widget;
+       xsh->gui.widget_count++;
 }
+
+

Index: widget.h
===================================================================
RCS file: /sources/antiright/antiright/xshell/widget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- widget.h    10 Jun 2007 20:54:01 -0000      1.1
+++ widget.h    23 Jul 2007 01:58:46 -0000      1.2
@@ -28,8 +28,12 @@
 xshell_XWidget_new(XShell * xsh, XWidget * parent, 
        int x, int y, int width, int height);
 
-void
-xshell_foreach_XWidget(XWidget * head, unsigned int type, Window w);
+XShell *
+xsh_get_XShell_for_widget(XWidget * widget);
+
+Display *
+xsh_get_display_for_widget(XWidget * widget);
 
 #endif /* XSH_WIDGET_H */
 
+

Index: xshell.c
===================================================================
RCS file: /sources/antiright/antiright/xshell/xshell.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- xshell.c    10 Jun 2007 20:54:01 -0000      1.1
+++ xshell.c    23 Jul 2007 01:58:46 -0000      1.2
@@ -23,56 +23,19 @@
 
 #include "xshell.h"
 
-static void
-setup_colors(XShell * xsh)
-{
-       Display * dpy;
-       int screen;
-
-       dpy=xsh->gui.display;
-       screen=DefaultScreen(dpy);
-       xsh->gui.colors.black=BlackPixel(dpy, screen);
-       xsh->gui.colors.white=WhitePixel(dpy, screen);
-}
-
-static void
-event_loop(XShell * xsh)
-{
-       XEvent event;
-       Display *dpy;
-
-       for(dpy=xsh->gui.display;;XNextEvent(dpy, &event))      
-       {
-               switch(event.type)
-               {
-               case Expose:
-                       xshell_foreach_XWidget(xsh->gui.widgets, 
-                               XSH_EXPOSE_EVENT, event.xexpose.window);
-                       break;
-               case ConfigureRequest:
-                       xshell_foreach_XWidget(xsh->gui.widgets,
-                               XSH_CONFIGURE_EVENT, 
-                               event.xconfigurerequest.window);
-                       break;
-               case KeyPress:
-                       xshell_foreach_XWidget(xsh->gui.widgets,
-                               XSH_KEY_PRESS_EVENT,    
-                               event.xkey.window);
-                       break;
-               case ButtonPress:
-                       xshell_foreach_XWidget(xsh->gui.widgets,
-                               XSH_BUTTON_PRESS_EVENT, 
-                               event.xbutton.window);
-                       break;
-               }
-       }
-}
-
-static void
-setup_XShell(XShell * xsh)
-{
-       xsh->gui.widgets=NULL;
-}
+#define SETUP_XSHELL_GUI_LAYOUT(layout)\
+       layout.row_count=0;\
+       layout.column_count=0;\
+       layout.max_row_count=XSH_ROWS_PER_COLUMN;
+
+#define SETUP_XSHELL_GUI(gui)\
+       gui.widgets=NULL;\
+       gui.widget_count=0;\
+       SETUP_XSHELL_GUI_LAYOUT(gui.layout);
+
+#define SETUP_XSHELL(xsh)\
+       xsh.options=0;\
+       SETUP_XSHELL_GUI(xsh.gui);
 
 static void
 delete_widgets(XWidget * head)
@@ -108,32 +71,25 @@
        Display * dpy;
 
        dpy=xsh->gui.display;
-       values.foreground=xsh->gui.colors.white;
+       values.foreground=
+#ifndef XSH_DECORATE
+               WhitePixel(dpy, DefaultScreen(dpy));
+#else /* XSH_DECORATE */
+               BlackPixel(dpy, DefaultScreen(dpy));
+#endif /* not XSH_DECORATE */
        xsh->gui.gc=XCreateGC(dpy, xsh->gui.widgets->window, 
                GCForeground, &values);
 }
 
-static void
-setup_close_button(XShell * xsh)
-{
-       xshell_button_new(xsh, xsh->gui.widgets, 84, 0, "Exit___ #X");
-       xsh->gui.last_widget->events.button_press=(void (*)(XWidget *))exit;
-       xsh->gui.last_widget->events.key_press=NULL;
-}
 
 static void
-setup_title(XShell * xsh , const char * title)
+show_main_window(Display * dpy, XShell * xsh)
 {
-       xshell_button_new(xsh, xsh->gui.widgets, 0, 0, title);
-       xsh->gui.last_widget->events.button_press=NULL;
-       xsh->gui.last_widget->events.key_press=NULL;
-}
+       Window toplevel;
 
-static void
-setup_titlebar(XShell * xsh, const char * title)
-{
-       setup_title(xsh, title);
-       setup_close_button(xsh);
+       toplevel=xsh->gui.widgets->window;
+       XMapSubwindows(dpy, toplevel);
+       XMapWindow(dpy, toplevel);
 }
 
 int
@@ -141,29 +97,33 @@
 {
        XShell xsh;
        Display * dpy;
-       unsigned int counter;
-
-       setup_XShell(&xsh);
+       if(argc<=1)
+       {
+               /* This should be split to function and kept with argument
+                  handler code.  */
+               fprintf(stderr, "Usage: xshell [-[a[]o[[r rows]n[g X+Y]]]"
+                       " BUTTON] ...\n");
+               exit(1);
+       }
+       SETUP_XSHELL(xsh);
        dpy=xsh.gui.display=XOpenDisplay(NULL);
-       setup_colors(&xsh);
+       /* Main window.  */
        xshell_XWidget_new(&xsh, NULL, 0, 0, 100, 16);
        setup_gc(&xsh);
-       for(counter=1; counter<(unsigned int)argc; counter++)
-       {
-               puts(argv[counter]);
-               xshell_button_new(&xsh, xsh.gui.widgets, 
-                       /*(100*(((counter-1)*16)%300)), ((counter-1)*16), */
-                       /*((counter*16)%xsh.gui.widgets->geometry.height)*100,*/
-                       0,
-                       counter*16,
-                       argv[counter]);
-       }
-       XResizeWindow(xsh.gui.display, xsh.gui.widgets->window, 100,
-               counter*16);
-       setup_titlebar(&xsh, argv[0]);
-       event_loop(&xsh);
+#ifdef XSH_USE_GRADIENT
+       xsh_setup_gradients(&xsh);
+#endif /* XSH_USE_GRADIENT */
+       xsh_parse_arguments(&xsh, argc, argv);
+       show_main_window(dpy, &xsh);
+       xsh_layout_widgets(&xsh);
+       XMoveWindow(dpy,
+               xsh.gui.widgets->window,
+               xsh.gui.widgets->geometry.x, 
+               xsh.gui.widgets->geometry.y);
+       xsh_event_loop(&xsh);
        cleanup(&xsh);
 
        return 0; 
 }
 
+

Index: xshell.h
===================================================================
RCS file: /sources/antiright/antiright/xshell/xshell.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- xshell.h    10 Jun 2007 20:54:01 -0000      1.1
+++ xshell.h    23 Jul 2007 01:58:46 -0000      1.2
@@ -36,59 +36,67 @@
 #define XMSG(msg) /* unused */
 #endif /* DEBUG */
 
-#define XSH_EXPOSE_EVENT 1
-#define XSH_KEY_PRESS_EVENT 2
-#define XSH_BUTTON_PRESS_EVENT 3
-#define XSH_CONFIGURE_EVENT 4
-
-struct XSHGeometry
-{
-       int x;
-       int y;
-       unsigned int width;
-       unsigned int height;
-};
-
-typedef struct XSHGeometry XSHGeometry;
-
 struct XWidget
 {
        Window window;
-       XSHGeometry geometry;
+       XWindowAttributes geometry;
        struct
        {
                void (*expose)(struct XWidget *);
                void (*button_press)(struct XWidget *);
+               void (*button_release)(struct XWidget *);
                void (*key_press)(struct XWidget *);
                void (*configure)(struct XWidget *);
        } events;
        void * data;
        void * xsh; /* Ensure root access.  */
        struct XWidget *next;
+       XEvent * event;
 };
 
 typedef struct XWidget XWidget;
 
+typedef unsigned int XSHBitmask;
+
+#define XSH_OVERRIDE_REDIRECT 1
+
 struct XShell
 {
        struct {
                Display * display;
                XWidget * widgets;
                XWidget * last_widget;
+               unsigned int widget_count;
                GC gc;
 
+#ifdef XSH_USE_GRADIENT
+               struct
+               {
+                       Pixmap outset;
+                       Pixmap inset;
+               } pixbufs;
+#endif /* XSH_USE_GRADIENT */
                struct
                {
-                       unsigned long black;
-                       unsigned long white;
-               } colors;
+                       unsigned int row_count;
+                       unsigned int max_row_count;
+                       unsigned int column_count;
+               } layout;
        } gui;
+
+       XSHBitmask options;
 };
 
 typedef struct XShell XShell;
 
 #include "widget.h"
 #include "button.h"
+#include "text.h"
+#include "arguments.h"
+#include "events.h"
+#include "decoration.h"
+#include "layout.h"
 
 #endif /* XSHELL_H */
 
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]