<div class="gmail_quote">On Tue, Jun 12, 2012 at 6:45 PM, Martin Minarik <span dir="ltr"><<a href="mailto:minarik11@student.fiit.stuba.sk" target="_blank">minarik11@student.fiit.stuba.sk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This allows the user to specify the format of the displayed time.<br>
It is possible to set the period of redraw (in seconds).<br></blockquote><div><br>Hi Martin, thanks for doing this. This seems to work but there are a few things that I noticed. A few comments below.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
clients/desktop-shell.c | 49 +++++++++++++++++++++++++++++++++++++++++++---<br>
1 files changed, 45 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c<br>
index 9a1b502..ff0afcb 100644<br>
--- a/clients/desktop-shell.c<br>
+++ b/clients/desktop-shell.c<br>
@@ -97,6 +97,8 @@ struct panel_clock {<br>
struct panel *panel;<br>
struct task clock_task;<br>
int clock_fd;<br>
+ char *time_format;<br>
+ unsigned int interval;<br>
};<br>
<br>
struct unlock_dialog {<br>
@@ -114,7 +116,10 @@ static uint32_t key_panel_color = 0xaa000000;<br>
static uint32_t key_background_color = 0xff002244;<br>
static char *key_launcher_icon;<br>
static char *key_launcher_path;<br>
+static char *key_clock_format = NULL;<br>
+static unsigned int *key_clock_interval = 0;<br>
static void launcher_section_done(void *data);<br>
+static void clock_section_done(void *data);<br>
static int key_locking = 1;<br>
<br>
static const struct config_key shell_config_keys[] = {<br>
@@ -130,12 +135,20 @@ static const struct config_key launcher_config_keys[] = {<br>
{ "path", CONFIG_KEY_STRING, &key_launcher_path },<br>
};<br>
<br>
+static const struct config_key clock_config_keys[] = {<br>
+ { "format", CONFIG_KEY_STRING, &key_clock_format },<br>
+ { "interval", CONFIG_KEY_UNSIGNED_INTEGER, &key_clock_interval },<br>
+};<br>
+<br>
static const struct config_section config_sections[] = {<br>
{ "shell",<br>
shell_config_keys, ARRAY_LENGTH(shell_config_keys) },<br>
{ "launcher",<br>
launcher_config_keys, ARRAY_LENGTH(launcher_config_keys),<br>
- launcher_section_done }<br>
+ launcher_section_done },<br>
+ { "clock",<br>
+ clock_config_keys, ARRAY_LENGTH(clock_config_keys),<br>
+ clock_section_done }<br>
};<br>
<br>
static void<br>
@@ -319,7 +332,7 @@ panel_clock_redraw_handler(struct widget *widget, void *data)<br>
<br>
time(&rawtime);<br>
timeinfo = localtime(&rawtime);<br>
- strftime(string, sizeof string, "%a %b %d, %I:%M %p", timeinfo);<br>
+ strftime(string, sizeof string, clock->time_format, timeinfo);<br>
<br>
widget_get_allocation(widget, &allocation);<br>
if (allocation.width == 0)<br>
@@ -349,9 +362,9 @@ clock_timer_reset(struct panel_clock *clock)<br>
{<br>
struct itimerspec its;<br>
<br>
- its.it_interval.tv_sec = 60;<br>
+ its.it_interval.tv_sec = clock->interval;<br>
its.it_interval.tv_nsec = 0;<br>
- its.it_value.tv_sec = 60;<br>
+ its.it_value.tv_sec = clock->interval;<br>
its.it_value.tv_nsec = 0;<br>
if (timerfd_settime(clock->clock_fd, 0, &its, NULL) < 0) {<br>
fprintf(stderr, "could not set timerfd\n: %m");<br>
@@ -361,6 +374,9 @@ clock_timer_reset(struct panel_clock *clock)<br>
return 0;<br>
}<br>
<br>
+static const char *clock_default_time_format = "DFLT%a %b %d, %p %I:%M:%S";<br></blockquote><div><br>Why does this start with "DFLT"?<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+static const unsigned int clock_default_interval = 1;<br>
+<br></blockquote><div><br>There is trailing whitespace after this line.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
static void<br>
panel_add_clock(struct panel *panel)<br>
{<br>
@@ -378,6 +394,8 @@ panel_add_clock(struct panel *panel)<br>
clock->panel = panel;<br>
panel->clock = clock;<br>
clock->clock_fd = timerfd;<br>
+ clock->time_format = clock_default_time_format;<br>
+ clock->interval = clock_default_interval;<br>
<br>
clock->clock_task.run = clock_func;<br>
display_watch_fd(window_get_display(panel->window), clock->clock_fd,<br>
@@ -875,6 +893,29 @@ launcher_section_done(void *data)<br>
}<br>
<br>
static void<br>
+clock_section_done(void *data)<br>
+{<br>
+ struct desktop *desktop = data;<br>
+ struct output *output;<br>
+ struct panel_clock *clock;<br>
+<br>
+ char * new_format = malloc ((strlen(key_clock_format) + 2) * sizeof(char));<br>
+ if (new_format == NULL)<br>
+ return;<br>
+ sprintf(new_format, "%s", key_clock_format);<br>
+<br>
+ wl_list_for_each(output, &desktop->outputs, link) {<br>
+ clock = output->panel->clock;<br>
+ clock->time_format = new_format;<br>
+ if (clock->interval > 0)<br>
+ clock->interval = key_clock_interval;<br>
+ }<br>
+<br>
+ free(key_clock_format);<br>
+ key_clock_format = NULL;<br>
+}<br>
+<br>
+static void<br>
add_default_launcher(struct desktop *desktop)<br>
{<br>
struct output *output;<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.5.4<br><br></font></span></blockquote><div><br>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.<br>
<br><br><br>Thanks,<br><br>Scott<br></div></div>