[PATCH] desktop-shell: Make clock format configurable

Scott Moreau oreaus at gmail.com
Wed Jun 13 10:17:33 PDT 2012


On Tue, Jun 12, 2012 at 6:45 PM, Martin Minarik <
minarik11 at student.fiit.stuba.sk> wrote:

> This allows the user to specify the format of the displayed time.
> It is possible to set the period of redraw (in seconds).
>

Hi Martin, thanks for doing this. This seems to work but there are a few
things that I noticed. A few comments below.


> ---
>  clients/desktop-shell.c |   49
> +++++++++++++++++++++++++++++++++++++++++++---
>  1 files changed, 45 insertions(+), 4 deletions(-)
>
> diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
> index 9a1b502..ff0afcb 100644
> --- a/clients/desktop-shell.c
> +++ b/clients/desktop-shell.c
> @@ -97,6 +97,8 @@ struct panel_clock {
>        struct panel *panel;
>        struct task clock_task;
>        int clock_fd;
> +       char *time_format;
> +       unsigned int interval;
>  };
>
>  struct unlock_dialog {
> @@ -114,7 +116,10 @@ static uint32_t key_panel_color = 0xaa000000;
>  static uint32_t key_background_color = 0xff002244;
>  static char *key_launcher_icon;
>  static char *key_launcher_path;
> +static char *key_clock_format = NULL;
> +static unsigned int *key_clock_interval = 0;
>  static void launcher_section_done(void *data);
> +static void clock_section_done(void *data);
>  static int key_locking = 1;
>
>  static const struct config_key shell_config_keys[] = {
> @@ -130,12 +135,20 @@ static const struct config_key
> launcher_config_keys[] = {
>        { "path", CONFIG_KEY_STRING, &key_launcher_path },
>  };
>
> +static const struct config_key clock_config_keys[] = {
> +       { "format", CONFIG_KEY_STRING, &key_clock_format },
> +       { "interval", CONFIG_KEY_UNSIGNED_INTEGER, &key_clock_interval },
> +};
> +
>  static const struct config_section config_sections[] = {
>        { "shell",
>          shell_config_keys, ARRAY_LENGTH(shell_config_keys) },
>        { "launcher",
>          launcher_config_keys, ARRAY_LENGTH(launcher_config_keys),
> -         launcher_section_done }
> +         launcher_section_done },
> +       { "clock",
> +         clock_config_keys, ARRAY_LENGTH(clock_config_keys),
> +         clock_section_done }
>  };
>
>  static void
> @@ -319,7 +332,7 @@ panel_clock_redraw_handler(struct widget *widget, void
> *data)
>
>        time(&rawtime);
>        timeinfo = localtime(&rawtime);
> -       strftime(string, sizeof string, "%a %b %d, %I:%M %p", timeinfo);
> +       strftime(string, sizeof string, clock->time_format, timeinfo);
>
>        widget_get_allocation(widget, &allocation);
>        if (allocation.width == 0)
> @@ -349,9 +362,9 @@ clock_timer_reset(struct panel_clock *clock)
>  {
>        struct itimerspec its;
>
> -       its.it_interval.tv_sec = 60;
> +       its.it_interval.tv_sec = clock->interval;
>        its.it_interval.tv_nsec = 0;
> -       its.it_value.tv_sec = 60;
> +       its.it_value.tv_sec = clock->interval;
>        its.it_value.tv_nsec = 0;
>        if (timerfd_settime(clock->clock_fd, 0, &its, NULL) < 0) {
>                fprintf(stderr, "could not set timerfd\n: %m");
> @@ -361,6 +374,9 @@ clock_timer_reset(struct panel_clock *clock)
>        return 0;
>  }
>
> +static const char *clock_default_time_format = "DFLT%a %b %d, %p
> %I:%M:%S";
>

Why does this start with "DFLT"?


> +static const unsigned int clock_default_interval = 1;
> +
>

There is trailing whitespace after this line.


>  static void
>  panel_add_clock(struct panel *panel)
>  {
> @@ -378,6 +394,8 @@ panel_add_clock(struct panel *panel)
>        clock->panel = panel;
>        panel->clock = clock;
>        clock->clock_fd = timerfd;
> +       clock->time_format = clock_default_time_format;
> +       clock->interval = clock_default_interval;
>
>        clock->clock_task.run = clock_func;
>        display_watch_fd(window_get_display(panel->window), clock->clock_fd,
> @@ -875,6 +893,29 @@ launcher_section_done(void *data)
>  }
>
>  static void
> +clock_section_done(void *data)
> +{
> +       struct desktop *desktop = data;
> +       struct output *output;
> +       struct panel_clock *clock;
> +
> +       char * new_format = malloc ((strlen(key_clock_format) + 2) *
> sizeof(char));
> +       if (new_format == NULL)
> +               return;
> +       sprintf(new_format, "%s", key_clock_format);
> +
> +       wl_list_for_each(output, &desktop->outputs, link) {
> +               clock = output->panel->clock;
> +               clock->time_format = new_format;
> +               if (clock->interval > 0)
> +                       clock->interval = key_clock_interval;
> +       }
> +
> +       free(key_clock_format);
> +       key_clock_format = NULL;
> +}
> +
> +static void
>  add_default_launcher(struct desktop *desktop)
>  {
>        struct output *output;
> --
> 1.7.5.4
>
>
I believe we want the default format to display the clock as it is before
this patch, without seconds. I also noticed the clock is not properly
aligned i.e. it runs off the edge of the output. I imagine we want it
aligned to the right edge of the panel.



Thanks,

Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20120613/cf891779/attachment-0001.html>


More information about the wayland-devel mailing list