[PATCH weston 5/6] toytoolkit: Implement support for the workspace manager interface

Jonas Ådahl jadahl at gmail.com
Wed Aug 29 13:13:02 PDT 2012


Two buttons are added to the right-click menu of the window frame for
moving a surface either up or down.

Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
 clients/Makefile.am |    8 ++++++--
 clients/window.c    |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/clients/Makefile.am b/clients/Makefile.am
index 71a37bd..1b7fa10 100644
--- a/clients/Makefile.am
+++ b/clients/Makefile.am
@@ -67,7 +67,9 @@ libtoytoolkit_a_SOURCES =			\
 	window.c				\
 	window.h				\
 	text-cursor-position-protocol.c		\
-	text-cursor-position-client-protocol.h
+	text-cursor-position-client-protocol.h	\
+	workspaces-protocol.c			\
+	workspaces-client-protocol.h
 
 toolkit_libs =						\
 	libtoytoolkit.a					\
@@ -143,7 +145,9 @@ BUILT_SOURCES =					\
 	desktop-shell-client-protocol.h		\
 	desktop-shell-protocol.c		\
 	tablet-shell-client-protocol.h		\
-	tablet-shell-protocol.c
+	tablet-shell-protocol.c			\
+	workspaces-client-protocol.h		\
+	workspaces-protocol.c
 
 CLEANFILES = $(BUILT_SOURCES)
 endif
diff --git a/clients/window.c b/clients/window.c
index 3846e15..131cd18 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -62,6 +62,7 @@
 #include <wayland-client.h>
 #include "../shared/cairo-util.h"
 #include "text-cursor-position-client-protocol.h"
+#include "workspaces-client-protocol.h"
 #include "../shared/os-compatibility.h"
 
 #include "window.h"
@@ -75,6 +76,7 @@ struct display {
 	struct wl_shm *shm;
 	struct wl_data_device_manager *data_device_manager;
 	struct text_cursor_position *text_cursor_position;
+	struct workspace_manager *workspace_manager;
 	EGLDisplay dpy;
 	EGLConfig argb_config;
 	EGLContext argb_ctx;
@@ -108,6 +110,9 @@ struct display {
 	void *user_data;
 
 	struct xkb_context *xkb_context;
+
+	uint32_t workspace;
+	uint32_t workspace_count;
 };
 
 enum {
@@ -1260,6 +1265,22 @@ widget_set_tooltip(struct widget *parent, char *entry, float x, float y)
 }
 
 static void
+workspace_manager_state(void *data,
+			struct workspace_manager *workspace_manager,
+			uint32_t current,
+			uint32_t count)
+{
+	struct display *display = data;
+
+	display->workspace = current;
+	display->workspace_count = count;
+}
+
+static const struct workspace_manager_listener workspace_manager_listener = {
+	workspace_manager_state
+};
+
+static void
 frame_resize_handler(struct widget *widget,
 		     int32_t width, int32_t height, void *data)
 {
@@ -1574,6 +1595,8 @@ frame_get_pointer_image_for_location(struct frame *frame, struct input *input)
 static void
 frame_menu_func(struct window *window, int index, void *data)
 {
+	struct display *display;
+
 	switch (index) {
 	case 0: /* close */
 		if (window->close_handler)
@@ -1587,6 +1610,20 @@ frame_menu_func(struct window *window, int index, void *data)
 		if (window->fullscreen_handler)
 			window->fullscreen_handler(window, window->user_data);
 		break;
+	case 2: /* move to workspace above */
+		display = window->display;
+		if (display->workspace > 0)
+			workspace_manager_move_surface(display->workspace_manager,
+						       window->surface,
+						       display->workspace - 1);
+		break;
+	case 3: /* move to workspace below */
+		display = window->display;
+		if (display->workspace < display->workspace_count)
+			workspace_manager_move_surface(display->workspace_manager,
+						       window->surface,
+						       display->workspace + 1);
+		break;
 	}
 }
 
@@ -1597,7 +1634,8 @@ window_show_frame_menu(struct window *window,
 	int32_t x, y;
 
 	static const char *entries[] = {
-		"Close", "Fullscreen"
+		"Close", "Fullscreen",
+		"Move to workspace above", "Move to workspace below"
 	};
 
 	input_get_position(input, &x, &y);
@@ -3419,6 +3457,17 @@ input_destroy(struct input *input)
 }
 
 static void
+init_workspace_manager(struct display *d, uint32_t id)
+{
+	d->workspace_manager =
+		wl_display_bind(d->display, id, &workspace_manager_interface);
+	if (d->workspace_manager != NULL)
+		workspace_manager_add_listener(d->workspace_manager,
+					       &workspace_manager_listener,
+					       d);
+}
+
+static void
 display_handle_global(struct wl_display *display, uint32_t id,
 		      const char *interface, uint32_t version, void *data)
 {
@@ -3443,6 +3492,8 @@ display_handle_global(struct wl_display *display, uint32_t id,
 		d->text_cursor_position =
 			wl_display_bind(display, id,
 					&text_cursor_position_interface);
+	} else if (strcmp(interface, "workspace_manager") == 0) {
+		init_workspace_manager(d, id);
 	}
 }
 
@@ -3609,6 +3660,9 @@ display_create(int argc, char *argv[])
 
 	wl_list_init(&d->window_list);
 
+	d->workspace = 0;
+	d->workspace_count = 1;
+
 	return d;
 }
 
-- 
1.7.9.5



More information about the wayland-devel mailing list