[PATCH 07/14] tablet-shell: add layout indicator on homescreen.

Tang, Ning ning.tang at intel.com
Tue Aug 21 20:21:31 PDT 2012



> -----Original Message-----
> From: wayland-devel-bounces+ning.tang=intel.com at lists.freedesktop.org
> [mailto:wayland-devel-bounces+ning.tang=intel.com at lists.freedesktop.org]
> On Behalf Of Philipp Brüschweiler
> Sent: Tuesday, August 21, 2012 11:57 PM
> To: tecton69 at gmail.com
> Cc: juan.j.zhao at linux.intel.com; Tang, Ning;
> wayland-devel at lists.freedesktop.org
> Subject: Re: [PATCH 07/14] tablet-shell: add layout indicator on homescreen.
> 
> On Tue, Aug 21, 2012 at 1:49 PM,  <tecton69 at gmail.com> wrote:
> > 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 <tecton69 at gmail.com>
> >
> > ---
> >  clients/tablet-shell.c | 51
> ++++++++++++++++++++++++++++++++++++++++++++++++++
> >  weston-tablet.ini      |  1 +
> >  2 files changed, 52 insertions(+)
> >
> > diff --git a/clients/tablet-shell.c b/clients/tablet-shell.c index
> > 860bba8..abf0e7c 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 },
> > @@ -224,6 +229,31 @@ homescreen_draw_trash(void *data, int x, int y)
> > }
> >
> >  static void
> > +layout_draw_indicator(struct layout *layout, int y, int x_center) {
> > +       const int index_size = 40;
> > +       int total_layout = wl_list_length(layout->layout_list) - 1;
> > +       int current_index = layout->index;
> > +       int odd = (total_layout % 2 == 0)? 1: 0;
> > +       int offset = current_index - (total_layout / 2) - (odd ? 0: 1);
> > +       int x;
> > +       cairo_surface_t *surface;
> > +       surface = window_get_surface(layout->homescreen->window);
> > +       cairo_t *cr = cairo_create(surface);
> > +
> > +       x = x_center + (offset * index_size) - (odd? index_size / 2:
> > + 0);
> 
> This is really complicated. How about:
> 
>    x = x_center - index_size * wl_list_length(layout->layout_list) / 2
> + current_index * index_size;
> 
It is complicated because I wanted to move half width of the center index image
If it has odd number of layouts to let them centered on screen exactly.
Your method is efficient and I will change it.
Thank you.

> > +       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; @@ -249,6 +279,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*/
> > @@ -785,7 +818,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,
> @@
> > -1027,6 +1062,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); @@ -1039,6 +1075,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;
> > @@ -1048,6 +1085,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) +
> > + 7));
> 
> This has to be at least + 8, but more if you want more than 9 layouts:
> strlen("-f.png") + number + null terminator.
> 
Oh, yes. :)

> > +               memset(index_image, 0, sizeof *index_image);
> 
> This isn't necessary.
> 
> > +               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
> >
> > _______________________________________________
> > wayland-devel mailing list
> > wayland-devel at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list