xdg-shell: Add set_margin request
authorJasper St. Pierre <jstpierre@mecheye.net>
Sat, 1 Feb 2014 23:36:41 +0000 (18:36 -0500)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 6 Feb 2014 21:05:03 +0000 (13:05 -0800)
This is used to figure out the size of "invisible" decorations, which we'll
use to better know the visible extents of the surface, which we can use for
constraining, titlebars, and more.

clients/window.c
desktop-shell/shell.c
protocol/xdg-shell.xml
shared/cairo-util.h
shared/frame.c

index 97cce1a..91c1ea0 100644 (file)
@@ -3938,6 +3938,27 @@ window_sync_transient_for(struct window *window)
 }
 
 static void
+window_sync_margin(struct window *window)
+{
+       int margin;
+
+       if (!window->xdg_surface)
+               return;
+
+       if (!window->frame)
+               return;
+
+       margin = frame_get_shadow_margin(window->frame->frame);
+
+       /* Shadow size is the same on every side. */
+       xdg_surface_set_margin(window->xdg_surface,
+                                    margin,
+                                    margin,
+                                    margin,
+                                    margin);
+}
+
+static void
 window_flush(struct window *window)
 {
        struct surface *surface;
@@ -3953,6 +3974,7 @@ window_flush(struct window *window)
                                                 &xdg_surface_listener, window);
 
                        window_sync_transient_for(window);
+                       window_sync_margin(window);
                }
        }
 
index b9b49cb..a73e8e0 100644 (file)
@@ -3172,6 +3172,18 @@ xdg_surface_pong(struct wl_client *client,
 }
 
 static void
+xdg_surface_set_margin(struct wl_client *client,
+                            struct wl_resource *resource,
+                            int32_t left,
+                            int32_t right,
+                            int32_t top,
+                            int32_t bottom)
+{
+       /* Do nothing, Weston doesn't try to constrain or place
+        * surfaces in any special manner... */
+}
+
+static void
 xdg_surface_set_app_id(struct wl_client *client,
                       struct wl_resource *resource,
                       const char *app_id)
@@ -3309,6 +3321,7 @@ xdg_surface_unset_maximized(struct wl_client *client,
 static const struct xdg_surface_interface xdg_surface_implementation = {
        xdg_surface_destroy,
        xdg_surface_set_transient_for,
+       xdg_surface_set_margin,
        xdg_surface_set_title,
        xdg_surface_set_app_id,
        xdg_surface_pong,
index 5c21f4e..f0d04aa 100644 (file)
       <arg name="parent" type="object" interface="wl_surface" allow-null="true"/>
     </request>
 
+    <request name="set_margin">
+      <description summary="set the visible frame boundaries">
+        This tells the compositor what the visible size of the window
+        should be, so it can use it to determine what borders to use for
+        constrainment and alignment.
+
+        CSD often has invisible areas for decoration purposes, like drop
+        shadows. These "shadow" drawings need to be subtracted out of the
+        normal boundaries of the window when computing where to place
+        windows (e.g. to set this window so it's centered on top of another,
+        or to put it to the left or right of the screen.)
+
+        This value should change as little as possible at runtime, to
+        prevent flicker.
+
+        This value is also ignored when the window is maximized or
+        fullscreen, and assumed to be 0.
+
+        If never called, this value is assumed to be 0.
+      </description>
+      <arg name="left_margin" type="int"/>
+      <arg name="right_margin" type="int"/>
+      <arg name="top_margin" type="int"/>
+      <arg name="bottom_margin" type="int"/>
+    </request>
+
     <request name="set_title">
       <description summary="set surface title">
        Set a short title for the surface.
index 7bcbc29..4493b0d 100644 (file)
@@ -165,6 +165,9 @@ void
 frame_opaque_rect(struct frame *frame, int32_t *x, int32_t *y,
                  int32_t *width, int32_t *height);
 
+int
+frame_get_shadow_margin(struct frame *frame);
+
 uint32_t
 frame_status(struct frame *frame);
 
index a039d15..35e6b65 100644 (file)
@@ -578,6 +578,14 @@ frame_opaque_rect(struct frame *frame, int32_t *x, int32_t *y,
                *height = frame->height - frame->opaque_margin * 2;
 }
 
+int
+frame_get_shadow_margin(struct frame *frame)
+{
+       frame_refresh_geometry(frame);
+
+       return frame->shadow_margin;
+}
+
 uint32_t
 frame_status(struct frame *frame)
 {