[mutter/wayland] wayland: use symbolic constants for interface version



commit 168ea64a459d6f0ad0f2847543fa29c0297efeb7
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Tue Sep 10 13:45:27 2013 +0200

    wayland: use symbolic constants for interface version
    
    Replace magic numbers scattered around the code with proper
    macros collected in one header file.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707851

 src/Makefile.am                        |    1 +
 src/wayland/meta-wayland-data-device.c |   15 +++++---
 src/wayland/meta-wayland-private.h     |    1 +
 src/wayland/meta-wayland-seat.c        |   11 +++---
 src/wayland/meta-wayland-surface.c     |   19 ++++++----
 src/wayland/meta-wayland-versions.h    |   62 ++++++++++++++++++++++++++++++++
 src/wayland/meta-wayland.c             |   24 +++++++-----
 src/wayland/meta-xwayland.c            |    7 ++--
 8 files changed, 110 insertions(+), 30 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2d98d97..442ad27 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -202,6 +202,7 @@ libmutter_wayland_la_SOURCES +=                     \
        wayland/meta-wayland-surface.c          \
        wayland/meta-wayland-surface.h          \
        wayland/meta-wayland-types.h            \
+       wayland/meta-wayland-versions.h         \
        wayland/meta-weston-launch.c            \
        wayland/meta-weston-launch.h
 
diff --git a/src/wayland/meta-wayland-data-device.c b/src/wayland/meta-wayland-data-device.c
index c6cea03..38d3def 100644
--- a/src/wayland/meta-wayland-data-device.c
+++ b/src/wayland/meta-wayland-data-device.c
@@ -111,7 +111,8 @@ meta_wayland_data_source_send_offer (MetaWaylandDataSource *source,
 
   offer->resource = wl_resource_create (wl_resource_get_client (target),
                                        &wl_data_offer_interface,
-                                       MIN (1, wl_resource_get_version (target)), 0);
+                                       MIN (META_WL_DATA_OFFER_VERSION,
+                                            wl_resource_get_version (target)), 0);
   wl_resource_set_implementation (offer->resource, &data_offer_interface,
                                  offer, destroy_data_offer);
   wl_resource_add_destroy_listener (source->resource,
@@ -466,7 +467,8 @@ create_data_source (struct wl_client *client,
     }
 
   source->resource = wl_resource_create (client, &wl_data_source_interface,
-                                        MIN (1, wl_resource_get_version (resource)), id);
+                                        MIN (META_WL_DATA_SOURCE_VERSION,
+                                             wl_resource_get_version (resource)), id);
   wl_resource_set_implementation (source->resource, &data_source_interface,
                                  source, destroy_data_source);
 
@@ -492,7 +494,8 @@ get_data_device (struct wl_client *client,
   struct wl_resource *resource;
 
   resource = wl_resource_create (client, &wl_data_device_interface,
-                                MIN (1, wl_resource_get_version (manager_resource)), id);
+                                MIN (META_WL_DATA_DEVICE_VERSION,
+                                     wl_resource_get_version (manager_resource)), id);
   wl_resource_set_implementation (resource, &data_device_interface, seat, unbind_data_device);
   wl_list_insert (&seat->drag_resource_list, wl_resource_get_link (resource));
 }
