From 14c92ff07239c3cb7b98c5e86244c59ef4268d9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonas=20=C3=85dahl?= Date: Wed, 29 Aug 2012 22:13:02 +0200 Subject: [PATCH] toytoolkit: Implement support for the workspace manager interface MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- 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 7b35fae..472aabf 100644 --- a/clients/window.c +++ b/clients/window.c @@ -62,6 +62,7 @@ #include #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 { @@ -1345,6 +1350,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) { @@ -1659,6 +1680,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) @@ -1672,6 +1695,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; } } @@ -1682,7 +1719,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); @@ -3504,6 +3542,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) { @@ -3528,6 +3577,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); } } @@ -3694,6 +3745,9 @@ display_create(int argc, char *argv[]) wl_list_init(&d->window_list); + d->workspace = 0; + d->workspace_count = 1; + return d; } -- 2.7.4