home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /** Copyright 1988 by Evans & Sutherland Computer Corporation, **/
- /** Salt Lake City, Utah **/
- /** **/
- /** 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 **/
- /** name of Evans & Sutherland not be used in advertising or publi- **/
- /** city pertaining to distribution of the software without specif- **/
- /** ic, written prior permission. **/
- /** **/
- /** EVANS & SUTHERLAND DISCLAIMS ALL WARRANTIES WITH REGARD TO **/
- /** THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI- **/
- /** TY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND BE LIABLE **/
- /** FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAM- **/
- /** AGES 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 PER- **/
- /** FORMANCE OF THIS SOFTWARE. **/
- /*****************************************************************************/
-
- /***********************************************************************
- *
- * $Header: events.c,v 1.31 88/04/15 07:09:47 tlastran Exp $
- *
- * twm event handling
- *
- * 17-Nov-87 Thomas E. LaStrange File created
- *
- ***********************************************************************/
-
- #ifndef lint
- static char RCSinfo[]=
- "$Header: events.c,v 1.31 88/04/15 07:09:47 tlastran Exp $";
- #endif
-
- #include <stdio.h>
- #include "twm.h"
- #include "add_window.h"
- #include "menus.h"
- #include "events.h"
- #include "resize.h"
- #include "gram.h"
-
- #include "twm.bm"
-
- static event_proc EventHandler[LASTEvent]; /* event handler jump table */
- static XEvent event; /* the current event */
- static TwmWindow *tmp_win; /* the current twm window */
- static Window w; /* the window that caused the event */
-
- static int ConstMove = FALSE; /* constrained move variables */
- static int ConstMoveDir;
- static int ConstMoveX;
- static int ConstMoveY;
- static int ConstMoveXL;
- static int ConstMoveXR;
- static int ConstMoveYT;
- static int ConstMoveYB;
-
- #define MOVE_NONE 0 /* modes of constrained move */
- #define MOVE_VERT 1
- #define MOVE_HORIZ 2
-
- static Window DragWindow; /* variables used in moving windows */
- static int DragX;
- static int DragY;
- static int DragWidth;
- static int DragHeight;
- static int enter_flag;
-
-
- /***********************************************************************
- *
- * Procedure:
- * InitEvents - initialize the event jump table
- *
- ***********************************************************************
- */
-
- void
- InitEvents()
- {
- int i;
-
- ResizeWindow = NULL;
- DragWindow = NULL;
- enter_flag = FALSE;
-
- for (i = 0; i < LASTEvent; i++)
- EventHandler[i] = HandleUnknown;
-
- EventHandler[Expose] = HandleExpose;
- EventHandler[DestroyNotify] = HandleDestroyNotify;
- EventHandler[MapRequest] = HandleMapRequest;
- EventHandler[MapNotify] = HandleMapNotify;
- EventHandler[UnmapNotify] = HandleUnmapNotify;
- EventHandler[MotionNotify] = HandleMotionNotify;
- EventHandler[ButtonRelease] = HandleButtonRelease;
- EventHandler[ButtonPress] = HandleButtonPress;
- EventHandler[EnterNotify] = HandleEnterNotify;
- EventHandler[LeaveNotify] = HandleLeaveNotify;
- EventHandler[ConfigureNotify] = HandleConfigureNotify;
- EventHandler[ClientMessage] = HandleClientMessage;
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleEvents - handle X events
- *
- ***********************************************************************
- */
-
- void
- HandleEvents()
- {
- InitEvents();
-
- while (TRUE)
- {
- XNextEvent(dpy, &event);
- w = event.xany.window;
- if (XFindContext(dpy, w, TwmContext, &tmp_win) == XCNOENT)
- tmp_win = NULL;
-
- #ifdef DEBUG
- if (event.type != MotionNotify)
- if (tmp_win != NULL)
- {
- fprintf(stderr, "Event w=%x, t->w=%x, t->frame=%x, t->title=%x, ",
- w, tmp_win->w, tmp_win->frame, tmp_win->title_w);
- }
- else
- {
- fprintf(stderr, "Event w=%x, ", w);
- }
- #endif
- if (event.type >= 0 && event.type < LASTEvent)
- (*EventHandler[event.type])();
- }
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleClientMessage - client message event handler
- *
- ***********************************************************************
- */
-
- void
- HandleClientMessage()
- {
- #ifdef DEBUG
- fprintf(stderr, "ClientMessage\n");
- #endif
-
- enter_flag = FALSE;
- }
- /***********************************************************************
- *
- * Procedure:
- * HandleExpose - expose event handler
- *
- ***********************************************************************
- */
-
- void
- HandleExpose()
- {
- MenuItem *tmp;
-
- #ifdef DEBUG
- fprintf(stderr, "Expose %d\n", event.xexpose.count);
- #endif
-
- if (event.xexpose.count != 0)
- return;
-
- if (w == VersionWindow)
- {
- XDrawImageString(dpy, VersionWindow, VersionNormalGC,
- twm_width + 10,
- 2 + VersionFont->ascent, Version, strlen(Version));
- }
-
- if (tmp_win != NULL)
- {
- if (tmp_win->title_w == w)
- {
- XDrawImageString(dpy, tmp_win->title_w,
- TitleNormalGC,
- TitleBarX, TitleBarY,
- tmp_win->name, strlen(tmp_win->name));
- return;
- }
-
- if (tmp_win->icon_w == w)
- {
- XDrawImageString(dpy, tmp_win->icon_w,
- IconNormalGC,
- tmp_win->icon_x, tmp_win->icon_y,
- tmp_win->icon_name, strlen(tmp_win->icon_name));
- return;
- }
- }
-
- if (XFindContext(dpy, w, MenuContext, &tmp) == 0)
- {
- if (tmp->state)
- XDrawImageString(dpy,w, MenuReverseGC, tmp->y, MenuY,
- tmp->item, strlen(tmp->item));
- else
- XDrawImageString(dpy,w, MenuNormalGC, tmp->y, MenuY,
- tmp->item, strlen(tmp->item));
-
- return;
- }
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleDestroyNotify - DestroyNotify event handler
- *
- ***********************************************************************
- */
-
- void
- HandleDestroyNotify()
- {
- #ifdef DEBUG
- fprintf(stderr, "DestroyNotify\n");
- #endif
- if (tmp_win == NULL)
- return;
-
- if (tmp_win == Focus)
- {
- FocusOnRoot();
- }
- XDeleteContext(dpy, tmp_win->w, TwmContext);
- XDeleteContext(dpy, tmp_win->frame, TwmContext);
- XDeleteContext(dpy, tmp_win->title_w, TwmContext);
- XDeleteContext(dpy, tmp_win->iconify_w, TwmContext);
- XDeleteContext(dpy, tmp_win->resize_w, TwmContext);
- XDeleteContext(dpy, tmp_win->icon_w, TwmContext);
- XDeleteContext(dpy, tmp_win->focus_w, TwmContext);
- XDeleteContext(dpy, tmp_win->hilite_w, TwmContext);
-
- XDestroyWindow(dpy, tmp_win->frame);
- XDestroyWindow(dpy, tmp_win->icon_w);
- tmp_win->prev->next = tmp_win->next;
- if (tmp_win->next != NULL)
- tmp_win->next->prev = tmp_win->prev;
-
- free((char *)tmp_win);
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleMapRequest - MapRequest event handler
- *
- ***********************************************************************
- */
-
- void
- HandleMapRequest()
- {
- int stat;
- XWindowChanges xwc;
- unsigned int xwcm;
-
- #ifdef DEBUG
- fprintf(stderr, "MapRequest\n");
- #endif
-
- stat = XFindContext(dpy, event.xmaprequest.window, TwmContext, &tmp_win);
- if (stat == XCNOENT)
- tmp_win = NULL;
-
- if (tmp_win == NULL)
- {
- tmp_win = AddWindow(event.xmaprequest.window);
- if (tmp_win->wmhints && (tmp_win->wmhints->flags & StateHint))
- {
- switch (tmp_win->wmhints->initial_state)
- {
- case DontCareState:
- case NormalState:
- case ZoomState:
- case InactiveState:
- XMapWindow(dpy, event.xmaprequest.window);
- XMapRaised(dpy, tmp_win->frame);
- break;
-
- case IconicState:
- xwcm = 0;
- xwcm |= CWX;
- xwcm |= CWY;
-
- xwc.x = 0;
- xwc.y = 0;
-
- if (tmp_win->wmhints->flags & IconPositionHint)
- {
- xwc.x = tmp_win->wmhints->icon_x;
- xwc.y = tmp_win->wmhints->icon_y;
- }
-
- XConfigureWindow(dpy, tmp_win->icon_w, xwcm, &xwc);
- XMapSubwindows(dpy, tmp_win->icon_w);
- XMapRaised(dpy, tmp_win->icon_w);
- tmp_win->iconified = TRUE;
- tmp_win->icon = TRUE;
- break;
- }
- }
- else
- {
- if (!tmp_win->icon)
- {
- XMapWindow(dpy, event.xmaprequest.window);
- XMapRaised(dpy, tmp_win->frame);
- }
- }
- }
- else
- {
- if (!tmp_win->icon)
- {
- XMapWindow(dpy, event.xmaprequest.window);
- XMapRaised(dpy, tmp_win->frame);
- }
- }
- XRaiseWindow(dpy, VersionWindow);
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleMapNotify - MapNotify event handler
- *
- ***********************************************************************
- */
-
- void
- HandleMapNotify()
- {
- #ifdef DEBUG
- fprintf(stderr, "MapNotify\n");
- #endif
- if (tmp_win == NULL)
- return;
-
- XMapSubwindows(dpy, tmp_win->title_w);
- XMapSubwindows(dpy, tmp_win->frame);
- XUnmapWindow(dpy, tmp_win->hilite_w);
-
- if (tmp_win->title_height == 0)
- XUnmapWindow(dpy, tmp_win->title_w);
-
- XMapRaised(dpy, tmp_win->frame);
- tmp_win->mapped = TRUE;
- XRaiseWindow(dpy, VersionWindow);
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleUnmapNotify - UnmapNotify event handler
- *
- ***********************************************************************
- */
-
- void
- HandleUnmapNotify()
- {
- #ifdef DEBUG
- fprintf(stderr, "UnmapNotify\n");
- #endif
- if (tmp_win == NULL)
- return;
-
- XUnmapWindow(dpy, tmp_win->frame);
- tmp_win->mapped = FALSE;
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleMotionNotify - MotionNotify event handler
- *
- ***********************************************************************
- */
-
- void
- HandleMotionNotify()
- {
- #ifdef DEBUG
- /*
- fprintf(stderr, "MotionNotify\n");
- */
- #endif
- /*XUnmapWindow(dpy, VersionWindow);*/
- if (ConstMove)
- {
- switch (ConstMoveDir)
- {
- case MOVE_NONE:
- if (event.xbutton.x_root < ConstMoveXL ||
- event.xbutton.x_root > ConstMoveXR)
- ConstMoveDir = MOVE_HORIZ;
-
- if (event.xbutton.y_root < ConstMoveYT ||
- event.xbutton.y_root > ConstMoveYB)
- ConstMoveDir = MOVE_VERT;
-
- XQueryPointer(dpy, DragWindow, &JunkRoot, &JunkChild,
- &JunkX, &JunkY, &DragX, &DragY, &JunkMask);
- break;
-
- case MOVE_VERT:
- ConstMoveY = event.xbutton.y_root - DragY - BorderWidth;
- break;
-
- case MOVE_HORIZ:
- ConstMoveX= event.xbutton.x_root - DragX - BorderWidth;
- break;
- }
-
- if (ConstMoveDir != MOVE_NONE)
- {
- MoveOutline(event.xbutton.root,
- ConstMoveX, ConstMoveY,
- DragWidth + 2 * BorderWidth,
- DragHeight + 2 * BorderWidth);
- }
- return;
- }
-
- if (DragWindow != NULL)
- {
- MoveOutline(event.xbutton.root,
- event.xbutton.x_root - DragX - BorderWidth,
- event.xbutton.y_root - DragY - BorderWidth,
- DragWidth + 2 * BorderWidth,
- DragHeight + 2 * BorderWidth);
-
- return;
- }
-
- if (ResizeWindow != NULL)
- {
- XFindContext(dpy, ResizeWindow, TwmContext, &tmp_win);
- DoResize(event, tmp_win);
- }
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleButtonRelease - ButtonRelease event handler
- *
- ***********************************************************************
- */
-
- void
- HandleButtonRelease()
- {
- #ifdef DEBUG
- fprintf(stderr, "ButtonRelease\n");
- #endif
- XUngrabPointer(dpy, CurrentTime);
- XUngrabServer(dpy);
- EventHandler[EnterNotify] = HandleEnterNotify;
- EventHandler[LeaveNotify] = HandleLeaveNotify;
-
- if (DragWindow != NULL)
- {
- XEvent client_event;
- XWindowChanges xwc;
- unsigned int xwcm;
-
- MoveOutline(event.xbutton.root, 0, 0, 0, 0);
-
- xwcm = 0;
- xwcm |= CWX;
- xwcm |= CWY;
-
- xwc.x = event.xbutton.x_root - DragX - BorderWidth;
- xwc.y = event.xbutton.y_root - DragY - BorderWidth;
-
- if (ConstMove)
- {
- if (ConstMoveDir == MOVE_HORIZ)
- xwc.y = ConstMoveY;
-
- if (ConstMoveDir == MOVE_VERT)
- xwc.x = ConstMoveX;
-
- if (ConstMoveDir == MOVE_NONE)
- {
- xwc.y = ConstMoveY;
- xwc.x = ConstMoveX;
- }
- }
-
- XFindContext(dpy, DragWindow, TwmContext, &tmp_win);
- tmp_win->frame_x = xwc.x;
- tmp_win->frame_y = xwc.y;
-
- XConfigureWindow(dpy, DragWindow, xwcm, &xwc);
- XRaiseWindow(dpy, DragWindow);
- DragWindow = NULL;
- ConstMove = FALSE;
-
- enter_flag = TRUE;
- client_event.type = ClientMessage;
- XSendEvent(dpy, tmp_win->frame, False, 0, &client_event);
-
- return;
- }
-
- if (ResizeWindow != NULL)
- {
- EndResize();
- EventHandler[EnterNotify] = HandleEnterNotify;
- EventHandler[LeaveNotify] = HandleLeaveNotify;
- }
-
- if (w == Root)
- {
- MenuRoot *tmp;
-
- /*
- if (ActiveItem != NULL)
- {
- int i;
-
- for (i = 0; i < 4; i++)
- XFillRectangle(dpy, ActiveItem->w,
- MenuXorGC,0,0,1000, 100);
-
- XFlush();
- }
- */
- for (tmp = ActiveMenu; tmp != NULL; tmp = tmp->prev)
- {
- XUnmapWindow(dpy, tmp->shadow);
- XUnmapWindow(dpy, tmp->w);
- }
- XFlush(dpy);
- ActiveMenu = NULL;
-
- if (ActiveItem != NULL)
- {
- ActiveItem->state = 0;
- ExecuteFunction(ActiveItem);
- ActiveItem = NULL;
- XUngrabPointer(dpy, CurrentTime);
- }
-
- return;
- }
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleButtonPress - ButtonPress event handler
- *
- ***********************************************************************
- */
-
- void
- HandleButtonPress()
- {
-
- #ifdef DEBUG
- fprintf(stderr, "ButtonPress\n");
- #endif
-
- XUnmapWindow(dpy, VersionWindow);
-
- if (w == Root)
- {
- if (Menu[event.xbutton.button] != NULL)
- {
- XGrabPointer(dpy, Root, True,
- ButtonReleaseMask | ButtonMotionMask,
- GrabModeAsync, GrabModeSync,
- Root, RightArrowCursor, CurrentTime);
-
- PopUpMenu(Menu[event.xbutton.button],
- event.xbutton.x, event.xbutton.y);
- }
- else if (Item[event.xbutton.button] != NULL)
- {
- ExecuteFunction(Item[event.xbutton.button]);
- }
-
- return;
- }
-
- if (tmp_win == NULL)
- return;
-
- if (w == tmp_win->frame || w == tmp_win->title_w || w == tmp_win->icon_w)
- {
- if (w != tmp_win->icon_w)
- w = tmp_win->frame;
-
- HandleTitleButton(w, tmp_win, event);
-
- return;
- }
-
- if (w == tmp_win->iconify_w)
- {
- if (!tmp_win->iconified)
- {
- XWindowChanges xwc;
- unsigned int xwcm;
-
- xwcm = 0;
- xwcm |= CWX;
- xwcm |= CWY;
-
- if (tmp_win->wmhints && tmp_win->wmhints->flags & IconPositionHint)
- {
- xwc.x = tmp_win->wmhints->icon_x;
- xwc.y = tmp_win->wmhints->icon_y;
- }
- else
- {
- xwc.x = event.xbutton.x_root - 5;
- xwc.y = event.xbutton.y_root - 5;
- }
-
- XConfigureWindow(dpy, tmp_win->icon_w, xwcm, &xwc);
- tmp_win->iconified = TRUE;
- }
-
- XUnmapWindow(dpy, tmp_win->frame);
- XMapSubwindows(dpy, tmp_win->icon_w);
- XMapRaised(dpy, tmp_win->icon_w);
- if (tmp_win == Focus)
- {
- XSetInputFocus(dpy, Root, RevertToPointerRoot,
- CurrentTime);
- Focus = NULL;
- FocusRoot = TRUE;
- }
- return;
- }
-
- if (w == tmp_win->resize_w)
- {
- EventHandler[EnterNotify] = HandleUnknown;
- EventHandler[LeaveNotify] = HandleUnknown;
- StartResize(event, tmp_win);
- }
-
- if (w == tmp_win->focus_w)
- {
- if (Focus != NULL && Focus != tmp_win)
- {
- XUnmapWindow(dpy, Focus->hilite_w);
- }
- XMapWindow(dpy, tmp_win->hilite_w);
- XSetInputFocus(dpy, tmp_win->w, RevertToPointerRoot,
- CurrentTime);
- FocusRoot = FALSE;
- Focus = tmp_win;
-
- return;
- }
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleEnterNotify - EnterNotify event handler
- *
- ***********************************************************************
- */
-
- void
- HandleEnterNotify()
- {
- MenuItem *tmp;
-
- #ifdef DEBUG
- fprintf(stderr, "EnterNotify\n");
- #endif
-
- if (ActiveMenu == NULL && tmp_win != NULL)
- {
- if (FocusRoot && tmp_win->mapped)
- {
- if (Focus != NULL && Focus != tmp_win)
- XUnmapWindow(dpy, Focus->hilite_w);
-
- XMapWindow(dpy, tmp_win->hilite_w);
- XSetInputFocus(dpy, tmp_win->w, RevertToPointerRoot,
- CurrentTime);
- Focus = tmp_win;
- }
- if (enter_flag == FALSE && tmp_win->auto_raise)
- {
- XEvent client_event;
-
- XRaiseWindow(dpy, tmp_win->frame);
- enter_flag = TRUE;
- client_event.type = ClientMessage;
- XSendEvent(dpy, tmp_win->frame, False, 0, &client_event);
- }
- return;
- }
-
-
- if (XFindContext(dpy, w, MenuContext, &tmp) != 0)
- return;
-
- if (w == tmp->w && tmp->root == ActiveMenu)
- {
- if (ActiveItem != NULL && ActiveItem->state != 0)
- {
- #ifdef DEBUG
- fprintf(stderr, "turning off \"%s\"\n", ActiveItem->item);
- #endif
- XFillRectangle(dpy, ActiveItem->w,MenuXorGC,0,0,1000, 100);
- if (tmp->pull != NULL)
- XFillRectangle(dpy, ActiveItem->pull, MenuXorGC,0,0,1000, 100);
- ActiveItem->state = 0;
- }
-
- if (tmp->state == 0)
- {
- #ifdef DEBUG
- fprintf(stderr, "turning on \"%s\"\n", tmp->item);
- #endif
- XFillRectangle(dpy, tmp->w,MenuXorGC,0,0,1000, 100);
- if (tmp->pull)
- XFillRectangle(dpy, tmp->pull, MenuXorGC,0,0,1000, 100);
- tmp->state = 1;
- }
- ActiveItem = tmp;
-
- return;
- }
-
- if (w == tmp->pull && tmp->root == ActiveMenu)
- {
- XGrabServer(dpy);
- PopUpMenu(tmp->sub, event.xcrossing.x_root,
- event.xcrossing.y_root);
- XUngrabServer(dpy);
-
- return;
- }
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleLeaveNotify - LeaveNotify event handler
- *
- ***********************************************************************
- */
-
- void
- HandleLeaveNotify()
- {
- MenuItem *tmp;
-
- #ifdef DEBUG
- fprintf(stderr, "LeaveNotify\n");
- #endif
- if (tmp_win != NULL)
- {
- XUnmapWindow(dpy, VersionWindow);
- if (FocusRoot)
- {
- if (event.xcrossing.detail != NotifyInferior)
- {
- XUnmapWindow(dpy, tmp_win->hilite_w);
- XSetInputFocus(dpy, Root, RevertToPointerRoot,
- CurrentTime);
- Focus = NULL;
- }
- }
- return;
- }
-
- if (XFindContext(dpy, w, MenuContext, &tmp) != 0)
- return;
-
- if (w == tmp->root->w)
- {
- int rootx, rooty, x, y;
- int wx, wy, ww, wh;
-
- /* see if the mouse really left the window
- * or just crossed into a sub-window
- */
-
- XQueryPointer(dpy, w, &JunkRoot,
- &JunkChild, &rootx, &rooty, &x, &y, &JunkMask);
-
- XGetGeometry(dpy, w, &JunkRoot, &wx, &wy,
- &ww, &wh, &JunkBW,
- &JunkDepth);
-
- if (rootx < wx ||
- rootx > (wx + ww) ||
- rooty < wy ||
- rooty > (wy + wh))
- {
- ActiveItem = NULL;
- if (tmp->root->prev != NULL)
- {
- if (ActiveMenu == tmp->root)
- {
- XUnmapWindow(dpy, ActiveMenu->shadow);
- XUnmapWindow(dpy, ActiveMenu->w);
- ActiveMenu = tmp->root->prev;
- }
- }
- }
- return;
- }
-
- if (w == tmp->w);
- {
- if (tmp == ActiveItem)
- ActiveItem = NULL;
-
- if (tmp->state != 0)
- {
- #ifdef DEBUG
- fprintf(stderr, "turning off \"%s\"\n", tmp->item);
- #endif
- XFillRectangle(dpy, tmp->w,MenuXorGC,0,0,1000, 100);
- if (tmp->pull != NULL)
- XFillRectangle(dpy, tmp->pull, MenuXorGC,0,0,1000, 100);
- tmp->state = 0;
- }
-
- return;
- }
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleConfigureNotify - ConfigureNotify event handler
- *
- ***********************************************************************
- */
-
- void
- HandleConfigureNotify()
- {
- #ifdef DEBUG
- fprintf(stderr, "ConfigureNotify\n");
- #endif
- if (tmp_win == NULL)
- return;
-
- if (event.xconfigure.override_redirect)
- return;
-
- SetupWindow(tmp_win,
- tmp_win->frame_x + event.xconfigure.x,
- tmp_win->frame_y + event.xconfigure.y - TITLE_BAR_HEIGHT - BorderWidth,
- event.xconfigure.width,
- event.xconfigure.height + TITLE_BAR_HEIGHT + BorderWidth);
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleUnknown - unknown event handler
- *
- ***********************************************************************
- */
-
- void
- HandleUnknown()
- {
- #ifdef DEBUG
- fprintf(stderr, "type = %d\n", event.type);
- #endif
- }
-
- /***********************************************************************
- *
- * Procedure:
- * HandleTitleButton - handle a button press event in the title bar
- *
- * Inputs:
- * w - the window effected by the button press
- * tmp_win - the TwmWindow structure
- * event - the X event structure for the button press
- *
- ***********************************************************************
- */
-
- HandleTitleButton(w, tmp_win, event)
- Window w;
- TwmWindow *tmp_win ;
- XEvent event;
- {
- static Time last_time = 0;
-
- if (event.xbutton.button > MAX_BUTTONS)
- return;
-
- switch (TitleButton[event.xbutton.button])
- {
- case T_NOP:
- break;
-
- case T_RAISE:
- if (w == tmp_win->icon_w)
- {
- XUnmapWindow(dpy, tmp_win->icon_w);
- XMapWindow(dpy, tmp_win->w);
- XMapRaised(dpy, tmp_win->frame);
- if (WarpCursor)
- {
- XWarpPointer(dpy, None, tmp_win->frame,
- 0, 0, 0, 0, 30, 8);
- }
- tmp_win->icon = FALSE;
- }
- else
- XRaiseWindow(dpy, tmp_win->frame);
- break;
-
- case T_LOWER:
- XLowerWindow(dpy, w);
- break;
-
- case T_MOVE:
- EventHandler[EnterNotify] = HandleUnknown;
- EventHandler[LeaveNotify] = HandleUnknown;
- XGrabServer(dpy);
- XGrabPointer(dpy, event.xbutton.root, True,
- ButtonReleaseMask | ButtonMotionMask,
- GrabModeAsync, GrabModeSync,
- Root, MoveCursor, CurrentTime);
-
- DragWindow = w;
-
- DragX = event.xbutton.x;
- DragY = event.xbutton.y;
-
- XGetGeometry(dpy, w, &JunkRoot, &JunkX, &JunkY,
- &DragWidth, &DragHeight, &JunkBW,
- &JunkDepth);
-
- MoveOutline((Window)event.xbutton.root,
- event.xbutton.x_root-DragX-BorderWidth,
- event.xbutton.y_root-DragY-BorderWidth,
- DragWidth + 2 * BorderWidth,
- DragHeight + 2 * BorderWidth);
-
- if ((event.xbutton.time - last_time) < 400)
- {
- int width, height;
-
- ConstMove = TRUE;
- ConstMoveDir = MOVE_NONE;
- ConstMoveX = event.xbutton.x_root - DragX - BorderWidth;
- ConstMoveY = event.xbutton.y_root - DragY - BorderWidth;
- width = DragWidth + 2 * BorderWidth;
- height = DragHeight + 2 * BorderWidth;
- ConstMoveXL = ConstMoveX + width/3;
- ConstMoveXR = ConstMoveX + 2*(width/3);
- ConstMoveYT = ConstMoveY + height/3;
- ConstMoveYB = ConstMoveY + 2*(height/3);
-
- XWarpPointer(dpy, None, w,
- 0, 0, 0, 0, DragWidth/2, DragHeight/2);
-
- XQueryPointer(dpy, DragWindow, &JunkRoot, &JunkChild,
- &JunkX, &JunkY, &DragX, &DragY, &JunkMask);
- }
- last_time = event.xbutton.time;
- break;
-
- }
- }
-