-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetwaresmp-xscreensaver-6.08.patch
1769 lines (1761 loc) · 61.1 KB
/
netwaresmp-xscreensaver-6.08.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -Naur xscreensaver-6.08-orig/driver/XScreenSaver.ad.in xscreensaver-6.08/driver/XScreenSaver.ad.in
--- xscreensaver-6.08-orig/driver/XScreenSaver.ad.in 2023-10-10 17:24:06.551773885 -0700
+++ xscreensaver-6.08/driver/XScreenSaver.ad.in 2024-03-13 20:00:35.946625276 -0700
@@ -413,6 +413,7 @@
wander --root \n\
xflame --root \n\
xmatrix --root \n\
+ netwaresmp --root \n\
@GL_KLUDGE@ GL: gflux --root \n\
- nerverot --root \n\
xrayswarm --root \n\
@@ -667,6 +668,7 @@
*hacks.morph3d.name: Morph 3D
*hacks.nerverot.name: Nerve Rot
*hacks.noseguy.name: Nose Guy
+*hacks.netwaresmp.name: Netware SMP
*hacks.pacman.name: Pac-Man
*hacks.papercube.name: Paper Cube
*hacks.photopile.name: Photo Pile
diff -Naur xscreensaver-6.08-orig/hacks/config/netwaresmp.xml xscreensaver-6.08/hacks/config/netwaresmp.xml
--- xscreensaver-6.08-orig/hacks/config/netwaresmp.xml 1969-12-31 16:00:00.000000000 -0800
+++ xscreensaver-6.08/hacks/config/netwaresmp.xml 2024-03-13 20:01:04.374997892 -0700
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<screensaver name="netwaresmp" _label="NetwareSMP">
+
+ <command arg="-root"/>
+
+ <video href="https://www.youtube.com/watch?v=G2Jk-tMz-eU"/>
+
+ <number id="cpus" type="spinbutton" _label="cpus" arg="--cpus %"
+ low="1" high="64" default="1"/>
+
+ <number id="speedup" type="slider" arg="--speedup %"
+ _label="Worm Speedup" _low-label="Slow" _high-label="Fast"
+ low="1" high="16" default="1"/>
+
+ <number id="delay" type="slider" arg="--delay %"
+ _label="System Load Average Delay (ms)" _low-label="Low" _high-label="High"
+ low="10000" high="100000" default="100000"
+ convert="invert"/>
+
+ <number id="wormsize" type="spinbutton" arg="--wormsize %"
+ _label="Wormsize" low="10" high="80" default="30"/>
+
+ <select id="shape" >
+ <option id="squares" _label="Squares Drawing Mode"/>
+ <option id="circles" _label="Circles Drawing Mode" arg-set="--shape 1"/>
+ <option id="snipes" _label="Snipes Drawing Mode" arg-set="--shape 2"/>
+ <option id="triangle" _label="Triangles Drawing Mode" arg-set="--shape 3"/>
+ <option id="classic" _label="Classic Drawing Mode" arg-set="--shape 4"/>
+ <option id="trees" _label="Trees Drawing Mode" arg-set="--shape 5"/>
+ <option id="3dballs" _label="3DBalls Drawing Mode" arg-set="--shape 6"/>
+ </select>
+
+ <boolean id="mono" _label="Mono Color Mode" arg-set="--mono"/>
+ <boolean id="stats" _label="Select Stats Display Popup" arg-set="--stats"/>
+
+ <string id="fg" _label="Foreground color" arg="--fg %" default="#FF0000"/>
+ <string id="bg" _label="Background color" arg="--bg %" default="#000000"/>
+
+
+ <_description>
+Draws a worm for each system cpu that grows longer and faster as the machine
+load increases for a particular processor . A rewrite of the classic Novell
+Netware SMP console screensaver.
+
+Originally written at Novell for NetWare SMP in 1994 by Jeffrey V. Merkey.
+Re-written by Jeffrey Merkey and Cosimo Streppone for xscreensaver based
+on PopSquares, Deco hacks, loadsnake, and the original Netware SMP screensaver; 2024.
+ </_description>
+</screensaver>
diff -Naur xscreensaver-6.08-orig/hacks/Makefile.in xscreensaver-6.08/hacks/Makefile.in
--- xscreensaver-6.08-orig/hacks/Makefile.in 2023-10-10 17:37:05.846255309 -0700
+++ xscreensaver-6.08/hacks/Makefile.in 2024-03-13 20:00:35.948625302 -0700
@@ -111,7 +111,7 @@
demon.c loop.c t3d.c penetrate.c deluxe.c compass.c \
squiral.c xflame.c wander.c spotlight.c critical.c \
phosphor.c xmatrix.c petri.c shadebobs.c xsublim.c ccurve.c \
- blaster.c bumps.c ripples.c xspirograph.c \
+ blaster.c bumps.c ripples.c xspirograph.c netwaresmp.c \
nerverot.c xrayswarm.c hyperball.c zoom.c whirlwindwarp.c \
rotzoomer.c whirlygig.c speedmine.c vermiculate.c \
ximage-loader.c webcollage-helper.c twang.c apollonian.c \
@@ -150,7 +150,7 @@
demon.o loop.o t3d.o penetrate.o deluxe.o compass.o \
squiral.o xflame.o wander.o spotlight.o critical.o \
phosphor.o xmatrix.o petri.o shadebobs.o xsublim.o ccurve.o \
- blaster.o bumps.o ripples.o xspirograph.o \
+ blaster.o bumps.o ripples.o xspirograph.o netwaresmp.o \
nerverot.o xrayswarm.o hyperball.o zoom.o whirlwindwarp.o \
rotzoomer.o whirlygig.o speedmine.o vermiculate.o \
ximage-loader.o webcollage-helper.o twang.o apollonian.o \
@@ -179,7 +179,7 @@
interference truchet bsod crystal discrete distort kumppa \
demon loop penetrate deluxe compass squiral xflame \
wander spotlight phosphor xmatrix petri shadebobs \
- ccurve blaster bumps ripples xspirograph \
+ ccurve blaster bumps ripples xspirograph netwaresmp \
nerverot xrayswarm zoom whirlwindwarp rotzoomer \
speedmine vermiculate twang apollonian euler2d \
polyominoes fluidballs anemone halftone \
@@ -237,7 +237,7 @@
twang.man vermiculate.man vidwhacker.man \
wander.man webcollage.man whirlwindwarp.man \
xflame.man xjack.man xlyap.man xmatrix.man \
- xrayswarm.man xspirograph.man \
+ xrayswarm.man xspirograph.man netwaresmp.man \
zoom.man halftone.man eruption.man metaballs.man \
barcode.man piecewise.man cloudlife.man \
fontglide.man apple2.man xanalogtv.man filmleader.man \
@@ -734,6 +734,9 @@
xmatrix: xmatrix.o $(HACK_OBJS) $(TEXT) $(PNG)
$(CC_HACK) -o $@ $@.o $(HACK_OBJS) $(TEXT) $(PNG) $(PNG_LIBS) $(TEXT_LIBS)
+netwaresmp: netwaresmp.o $(HACK_OBJS) $(TEXT) $(COL)
+ $(CC_HACK) -o $@ $@.o $(HACK_OBJS) $(DBE) $(TEXT) $(COL) $(HACK_LIBS) $(TEXT_LIBS)
+
petri: petri.o $(HACK_OBJS) $(COL) $(SPL)
$(CC_HACK) -o $@ $@.o $(HACK_OBJS) $(COL) $(SPL) $(HACK_LIBS)
diff -Naur xscreensaver-6.08-orig/hacks/netwaresmp.c xscreensaver-6.08/hacks/netwaresmp.c
--- xscreensaver-6.08-orig/hacks/netwaresmp.c 1969-12-31 16:00:00.000000000 -0800
+++ xscreensaver-6.08/hacks/netwaresmp.c 2024-03-13 20:00:51.879834110 -0700
@@ -0,0 +1,1508 @@
+/***************************************************************************
+*
+* Copyright(c) Jeff V. Merkey 1997-2024. All rights reserved.
+*
+* Portions adapted from xscreensaver loadsnake program is
+* portions Copyright (c) 2007-2011 Cosimo Streppone <cosimo@cpan.org>
+* Portions adapted from XScreensaver Copyright (c) 2024 Jamie Zawinski <jwz@jwz.org>
+*
+* Licensed under the MIT/X License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to
+* deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*
+* NetWare SMP style worm XScreensaver for Linux and android
+*
+**************************************************************************/
+
+#include <assert.h>
+#include <math.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <string.h>
+#include <locale.h>
+#include <time.h>
+#include <pty.h>
+#include <sys/resource.h>
+
+#include "screenhack.h"
+#include "colors.h"
+#include "textclient.h"
+#include "xft.h"
+#include "utf8wc.h"
+
+#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
+# include "xdbe.h"
+#endif
+
+#define WORM_MIN_LEN 4
+#define WORM_MAX_LEN 36
+#define WORM_TAIL_LEN 3
+#define MAX_WORMS 64
+
+/* adjust worm total length based on screen area size. smaller
+ displays have shorter worms. the current logic adjusts for
+ worm speedup based on the current max worm length. Here we
+ check a min and max screen area for worm length expansion. */
+
+#define AREA_BASE_LEN (WORM_MAX_LEN / 2)
+#define AREA_MINLINES 19
+#define AREA_MINCOLS 80
+#define AREA_MIN (AREA_MINLINES * AREA_MINCOLS)
+#define AREA_MAXLINES 64
+#define AREA_MAXCOLS 160
+#define AREA_MAX (AREA_MAXLINES * AREA_MAXCOLS)
+#define AREA ((st->COLS * st->LINES) < (AREA_MINLINES * AREA_MINCOLS) \
+ ? (AREA_MINLINES * AREA_MINCOLS) : (st->COLS * st->LINES))
+#define AREA_DIVISOR ((AREA_MAX - AREA_MIN) / AREA_BASE_LEN)
+#define AREA_EXT_LEN (((AREA - (AREA_MIN)) / (AREA_DIVISOR)) > \
+ AREA_BASE_LEN ? AREA_BASE_LEN : \
+ ((AREA - (AREA_MIN)) / (AREA_DIVISOR)))
+
+#define MAX_LOADAVG 100
+#define MAX_MICROSEC 100000
+#define MIN_MICROSEC 10000
+#define COLORSETS 16
+
+#define VERBOSE 0
+#define DEBUG 0
+#define DRAW 0
+#define CLEAR 1
+#define HEAD 1
+#define BODY 0
+
+/* worm drawing shapes */
+#define SQUARES 0
+#define CIRCLES 1
+#define SNIPES 2
+#define TRIANGLES 3
+#define CLASSIC 4
+#define TREES 5
+#define BALLS3D 6
+
+/* worm state structure */
+typedef struct _WORM
+{
+ int cpu;
+ int count;
+ int limit;
+ int x[WORM_MAX_LEN];
+ int y[WORM_MAX_LEN];
+ int d[WORM_MAX_LEN];
+ int x_prev[WORM_MAX_LEN];
+ int y_prev[WORM_MAX_LEN];
+ int d_prev[WORM_MAX_LEN];
+ int length;
+ int length_prev;
+ int direction;
+ int runlength;
+ int windowlength;
+ int color;
+ unsigned long delta;
+} WORM;
+
+/* Netware SMP Xscreesnaver state array */
+typedef struct _STATE
+{
+ Display *dpy;
+ Window window;
+ Visual *visual;
+ Screen *screen;
+ int scr;
+ Colormap cmap;
+ XftDraw *draw;
+ XftColor color;
+ XftFont *xftfont;
+ int hascolor;
+
+ int delay, wormsize, ncolors, dbuf;
+ int cpus;
+ XWindowAttributes xgwa;
+ GC gc;
+ XColor **colors;
+ XColor *black;
+ Pixmap b, ba, bb;
+#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
+ XdbeBackBuffer backb;
+#endif
+ int worm_max_length;
+ int COLS;
+ int LINES;
+ int HEIGHT;
+ int WIDTH;
+ int cpunum;
+ int speedup;
+ int divisor;
+ int prio;
+ int mono;
+ int stats;
+ int shape;
+ char *charset;
+ int sw, sh;
+ unsigned long usr[MAX_WORMS];
+ unsigned long sys[MAX_WORMS];
+ unsigned long nice[MAX_WORMS];
+ unsigned long idle[MAX_WORMS];
+ unsigned long io[MAX_WORMS];
+ unsigned long irq[MAX_WORMS];
+ unsigned long sirq[MAX_WORMS];
+ unsigned long steal[MAX_WORMS];
+ unsigned long guest[MAX_WORMS];
+ unsigned long guest_nice[MAX_WORMS];
+ WORM *worms;
+} STATE;
+
+/* utf8 encoding for \u25C0\u25b6 C89 compliance */
+unsigned char snipes_utf8_1[7] = { 0xE2, 0x97, 0x80, 0xE2, 0x96, 0xB6, 0 };
+/* utf8 encoding for \u229A\u229A C89 compliance */
+unsigned char snipes_utf8_2[7] = { 0xE2, 0x8A, 0x9A, 0xE2, 0x8A, 0x9A, 0 };
+/* utf8 encoding for \u2588\u2588 C89 compliance */
+unsigned char classic_utf8_1[7] = { 0xE2, 0x96, 0x88, 0xE2, 0x96, 0x88, 0 };
+/* utf8 encoding for \u2593\u2593 C89 compliance */
+unsigned char classic_utf8_2[7] = { 0xE2, 0x96, 0x93, 0xE2, 0x96, 0x93, 0 };
+/* utf8 encoding for \u2592\u2592 C89 compliance */
+unsigned char classic_utf8_3[7] = { 0xE2, 0x96, 0x92, 0xE2, 0x96, 0x92, 0 };
+/* utf8 encoding for \u2591\u2591 C89 compliance */
+unsigned char classic_utf8_4[7] = { 0xE2, 0x96, 0x91, 0xE2, 0x96, 0x91, 0 };
+
+static XColor *make_colorset(STATE *st, const int *rgb, const int *rgb_low)
+{
+ int h1, h2 = 0;
+ double s1, v1, s2, v2 = 0;
+ XColor *colset = (XColor *)calloc(st->ncolors, sizeof(XColor));
+
+ /* ramp the colors based on rgb_low array. If rgb_low not specified,
+ then default to the color black as the ramp color to scale to. */
+ if (rgb_low)
+ rgb_to_hsv(rgb_low[0], rgb_low[1], rgb_low[2], &h1, &s1, &v1);
+ else
+ rgb_to_hsv(0, 0, 0, &h1, &s1, &v1);
+
+ /* Finish: foreground, head */
+ rgb_to_hsv(rgb[0], rgb[1], rgb[2], &h2, &s2, &v2);
+
+ make_color_ramp(
+ st->screen, st->visual, st->xgwa.colormap,
+ h1, s1, v1,
+ h2, s2, v2,
+ colset, &st->ncolors,
+ True, True, False
+ );
+ return colset;
+}
+
+static XColor **init_colorsets(STATE *st)
+{
+ int n;
+
+ /* monochrome mode rgb bitmap (white) */
+ int rgbmono[3]= {
+ 0xFFFF, 0xFFFF, 0xFFFF
+ };
+
+ int rgb[COLORSETS][3] = {
+ { 0xFFFF, 0, 0 }, /* red */
+ { 0, 0x7FFF, 0xFFFF }, /* blue */
+ { 0, 0xFFFF, 0 }, /* green */
+ { 0, 0xFFFF, 0xFFFF }, /* cyan */
+
+ { 0xFFFF, 0xFFFF, 0 }, /* yellow */
+ { 0xFFFF, 0xFFFF, 0xFFFF }, /* britewhite */
+ { 0xFFFF, 0, 0xFFFF }, /* magenta */
+ { 0x7FFF, 0x7FFF, 0xFFFF }, /* purple */
+
+ { 0xFFFF, 0x80FF, 0 }, /* orange */
+ { 0x0, 0x99FF, 0x4CFF }, /* olive */
+ { 0x99FF, 0, 0 }, /* burgundy */
+ { 0xFFFF, 0x99FF, 0x99FF }, /* salmon */
+
+ { 0xCCFF, 0xFFFF, 0x99FF }, /* yellowgreen */
+ { 0x99FF, 0xCCFF, 0xFFFF }, /* ltblue */
+ { 0xFFFF, 0x99FF, 0xFFFF }, /* ltmagenta */
+ { 0xB8FF, 0x73FF, 0x33FF }, /* copper */
+ };
+
+ /* ramp scaling to black for certain colors
+ will induce too much green or yellow into
+ the output color ramp array for certain colors.
+ Set a more reasonable target since the
+ color ramp libs with xscreensaver utils
+ don't always handle the color black very
+ well when scaling and add too much green
+ or yellow to the ramp colorsets. */
+
+ int rgb_low[COLORSETS][3] = {
+ { 0x1, 0, 0 }, /* red target */
+ { 0, 0x1, 0x2 }, /* blue target */
+ { 0, 0x1, 0 }, /* green target */
+ { 0, 0x1, 0x1 }, /* cyan target */
+
+ { 0x1, 0x1, 0 }, /* yellow target */
+ { 0, 0, 0 }, /* britewhite targer */
+ { 0x1, 0, 0x1 }, /* magenta target */
+ { 0, 0, 0x7 }, /* purple target */
+
+ { 0x2, 0x1, 0 }, /* orange target */
+ { 0, 0x9, 0x4 }, /* olive target */
+ { 0x1, 0, 0 }, /* burgundy target */
+ { 0x2, 0x1, 0x1 }, /* salmon target */
+
+ { 0x1, 0x1, 0 }, /* yellowgreen target */
+ { 0x1, 0x2, 0x2 }, /* ltblue target */
+ { 0x2, 0x1, 0x2 }, /* ltmagenta target */
+ { 0, 0, 0 }, /* copper target */
+ };
+
+ int rgb_low_snipes[COLORSETS][3] = {
+ { 0x7FFF, 0, 0 }, /* red target */
+ { 0, 0x1, 0x2 }, /* blue target */
+ { 0, 0x1, 0 }, /* green target */
+ { 0, 0x1, 0x1 }, /* cyan target */
+
+ { 0x1, 0x1, 0 }, /* yellow target */
+ { 0, 0, 0 }, /* britewhite targer */
+ { 0x1, 0, 0x1 }, /* magenta target */
+ { 0, 0, 0x7 }, /* purple target */
+
+ { 0x2, 0x1, 0 }, /* orange target */
+ { 0, 0x9, 0x4 }, /* olive target */
+ { 0x7FFF, 0, 0 }, /* burgundy target */
+ { 0x2, 0x1, 0x1 }, /* salmon target */
+
+ { 0x1, 0x1, 0 }, /* yellowgreen target */
+ { 0x1, 0x2, 0x2 }, /* ltblue target */
+ { 0x2, 0x1, 0x2 }, /* ltmagenta target */
+ { 0, 0, 0 }, /* copper target */
+ };
+
+ XColor** colset = (XColor **)calloc(COLORSETS, sizeof(XColor *));
+
+ if (st->mono) {
+ for (n = 0; n < COLORSETS; n++)
+ colset[n] = make_colorset(st, rgbmono, NULL);
+ }
+ else {
+ for (n = 0; n < COLORSETS; n++) {
+ if (st->shape == SNIPES)
+ colset[n] = make_colorset(st, rgb[n], rgb_low_snipes[n]);
+ else
+ colset[n] = make_colorset(st, rgb[n], rgb_low[n]);
+ }
+ }
+ return colset;
+}
+
+static void xcolor_to_xftcolor(STATE *st, XColor *xcolor, unsigned short alpha)
+{
+ st->color.color.red = xcolor->red;
+ st->color.color.green = xcolor->green;
+ st->color.color.blue = xcolor->blue;
+ st->color.color.alpha = alpha;
+ st->color.pixel = 0xFFFFFF00;
+}
+
+static void set_xftcolor(STATE *st, unsigned long tcolor, unsigned short alpha)
+{
+ st->color.color.red = ((tcolor & 0xFF0000) >> 16 ) * 0x101;
+ st->color.color.green = ((tcolor & 0x00FF00) >> 8 ) * 0x101;
+ st->color.color.blue = ((tcolor & 0x0000FF) ) * 0x101;
+ st->color.color.alpha = alpha;
+ st->color.pixel = 0xFFFFFF00;
+}
+
+static int XLoadFonts(STATE *st)
+{
+#if DEBUG
+ char **names = NULL, **names2 = NULL;
+ int count = 0, count2 = 0;
+ XFontStruct *info = 0;
+#endif
+
+ char pattern[1024];
+ const char *fontname =
+ "DejaVu Sans Mono:pixelsize=%d:antialias=false;style=bold;";
+
+#if DEBUG
+ sprintf (pattern, "-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s",
+ "*", /* foundry */
+ "*", /* family */
+ "*", /* weight */
+ "*", /* slant */
+ "*", /* swidth */
+ "*", /* adstyle */
+ "0", /* pixel size */
+ "0", /* point size */
+ "0", /* resolution x */
+ "0", /* resolution y */
+ "m", /* spacing */
+ "0", /* avg width */
+ "*"); /* registry + encoding */
+
+ names = XListFonts (st->dpy, pattern, 1000, &count);
+ if (count > 0) {
+#if VERBOSE
+ int i;
+
+ for (i=0; i < count; i++) {
+ printf("%s\n", names[i]);
+ }
+#endif
+ names2 = XListFontsWithInfo (st->dpy, names[0], 1000, &count2, &info);
+ if (count2 > 0)
+ XFreeFontInfo(names2, info, count2);
+ XFreeFontNames(names);
+ }
+#endif
+
+ if (st->shape == CLASSIC)
+ sprintf(pattern, fontname, st->wormsize - 4);
+ else
+ sprintf(pattern, fontname, st->wormsize);
+#if VERBOSE
+ fprintf (stderr, "%s: xft pattern %s\n", progname, pattern);
+#endif
+
+ st->scr = DefaultScreen(st->dpy);
+ st->cmap = DefaultColormap(st->dpy, st->scr);
+
+ st->xftfont = XftFontOpenName(st->dpy, st->scr, pattern);
+ if (!st->xftfont) {
+ fprintf (stderr, "%s: could not load base font %s\n",
+ progname, fontname);
+ return 1;
+ }
+
+ if (!(st->hascolor = XftColorAllocName(st->dpy, st->visual, st->cmap,
+ "white", &st->color))) {
+ fprintf (stderr, "%s: cannot allocate xft color\n", progname);
+ return 1;
+ }
+
+ st->draw = XftDrawCreate(st->dpy, st->window, st->visual, st->cmap);
+ if (!st->draw) {
+ fprintf (stderr, "%s: cannot allocate XftDraw\n", progname);
+ return 1;
+ }
+
+ /* reset height, width, lines, and columns based on font metrics */
+ st->HEIGHT = ((st->xftfont->height + 1) * 2) / 2;
+ st->WIDTH = st->HEIGHT / 2;
+
+ XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
+ st->LINES = st->xgwa.height / st->HEIGHT;
+ st->COLS = st->xgwa.width / st->WIDTH;
+
+ return 0;
+}
+
+static void Trees(STATE *st, WORM *s, int x, int y, int direction, int c,
+ unsigned long pixel, int head)
+{
+ XPoint points1[3], points2[3], points3[3];
+ double th;
+ int radius, radius2, d, factor;
+ double tick = ((M_PI * 2) / 18) * 2;
+
+ radius = st->wormsize;
+ radius2 = radius - (radius / 8) * 3;
+
+ switch (direction) {
+ default: return;
+ case 0: d = 90; break;
+ case 1: d = 90; break;
+ case 2: d = 90; break;
+ case 3: d = 90; break;
+ case 4: d = 90; break;
+ case 5: d = 90; break;
+ case 6: d = 90; break;
+ case 7: d = 90; break;
+ }
+
+ th = M_PI * 2 * (d % 360) / 360;
+
+ factor = 3;
+ points1[0].x = x + radius * cos(th);
+ points1[0].y = y + -(radius * sin(th));
+ points1[1].x = x + radius2 * cos(th - (tick * factor));
+ points1[1].y = y + -(radius2 * sin(th - (tick * factor)));
+ points1[2].x = x + radius2 * cos(th + (tick * factor));
+ points1[2].y = y + -(radius2 * sin(th + (tick * factor)));
+
+ factor = 2;
+ points2[0].x = x + radius * cos(th);
+ points2[0].y = factor + y + -(radius * sin(th));
+ points2[1].x = x + radius2 * cos(th - (tick * factor));
+ points2[1].y = factor + y + -(radius2 * sin(th - (tick * factor)));
+ points2[2].x = x + radius2 * cos(th + (tick * factor));
+ points2[2].y = factor + y + -(radius2 * sin(th + (tick * factor)));
+
+ factor = 1;
+ points3[0].x = x + radius * cos(th);
+ points3[0].y = factor + y + -(radius * sin(th));
+ points3[1].x = x + radius2 * cos(th - (tick * factor));
+ points3[1].y = factor + y + -(radius2 * sin(th - (tick * factor)));
+ points3[2].x = x + radius2 * cos(th + (tick * factor));
+ points3[2].y = factor + y + -(radius2 * sin(th + (tick * factor)));
+
+ XSetLineAttributes(st->dpy, st->gc, 1, LineSolid, CapRound, JoinRound);
+
+ XSetForeground(st->dpy, st->gc, pixel);
+ XFillPolygon (st->dpy, st->b, st->gc, points1, 3, Convex, CoordModeOrigin);
+ XSetForeground(st->dpy, st->gc, st->black[0].pixel);
+ XDrawLines(st->dpy, st->b, st->gc, points1, 3, CoordModeOrigin);
+
+ XSetForeground(st->dpy, st->gc, pixel);
+ XFillPolygon (st->dpy, st->b, st->gc, points2, 3, Convex, CoordModeOrigin);
+ XSetForeground(st->dpy, st->gc, st->black[0].pixel);
+ XDrawLines(st->dpy, st->b, st->gc, points2, 3, CoordModeOrigin);
+
+ XSetForeground(st->dpy, st->gc, pixel);
+ XFillPolygon (st->dpy, st->b, st->gc, points3, 3, Convex, CoordModeOrigin);
+ XSetForeground(st->dpy, st->gc, st->black[0].pixel);
+ XDrawLines(st->dpy, st->b, st->gc, points3, 3, CoordModeOrigin);
+
+ XSetForeground(st->dpy, st->gc, pixel);
+ XSetLineAttributes(st->dpy, st->gc, 8, LineSolid, CapRound, JoinRound);
+ XDrawLine (st->dpy, st->b, st->gc,
+ (int) (x + radius2 * cos(th)),
+ (int) (y + -radius2 * sin(th)),
+ (int) (x + -radius * cos(th)),
+ (int) (y + radius * sin(th)));
+}
+
+static void Triangle(STATE *st, int x, int y, int direction, int c)
+{
+ XPoint points[3];
+ int npoints = 3;
+ int shape = Convex;
+ int mode = CoordModeOrigin;
+ int radius, d = -1;
+
+ switch (c) {
+ default:
+ case 0: radius = (st->WIDTH * 7) / 8; break;
+ case 1: radius = (st->WIDTH * 6) / 8; break;
+ case 2: radius = (st->WIDTH * 5) / 8; break;
+ case 3: radius = (st->WIDTH * 4) / 8; break;
+ }
+
+ /* 0=down, 1=down-right 2=right, 3=up-right */
+ /* 4=up, 5=up-left 6=left 7-down-left */
+ switch (direction) {
+ default: return;
+ case 0: d = 270; break;
+ case 1: d = 300; break;
+ case 2: d = 0; break;
+ case 3: d = 60; break;
+ case 4: d = 90; break;
+ case 5: d = 120; break;
+ case 6: d = 180; break;
+ case 7: d = 240; break;
+ }
+
+ /* convert from unit circle x,y coordinates to screen x,y coordinates by
+ * making y equal to abs -|r * sin(M_PI * 2 * degrees / 360)|. */
+ points[0].x = (short) x + (radius * cos(M_PI * 2 * (d % 360 ) / 360));
+ points[0].y = (short) y + -(radius * sin(M_PI * 2 * (d % 360 ) / 360));
+ points[1].x = (short) x + (radius * cos(M_PI * 2 * ((d + 120) % 360) / 360));
+ points[1].y = (short) y + -(radius * sin(M_PI * 2 * ((d + 120) % 360) / 360));
+ points[2].x = (short) x + (radius * cos(M_PI * 2 * ((d + 240) % 360) / 360));
+ points[2].y = (short) y + -(radius * sin(M_PI * 2 * ((d + 240) % 360) / 360));
+ XFillPolygon(st->dpy, st->b, st->gc, points, npoints, shape, mode);
+
+}
+
+static void worm_write(STATE *st, int c, long row, long col, WORM *s,
+ int clear, int direction, int head)
+{
+ int which;
+ XColor *worm_colset;
+ XGlyphInfo extents1, extents2, extents3, extents4, extents5;
+#if VERBOSE
+ printf("Xfill(%d) direction %d col: %ld row: %ld COLS: %d LINES: %d\n",
+ s->cpu, direction, col, row, st->COLS, st->LINES);
+#endif
+
+ if (!clear) {
+ if (col >= st->COLS)
+ return;
+ if (row >= st->LINES)
+ return;
+ }
+
+ /* set defaults */
+ if (!st->black || !st->colors) {
+ fprintf (stderr, "%s: basic colorsets not initialized\n", progname);
+ return;
+ }
+
+ worm_colset = st->colors[s->color];
+ if (!worm_colset) {
+ fprintf (stderr, "%s: worm colorsets not initialized\n", progname);
+ return;
+ }
+ which = st->ncolors >> 1;
+
+ if (clear) {
+ /* clear previous block */
+ XSetForeground(st->dpy, st->gc, st->black[0].pixel);
+ }
+ else {
+ switch (c)
+ {
+ /* head block */
+ case 0:
+ default:
+ which = st->ncolors >> 1;
+ break;
+ /* dark shade block */
+ case 1:
+ which = (st->ncolors >> 1) + 2;
+ break;
+ /* medium shade block */
+ case 2:
+ which = (st->ncolors >> 1) + 3;
+ break;
+ /* light shade block */
+ case 3:
+ which = (st->ncolors >> 1) + 4;
+ break;
+ }
+ XSetForeground(st->dpy, st->gc, worm_colset[which].pixel);
+ }
+
+ switch (st->shape) {
+
+ /* from the Novell Netware Snipes Network Game */
+ case SNIPES:
+ if (!st->xftfont || !st->hascolor || !st->draw)
+ break;
+
+ /* if clear then set foreground to black */
+ if (clear)
+ set_xftcolor(st, (unsigned long)0x000000, 0xFFFF);
+ else
+ xcolor_to_xftcolor(st, &worm_colset[which], 0xFFFF);
+
+ XftTextExtentsUtf8(st->dpy, st->xftfont,
+ (FcChar8 *) "^^", 2, &extents1);
+ XftTextExtentsUtf8(st->dpy, st->xftfont,
+ (FcChar8 *) "oo", 2, &extents2);
+ XftTextExtentsUtf8(st->dpy, st->xftfont,
+ /* \u25C0\u25B6 */
+ (FcChar8 *)snipes_utf8_1, 6, &extents3);
+ XftTextExtentsUtf8(st->dpy, st->xftfont,
+ /* \u229a\u229a */
+ (FcChar8 *)snipes_utf8_2, 6, &extents4);
+ XftTextExtentsUtf8(st->dpy, st->xftfont,
+ (FcChar8 *)"<>", 2, &extents5);
+ if (head)
+ {
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH,
+ (row * st->HEIGHT) + extents1.height +
+ extents1.height + (extents1.height / 2),
+ (const FcChar8 *)"^^", 2);
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH,
+ (row * st->HEIGHT) +
+ extents1.height + extents2.height,
+ (const FcChar8 *)"oo", 2);
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH,
+ (row * st->HEIGHT) +
+ extents2.height + extents3.height,
+ (const FcChar8 *)snipes_utf8_1, 6);
+ }
+ else {
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH,
+ (row * st->HEIGHT) + extents1.height +
+ extents4.height - (extents1.height / 2),
+ (const FcChar8 *)snipes_utf8_2, 6);
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH,
+ (row * st->HEIGHT) +
+ extents1.height + extents4.height +
+ extents5.height - (extents1.height / 2),
+ (const FcChar8 *)"<>", 2);
+ }
+ break;
+
+ /* NetWare SMP classic screensaver */
+ case CLASSIC:
+ if (!st->xftfont || !st->hascolor || !st->draw)
+ break;
+
+ XftTextExtentsUtf8(st->dpy, st->xftfont,
+ (FcChar8 *)classic_utf8_1, 6, &extents1);
+ XftTextExtentsUtf8(st->dpy, st->xftfont,
+ (FcChar8 *)classic_utf8_2, 6, &extents2);
+ XftTextExtentsUtf8(st->dpy, st->xftfont,
+ (FcChar8 *)classic_utf8_3, 6, &extents3);
+ XftTextExtentsUtf8(st->dpy, st->xftfont,
+ (FcChar8 *)classic_utf8_4, 6, &extents4);
+
+ /* if clear then set foreground to black */
+ if (clear) {
+ set_xftcolor(st, (unsigned long)0x000000, 0xFFFF);
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH, (row * st->HEIGHT) +
+ extents1.height,
+ (const FcChar8 *)classic_utf8_1, 6);
+ }
+ else {
+ xcolor_to_xftcolor(st, &worm_colset[which], 0xFFFF);
+ switch (c) {
+ case 0:
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH, (row * st->HEIGHT) +
+ extents1.height,
+ (const FcChar8 *)classic_utf8_1, 3);
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH + st->WIDTH,
+ (row * st->HEIGHT) +
+ extents1.height,
+ (const FcChar8 *)classic_utf8_1, 3);
+ break;
+ case 1:
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH, (row * st->HEIGHT) +
+ extents1.height,
+ (const FcChar8 *)classic_utf8_1, 3);
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH + st->WIDTH,
+ (row * st->HEIGHT) +
+ extents1.height,
+ (const FcChar8 *)classic_utf8_1, 3);
+ break;
+ case 2:
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH, (row * st->HEIGHT) +
+ extents1.height,
+ (const FcChar8 *)classic_utf8_1, 3);
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH + st->WIDTH,
+ (row * st->HEIGHT) +
+ extents1.height,
+ (const FcChar8 *)classic_utf8_1, 3);
+ break;
+ case 3:
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH, (row * st->HEIGHT) +
+ extents1.height,
+ (const FcChar8 *)classic_utf8_1, 3);
+ XftDrawStringUtf8(st->draw, &st->color, st->xftfont,
+ col * st->WIDTH + st->WIDTH,
+ (row * st->HEIGHT) +
+ extents1.height,
+ (const FcChar8 *)classic_utf8_1, 3);
+ break;
+ }
+ }
+ break;
+
+ default:
+ case SQUARES:
+ XSetForeground(st->dpy, st->gc, st->black[0].pixel);
+ XDrawRectangle(st->dpy, st->b, st->gc, col * st->WIDTH,
+ row * st->HEIGHT, st->HEIGHT, st->HEIGHT);
+ if (!clear)
+ XSetForeground (st->dpy, st->gc, worm_colset[which].pixel);
+ XFillRectangle(st->dpy, st->b, st->gc, col * st->WIDTH + 1,
+ row * st->HEIGHT + 1, st->HEIGHT - 1, st->HEIGHT - 1);
+ break;
+
+ case BALLS3D:
+ break;
+
+ case CIRCLES:
+ XFillArc(st->dpy, st->b, st->gc, col * st->WIDTH, row * st->HEIGHT,
+ st->HEIGHT, st->HEIGHT, 0, 360 * 64);
+ break;
+
+ case TREES:
+ switch (c)
+ {
+ /* head block */
+ case 0:
+ default:
+ if (head)
+ which = st->ncolors >> 1;
+ else
+ which = (st->ncolors >> 1) + 2;
+ break;
+ /* dark shade block */
+ case 1:
+ which = (st->ncolors >> 1) + 3;
+ break;
+ /* medium shade block */
+ case 2:
+ which = (st->ncolors >> 1) + 4;
+ break;
+ /* light shade block */
+ case 3:
+ which = (st->ncolors >> 1) + 5;
+ break;
+ }
+ if (clear)
+ Trees(st, s, col * st->WIDTH, row * st->HEIGHT, direction, c,
+ st->black[0].pixel, head);
+ else
+ Trees(st, s, col * st->WIDTH, row * st->HEIGHT, direction, c,
+ worm_colset[which].pixel, head);
+ break;
+
+ case TRIANGLES:
+ /* always clear arc in case of stacked frames from direction changes
+ * to preserve worm overwrite order */
+ XSetForeground(st->dpy, st->gc, st->black[0].pixel);
+ XFillArc(st->dpy, st->b, st->gc, col * st->WIDTH, row * st->HEIGHT,
+ st->HEIGHT, st->HEIGHT, 0, 360 * 64);
+
+ if (!clear)
+ XSetForeground(st->dpy, st->gc, worm_colset[which].pixel);
+ XSetLineAttributes(st->dpy, st->gc,
+ (st->HEIGHT / 10) ? (st->HEIGHT / 10) : 1,
+ LineSolid, CapRound, JoinRound);
+ XDrawArc(st->dpy, st->b, st->gc, col * st->WIDTH, row * st->HEIGHT,
+ st->HEIGHT, st->HEIGHT, 0, 360 * 64);
+ Triangle(st, (col * st->WIDTH) + st->WIDTH,
+ (row * st->HEIGHT) + st->HEIGHT / 2, direction, c);
+ break;
+ }
+
+ return;
+}
+
+static int get_processors(void)
+{
+ int cpus = 0;
+
+ cpus = sysconf(_SC_NPROCESSORS_ONLN);
+ if (cpus < 1)
+ cpus = 1;
+ return (cpus);
+}
+
+static int get_cpu_load(STATE *st, int cpu)
+{
+ static char line[1024], *s;
+ unsigned long p_usr = 0, p_nice = 0, p_sys = 0, p_idle = 0;
+ unsigned long load = 0, idle = 0, util = 0;
+ unsigned long p_io = 0, p_irq = 0, p_sirq = 0;
+ unsigned long p_steal = 0, p_guest = 0, p_guest_nice = 0;
+ long len;
+ FILE *f;
+ char src[1024] = "\0";
+
+ if (cpu > st->cpus)
+ return 0;
+
+ if (cpu > MAX_WORMS)
+ return 0;
+
+ /* convert cpu num to ascii text number
+ and null terminate */
+ snprintf(src, 100, "cpu%d", cpu);
+ len = strlen(src);
+
+ if (NULL != (f = fopen("/proc/stat", "r")))
+ {
+ while (!feof(f) && !load)
+ {
+ s = fgets(line, sizeof(line) - 1, f);
+ if (s && !strncasecmp(src, line, len))
+ {
+ p_usr = st->usr[cpu];
+ p_nice = st->nice[cpu];
+ p_sys = st->sys [cpu];
+ p_idle = st->idle[cpu];
+ p_io = st->io[cpu];
+ p_irq = st->irq[cpu];
+ p_sirq = st->sirq[cpu];
+ p_steal = st->steal[cpu];
+ p_guest = st->guest[cpu];
+ p_guest_nice = st->guest_nice[cpu];
+
+ if (sscanf(&line[len + 1],
+ "%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
+ &(st->usr[cpu]), &(st->nice[cpu]),
+ &(st->sys[cpu]), &(st->idle[cpu]),
+ &(st->io[cpu]), &(st->irq[cpu]),
+ &(st->sirq[cpu]), &(st->steal[cpu]),
+ &(st->guest[cpu]), &(st->guest_nice[cpu])) == 10)
+ {
+ /* calculate total cycles */
+ unsigned long user, nice;
+ unsigned long idletime;
+ unsigned long deltaidle;
+ unsigned long systime;
+ unsigned long virtalltime;
+ unsigned long totaltime;
+ unsigned long deltatime;
+
+ /* Guest time is already accounted in usertime */
+ user = st->usr[cpu] - st->guest[cpu];
+ nice = st->nice[cpu] - st->guest_nice[cpu];
+ /* io is added in the total idle time */
+ idletime = st->idle[cpu] + st->io[cpu];
+ systime = st->sys[cpu] + st->irq[cpu] + st->sirq[cpu];
+ virtalltime = st->guest[cpu] + st->guest_nice[cpu];
+ totaltime = user + nice + systime + idletime +
+ st->steal[cpu] + virtalltime;
+
+ /* Guest time is already accounted in usertime */