desktop-shell: add set_panel_position to help place views onscreen

Panels are always assumed to be on the top edge of the output. If this
is not the case views will be placed under the panel, wherever it is,
and maximize doesn't use the correct space allocated for views.

By telling the server on which edge the panel is located, it can
correctly calculate where to put new views and how big maximized views
should be.

[Pekka Paalanen: the user of this protocol so far is Maynard.]

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index ec72287..d307e48 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -4124,13 +4124,34 @@
 	shell_fade_startup(shell);
 }
 
+static void
+desktop_shell_set_panel_position(struct wl_client *client,
+				 struct wl_resource *resource,
+				 uint32_t position)
+{
+	struct desktop_shell *shell = wl_resource_get_user_data(resource);
+
+	if (position != DESKTOP_SHELL_PANEL_POSITION_TOP &&
+	    position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM &&
+	    position != DESKTOP_SHELL_PANEL_POSITION_LEFT &&
+	    position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) {
+		wl_resource_post_error(resource,
+				       DESKTOP_SHELL_ERROR_INVALID_ARGUMENT,
+				       "bad position argument");
+		return;
+	}
+
+	shell->panel_position = position;
+}
+
 static const struct desktop_shell_interface desktop_shell_implementation = {
 	desktop_shell_set_background,
 	desktop_shell_set_panel,
 	desktop_shell_set_lock_surface,
 	desktop_shell_unlock,
 	desktop_shell_set_grab_surface,
-	desktop_shell_desktop_ready
+	desktop_shell_desktop_ready,
+	desktop_shell_set_panel_position
 };
 
 static enum shell_surface_type
@@ -5344,7 +5365,7 @@
 	struct wl_resource *resource;
 
 	resource = wl_resource_create(client, &desktop_shell_interface,
-				      MIN(version, 2), id);
+				      MIN(version, 3), id);
 
 	if (client == shell->child.client) {
 		wl_resource_set_implementation(resource,
@@ -6265,7 +6286,7 @@
 		return -1;
 
 	if (wl_global_create(ec->wl_display,
-			     &desktop_shell_interface, 2,
+			     &desktop_shell_interface, 3,
 			     shell, bind_desktop_shell) == NULL)
 		return -1;
 
@@ -6279,6 +6300,8 @@
 
 	shell->child.deathstamp = weston_compositor_get_time();
 
+	shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP;
+
 	setup_output_destroy_handler(ec, shell);
 
 	loop = wl_display_get_event_loop(ec->wl_display);
diff --git a/desktop-shell/shell.h b/desktop-shell/shell.h
index e994cdb..c6ea328 100644
--- a/desktop-shell/shell.h
+++ b/desktop-shell/shell.h
@@ -26,6 +26,8 @@
 
 #include "compositor.h"
 
+#include "desktop-shell-server-protocol.h"
+
 enum animation_type {
 	ANIMATION_NONE,
 
@@ -205,6 +207,8 @@
 	struct wl_listener output_move_listener;
 	struct wl_list output_list;
 
+	enum desktop_shell_panel_position panel_position;
+
 	char *client;
 };