checkpoint
authorroot <root@Thermopile.lan>
Thu, 13 May 2010 17:59:22 +0000 (13:59 -0400)
committerroot <root@Thermopile.lan>
Thu, 13 May 2010 17:59:22 +0000 (13:59 -0400)
Makefile
main.c
obtheme.h
obtheme.l
obtheme.y
theme.obtheme

index 610580e..481d4f5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,6 @@
-CFLAGS=-g -Wall -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
+CFLAGS=-g -Wall -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include \
+       -I../openbox/openbox -I../openbox -I/usr/include/pango-1.0 \
+       -I/usr/include/freetype2
 
 .PRECIOUS: %.tab.h %.lex.c %.tab.c
 
diff --git a/main.c b/main.c
index b93ef08..0e54d18 100644 (file)
--- a/main.c
+++ b/main.c
@@ -13,13 +13,13 @@ static void decor_print(gpointer data, gpointer user_data)
                g_slist_foreach(decor->children, decor_print, NULL);
 }
 
-static void class_print(gpointer key, gpointer value, gpointer user_data)
+static void style_print(gpointer key, gpointer value, gpointer user_data)
 {
-       char *classname = key;
-       struct class *class = value;
+       char *stylename = key;
+       struct style *style = value;
 
-       printf("  Class %s\n", classname);
-       g_slist_foreach(class->tree, decor_print, NULL);
+       printf("  style %s\n", stylename);
+       g_slist_foreach(style->tree, decor_print, NULL);
 }
 
 static void theme_print(gpointer key, gpointer value, gpointer user_data)
@@ -27,7 +27,7 @@ static void theme_print(gpointer key, gpointer value, gpointer user_data)
        char *name = key;
        struct theme *thm = value;
        printf("name = %s\n", name);
-       g_hash_table_foreach(thm->classes, class_print, NULL);
+       g_hash_table_foreach(thm->styles, style_print, NULL);
 }
 
 static void material_print(gpointer key, gpointer value, gpointer user_data)
index 6c67788..d98d335 100644 (file)
--- a/obtheme.h
+++ b/obtheme.h
@@ -2,6 +2,8 @@
 #define __THEME_PARSE_H__
 
 #include <glib.h>
+#include "frame.h"
+#include "misc.h"
 
 #undef YY_DECL
 #define YY_DECL int obthemelex(YYSTYPE *yylval, struct parser_control *pc)
@@ -18,7 +20,7 @@ struct material {
        float opacity;
 };
 