@@ -508,7 +511,8 @@ bind_manager (struct wl_client *client,
 {
   struct wl_resource *resource;
 
-  resource = wl_resource_create (client, &wl_data_device_manager_interface, MIN (version, 1), id);
+  resource = wl_resource_create (client, &wl_data_device_manager_interface,
+                                MIN (version, META_WL_DATA_DEVICE_MANAGER_VERSION), id);
   wl_resource_set_implementation (resource, &manager_interface, NULL, NULL);
 }
 
@@ -539,7 +543,8 @@ int
 meta_wayland_data_device_manager_init (struct wl_display *display)
 {
   if (wl_global_create (display,
-                       &wl_data_device_manager_interface, 1,
+                       &wl_data_device_manager_interface,
+                       META_WL_DATA_DEVICE_MANAGER_VERSION,
                        NULL, bind_manager) == NULL)
     return -1;
 
diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h
index 79ff6fd..8611fa6 100644
--- a/src/wayland/meta-wayland-private.h
+++ b/src/wayland/meta-wayland-private.h
@@ -32,6 +32,7 @@
 #include <meta/meta-cursor-tracker.h>
 
 #include "meta-wayland-types.h"
+#include "meta-wayland-versions.h"
 #include "meta-wayland-surface.h"
 #include "meta-wayland-seat.h"
 
diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c
index 76e7522..1b76744 100644
--- a/src/wayland/meta-wayland-seat.c
+++ b/src/wayland/meta-wayland-seat.c
@@ -176,7 +176,7 @@ seat_get_pointer (struct wl_client *client,
   struct wl_resource *cr;
 
   cr = wl_resource_create (client, &wl_pointer_interface,
-                          MIN (wl_resource_get_version (resource), 2), id);
+                          MIN (META_WL_POINTER_VERSION, wl_resource_get_version (resource)), id);
   wl_resource_set_implementation (cr, &pointer_interface, seat, unbind_resource);
   wl_list_insert (&seat->pointer.resource_list, wl_resource_get_link (cr));
 
@@ -206,7 +206,7 @@ seat_get_keyboard (struct wl_client *client,
   struct wl_resource *cr;
 
   cr = wl_resource_create (client, &wl_keyboard_interface,
-                          MIN (wl_resource_get_version (resource), 2), id);
+                          MIN (META_WL_KEYBOARD_VERSION, wl_resource_get_version (resource)), id);
   wl_resource_set_implementation (cr, NULL, seat, unbind_resource);
   wl_list_insert (&seat->keyboard.resource_list, wl_resource_get_link (cr));
 
@@ -249,7 +249,8 @@ bind_seat (struct wl_client *client,
   MetaWaylandSeat *seat = data;
   struct wl_resource *resource;
 
-  resource = wl_resource_create (client, &wl_seat_interface, MIN (version, 2), id);
+  resource = wl_resource_create (client, &wl_seat_interface,
+                                MIN (META_WL_SEAT_VERSION, version), id);
   wl_resource_set_implementation (resource, &seat_interface, seat, unbind_resource);
   wl_list_insert (&seat->base_resource_list, wl_resource_get_link (resource));
 
@@ -257,7 +258,7 @@ bind_seat (struct wl_client *client,
                              WL_SEAT_CAPABILITY_POINTER |
                              WL_SEAT_CAPABILITY_KEYBOARD);
 
-  if (version >= 2)
+  if (version >= META_WL_SEAT_HAS_NAME)
     wl_seat_send_name (resource, "seat0");
 }
 
@@ -297,7 +298,7 @@ meta_wayland_seat_new (struct wl_display *display,
   seat->hotspot_x = 16;
   seat->hotspot_y = 16;
 
-  wl_global_create (display, &wl_seat_interface, 2, seat, bind_seat);
+  wl_global_create (display, &wl_seat_interface, META_WL_SEAT_VERSION, seat, bind_seat);
 
   return seat;
 }
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index 8374ebe..f6547c0 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -817,6 +817,7 @@ static void
 create_surface_extension (struct wl_client          *client,
                          struct wl_resource        *master_resource,
                          guint32                    id,
+                         int                        max_version,
                          MetaWaylandSurface        *surface,
                          const struct wl_interface *interface,
                          const void                *implementation)
@@ -826,7 +827,7 @@ create_surface_extension (struct wl_client          *client,
   extension = g_new0 (MetaWaylandSurfaceExtension, 1);
 
   extension->resource = wl_resource_create (client, interface,
-                                           wl_resource_get_version (master_resource), id);
+                                           MIN (max_version, wl_resource_get_version (master_resource)), id);
   wl_resource_set_implementation (extension->resource, implementation,
                                  extension, destroy_surface_extension);
 
@@ -852,7 +853,7 @@ get_shell_surface (struct wl_client *client,
       return;
     }
 
-  create_surface_extension (client, resource, id, surface,
+  create_surface_extension (client, resource, id, META_WL_SHELL_SURFACE_VERSION, surface,
                            &wl_shell_surface_interface,
                            &meta_wayland_shell_surface_interface);
   surface->has_shell_surface = TRUE;
@@ -871,7 +872,8 @@ bind_shell (struct wl_client *client,
 {
   struct wl_resource *resource;
 
-  resource = wl_resource_create (client, &wl_shell_interface, MIN (1, version), id);
+  resource = wl_resource_create (client, &wl_shell_interface,
+                                MIN (META_WL_SHELL_VERSION, version), id);
   wl_resource_set_implementation (resource, &meta_wayland_shell_interface, data, NULL);
 }
 
@@ -954,7 +956,7 @@ get_gtk_surface (struct wl_client *client,
       return;
     }
 
-  create_surface_extension (client, resource, id, surface,
+  create_surface_extension (client, resource, id, META_GTK_SURFACE_VERSION, surface,
                            &gtk_surface_interface,
                            &meta_wayland_gtk_surface_interface);
   surface->has_gtk_surface = TRUE;
@@ -973,7 +975,8 @@ bind_gtk_shell (struct wl_client *client,
 {
   struct wl_resource *resource;
 
-  resource = wl_resource_create (client, &gtk_shell_interface, MIN (1, version), id);
+  resource = wl_resource_create (client, &gtk_shell_interface,
+                                MIN (META_GTK_SHELL_VERSION, version), id);
   wl_resource_set_implementation (resource, &meta_wayland_gtk_shell_interface, data, NULL);
 
   /* FIXME: ask the plugin */
@@ -984,12 +987,14 @@ void
 meta_wayland_init_shell (MetaWaylandCompositor *compositor)
 {
   if (wl_global_create (compositor->wayland_display,
-                       &wl_shell_interface, 1,
+                       &wl_shell_interface,
+                       META_WL_SHELL_VERSION,
                        compositor, bind_shell) == NULL)
     g_error ("Failed to register a global shell object");
 
   if (wl_global_create (compositor->wayland_display,
-                       &gtk_shell_interface, 1,
+                       &gtk_shell_interface,
+                       META_GTK_SHELL_VERSION,
                        compositor, bind_gtk_shell) == NULL)
     g_error ("Failed to register a global gtk-shell object");
 }
diff --git a/src/wayland/meta-wayland-versions.h b/src/wayland/meta-wayland-versions.h
new file mode 100644
index 0000000..1cb569b
--- /dev/null
+++ b/src/wayland/meta-wayland-versions.h
@@ -0,0 +1,62 @@
+/*
+ * Wayland Support
+ *
+ * Copyright (C) 2012,2013 Intel Corporation
+ *               2013 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef META_WAYLAND_VERSIONS_H
+#define META_WAYLAND_VERSIONS_H
+
+/* Protocol objects, will never change version */
+/* #define META_WL_DISPLAY_VERSION  1 */
+/* #define META_WL_REGISTRY_VERSION 1 */
+#define META_WL_CALLBACK_VERSION 1
+
+/* Not handled by mutter-wayland directly */
+/* #define META_WL_SHM_VERSION        1 */
+/* #define META_WL_SHM_POOL_VERSION   1 */
+/* #define META_WL_DRM_VERSION        1 */
+/* #define META_WL_BUFFER_VERSION     1 */
+
+/* Global/master objects (version exported by wl_registry and negotiated through bind) */
+#define META_WL_COMPOSITOR_VERSION          3
+#define META_WL_DATA_DEVICE_MANAGER_VERSION 1
+#define META_WL_SHELL_VERSION               1
+#define META_WL_SEAT_VERSION                2 /* 3 not implemented yet */
+#define META_WL_OUTPUT_VERSION              2
+#define META_XSERVER_VERSION                1
+#define META_GTK_SHELL_VERSION              1
+
+/* Slave objects (version inherited from a master object) */
+#define META_WL_DATA_OFFER_VERSION          1 /* from wl_data_device */
+#define META_WL_DATA_SOURCE_VERSION         1 /* from wl_data_device */
+#define META_WL_DATA_DEVICE_VERSION         1 /* from wl_data_device_manager */
+#define META_WL_SHELL_SURFACE_VERSION       1 /* from wl_shell */
+#define META_WL_SURFACE_VERSION             3 /* from wl_compositor */
+#define META_WL_POINTER_VERSION             2 /* from wl_seat; 3 not implemented yet */
+#define META_WL_KEYBOARD_VERSION            2 /* from wl_seat; 3 not implemented yet */
+#define META_WL_TOUCH_VERSION               0 /* from wl_seat; wl_touch not supported */
+#define META_WL_REGION_VERSION              1 /* from wl_compositor */
+#define META_GTK_SURFACE_VERSION            1 /* from gtk_shell */
+
+/* The first version to implement a specific event */
+#define META_WL_SEAT_HAS_NAME               2
+#define META_WL_OUTPUT_HAS_DONE             2
+
+#endif
diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c
index e20ae75..db6662e 100644
--- a/src/wayland/meta-wayland.c
+++ b/src/wayland/meta-wayland.c
@@ -230,11 +230,10 @@ meta_wayland_compositor_create_surface (struct wl_client *wayland_client,
     wl_resource_get_user_data (wayland_compositor_resource);
   MetaWaylandSurface *surface;
 
-  /* a surface inherits the version from the compositor */
   surface = meta_wayland_surface_create (compositor,
-                                        wayland_client,
-                                        id,
-                                        MIN (3, wl_resource_get_version (wayland_compositor_resource)));
+                                        wayland_client, id,
+                                        MIN (META_WL_SURFACE_VERSION,
+                                             wl_resource_get_version (wayland_compositor_resource)));
   
   compositor->surfaces = g_list_prepend (compositor->surfaces, surface);
 }
@@ -298,7 +297,8 @@ meta_wayland_compositor_create_region (struct wl_client *wayland_client,
 
   region->resource = wl_resource_create (wayland_client,
                                         &wl_region_interface,
-                                        MIN (1, wl_resource_get_version (compositor_resource)),
+                                        MIN (META_WL_REGION_VERSION,
+                                             wl_resource_get_version (compositor_resource)),
                                         id);
   wl_resource_set_implementation (region->resource,
                                  &meta_wayland_region_interface, region,
@@ -336,7 +336,8 @@ bind_output (struct wl_client *client,
   struct wl_resource *resource;
   guint mode_flags;
 
-  resource = wl_resource_create (client, &wl_output_interface, MIN (2, version), id);
+  resource = wl_resource_create (client, &wl_output_interface,
+                                MIN (META_WL_OUTPUT_VERSION, version), id);
   wayland_output->resources = g_list_prepend (wayland_output->resources, resource);
 
   wl_resource_set_user_data (resource, wayland_output);
@@ -374,7 +375,7 @@ bind_output (struct wl_client *client,
                           (int)output->crtc->current_mode->height,
                           (int)output->crtc->current_mode->refresh_rate);
 
-  if (version >= 2)
+  if (version >= META_WL_OUTPUT_HAS_DONE)
     wl_resource_post_event (resource,
                             WL_OUTPUT_DONE);
 }
@@ -477,7 +478,8 @@ meta_wayland_compositor_update_outputs (MetaWaylandCompositor *compositor,
         {
           wayland_output = g_slice_new0 (MetaWaylandOutput);
           wayland_output->global = wl_global_create (compositor->wayland_display,
-                                                     &wl_output_interface, 2,
+                                                     &wl_output_interface,
+                                                    META_WL_OUTPUT_VERSION,
                                                      wayland_output, bind_output);
         }
 
@@ -519,7 +521,8 @@ compositor_bind (struct wl_client *client,
   MetaWaylandCompositor *compositor = data;
   struct wl_resource *resource;
 
-  resource = wl_resource_create (client, &wl_compositor_interface, MIN (3, version), id);
+  resource = wl_resource_create (client, &wl_compositor_interface,
+                                MIN (META_WL_COMPOSITOR_VERSION, version), id);
   wl_resource_set_implementation (resource, &meta_wayland_compositor_interface, compositor, NULL);
 }
 
@@ -823,7 +826,8 @@ meta_wayland_init (void)
   wl_list_init (&compositor->frame_callbacks);
 
   if (!wl_global_create (compositor->wayland_display,
-                        &wl_compositor_interface, 3,
+                        &wl_compositor_interface,
+                        META_WL_COMPOSITOR_VERSION,
                         compositor, compositor_bind))
     g_error ("Failed to register wayland compositor object");
 
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
index 2d1af18..fee0f03 100644
--- a/src/wayland/meta-xwayland.c
+++ b/src/wayland/meta-xwayland.c
@@ -87,8 +87,8 @@ bind_xserver (struct wl_client *client,
   if (client != compositor->xwayland_client)
     return;
 
-  compositor->xserver_resource =
-    wl_resource_create (client, &xserver_interface, MIN (1, version), id);
+  compositor->xserver_resource = wl_resource_create (client, &xserver_interface,
+                                                    MIN (META_XSERVER_VERSION, version), id);
   wl_resource_set_implementation (compositor->xserver_resource,
                                  &xserver_implementation, compositor, NULL);
 
@@ -323,7 +323,8 @@ meta_xwayland_start (MetaWaylandCompositor *compositor)
   GError *error;
 
   wl_global_create (compositor->wayland_display,
-                   &xserver_interface, 1,
+                   &xserver_interface,
+                   META_XSERVER_VERSION,
                    compositor, bind_xserver);
 
   do


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