[PATCH v2 08/15] tablet-shell: add layout indicator on homescreen.

ning.tang at intel.com ning.tang at intel.com
Thu Aug 23 01:07:43 PDT 2012


From: Ning Tang <ning.tang at intel.com>

We could know how many layouts in total and our current layout.
Keyword in ini file is the path to indicator images, use the format of
1-f.png(focus) 1.png 2-f.png...

 Signed-off-by: Ning Tang <ning.tang at intel.com>
---
 clients/tablet-shell.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 weston-tablet.ini      |  1 +
 2 files changed, 48 insertions(+)

diff --git a/clients/tablet-shell.c b/clients/tablet-shell.c
index e3b5cf3..bb327b4 100644
--- a/clients/tablet-shell.c
+++ b/clients/tablet-shell.c
@@ -63,6 +63,7 @@ struct layout {
 	struct wl_list launcher_list;
 	struct wl_list link;
 	int index;
+	int active;
 	int pressed;
 	int showing;
 	int offset;
@@ -74,6 +75,8 @@ struct layout {
 	int switching;			/* 0-no 1-right -1-left*/
 	int s_speed;			/* switching speed */
 	struct wl_list *layout_list;	/* we need know the number of list */
+	cairo_surface_t *active_indicator;
+	cairo_surface_t *inactive_indicator;
 };
 
 struct launcher {
@@ -103,6 +106,7 @@ static char *key_launcher_icon;
 static char *key_launcher_path;
 static void launcher_section_done(void *data);
 static void layout_section_done(void *data);
+static char *key_layout_indicator_path;
 static char *key_trash_image;
 /* launcher drag */
 struct launcher *gl_launcher_drag = NULL;
@@ -119,6 +123,7 @@ static const struct config_key shell_config_keys[] = {
 	{ "lockscreen", CONFIG_KEY_STRING, &key_lockscreen_background },
 	{ "homescreen", CONFIG_KEY_STRING, &key_homescreen_background },
 	{ "trash-image", CONFIG_KEY_STRING, &key_trash_image },
+	{ "layout-indicator", CONFIG_KEY_STRING, &key_layout_indicator_path },
 	{ "layout-rows", CONFIG_KEY_UNSIGNED_INTEGER, &key_layout_rows },
 	{ "layout-columns", CONFIG_KEY_UNSIGNED_INTEGER, &key_layout_columns },
 	{ "icon-size", CONFIG_KEY_UNSIGNED_INTEGER, &launcher_size },
@@ -207,6 +212,27 @@ homescreen_draw_trash(struct homescreen *homescreen)
 }
 
 static void
+layout_draw_indicator(struct layout *layout, int y, int x_center)
+{
+	const int index_size = 40;
+	cairo_surface_t *surface;
+	surface = window_get_surface(layout->homescreen->window);
+	cairo_t *cr = cairo_create(surface);
+
+	int x = x_center - index_size * wl_list_length(layout->layout_list) / 2
+		+ layout->index * index_size;
+	if (layout->active) {
+		cairo_set_source_surface(cr, layout->active_indicator, x, y);
+	} else {
+		cairo_set_source_surface(cr, layout->inactive_indicator, x, y);
+	}
+	cairo_paint(cr);
+
+	cairo_destroy(cr);
+	cairo_surface_destroy(surface);
+}
+
+static void
 homescreen_draw(struct widget *widget, void *data)
 {
 	struct homescreen *homescreen = data;
@@ -232,6 +258,9 @@ homescreen_draw(struct widget *widget, void *data)
 					      allocation.height
 					      - 2 * layout->vmargin);
 		}
+		layout_draw_indicator(layout,
+				      allocation.height - layout->vmargin,
+				      allocation.width / 2);
 	}
 
 	/* draw trash if dragging*/
@@ -787,7 +816,9 @@ layout_frame_callback(void *data, struct wl_callback *callback, uint32_t time)
 			layout->showing = 0;
 			widget_set_allocation(layout->widget,
 					      0, 0, 0, 0);
+			layout->active = 0;
 		} else {
+			layout->active = 1;
 			widget_set_allocation(layout->widget,
 					      layout->hmargin,
 					      layout->vmargin,
@@ -1034,6 +1065,7 @@ tablet_shell_add_layout(struct tablet *tablet)
 	struct layout *layout;
 	struct homescreen *homescreen = tablet->homescreen;
 	struct rectangle allocation;
+	char *index_image;
 	widget_get_allocation(homescreen->widget, &allocation);
 
 	layout = malloc(sizeof *layout);
@@ -1046,6 +1078,7 @@ tablet_shell_add_layout(struct tablet *tablet)
 	layout->switching = 0;
 	layout->s_speed = 30;
 	if (wl_list_empty(&homescreen->layout_list)) {
+		layout->active = 1;
 		layout->showing = 1;
 	}
 	layout->offset = 0;
@@ -1055,6 +1088,20 @@ tablet_shell_add_layout(struct tablet *tablet)
 	layout->index = wl_list_length(layout->layout_list);
 
 	wl_list_insert(homescreen->layout_list.prev, &layout->link);
+	if (layout->inactive_indicator == NULL && key_layout_indicator_path) {
+		index_image = malloc(sizeof (char) *
+			      (strlen(key_layout_indicator_path) + 8));
+		memset(index_image, 0, sizeof *index_image);
+		sprintf(index_image, "%s%d%s",
+			key_layout_indicator_path, layout->index + 1, ".png");
+		layout->inactive_indicator =
+			load_cairo_surface(index_image);
+		sprintf(index_image, "%s%d%s",
+			key_layout_indicator_path, layout->index + 1, "-f.png");
+		layout->active_indicator =
+			load_cairo_surface(index_image);
+		free(index_image);
+	}
 	widget_set_button_handler(layout->widget,
 				  layout_button_handler);
 	widget_set_motion_handler(layout->widget,
diff --git a/weston-tablet.ini b/weston-tablet.ini
index 58fd688..f1f12ad 100644
--- a/weston-tablet.ini
+++ b/weston-tablet.ini
@@ -8,6 +8,7 @@ layout-rows=6
 layout-columns=8
 icon-size=64
 trash-image=/usr/share/weston/trash.png
+layout-indicator=/usr/share/weston/
 
 [layout]
 [launcher]
-- 
1.7.11.5



More information about the wayland-devel mailing list