-
Notifications
You must be signed in to change notification settings - Fork 6
/
oneko.c
1656 lines (1421 loc) · 52.1 KB
/
oneko.c
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
/*
* oneko - X11 猫
*/
#ifndef lint
static char rcsid[] = "$Header: /home/sun/unix/kato/xsam/oneko/oneko.c,v 1.5 90/10/19 21:25:16 kato Exp $";
#endif
#include "oneko.h"
#include "patchlevel.h"
/*
* グローバル変数
*/
char *ClassName = "Oneko"; /* コマンド名称 */
char *ProgramName; /* コマンド名称 */
Display *theDisplay; /* ディスプレイ構造体 */
int theScreen; /* スクリーン番号 */
unsigned int theDepth; /* デプス */
Window theRoot; /* ルートウィンドウのID */
Window theWindow; /* 猫ウィンドウのID */
char *WindowName = NULL; /* 猫ウィンドウの名前 */
Window theTarget = None; /* 目標ウィンドウのID */
char *TargetName = NULL; /* 目標ウィンドウの名前 */
Cursor theCursor; /* ねずみカーソル */
unsigned int WindowWidth; /* ルートウィンドウの幅 */
unsigned int WindowHeight; /* ルートウィンドウの高さ */
XColor theForegroundColor; /* 色 (フォアグラウンド) */
XColor theBackgroundColor; /* 色 (バックグラウンド) */
int Synchronous = False;
/* Types of animals */
#define BITMAPTYPES 6
typedef struct _AnimalDefaults {
char *name;
int speed, idle, bitmap_width, bitmap_height;
long time;
int off_x, off_y;
char *cursor,*mask;
int cursor_width,cursor_height,cursor_x_hot,cursor_y_hot;
} AnimalDefaultsData;
AnimalDefaultsData AnimalDefaultsDataTable[] =
{
{ "neko", 13, 6, 32, 32, 125000L, 0, 0, mouse_cursor_bits,mouse_cursor_mask_bits,
mouse_cursor_width,mouse_cursor_height, mouse_cursor_x_hot,mouse_cursor_y_hot },
{ "tora", 16, 6, 32, 32, 125000L, 0, 0, mouse_cursor_bits,mouse_cursor_mask_bits,
mouse_cursor_width,mouse_cursor_height, mouse_cursor_x_hot,mouse_cursor_y_hot },
{ "dog" , 10, 6, 32, 32, 125000L, 0, 0, bone_cursor_bits,bone_cursor_mask_bits,
bone_cursor_width,bone_cursor_height, bone_cursor_x_hot,bone_cursor_y_hot },
{ "bsd_daemon" , 16, 6, 32, 32, 300000L, 22, 20, bsd_cursor_bits,bsd_cursor_mask_bits,
bsd_cursor_width,bsd_cursor_height, bsd_cursor_x_hot,bsd_cursor_y_hot },
{ "sakura" , 13, 6, 32, 32, 125000L, 0, 0, card_cursor_bits,card_cursor_mask_bits,
card_cursor_width,card_cursor_height, card_cursor_x_hot,card_cursor_y_hot },
{ "tomoyo" , 10, 6, 32, 32, 125000L, 32, 32, petal_cursor_bits,petal_cursor_mask_bits,
petal_cursor_width,petal_cursor_height, petal_cursor_x_hot,petal_cursor_y_hot },
};
/*
* いろいろな初期設定 (オプション、リソースで変えられるよ)
*/
/* Resource: */
char *Foreground = NULL; /* foreground */
char *Background = NULL; /* background */
long IntervalTime = 0L; /* time */
double NekoSpeed = (double)0; /* speed */
int ScaleFactor = NOTDEFINED; /* scale */
int IdleSpace = 0; /* idle */
int NekoMoyou = NOTDEFINED; /* tora */
int NoShape = NOTDEFINED; /* noshape */
int ReverseVideo = NOTDEFINED; /* reverse */
int ToWindow = NOTDEFINED; /* towindow */
int ToFocus = NOTDEFINED; /* tofocus */
int XOffset=0,YOffset=0; /* X and Y offsets for cat from mouse
pointer. */
/*
* いろいろな状態変数
*/
Bool DontMapped = True;
int NekoTickCount; /* 猫動作カウンタ */
int NekoStateCount; /* 猫同一状態カウンタ */
int NekoState; /* 猫の状態 */
int MouseX; /* マウスX座標 */
int MouseY; /* マウスY座標 */
int PrevMouseX = 0; /* 直前のマウスX座標 */
int PrevMouseY = 0; /* 直前のマウスY座標 */
Window PrevTarget = None; /* 直前の目標ウィンドウのID */
int NekoX; /* 猫X座標 */
int NekoY; /* 猫Y座標 */
int NekoMoveDx; /* 猫移動距離X */
int NekoMoveDy; /* 猫移動距離Y */
int NekoLastX; /* 猫最終描画X座標 */
int NekoLastY; /* 猫最終描画Y座標 */
GC NekoLastGC; /* 猫最終描画 GC */
/* Variables used to set how quickly the program will chose to raise itself. */
/* Look at Interval(), Handle Visiblility Notify Event */
#define DEFAULT_RAISE_WAIT 16 /* About 2 seconds with default interval */
int RaiseWindowDelay=0;
/*
* その他
*/
double SinPiPer8Times3; /* sin(3π/8) */
double SinPiPer8; /* sin(π/8) */
Pixmap Mati2Xbm, Jare2Xbm, Kaki1Xbm, Kaki2Xbm, Mati3Xbm, Sleep1Xbm, Sleep2Xbm;
Pixmap Mati2Msk, Jare2Msk, Kaki1Msk, Kaki2Msk, Mati3Msk, Sleep1Msk, Sleep2Msk;
Pixmap AwakeXbm, AwakeMsk;
Pixmap Up1Xbm, Up2Xbm, Down1Xbm, Down2Xbm, Left1Xbm, Left2Xbm;
Pixmap Up1Msk, Up2Msk, Down1Msk, Down2Msk, Left1Msk, Left2Msk;
Pixmap Right1Xbm, Right2Xbm, UpLeft1Xbm, UpLeft2Xbm, UpRight1Xbm;
Pixmap Right1Msk, Right2Msk, UpLeft1Msk, UpLeft2Msk, UpRight1Msk;
Pixmap UpRight2Xbm, DownLeft1Xbm, DownLeft2Xbm, DownRight1Xbm, DownRight2Xbm;
Pixmap UpRight2Msk, DownLeft1Msk, DownLeft2Msk, DownRight1Msk, DownRight2Msk;
Pixmap UpTogi1Xbm, UpTogi2Xbm, DownTogi1Xbm, DownTogi2Xbm, LeftTogi1Xbm;
Pixmap UpTogi1Msk, UpTogi2Msk, DownTogi1Msk, DownTogi2Msk, LeftTogi1Msk;
Pixmap LeftTogi2Xbm, RightTogi1Xbm, RightTogi2Xbm;
Pixmap LeftTogi2Msk, RightTogi1Msk, RightTogi2Msk;
GC Mati2GC;
GC Jare2GC, Kaki1GC, Kaki2GC, Mati3GC, Sleep1GC, Sleep2GC;
GC AwakeGC;
GC Up1GC, Up2GC, Down1GC, Down2GC, Left1GC, Left2GC, Right1GC, Right2GC;
GC UpLeft1GC, UpLeft2GC, UpRight1GC, UpRight2GC, DownLeft1GC, DownLeft2GC;
GC DownRight1GC, DownRight2GC;
GC UpTogi1GC, UpTogi2GC, DownTogi1GC, DownTogi2GC, LeftTogi1GC;
GC LeftTogi2GC, RightTogi1GC, RightTogi2GC;
typedef struct {
GC *GCCreatePtr;
Pixmap *BitmapCreatePtr;
char *PixelPattern[BITMAPTYPES];
Pixmap *BitmapMasksPtr;
char *MaskPattern[BITMAPTYPES];
} BitmapGCData;
BitmapGCData BitmapGCDataTable[] =
{
{ &Mati2GC, &Mati2Xbm, mati2_bits, mati2_tora_bits, mati2_dog_bits, mati2_bsd_bits, mati2_sakura_bits, mati2_tomoyo_bits,
&Mati2Msk, mati2_mask_bits, mati2_mask_bits, mati2_dog_mask_bits, mati2_bsd_mask_bits, mati2_sakura_mask_bits, mati2_tomoyo_mask_bits },
{ &Jare2GC, &Jare2Xbm, jare2_bits, jare2_tora_bits, jare2_dog_bits, jare2_bsd_bits, jare2_sakura_bits, jare2_tomoyo_bits,
&Jare2Msk, jare2_mask_bits, jare2_mask_bits, jare2_dog_mask_bits, jare2_bsd_mask_bits, jare2_sakura_mask_bits, jare2_tomoyo_mask_bits },
{ &Kaki1GC, &Kaki1Xbm, kaki1_bits, kaki1_tora_bits, kaki1_dog_bits, kaki1_bsd_bits, kaki1_sakura_bits, kaki1_tomoyo_bits,
&Kaki1Msk, kaki1_mask_bits, kaki1_mask_bits, kaki1_dog_mask_bits, kaki1_bsd_mask_bits, kaki1_sakura_mask_bits, kaki1_tomoyo_mask_bits },
{ &Kaki2GC, &Kaki2Xbm, kaki2_bits, kaki2_tora_bits, kaki2_dog_bits, kaki2_bsd_bits, kaki2_sakura_bits, kaki2_tomoyo_bits,
&Kaki2Msk, kaki2_mask_bits, kaki2_mask_bits, kaki2_dog_mask_bits, kaki2_bsd_mask_bits, kaki2_sakura_mask_bits, kaki2_tomoyo_mask_bits },
{ &Mati3GC, &Mati3Xbm, mati3_bits, mati3_tora_bits, mati3_dog_bits, mati3_bsd_bits, mati3_sakura_bits, mati3_tomoyo_bits,
&Mati3Msk, mati3_mask_bits, mati3_mask_bits, mati3_dog_mask_bits, mati3_bsd_mask_bits, mati3_sakura_mask_bits, mati3_tomoyo_mask_bits },
{ &Sleep1GC, &Sleep1Xbm, sleep1_bits, sleep1_tora_bits, sleep1_dog_bits, sleep1_bsd_bits, sleep1_sakura_bits, sleep1_tomoyo_bits,
&Sleep1Msk, sleep1_mask_bits, sleep1_mask_bits, sleep1_dog_mask_bits, sleep1_bsd_mask_bits, sleep1_sakura_mask_bits, sleep1_tomoyo_mask_bits },
{ &Sleep2GC, &Sleep2Xbm, sleep2_bits, sleep2_tora_bits, sleep2_dog_bits, sleep2_bsd_bits, sleep2_sakura_bits, sleep2_tomoyo_bits,
&Sleep2Msk, sleep2_mask_bits, sleep2_mask_bits, sleep2_dog_mask_bits, sleep2_bsd_mask_bits, sleep2_sakura_mask_bits, sleep2_tomoyo_mask_bits },
{ &AwakeGC, &AwakeXbm, awake_bits, awake_tora_bits, awake_dog_bits, awake_bsd_bits, awake_sakura_bits, awake_tomoyo_bits,
&AwakeMsk, awake_mask_bits, awake_mask_bits, awake_dog_mask_bits, awake_bsd_mask_bits, awake_sakura_mask_bits, awake_tomoyo_mask_bits },
{ &Up1GC, &Up1Xbm, up1_bits, up1_tora_bits, up1_dog_bits, up1_bsd_bits, up1_sakura_bits, up1_tomoyo_bits,
&Up1Msk, up1_mask_bits, up1_mask_bits, up1_dog_mask_bits, up1_bsd_mask_bits, up1_sakura_mask_bits, up1_tomoyo_mask_bits },
{ &Up2GC, &Up2Xbm, up2_bits, up2_tora_bits, up2_dog_bits, up2_bsd_bits, up2_sakura_bits, up2_tomoyo_bits,
&Up2Msk, up2_mask_bits, up2_mask_bits, up2_dog_mask_bits, up2_bsd_mask_bits, up2_sakura_mask_bits, up2_tomoyo_mask_bits },
{ &Down1GC, &Down1Xbm, down1_bits, down1_tora_bits, down1_dog_bits, down1_bsd_bits, down1_sakura_bits, down1_tomoyo_bits,
&Down1Msk, down1_mask_bits, down1_mask_bits, down1_dog_mask_bits, down1_bsd_mask_bits, down1_sakura_mask_bits, down1_tomoyo_mask_bits },
{ &Down2GC, &Down2Xbm, down2_bits, down2_tora_bits, down2_dog_bits, down2_bsd_bits, down2_sakura_bits, down2_tomoyo_bits,
&Down2Msk, down2_mask_bits, down2_mask_bits, down2_dog_mask_bits, down2_bsd_mask_bits, down2_sakura_mask_bits, down2_tomoyo_mask_bits },
{ &Left1GC, &Left1Xbm, left1_bits, left1_tora_bits, left1_dog_bits, left1_bsd_bits, left1_sakura_bits, left1_tomoyo_bits,
&Left1Msk, left1_mask_bits, left1_mask_bits, left1_dog_mask_bits, left1_bsd_mask_bits, left1_sakura_mask_bits, left1_tomoyo_mask_bits },
{ &Left2GC, &Left2Xbm, left2_bits, left2_tora_bits, left2_dog_bits, left2_bsd_bits, left2_sakura_bits, left2_tomoyo_bits,
&Left2Msk, left2_mask_bits, left2_mask_bits, left2_dog_mask_bits, left2_bsd_mask_bits, left2_sakura_mask_bits, left2_tomoyo_mask_bits },
{ &Right1GC, &Right1Xbm, right1_bits, right1_tora_bits, right1_dog_bits, right1_bsd_bits, right1_sakura_bits, right1_tomoyo_bits,
&Right1Msk, right1_mask_bits, right1_mask_bits,right1_dog_mask_bits, right1_bsd_mask_bits, right1_sakura_mask_bits, right1_tomoyo_mask_bits },
{ &Right2GC, &Right2Xbm, right2_bits, right2_tora_bits, right2_dog_bits, right2_bsd_bits, right2_sakura_bits, right2_tomoyo_bits,
&Right2Msk, right2_mask_bits, right2_mask_bits, right2_dog_mask_bits, right2_bsd_mask_bits, right2_sakura_mask_bits, right2_tomoyo_mask_bits },
{ &UpLeft1GC, &UpLeft1Xbm, upleft1_bits, upleft1_tora_bits, upleft1_dog_bits, upleft1_bsd_bits, upleft1_sakura_bits, upleft1_tomoyo_bits,
&UpLeft1Msk, upleft1_mask_bits, upleft1_mask_bits, upleft1_dog_mask_bits, upleft1_bsd_mask_bits, upleft1_sakura_mask_bits, upleft1_tomoyo_mask_bits },
{ &UpLeft2GC, &UpLeft2Xbm, upleft2_bits, upleft2_tora_bits, upleft2_dog_bits, upleft2_bsd_bits, upleft2_sakura_bits, upleft2_tomoyo_bits,
&UpLeft2Msk, upleft2_mask_bits, upleft2_mask_bits,upleft2_dog_mask_bits, upleft2_bsd_mask_bits, upleft2_sakura_mask_bits, upleft2_tomoyo_mask_bits },
{ &UpRight1GC, &UpRight1Xbm, upright1_bits, upright1_tora_bits, upright1_dog_bits, upright1_bsd_bits, upright1_sakura_bits, upright1_tomoyo_bits,
&UpRight1Msk, upright1_mask_bits, upright1_mask_bits,upright1_dog_mask_bits, upright1_bsd_mask_bits, upright1_sakura_mask_bits, upright1_tomoyo_mask_bits },
{ &UpRight2GC, &UpRight2Xbm, upright2_bits, upright2_tora_bits, upright2_dog_bits, upright2_bsd_bits, upright2_sakura_bits, upright2_tomoyo_bits,
&UpRight2Msk, upright2_mask_bits, upright2_mask_bits,upright2_dog_mask_bits, upright2_bsd_mask_bits, upright2_sakura_mask_bits, upright2_tomoyo_mask_bits },
{ &DownLeft1GC, &DownLeft1Xbm, dwleft1_bits, dwleft1_tora_bits, dwleft1_dog_bits, dwleft1_bsd_bits, dwleft1_sakura_bits, dwleft1_tomoyo_bits,
&DownLeft1Msk, dwleft1_mask_bits, dwleft1_mask_bits, dwleft1_dog_mask_bits, dwleft1_bsd_mask_bits, dwleft1_sakura_mask_bits, dwleft1_tomoyo_mask_bits },
{ &DownLeft2GC, &DownLeft2Xbm, dwleft2_bits, dwleft2_tora_bits, dwleft2_dog_bits, dwleft2_bsd_bits, dwleft2_sakura_bits, dwleft2_tomoyo_bits,
&DownLeft2Msk, dwleft2_mask_bits, dwleft2_mask_bits, dwleft2_dog_mask_bits, dwleft2_bsd_mask_bits, dwleft2_sakura_mask_bits, dwleft2_tomoyo_mask_bits },
{ &DownRight1GC, &DownRight1Xbm, dwright1_bits, dwright1_tora_bits, dwright1_dog_bits, dwright1_bsd_bits, dwright1_sakura_bits, dwright1_tomoyo_bits,
&DownRight1Msk, dwright1_mask_bits, dwright1_mask_bits, dwright1_dog_mask_bits, dwright1_bsd_mask_bits, dwright1_sakura_mask_bits, dwright1_tomoyo_mask_bits },
{ &DownRight2GC, &DownRight2Xbm, dwright2_bits, dwright2_tora_bits, dwright2_dog_bits, dwright2_bsd_bits, dwright2_sakura_bits, dwright2_tomoyo_bits,
&DownRight2Msk, dwright2_mask_bits, dwright2_mask_bits, dwright2_dog_mask_bits, dwright2_bsd_mask_bits, dwright2_sakura_mask_bits, dwright2_tomoyo_mask_bits },
{ &UpTogi1GC, &UpTogi1Xbm, utogi1_bits, utogi1_tora_bits, utogi1_dog_bits, utogi1_bsd_bits, utogi1_sakura_bits, utogi1_tomoyo_bits,
&UpTogi1Msk, utogi1_mask_bits, utogi1_mask_bits, utogi1_dog_mask_bits, utogi1_bsd_mask_bits, utogi1_sakura_mask_bits, utogi1_tomoyo_mask_bits },
{ &UpTogi2GC, &UpTogi2Xbm, utogi2_bits, utogi2_tora_bits, utogi2_dog_bits, utogi2_bsd_bits, utogi2_sakura_bits, utogi2_tomoyo_bits,
&UpTogi2Msk, utogi2_mask_bits, utogi2_mask_bits, utogi2_dog_mask_bits, utogi2_bsd_mask_bits, utogi2_sakura_mask_bits, utogi2_tomoyo_mask_bits },
{ &DownTogi1GC, &DownTogi1Xbm, dtogi1_bits, dtogi1_tora_bits, dtogi1_dog_bits, dtogi1_bsd_bits, dtogi1_sakura_bits, dtogi1_tomoyo_bits,
&DownTogi1Msk, dtogi1_mask_bits, dtogi1_mask_bits, dtogi1_dog_mask_bits, dtogi1_bsd_mask_bits, dtogi1_sakura_mask_bits, dtogi1_tomoyo_mask_bits },
{ &DownTogi2GC, &DownTogi2Xbm, dtogi2_bits, dtogi2_tora_bits, dtogi2_dog_bits, dtogi2_bsd_bits, dtogi2_sakura_bits, dtogi2_tomoyo_bits,
&DownTogi2Msk, dtogi2_mask_bits, dtogi2_mask_bits, dtogi2_dog_mask_bits, dtogi2_bsd_mask_bits, dtogi2_sakura_mask_bits, dtogi2_tomoyo_mask_bits },
{ &LeftTogi1GC, &LeftTogi1Xbm, ltogi1_bits, ltogi1_tora_bits, ltogi1_dog_bits, ltogi1_bsd_bits, ltogi1_sakura_bits, ltogi1_tomoyo_bits,
&LeftTogi1Msk, ltogi1_mask_bits, ltogi1_mask_bits,ltogi1_dog_mask_bits, ltogi1_bsd_mask_bits, ltogi1_sakura_mask_bits, ltogi1_tomoyo_mask_bits },
{ &LeftTogi2GC, &LeftTogi2Xbm, ltogi2_bits, ltogi2_tora_bits, ltogi2_dog_bits, ltogi2_bsd_bits, ltogi2_sakura_bits, ltogi2_tomoyo_bits,
&LeftTogi2Msk, ltogi2_mask_bits, ltogi2_mask_bits,ltogi2_dog_mask_bits, ltogi2_bsd_mask_bits, ltogi2_sakura_mask_bits, ltogi2_tomoyo_mask_bits },
{ &RightTogi1GC, &RightTogi1Xbm, rtogi1_bits, rtogi1_tora_bits, rtogi1_dog_bits, rtogi1_bsd_bits, rtogi1_sakura_bits, rtogi1_tomoyo_bits,
&RightTogi1Msk, rtogi1_mask_bits, rtogi1_mask_bits,rtogi1_dog_mask_bits, rtogi1_bsd_mask_bits, rtogi1_sakura_mask_bits, rtogi1_tomoyo_mask_bits },
{ &RightTogi2GC, &RightTogi2Xbm, rtogi2_bits, rtogi2_tora_bits, rtogi2_dog_bits, rtogi2_bsd_bits, rtogi2_sakura_bits, rtogi2_tomoyo_bits,
&RightTogi2Msk, rtogi2_mask_bits, rtogi2_mask_bits,rtogi2_dog_mask_bits, rtogi2_bsd_mask_bits, rtogi2_sakura_mask_bits, rtogi2_tomoyo_mask_bits },
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
typedef struct {
GC *TickGCPtr;
Pixmap *TickMaskPtr;
} Animation;
Animation AnimationPattern[][2] =
{
{ { &Mati2GC, &Mati2Msk },
{ &Mati2GC, &Mati2Msk } }, /* NekoState == NEKO_STOP */
{ { &Jare2GC, &Jare2Msk },
{ &Mati2GC, &Mati2Msk } }, /* NekoState == NEKO_JARE */
{ { &Kaki1GC, &Kaki1Msk },
{ &Kaki2GC, &Kaki2Msk } }, /* NekoState == NEKO_KAKI */
{ { &Mati3GC, &Mati3Msk },
{ &Mati3GC, &Mati3Msk } }, /* NekoState == NEKO_AKUBI */
{ { &Sleep1GC, &Sleep1Msk },
{ &Sleep2GC, &Sleep2Msk } }, /* NekoState == NEKO_SLEEP */
{ { &AwakeGC, &AwakeMsk },
{ &AwakeGC, &AwakeMsk } }, /* NekoState == NEKO_AWAKE */
{ { &Up1GC, &Up1Msk },
{ &Up2GC, &Up2Msk } }, /* NekoState == NEKO_U_MOVE */
{ { &Down1GC, &Down1Msk },
{ &Down2GC, &Down2Msk } }, /* NekoState == NEKO_D_MOVE */
{ { &Left1GC, &Left1Msk },
{ &Left2GC, &Left2Msk } }, /* NekoState == NEKO_L_MOVE */
{ { &Right1GC, &Right1Msk },
{ &Right2GC, &Right2Msk } }, /* NekoState == NEKO_R_MOVE */
{ { &UpLeft1GC, &UpLeft1Msk },
{ &UpLeft2GC, &UpLeft2Msk } }, /* NekoState == NEKO_UL_MOVE */
{ { &UpRight1GC, &UpRight1Msk },
{ &UpRight2GC, &UpRight2Msk } }, /* NekoState == NEKO_UR_MOVE */
{ { &DownLeft1GC, &DownLeft1Msk },
{ &DownLeft2GC, &DownLeft2Msk } }, /* NekoState == NEKO_DL_MOVE */
{ { &DownRight1GC, &DownRight1Msk },
{ &DownRight2GC, &DownRight2Msk } }, /* NekoState == NEKO_DR_MOVE */
{ { &UpTogi1GC, &UpTogi1Msk },
{ &UpTogi2GC, &UpTogi2Msk } }, /* NekoState == NEKO_U_TOGI */
{ { &DownTogi1GC, &DownTogi1Msk },
{ &DownTogi2GC, &DownTogi2Msk } }, /* NekoState == NEKO_D_TOGI */
{ { &LeftTogi1GC, &LeftTogi1Msk },
{ &LeftTogi2GC, &LeftTogi2Msk } }, /* NekoState == NEKO_L_TOGI */
{ { &RightTogi1GC, &RightTogi1Msk },
{ &RightTogi2GC, &RightTogi2Msk } }, /* NekoState == NEKO_R_TOGI */
};
static void NullFunction();
/*
* Scales the bitmap, returning a freshly malloc()'d copy which it is the
* caller's responsibility to free.
*/
char*
ScaleBitmap(char* inputBitmap)
{
int scaledBitmapWidth = BITMAP_WIDTH * ScaleFactor;
int scaledBitmapHeight = BITMAP_HEIGHT * ScaleFactor;
int scaledBitmapSize = (scaledBitmapWidth / 8) * scaledBitmapHeight;
char* result = malloc(scaledBitmapSize);
for (int i = 0; i < scaledBitmapSize; i++) {
result[i] = 0x00;
}
for (int srcY = 0; srcY < BITMAP_HEIGHT; srcY++) {
for (int srcX = 0; srcX < BITMAP_WIDTH; srcX++) {
int srcByteOffset = (srcX / 8) + (srcY * BITMAP_WIDTH / 8);
int srcBitOffset = (srcX % 8);
char bit = inputBitmap[srcByteOffset] >> srcBitOffset & 0x01;
if (bit != 0) {
for (int ySub = 0; ySub < ScaleFactor; ySub++) {
int dstY = srcY * ScaleFactor + ySub;
for (int xSub = 0; xSub < ScaleFactor; xSub += 8) {
int dstX = srcX * ScaleFactor + xSub;
int dstByteOffset = (dstX / 8) + (dstY * scaledBitmapWidth / 8);
int dstBitCount = ScaleFactor - xSub;
if (dstBitCount > 8) {
dstBitCount = 8;
}
int dstBitOffset = (dstX % 8);
char dstBitMask = ((1 << dstBitCount) - 1) << dstBitOffset;
result[dstByteOffset] |= dstBitMask;
}
}
}
}
}
return result;
}
/*
* ビットマップデータ・GC 初期化
*/
void
InitBitmapAndGCs()
{
BitmapGCData *BitmapGCDataTablePtr;
XGCValues theGCValues;
theGCValues.function = GXcopy;
theGCValues.foreground = theForegroundColor.pixel;
theGCValues.background = theBackgroundColor.pixel;
theGCValues.fill_style = FillTiled;
theGCValues.ts_x_origin = 0;
theGCValues.ts_y_origin = 0;
for (BitmapGCDataTablePtr = BitmapGCDataTable;
BitmapGCDataTablePtr->GCCreatePtr != NULL;
BitmapGCDataTablePtr++) {
char* scaledPixelPattern =
ScaleBitmap(BitmapGCDataTablePtr->PixelPattern[NekoMoyou]);
*(BitmapGCDataTablePtr->BitmapCreatePtr)
= XCreatePixmapFromBitmapData(theDisplay, theRoot,
scaledPixelPattern,
BITMAP_WIDTH * ScaleFactor, BITMAP_HEIGHT * ScaleFactor,
theForegroundColor.pixel,
theBackgroundColor.pixel,
DefaultDepth(theDisplay, theScreen));
free(scaledPixelPattern);
theGCValues.tile = *(BitmapGCDataTablePtr->BitmapCreatePtr);
char* scaledMaskPattern =
ScaleBitmap(BitmapGCDataTablePtr->MaskPattern[NekoMoyou]);
*(BitmapGCDataTablePtr->BitmapMasksPtr)
= XCreateBitmapFromData(theDisplay, theRoot,
scaledMaskPattern,
BITMAP_WIDTH * ScaleFactor, BITMAP_HEIGHT * ScaleFactor);
free(scaledMaskPattern);
*(BitmapGCDataTablePtr->GCCreatePtr)
= XCreateGC(theDisplay, theWindow,
GCFunction | GCForeground | GCBackground | GCTile |
GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle,
&theGCValues);
}
}
/*
* リソース・データベースから必要なリソースを取り出す
*/
char *
NekoGetDefault(resource)
char *resource;
{
char *value;
if (value = XGetDefault(theDisplay, ProgramName, resource)) {
return value;
}
if (value = XGetDefault(theDisplay, ClassName, resource)) {
return value;
}
return NULL;
}
/*
* リソース・データベースからオプションを設定
*/
GetResources()
{
char *resource;
int num;
int loop;
if (Foreground == NULL) {
if ((resource = NekoGetDefault("foreground")) != NULL) {
Foreground = resource;
}
}
if (Background == NULL) {
if ((resource = NekoGetDefault("background")) != NULL) {
Background = resource;
}
}
if (IntervalTime == 0) {
if ((resource = NekoGetDefault("time")) != NULL) {
if (num = atoi(resource)) {
IntervalTime = num;
}
}
}
if (NekoSpeed == (double)0) {
if ((resource = NekoGetDefault("speed")) != NULL) {
if (num = atoi(resource)) {
NekoSpeed = (double)num;
}
}
}
if (ScaleFactor == NOTDEFINED) {
if ((resource = NekoGetDefault("scale")) != NULL) {
if (num = atoi(resource)) {
ScaleFactor = num;
}
}
}
if (IdleSpace == 0) {
if ((resource = NekoGetDefault("idle")) != NULL) {
if (num = atoi(resource)) {
IdleSpace = num;
}
}
}
if (NekoMoyou == NOTDEFINED) {
for (loop=0;loop<BITMAPTYPES;loop++)
if ((resource = NekoGetDefault(AnimalDefaultsDataTable[loop].name)) != NULL) {
if (IsTrue(resource))
NekoMoyou = loop;
}
}
if (NoShape == NOTDEFINED) {
if ((resource = NekoGetDefault("noshape")) != NULL) {
NoShape = IsTrue(resource);
}
}
if (ReverseVideo == NOTDEFINED) {
if ((resource = NekoGetDefault("reverse")) != NULL) {
ReverseVideo = IsTrue(resource);
}
}
if (Foreground == NULL) {
Foreground = DEFAULT_FOREGROUND;
}
if (Background == NULL) {
Background = DEFAULT_BACKGROUND;
}
if (NekoMoyou == NOTDEFINED) {
NekoMoyou = 0;
}
if (IntervalTime == 0) {
IntervalTime = AnimalDefaultsDataTable[NekoMoyou].time;
}
if (ScaleFactor == NOTDEFINED) {
ScaleFactor = 1;
}
if (NekoSpeed == (double)0) {
NekoSpeed = (double)(AnimalDefaultsDataTable[NekoMoyou].speed)
* ScaleFactor;
}
if (IdleSpace == 0) {
IdleSpace = AnimalDefaultsDataTable[NekoMoyou].idle;
}
XOffset = XOffset + AnimalDefaultsDataTable[NekoMoyou].off_x;
YOffset = YOffset + AnimalDefaultsDataTable[NekoMoyou].off_y;
if (NoShape == NOTDEFINED) {
NoShape = False;
}
if (ReverseVideo == NOTDEFINED) {
ReverseVideo = False;
}
if (ToWindow == NOTDEFINED) {
ToWindow = False;
}
if (ToFocus == NOTDEFINED) {
ToFocus = False;
}
}
/*
* ねずみ型カーソルを作る
*/
MakeMouseCursor()
{
Pixmap theCursorSource;
Pixmap theCursorMask;
theCursorSource
= XCreateBitmapFromData(theDisplay, theRoot,
AnimalDefaultsDataTable[NekoMoyou].cursor,
AnimalDefaultsDataTable[NekoMoyou].cursor_width,
AnimalDefaultsDataTable[NekoMoyou].cursor_height);
theCursorMask
= XCreateBitmapFromData(theDisplay, theRoot,
AnimalDefaultsDataTable[NekoMoyou].mask,
AnimalDefaultsDataTable[NekoMoyou].cursor_width,
AnimalDefaultsDataTable[NekoMoyou].cursor_height);
theCursor = XCreatePixmapCursor(theDisplay, theCursorSource, theCursorMask,
&theBackgroundColor, &theForegroundColor,
AnimalDefaultsDataTable[NekoMoyou].cursor_x_hot,
AnimalDefaultsDataTable[NekoMoyou].cursor_y_hot);
XFreePixmap(theDisplay,theCursorSource);
XFreePixmap(theDisplay,theCursorMask);
}
/*
* 色を初期設定する
*/
SetupColors()
{
XColor theExactColor;
Colormap theColormap;
theColormap = DefaultColormap(theDisplay, theScreen);
if (theDepth == 1) {
Foreground = "black";
Background = "white";
}
if (ReverseVideo == True) {
char *tmp;
tmp = Foreground;
Foreground = Background;
Background = tmp;
}
if (!XAllocNamedColor(theDisplay, theColormap,
Foreground, &theForegroundColor, &theExactColor)) {
fprintf(stderr, "%s: Can't XAllocNamedColor(\"%s\").\n",
ProgramName, Foreground);
exit(1);
}
if (!XAllocNamedColor(theDisplay, theColormap,
Background, &theBackgroundColor, &theExactColor)) {
fprintf(stderr, "%s: Can't XAllocNamedColor(\"%s\").\n",
ProgramName, Background);
exit(1);
}
}
/*
* Routine to let user select a window using the mouse
*
* This routine originate in dsimple.c
*/
Window Select_Window(dpy)
Display *dpy;
{
int status;
Cursor cursor;
XEvent event;
Window target_win = None, root = theRoot;
int buttons = 0;
/* Make the target cursor */
cursor = theCursor;
/* Grab the pointer using target cursor, letting it room all over */
status = XGrabPointer(dpy, root, False,
ButtonPressMask|ButtonReleaseMask, GrabModeSync,
GrabModeAsync, root, cursor, CurrentTime);
if (status != GrabSuccess) {
fprintf(stderr, "%s: Can't grab the mouse.\n", ProgramName);
exit(1);
}
/* Let the user select a window... */
while ((target_win == None) || (buttons != 0)) {
/* allow one more event */
XAllowEvents(dpy, SyncPointer, CurrentTime);
XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event);
switch (event.type) {
case ButtonPress:
if (target_win == None) {
target_win = event.xbutton.subwindow; /* window selected */
if (target_win == None) target_win = root;
}
buttons++;
break;
case ButtonRelease:
if (buttons > 0) /* there may have been some down before we started */
buttons--;
break;
}
}
XUngrabPointer(dpy, CurrentTime); /* Done with pointer */
return(target_win);
}
/*
* Window_With_Name: routine to locate a window with a given name on a display.
* If no window with the given name is found, 0 is returned.
* If more than one window has the given name, the first
* one found will be returned. Only top and its subwindows
* are looked at. Normally, top should be the RootWindow.
*
* This routine originate in dsimple.c
*/
Window Window_With_Name(dpy, top, name)
Display *dpy;
Window top;
char *name;
{
Window *children, dummy;
unsigned int nchildren;
int i;
Window w=0;
char *window_name;
if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
return(top);
if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
return(0);
for (i=0; i<nchildren; i++) {
w = Window_With_Name(dpy, children[i], name);
if (w)
break;
}
if (children) XFree ((char *)children);
return(w);
}
/*
* スクリーン環境初期化
*/
void
InitScreen(DisplayName)
char *DisplayName;
{
XSetWindowAttributes theWindowAttributes;
unsigned long theWindowMask;
Window theTempRoot;
int WindowPointX;
int WindowPointY;
unsigned int BorderWidth;
int event_base, error_base;
if ((theDisplay = XOpenDisplay(DisplayName)) == NULL) {
fprintf(stderr, "%s: Can't open display", ProgramName);
if (DisplayName != NULL) {
fprintf(stderr, " %s.\n", DisplayName);
} else {
fprintf(stderr, ".\n");
}
exit(1);
}
GetResources();
if (Synchronous == True) {
fprintf(stderr,"Synchronizing.\n");
XSynchronize(theDisplay,True);
}
#ifdef SHAPE
if (!NoShape && XShapeQueryExtension(theDisplay,
&event_base, &error_base) == False) {
fprintf(stderr, "Display not suported shape extension.\n");
NoShape = True;
}
#endif SHAPE
theScreen = DefaultScreen(theDisplay);
theDepth = DefaultDepth(theDisplay, theScreen);
theRoot = RootWindow(theDisplay, theScreen);
XGetGeometry(theDisplay, theRoot, &theTempRoot,
&WindowPointX, &WindowPointY,
&WindowWidth, &WindowHeight,
&BorderWidth, &theDepth);
SetupColors();
MakeMouseCursor();
if (ToWindow && theTarget == None) {
if (TargetName != NULL) {
int i;
for (i=0; i<5; i++) {
theTarget = Window_With_Name(theDisplay, theRoot, TargetName);
if (theTarget != None) break;
}
if (theTarget == None) {
fprintf(stderr, "%s: No window with name '%s' exists.\n",
ProgramName, TargetName);
exit(1);
}
} else {
theTarget = Select_Window(theDisplay);
if (theTarget == theRoot) {
theTarget = None;
ToWindow = False;
}
}
if (theTarget != None) {
Window QueryRoot, QueryParent, *QueryChildren;
unsigned int nchild;
for (;;) {
if (XQueryTree(theDisplay, theTarget, &QueryRoot,
&QueryParent, &QueryChildren, &nchild)) {
XFree(QueryChildren);
if (QueryParent == QueryRoot) break;
theTarget = QueryParent;
}
else {
fprintf(stderr, "%s: Target Lost.\n",ProgramName);
exit(1);
}
}
}
}
theWindowAttributes.background_pixel = theBackgroundColor.pixel;
theWindowAttributes.cursor = theCursor;
theWindowAttributes.override_redirect = True;
if (!ToWindow) XChangeWindowAttributes(theDisplay, theRoot, CWCursor,
&theWindowAttributes);
theWindowMask = CWBackPixel |
CWCursor |
CWOverrideRedirect;
theWindow = XCreateWindow(theDisplay, theRoot, 0, 0,
BITMAP_WIDTH * ScaleFactor, BITMAP_HEIGHT * ScaleFactor,
0, theDepth, InputOutput, CopyFromParent,
theWindowMask, &theWindowAttributes);
if (WindowName == NULL) WindowName = ProgramName;
XStoreName(theDisplay, theWindow, WindowName);
InitBitmapAndGCs();
XSelectInput(theDisplay, theWindow,
ExposureMask|VisibilityChangeMask|KeyPressMask);
XFlush(theDisplay);
}
/*
* SIGINT シグナル処理
*/
void
RestoreCursor()
{
XSetWindowAttributes theWindowAttributes;
BitmapGCData *BitmapGCDataTablePtr;
theWindowAttributes.cursor = None;
XChangeWindowAttributes(theDisplay, theRoot, CWCursor,
&theWindowAttributes);
for (BitmapGCDataTablePtr = BitmapGCDataTable;
BitmapGCDataTablePtr->GCCreatePtr != NULL;
BitmapGCDataTablePtr++) {
XFreePixmap(theDisplay,*(BitmapGCDataTablePtr->BitmapCreatePtr));
XFreePixmap(theDisplay,*(BitmapGCDataTablePtr->BitmapMasksPtr));
XFreeGC(theDisplay,*(BitmapGCDataTablePtr->GCCreatePtr));
}
XFreeCursor(theDisplay,theCursor);
XCloseDisplay(theDisplay);
exit(0);
}
/*
* インターバル
*
* この関数を呼ぶと、ある一定の時間返ってこなくなる。猫
* の動作タイミング調整に利用すること。
*/
void
Interval()
{
pause();
if (RaiseWindowDelay>0)
RaiseWindowDelay--;
}
/*
* ティックカウント処理
*/
void
TickCount()
{
if (++NekoTickCount >= MAX_TICK) {
NekoTickCount = 0;
}
if (NekoTickCount % 2 == 0) {
if (NekoStateCount < MAX_TICK) {
NekoStateCount++;
}
}
}
/*
* 猫状態設定
*/
void
SetNekoState(SetValue)
int SetValue;
{
NekoTickCount = 0;
NekoStateCount = 0;
NekoState = SetValue;
}
/*
* 猫描画処理
*/
void
DrawNeko(x, y, DrawAnime)
int x;
int y;
Animation DrawAnime;
{
/*@@@@@@*/
register GC DrawGC = *(DrawAnime.TickGCPtr);
register Pixmap DrawMask = *(DrawAnime.TickMaskPtr);
if ((x != NekoLastX) || (y != NekoLastY)
|| (DrawGC != NekoLastGC)) {
XWindowChanges theChanges;
theChanges.x = x;
theChanges.y = y;
XConfigureWindow(theDisplay, theWindow, CWX | CWY, &theChanges);
#ifdef SHAPE
if (NoShape == False) {
XShapeCombineMask(theDisplay, theWindow, ShapeBounding,
0, 0, DrawMask, ShapeSet);
}
#endif SHAPE
if (DontMapped) {
XMapWindow(theDisplay, theWindow);
DontMapped = 0;
}
XFillRectangle(theDisplay, theWindow, DrawGC,
0, 0,
BITMAP_WIDTH * ScaleFactor,
BITMAP_HEIGHT * ScaleFactor);
}
XFlush(theDisplay);
NekoLastX = x;
NekoLastY = y;
NekoLastGC = DrawGC;
}
/*
* 猫再描画処理
*/
void
RedrawNeko()
{
XFillRectangle(theDisplay, theWindow, NekoLastGC,
0, 0,
BITMAP_WIDTH * ScaleFactor,
BITMAP_HEIGHT * ScaleFactor);
XFlush(theDisplay);
}
/*
* 猫移動方法決定
*
* This sets the direction that the neko is moving.
*
*/
void
NekoDirection()
{
int NewState;
double LargeX, LargeY;
double Length;
double SinTheta;
if (NekoMoveDx == 0 && NekoMoveDy == 0) {
NewState = NEKO_STOP;
} else {
LargeX = (double)NekoMoveDx;
LargeY = (double)(-NekoMoveDy);
Length = sqrt(LargeX * LargeX + LargeY * LargeY);
SinTheta = LargeY / Length;
if (NekoMoveDx > 0) {
if (SinTheta > SinPiPer8Times3) {
NewState = NEKO_U_MOVE;
} else if ((SinTheta <= SinPiPer8Times3)
&& (SinTheta > SinPiPer8)) {
NewState = NEKO_UR_MOVE;
} else if ((SinTheta <= SinPiPer8)
&& (SinTheta > -(SinPiPer8))) {
NewState = NEKO_R_MOVE;
} else if ((SinTheta <= -(SinPiPer8))
&& (SinTheta > -(SinPiPer8Times3))) {
NewState = NEKO_DR_MOVE;
} else {
NewState = NEKO_D_MOVE;
}
} else {
if (SinTheta > SinPiPer8Times3) {
NewState = NEKO_U_MOVE;
} else if ((SinTheta <= SinPiPer8Times3)
&& (SinTheta > SinPiPer8)) {
NewState = NEKO_UL_MOVE;
} else if ((SinTheta <= SinPiPer8)
&& (SinTheta > -(SinPiPer8))) {
NewState = NEKO_L_MOVE;
} else if ((SinTheta <= -(SinPiPer8))
&& (SinTheta > -(SinPiPer8Times3))) {
NewState = NEKO_DL_MOVE;
} else {
NewState = NEKO_D_MOVE;
}
}
}
if (NekoState != NewState) {
SetNekoState(NewState);
}
}
/*
* 猫壁ぶつかり判定
*/
Bool
IsWindowOver()
{
Bool ReturnValue = False;
if (NekoY <= 0) {
NekoY = 0;
ReturnValue = True;
} else if (NekoY >= WindowHeight - BITMAP_HEIGHT * ScaleFactor) {
NekoY = WindowHeight - BITMAP_HEIGHT * ScaleFactor;
ReturnValue = True;
}
if (NekoX <= 0) {
NekoX = 0;
ReturnValue = True;
} else if (NekoX >= WindowWidth - BITMAP_WIDTH * ScaleFactor) {
NekoX = WindowWidth - BITMAP_WIDTH * ScaleFactor;