1 $Id: trayer+dclock.patch 1299 2008-03-17 02:12:14Z mehani $
2 Backport the dclock function into trayer from fbpanel.
4 Olivier Mehani <shtrom@ssji.net>
6 diff -urN trayer-1.0/Makefile trayer+dclock-1.0/Makefile
7 --- trayer-1.0/Makefile 2005-01-14 23:46:19.000000000 +0100
8 +++ trayer+dclock-1.0/Makefile 2007-05-07 10:12:55.000000000 +0200
13 -SRC = panel.c misc.c plugin.c gtkbar.c bg.c
14 +SRC = panel.c misc.c plugin.c gtkbar.c bg.c dclock.c
16 DEP = $(SRC:%.c=%.dep)
18 diff -urN trayer-1.0/dclock.c trayer+dclock-1.0/dclock.c
19 --- trayer-1.0/dclock.c 1970-01-01 01:00:00.000000000 +0100
20 +++ trayer+dclock-1.0/dclock.c 2007-05-07 10:18:04.000000000 +0200
24 +#include <sys/time.h>
25 +#include <sys/types.h>
39 +#define DEFAULT_TIP_FORMAT "%A %x"
40 +#define DEFAULT_CLOCK_FORMAT "%T"
59 +clicked( GtkWidget *widget, gpointer dummy, dclock *dc)
62 + DBG("%s\n", dc->action);
63 + system (dc->action);
70 +clock_update(gpointer data )
72 + char output[64], str[64];
79 + g_assert(data != NULL);
80 + dc = (dclock *)data;
83 + detail = localtime(&now);
84 + strftime(output, sizeof(output), dc->cfmt, detail) ;
85 + g_snprintf(str, 64, "<b>%s</b>", output);
86 + gtk_label_set_markup (GTK_LABEL(dc->clockw), str) ;
88 + if (detail->tm_mday != dc->lastDay) {
89 + dc->lastDay = detail->tm_mday ;
91 + strftime (output, sizeof(output), dc->tfmt, detail) ;
92 + if ((utf8 = g_locale_to_utf8(output, -1, NULL, NULL, NULL))) {
93 + gtk_tooltips_set_tip(dc->tip, dc->main, utf8, NULL) ;
102 +dclock_constructor(plugin *p)
108 + struct tm * detail ;
111 + dc = g_new0(dclock, 1);
112 + g_return_val_if_fail(dc != NULL, 0);
116 + dc->cfmt = dc->tfmt = dc->action = 0;
117 + while (get_line(p->fp, &s) != LINE_BLOCK_END) {
118 + if (s.type == LINE_NONE) {
119 + ERR( "dclock: illegal token %s\n", s.str);
122 + if (s.type == LINE_VAR) {
123 + if (!g_ascii_strcasecmp(s.t[0], "ClockFmt"))
124 + dc->cfmt = g_strdup(s.t[1]);
125 + else if (!g_ascii_strcasecmp(s.t[0], "TooltipFmt"))
126 + dc->tfmt = g_strdup(s.t[1]);
127 + else if (!g_ascii_strcasecmp(s.t[0], "Action"))
128 + dc->action = g_strdup(s.t[1]);
130 + ERR( "dclock: unknown var %s\n", s.t[0]);
134 + ERR( "dclock: illegal in this context %s\n", s.str);
139 + dc->cfmt = g_strdup(DEFAULT_CLOCK_FORMAT);
141 + dc->tfmt = g_strdup(DEFAULT_TIP_FORMAT);
142 + dc->main = gtk_event_box_new();
143 + //gtk_widget_add_events (dc->main, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
144 + //button = gtk_button_new();
145 + //gtk_container_add(GTK_CONTAINER(dc->main), button);
147 + g_signal_connect (G_OBJECT (dc->main), "button_press_event",
148 + G_CALLBACK (clicked), (gpointer) dc);
150 + detail = localtime(&now);
151 + strftime(output, sizeof(output), dc->cfmt, detail) ;
152 + dc->clockw = gtk_label_new(output);
153 + gtk_misc_set_alignment(GTK_MISC(dc->clockw), 0.5, 0.5);
154 + gtk_misc_set_padding(GTK_MISC(dc->clockw), 4, 0);
155 + //gtk_widget_show(dc->clockw);
156 + gtk_container_add(GTK_CONTAINER(dc->main), dc->clockw);
157 + gtk_widget_show_all(dc->main);
158 + dc->tip = gtk_tooltips_new();
159 + dc->timer = g_timeout_add(1000, (GSourceFunc) clock_update, (gpointer)dc);
160 + gtk_container_add(GTK_CONTAINER(p->pwid), dc->main);
166 + g_free(dc->action);
173 +dclock_destructor(plugin *p)
175 + dclock *dc = (dclock *)p->priv;
178 + dc = (dclock *) p->priv;
180 + g_source_remove(dc->timer);
181 + gtk_widget_destroy(dc->main);
184 + g_free(dc->action);
189 +plugin_class dclock_plugin_class = {
194 + name : "Digital Clock",
196 + description : "Display Digital clock and Tooltip",
198 + constructor : dclock_constructor,
199 + destructor : dclock_destructor,
201 diff -urN trayer-1.0/panel.c trayer+dclock-1.0/panel.c
202 --- trayer-1.0/panel.c 2005-02-11 19:27:03.000000000 +0100
203 +++ trayer+dclock-1.0/panel.c 2007-05-07 10:12:55.000000000 +0200
206 static gchar *cfgfile = NULL;
207 static gchar version[] = VERSION;
208 -static gchar *cprofile = "default";
209 +//static gchar *cprofile = "default";
211 int expand=1 , padding=0;
216 p->plugins = g_list_append(p->plugins, plug);
218 + if (!(plug = plugin_load("dclock"))) {
219 + ERR( "trayer: can't load dclock\n" );
224 + plug->expand = expand;
225 + plug->padding = padding;
226 + fprintf(tmpfp, "}\n");
227 + fseek(tmpfp, 0, SEEK_SET);
228 + if (!plugin_start(plug)) {
229 + ERR( "trayer: can't start dclock\n" );
233 + p->plugins = g_list_append(p->plugins, plug);
237 diff -urN trayer-1.0/plugin.c trayer+dclock-1.0/plugin.c
238 --- trayer-1.0/plugin.c 2005-01-12 22:53:40.000000000 +0100
239 +++ trayer+dclock-1.0/plugin.c 2007-05-07 10:12:55.000000000 +0200
244 +#ifdef STATIC_DCLOCK
245 + STATIC_PLUGIN_CLASS(dclock_plugin_class);
249 STATIC_PLUGIN_CLASS(tray_plugin_class);