-struct class {
+struct style {
        char *name;
        GSList *tree;
 };
@@ -30,7 +32,7 @@ struct obthemedata {
 
 struct theme {
        char *name;
-       GHashTable *classes;
+       GHashTable *styles;
 };
 
 struct vector {
@@ -48,6 +50,8 @@ struct decor {
        char *name;
        GSList *children;
        struct space space;
+       ObDirection cursor;
+       ObFrameContext context;
 };
 
 struct parser_control {
index c87dc4d..f5eaed7 100644 (file)
--- a/obtheme.l
+++ b/obtheme.l
@@ -4,6 +4,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
+#include "frame.h"
+#include "misc.h"
 #include "obtheme.h"
 #include "obtheme.tab.h"
 
@@ -115,12 +117,22 @@ material          return MATERIAL;
 gradient               return GRADIENT;
 context                        return CONTEXT;
 cursor                 return CURSOR;
-class                  return CLASS;
+style                  return STYLE;
 up                     return UP;
 anchor                 return ANCHOR;
 opacity                        return OPACITY;
 shapeof                        return SHAPEOF;
 texture                        return TEXTURE;
+NORTH                  return NORTH;
+NORTHEAST              return NORTHEAST;
+EAST                   return EAST;
+SOUTHEAST              return SOUTHEAST;
+SOUTH                  return SOUTH;
+SOUTHWEST              return SOUTHWEST;
+WEST                   return WEST;
+NORTHWEST              return NORTHWEST;
+NONE                   return NONE;
+UNCHANGED              return UNCHANGED;
 
 0x[0-9A-Z]+            yylval->integer = strtol(yytext, (char **)NULL, 16); return NUMBER;
 [0-9]+                 yylval->integer = atoi(yytext); return NUMBER;
index 2146130..e064e1c 100644 (file)
--- a/obtheme.y
+++ b/obtheme.y
 #include <sys/stat.h>
 #include <limits.h>
 #include <unistd.h>
+#include "frame.h"
+#include "misc.h"
 #include "obtheme.h"
 #include "obtheme.tab.h"
 
 YY_DECL;
 
+struct context_table_item {
+       char *name;
+       ObFrameContext val;
+};
+
+/* some of these contexts don't make any sense for a theme... */
+static struct context_table_item contexts[OB_FRAME_NUM_CONTEXTS] = {
+       {"none", OB_FRAME_CONTEXT_NONE},
+       {"desktop", OB_FRAME_CONTEXT_DESKTOP},
+       {"root", OB_FRAME_CONTEXT_ROOT},
+       {"client", OB_FRAME_CONTEXT_CLIENT},
+       {"titlebar", OB_FRAME_CONTEXT_TITLEBAR},
+       {"frame", OB_FRAME_CONTEXT_FRAME},
+       {"blcorner", OB_FRAME_CONTEXT_BLCORNER},
+       {"brcorner", OB_FRAME_CONTEXT_BRCORNER},
+       {"tlcorner", OB_FRAME_CONTEXT_TLCORNER},
+       {"trcorner", OB_FRAME_CONTEXT_TRCORNER},
+       {"top", OB_FRAME_CONTEXT_TOP},
+       {"bottom", OB_FRAME_CONTEXT_BOTTOM},
+       {"left", OB_FRAME_CONTEXT_LEFT},
+       {"right", OB_FRAME_CONTEXT_RIGHT},
+       {"maximize", OB_FRAME_CONTEXT_MAXIMIZE},
+       {"alldesktops", OB_FRAME_CONTEXT_ALLDESKTOPS},
+       {"shade", OB_FRAME_CONTEXT_SHADE},
+       {"iconify", OB_FRAME_CONTEXT_ICONIFY},
+       {"icon", OB_FRAME_CONTEXT_ICON},
+       {"close", OB_FRAME_CONTEXT_CLOSE},
+       {"moveresize", OB_FRAME_CONTEXT_MOVE_RESIZE}
+};
+
+static ObFrameContext context_from_string(char *str)
+{
+       int i;
+       for (i = 0; i < OB_FRAME_NUM_CONTEXTS; i++)
+               if (strcmp(contexts[i].name, str) == 1)
+                       return contexts[i].val;
+       return -1;
+}
+
 struct parser_control *parser_init(struct obthemedata *otd)
 {
        struct parser_control *out;
@@ -40,12 +81,16 @@ void parser_finish(struct parser_control *c)
        struct space space;
        struct theme theme;
        struct material material;
-       struct class class;
+       struct style style;
        GSList *list;
        GHashTable *hash;
        struct vector vector;
+       ObCursor dir;
+       ObFrameContext context;
 }
 
+%token NORTH NORTHEAST EAST SOUTHEAST SOUTH SOUTHWEST
+%token WEST NORTHWEST NONE UNCHANGED
 %token LCB RCB LB RB
 %token LEFT_ARROW RIGHT_ARROW DOUBLE_ARROW
 %token SEMICOLON AT COLON DEFAULT NOT
@@ -53,17 +98,19 @@ void parser_finish(struct parser_control *c)
 %token <string> STRING ID
 %token <integer> NUMBER SUBST BULK BIG LITTLE
 %token THEME FRAME SPACE GEOMETRY MATERIAL GRADIENT
-%token CONTEXT CURSOR UP ANCHOR CLASS TEXTURE OPACITY
+%token CONTEXT CURSOR UP ANCHOR STYLE TEXTURE OPACITY
 %token SHAPEOF DECOR
 %type <decor> decor
-%type <decor> decoritems classitem
+%type <decor> decoritems styleitem
 %type <space> space
-%type <class> class classitems
-%type <hash> classes
+%type <style> style styleitems
+%type <hash> styles
 %type <material> material_props
 %type <realnum> opacity
 %type <space> spaceconstraints
 %type <vector> up anchor
+%type <dir> cursor
+%type <context> context
 %%
 
 theme_object   : material_decl
@@ -74,11 +121,11 @@ theme_objects      : /* empty */
                | theme_objects theme_object
                ;
 
-theme          : THEME ID LCB classes RCB {
+theme          : THEME ID LCB styles RCB {
                        struct theme *out;
                        out = malloc(sizeof(struct theme));
                        out->name = $2;
-                       out->classes = $4;
+                       out->styles = $4;
                        g_hash_table_insert(pc->target->themes, $2, out);
                }
                ;
@@ -135,14 +182,20 @@ geometry_item     : /* empty */
 geometry       : GEOMETRY LCB geometry_item RCB
                ;
 
-material_use   : MATERIAL LB ID RB
+material_use   : MATERIAL LB ID RB {
+                       if (g_hash_table_lookup(pc->target->materials, $3) == NULL) {
+                               snprintf(pc->error_buf, 4000, "No definition for material '%s'\n", $3);
+                               obthemeerror(pc, pc->error_buf);
+                               return 1;
+                       }
+               }
                ;
 
-classitem      : decor
+styleitem      : decor
                ;
 
-classitems     : /* empty */ { $$.tree = NULL; $$.name = NULL; }
-               | classitems classitem {
+styleitems     : /* empty */ { $$.tree = NULL; $$.name = NULL; }
+               | styleitems styleitem {
                        struct decor *out = malloc(sizeof(struct decor));
                        *out = $2;
                        $1.tree = g_slist_prepend($1.tree, out);
@@ -150,16 +203,16 @@ classitems        : /* empty */ { $$.tree = NULL; $$.name = NULL; }
                }
                ;
 
-classes                : /* empty */ { $$ = g_hash_table_new(g_str_hash, g_str_equal); }
-               | classes class {
-                       struct class *out = malloc(sizeof(struct class));
+styles         : /* empty */ { $$ = g_hash_table_new(g_str_hash, g_str_equal); }
+               | styles style {
+                       struct style *out = malloc(sizeof(struct style));
                        *out = $2;
                        $$ = $1;
                        g_hash_table_insert($1, out->name, out);
                }
                ;
 
-class          : CLASS ID LCB classitems RCB {
+style          : STYLE ID LCB styleitems RCB {
                        $$ = $4;
                        $$.name = $2;
                }
@@ -168,6 +221,7 @@ class               : CLASS ID LCB classitems RCB {
 decoritems     : /* empty */ {
                        memset(&$$, 0, sizeof($$));
                        $$.space.up.y = -1;
+                       $$.cursor = OB_CURSOR_NONE;
                }
                | decoritems decor {
                        struct decor *out = malloc(sizeof(struct decor));
@@ -179,9 +233,9 @@ decoritems  : /* empty */ {
                | decoritems material_use
                | decoritems geometry
                | decoritems texture
-               | decoritems context
+               | decoritems context { $1.context = $2; }
                | decoritems gradient
-               | decoritems cursor
+               | decoritems cursor { $1.cursor = $2; }
                ;
 
                ;
@@ -195,11 +249,28 @@ decor             : DECOR ID LCB decoritems RCB {
 texture                : TEXTURE LCB RCB
                ;
 
-context                : CONTEXT LB ID RB
+context                : CONTEXT LB ID RB {
+                       ObFrameContext frc;
+                       frc = context_from_string($3);
+                       if (frc == -1) {
+                               snprintf(pc->error_buf, 4000, "Illegal context '%s'\n", $3);
+                               obthemeerror(pc, pc->error_buf);
+                               return 1;
+                       }
+               }
                ;
 
-cursor         : CURSOR LB ID RB
-
+cursor         : CURSOR LB NORTH RB { $$ = OB_CURSOR_NORTH; }
+               | CURSOR LB NORTHEAST RB { $$ = OB_CURSOR_NORTHEAST; }
+               | CURSOR LB EAST RB { $$ = OB_CURSOR_EAST; }
+               | CURSOR LB SOUTHEAST RB { $$ = OB_CURSOR_SOUTHEAST; }
+               | CURSOR LB SOUTH RB { $$ = OB_CURSOR_SOUTH; }
+               | CURSOR LB SOUTHWEST RB { $$ = OB_CURSOR_SOUTHWEST; }
+               | CURSOR LB WEST RB { $$ = OB_CURSOR_WEST; }
+               | CURSOR LB NORTHWEST RB { $$ = OB_CURSOR_NORTHWEST; }
+//             | CURSOR LB NONE RB { $$ = OB_CURSOR_NORTHEAST; }
+               | CURSOR LB UNCHANGED RB { $$ = OB_CURSOR_NONE; }
+               ;
 gradient       : GRADIENT LB ID RB
                ;
 
index 8d574fa..c02e21a 100644 (file)
@@ -1,11 +1,16 @@
 //#include materials.obtheme
 
+//version(1)
+
 material flat {
        opacity(1)
 }
 
+material none {
+}
+
 theme awesome {
-       class regular_window {
+       style regular_window {
                decor clientwindow {
                        space {
                                anchor(10 9 8)
@@ -19,7 +24,7 @@ theme awesome {
                        }
 
                        decor titlebar {
-                               context(OB_FRAME_CONTEXT_TITLEBAR)
+                               context(titlebar)
                                geometry {
                                //      box (0, 0, 0) to (100% of $CLIENT, 100%, 0)
                                }
@@ -34,11 +39,11 @@ theme awesome {
                                }
                                decor minbutton {
                                        material(none)
-                                       context(OB_FRAME_CONTEXT_MINIMIZE)
+                                       context(minimize)
                                }
                                decor maxbutton {
                                        material(none)
-                                       context(OB_FRAME_CONTEXT_MAXIMIZE)
+                                       context(maximize)
                                }
                        }
                        decor handle {
@@ -47,14 +52,14 @@ theme awesome {
                                        up(0 0 0)
                                }
                                decor leftgrip {
-                                       context(OB_FRAME_CONTEXT_BLCORNER)
+                                       context(blcorner)
                                        cursor(SOUTHWEST)
                                }
                                decor rightgrip {
-                                       context(OB_FRAME_CONTEXT_BRCORNER)
+                                       context(brcorner)
                                        cursor(SOUTHEAST)
                                }
-                               context(OB_FRAME_CONTEXT_BOTTOM)
+                               context(bottom)
                                cursor(SOUTH)
                        }
                }