updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / trayer+dclock / trayer+dclock.patch
blob6f3dd6af821546cc0b9367df5b7f328cabaa2694
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>
5 ===
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
9 @@ -16,7 +16,7 @@
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
15 OBJ = $(SRC:%.c=%.o)
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
21 @@ -0,0 +1,179 @@
23 +#include <time.h>
24 +#include <sys/time.h>
25 +#include <sys/types.h>
26 +#include <stdio.h>
27 +#include <stdlib.h>
28 +#include <string.h>
31 +#include "panel.h"
32 +#include "misc.h"
33 +#include "plugin.h"
35 +//#define DEBUG
36 +#include "dbg.h"
39 +#define DEFAULT_TIP_FORMAT "%A %x"
40 +#define DEFAULT_CLOCK_FORMAT "%T"
42 +typedef struct {
43 + GtkWidget *eb;
44 + GtkWidget *main;
45 + GtkWidget *clockw;
46 + GtkTooltips *tip;
47 + char *tfmt;
48 + char *cfmt;
49 + char *action;
50 + short lastDay;
51 + int timer;
52 +} dclock;
54 +//static dclock me;
58 +static gboolean
59 +clicked( GtkWidget *widget, gpointer dummy, dclock *dc)
61 + ENTER2;
62 + DBG("%s\n", dc->action);
63 + system (dc->action);
64 + RET2(TRUE);
69 +static gint
70 +clock_update(gpointer data )
72 + char output[64], str[64];
73 + time_t now;
74 + struct tm * detail;
75 + dclock *dc;
76 + gchar *utf8;
78 + ENTER;
79 + g_assert(data != NULL);
80 + dc = (dclock *)data;
82 + time(&now);
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) ;
94 + g_free(utf8);
95 + }
96 + }
97 + RET(TRUE);
101 +static int
102 +dclock_constructor(plugin *p)
104 + line s;
105 + dclock *dc;
106 + char output [40] ;
107 + time_t now ;
108 + struct tm * detail ;
110 + ENTER;
111 + dc = g_new0(dclock, 1);
112 + g_return_val_if_fail(dc != NULL, 0);
113 + p->priv = dc;
115 + s.len = 256;
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);
120 + goto error;
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]);
129 + else {
130 + ERR( "dclock: unknown var %s\n", s.t[0]);
131 + goto error;
133 + } else {
134 + ERR( "dclock: illegal in this context %s\n", s.str);
135 + goto error;
138 + if (!dc->cfmt)
139 + dc->cfmt = g_strdup(DEFAULT_CLOCK_FORMAT);
140 + if (!dc->tfmt)
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);
146 + if (dc->action)
147 + g_signal_connect (G_OBJECT (dc->main), "button_press_event",
148 + G_CALLBACK (clicked), (gpointer) dc);
149 + time(&now);
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);
161 + RET(1);
163 + error:
164 + g_free(dc->cfmt);
165 + g_free(dc->tfmt);
166 + g_free(dc->action);
167 + g_free(dc);
168 + RET(0);
172 +static void
173 +dclock_destructor(plugin *p)
175 + dclock *dc = (dclock *)p->priv;
177 + ENTER;
178 + dc = (dclock *) p->priv;
179 + if (dc->timer)
180 + g_source_remove(dc->timer);
181 + gtk_widget_destroy(dc->main);
182 + g_free(dc->cfmt);
183 + g_free(dc->tfmt);
184 + g_free(dc->action);
185 + g_free(dc);
186 + RET();
189 +plugin_class dclock_plugin_class = {
190 + fname: NULL,
191 + count: 0,
193 + type : "dclock",
194 + name : "Digital Clock",
195 + version: "1.0",
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
204 @@ -20,7 +20,7 @@
206 static gchar *cfgfile = NULL;
207 static gchar version[] = VERSION;
208 -static gchar *cprofile = "default";
209 +//static gchar *cprofile = "default";
210 int distance=0;
211 int expand=1 , padding=0;
213 @@ -515,6 +515,23 @@
215 DBG("systray\n");
216 p->plugins = g_list_append(p->plugins, plug);
218 + if (!(plug = plugin_load("dclock"))) {
219 + ERR( "trayer: can't load dclock\n" );
220 + goto error;
222 + plug->panel = p;
223 + plug->fp = tmpfp;
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" );
230 + goto error;
232 + DBG("dclock\n");
233 + p->plugins = g_list_append(p->plugins, plug);
234 RET(1);
236 error:
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
240 @@ -30,6 +30,10 @@
242 ENTER;
244 +#ifdef STATIC_DCLOCK
245 + STATIC_PLUGIN_CLASS(dclock_plugin_class);
246 +#endif
248 #ifdef STATIC_TRAY
249 STATIC_PLUGIN_CLASS(tray_plugin_class);
250 #endif