?? windows.c
字號:
/* $Id: windows.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 placement code is by Rob Nation * * This code does smart-placement initial window placement stuff * * Copyright 1994 Robert Nation. No restrictions are placed on this code, * as long as the copyright notice is preserved . No guarantees or * warrantees of any sort whatsoever are given or implied or anything. ****************************************************************************//*********************************************************************** * The rest of it is all my fault -- MLM * mwm - "LessTif Window Manager" ***********************************************************************/#include <LTconfig.h>#include <stdio.h>#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include <X11/Intrinsic.h>#include <X11/extensions/shape.h>#include <Xm/Xm.h>#include <Xm/MwmUtil.h>#include "mwm.h"/* * some macros used by the constraint code */#define makemult(a,b) ((b==1) ? (a) : (((int)((a)/(b))) * (b)) )#define _min(a,b) (((a) < (b)) ? (a) : (b))#define MaxAspectX(t) ((t)->hints.max_aspect.x)#define MaxAspectY(t) ((t)->hints.max_aspect.y)#define MinAspectX(t) ((t)->hints.min_aspect.x)#define MinAspectY(t) ((t)->hints.min_aspect.y)static Boolean PPosOverride = False;static long isIconicState = 0;char NoName[] = "Untitled"; /* name if no name is specified *//* * check to see if we should really put a mwm frame on the window */static Booleanmapped_not_override(ScreenInfo *scr, Window w){ XWindowAttributes wa; Atom atype; int aformat; unsigned long nitems, bytes_remain; unsigned char *prop; isIconicState = DontCareState; if (!XGetWindowAttributes(dpy, w, &wa)) return False; if (XGetWindowProperty(dpy, w, XA_WM_STATE, 0L, 3L, False, XA_WM_STATE, &atype, &aformat, &nitems, &bytes_remain, &prop) == Success) { if (prop != NULL) { isIconicState = *(long *)prop; XFree(prop); } } if (w == scr->pager_win) return True; if ((isIconicState == IconicState || wa.map_state != IsUnmapped) && wa.override_redirect != True) return True; return False;}/* * map gravity to (x,y) offset signs for adding to x and y when window is * mapped to get proper placement. */static voidget_gravity_offsets(MwmWindow *tmp, int *xp, int *yp){ static struct _gravity_offset { int x, y; } gravity_offsets[11] = { { 0, 0 } , /* ForgetGravity */ { -1, -1 } , /* NorthWestGravity */ { 0, -1 } , /* NorthGravity */ { 1, -1 } , /* NorthEastGravity */ { -1, 0 } , /* WestGravity */ { 0, 0 } , /* CenterGravity */ { 1, 0 } , /* EastGravity */ { -1, 1 } , /* SouthWestGravity */ { 0, 1 } , /* SouthGravity */ { 1, 1 } , /* SouthEastGravity */ { 0, 0 } , /* StaticGravity */ }; register int g = ((tmp->hints.flags & PWinGravity) ? tmp->hints.win_gravity : NorthWestGravity); if (g < ForgetGravity || g > StaticGravity) *xp = *yp = 0; else { *xp = (int)gravity_offsets[g].x; *yp = (int)gravity_offsets[g].y; }}/* * grab needed buttons for the window */static voidgrab_buttons(ScreenInfo *scr, MwmWindow *tmp_win){ MouseButton *MouseEntry; MouseEntry = scr->buttons; while (MouseEntry != (MouseButton *)0) { if ((MouseEntry->func != (int)0) && (MouseEntry->context & C_WINDOW)) { if (MouseEntry->button > 0) { XGrabButton(dpy, MouseEntry->button, MouseEntry->modifier, tmp_win->w, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, scr->cursors[DEFAULT_CURS]); if (MouseEntry->modifier != AnyModifier) { XGrabButton(dpy, MouseEntry->button, (MouseEntry->modifier | LockMask), tmp_win->w, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, scr->cursors[DEFAULT_CURS]); } } else { XGrabButton(dpy, 1, MouseEntry->modifier, tmp_win->w, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, scr->cursors[DEFAULT_CURS]); XGrabButton(dpy, 2, MouseEntry->modifier, tmp_win->w, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, scr->cursors[DEFAULT_CURS]); XGrabButton(dpy, 3, MouseEntry->modifier, tmp_win->w, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, scr->cursors[DEFAULT_CURS]); if (MouseEntry->modifier != AnyModifier) { XGrabButton(dpy, 1, (MouseEntry->modifier | LockMask), tmp_win->w, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, scr->cursors[DEFAULT_CURS]); XGrabButton(dpy, 2, (MouseEntry->modifier | LockMask), tmp_win->w, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, scr->cursors[DEFAULT_CURS]); XGrabButton(dpy, 3, (MouseEntry->modifier | LockMask), tmp_win->w, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, scr->cursors[DEFAULT_CURS]); } } } MouseEntry = MouseEntry->next; }}/* * grab needed keys for the window */static voidgrab_keys(ScreenInfo *scr, MwmWindow *tmp_win){ FuncKey *tmp; for (tmp = scr->keys; tmp != NULL; tmp = tmp->next) { if (tmp->cont & (C_WINDOW | C_TITLE | C_RALL | C_LALL | C_FRAME)) { XGrabKey(dpy, tmp->keycode, tmp->mods, tmp_win->frame, True, GrabModeAsync, GrabModeAsync); if (tmp->mods != AnyModifier) { XGrabKey(dpy, tmp->keycode, tmp->mods | LockMask, tmp_win->frame, True, GrabModeAsync, GrabModeAsync); } } }}/* * set the contexts for the various windows */static voidsave_context(MwmWindow *tmp_win){ int i; XSaveContext(dpy, tmp_win->w, MwmContext, (XPointer)tmp_win); XSaveContext(dpy, tmp_win->frame, MwmContext, (XPointer)tmp_win); XSaveContext(dpy, tmp_win->parent, MwmContext, (XPointer)tmp_win); if (tmp_win->decorations & MWM_DECOR_TITLE) { XSaveContext(dpy, tmp_win->title, MwmContext, (XPointer)tmp_win); if (tmp_win->menub != None) XSaveContext(dpy, tmp_win->menub, MwmContext, (XPointer)tmp_win); if (tmp_win->minimizeb != None) XSaveContext(dpy, tmp_win->minimizeb, MwmContext, (XPointer)tmp_win); if (tmp_win->maximizeb != None) XSaveContext(dpy, tmp_win->maximizeb, MwmContext, (XPointer)tmp_win); } if (tmp_win->decorations & MWM_DECOR_BORDER) { for (i = 0; i < 4; i++) { XSaveContext(dpy, tmp_win->sides[i], MwmContext, (XPointer)tmp_win); } } if (tmp_win->decorations & MWM_DECOR_RESIZEH) { for (i = 0; i < 4; i++) { XSaveContext(dpy, tmp_win->corners[i], MwmContext, (XPointer)tmp_win); } }}/* * The function below, in its previous life, tried to allocate a window * such that it wouldn't overlap with others. I guess this comes from fvwm. * If the result (x and y) are negative, our caller will prompt the user * to let him interactively position the window. * * As far as I know mwm isn't supposed to behave like this so I really * disabled that functionality. * * Danny 19/4/1997 * * Converted this to a resource file setting. MLM (sometime in August 97). */#define INC 25/* * try to be smart about how to place the window */static voidsmart_placement(ScreenInfo *scr, MwmWindow *t, int width, int height, int *x, int *y){ int temp_h, temp_w; int test_x = 0, test_y = 0; int loc_ok = False, tw, tx, ty, th; MwmWindow *test_window; static int last_x = 0, last_y = 0, begin_x = INC, begin_y = INC; temp_h = height; temp_w = width; if (!scr->smart_placement) { if (t == NULL) { test_x = test_y = -1; } else { test_x = t->frame_x; test_y = t->frame_y; /* If the user specified a position, grant it */ if (t->hints.flags & USPosition) { *x = test_x; *y = test_y; return; } /* Otherwise, we need to make up a position. * Let's start near the top left of the screen, always move a bit * to the lower right with each next window, until a window would * fall of the screen either on the right or on the bottom edge. * When that happens, start near the upper left again. * The upper left starting point should change somewhat too. */#if 0 if (test_x == 0 && test_y == 0)#endif { last_x += INC; last_y += INC; test_x = last_x; test_y = last_y; if (t->frame_width + last_x >= scr->d_width || t->frame_height + last_y >= scr->d_height) { begin_x += INC; begin_y = INC; test_x = last_x = begin_x; test_y = last_y = begin_y; if (begin_x > scr->d_width / 2) begin_x = begin_y = INC; } /* Is this window simply too big ? */ if (t->frame_width + last_x >= scr->d_width) test_x = 0; if (t->frame_height + last_y >= scr->d_height) test_y = 0; } } } /* smart placement */ else { while (((test_y + temp_h) < (scr->d_height)) && (!loc_ok)) { test_x = 0; while (((test_x + temp_w) < (scr->d_width)) && (!loc_ok)) { loc_ok = True; test_window = scr->mwm_root.next; while ((test_window != (MwmWindow *)0) && (loc_ok == True)) { if (test_window->Desk == scr->current_desk) { if (scr->flags & StubbornPlacement) { if ((test_window->flags & ICONIFIED) && (!(test_window->flags & ICON_UNMAPPED)) && (test_window->icon_w) && (test_window != t)) { tw = test_window->icon_p_width; th = test_window->icon_p_height + test_window->icon_w_height; tx = test_window->icon_x_loc; ty = test_window->icon_y_loc; if ((tx < (test_x + width)) && ((tx + tw) > test_x) && (ty < (test_y + height)) && ((ty + th) > test_y)) { loc_ok = False; test_x = tx + tw; } } } if (!(test_window->flags & ICONIFIED) && (test_window != t)) { tw = test_window->frame_width + 2 * test_window->bw; th = test_window->frame_height + 2 * test_window->bw; tx = test_window->frame_x; ty = test_window->frame_y; if ((tx <= (test_x + width)) && ((tx + tw) >= test_x) && (ty <= (test_y + height)) && ((ty + th) >= test_y)) { loc_ok = False; test_x = tx + tw; } } } test_window = test_window->next; } test_x += 1; } test_y += 1; } if (loc_ok == False) { *x = -1; *y = -1; return; } } *x = test_x; *y = test_y;}/* * Handles initial placement and sizing of a new window. Returns False in * the event of a lost window. */static Booleanplace_window(ScreenInfo *scr, MwmWindow *tmp_win)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -