-
Notifications
You must be signed in to change notification settings - Fork 0
/
xvmisc.c
1157 lines (903 loc) · 29.1 KB
/
xvmisc.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
/*
* xvmisc.c - random 'handy' routines used in XV
*
* Contains:
* Window CreateWindow(name, clname, geom, w, h, fg, bg, usesize)
* void CenterString(win, str, x, y)
* void ULineString(win, str, x, y)
* int StringWidth(str)
* void FakeButtonPress(bptr)
* void FakeKeyPress(win, keysym);
* void GenExpose(win, x, y, w, h);
* void RemapKeyCheck(ks, buf, stlen)
* void xvDestroyImage(XImage *);
* void DimRect(win, x, y, w, h, bg);
* void Draw3dRect(win, x,y,w,h, inout, bwidth, hicol, locol);
* void SetCropString()
* void SetSelectionString()
* void Warning()
* void FatalError(str)
* void Quit(int)
* void LoadFishCursors()
* void WaitCursor()
* void SetCursors(int)
* char *BaseName(char *)
* void DrawTempGauge(win, x,y,w,h, percent, fg,bg,hi,lo, str)
* void ProgressMeter(min, max, val, str);
* void xvbcopy(src, dst, length)
* int xvbcmp (s1, s2, length)
* void xvbzero(s, length)
* char *xv_strstr(s1, s2)
* FILE *xv_fopen(str, str)
* void xv_mktemp(str)
* void Timer(milliseconds)
*/
#include "copyright.h"
#define NEEDSTIME
#include "xv.h"
#include "bits/fc_left"
#include "bits/fc_leftm"
#include "bits/fc_left1"
#include "bits/fc_left1m"
#include "bits/fc_mid"
#include "bits/fc_midm"
#include "bits/fc_right1"
#include "bits/fc_right1m"
#include "bits/fc_right"
#include "bits/fc_rightm"
static void set_cursors PARM((Cursor, Cursor));
static Atom atom_DELWIN = 0;
static Atom atom_PROTOCOLS = 0;
/***************************************************/
void StoreDeleteWindowProp (win)
Window win;
{
if (! atom_DELWIN)
atom_DELWIN = XInternAtom (theDisp, "WM_DELETE_WINDOW", FALSE);
/* the following fakes 'XSetWMProtocols(theDisp, win, &atom_DELWIN, 1);' */
if (! atom_PROTOCOLS)
atom_PROTOCOLS = XInternAtom (theDisp, "WM_PROTOCOLS", False);
if (atom_PROTOCOLS == None) return;
XChangeProperty(theDisp, win, atom_PROTOCOLS, XA_ATOM, 32,
PropModeReplace, (unsigned char *) &atom_DELWIN, 1);
}
/***************************************************/
Window CreateWindow(name,clname,geom,defw,defh,fg,bg,usesize)
char *name, *clname, *geom;
int defw,defh,usesize;
unsigned long fg, bg;
{
Window win;
XSetWindowAttributes xswa;
unsigned long xswamask;
XWMHints xwmh;
XSizeHints hints;
int i,x,y,w,h;
XClassHint classh;
/* note: if usesize, w,h are extracted from geom spec, otherwise
defw,defh are used */
x = y = 1;
i = XParseGeometry(geom,&x,&y, (unsigned int *) &w, (unsigned int *) &h);
if ((i&XValue || i&YValue)) hints.flags = USPosition;
else hints.flags = PPosition;
if (!usesize || !(i&WidthValue)) w = defw;
if (!usesize || !(i&HeightValue)) h = defh;
hints.flags |= USSize;
if (i&XValue && i&XNegative) x = dispWIDE - w - abs(x);
if (i&YValue && i&YNegative) y = dispHIGH - h - abs(y);
#define VROOT_TRANS
#ifdef VROOT_TRANS
if (vrootW != rootW) { /* virtual window manager running */
int x1,y1;
Window child;
XTranslateCoordinates(theDisp, rootW, vrootW, x, y, &x1, &y1, &child);
if (DEBUG) fprintf(stderr,"translate: %d,%d -> %d,%d\n",x,y,x1,y1);
x = x1; y = y1;
}
#endif
hints.x = x; hints.y = y;
hints.width = w; hints.height = h;
if (!usesize) {
hints.min_width = w; hints.min_height = h;
hints.max_width = w; hints.max_height = h;
hints.flags |= PMaxSize | PMinSize;
}
xswa.background_pixel = bg;
xswa.border_pixel = fg;
xswa.colormap = theCmap;
xswa.bit_gravity = StaticGravity;
xswamask = CWBackPixel | CWBorderPixel | CWColormap;
if (!usesize) xswamask |= CWBitGravity;
win = XCreateWindow(theDisp, rootW, x, y, (u_int) w, (u_int) h,
(u_int) bwidth, (int) dispDEEP, InputOutput,
theVisual, xswamask, &xswa);
if (!win) return(win); /* leave immediately if couldn't create */
XSetStandardProperties(theDisp, win, name, name, None, NULL, 0, &hints);
xwmh.input = True;
xwmh.flags = InputHint;
if (iconPix) { xwmh.icon_pixmap = iconPix; xwmh.flags |= IconPixmapHint; }
XSetWMHints(theDisp, win, &xwmh);
if (clname && strlen(clname)) {
classh.res_name = "xv";
classh.res_class = clname;
XSetClassHint(theDisp, win, &classh);
StoreDeleteWindowProp(win);
}
return(win);
}
/**************************************************/
void DrawString(win,x,y,str)
Window win;
int x,y;
char *str;
{
XDrawString(theDisp, win, theGC, x, y, str, (int) strlen(str));
}
/**************************************************/
void CenterString(win,x,y,str)
Window win;
int x,y;
char *str;
{
DrawString(win, CENTERX(mfinfo, x, str), CENTERY(mfinfo, y), str);
}
/**************************************************/
void ULineString(win,x,y,str)
Window win;
int x,y;
char *str;
{
DrawString(win, x, y, str);
XDrawLine(theDisp, win, theGC, x, y+DESCENT-1,
x+StringWidth(str), y+DESCENT-1);
}
/**************************************************/
int StringWidth(str)
char *str;
{
return(XTextWidth(mfinfo, str, (int) strlen(str)));
}
/**************************************************/
int CursorKey(ks, shift, dotrans)
KeySym ks;
int shift, dotrans;
{
/* called by the KeyPress/KeyRelease event handler to determine if a
given keypress is a cursor key. More complex than you'd think, since
certain Sun Keyboards generate a variety of odd keycodes, and not all
keyboards *have* all these keys. Note that 'shifted' arrow keys
are not translated to PageUp/Down, since it's up to the particular
case whether that translation should occur */
/* if we don't have the new R5-R6 'XK_KP_*' cursor movement
symbols, make them. */
#ifndef XK_KP_Up
# define XK_KP_Up XK_Up
# define XK_KP_Down XK_Down
# define XK_KP_Left XK_Left
# define XK_KP_Right XK_Right
# define XK_KP_Prior XK_Prior
# define XK_KP_Next XK_Next
# define XK_KP_Home XK_Home
# define XK_KP_End XK_End
#endif
int i = CK_NONE;
if (ks==XK_Up || ks==XK_KP_Up ||
ks==XK_KP_8 || ks==XK_F28) i=CK_UP;
else if (ks==XK_Down || ks==XK_KP_Down ||
ks==XK_KP_2 || ks==XK_F34) i=CK_DOWN;
else if (ks==XK_Left || ks==XK_KP_Left ||
ks==XK_KP_4 || ks==XK_F30) i=CK_LEFT;
else if (ks==XK_Right || ks==XK_KP_Right ||
ks==XK_KP_6 || ks==XK_F32) i=CK_RIGHT;
else if (ks==XK_Prior || ks==XK_KP_Prior ||
ks==XK_KP_9 || ks==XK_F29) i=CK_PAGEUP;
else if (ks==XK_Next || ks==XK_KP_Next ||
ks==XK_KP_3 || ks==XK_F35) i=CK_PAGEDOWN;
else if (ks==XK_Home || ks==XK_KP_Home ||
ks==XK_KP_7 || ks==XK_F27) i=CK_HOME;
else if (ks==XK_End || ks==XK_KP_End ||
ks==XK_KP_1 || ks==XK_F33) i=CK_END;
else i = CK_NONE;
if (dotrans && shift) {
if (i==CK_PAGEUP) i=CK_HOME;
else if (i==CK_PAGEDOWN) i=CK_END;
else if (i==CK_UP) i=CK_PAGEUP;
else if (i==CK_DOWN) i=CK_PAGEDOWN;
}
return i;
}
/***********************************/
void FakeButtonPress(bp)
BUTT *bp;
{
/* called when a button keyboard equivalent has been pressed.
'fakes' a ButtonPress event in the button, which A) makes the button
blink, and B) falls through to ButtonPress command dispatch code */
Window rW, cW;
int x, y, rx, ry;
unsigned int mask;
XButtonEvent ev;
ev.type = ButtonPress;
ev.send_event = True;
ev.display = theDisp;
ev.window = bp->win;
ev.root = rootW;
ev.subwindow = (Window) NULL;
ev.x = bp->x;
ev.y = bp->y;
ev.state = 0;
ev.button = Button1;
XSendEvent(theDisp, bp->win, False, NoEventMask, (XEvent *) &ev);
/* if button1 is pressed, loop until RELEASED to avoid probs in BTTrack */
while (XQueryPointer(theDisp, rootW, &rW,&cW,&rx,&ry,&x,&y,&mask)) {
if (!(mask & Button1Mask)) break; /* button released */
}
}
/************************************************************************/
void FakeKeyPress(win, ksym)
Window win;
KeySym ksym;
{
XKeyEvent ev;
ev.type = KeyPress;
ev.send_event = True;
ev.display = theDisp;
ev.window = win;
ev.root = rootW;
ev.subwindow = (Window) NULL;
ev.time = CurrentTime;
ev.x = ev.y = ev.x_root = ev.y_root = 0;
ev.state = 0;
ev.keycode = XKeysymToKeycode(theDisp, ksym);
ev.same_screen = True;
XSendEvent(theDisp, win, False, NoEventMask, (XEvent *) &ev);
XFlush(theDisp);
}
/***********************************/
void GenExpose(win, x, y, w, h)
Window win;
int x, y;
unsigned int w, h;
{
/* generates an expose event on 'win' of the specified rectangle. Unlike
XClearArea(), it doesn't clear the rectangular region */
XExposeEvent ev;
ev.type = Expose;
ev.send_event = True;
ev.display = theDisp;
ev.window = win;
ev.x = x; ev.y = y; ev.width = w; ev.height = h;
ev.count = 0;
XSendEvent(theDisp, win, False, NoEventMask, (XEvent *) &ev);
}
/***********************************/
void RemapKeyCheck(ks, buf, stlen)
KeySym ks;
char *buf;
int *stlen;
{
/* remap weirdo keysyms into normal key events */
if (ks == 0x1000ff00) { /* map 'Remove' key on DEC keyboards -> ^D */
buf[0] = '\004';
buf[1] = '\0';
*stlen = 1;
}
}
/***********************************/
void xvDestroyImage(image)
XImage *image;
{
/* called in place of XDestroyImage(). Explicitly destroys *BOTH* the
data and the structure. XDestroyImage() doesn't seem to do this on all
systems. Also, can be called with a NULL image pointer */
if (image) {
/* free data by hand, since XDestroyImage is vague about it */
if (image->data) free(image->data);
image->data = NULL;
XDestroyImage(image);
}
}
/***********************************/
void DimRect(win, x, y, w, h, bg)
Window win;
int x, y;
u_int w, h;
u_long bg;
{
/* stipple a rectangular region by drawing 'bg' where there's 1's
in the stipple pattern */
XSetFillStyle (theDisp, theGC, FillStippled);
XSetStipple (theDisp, theGC, dimStip);
XSetForeground(theDisp, theGC, bg);
XFillRectangle(theDisp, win, theGC, x, y, (u_int) w, (u_int) h);
XSetFillStyle (theDisp, theGC, FillSolid);
}
/**************************************************/
void Draw3dRect(win, x,y,w,h, inout, bwidth, hi, lo, bg)
Window win;
int x,y,inout,bwidth;
unsigned int w,h;
unsigned long hi, lo, bg;
{
int i,x1,y1;
x1 = x + (int) w;
y1 = y + (int) h;
if (ctrlColor) {
/* draw top-left */
XSetForeground(theDisp, theGC, (inout==R3D_OUT) ? hi : lo);
for (i=0; i<bwidth; i++) {
XDrawLine(theDisp, win, theGC, x+i, y1-i, x+i, y+i);
XDrawLine(theDisp, win, theGC, x+i, y+i, x1-i, y+i);
}
/* draw bot-right */
XSetForeground(theDisp, theGC, (inout==R3D_OUT) ? lo : hi);
for (i=0; i<bwidth; i++) {
XDrawLine(theDisp, win, theGC, x+i+1, y1-i, x1-i, y1-i);
XDrawLine(theDisp, win, theGC, x1-i, y1-i, x1-i, y+i+1);
}
/* draw diagonals */
XSetForeground(theDisp, theGC, bg);
for (i=0; i<bwidth; i++) {
XDrawPoint(theDisp, win, theGC, x+i, y1-i);
XDrawPoint(theDisp, win, theGC, x1-i, y+i);
}
}
}
/**************************************************/
void SetCropString()
{
/* sets the crop string in the info box to be correct. should
be called whenever 'but[BCROP].active', cXOFF,cYOFF,cWIDE,cHIGH
are changed */
if (cpic != pic)
SetISTR(ISTR_CROP, "%dx%d rectangle starting at %d,%d",
cWIDE, cHIGH, cXOFF, cYOFF);
else SetISTR(ISTR_CROP, "<none>");
}
/**************************************************/
void SetSelectionString()
{
/* sets the Selection string in the info box to be correct. should
be called whenever the selection may have changed */
if (HaveSelection()) {
int x,y,w,h;
GetSelRCoords(&x,&y,&w,&h);
SetISTR(ISTR_SELECT, "%dx%d rectangle starting at %d,%d", w, h, x, y);
}
else SetISTR(ISTR_SELECT, "<none>");
}
/***********************************/
void Warning()
{
char *st;
/* give 'em time to read message */
if (infoUp || ctrlUp || anyBrowUp) sleep(3);
else {
st = GetISTR(ISTR_INFO);
OpenAlert(st);
sleep(3);
CloseAlert();
}
}
/***********************************/
void FatalError (identifier)
char *identifier;
{
fprintf(stderr, "%s: %s\n",cmd, identifier);
Quit(-1);
}
/***********************************/
void Quit(i)
int i;
{
/* called when the program exits. frees everything explictly created
EXCEPT allocated colors. This is used when 'useroot' is in operation,
as we have to keep the alloc'd colors around, but we don't want anything
else to stay */
if (!theDisp) exit(i); /* called before connection opened */
if (useroot && i==0) { /* save the root info */
SaveRootInfo();
/* kill the various windows, since we're in RetainPermanent mode now */
if (dirW) XDestroyWindow(theDisp, dirW);
if (infoW) XDestroyWindow(theDisp, infoW);
if (ctrlW) XDestroyWindow(theDisp, ctrlW);
if (gamW) XDestroyWindow(theDisp, gamW);
KillBrowseWindows();
if (psW) XDestroyWindow(theDisp, psW);
#ifdef HAVE_JPEG
if (jpegW) XDestroyWindow(theDisp, jpegW);
#endif
#ifdef HAVE_TIFF
if (tiffW) XDestroyWindow(theDisp, tiffW);
#endif
#ifdef HAVE_PNG
if (pngW) XDestroyWindow(theDisp, pngW);
#endif
/* if NOT using stdcmap for images, free stdcmap */
if (colorMapMode != CM_STDCMAP) {
int j;
for (j=0; j<stdnfcols; j++)
xvFreeColors(theDisp, theCmap, &stdfreecols[j], 1, 0L);
}
/* free browCmap, if any */
if (browPerfect && browCmap) XFreeColormap(theDisp, browCmap);
XFlush(theDisp);
}
KillPageFiles(pageBaseName, numPages);
if (autoDelete) { /* delete all files listed on command line */
int j; char str[MAXPATHLEN+1];
for (j=0; j<orignumnames; j++) {
if (origlist[j][0] != '/') { /* relative path, prepend 'initdir' */
sprintf(str,"%s/%s", initdir, origlist[j]);
if (unlink(str)) {
fprintf(stderr,"%s: can't delete '%s' - %s\n",
cmd, str, ERRSTR(errno));
}
}
else {
if (unlink(origlist[j])) {
fprintf(stderr,"%s: can't delete '%s' - %s\n",
cmd, origlist[j], ERRSTR(errno));
}
}
}
}
XSync(theDisp, False);
exit(i);
}
static Cursor flcurs, fl1curs, fmcurs, fr1curs, frcurs;
/***********************************/
void LoadFishCursors()
{
#define fc_w 16
#define fc_h 16
Pixmap flpix,flmpix,fmpix,fmmpix,frpix,frmpix;
Pixmap fl1pix, fl1mpix, fr1pix, fr1mpix;
XColor fg, bg;
flcurs = fl1curs = fmcurs = fr1curs = frcurs = (Pixmap) NULL;
flpix = XCreatePixmapFromBitmapData(theDisp, ctrlW, (char *) fc_left_bits,
fc_w, fc_h, 1L, 0L, 1);
flmpix= XCreatePixmapFromBitmapData(theDisp, ctrlW, (char *) fc_leftm_bits,
fc_w, fc_h, 1L, 0L, 1);
fl1pix = XCreatePixmapFromBitmapData(theDisp, ctrlW, (char *) fc_left1_bits,
fc_w, fc_h, 1L, 0L, 1);
fl1mpix= XCreatePixmapFromBitmapData(theDisp, ctrlW, (char *) fc_left1m_bits,
fc_w, fc_h, 1L, 0L, 1);
fmpix = XCreatePixmapFromBitmapData(theDisp, ctrlW, (char *) fc_mid_bits,
fc_w, fc_h, 1L, 0L, 1);
fmmpix= XCreatePixmapFromBitmapData(theDisp, ctrlW, (char *) fc_midm_bits,
fc_w, fc_h, 1L, 0L, 1);
fr1pix = XCreatePixmapFromBitmapData(theDisp, ctrlW, (char *) fc_right1_bits,
fc_w, fc_h, 1L, 0L, 1);
fr1mpix = XCreatePixmapFromBitmapData(theDisp, ctrlW,
(char *) fc_right1m_bits,
fc_w, fc_h, 1L, 0L, 1);
frpix = XCreatePixmapFromBitmapData(theDisp, ctrlW, (char *) fc_right_bits,
fc_w, fc_h, 1L, 0L, 1);
frmpix = XCreatePixmapFromBitmapData(theDisp, ctrlW, (char *) fc_rightm_bits,
fc_w, fc_h, 1L, 0L, 1);
if (!flpix || !flmpix || !fmpix || !fmmpix || !frpix || !frmpix
|| !fl1pix || !fl1mpix || !fr1pix || !fr1mpix) return;
fg.red = fg.green = fg.blue = 0;
bg.red = bg.green = bg.blue = 0xffff;
flcurs = XCreatePixmapCursor(theDisp, flpix, flmpix, &fg, &bg, 8,8);
fl1curs= XCreatePixmapCursor(theDisp, fl1pix,fl1mpix,&fg, &bg, 8,8);
fmcurs = XCreatePixmapCursor(theDisp, fmpix, fmmpix, &fg, &bg, 8,8);
fr1curs= XCreatePixmapCursor(theDisp, fr1pix,fr1mpix,&fg, &bg, 8,8);
frcurs = XCreatePixmapCursor(theDisp, frpix, frmpix, &fg, &bg, 8,8);
if (!flcurs || !fmcurs || !frcurs || !fl1curs || !fr1curs)
{ flcurs = fmcurs = frcurs = (Cursor) NULL; }
}
static int fishno=0;
static int waiting=0;
static time_t lastwaittime;
/***********************************/
void WaitCursor()
{
XWMHints xwmh;
time_t nowT;
if (!waiting) {
time(&lastwaittime);
waiting=1;
xwmh.input = True;
xwmh.icon_pixmap = riconPix;
xwmh.icon_mask = riconmask;
xwmh.flags = (InputHint | IconPixmapHint | IconMaskHint) ;
if (!useroot && mainW) XSetWMHints(theDisp, mainW, &xwmh);
if ( useroot && ctrlW) XSetWMHints(theDisp, ctrlW, &xwmh);
}
else { /* waiting */
time(&nowT);
if (nowT == lastwaittime) return;
lastwaittime = nowT;
}
SetCursors(fishno);
fishno = (fishno+1) % 8;
}
/***********************************/
void SetCursors(n)
int n;
{
Cursor c;
XWMHints xwmh;
c = cross;
/* if n < 0 sets normal cursor in all windows
n = 0..6 cycles through fish cursors */
if (n<0) {
if (waiting) {
waiting=0;
xwmh.input = True;
xwmh.icon_pixmap = iconPix;
xwmh.icon_mask = iconmask;
xwmh.flags = (InputHint | IconPixmapHint | IconMaskHint) ;
if (!useroot && mainW) XSetWMHints(theDisp, mainW, &xwmh);
if ( useroot && ctrlW) XSetWMHints(theDisp, ctrlW, &xwmh);
}
if (showzoomcursor) set_cursors(zoom, arrow);
else set_cursors(arrow, arrow);
fishno = 0;
}
else if (flcurs) { /* was able to load the cursors */
switch (n%8) {
case 0: c = flcurs; break;
case 1: c = fl1curs; break;
case 2: c = fmcurs; break;
case 3: c = fr1curs; break;
case 4: c = frcurs; break;
case 5: c = fr1curs; break;
case 6: c = fmcurs; break;
case 7: c = fl1curs; break;
}
set_cursors(c,c);
}
XFlush(theDisp);
}
static void set_cursors(mainc, otherc)
Cursor mainc, otherc;
{
if (!useroot && mainW) XDefineCursor(theDisp, mainW, mainc);
if (infoW) XDefineCursor(theDisp, infoW, otherc);
if (ctrlW) XDefineCursor(theDisp, ctrlW, otherc);
if (dirW) XDefineCursor(theDisp, dirW, otherc);
if (gamW) XDefineCursor(theDisp, gamW, otherc);
if (psW) XDefineCursor(theDisp, psW, otherc);
SetBrowseCursor(otherc);
SetTextCursor(otherc);
#ifdef HAVE_JPEG
if (jpegW) XDefineCursor(theDisp, jpegW, otherc);
#endif
#ifdef HAVE_TIFF
if (tiffW) XDefineCursor(theDisp, tiffW, otherc);
#endif
#ifdef HAVE_PNG
if (pngW) XDefineCursor(theDisp, pngW, otherc);
#endif
}
/***************************************************/
char *BaseName(fname)
char *fname;
{
char *basname;
/* given a complete path name ('/foo/bar/weenie.gif'), returns just the
'simple' name ('weenie.gif'). Note that it does not make a copy of
the name, so don't be modifying it... */
basname = (char *) rindex(fname, '/');
if (!basname) basname = fname;
else basname++;
return basname;
}
/***************************************************/
void DrawTempGauge(win, x,y,w,h, ratio, fg,bg,hi,lo, str)
Window win;
int x,y,w,h;
double ratio;
u_long fg,bg,hi,lo;
char *str;
{
/* draws a 'temprature'-style horizontal progress meter in the specified
window, at the specified location */
int barwide, maxwide, numchars, tw;
if (!win) return;
numchars = tw = 0;
if (str && str[0] != '\0') {
numchars = (int) strlen(str);
while ( (XTextWidth(mfinfo, str, numchars) > w) && numchars>0) numchars--;
}
if (numchars) tw = XTextWidth(mfinfo, str, numchars);
XSetForeground(theDisp, theGC, fg);
XDrawRectangle(theDisp, win, theGC, x,y, (u_int) w, (u_int) h);
if (ctrlColor) {
Draw3dRect(win, x+1,y+1, (u_int) w-2, (u_int) h-2, R3D_IN, 2, hi, lo, bg);
maxwide = w-4;
barwide = (int) (maxwide * ratio + 0.5);
XSetForeground(theDisp, theGC, fg);
XFillRectangle(theDisp,win,theGC, x+3, y+3, (u_int) barwide, (u_int) h-5);
if (numchars) { /* do string */
if (barwide < maxwide) {
XSetForeground(theDisp, theGC, bg);
XFillRectangle(theDisp, win, theGC, x+3+barwide, y+3,
(u_int) (maxwide-barwide), (u_int) (h-5));
}
XSetFunction(theDisp, theGC, GXinvert);
XSetPlaneMask(theDisp, theGC, fg ^ bg);
XDrawString(theDisp, win, theGC, CENTERX(mfinfo, (x+w/2), str),
CENTERY(mfinfo, (y+h/2)), str, numchars);
XSetFunction(theDisp, theGC, GXcopy);
XSetPlaneMask(theDisp, theGC, AllPlanes);
}
else if (barwide < maxwide) {
XDrawLine(theDisp,win,theGC,x+3+barwide, y+h/2 + 0, x+w-3, y+h/2 + 0);
XSetForeground(theDisp, theGC, lo);
XDrawLine(theDisp,win,theGC,x+3+barwide, y+h/2 + 1, x+w-3, y+h/2 + 1);
XSetForeground(theDisp, theGC, hi);
XDrawLine(theDisp,win,theGC,x+3+barwide, y+h/2 + 2, x+w-3, y+h/2 + 2);
XSetForeground(theDisp, theGC, bg);
XFillRectangle(theDisp, win, theGC, x+3+barwide, y+3,
(u_int) (maxwide-barwide), (u_int) (h/2 - 3));
XFillRectangle(theDisp, win, theGC, x+3+barwide, y+h/2 + 3,
(u_int) (maxwide-barwide),(u_int)((h-3) - (h/2+3)) + 1);
}
}
else {
maxwide = w-1;
barwide = (int) (maxwide * ratio + 0.5);
XSetForeground(theDisp, theGC, fg);
XFillRectangle(theDisp,win,theGC, x+1, y+1, (u_int) barwide, (u_int) h-1);
if (numchars) {
if (barwide < maxwide) {
XSetForeground(theDisp, theGC, bg);
XFillRectangle(theDisp, win, theGC, x+1+barwide, y+1,
(u_int) (maxwide-barwide), (u_int) (h-1));
}
XSetFunction(theDisp, theGC, GXinvert);
XSetPlaneMask(theDisp, theGC, fg ^ bg);
XDrawString(theDisp, win, theGC, CENTERX(mfinfo, (x+w/2), str),
CENTERY(mfinfo, (y+h/2)), str, numchars);
XSetFunction(theDisp, theGC, GXcopy);
XSetPlaneMask(theDisp, theGC, AllPlanes);
}
else if (barwide < maxwide) {
XDrawLine(theDisp, win, theGC, x+1+barwide, y+h/2, x+w-1, y+h/2);
XSetForeground(theDisp, theGC, bg);
XFillRectangle(theDisp, win, theGC, x+1+barwide, y+1,
(u_int) (maxwide-barwide), (u_int) (h/2 - 1));
XFillRectangle(theDisp, win, theGC, x+1+barwide, y+h/2 + 1,
(u_int)(maxwide-barwide),(u_int)(((h-1) - (h/2+1))+1));
}
}
XFlush(theDisp);
}
/***************************************************/
void ProgressMeter(min, max, val, str)
int min, max, val;
char *str;
{
/* called during 'long' operations (algorithms, smoothing, etc.) to
give some indication that the program will ever finish. Draws a
temperature gauge in either mainW (if not useRoot), or ctrlW.
Tries to be clever: only draws gauge if it looks like the operation is
going to take more than a few seconds. Calling with val == max removes
the gauge. */
static int waiting = 0;
static time_t lastTime = 0;
time_t nowTime;
double doneness;
Window win;
int xpos,ypos;
if (useroot) { win=ctrlW; xpos=10; ypos=3; }
else { win=mainW; xpos=5; ypos=5; }
if (!win) return;
if (min >= max) return;
if (val==max && lastTime==0) return; /* already erased meter */
doneness = ((double) (val-min)) / ((double) (max - min));
time(&nowTime);
if (lastTime == 0) { /* first time we're calling for this meter */
lastTime = nowTime;
waiting = 1;
}
else if (waiting) { /* haven't drawn meter yet... */
if ((nowTime - lastTime >= 2) && doneness < .5) waiting = 0;
}
if (!waiting) { /* not waiting (or not waiting any longer) */
if (nowTime == lastTime && val<max) return; /* max one draw per second */
lastTime = nowTime;
DrawTempGauge(win, xpos, ypos, 100,19, doneness,
infofg,infobg,hicol,locol,str);
if (val >= max) { /* remove temp gauge */
XClearArea(theDisp, win, xpos,ypos, 100+1,19+1, True);
lastTime = 0;
}
}
}
/***************************************************/
void XVDeletedFile(fullname)
char *fullname;
{
/* called whenever a file has been deleted. Updates browser & dir windows,
if necessary */
BRDeletedFile(fullname);
DIRDeletedFile(fullname);
}
/***************************************************/
void XVCreatedFile(fullname)
char *fullname;
{
/* called whenever a file has been deleted. Updates browser & dir windows,
if necessary */
BRCreatedFile(fullname);
DIRCreatedFile(fullname);
}
/***************************************************/
void xvbcopy(src, dst, len)
char *src, *dst;
size_t len;
{
/* Modern OS's (Solaris, etc.) frown upon the use of bcopy(),
* and only want you to use memcpy(). However, memcpy() is broken,
* in the sense that it doesn't properly handle overlapped regions
* of memory. This routine does, and also has its arguments in
* the same order as bcopy() did, without using bcopy().
*/
/* determine if the regions overlap
*
* 3 cases: src=dst, src<dst, src>dst
*
* if src=dst, they overlap completely, but nothing needs to be moved
* if src<dst and src+len>dst then they overlap
* if src>dst and src<dst+len then they overlap
*/
if (src==dst || len<=0) return; /* nothin' to do */
if (src<dst && src+len>dst) { /* do a backward copy */
src = src + len - 1;
dst = dst + len - 1;
for ( ; len>0; len--, src--, dst--) *dst = *src;
}
else { /* they either overlap (src>dst) or they don't overlap */
/* do a forward copy */
for ( ; len>0; len--, src++, dst++) *dst = *src;
}
}
/***************************************************/
int xvbcmp (s1, s2, len)
char *s1, *s2;
size_t len;
{
for ( ; len>0; len--, s1++, s2++) {
if (*s1 < *s2) return -1;
else if (*s1 > *s2) return 1;
}
return 0;
}
/***************************************************/
void xvbzero(s, len)
char *s;
size_t len;
{
for ( ; len>0; len--) *s++ = 0;
}
/***************************************************/
void xv_getwd(buf, buflen)
char *buf;
size_t buflen;
{
/* gets the current working directory. No trailing '/' */
char *rv;