File clock-24hour.patch of Package xview-64bit
diff -rNu xview-3.2p1.4-old/clients/clock/clock.c xview-3.2p1.4/clients/clock/clock.c
--- xview-3.2p1.4-old/clients/clock/clock.c 2013-08-25 15:07:13.652541193 +0200
+++ xview-3.2p1.4/clients/clock/clock.c 2013-08-25 15:29:16.216560590 +0200
@@ -71,9 +71,13 @@
"56", "57", "58", "59", "60"
};
+/* for 12-hour clock */
static int majorHour[] = {0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1};
static int minorHour[] = {0,1,2,3,4,5,6,7,8,9,0,1,2,1,2,3,4,5,6,7,8,9,0,1};
+/* for 24-hour clock */
+static int majorHour24[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2};
+static int minorHour24[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3};
struct pr_pos partA[4] = { {1,0}, {3,2}, {15,2}, {17,0} };
struct pr_pos partB[4] = { {0,0}, {2,2}, {2,10}, {0,12} };
@@ -173,6 +177,9 @@
Panel_item dateToggle; /* date toggle item */
int date; /* date toggle value */
int dateBAK; /* date toggle temp value */
+ Panel_item use24Toggle; /* 24-hour format toggle item */
+ int use24; /* 24-hour format toggle value */
+ int use24BAK; /* 24-hour format toogle temp value */
} ClockOptions, *Options;
/* Coordinates & measures used to display/resize both clock faces */
@@ -230,8 +237,8 @@
static void icon_repaint(Icon i, Pixwin *pw, Rectlist *area);
static Notify_value icon_timer_expired(Frame me, int which);
static Notify_value analog_timer_expired(Frame me, int which);
-static void paint_dig_seconds(Clock c, struct tm *tm);
-static void dig_repaint(Canvas canvas, Pixwin *pw, Rectlist *area);
+static void paint_dig_seconds(Clock c, struct tm *tm, int use24);
+static void dig_repaint(Canvas canvas, Pixwin *pw, Rectlist *area, int use24);
static Notify_value dig_timer_expired(Frame me, int which, int invalidate);
static Notify_value clock_reset(Panel_item item, Event *event);
static int date_changed(Options o);
@@ -292,6 +299,7 @@
o-> face = analog;
o-> seconds = 0;
o-> date = 0;
+ o-> use24 = 0;
pw = getpwuid (getuid ());
if (pw == NULL) {
fprintf(stderr,"clock: can't find home directory\n");
@@ -302,7 +310,7 @@
strcat(buf, ".clockrc");
fp = fopen(buf, "r");
if (fp == NULL) return;
- n = fscanf(fp, "%x %d %d", &o->face, &o->seconds, &o->date);
+ n = fscanf(fp, "%x %d %d %d", &o->face, &o->seconds, &o->date, &o->use24);
backup_values (o);
fclose(fp);
}
@@ -326,7 +334,7 @@
strcat (buf, ".clockrc");
fp = fopen (buf, "w");
if (fp==NULL) return;
- fprintf (fp, "%d %d %d\n", o->face, o->seconds, o->date);
+ fprintf (fp, "%d %d %d %d\n", o->face, o->seconds, o->date, o->use24);
fclose (fp);
}
@@ -466,7 +474,7 @@
analog_repaint (canvas, pw, area);
break;
case digital:
- dig_repaint (canvas, pw, area);
+ dig_repaint(canvas, pw, area, c->options->use24);
break;
}
return(NOTIFY_DONE);
@@ -1158,8 +1166,8 @@
}
static void
-paint_dig_seconds (c, tm)
- Clock c; struct tm *tm;
+paint_dig_seconds (c, tm, use24)
+ Clock c; struct tm *tm; int use24;
{
int fontHeight, descent, y_coord;
Xv_Font font;
@@ -1184,19 +1192,23 @@
font,
nums[tm-> tm_sec]
);
- pw_text ((Xv_opaque)pw, d-> slots[5],
- (2*fontSize.height) + y_coord + 3, /* 3 = fudge factor */
- PIX_SRC,
- font,
- (tm-> tm_hour < 12) ? "am" : "pm");
+
+ if (!use24) {
+ pw_text ((Xv_opaque)pw, d-> slots[5],
+ (2*fontSize.height) + y_coord + 3, /* 3 = fudge factor */
+ PIX_SRC,
+ font,
+ (tm-> tm_hour < 12) ? "am" : "pm");
+ }
}
static void
-dig_repaint (canvas, pw, area)
+dig_repaint (canvas, pw, area, use24)
Canvas canvas;
Pixwin * pw;
Rectlist *area;
+ int use24;
{
/* Alpha compatibility, mbuck@debian.org */
#if 0
@@ -1218,26 +1230,38 @@
y_coord = ((int) xv_get (canvas, XV_HEIGHT, NULL)-fontHeight)/2;
d->y_coord = y_coord;
- if (tm-> tm_hour == 0)
+ if ((tm-> tm_hour == 0) && !use24)
tm-> tm_hour = 12;
- if (majorHour[tm-> tm_hour] == 1)
+ if((!use24 && (majorHour[tm-> tm_hour] == 1)) ||
+ (use24 && (majorHour24[tm-> tm_hour] == 1))) {
pw_write ((Xv_opaque)pw, d-> slots[0],
y_coord, fontWidth,
fontHeight, PIX_SRC,
d-> images[1],
0, 0);
- else
- pw_write ((Xv_opaque)pw, d-> slots[0],
- y_coord, fontWidth,
- fontHeight, PIX_SRC,
- d-> images[11],
- 0, 0);
-
+ } else if(use24 && (majorHour24[tm-> tm_hour] == 2)) {
+ pw_write((Xv_opaque)pw, d-> slots[0],
+ y_coord, fontWidth,
+ fontHeight, PIX_SRC,
+ d-> images[2],
+ 0, 0);
+ } else {
+ pw_write ((Xv_opaque)pw, d-> slots[0],
+ y_coord, fontWidth,
+ fontHeight, PIX_SRC,
+ d-> images[11],
+ 0, 0);
+ }
+
pw_write ((Xv_opaque)pw, d-> slots[1],
y_coord, fontWidth,
fontHeight, PIX_SRC,
- d-> images[minorHour[tm-> tm_hour]],
+ d-> images[
+ use24 ?
+ minorHour24[tm-> tm_hour] :
+ minorHour[tm-> tm_hour]
+ ],
0, 0);
pw_write ((Xv_opaque)pw, d-> slots[2],
y_coord, fontWidth,
@@ -1252,7 +1276,7 @@
fontHeight, PIX_SRC,
d-> images[tm-> tm_min % 10], 0, 0);
if (seconds_on (c-> options))
- paint_dig_seconds (c, tm);
+ paint_dig_seconds(c, tm, c->options->use24);
}
static Notify_value
@@ -1282,10 +1306,10 @@
if (tm->tm_min != mins || tm-> tm_hour != hours || invalidate) {
mins = tm-> tm_min;
hours = tm-> tm_hour;
- dig_repaint (c->canvas, c->pw, NULL);
+ dig_repaint (c->canvas, c->pw, NULL, c->options->use24);
}
else {
- if (seconds_on (c->options)) paint_dig_seconds (c, tm);
+ if (seconds_on (c->options)) paint_dig_seconds (c, tm, c->options->use24);
}
if (date_on (c-> options))
paint_date (c);
@@ -1302,6 +1326,7 @@
xv_set (o-> faceChoice, PANEL_VALUE, (Attr_attribute)o-> faceBAK, NULL);
xv_set (o-> secondsToggle, PANEL_VALUE, (Attr_attribute)o->secondsBAK, NULL);
xv_set (o-> dateToggle, PANEL_VALUE, (Attr_attribute)o->dateBAK, NULL);
+ xv_set (o-> use24Toggle, PANEL_VALUE, (Attr_attribute)o->use24Toggle, NULL);
}
static int
@@ -1341,6 +1366,7 @@
o-> face = (Face) xv_get (o-> faceChoice, PANEL_VALUE, NULL);
o-> seconds = (int) xv_get (o-> secondsToggle, PANEL_VALUE, NULL);
o-> date = (int) xv_get (o-> dateToggle, PANEL_VALUE, NULL);
+ o-> use24 = (int) xv_get (o-> use24Toggle, PANEL_VALUE, NULL);
writerc(c->options);
if (date_changed(o)) {
@@ -1369,7 +1395,7 @@
pw_write((Xv_opaque)c->pw, d->slots[5], d->y_coord, d->fontWidth,
5000, PIX_CLR, 0, 0, 0);
enable_timer (c->frame, 0, 60-tm->tm_sec, 0, 60);
- dig_repaint(c->canvas, c->pw, NULL);
+ dig_repaint(c->canvas, c->pw, NULL, c->options->use24);
}
break;
case analog:
@@ -1416,6 +1442,8 @@
o->seconds=0;
xv_set(o-> dateToggle, PANEL_VALUE, 0L, NULL);
o->date=0;
+ xv_set(o-> use24Toggle, PANEL_VALUE, 0L, NULL);
+ o->use24 = 0;
writerc(c->options);
clock_repaint_proc(c->canvas, c->pw, NULL);
xv_set(o->frame, XV_SHOW, FALSE, NULL);
@@ -1454,6 +1482,10 @@
XV_X, xv_get (o-> secondsToggle, XV_X, 0) + 80,
XV_Y, xv_row (o-> panel, 2),
NULL);
+ xv_set(o-> use24Toggle,
+ XV_X, xv_get(o-> dateToggle, XV_X, 0) + 59,
+ XV_Y, xv_row(o-> panel, 2),
+ NULL);
xv_set (o-> apply_button,
XV_X, xv_get(o->displayStr, XV_X, 0)+30,
XV_Y, xv_row (o-> panel, 3),
@@ -1581,6 +1613,13 @@
PANEL_VALUE, (Attr_attribute)o->date,
XV_HELP_DATA, "clock:DisplayStyle",
NULL);
+ o-> use24Toggle =
+ (Panel_item) xv_create(o-> panel, PANEL_TOGGLE,
+ PANEL_CHOICE_STRINGS, "24-hour clock", 0,
+ PANEL_VALUE, (Attr_attribute)o->use24,
+ XV_HELP_DATA, "clock:DisplayStyle",
+ NULL);
+
layout_options (o);
window_fit (o-> panel);
window_fit (o-> frame);
@@ -1597,6 +1636,7 @@
o-> faceBAK = o-> face;
o-> secondsBAK = o-> seconds;
o-> dateBAK = o-> date;
+ o-> use24BAK = o-> use24;
}
static void
@@ -1612,6 +1652,7 @@
xv_set (o->faceChoice, PANEL_VALUE, (Attr_attribute)o->face, NULL);
xv_set (o->secondsToggle, PANEL_VALUE, (Attr_attribute)o->seconds, NULL);
xv_set (o->dateToggle, PANEL_VALUE, (Attr_attribute)o->date, NULL);
+ xv_set(o->use24Toggle, PANEL_VALUE, (Attr_attribute)o->use24, NULL);
xv_set (o->frame, FRAME_PROPS_PUSHPIN_IN, TRUE, NULL);
xv_set (o->frame, XV_SHOW, TRUE, NULL);
clock_repaint_proc(c->canvas, c->pw, NULL);
diff -rNu xview-3.2p1.4-old/clients/clock/clock.man xview-3.2p1.4/clients/clock/clock.man
--- xview-3.2p1.4-old/clients/clock/clock.man 2013-08-25 15:07:13.652541193 +0200
+++ xview-3.2p1.4/clients/clock/clock.man 2013-08-25 15:07:55.232541803 +0200
@@ -42,6 +42,11 @@
Turns on a date display for both analog and digital versions of
.B clock.
.RE
+.B 24-hour clock:
+.RS
+Turns on 24-hour clock mode. When you are using analog clock face,
+this option has no effect.
+.RE
.RE
.SH BUGS
If you reset the system time,