127
126
extern int AlternateKeymap;
128
127
extern Bool AlternateContext;
130
static void CtwmNextEvent ();
131
static void RedoIcon();
132
static void do_key_menu ();
134
int RestoreWithdrawnLocation (); /* in ctwm.c */
129
static void CtwmNextEvent (Display *dpy, XEvent *event);
130
static void RedoIcon(void);
131
static void do_key_menu (MenuRoot *menu, /* menu to pop up */
132
Window w); /* invoking window or None */
133
void RedoIconName(void);
136
extern void play_sound(int snd);
139
138
FILE *tracefile = NULL;
167
167
static int ColortableThrashing;
168
168
static TwmWindow *enter_win, *raise_win, *leave_win, *lower_win;
170
ScreenInfo *FindScreenInfo();
171
170
int ButtonPressed = -1;
172
171
int Cancel = FALSE;
174
void HandleCreateNotify();
176
void HandleShapeNotify ();
177
void HandleFocusChange ();
173
void HandleCreateNotify(void);
174
void HandleShapeNotify (void);
175
void HandleFocusChange (void);
178
176
extern int ShapeEventBase, ShapeErrorBase;
180
178
extern Window lowerontop;
181
# include "gnomewindefs.h"
182
extern Atom _XA_WIN_WORKSPACE;
183
extern Atom _XA_WIN_STATE;
182
186
extern Atom _XA_WM_OCCUPATION;
183
187
extern Atom _XA_WM_CURRENTWORKSPACE;
189
int GnomeProxyButtonPress = -1;
184
191
/*#define TRACE_FOCUS*/
185
192
/*#define TRACE*/
188
static void dumpevent ();
194
static void dumpevent (XEvent *e);
191
196
#if defined(__hpux) && !defined(_XPG4_EXTENDED)
192
197
# define FDSET int*
396
void FixRootEvent (e)
394
void FixRootEvent (XEvent *e)
399
396
switch (e->type) {
402
e->xkey.x_root -= Scr->MyDisplayX;
403
e->xkey.y_root -= Scr->MyDisplayY;
399
e->xkey.x_root -= Scr->rootx;
400
e->xkey.y_root -= Scr->rooty;
404
401
e->xkey.root = Scr->Root;
406
403
case ButtonPress:
407
404
case ButtonRelease:
408
e->xbutton.x_root -= Scr->MyDisplayX;
409
e->xbutton.y_root -= Scr->MyDisplayY;
405
e->xbutton.x_root -= Scr->rootx;
406
e->xbutton.y_root -= Scr->rooty;
410
407
e->xbutton.root = Scr->Root;
412
409
case MotionNotify:
413
e->xmotion.x_root -= Scr->MyDisplayX;
414
e->xmotion.y_root -= Scr->MyDisplayY;
410
e->xmotion.x_root -= Scr->rootx;
411
e->xmotion.y_root -= Scr->rooty;
415
412
e->xmotion.root = Scr->Root;
417
414
case EnterNotify:
418
415
case LeaveNotify:
419
e->xcrossing.x_root -= Scr->MyDisplayX;
420
e->xcrossing.y_root -= Scr->MyDisplayY;
416
e->xcrossing.x_root -= Scr->rootx;
417
e->xcrossing.y_root -= Scr->rooty;
421
418
e->xcrossing.root = Scr->Root;
484
483
Scr = FindScreenInfo (WindowOfEvent (&Event));
487
488
if (!Scr) return False;
490
if ((Event.type == ConfigureNotify) &&
491
(Event.xconfigure.window == Scr->Root)) {
492
ConfigureRootWindow (&Event);
495
FixRootEvent (&Event);
491
if ((Event.type == ConfigureNotify) && (Event.xconfigure.window == Scr->CaptiveRoot)) {
492
ConfigureRootWindow (&Event);
496
if (Scr->Root != Scr->RealRoot) FixRootEvent (&Event);
497
497
if (Event.type>= 0 && Event.type < MAX_X_EVENT) {
499
499
play_sound(Event.type);
501
501
(*EventHandler[Event.type])();
551
# define nextEvent(event) XtAppNextEvent(appContext, event);
553
# define nextEvent(event) XNextEvent(dpy, event);
562
557
extern unsigned long timefe;
565
static void CtwmNextEvent (dpy, event)
560
static void CtwmNextEvent (Display *dpy, XEvent *event)
562
int animate = (AnimationActive && MaybeAnimate);
570
565
if (QLength (dpy) != 0) {
571
566
nextEvent (event);
574
if (AnimationPending) Animate ();
569
if (animate && AnimationPending) Animate ();
576
571
sys$waitfr(timefe);
577
572
sys$clref(timefe);
579
if (AnimationPending) Animate ();
574
if (animate && AnimationPending) Animate ();
580
575
if (QLength (dpy) != 0) {
581
576
nextEvent (event);
615
615
#else /* USE_SIGNALS */
616
if (animate) TryToAnimate ();
618
DoRestart(CurrentTime);
617
619
if (! MaybeAnimate) {
618
620
nextEvent (event);
621
tout = (AnimationSpeed > 0) ? &timeout : NULL;
623
if (animate) tout = (AnimationSpeed > 0) ? &timeout : NULL;
624
626
FD_SET (fd, &mask);
625
timeout = AnimateTimeout;
628
timeout = AnimateTimeout;
626
630
found = select (fd + 1, (FDSET)&mask, (FDSET) 0, (FDSET) 0, tout);
632
DoRestart(CurrentTime);
628
634
if (errno != EINTR) perror ("select");
659
667
***********************************************************************
663
HandleColormapNotify()
670
void HandleColormapNotify(void)
665
672
XColormapEvent *cevent = (XColormapEvent *) &Event;
666
673
ColormapWindow *cwin, **cwins;
667
674
TwmColormap *cmap;
668
675
int lost, won, n, number_cwins;
669
extern TwmColormap *CreateTwmColormap();
671
677
/* if (! Tmp_win) return; */
672
678
if (XFindContext(dpy, cevent->window, ColormapContext, (XPointer *)&cwin) == XCNOENT)
1438
1431
case PropertyNewValue:
1439
1432
if (XGetWindowProperty (dpy, Scr->Root, _XA_WM_CURRENTWORKSPACE,
1440
1433
0L, 200L, False, XA_STRING, &actual, &actual_format,
1441
&nitems, &bytesafter, (unsigned char **) &prop) == Success) {
1434
&nitems, &bytesafter, &prop) == Success) {
1442
1435
if (nitems == 0) return;
1443
GotoWorkSpaceByName (prop);
1436
GotoWorkSpaceByName (Scr->vScreenList, (char*)prop);
1444
1437
XFree ((char*) prop);
1478
1471
if (XGetWindowProperty (dpy, Tmp_win->w, Event.xproperty.atom, 0L,
1479
1472
MAX_NAME_LEN, False, XA_STRING, &actual,
1480
1473
&actual_format, &nitems, &bytesafter,
1481
(unsigned char **) &prop) != Success ||
1474
&prop) != Success ||
1482
1475
actual == None)
1484
1477
if (!prop) prop = NoName;
1485
1478
#endif /* NO_LOCALE */
1480
if (strstr (prop, " - Mozilla")) {
1481
char *moz = strstr (prop, " - Mozilla");
1486
1485
free_window_names (Tmp_win, True, True, False);
1488
Tmp_win->full_name = prop;
1489
Tmp_win->name = prop;
1487
Tmp_win->full_name = (char*) prop;
1488
Tmp_win->name = (char*) prop;
1491
1490
Tmp_win->nameChanged = 1;
1557
1556
if (XGetWindowProperty (dpy, Tmp_win->w, Event.xproperty.atom, 0,
1558
1557
MAX_ICON_NAME_LEN, False, XA_STRING, &actual,
1559
1558
&actual_format, &nitems, &bytesafter,
1560
(unsigned char **) &prop) != Success ||
1559
&prop) != Success ||
1561
1560
actual == None)
1563
1562
if (!prop) prop = NoName;
1564
1563
#endif /* NO_LOCALE */
1566
if ((strlen (prop) > 11) && (strncmp (prop, "Netscape: ", 10) == 0)) {
1569
tmp = strdup (prop + 10);
1570
XFree ((char*) prop);
1565
if (strstr (prop, " - Mozilla")) {
1566
char *moz = strstr (prop, " - Mozilla");
1574
icon_change = strcmp (Tmp_win->icon_name, prop);
1570
icon_change = strcmp (Tmp_win->icon_name, (char*) prop);
1575
1571
free_window_names (Tmp_win, False, False, True);
1576
Tmp_win->icon_name = prop;
1572
Tmp_win->icon_name = (char*) prop;
1578
1574
if (icon_change) {
1749
1745
} else if (Event.xproperty.atom == _XA_WM_OCCUPATION) {
1750
1746
if (XGetWindowProperty (dpy, Tmp_win->w, Event.xproperty.atom, 0L, MAX_NAME_LEN, False,
1751
1747
XA_STRING, &actual, &actual_format, &nitems,
1752
&bytesafter, (unsigned char **) &prop) != Success ||
1748
&bytesafter, &prop) != Success ||
1753
1749
actual == None) return;
1754
1750
ChangeOccupation (Tmp_win, GetMaskFromProperty (prop, nitems));
1753
else if (Event.xproperty.atom == _XA_WIN_WORKSPACE){
1754
if(XGetWindowProperty(dpy, Tmp_win->w, Event.xproperty.atom, 0L, 32, False,
1755
XA_CARDINAL, &actual, &actual_format, &nitems, &bytesafter,
1756
&gwkspc) != Success || actual == None) return;
1757
ChangeOccupation (Tmp_win, 1 << (int)(*gwkspc));
1762
static void RedoIcon()
1766
static void RedoIcon(void)
1771
1775
icon = (Icon*) 0;
1772
if (pattern = LookPatternInNameList (Scr->IconNames, Tmp_win->icon_name)) {
1773
icon = (Icon*) LookInNameList (Tmp_win->iconslist, pattern);
1776
if (pattern = LookPatternInNameList (Scr->IconNames, Tmp_win->full_name)) {
1777
icon = (Icon*) LookInNameList (Tmp_win->iconslist, pattern);
1780
if (pattern = LookPatternInList (Scr->IconNames, Tmp_win->full_name, &Tmp_win->class)) {
1776
if ((pattern = LookPatternInNameList (Scr->IconNames, Tmp_win->icon_name))) {
1777
icon = (Icon*) LookInNameList (Tmp_win->iconslist, pattern);
1780
if ((pattern = LookPatternInNameList (Scr->IconNames, Tmp_win->full_name))) {
1781
icon = (Icon*) LookInNameList (Tmp_win->iconslist, pattern);
1784
if ((pattern = LookPatternInList (Scr->IconNames, Tmp_win->full_name, &Tmp_win->class))) {
1781
1785
icon = (Icon*) LookInNameList (Tmp_win->iconslist, pattern);
1783
1787
if (pattern == NULL) {
1789
1793
RedoIconName ();
1792
if (Tmp_win->icon_on && (OCCUPY (Tmp_win, Scr->workSpaceMgr.activeWSPC))) {
1796
if (Tmp_win->icon_on && visible (Tmp_win)) {
1793
1797
IconDown (Tmp_win);
1794
1798
if (Tmp_win->icon && Tmp_win->icon->w) XUnmapWindow (dpy, Tmp_win->icon->w);
1795
1799
Tmp_win->icon = icon;
1796
1800
IconUp (Tmp_win);
1797
1801
XMapRaised (dpy, Tmp_win->icon->w);
1800
1804
Tmp_win->icon = icon;
1802
1806
RedoIconName ();
1805
if (Tmp_win->icon_on && (OCCUPY (Tmp_win, Scr->workSpaceMgr.activeWSPC))) {
1809
if (Tmp_win->icon_on && visible (Tmp_win)) {
1806
1810
IconDown (Tmp_win);
1807
1811
if (Tmp_win->icon && Tmp_win->icon->w) XUnmapWindow (dpy, Tmp_win->icon->w);
1808
1812
CreateIconWindow (Tmp_win, -100, -100);
1914
1918
0, &rect, 1, ShapeUnion, 0);
1917
if (Scr->SchrinkIconTitles &&
1918
Tmp_win->icon->title_schrinked &&
1920
(OCCUPY (Tmp_win, Scr->workSpaceMgr.activeWSPC))) {
1921
if (Scr->ShrinkIconTitles &&
1922
Tmp_win->icon->title_shrunk &&
1923
Tmp_win->icon_on && (visible (Tmp_win))) {
1921
1924
IconDown (Tmp_win);
1922
1925
IconUp (Tmp_win);
1939
1942
***********************************************************************
1943
HandleClientMessage()
1945
void HandleClientMessage(void)
1945
if (Event.xclient.message_type == _XA_WM_CHANGE_STATE)
1947
if (Tmp_win != NULL)
1949
if (Event.xclient.data.l[0] == IconicState && !Tmp_win->isicon)
1950
if (Event.xclient.message_type == _XA_WM_CHANGE_STATE) {
1951
if (Tmp_win != NULL) {
1952
if (Event.xclient.data.l[0] == IconicState && !Tmp_win->isicon) {
1953
XQueryPointer( dpy, Scr->Root, &JunkRoot, &JunkChild,
1954
&(button.xmotion.x_root),
1955
&(button.xmotion.y_root),
1956
&JunkX, &JunkY, &JunkMask);
1958
ExecuteFunction(F_ICONIFY, NULLSTR, Event.xany.window,
1959
Tmp_win, &button, FRAME, FALSE);
1960
XUngrabPointer(dpy, CurrentTime);
1954
XQueryPointer (dpy, Scr->Root, &JunkRoot, &JunkChild,
1955
&(button.xmotion.x_root),
1956
&(button.xmotion.y_root),
1957
&JunkX, &JunkY, &JunkMask);
1959
ExecuteFunction (F_ICONIFY, NULLSTR, Event.xany.window,
1960
Tmp_win, &button, FRAME, FALSE);
1961
XUngrabPointer (dpy, CurrentTime);
1967
/* 6/19/1999 nhd for GNOME compliance */
1968
if (Event.xclient.message_type == _XA_WIN_WORKSPACE) {
1970
supposedly works with a single screen, but is less certain with
1972
GotoWorkSpaceByNumber (Scr->currentvs, Event.xclient.data.l[0]);
1975
if (Event.xclient.message_type == _XA_WIN_STATE) {
1976
unsigned long new_stuff = (unsigned long) Event.xclient.data.l [1];
1977
unsigned long old_stuff = (unsigned long) Event.xclient.data.l [0];
1978
Window tmp_win = Event.xclient.window;
1979
for (twm_win = (Scr->TwmRoot).next; twm_win != NULL; twm_win = twm_win->next)
1980
if (twm_win->w == tmp_win) break;
1981
if (twm_win == NULL) return;
1982
for (i = 1; i < (1 << 10); i <<= 1){
1983
switch (old_stuff & i) {
1984
case WIN_STATE_STICKY: /* sticky */
1985
if (new_stuff & i) OccupyAll (twm_win);
1986
else ChangeOccupation (twm_win, (1<<(Scr->currentvs->wsw->currentwspc->number)));
1988
case WIN_STATE_MINIMIZED: /* minimized - reserved */
1990
case WIN_STATE_MAXIMIZED_VERT: /* window in maximized V state */
1992
case WIN_STATE_MAXIMIZED_HORIZ: /* maximized horizontally */
1994
case WIN_STATE_HIDDEN: /* hidden - what does this mean?? */
1996
case WIN_STATE_SHADED: /* shaded (squeezed) */
1999
case WIN_STATE_HID_WORKSPACE: /* not on this workspace */
2001
case WIN_STATE_HID_TRANSIENT: /* owner of transient hidden ? */
2003
case WIN_STATE_FIXED_POSITION: /* position fixed, don't move */
2005
case WIN_STATE_ARRANGE_IGNORE: /* ignore when auto-arranging */
2057
if (Tmp_win == Scr->workSpaceMgr.workspaceWindow.twm_win) {
2058
WMgrHandleExposeEvent (&Event);
2104
for (vs = Scr->vScreenList; vs != NULL; vs = vs->next) {
2105
if (Tmp_win == vs->wsw->twm_win) {
2106
WMgrHandleExposeEvent (vs, &Event);
2059
2107
flush_expose (Event.xany.window);
2062
else if (Tmp_win == Scr->workSpaceMgr.occupyWindow.twm_win) {
2111
if (Tmp_win == Scr->workSpaceMgr.occupyWindow->twm_win) {
2063
2112
PaintOccupyWindow ();
2064
2113
flush_expose (Event.xany.window);
2380
2429
case InactiveState:
2381
2430
Tmp_win->mapped = TRUE;
2382
2431
if (Tmp_win->UnmapByMovingFarAway) {
2383
XMoveWindow (dpy, Tmp_win->frame, Scr->MyDisplayWidth + 1,
2384
Scr->MyDisplayHeight + 1);
2432
XMoveWindow (dpy, Tmp_win->frame, Scr->rootw + 1, Scr->rooth + 1);
2385
2433
XMapWindow (dpy, Tmp_win->w);
2386
2434
XMapWindow (dpy, Tmp_win->frame);
2590
2634
***********************************************************************
2593
HandleButtonRelease()
2636
void HandleButtonRelease(void)
2595
2638
int xl, yt, w, h;
2642
if (GnomeProxyButtonPress == Event.xbutton.button) {
2643
GnomeProxyButtonPress = -1;
2644
XSendEvent (dpy, Scr->currentvs->wsw->w, False, SubstructureNotifyMask, &Event);
2598
2647
if (InfoLines) /* delete info box on 2nd button release */
2599
2648
if (Context == C_IDENTIFY) {
2600
2649
XUnmapWindow(dpy, Scr->InfoWindow);
2648
2697
Scr->OpaqueMove &&
2649
2698
DragWindow == Tmp_win->frame) TryToPush (Tmp_win, xl, yt, 0);
2650
2699
if (MoveFunction == F_MOVEPACK ||
2651
MoveFunction == F_MOVEPUSH &&
2652
DragWindow == Tmp_win->frame) TryToPack (Tmp_win, &xl, &yt);
2700
(MoveFunction == F_MOVEPUSH &&
2701
DragWindow == Tmp_win->frame)) TryToPack (Tmp_win, &xl, &yt);
2653
2702
if (Scr->DontMoveOff && MoveFunction != F_FORCEMOVE)
2655
2704
ConstrainByBorders (Tmp_win, &xl, w, &yt, h);
2886
2943
CurrentDragX = origDragX;
2887
2944
CurrentDragY = origDragY;
2888
if (!menuFromFrameOrWindowOrTitlebar)
2945
if (!menuFromFrameOrWindowOrTitlebar) {
2889
2946
if (Scr->OpaqueMove && DragWindow != None) {
2890
2947
XMoveWindow (dpy, DragWindow, origDragX, origDragY);
2892
2949
MoveOutline(Scr->Root, 0, 0, 0, 0, 0, 0);
2894
2952
XUnmapWindow(dpy, Scr->SizeWindow);
2895
2953
if (!Scr->OpaqueMove)
2896
2954
UninstallRootColormap();
3195
else if (Tmp_win == Scr->workSpaceMgr.workspaceWindow.twm_win) /* Baaad */
3197
WMgrHandleButtonEvent (&Event);
3254
if (Tmp_win == Scr->currentvs->wsw->twm_win) {
3255
WMgrHandleButtonEvent (Scr->currentvs, &Event);
3199
else if (Tmp_win == Scr->workSpaceMgr.occupyWindow.twm_win)
3259
if (Tmp_win == Scr->workSpaceMgr.occupyWindow->twm_win)
3201
3261
OccupyHandleButtonEvent (&Event);
3203
else if (Scr->DefaultFunction.func != 0)
3263
else if (func == 0 && Scr->DefaultFunction.func != 0)
3205
3265
if (Scr->DefaultFunction.func == F_MENU)
3214
3274
Event.xany.window, Tmp_win, &Event, Context, FALSE);
3277
#ifdef GNOME1 /* Makes DeferExecution (in menus.c) fail. TODO. */
3279
/* GNOME: Pass on the event to any applications listening for root window clicks */
3280
GnomeProxyButtonPress = Event.xbutton.button;
3282
XUngrabPointer (dpy, CurrentTime);
3283
XSendEvent (dpy, Scr->currentvs->wsw->twm_win->w, False,
3284
SubstructureNotifyMask, &Event);
3387
for (vs = Scr->vScreenList; vs != NULL; vs = vs->next) {
3388
if (ewp->window == vs->window) {
3389
Scr->Root = vs->window;
3390
Scr->rootx = Scr->crootx + vs->x;
3391
Scr->rooty = Scr->crooty + vs->y;
3394
Scr->currentvs = vs;
3395
/*fprintf (stderr, "entering new vs : 0x%x, 0x%x, %d, %d, %d, %d\n",
3396
vs, Scr->Root, vs->x, vs->y, vs->w, vs->h);*/
3322
3401
/* Handle RaiseDelay, if any.....
4190
ConfigureRootWindow (ev)
4259
void ConfigureRootWindow (XEvent *ev)
4195
unsigned int w, h, bw, d;
4197
XGetGeometry (dpy, Scr->Root, &root, &x, &y, &w, &h, &bw, &d);
4198
XTranslateCoordinates (dpy, Scr->Root, root, 0, 0, &Scr->MyDisplayX,
4199
&Scr->MyDisplayY, &child);
4201
Scr->MyDisplayWidth = ev->xconfigure.width;
4202
Scr->MyDisplayHeight = ev->xconfigure.height;
4263
unsigned int w, h, bw, d, oldw, oldh;
4264
extern void twmrc_error_prefix(void);
4266
XGetGeometry (dpy, Scr->CaptiveRoot, &root, &x, &y, &w, &h, &bw, &d);
4267
XTranslateCoordinates (dpy, Scr->CaptiveRoot, root, 0, 0, &Scr->crootx, &Scr->crooty, &child);
4271
Scr->crootw = ev->xconfigure.width;
4272
Scr->crooth = ev->xconfigure.height;
4274
fprintf (stderr, "ConfigureRootWindow: cx = %d, cy = %d, cw = %d, ch = %d\n",
4275
Scr->crootx, Scr->crooty, Scr->crootw, Scr->crooth);
4277
if (Scr->currentvs) {
4278
Scr->rootx = Scr->crootx + Scr->currentvs->x;
4279
Scr->rooty = Scr->crooty + Scr->currentvs->y;
4281
Scr->rootw = Scr->crootw;
4282
Scr->rooth = Scr->crooth;
4284
if (captive && ((Scr->crootw != oldw) || (Scr->crooth != oldh))) {
4285
twmrc_error_prefix ();
4286
fprintf (stderr, "You cannot change root window geometry with virtual screens active,\n");
4287
fprintf (stderr, "from now on, the ctwm behaviour is unpredictable.\n");
4206
static void dumpevent (e)
4291
static void dumpevent (XEvent *e)
4293
char *name = "Unknown event";
4211
4295
if (! tracefile) return;
4212
4296
switch (e->type) {
4244
4328
case ClientMessage: name = "ClientMessage"; break;
4245
4329
case MappingNotify: name = "MappingNotify"; break;
4249
fprintf (tracefile, "event: %s, %d remaining\n", name, QLength(dpy));
4251
fprintf (tracefile, "unknown event %d, %d remaining\n", e->type, QLength(dpy));
4331
fprintf (tracefile, "event: %s in window 0x%x\n", name, e->xany.window);
4335
fprintf (tracefile, " : +%d,+%d (+%d,+%d) state=%d, keycode=%d\n",
4336
e->xkey.x, e->xkey.y,
4337
e->xkey.x_root, e->xkey.y_root,
4338
e->xkey.state, e->xkey.keycode);
4342
fprintf (tracefile, " : +%d,+%d (+%d,+%d) state=%d, button=%d\n",
4343
e->xbutton.x, e->xbutton.y,
4344
e->xbutton.x_root, e->xbutton.y_root,
4345
e->xbutton.state, e->xbutton.button);