?? misc.c
字號(hào):
/* $Id: misc.c,v 1.1 2004/08/28 19:25:46 dannybackx Exp $ *//*****************************************************************************//** 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. **//*****************************************************************************//**************************************************************************** * This module is based on Twm, but has been siginificantly modified * by Rob Nation ****************************************************************************//*********************************************************************** * The rest of it is all my fault -- MLM * mwm - "LessTif Window Manager" ***********************************************************************/#include <LTconfig.h>#include <stdio.h>#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#ifdef HAVE_SYS_TIME_H#include <sys/time.h>#endif#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include <X11/Intrinsic.h>#include <X11/keysym.h>#include <Xm/Xm.h>#include <Xm/MwmUtil.h>#include <Xm/XmosP.h>#if XmVERSION >= 2#include <XmI/XmI.h>#endif#include "mwm.h"/* * find a window in the tree */static MwmWindow *find_by_window(MwmWindow *win, Window w){ MwmWindow *child, *tmp; if (win->w == w) return win; /* search breadth first */ for (tmp = win->next; tmp != NULL; tmp = tmp->next) { if ((child = find_by_window(tmp, w)) != NULL) return child; } /* then depth */ for (tmp = win->child; tmp != NULL; tmp = tmp->child) { if ((child = find_by_window(tmp, w)) != NULL) return child; } return NULL;}/* * find a window in the tree. Returns a SIBLING in a window group. The * caller must determine if the ancestor is valid. */static MwmWindow *find_by_group(MwmWindow *win, XID group){ MwmWindow *child, *tmp; if (win->wmhints && (win->wmhints->flags & WindowGroupHint) && win->wmhints->window_group == group) { return win; } tmp = win->next; if (tmp != NULL) { if ((child = find_by_group(tmp, group)) != NULL) { return child; } } tmp = win->child; if (tmp != NULL) { if ((child = find_by_group(tmp, group)) != NULL) { return child; } } return NULL;}/* * add a new child to a window group */static voidadd_child(MwmWindow *win, MwmWindow *child){ if (win == NULL || child == NULL) return; if (win->child == NULL) { win->child = child; child->ancestor = win; child->next = child->prev = NULL; return; } child->ancestor = win; child->next = win->child; child->next->prev = child; win->child = child;}/* * remove a child from a window group * the child itself may have transient children. These must be taken * care of elsewhere */static voidremove_child(MwmWindow *win, MwmWindow *child){ if (child == NULL || win == NULL) return; if (win->child == child) { win->child = child->next; if (child->next != NULL) child->next->prev = NULL; child->next = child->prev = child->ancestor = NULL; return; } if (child->next != NULL) child->next->prev = child->prev; child->prev->next = child->next; child->next = child->prev = child->ancestor = NULL;}/* * print one window tree */static voidprint_window_tree(MwmWindow *win, int depth){ int i; MwmWindow *tmp; if (win == NULL) { for (i = 0; i < depth; i++) printf(" "); printf("none\n"); return; } for (tmp = win; tmp != NULL; tmp = tmp->next) { for (i = 0; i < depth; i++) printf(" "); if (tmp->name) printf("Window: %08lx %s\n", tmp->w, tmp->name); else printf("Window: %08lx\n", tmp->w); for (i = 0; i < depth; i++) printf(" "); printf("Children:\n"); print_window_tree(win->child, depth + 4); }}/* * see if a window is in a subtree */static Booleanwindow_in_subtree(MwmWindow *win, MwmWindow *sub){ MwmWindow *tmp; if (sub == win) return True; for (tmp = win->child; tmp != NULL; tmp = tmp->next) { if (window_in_subtree(tmp, sub)) return True; } return False;}/* * Removes expose events for a specific window from the queue */extern intMISC_FlushExpose(Window w){ XEvent dummy; int i = 0; while (XCheckTypedWindowEvent(dpy, w, Expose, &dummy)) i++; return i;}/* * Start/Stops the auto-raise timer */extern voidMISC_SetTimer(int delay){#ifdef HAVE_SETITIMER struct itimerval value; value.it_value.tv_usec = 1000 * (delay % 1000); value.it_value.tv_sec = delay / 1000; value.it_interval.tv_usec = 0; value.it_interval.tv_sec = 0; setitimer(ITIMER_REAL, &value, NULL);#endif}/* * Records the time of the last processed event. Used in XSetInputFocus */extern BooleanMISC_StashEventTime(XEvent *ev){ Time NewTimestamp = CurrentTime; switch (ev->type) { case KeyPress: case KeyRelease: NewTimestamp = ev->xkey.time; break; case ButtonPress: case ButtonRelease: NewTimestamp = ev->xbutton.time; break; case MotionNotify: NewTimestamp = ev->xmotion.time; break; case EnterNotify: case LeaveNotify: NewTimestamp = ev->xcrossing.time; break; case PropertyNotify: NewTimestamp = ev->xproperty.time; break; case SelectionClear: NewTimestamp = ev->xselectionclear.time; break; case SelectionRequest: NewTimestamp = ev->xselectionrequest.time; break; case SelectionNotify: NewTimestamp = ev->xselection.time; break; default: return False; } if (NewTimestamp > lastTimestamp) lastTimestamp = NewTimestamp; return True;}/* * fetch the last saved time */extern TimeMISC_FetchEventTime(){ return lastTimestamp;}/****************************************************************************** * * Cleare the CIRCULATED field of the window flags. * *****************************************************************************/extern voidMISC_SetFocusSequence(ScreenInfo *scr){ MwmWindow *temp; int i = 0; temp = scr->mwm_root.next; while (temp != NULL) { temp->focus_sequence = i++; temp = temp->next; }}/***************************************************************************** * * Grab the pointer and keyboard * ****************************************************************************/extern BooleanMISC_Grab(ScreenInfo *scr, int cursor){ int i = 0, val = 0; unsigned int mask; XSync(dpy, 0); /* move the keyboard focus prior to grabbing the pointer to * eliminate the enterNotify and exitNotify events that go * to the windows */ if (scr->mwm_last_focus == NULL) scr->mwm_last_focus = scr->mwm_focus; WIN_SetFocus(scr, scr->no_focus_win, NULL); mask = ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask; while ((i < 1000) && (val = XGrabPointer(dpy, scr->root_win, True, mask, GrabModeAsync, GrabModeAsync, scr->root_win, scr->cursors[cursor], CurrentTime) != GrabSuccess)) {
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -