-
Notifications
You must be signed in to change notification settings - Fork 0
/
xvevent.c
3319 lines (2613 loc) · 87.4 KB
/
xvevent.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
/*
* xvevent.c - EventLoop and support routines for XV
*
* Author: John Bradley, University of Pennsylvania
*
* Contains:
* int EventLoop()
* void DrawWindow(x,y,w,h)
* void WResize(w,h)
* void WRotate()
* void WCrop(w,h,dx,dy)
* void WUnCrop()
* void GetWindowPos(&xwa)
* void SetWindowPos(&xwa)
* void SetEpicMode()
* int xvErrorHandler(disp, err)
*/
#include "copyright.h"
#define NEEDSTIME /* for -wait handling in eventloop */
#include "xv.h"
#include "bits/dropper"
#include "bits/dropperm"
#include "bits/pen"
#include "bits/penm"
#include "bits/blur"
#include "bits/blurm"
static int rotatesLeft = 0;
static int origcropx, origcropy, origcropvalid=0;
static int canstartwait;
static int frominterrupt = 0;
static char *xevPriSel = NULL;
static Time lastEventTime;
static Cursor dropper = 0, pen = 0, blur = 0;
static void SelectDispMB PARM((int));
static void Select24to8MB PARM((int));
static void SelectRootMB PARM((int));
static void SelectWindowMB PARM((int));
static void SelectSizeMB PARM((int));
static void DoPrint PARM((void));
static void debugEvent PARM((XEvent *));
static const char *win2name PARM((Window));
static void handleButtonEvent PARM((XEvent *, int *, int *));
static void handleKeyEvent PARM((XEvent *, int *, int *));
static void zoomCurs PARM((u_int));
static void textViewCmd PARM((void));
static void setSizeCmd PARM((void));
static void WMaximize PARM((void));
static void CropKey PARM((int, int, int, int));
static void TrackPicValues PARM((int, int));
static int CheckForConfig PARM((void));
static Bool IsConfig PARM((Display *, XEvent *, char *));
static void onInterrupt PARM((int));
static void Paint PARM((void));
static void paintPixel PARM((int, int));
static void paintLine PARM((int, int, int, int));
static void paintXLine PARM((int, int, int, int, int));
static void BlurPaint PARM((void));
static int highbit PARM((u_long));
static u_long RGBToXColor PARM((int, int, int));
static void blurPixel PARM((int, int));
static void annotatePic PARM((void));
static int debkludge_offx;
static int debkludge_offy;
/****************/
int EventLoop()
/****************/
{
XEvent event;
int retval,done,waiting;
#ifdef USE_TICKS
clock_t waitsec_ticks=0L, orgtime_ticks=0L, curtime_ticks;
clock_t elapsed_ticks=0L, remaining_interval;
#else
time_t orgtime=0L, curtime;
#endif
#ifndef NOSIGNAL
signal(SIGQUIT, onInterrupt);
#endif
if (startGrab == 1) {
startGrab = 2;
FakeButtonPress(&but[BGRAB]);
FakeKeyPress(ctrlW, XK_Return);
return(1);
}
/* note: there's no special event handling if we're using the root window.
if we're using the root window, we will recieve NO events for mainW */
/* note: 'canstartwait' is magically turned 'true' in HandleEvent when I
think I've finally gotten 'mainW' drawn. It does not necessarily
mean that any waiting is/will be done. Also note that if we're
using a root mode, canstartwait is instantly turned on, as we aren't
going to be getting Expose/Configure events on the root window */
done = retval = waiting = canstartwait = 0;
if (useroot) canstartwait = 1;
else if (mainW) { /* if mainW iconified, start wait now */
XWindowAttributes xwa;
XSync(theDisp, False);
if (XGetWindowAttributes(theDisp, mainW, &xwa)) {
if (xwa.map_state != IsViewable) canstartwait = 1;
}
}
while (!done) {
if (waitsec >= 0.0 && canstartwait && !waiting && XPending(theDisp)==0) {
/* we wanna wait, we can wait, we haven't started waiting yet, and
all pending events (ie, drawing the image the first time)
have been dealt with: START WAITING */
#ifdef USE_TICKS
waitsec_ticks = (clock_t)(waitsec * CLK_TCK);
orgtime_ticks = times(NULL); /* unclear if NULL valid, but OK on Linux */
#else
orgtime = time(NULL);
#endif
waiting = 1;
}
/* if there's an XEvent pending *or* we're not doing anything
in real-time (polling, flashing the selection, etc.) get next event */
if ((waitsec<0.0 && !polling && !HaveSelection()) || XPending(theDisp)>0)
{
XNextEvent(theDisp, &event);
retval = HandleEvent(&event,&done);
}
else { /* no events. check wait status */
if (HaveSelection()) {
DrawSelection(0);
DrawSelection(1);
XFlush(theDisp);
Timer(200); /* milliseconds */
}
if (polling) {
if (CheckPoll(2)) return POLLED;
else if (!XPending(theDisp)) sleep(1);
}
if (waitsec>=0.0 && waiting) {
#ifdef USE_TICKS
curtime_ticks = times(NULL); /* value in ticks */
if (curtime_ticks < orgtime_ticks) {
/* clock ticks rolled over: need to correct for that (i.e.,
* curtime_ticks is presumably quite small, while orgtime_ticks
* should be close to LONG_MAX, so do math accordingly--any way
* to check whether clock_t is *not* a signed long?) */
elapsed_ticks = curtime_ticks + (LONG_MAX - orgtime_ticks);
} else
elapsed_ticks = curtime_ticks - orgtime_ticks;
remaining_interval = waitsec_ticks - elapsed_ticks;
if (remaining_interval >= (clock_t)(1 * CLK_TCK))
sleep(1);
else {
/* less than one second remaining: do delay in msec, then return */
Timer((remaining_interval * 1000L) / CLK_TCK); /* can't overflow */
return waitloop? NEXTLOOP : NEXTQUIT;
}
#else
curtime = time(NULL); /* value in seconds */
if (curtime - orgtime < (time_t)waitsec)
sleep(1);
else
return waitloop? NEXTLOOP : NEXTQUIT;
#endif
}
}
} /* while (!done) */
if (!useroot && origcropvalid) WUnCrop();
origcropvalid = 0;
return(retval);
}
/****************/
int HandleEvent(event, donep)
XEvent *event;
int *donep;
{
static int wasInfoUp=0, wasCtrlUp=0, wasDirUp=0, wasGamUp=0, wasPsUp=0;
#ifdef HAVE_JPEG
static int wasJpegUp=0;
#endif
#ifdef HAVE_JP2K
static int wasJp2kUp=0;
#endif
#ifdef HAVE_TIFF
static int wasTiffUp=0;
#endif
#ifdef HAVE_PNG
static int wasPngUp=0;
#endif
#ifdef HAVE_PCD
static int wasPcdUp=0;
#endif
#ifdef HAVE_PIC2
static int wasPic2Up=0;
#endif
#ifdef HAVE_MGCSFX
static int wasMgcSfxUp=0;
#endif
static int mainWKludge=0; /* force first mainW expose after a mainW config
to redraw all of mainW */
int done=0, retval=0;
if (DEBUG) debugEvent((XEvent *) event);
switch (event->type) {
case ButtonPress:
lastEventTime = ((XButtonEvent *) event)->time;
handleButtonEvent(event, &done, &retval);
break;
case KeyRelease:
case KeyPress:
lastEventTime = ((XKeyEvent *) event)->time;
handleKeyEvent(event, &done, &retval);
break;
case Expose: {
XExposeEvent *exp_event = (XExposeEvent *) event;
int x,y,w,h;
Window win;
#ifdef VMS
static int borders_sized = 0;
if (!borders_sized && !useroot && exp_event->window == mainW) {
/*
* Initial expose of main window, find the size of the ancestor
* window just prior to the root window and adjust saved size
* of display so that maximize functions will allow for window
* decorations.
*/
int status, count, mwid, mhgt, x, y, w, h, b, d, mbrd;
Window root, parent, *children, crw = exp_event->window;
borders_sized = 1;
status = XGetGeometry(theDisp, crw,
&root, &x, &y, &mwid, &mhgt, &mbrd, &d);
for ( parent = crw, w=mwid, h=mhgt;
status && (parent != root) && (parent != vrootW); ) {
crw = parent;
status = XQueryTree ( theDisp, crw, &root, &parent,
&children, &count );
if ( children != NULL ) XFree ( children );
}
status = XGetGeometry(theDisp, crw, &root, &x, &y, &w, &h, &b, &d);
if ( status ) {
dispWIDE = dispWIDE + mwid - w + (2*b);
dispHIGH = dispHIGH + mhgt - h + b;
/*printf("New display dims: %d %d\n", dispWIDE, dispHIGH ); */
}
}
#endif
win = exp_event->window;
x = exp_event->x; y = exp_event->y;
w = exp_event->width; h = exp_event->height;
if (PUCheckEvent (event)) break; /* event has been processed */
if (PSCheckEvent (event)) break; /* event has been processed */
#ifdef HAVE_JPEG
if (JPEGCheckEvent(event)) break; /* event has been processed */
#endif
#ifdef HAVE_JP2K
if (JP2KCheckEvent(event)) break; /* event has been processed */
#endif
#ifdef HAVE_TIFF
if (TIFFCheckEvent(event)) break; /* event has been processed */
#endif
#ifdef HAVE_PNG
if (PNGCheckEvent (event)) break; /* event has been processed */
#endif
if (PCDCheckEvent(event)) break; /* event has been processed */
#ifdef HAVE_PIC2
if (PIC2CheckEvent(event)) break; /* event has been processed */
#endif
#ifdef HAVE_PCD
if (PCDCheckEvent (event)) break; /* event has been processed */
#endif
#ifdef HAVE_MGCSFX
if (MGCSFXCheckEvent(event)) break; /* event has been processed */
#endif
#ifdef TV_MULTILINGUAL
if (CharsetCheckEvent(event)) break; /* event has been processed */
#endif
if (GamCheckEvent (event)) break; /* event has been processed */
if (BrowseCheckEvent (event, &retval, &done)) break; /* event eaten */
if (TextCheckEvent (event, &retval, &done)) break; /* event eaten */
/* if the window doesn't do intelligent redraw, drop but last expose */
if (exp_event->count>0 &&
win != mainW && win != ctrlW && win != dirW && win != infoW) break;
if (win == mainW && CheckForConfig()) {
if (DEBUG) fprintf(stderr,"Expose mainW ignored. Config pending.\n");
break;
}
if (win==mainW || win==ctrlW || win==dirW || win==infoW) {
/* must be a 'smart' window. group exposes into an expose 'region' */
int count;
Region reg;
XRectangle rect;
XEvent evt;
xvbcopy((char *) exp_event, (char *) &evt, sizeof(XEvent));
reg = XCreateRegion();
count = 0;
do {
rect.x = evt.xexpose.x;
rect.y = evt.xexpose.y;
rect.width = evt.xexpose.width;
rect.height = evt.xexpose.height;
XUnionRectWithRegion(&rect, reg, reg);
count++;
if (DEBUG) debugEvent((XEvent *) &evt);
} while (XCheckWindowEvent(theDisp,evt.xexpose.window,
ExposureMask, &evt));
XClipBox(reg, &rect); /* bounding box of region */
XSetRegion(theDisp, theGC, reg);
x = rect.x; y = rect.y;
w = rect.width; h = rect.height;
if (DEBUG) fprintf(stderr,"window: 0x%08x collapsed %d expose events\n",
(u_int) exp_event->window, count);
if (DEBUG) fprintf(stderr," region bounding box: %d,%d %dx%d\n",
x, y, w, h);
if (win == mainW) {
if (DEBUG) fprintf(stderr,"EXPOSE: ");
if (!CheckForConfig()) {
if (mainWKludge) {
if (DEBUG) fprintf(stderr, "Using mainWKludge\n");
x = 0; y = 0; w = eWIDE; h = eHIGH;
XSetClipMask(theDisp, theGC, None);
mainWKludge = 0;
}
if (DEBUG) fprintf(stderr,"No configs pending.\n");
/* if (DEBUG) XClearArea(theDisp, mainW, x,y,w,h, False); */
DrawWindow(x,y,w,h);
if (HaveSelection()) DrawSelection(0);
canstartwait = 1; /* finished drawing */
XSync(theDisp, False);
}
else
if (DEBUG) fprintf(stderr,"Ignored. Config pending\n");
}
else if (win == infoW) RedrawInfo(x,y,w,h);
else if (win == ctrlW) RedrawCtrl(x,y,w,h);
else if (win == dirW) RedrawDirW(x,y,w,h);
XSetClipMask(theDisp, theGC, None);
XDestroyRegion(reg);
}
else if (win == nList.win) LSRedraw(&nList,0);
else if (win == nList.scrl.win) SCRedraw(&nList.scrl);
else if (win == dList.win) LSRedraw(&dList,0);
else if (win == dList.scrl.win) SCRedraw(&dList.scrl);
else if (win == dnamW) RedrawDNamW();
}
break;
case ClientMessage: {
Atom proto, delwin;
XClientMessageEvent *client_event = (XClientMessageEvent *) event;
if (PUCheckEvent (event)) break; /* event has been processed */
proto = XInternAtom(theDisp, "WM_PROTOCOLS", FALSE);
delwin = XInternAtom(theDisp, "WM_DELETE_WINDOW", FALSE);
if (client_event->message_type == proto &&
client_event->data.l[0] == delwin) {
/* it's a WM_DELETE_WINDOW event */
if (BrowseDelWin(client_event->window)) break;
if (TextDelWin(client_event->window)) break;
#ifdef TV_MULTILINGUAL
if (CharsetDelWin(client_event->window)) break;
#endif
if (client_event->window == infoW) InfoBox(0);
else if (client_event->window == gamW) GamBox(0);
else if (client_event->window == ctrlW) CtrlBox(0);
else if (client_event->window == dirW) DirBox(0);
else if (client_event->window == psW) PSDialog(0);
#ifdef HAVE_JPEG
else if (client_event->window == jpegW) JPEGDialog(0);
#endif
#ifdef HAVE_JP2K
else if (client_event->window == jp2kW) JP2KDialog(0);
#endif
#ifdef HAVE_TIFF
else if (client_event->window == tiffW) TIFFDialog(0);
#endif
#ifdef HAVE_PNG
else if (client_event->window == pngW) PNGDialog(0);
#endif
else if (client_event->window == pcdW) PCDDialog(0);
#ifdef HAVE_PIC2
else if (client_event->window == pic2W) PIC2Dialog(0);
#endif
#ifdef HAVE_PCD
else if (client_event->window == pcdW) PCDDialog(0);
#endif
#ifdef HAVE_MGCSFX
else if (client_event->window == mgcsfxW) MGCSFXDialog(0);
#endif
else if (client_event->window == mainW) Quit(0);
}
}
break;
case ConfigureNotify: {
XConfigureEvent *cevt = (XConfigureEvent *) event;
Window win = cevt->window;
if (BrowseCheckEvent (event, &retval, &done)) break; /* event eaten */
if (TextCheckEvent (event, &retval, &done)) break; /* event eaten */
/*
* if it's a configure of one of the 'major' xv windows, update the
* NORMAL position hints for this window appropriately (so it can be
* iconified and deiconified correctly)
*/
if (win==ctrlW || win==gamW || win==infoW || win==mainW || win==dirW) {
XSizeHints hints;
#define BAD_IDEA
#ifdef BAD_IDEA
/*
* if there is a virtual window manager running (e.g., tvtwm / olvwm),
* we're going to get 'cevt' values in terms of the
* 'real' root window (the one that is the size of the screen).
* We'll want to translate them into values that are in terms of
* the 'virtual' root window (the 'big' one)
*/
if (vrootW != rootW) {
int x1,y1;
Window child;
XTranslateCoordinates(theDisp, rootW, vrootW, cevt->x, cevt->y,
&x1, &y1, &child);
if (DEBUG) fprintf(stderr," CONFIG trans %d,%d root -> %d,%d vroot\n",
cevt->x, cevt->y, x1, y1);
cevt->x = x1; cevt->y = y1;
}
#endif
#ifndef VMS
/* read hints for this window and adjust any position hints, but
only if this is a 'synthetic' event sent to us by the WM
('real' events from the server have useless x,y info, since the
mainW has been reparented by the WM) */
if (cevt->send_event &&
XGetNormalHints(theDisp, cevt->window, &hints)) {
if (DEBUG) fprintf(stderr," CONFIG got hints (0x%x %d,%d)\n",
(u_int) hints.flags, hints.x, hints.y);
hints.x = cevt->x;
hints.y = cevt->y;
XSetNormalHints(theDisp, cevt->window, &hints);
if (DEBUG) fprintf(stderr," CONFIG set hints (0x%x %d,%d)\n",
(u_int) hints.flags, hints.x, hints.y);
}
#endif
}
if (cevt->window == mainW) {
/* when we load a new image, we may get *2* configure events from
* the 'XMoveResizeWindow()' call. One at the 'old' size, in the
* new position, and one at the new size at the new position.
* We want to *IGNORE* the one at the old size, as we don't want to
* call Resize() for images that we won't need.
*
* Note that we may also only get *one* Configure event (if the window
* didn't move), and we may also only get *one* Configure event in
* some unasked for size (if the asked for size wasn't acceptable to
* the window manager), and we may also get *no* Configure event
* if the window doesn't move or change size
*
* This sucks!
*
* So, if we have just loaded an image, and we get a Synthetic conf
* that is not the desired size (eWIDExeHIGH), ignore it, as it's
* just the conf generated by moving the old window. And stop
* ignoring further config events
*
* EVIL KLUDGE: do *not* ignore configs that are <100x100. Not
* ignoring them won't be a big performance problem, and it'll get
* around the 'I only got one config in the wrong size' problem when
* initially displaying small images
*/
if (cevt->width<100 && cevt->height < 100 ) ignoreConfigs = 0;
/* fprintf(stderr,"***mainw, ignore=%d, send_event=%d, evtSize=%d,%d, size=%d,%d\n", ignoreConfigs, cevt->send_event, cevt->width, cevt->height, eWIDE, eHIGH); */
if (ignoreConfigs==1 && cevt->send_event &&
(cevt->width != eWIDE || cevt->height != eHIGH)) {
ignoreConfigs=0; /* ignore this one only */
break;
}
ignoreConfigs = 0;
if (!rotatesLeft) {
if (CheckForConfig()) {
if (DEBUG) fprintf(stderr,"more configs pending. ignored\n");
}
else {
XEvent xev;
if (DEBUG) fprintf(stderr,"No configs pend.");
if (cevt->width == eWIDE && cevt->height == eHIGH) {
if (DEBUG) fprintf(stderr,"No redraw\n");
}
else {
if (DEBUG) fprintf(stderr,"Do full redraw\n");
Resize(cevt->width, cevt->height);
/* eat any pending expose events and do a full redraw */
while (XCheckTypedWindowEvent(theDisp, mainW, Expose, &xev)) {
XExposeEvent *exp = (XExposeEvent *) &xev;
if (DEBUG)
fprintf(stderr," ate expose (%s) (count=%d) %d,%d %dx%d\n",
exp->send_event ? "synth" : "real", exp->count,
exp->x, exp->y, exp->width, exp->height);
}
DrawWindow(0,0,cevt->width, cevt->height);
if (HaveSelection()) DrawSelection(0);
canstartwait=1;
XSync(theDisp, False);
SetCursors(-1);
}
}
}
if (rotatesLeft>0) {
rotatesLeft--;
if (!rotatesLeft) mainWKludge = 1;
}
if (!rotatesLeft) SetCursors(-1);
}
}
break;
case CirculateNotify:
case DestroyNotify:
case GravityNotify: break;
case MapNotify: {
XMapEvent *map_event = (XMapEvent *) event;
if (map_event->window == mainW ||
(map_event->window == ctrlW && dispMode != RMB_WINDOW)) {
if (DEBUG) fprintf(stderr,"map event received on mainW/ctrlW\n");
if (autoclose) {
if (autoclose>1) autoclose -= 2; /* grab kludge */
if (wasInfoUp) { InfoBox(wasInfoUp); wasInfoUp=0; }
if (wasCtrlUp) { CtrlBox(wasCtrlUp); wasCtrlUp=0; }
if (wasDirUp) { DirBox(wasDirUp); wasDirUp=0; }
UnHideBrowseWindows();
UnHideTextWindows();
if (wasGamUp) { GamBox(wasGamUp); wasGamUp=0; }
if (wasPsUp) { PSDialog(wasPsUp); wasPsUp=0; }
#ifdef HAVE_JPEG
if (wasJpegUp) { JPEGDialog(wasJpegUp); wasJpegUp=0; }
#endif
#ifdef HAVE_JP2K
if (wasJp2kUp) { JP2KDialog(wasJpegUp); wasJp2kUp=0; }
#endif
#ifdef HAVE_TIFF
if (wasTiffUp) { TIFFDialog(wasTiffUp); wasTiffUp=0; }
#endif
#ifdef HAVE_PNG
if (wasPngUp) { PNGDialog(wasPngUp); wasPngUp=0; }
#endif
#ifdef HAVE_PCD
if (wasPcdUp) { PCDDialog(wasPcdUp); wasPcdUp=0; }
#endif
#ifdef HAVE_PIC2
if (wasPic2Up) { PIC2Dialog(wasPic2Up); wasPic2Up=0; }
#endif
#ifdef HAVE_MGCSFX
if (wasMgcSfxUp) { MGCSFXDialog(wasMgcSfxUp); wasMgcSfxUp=0; }
#endif
}
}
}
break;
case UnmapNotify: {
XUnmapEvent *unmap_event = (XUnmapEvent *) event;
if (unmap_event->window == mainW ||
(unmap_event->window == ctrlW && dispMode != RMB_WINDOW)) {
if (DEBUG) fprintf(stderr,"unmap event received on mainW/ctrlW\n");
if (DEBUG) fprintf(stderr,"dispMode = %d\n", dispMode);
/* don't do it if we've just switched to a root mode */
if ((unmap_event->window == mainW && dispMode == 0) ||
(unmap_event->window == ctrlW && dispMode != 0)) {
if (autoclose) {
if (autoclose>1) autoclose -= 2; /* grab kludge */
if (unmap_event->window == mainW) {
if (ctrlUp) { wasCtrlUp = ctrlUp; CtrlBox(0); }
}
if (infoUp) { wasInfoUp = infoUp; InfoBox(0); }
if (dirUp) { wasDirUp = dirUp; DirBox(0); }
HideBrowseWindows();
HideTextWindows();
if (gamUp) { wasGamUp = gamUp; GamBox(0); }
if (psUp) { wasPsUp = psUp; PSDialog(0); }
#ifdef HAVE_JPEG
if (jpegUp) { wasJpegUp = jpegUp; JPEGDialog(0); }
#endif
#ifdef HAVE_JP2K
if (jp2kUp) { wasJp2kUp = jp2kUp; JP2KDialog(0); }
#endif
#ifdef HAVE_TIFF
if (tiffUp) { wasTiffUp = tiffUp; TIFFDialog(0); }
#endif
#ifdef HAVE_PNG
if (pngUp) { wasPngUp = pngUp; PNGDialog(0); }
#endif
#ifdef HAVE_PCD
if (pcdUp) { wasPcdUp = pcdUp; PCDDialog(0); }
#endif
#ifdef HAVE_PIC2
if (pic2Up) { wasPic2Up = pic2Up; PIC2Dialog(0); }
#endif
#ifdef HAVE_MGCSFX
if (mgcsfxUp) { wasMgcSfxUp = mgcsfxUp; MGCSFXDialog(0); }
#endif
}
}
}
}
break;
case ReparentNotify: {
XReparentEvent *reparent_event = (XReparentEvent *) event;
if (DEBUG) {
fprintf(stderr,"Reparent: mainW=%x ->win=%x ->ev=%x ->parent=%x ",
(u_int) mainW, (u_int) reparent_event->window,
(u_int) reparent_event->event, (u_int) reparent_event->parent);
fprintf(stderr,"%d,%d\n", reparent_event->x, reparent_event->y);
}
if (reparent_event->window == mainW) {
ch_offx = reparent_event->x; /* offset required for ChangeAttr call */
ch_offy = reparent_event->y;
p_offx = p_offy = 0; /* topleft correction for WMs titlebar */
if (ch_offx == 0 && ch_offy == 0) {
/* looks like the user is running MWM or OLWM */
XWindowAttributes xwa;
/* first query the attributes of mainW. x,y should be the offset
from the parent's topleft corner to the windows topleft.
OLWM puts the info here */
XSync(theDisp, False);
XGetWindowAttributes(theDisp, mainW, &xwa);
if (DEBUG)
fprintf(stderr,"XGetAttr: mainW %d,%d %dx%d\n", xwa.x, xwa.y,
xwa.width, xwa.height);
if (xwa.x == 0 && xwa.y == 0) {
/* MWM, at least mine, puts 0's in those fields. To get the
info, we'll have to query the parent window */
XSync(theDisp, False);
XGetWindowAttributes(theDisp, reparent_event->parent, &xwa);
if (DEBUG)
fprintf(stderr,"XGetAttr: parent %d,%d %dx%d\n", xwa.x, xwa.y,
xwa.width, xwa.height);
}
else {
/* KLUDGE: if we're running olwm, xwa.{x,y} won't be 0,0.
in olwm, the window drifts down and right each time
SetWindowPos() is called. God knows why. Anyway, I'm
inserting a kludge here to increase 'ch_offx' and 'ch_offy'
by bwidth so that this drifting won't happen. No doubt this'll
screw up behavior on some *other* window manager, but it should
work with TWM, OLWM, and MWM (the big three) */
ch_offx += bwidth;
ch_offy += bwidth;
}
p_offx = xwa.x;
p_offy = xwa.y;
}
/* Gather info to keep right border inside */
{
Window current;
Window root_r;
Window parent_r;
Window *children_r;
unsigned int nchildren_r;
XWindowAttributes xwa;
parent_r=mainW;
current=mainW;
do {
current=parent_r;
XQueryTree(theDisp, current, &root_r, &parent_r,
&children_r, &nchildren_r);
if (children_r!=NULL) {
XFree(children_r);
}
} while (parent_r!=root_r && parent_r!=vrootW);
XGetWindowAttributes(theDisp, current, &xwa);
debkludge_offx = eWIDE-xwa.width+p_offx;
debkludge_offy = eHIGH-xwa.height+p_offy;
}
#if 0
/* FIXME: if we want to do this, we first have to wait for a configure
* notify to avoid a race condition because the location might be in-
* correct if the window manager does placement after managing the window.
*/
/* move window around a bit... */
{
XWindowAttributes xwa;
GetWindowPos(&xwa);
//fprintf(stderr, "RAC: orig window pos %d,%d\n", xwa.x, xwa.y);
xwa.width = eWIDE; xwa.height = eHIGH;
//fprintf(stderr, "RAC: image size now %d,%d\n", xwa.width, xwa.height);
/* try to keep the damned thing on-screen, if possible */
if (xwa.x + xwa.width > vrWIDE) xwa.x = vrWIDE - xwa.width;
if (xwa.y + xwa.height > vrHIGH) xwa.y = vrHIGH - xwa.height;
if (xwa.x < 0) xwa.x = 0;
if (xwa.y < 0) xwa.y = 0;
//fprintf(stderr, "RAC: moving window to %d,%d\n", xwa.x, xwa.y);
SetWindowPos(&xwa);
}
#endif
}
}
break;
case EnterNotify:
case LeaveNotify: {
XCrossingEvent *cross_event = (XCrossingEvent *) event;
if (cross_event->window == mainW || 0
/* (cross_event->window == gamW && cmapInGam) */ ) {
if (cross_event->type == EnterNotify && cross_event->window == mainW) {
zoomCurs(cross_event->state);
}
if (cross_event->type == EnterNotify && LocalCmap && !ninstall)
XInstallColormap(theDisp,LocalCmap);
if (cross_event->type == LeaveNotify && LocalCmap && !ninstall)
XUninstallColormap(theDisp,LocalCmap);
}
}
break;
case SelectionClear: break;
case SelectionRequest:
{
XSelectionRequestEvent *xsrevt = (XSelectionRequestEvent *) event;
XSelectionEvent xse;
if (xsrevt->owner != ctrlW ||
xsrevt->selection != XA_PRIMARY ||
xsrevt->target != XA_STRING) { /* can't do it. */
xse.property = None;
}
else {
if (xsrevt->property == None) xse.property = xsrevt->target;
else xse.property = xsrevt->property;
if (xse.property != None) {
xerrcode = 0;
XChangeProperty(theDisp, xsrevt->requestor, xse.property,
XA_STRING, 8, PropModeReplace,
(byte *) ((xevPriSel) ? xevPriSel : "\0"),
(int) ((xevPriSel) ? strlen(xevPriSel)+1 : 1));
XSync(theDisp, False);
if (!xerrcode) xse.property = None;
}
}
xse.type = SelectionNotify;
xse.send_event = True;
xse.display = theDisp;
xse.requestor = xsrevt->requestor;
xse.selection = xsrevt->selection;
xse.target = xsrevt->target;
xse.time = xsrevt->time;
XSendEvent(theDisp, xse.requestor, False, NoEventMask, (XEvent *) &xse);
XSync(theDisp, False);
}
break;
default: break; /* ignore unexpected events */
} /* switch */
frominterrupt = 0;
*donep = done;
return(retval);
}
/***********************************/
static void SelectDispMB(i)
int i;
{
/* called to handle selection of a dispMB item */
if (i<0 || i>=DMB_MAX) return;
if (dispMB.dim[i]) return; /* disabled */
if (i>=DMB_RAW && i<=DMB_SMOOTH) {
if (i==DMB_RAW) epicMode = EM_RAW;
else if (i==DMB_DITH) epicMode = EM_DITH;
else epicMode = EM_SMOOTH;
SetEpicMode();
GenerateEpic(eWIDE, eHIGH);
DrawEpic();
SetCursors(-1);
}
else if (i==DMB_COLRW) { /* toggle rw on/off */
dispMB.flags[i] = !dispMB.flags[i];
allocMode = (dispMB.flags[i]) ? AM_READWRITE : AM_READONLY;
ChangeCmapMode(colorMapMode, 1, 0);
}
else if (i>=DMB_COLNORM && i<=DMB_COLSTDC && !dispMB.flags[i]) {
switch (i) {
case DMB_COLNORM:
ChangeCmapMode(CM_NORMAL, 1, 0);
defaultCmapMode = CM_NORMAL;
break;
case DMB_COLPERF:
ChangeCmapMode(CM_PERFECT,1, 0);
defaultCmapMode = CM_PERFECT;
break;
case DMB_COLOWNC:
ChangeCmapMode(CM_OWNCMAP,1, 0);
defaultCmapMode = CM_OWNCMAP;
break;
case DMB_COLSTDC:
ChangeCmapMode(CM_STDCMAP,1, 0);
defaultCmapMode = CM_STDCMAP;
break;
}
}
}
/***********************************/
static void SelectRootMB(i)
int i;
{
/* called to handle selection of a rootMB item */
if (i<0 || i>=RMB_MAX) return;
if (rootMB.flags[i]) return;
if (rootMB.dim[i]) return;
dispMode = i;
/* move checkmark */
for (i=RMB_WINDOW; i<RMB_MAX; i++) rootMB.flags[i] = 0;
rootMB.flags[dispMode] = 1;
HandleDispMode();
}
/***********************************/
static void Select24to8MB(i)
int i;
{
if (i<0 || i>=CONV24_MAX) return;
if (conv24MB.dim[i]) return;
if (i==CONV24_8BIT || i==CONV24_24BIT) {
if (i != picType) {
Change824Mode(i);
if (i==CONV24_8BIT && state824==0) state824 = 1; /* did 24->8 */
else if (i==CONV24_24BIT && state824==1) {