-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.c
4108 lines (3544 loc) · 110 KB
/
events.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
/*****************************************************************************/
/** Copyright 1988 by Evans & Sutherland Computer Corporation, **/
/** Salt Lake City, Utah **/
/** Portions Copyright 1989 by the Massachusetts Institute of Technology **/
/** Cambridge, Massachusetts **/
/** **/
/** All Rights Reserved **/
/** **/
/** Permission to use, copy, modify, and distribute this software and **/
/** its documentation for any purpose and without fee is hereby **/
/** granted, provided that the above copyright notice appear in all **/
/** copies and that both that copyright notice and this permis- **/
/** sion notice appear in supporting documentation, and that the **/
/** names of Evans & Sutherland and M.I.T. not be used in advertising **/
/** in publicity pertaining to distribution of the software without **/
/** specific, written prior permission. **/
/** **/
/** EVANS & SUTHERLAND AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD **/
/** TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- **/
/** ABILITY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND OR **/
/** M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAM- **/
/** AGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/
/** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/
/** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/
/** OR PERFORMANCE OF THIS SOFTWARE. **/
/*****************************************************************************/
/***********************************************************************
*
* $XConsortium: events.c,v 1.182 91/07/17 13:59:14 dave Exp $
*
* twm event handling
*
* 17-Nov-87 Thomas E. LaStrange File created
*
***********************************************************************/
#include <stdio.h>
#include <string.h>
#include "twm.h"
#include <X11/Xatom.h>
#include <X11/Xproto.h>
#include <X11/Xos.h>
#include "add_window.h"
#include "menus.h"
#include "events.h"
#include "resize.h"
#include "parse.h"
#include "gram.h"
#include "image_formats.h"
#include "util.h"
#include "screen.h"
#include "iconmgr.h"
#include "version.h"
#include "desktop.h"
#ifdef SOUND_SUPPORT
#include "sound.h"
#endif
#include "prototypes.h"
#ifdef NEED_SELECT_H
#include <sys/select.h> /* RAISEDELAY */
#else
#include <sys/time.h> /* RAISEDELAY */
#include <sys/types.h> /* RAISEDELAY */
#include <unistd.h>
#endif
extern void IconDown(TwmWindow * tmp_win);
extern void RedoIconName(void);
#ifdef TWM_USE_XRANDR
static void HandleXrandrScreenChangeNotify(void);
#endif /* TWM_USE_XRANDR */
static Window WindowOfEvent(XEvent * e);
extern int iconifybox_width, iconifybox_height;
extern unsigned int mods_used;
extern int menuFromFrameOrWindowOrTitlebar;
#ifdef SOUND_SUPPORT
extern int createSoundFromFunction;
extern int destroySoundFromFunction;
#endif
extern int PrintErrorMessages;
#define MAX_X_EVENT 256
event_proc EventHandler[MAX_X_EVENT]; /* event handler jump table */
char *Action = 0, *Action2 = 0, *Action3 = 0, *Action4 = 0;
int Context = C_NO_CONTEXT; /* current button press context */
TwmWindow *ButtonWindow; /* button press window structure */
XEvent ButtonEvent; /* button press event */
XEvent Event; /* the current event */
TwmWindow *Tmp_win; /* During event processing points to the
* TwmWindow structure for the window of the
* event. Also used as a scratch variable. */
/* Used in HandleEnterNotify to remove border highlight from a window
* that has not recieved a LeaveNotify event because of a pointer grab
*/
TwmWindow *UnHighLight_win = NULL;
Window DragWindow; /* variables used in moving windows */
int origDragX;
int origDragY;
int DragX;
int DragY;
int DragWidth;
int DragHeight;
int CurrentDragX;
int CurrentDragY;
/* Vars to tell if the resize has moved. */
extern int ResizeOrigX;
extern int ResizeOrigY;
static int enter_flag;
static int ColortableThrashing;
static TwmWindow *enter_win, *raise_win;
int ButtonPressed = -1;
int Cancel = FALSE;
int GlobalFirstTime = True;
int GlobalMenuButton = False;
extern void HandleCreateNotify(void);
extern void HandleShapeNotify(void);
extern int ShapeEventBase, ShapeErrorBase;
#ifdef TWM_USE_XRANDR
extern int XrandrEventBase;
extern int XrandrErrorBase;
#endif
void
AutoRaiseWindow(TwmWindow * tmp)
{
XRaiseWindow(dpy, tmp->frame);
XRaiseWindow(dpy, tmp->VirtualDesktopDisplayWindow.win);
RaiseStickyAbove();
RaiseAutoPan();
XSync(dpy, False);
enter_win = NULL;
enter_flag = TRUE;
raise_win = tmp;
}
void
SetRaiseWindow(TwmWindow * tmp)
{
enter_flag = TRUE;
enter_win = NULL;
raise_win = tmp;
XSync(dpy, False);
}
/***********************************************************************
*
* Procedure:
* InitEvents - initialize the event jump table
*
***********************************************************************
*/
void
InitEvents(void)
{
int i;
ResizeWindow = 0;
DragWindow = 0;
enter_flag = FALSE;
enter_win = raise_win = NULL;
for (i = 0; i < MAX_X_EVENT; i++)
EventHandler[i] = HandleUnknown;
EventHandler[Expose] = HandleExpose;
EventHandler[CreateNotify] = HandleCreateNotify;
EventHandler[DestroyNotify] = HandleDestroyNotify;
EventHandler[MapRequest] = HandleMapRequest;
EventHandler[MapNotify] = HandleMapNotify;
EventHandler[UnmapNotify] = HandleUnmapNotify;
EventHandler[ButtonRelease] = HandleButtonRelease;
EventHandler[ButtonPress] = HandleButtonPress;
EventHandler[EnterNotify] = HandleEnterNotify;
EventHandler[LeaveNotify] = HandleLeaveNotify;
EventHandler[FocusIn] = HandleFocusChange;
EventHandler[FocusOut] = HandleFocusChange;
EventHandler[ConfigureRequest] = HandleConfigureRequest;
EventHandler[ClientMessage] = HandleClientMessage;
EventHandler[PropertyNotify] = HandlePropertyNotify;
EventHandler[KeyPress] = HandleKeyPress;
EventHandler[ColormapNotify] = HandleColormapNotify;
EventHandler[VisibilityNotify] = HandleVisibilityNotify;
EventHandler[GraphicsExpose] = HandleGraphicsExpose;
EventHandler[NoExpose] = HandleGraphicsExpose;
if (HasShape)
EventHandler[ShapeEventBase + ShapeNotify] = HandleShapeNotify;
#ifdef TWM_USE_XRANDR
if (HasXrandr)
EventHandler[XrandrEventBase + RRScreenChangeNotify] = HandleXrandrScreenChangeNotify;
#endif
}
Time lastTimestamp = CurrentTime; /* until Xlib does this for us */
Bool
StashEventTime(register XEvent * ev)
{
switch (ev->type)
{
case KeyPress:
case KeyRelease:
lastTimestamp = ev->xkey.time;
return True;
case ButtonPress:
case ButtonRelease:
lastTimestamp = ev->xbutton.time;
return True;
case MotionNotify:
lastTimestamp = ev->xmotion.time;
return True;
case EnterNotify:
case LeaveNotify:
lastTimestamp = ev->xcrossing.time;
return True;
case PropertyNotify:
lastTimestamp = ev->xproperty.time;
return True;
case SelectionClear:
lastTimestamp = ev->xselectionclear.time;
return True;
case SelectionRequest:
lastTimestamp = ev->xselectionrequest.time;
return True;
case SelectionNotify:
lastTimestamp = ev->xselection.time;
return True;
}
return False;
}
/*
* WindowOfEvent - return the window about which this event is concerned; this
* window may not be the same as XEvent.xany.window (the first window listed
* in the structure).
*/
static Window
WindowOfEvent(XEvent * e)
{
/*
* Each window subfield is marked with whether or not it is the same as
* XEvent.xany.window or is different (which is the case for some of the
* notify events).
*/
switch (e->type)
{
case KeyPress:
case KeyRelease:
return e->xkey.window; /* same */
case ButtonPress:
case ButtonRelease:
return e->xbutton.window; /* same */
case MotionNotify:
return e->xmotion.window; /* same */
case EnterNotify:
case LeaveNotify:
return e->xcrossing.window; /* same */
case FocusIn:
case FocusOut:
return e->xfocus.window; /* same */
case KeymapNotify:
return e->xkeymap.window; /* same */
case Expose:
return e->xexpose.window; /* same */
case GraphicsExpose:
return e->xgraphicsexpose.drawable; /* same */
case NoExpose:
return e->xnoexpose.drawable; /* same */
case VisibilityNotify:
return e->xvisibility.window; /* same */
case CreateNotify:
return e->xcreatewindow.window; /* DIFF */
case DestroyNotify:
return e->xdestroywindow.window; /* DIFF */
case UnmapNotify:
return e->xunmap.window; /* DIFF */
case MapNotify:
return e->xmap.window; /* DIFF */
case MapRequest:
return e->xmaprequest.window; /* DIFF */
case ReparentNotify:
return e->xreparent.window; /* DIFF */
case ConfigureNotify:
return e->xconfigure.window; /* DIFF */
case ConfigureRequest:
return e->xconfigurerequest.window; /* DIFF */
case GravityNotify:
return e->xgravity.window; /* DIFF */
case ResizeRequest:
return e->xresizerequest.window; /* same */
case CirculateNotify:
return e->xcirculate.window; /* DIFF */
case CirculateRequest:
return e->xcirculaterequest.window; /* DIFF */
case PropertyNotify:
return e->xproperty.window; /* same */
case SelectionClear:
return e->xselectionclear.window; /* same */
case SelectionRequest:
return e->xselectionrequest.requestor; /* DIFF */
case SelectionNotify:
return e->xselection.requestor; /* same */
case ColormapNotify:
return e->xcolormap.window; /* same */
case ClientMessage:
return e->xclient.window; /* same */
case MappingNotify:
return None;
}
return None;
}
/***********************************************************************
*
* Procedure:
* DispatchEvent - handle a single X event stored in global var Event
*
***********************************************************************
*/
Bool
DispatchEvent(void)
{
Window w = Event.xany.window;
StashEventTime(&Event);
if (XFindContext(dpy, w, TwmContext, (caddr_t *) & Tmp_win) == XCNOENT)
Tmp_win = NULL;
/* Set Scr as an implicit argument for operations. */
if (XFindContext(dpy, w, ScreenContext, (caddr_t *) & Scr) == XCNOENT)
Scr = FindScreenInfo(WindowOfEvent(&Event));
if (!Scr)
return False;
if (MoveFunction != F_NOFUNCTION && menuFromFrameOrWindowOrTitlebar)
{
if (Event.type == Expose)
HandleExpose();
}
else if (Event.type >= 0 && Event.type < MAX_X_EVENT)
(*EventHandler[Event.type]) ();
return True;
}
/***********************************************************************
*
* Procedure:
* HandleEvents - handle X events
*
***********************************************************************
*/
void
HandleEvents(void)
{
while (TRUE)
{
if (enter_flag && !QLength(dpy))
{
if (enter_win && enter_win != raise_win)
{
AutoRaiseWindow(enter_win); /* sets enter_flag T */
}
else
{
enter_flag = FALSE;
}
}
if (ColortableThrashing && !QLength(dpy) && Scr)
{
InstallWindowColormaps(ColormapNotify, (TwmWindow *) NULL);
}
WindowMoved = FALSE;
if (ReqWakeup < 0)
QueueRestartVtwm(0);
ReqWakeup = 1;
if (IsDone)
Done(0);
XNextEvent(dpy, &Event);
ReqWakeup = 0;
if (IsDone)
Done(0);
(void)DispatchEvent();
}
}
/***********************************************************************
*
* Procedure:
* HandleColormapNotify - colormap notify event handler
*
* This procedure handles both a client changing its own colormap, and
* a client explicitly installing its colormap itself (only the window
* manager should do that, so we must set it correctly).
*
***********************************************************************
*/
void
HandleColormapNotify(void)
{
XColormapEvent *cevent = (XColormapEvent *) & Event;
ColormapWindow *cwin, **cwins;
TwmColormap *cmap;
int lost, won, n, number_cwins;
if (XFindContext(dpy, cevent->window, ColormapContext, (caddr_t *) & cwin) == XCNOENT)
return;
cmap = cwin->colormap;
if (cevent->new)
{
if (XFindContext(dpy, cevent->colormap, ColormapContext, (caddr_t *) & cwin->colormap) == XCNOENT)
cwin->colormap = CreateTwmColormap(cevent->colormap);
else
cwin->colormap->refcnt++;
cmap->refcnt--;
if (cevent->state == ColormapUninstalled)
cmap->state &= ~CM_INSTALLED;
else
cmap->state |= CM_INSTALLED;
if (cmap->state & CM_INSTALLABLE)
InstallWindowColormaps(ColormapNotify, (TwmWindow *) NULL);
if (cmap->refcnt == 0)
{
XDeleteContext(dpy, cmap->c, ColormapContext);
free((char *)cmap);
}
return;
}
if (cevent->state == ColormapUninstalled && (cmap->state & CM_INSTALLABLE))
{
if (!(cmap->state & CM_INSTALLED))
return;
cmap->state &= ~CM_INSTALLED;
if (!ColortableThrashing)
{
ColortableThrashing = TRUE;
XSync(dpy, False);
}
if (cevent->serial >= Scr->cmapInfo.first_req)
{
number_cwins = Scr->cmapInfo.cmaps->number_cwins;
/*
* Find out which colortables collided.
*/
cwins = Scr->cmapInfo.cmaps->cwins;
for (lost = won = -1, n = 0; (lost == -1 || won == -1) && n < number_cwins; n++)
{
if (lost == -1 && cwins[n] == cwin)
{
lost = n; /* This is the window which lost its colormap */
continue;
}
if (won == -1 && cwins[n]->colormap->install_req == cevent->serial)
{
won = n; /* This is the window whose colormap caused */
continue; /* the de-install of the previous colormap */
}
}
/*
** Cases are:
** Both the request and the window were found:
** One of the installs made honoring the WM_COLORMAP
** property caused another of the colormaps to be
** de-installed, just mark the scoreboard.
**
** Only the request was found:
** One of the installs made honoring the WM_COLORMAP
** property caused a window not in the WM_COLORMAP
** list to lose its map. This happens when the map
** it is losing is one which is trying to be installed,
** but is getting getting de-installed by another map
** in this case, we'll get a scoreable event later,
** this one is meaningless.
**
** Neither the request nor the window was found:
** Somebody called installcolormap, but it doesn't
** affect the WM_COLORMAP windows. This case will
** probably never occur.
**
** Only the window was found:
** One of the WM_COLORMAP windows lost its colormap
** but it wasn't one of the requests known. This is
** probably because someone did an "InstallColormap".
** The colormap policy is "enforced" by re-installing
** the colormaps which are believed to be correct.
*/
if (won != -1)
if (lost != -1)
{
/* lower diagonal index calculation */
if (lost > won)
n = lost * (lost - 1) / 2 + won;
else
n = won * (won - 1) / 2 + lost;
Scr->cmapInfo.cmaps->scoreboard[n] = 1;
}
else
{
/*
** One of the cwin installs caused one of the cwin
** colormaps to be de-installed, so I'm sure to get an
** UninstallNotify for the cwin I know about later.
** I haven't got it yet, or the test of CM_INSTALLED
** above would have failed. Turning the CM_INSTALLED
** bit back on makes sure we get back here to score
** the collision.
*/
cmap->state |= CM_INSTALLED;
}
else if (lost != -1)
InstallWindowColormaps(ColormapNotify, (TwmWindow *) NULL);
}
}
else if (cevent->state == ColormapUninstalled)
cmap->state &= ~CM_INSTALLED;
else if (cevent->state == ColormapInstalled)
cmap->state |= CM_INSTALLED;
}
/***********************************************************************
*
* Procedure:
* HandleVisibilityNotify - visibility notify event handler
*
* This routine keeps track of visibility events so that colormap
* installation can keep the maximum number of useful colormaps
* installed at one time.
*
***********************************************************************
*/
void
HandleVisibilityNotify(void)
{
XVisibilityEvent *vevent = (XVisibilityEvent *) & Event;
ColormapWindow *cwin;
TwmColormap *cmap;
if (XFindContext(dpy, vevent->window, ColormapContext, (caddr_t *) & cwin) == XCNOENT)
return;
/*
* when Saber complains about retreiving an <int> from an <unsigned int>
* just type "touch vevent->state" and "cont"
*/
cmap = cwin->colormap;
if ((cmap->state & CM_INSTALLABLE) &&
vevent->state != cwin->visibility &&
(vevent->state == VisibilityFullyObscured || cwin->visibility == VisibilityFullyObscured) && cmap->w == cwin->w)
{
cwin->visibility = vevent->state;
InstallWindowColormaps(VisibilityNotify, (TwmWindow *) NULL);
}
else
cwin->visibility = vevent->state;
}
/***********************************************************************
*
* Procedure:
* HandleKeyPress - key press event handler
*
***********************************************************************
*/
int MovedFromKeyPress = False;
void
HandleKeyPress(void)
{
FuncKey *key;
int len;
unsigned int modifier;
TwmWindow *tmp_win;
int have_ScrFocus = 0;
Context = C_NO_CONTEXT;
if (Event.xany.window == Scr->Root)
Context = C_ROOT;
if ((Event.xany.window == Scr->VirtualDesktopDisplay) || (Event.xany.window == Scr->VirtualDesktopDisplayOuter))
{
if (Event.xkey.subwindow && (XFindContext(dpy, Event.xkey.subwindow, VirtualContext, (caddr_t *) & tmp_win) != XCNOENT))
{
Tmp_win = tmp_win;
Context = C_VIRTUAL_WIN;
}
else
{
Context = C_VIRTUAL;
Tmp_win = Scr->VirtualDesktopDisplayTwin;
}
}
if (Tmp_win)
{
if (Event.xany.window == Tmp_win->title_w.win)
Context = C_TITLE;
if (Event.xany.window == Tmp_win->w)
Context = C_WINDOW;
if (Event.xany.window == Tmp_win->icon_w.win)
Context = C_ICON;
if (Event.xany.window == Tmp_win->frame)
Context = C_FRAME;
if (Tmp_win->list && Event.xany.window == Tmp_win->list->w.win)
Context = C_ICONMGR;
if (Tmp_win->list && Event.xany.window == Tmp_win->list->icon)
Context = C_ICONMGR;
}
/*
* Now HERE'S a fine little kludge: Make an icon manager's frame or
* the virtual desktop's frame or a door and it's frame context-
* sensitive to key bindings, and make the frames of windows without
* titlebars forward key events.
*
* djhjr - 6/5/98 7/2/98 7/14/98
*/
if (Focus && (Context == C_NO_CONTEXT || Context == C_ROOT))
{
if (Focus->iconmgr)
{
have_ScrFocus = 1;
}
else if (Scr->VirtualDesktopDisplayTwin == Focus)
{
Tmp_win = Focus;
Context = C_VIRTUAL;
}
/* XFindContext() doesn't seem to work here!?! */
else if (Scr->Doors)
{
TwmDoor *door_win;
for (door_win = Scr->Doors; door_win != NULL; door_win = door_win->next)
if (door_win->twin == Focus)
{
Tmp_win = Focus;
Context = C_DOOR;
break;
}
}
else if (Focus->frame && !Focus->title_w.win)
{
Tmp_win = Focus;
Event.xany.window = Tmp_win->frame;
Context = C_FRAME;
}
}
modifier = (Event.xkey.state & mods_used);
for (key = Scr->FuncKeyRoot.next; key != NULL; key = key->next)
{
if (key->keycode == Event.xkey.keycode && key->mods == modifier && (key->cont == Context || key->cont == C_NAME))
{
/* it doesn't make sense to resize from a key press? */
if (key->func == F_RESIZE)
return;
/*
* Exceptions for warps from icon managers (see the above kludge)
*/
switch (key->func)
{
case F_WARP:
if (have_ScrFocus && Context == C_ROOT)
return;
break;
case F_WARPCLASSNEXT:
case F_WARPCLASSPREV:
case F_WARPRING:
if (Context == C_ICONMGR)
Tmp_win = Tmp_win->list->iconmgr->twm_win;
if (have_ScrFocus)
{
Tmp_win = Focus;
Context = C_ICONMGR;
}
break;
default:
break;
}
/* special case for moves */
if (key->func == F_MOVE || key->func == F_FORCEMOVE)
MovedFromKeyPress = True;
if (key->cont != C_NAME)
{
ExecuteFunction(key->func, key->action, key->action2, key->action3, key->action4, Event.xany.window, Tmp_win, &Event, Context, FALSE);
if (!(Context = C_ROOT && RootFunction != F_NOFUNCTION))
XUngrabPointer(dpy, CurrentTime);
return;
}
else
{
int matched = FALSE;
len = strlen(key->win_name);
/* try and match the name first */
for (Tmp_win = Scr->TwmRoot.next; Tmp_win != NULL; Tmp_win = Tmp_win->next)
{
if (!strncmp(key->win_name, Tmp_win->name, len))
{
matched = TRUE;
ExecuteFunction(key->func, key->action, key->action2, key->action3, key->action4, Tmp_win->frame, Tmp_win, &Event, C_FRAME, FALSE);
XUngrabPointer(dpy, CurrentTime);
}
}
/* now try the res_name */
if (!matched)
for (Tmp_win = Scr->TwmRoot.next; Tmp_win != NULL; Tmp_win = Tmp_win->next)
{
if (!strncmp(key->win_name, Tmp_win->class.res_name, len))
{
matched = TRUE;
ExecuteFunction(key->func, key->action, key->action2, key->action3, key->action4, Tmp_win->frame, Tmp_win, &Event, C_FRAME, FALSE);
XUngrabPointer(dpy, CurrentTime);
}
}
/* now try the res_class */
if (!matched)
for (Tmp_win = Scr->TwmRoot.next; Tmp_win != NULL; Tmp_win = Tmp_win->next)
{
if (!strncmp(key->win_name, Tmp_win->class.res_class, len))
{
matched = TRUE;
ExecuteFunction(key->func, key->action, key->action2, key->action3, key->action4, Tmp_win->frame, Tmp_win, &Event, C_FRAME, FALSE);
XUngrabPointer(dpy, CurrentTime);
}
}
if (matched)
return;
}
}
}
/*
* If we get here, no function was bound to the key. Send it
* to the client if it was in a window we know about.
*/
if (Tmp_win)
{
if (Event.xany.window == Tmp_win->icon_w.win ||
Event.xany.window == Tmp_win->frame ||
Event.xany.window == Tmp_win->title_w.win || (Tmp_win->list && (Event.xany.window == Tmp_win->list->w.win)))
{
Event.xkey.window = Tmp_win->w;
XSendEvent(dpy, Tmp_win->w, False, KeyPressMask, &Event);
}
}
}
void
free_window_names(TwmWindow * tmp, Bool nukefull, Bool nukename, Bool nukeicon)
{
if (tmp->name == tmp->full_name)
nukefull = False;
#define isokay(v) ((v) && (v) != NoName)
if (nukefull && isokay(tmp->full_name))
free(tmp->full_name);
if (nukename && isokay(tmp->name))
free(tmp->name);
if (nukeicon && tmp->icon_name)
free(tmp->icon_name);
#undef isokay
return;
}
void
free_cwins(TwmWindow * tmp)
{
int i;
TwmColormap *cmap;
if (tmp->cmaps.number_cwins)
{
for (i = 0; i < tmp->cmaps.number_cwins; i++)
{
if (--tmp->cmaps.cwins[i]->refcnt == 0)
{
cmap = tmp->cmaps.cwins[i]->colormap;
if (--cmap->refcnt == 0)
{
XDeleteContext(dpy, cmap->c, ColormapContext);
free((char *)cmap);
}
XDeleteContext(dpy, tmp->cmaps.cwins[i]->w, ColormapContext);
free((char *)tmp->cmaps.cwins[i]);
}
}
free((char *)tmp->cmaps.cwins);
if (tmp->cmaps.number_cwins > 1)
{
free(tmp->cmaps.scoreboard);
tmp->cmaps.scoreboard = NULL;
}
tmp->cmaps.number_cwins = 0;
}
}
/***********************************************************************
*
* Procedure:
* HandlePropertyNotify - property notify event handler
*
***********************************************************************
*/
void
HandlePropertyNotify(void)
{
char *prop = NULL;
unsigned long valuemask; /* mask for create windows */
XSetWindowAttributes attributes; /* attributes for create windows */
Pixmap pm;
/* watch for standard colormap changes */
if (Event.xproperty.window == Scr->Root)
{
XStandardColormap *maps = NULL;
int nmaps;
switch (Event.xproperty.state)
{
case PropertyNewValue:
if (XGetRGBColormaps(dpy, Scr->Root, &maps, &nmaps, Event.xproperty.atom))
{
/* if got one, then replace any existing entry */
InsertRGBColormap(Event.xproperty.atom, maps, nmaps, True);
}
return;
case PropertyDelete:
RemoveRGBColormap(Event.xproperty.atom);
return;
}
}
if (!Tmp_win)
return; /* unknown window */
#define MAX_NAME_LEN 200L /* truncate to this many */
#define MAX_ICON_NAME_LEN 200L /* ditto */
switch (Event.xproperty.atom)
{
case XA_WM_NAME:
if (!I18N_FetchName(dpy, Tmp_win->w, &prop))
return;
int icon_name_follows_window_name = (Tmp_win->icon_name && Tmp_win->name && (! strcmp(Tmp_win->icon_name,Tmp_win->name)));
free_window_names(Tmp_win, True, True, False);
Tmp_win->full_name = (prop) ? strdup(prop) : NoName;
Tmp_win->name = (prop) ? strdup(prop) : NoName;
if (prop)
free(prop);
Tmp_win->name_width = MyFont_TextWidth(&Scr->TitleBarFont, Tmp_win->name, strlen(Tmp_win->name));
SetupWindow(Tmp_win, Tmp_win->frame_x, Tmp_win->frame_y, Tmp_win->frame_width, Tmp_win->frame_height, -1);
if (Tmp_win->title_w.win)
XClearArea(dpy, Tmp_win->title_w.win, 0, 0, 0, 0, True);
/*
* if the icon name is NoName, set the name of the icon to be
* the same as the window
*
* see that the icon name is it's own memory - djhjr - 2/20/99
*
* also, because Chrome is dumb and only updates the window name
* (not the icon name) on change of tab focus, if the icon name
* was the same as the window name, then just go ahead and update
* the icon name any time the window name changes.
* -douzzer 2017-Dec-2
*/
if ((icon_name_follows_window_name && strcmp(Tmp_win->icon_name,Tmp_win->name)) || (!strcmp(Tmp_win->icon_name, NoName)))
{
free(Tmp_win->icon_name);
Tmp_win->icon_name = strdup(Tmp_win->name);
RedoIconName();
}
break;
case XA_WM_ICON_NAME:
if (!I18N_GetIconName(dpy, Tmp_win->w, &prop))
return;
/* if the icon name already has the ostensibly new value, there's nothing to do. */
if (Tmp_win->icon_name && prop && (! strcmp(Tmp_win->icon_name,prop))) {
free(prop);
return;
}
free_window_names(Tmp_win, False, False, True);
Tmp_win->icon_name = prop ? : NoName;
RedoIconName();
break;
case XA_WM_HINTS:
if (Tmp_win->wmhints)
XFree((char *)Tmp_win->wmhints);
Tmp_win->wmhints = XGetWMHints(dpy, Event.xany.window);
/* Turn off 'initial_state' flag as the client is mapped; this would intervene iconify/deiconify handling */
if (Tmp_win->wmhints)
Tmp_win->wmhints->flags &= ~StateHint;
if (Tmp_win->wmhints && (Tmp_win->wmhints->flags & WindowGroupHint))
Tmp_win->group = Tmp_win->wmhints->window_group;
if (!Tmp_win->forced && Tmp_win->wmhints && Tmp_win->wmhints->flags & IconWindowHint)
{
if (Tmp_win->icon_w.win)
{
int icon_x, icon_y;