⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mwm.c

📁 安装DDD之前
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: mwm.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 * * Copyright (C) 1995-2002 LessTif Development Team * mwm - "LessTif Window Manager" ***********************************************************************/#include <LTconfig.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <ctype.h>#include <signal.h>#ifdef HAVE_FCNTL_H#include <fcntl.h>#endif#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#ifdef HAVE_SYS_WAIT_H#include <sys/wait.h>#endif#ifdef HAVE_SYS_STAT_H#include <sys/stat.h>#else#error "you lose (I don't know how to fix this)"#endif#ifdef HAVE_PWD_H#include <pwd.h>#endif#ifdef HAVE_GETRLIMIT#ifdef HAVE_SYS_TIME_H#include <sys/time.h>#endif#include <sys/resource.h>#endif#ifdef __EMX__#include <netdb.h>#include <X11/Xlibint.h>    /* for __XOS2RedirRoot() */#endif#include <X11/Intrinsic.h>#include <X11/Shell.h>#include <X11/Xproto.h>#include <Xm/Xm.h>#include <Xm/MwmUtil.h>#include <Xm/XmosP.h>#include <Xm/DisplayP.h>#include <Xm/ScreenP.h>#if XmVERSION >= 2#include <XmI/XmI.h>#endif#include "mwm.h"#ifndef HAVE_GETHOSTNAME/* our fallback implementation (gethostname.c) */extern int gethostname (char *name, size_t len);#endif/* * application globals */#define MAXHOSTNAME 255MwmInternalInfo Mwm;Display *dpy;			/* which display are we talking to */Widget toplevel;static Widget xmDisplay;static Boolean multiscreen = False;static char *mwm_name = "mwm";XContext MwmContext;		/* context for mwm windows */XContext MenuContext;		/* context for mwm menus */int JunkX = 0, JunkY = 0;Window JunkRoot, JunkChild;	/* junk window */unsigned int JunkWidth, JunkHeight, JunkBW, JunkDepth, JunkMask;char **g_argv;int fd_width, x_fd;static XtAppContext app;volatile int alarmed;Bool debugging = False;static int last_event_type = 0;/****************************************************************************//* * print usage */static voidusage(void){    fprintf(stderr,             "Mwm Ver %s\n\nusage: mwm [-display dpy] [-debug] [-xrm resourcestring] [-multiscreen] [-name name] [-screens name [name [...]]]\n",             VERSION);}/* * restart on a signal */static voidsig_restart(int sig){    MWM_Done(1, *g_argv);}/* * exit on a signal */static voidsig_done(int nonsense){    MWM_Done(0, NULL);}/* * For auto-raising windows, this routine is called */static voidsig_alarm(int nonsense){    alarmed = True;    signal(SIGALRM, sig_alarm);}/* * figures out if there's another WM running */static voidcatch_redirect(Display *dpy, XErrorEvent *event){    fprintf(stderr, "mwm: Error: Another WM is running\n");    exit(1); /* we don't return (this determines function type) */}/* * displays info on internal errors */static XErrorHandlergeneral_error(Display *dpy, XErrorEvent *event){    /* some errors are acceptable, mostly they're caused by      * trying to update a lost  window */    if ((event->error_code == BadWindow) ||	(event->request_code == X_GetGeometry) ||	(event->error_code == BadDrawable) ||	(event->request_code == X_SetInputFocus) ||	(event->request_code == X_GrabButton) ||	(event->request_code == X_ChangeWindowAttributes) ||	(event->request_code == X_InstallColormap))	return 0;    fprintf(stderr, "mwm: internal error");    fprintf(stderr, "      Request %d, Error %d\n", event->request_code,	    event->error_code);    fprintf(stderr, "      EventType: %d", last_event_type);    fprintf(stderr, "\n");    return 0;}/* * do global mwm initialization */static voidinitialize_mwm( void){    int i;    ScreenInfo *scr;    xmDisplay = XmGetXmDisplay(dpy);    RES_Initialize();    if (Mwm.multi_screen)	multiscreen = True;    EVENT_Initialize();    PROP_Initialize();    MwmContext = XUniqueContext();    MenuContext = XUniqueContext();    if (multiscreen)    {	Mwm.number_of_screens = ScreenCount(dpy);	Mwm.screen_info = (ScreenInfo **)XtMalloc(Mwm.number_of_screens *						  sizeof(ScreenInfo *));	for (i = 0; i < Mwm.number_of_screens; i++)	{	    scr = (ScreenInfo *)XtCalloc(1, sizeof(ScreenInfo));	    scr->screen = i;	    scr->root_win = RootWindow(dpy, scr->screen);	    if (scr->root_win == None)	    {		fprintf(stderr, "Screen %ld is not a valid screen", scr->screen);		exit(1);	    }	/*TODO: only default screen names are supported	 *   since '-screens' mwm command line option is not implemented yet	 *		A.R.	 */	    /* By default, the screen number is used for the screen name. */	    scr->screen_name = (String)XtMalloc(12);	    sprintf(scr->screen_name, "%lu", scr->screen);	    SCREEN_Initialize(scr);	    Mwm.screen_info[i] = scr;	}    }    else    {	Mwm.number_of_screens = 1;	Mwm.screen_info = (ScreenInfo **)XtMalloc(Mwm.number_of_screens *						  sizeof(ScreenInfo *));	scr = (ScreenInfo *)XtCalloc(1, sizeof(ScreenInfo));	scr->screen = DefaultScreen(dpy);	scr->root_win = RootWindow(dpy, scr->screen);	if (scr->root_win == None)	{	    fprintf(stderr, "Screen %ld is not a valid screen", scr->screen);	    exit(1);	}	/*TODO: only default screen names are supported	 *   since '-screens' mwm command line option is not implemented yet	 *		A.R.	 */	/* By default, the screen number is used for the screen name. */	scr->screen_name = (String)XtMalloc(12);	sprintf(scr->screen_name, "%lu", scr->screen);	SCREEN_Initialize(scr);	Mwm.screen_info[0] = scr;    }}/* * set the appropriate error handler */voidMWM_SetErrorHandler(int which){    if (which == REDIRECT)	XSetErrorHandler((XErrorHandler)catch_redirect);    else	XSetErrorHandler((XErrorHandler)general_error);}/* * cleanup and exit mwm */voidMWM_Done(int restart, const char *command){    ScreenInfo *scr;    int i, done, j;    for (i = 0; i < Mwm.number_of_screens; i++)    {	PAGER_MoveViewPort(Mwm.screen_info[i], 0, 0, False);	WIN_ReleaseWindows(Mwm.screen_info[i]);    }    /*     * serious cleanup     */    if (restart)    {	for (i = 0; i < Mwm.number_of_screens; i++)	{	    scr = Mwm.screen_info[i];	    DT_SaveState(scr);	    /* Really make sure that the connection is closed and cleared! */	    XSelectInput(dpy, scr->root_win, 0);	}	XSync(dpy, 0);	XCloseDisplay(dpy);	i = 0;	j = 0;	done = 0;	/* really need to destroy all windows, explicitly,	 * not sleep, but this is adequate for now */	_XmSleep(1);	ReapChildren();	execvp(command, g_argv);	fprintf(stderr, "MWM: Call of '%s' failed!!!!\n", command);	execvp(g_argv[0], g_argv);	/* that _should_ work */	fprintf(stderr, "MWM: Call of '%s' failed!!!!\n", g_argv[0]);    }    else    {	for (i = 0; i < Mwm.number_of_screens; i++)	    PROP_ClearBehavior(Mwm.screen_info[i]);	XCloseDisplay(dpy);	exit(0);    }}/* * ReapChildren - wait() for all dead child processes */voidReapChildren(void){#ifdef HAVE_WAITPID    while ((waitpid(-1, NULL, WNOHANG)) > 0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -