Define the shell resize enumeration in the xml spec
authorKristian Høgsberg <krh@bitplanet.net>
Sat, 22 Jan 2011 02:57:55 +0000 (21:57 -0500)
committerKristian Høgsberg <krh@bitplanet.net>
Sat, 22 Jan 2011 02:57:55 +0000 (21:57 -0500)
compositor/compositor.c
compositor/shell.c
protocol/wayland.xml
wayland/scanner.c
wayland/wayland-util.h

index 5199b9e..27dd50d 100644 (file)
@@ -723,7 +723,7 @@ notify_button(struct wl_input_device *device,
                shell_resize(NULL,
                             (struct wl_shell *) &compositor->shell,
                             &surface->surface, device, time,
-                            WL_GRAB_RESIZE_BOTTOM_RIGHT);
+                            WL_SHELL_RESIZE_BOTTOM_RIGHT);
 
        if (device->grab)
                device->grab->interface->button(device->grab, time,
index 4a9c936..2699b22 100644 (file)
@@ -117,17 +117,17 @@ resize_grab_motion(struct wl_grab *grab,
        struct wl_surface *surface = &resize->surface->surface;
        int32_t width, height;
 
-       if (resize->edges & WL_GRAB_RESIZE_LEFT) {
+       if (resize->edges & WL_SHELL_RESIZE_LEFT) {
                width = device->grab_x - x + resize->width;
-       } else if (resize->edges & WL_GRAB_RESIZE_RIGHT) {
+       } else if (resize->edges & WL_SHELL_RESIZE_RIGHT) {
                width = x - device->grab_x + resize->width;
        } else {
                width = resize->width;
        }
 
-       if (resize->edges & WL_GRAB_RESIZE_TOP) {
+       if (resize->edges & WL_SHELL_RESIZE_TOP) {
                height = device->grab_y - y + resize->height;
-       } else if (resize->edges & WL_GRAB_RESIZE_BOTTOM) {
+       } else if (resize->edges & WL_SHELL_RESIZE_BOTTOM) {
                height = y - device->grab_y + resize->height;
        } else {
                height = resize->height;
@@ -193,28 +193,28 @@ shell_resize(struct wl_client *client, struct wl_shell *shell,
                return;
 
        switch (edges) {
-       case WL_GRAB_RESIZE_TOP:
+       case WL_SHELL_RESIZE_TOP:
                pointer = WLSC_POINTER_TOP;
                break;
-       case WL_GRAB_RESIZE_BOTTOM:
+       case WL_SHELL_RESIZE_BOTTOM:
                pointer = WLSC_POINTER_BOTTOM;
                break;
-       case WL_GRAB_RESIZE_LEFT:
+       case WL_SHELL_RESIZE_LEFT:
                pointer = WLSC_POINTER_LEFT;
                break;
-       case WL_GRAB_RESIZE_TOP_LEFT:
+       case WL_SHELL_RESIZE_TOP_LEFT:
                pointer = WLSC_POINTER_TOP_LEFT;
                break;
-       case WL_GRAB_RESIZE_BOTTOM_LEFT:
+       case WL_SHELL_RESIZE_BOTTOM_LEFT:
                pointer = WLSC_POINTER_BOTTOM_LEFT;
                break;
-       case WL_GRAB_RESIZE_RIGHT:
+       case WL_SHELL_RESIZE_RIGHT:
                pointer = WLSC_POINTER_RIGHT;
                break;
-       case WL_GRAB_RESIZE_TOP_RIGHT:
+       case WL_SHELL_RESIZE_TOP_RIGHT:
                pointer = WLSC_POINTER_TOP_RIGHT;
                break;
-       case WL_GRAB_RESIZE_BOTTOM_RIGHT:
+       case WL_SHELL_RESIZE_BOTTOM_RIGHT:
                pointer = WLSC_POINTER_BOTTOM_RIGHT;
                break;
        }
index 7f1a377..13c71bd 100644 (file)
       <arg name="time" type="uint"/>
     </request>
 
+    <enum name="resize">
+      <entry name="none" value="0"/>
+      <entry name="top" value="1"/>
+      <entry name="bottom" value="2"/>
+      <entry name="left" value="4"/>
+      <entry name="top_left" value="5"/>
+      <entry name="bottom_left" value="6"/>
+      <entry name="right" value="8"/>
+      <entry name="top_right" value="9"/>
+      <entry name="bottom_right" value="10"/>
+    </enum>
+
     <request name="resize">
       <arg name="surface" type="object" interface="surface"/>
       <arg name="input_device" type="object" interface="input_device"/>
index 9d099fb..91054b7 100644 (file)
@@ -68,6 +68,7 @@ struct interface {
        int version;
        struct wl_list request_list;
        struct wl_list event_list;
+       struct wl_list enumeration_list;
        struct wl_list link;
 };
 
@@ -96,10 +97,25 @@ struct arg {
        struct wl_list link;
 };
 
+struct enumeration {
+       char *name;
+       char *uppercase_name;
+       struct wl_list entry_list;
+       struct wl_list link;
+};
+
+struct entry {
+       char *name;
+       char *uppercase_name;
+       char *value;
+       struct wl_list link;
+};
+
 struct parse_context {
        struct protocol *protocol;
        struct interface *interface;
        struct message *message;
+       struct enumeration *enumeration;
 };
 
 static char *
@@ -123,13 +139,16 @@ start_element(void *data, const char *element_name, const char **atts)
        struct interface *interface;
        struct message *message;
        struct arg *arg;
-       const char *name, *type, *interface_name;
+       struct enumeration *enumeration;
+       struct entry *entry;
+       const char *name, *type, *interface_name, *value;
        int i, version;
 
        name = NULL;
        type = NULL;
        version = 0;
        interface_name = NULL;
+       value = NULL;
        for (i = 0; atts[i]; i += 2) {
                if (strcmp(atts[i], "name") == 0)
                        name = atts[i + 1];
@@ -137,6 +156,8 @@ start_element(void *data, const char *element_name, const char **atts)
                        version = atoi(atts[i + 1]);
                if (strcmp(atts[i], "type") == 0)
                        type = atts[i + 1];
+               if (strcmp(atts[i], "value") == 0)
+                       value = atts[i + 1];
                if (strcmp(atts[i], "interface") == 0)
                        interface_name = atts[i + 1];
        }
@@ -166,6 +187,7 @@ start_element(void *data, const char *element_name, const char **atts)
                interface->version = version;
                wl_list_init(&interface->request_list);
                wl_list_init(&interface->event_list);
+               wl_list_init(&interface->enumeration_list);
                wl_list_insert(ctx->protocol->interface_list.prev,
                               &interface->link);
                ctx->interface = interface;
@@ -227,8 +249,29 @@ start_element(void *data, const char *element_name, const char **atts)
                        exit(EXIT_FAILURE);
                }
 
-               wl_list_insert(ctx->message->arg_list.prev,
-                              &arg->link);
+               wl_list_insert(ctx->message->arg_list.prev, &arg->link);
+       } else if (strcmp(element_name, "enum") == 0) {
+               if (name == NULL) {
+                       fprintf(stderr, "no enum name given\n");
+                       exit(EXIT_FAILURE);
+               }
+
+               enumeration = malloc(sizeof *enumeration);
+               enumeration->name = strdup(name);
+               enumeration->uppercase_name = uppercase_dup(name);
+               wl_list_init(&enumeration->entry_list);
+
+               wl_list_insert(ctx->interface->enumeration_list.prev,
+                              &enumeration->link);
+
+               ctx->enumeration = enumeration;
+       } else if (strcmp(element_name, "entry") == 0) {
+               entry = malloc(sizeof *entry);
+               entry->name = strdup(name);
+               entry->uppercase_name = uppercase_dup(name);
+               entry->value = strdup(value);
+               wl_list_insert(ctx->enumeration->entry_list.prev,
+                              &entry->link);
        }
 }
 
@@ -421,6 +464,23 @@ static const char *indent(int n)
 }
 
 static void
+emit_enumerations(struct interface *interface)
+{
+       struct enumeration *e;
+       struct entry *entry;
+
+       wl_list_for_each(e, &interface->enumeration_list, link) {
+               printf("enum wl_%s_%s {\n", interface->name, e->name);
+               wl_list_for_each(entry, &e->entry_list, link)
+                       printf("\tWL_%s_%s_%s = %s,\n",
+                              interface->uppercase_name,
+                              e->uppercase_name,
+                              entry->uppercase_name, entry->value);
+               printf("};\n\n");
+       }
+}
+
+static void
 emit_structs(struct wl_list *message_list, struct interface *interface)
 {
        struct message *m;
@@ -543,6 +603,8 @@ emit_header(struct protocol *protocol, int server)
 
        wl_list_for_each(i, &protocol->interface_list, link) {
 
+               emit_enumerations(i);
+
                if (server) {
                        emit_structs(&i->request_list, i);
                        emit_opcodes(&i->event_list, i);
index fcd134e..76d703a 100644 (file)
@@ -149,23 +149,6 @@ void wl_array_init(struct wl_array *array);
 void wl_array_release(struct wl_array *array);
 void *wl_array_add(struct wl_array *array, int size);
 
-/* FIXME: These should be part of the protocol document */
-enum wl_grab_type {
-       WL_GRAB_NONE = 0,
-       WL_GRAB_RESIZE_TOP = 1,
-       WL_GRAB_RESIZE_BOTTOM = 2,
-       WL_GRAB_RESIZE_LEFT = 4,
-       WL_GRAB_RESIZE_TOP_LEFT = 5,
-       WL_GRAB_RESIZE_BOTTOM_LEFT = 6,
-       WL_GRAB_RESIZE_RIGHT = 8,
-       WL_GRAB_RESIZE_TOP_RIGHT = 9,
-       WL_GRAB_RESIZE_BOTTOM_RIGHT = 10,
-       WL_GRAB_RESIZE_MASK = 15,
-       WL_GRAB_MOVE = 16,
-       WL_GRAB_MOTION = 17,
-       WL_GRAB_DRAG = 18
-};
-
 #ifdef  __cplusplus
 }
 #endif