[PATCH 4/5] shell: do the actual taskbar_handler visual actions

Manuel Bachmann manuel.bachmann at open.eurogiciel.org
Tue Feb 18 21:18:54 PST 2014


We now really draw the handler widgets. They will be added,
destroyed and renamed when receiving events.

Signed-off-by: Manuel Bachmann <manuel.bachmann at open.eurogiciel.org>
---
 clients/desktop-shell.c |  123 ++++++++++++++++++++++++++++++++++++++++++++++-
 desktop-shell/shell.c   |    3 +-
 2 files changed, 123 insertions(+), 3 deletions(-)

diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 5f861b2..c1fb15d 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -599,6 +599,52 @@ panel_create(struct desktop *desktop)
 }
 
 static void
+taskbar_handler_activate(struct taskbar_handler *handler)
+{
+	 /* invert the handler state */
+	if (handler->state == 0)
+		handler->state = 1;
+	else
+		handler->state = 0;
+
+	 /* request the compositor to minimize/raise the window */
+	managed_surface_set_state(handler->surface, handler->state);
+}
+
+static void
+taskbar_handler_redraw_handler(struct widget *widget, void *data)
+{
+	struct taskbar_handler *handler = data;
+	struct rectangle allocation;
+	cairo_t *cr;
+
+	cr = widget_cairo_create(handler->taskbar->widget);
+
+	widget_get_allocation(widget, &allocation);
+	if (handler->pressed) {
+		allocation.x++;
+		allocation.y++;
+	}
+
+	cairo_set_source_surface(cr, handler->icon,
+				 allocation.x, allocation.y);
+	cairo_paint(cr);
+
+	cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
+	/* cairo_set_font_size (cr, 20); */
+	cairo_move_to (cr, allocation.x+20, allocation.y+12);
+	cairo_show_text (cr, handler->title);
+
+	if (handler->focused) {
+		cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4);
+		cairo_mask_surface(cr, handler->icon,
+				   allocation.x, allocation.y);
+	}
+
+	cairo_destroy(cr);
+}
+
+static void
 taskbar_redraw_handler(struct widget *widget, void *data)
 {
 	cairo_surface_t *surface;
@@ -617,6 +663,44 @@ taskbar_redraw_handler(struct widget *widget, void *data)
 	check_desktop_ready(taskbar->window);
 }
 
+static int
+taskbar_handler_enter_handler(struct widget *widget, struct input *input,
+			     float x, float y, void *data)
+{
+	struct taskbar_handler *handler = data;
+
+	handler->focused = 1;
+	widget_schedule_redraw(widget);
+
+	return CURSOR_LEFT_PTR;
+}
+
+static void
+taskbar_handler_leave_handler(struct widget *widget,
+			     struct input *input, void *data)
+{
+	struct taskbar_handler *handler = data;
+
+	handler->focused = 0;
+	/* no tooltip yet... */
+	/* widget_destroy_tooltip(widget); */
+	widget_schedule_redraw(widget);
+}
+
+static void
+taskbar_handler_button_handler(struct widget *widget,
+			      struct input *input, uint32_t time,
+			      uint32_t butt,
+			      enum wl_pointer_button_state state, void *data)
+{
+	struct taskbar_handler *handler;
+
+	handler = widget_get_user_data(widget);
+	widget_schedule_redraw(widget);
+	if (state == WL_POINTER_BUTTON_STATE_RELEASED)
+		taskbar_handler_activate(handler);
+}
+
 static void
 taskbar_resize_handler(struct widget *widget,
 		     int32_t width, int32_t height, void *data)
@@ -822,6 +906,39 @@ panel_add_launcher(struct panel *panel, const char *icon, const char *path)
 				  panel_launcher_motion_handler);
 }
 
+static const struct managed_surface_listener managed_surface_listener;
+
+static void
+taskbar_add_handler(struct taskbar *taskbar,
+			        struct managed_surface *managed_surface, 
+			        const char *title)
+{
+	struct taskbar_handler *handler;
+
+	handler = xzalloc(sizeof *handler);
+	handler->icon = load_icon_or_fallback(DATADIR "/weston/icon_window.png");
+	handler->surface = managed_surface;
+	handler->title = strdup(title);
+	handler->state = 0;
+
+	handler->taskbar = taskbar;
+	wl_list_insert(taskbar->handler_list.prev, &handler->link);
+
+	handler->widget = widget_add_widget(taskbar->widget, handler);
+	widget_set_enter_handler(handler->widget,
+				 taskbar_handler_enter_handler);
+	widget_set_leave_handler(handler->widget,
+				   taskbar_handler_leave_handler);
+	widget_set_button_handler(handler->widget,
+				    taskbar_handler_button_handler);
+	widget_set_redraw_handler(handler->widget,
+				  taskbar_handler_redraw_handler);
+
+	managed_surface_add_listener(handler->surface,
+	                             &managed_surface_listener,
+	                             handler);
+}
+
 enum {
 	BACKGROUND_SCALE,
 	BACKGROUND_SCALE_CROP,
@@ -1130,7 +1247,8 @@ desktop_shell_add_managed_surface(void *data,
 	struct output *output;
 
 	wl_list_for_each(output, &desktop->outputs, link) {
-		/* will follow in next patch : add the actual handler here */
+		/* add a handler with default title */
+		taskbar_add_handler(output->taskbar, managed_surface, "<Default>");
 		update_window(output->taskbar->window);
 	}
 }
@@ -1223,7 +1341,8 @@ managed_surface_removed(void *data,
 	struct taskbar_handler *handler = data;
 
 	if (handler->surface == managed_surface) {
-		/* will follow in next patch : destroy the actual handler here */
+		/* destroy the handler */
+		taskbar_destroy_handler(handler);
 		update_window(handler->taskbar->window);
 	}
 }
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 57afe5b..8910df4 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -3001,7 +3001,8 @@ destroy_shell_surface(struct shell_surface *shsurf)
 
 	if (shsurf->type == SHELL_SURFACE_TOPLEVEL) {
 		struct managed_surface *managed_surface;
-		wl_list_for_each(managed_surface, &shsurf->shell->managed_surfaces_list, link) {
+		struct managed_surface *tmp;
+		wl_list_for_each_safe(managed_surface, tmp, &shsurf->shell->managed_surfaces_list, link) {
 			if (managed_surface->surface == shsurf->surface) {
 				managed_surface_send_removed (managed_surface->resource);
 				wl_list_remove(&managed_surface->link);
-- 
1.7.10.4



More information about the wayland-devel mailing list