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

📄 uwm.c

📁 最简单的窗口管理器
💻 C
📖 第 1 页 / 共 2 页
字号:
        } else {            if (IsIcon(event_win, 0, 0, FALSE, NULL))                context = ICON;            else context = WINDOW;        }        /*         * Get the button event detail.         */        lo = ((XButtonPressedEvent *)&button_event)->button;        hi = ((XButtonPressedEvent *)&button_event)->state;        /*         * Determine which function was selected and invoke it.         */        for(bptr = Blist; bptr; bptr = bptr->next) {            if ((bptr->button != lo) ||                (((int)bptr->mask & ModMask) != hi))                continue;            if (bptr->context != context)                continue;            if (!(bptr->mask & ButtonDown))                continue;            /*             * Found a match! Invoke the function.             */            if ((*bptr->func)(event_win,                              (int)bptr->mask & ModMask,                              bptr->button,                              x, y,                              bptr->menu)) {                func_stat = TRUE;                break;            }        }        /*         * If the function ate the ButtonUp event, then restart the loop.         */        if (func_stat) continue;        while(TRUE) {            /*             * Wait for the next button event.             */            if (XPending(dpy) && GetButton(&button_event)) {                    /*                 * If it's not a release of the same button that was pressed,                 * don't do the function bound to 'ButtonUp'.                 */                if (button_event.type != ButtonRelease)                    break;                if (lo != ((XButtonReleasedEvent *)&button_event)->button)                    break;                if ((hi|ButtonMask(lo)) != 		     ((XButtonReleasedEvent *)&button_event)->state)                    break;                        /*                 * Okay, determine the event window and mouse coordinates.                 */                status = XTranslateCoordinates(dpy, 				    RootWindow(dpy, scr), RootWindow(dpy, scr),                                    ((XButtonReleasedEvent *)&button_event)->x,				    ((XButtonReleasedEvent *)&button_event)->y,                                    &x, &y,                                    &event_win);                if (status == FAILURE) break;                if (event_win == 0) {                        event_win = RootWindow(dpy, scr);                        context = ROOT;                } else {                    if (IsIcon(event_win, 0, 0, FALSE, NULL))                        context = ICON;                    else context = WINDOW;                }                        /*                 * Determine which function was selected and invoke it.                 */                for(bptr = Blist; bptr; bptr = bptr->next) {                            if ((bptr->button != lo) ||                        (((int)bptr->mask & ModMask) != hi))                        continue;                            if (bptr->context != context)                        continue;                            if (!(bptr->mask & ButtonUp))                        continue;                            /*                     * Found a match! Invoke the function.                     */                    (*bptr->func)(event_win,                                  (int)bptr->mask & ModMask,                                  bptr->button,                                  x, y,                                  bptr->menu);                }                break;            }                XQueryPointer(dpy, RootWindow(dpy, scr), 	    	&root, &event_win, &root_x, &root_y, &cur_x, &cur_y, &ptrmask);            if (!delta_done &&                ((abs(cur_x - x) > Delta) || (abs(cur_y - y) > Delta))) {                /*                 * Delta functions are done once (and only once.)                 */                delta_done = TRUE;                /*                 * Determine the new event window's coordinates.		 * from the original ButtonPress event                 */                status = XTranslateCoordinates(dpy, 			  RootWindow(dpy, scr), RootWindow(dpy, scr),			  down_x, down_y, &x, &y, &event_win);                if (status == FAILURE) break;                /*                 * Determine the event window and context.                 */                if (event_win == 0) {                        event_win = RootWindow(dpy, scr);                        context = ROOT;                } else {                    if (IsIcon(event_win, 0, 0, FALSE, NULL))                        context = ICON;                    else context = WINDOW;                }                    /*                 * Determine which function was selected and invoke it.                 */                for(bptr = Blist; bptr; bptr = bptr->next) {                            if ((bptr->button != lo) ||                        (((int)bptr->mask & ModMask) != hi))                        continue;                            if (bptr->context != context)                        continue;                            if (!(bptr->mask & DeltaMotion))                        continue;                            /*                     * Found a match! Invoke the function.                     */                    if ((*bptr->func)(event_win,                                      (int)bptr->mask & ModMask,                                      bptr->button,                                      x, y,                                      bptr->menu)) {                        func_stat = TRUE;                        break;                    }                }                /*                 * If the function ate the ButtonUp event,                 * then restart the loop.                 */                if (func_stat) break;            }        }    }}/* * Initialize the default bindings.  First, write the character array * out to a temp file, then point the parser to it and read it in. * Afterwards, we unlink the temp file. */InitBindings(){    char *mktemp();    char *tempfile = TEMPFILE;	/* Temporary filename. */    register FILE *fp;		/* Temporary file pointer. */    register char **ptr;	/* Default bindings string array pointer. */    /*     * Create and write the temp file.     */    sfilename = mktemp(tempfile);    if ((fp = fopen(tempfile, "w")) == NULL) {        perror("uwm: cannot create temp file");        exit(1);    }    for (ptr = DefaultBindings; *ptr; ptr++) {        fputs(*ptr, fp);        fputc('\n', fp);    }    fclose(fp);    /*     * Read in the bindings from the temp file and parse them.     */    if ((yyin = fopen(tempfile, "r")) == NULL) {        perror("uwm: cannot open temp file");        exit(1);    }    Lineno = 1;    yyparse();    fclose(yyin);    unlink(tempfile);    if (Startup_File_Error)        Error("Bad default bindings...aborting");    /*     * Parse the system startup file, if one exists.     */    if ((yyin = fopen(SYSFILE, "r")) != NULL) {        sfilename = SYSFILE;        Lineno = 1;        yyparse();        fclose(yyin);        if (Startup_File_Error)            Error("Bad system startup file...aborting");    }}/* * Verify menu bindings by checking that a menu that is mapped actually * exists.  Stash a pointer in the binding to the relevant menu info data * structure. * Check nested menu consistency. */VerifyMenuBindings(){    Binding *bptr;    MenuLink *mptr;    for(bptr = Blist; bptr; bptr = bptr->next) {        if (bptr->func == Menu) {            for(mptr = Menus; mptr; mptr = mptr->next) {                if(!(strcmp(bptr->menuname, mptr->menu->name))) {                    bptr->menu = mptr->menu;                    break;                }            }            if (mptr == NULL) {                fprintf(stderr,                        "uwm: non-existent menu reference: \"%s\"\n",                        bptr->menuname);                Startup_File_Error = TRUE;            }        }    }    CheckMenus();}/* * Verify that the menu variables have reasonable values */VerifyMenuVariables(){    /*     * If we pushrelative, we divide the window size by     * the push variable. If it's zero, we die a sad death.     * So lets use the default push value in this case.     */    if (!Pushval && Push) Pushval = DEF_PUSH;}/* * Check nested menu consistency by verifying that every menu line that * calls another menu references a menu that actually exists. */CheckMenus(){    MenuLink *ptr;    Bool errflag = FALSE;    for(ptr = Menus; ptr; ptr = ptr->next) {        if (ChkMline(ptr->menu))            errflag = TRUE;    }    if (errflag)        Error("Nested menu inconsistency");}Bool ChkMline(menu)MenuInfo *menu;{    MenuLine *ptr;    MenuLink *lptr;    Bool errflag = FALSE;    for(ptr = menu->line; ptr; ptr = ptr->next) {        if (ptr->type == IsMenuFunction) {            for(lptr = Menus; lptr; lptr = lptr->next) {                if(!(strcmp(ptr->text, lptr->menu->name))) {                    ptr->menu = lptr->menu;                    break;                }            }            if (lptr == NULL) {                fprintf(stderr,                        "uwm: non-existent menu reference: \"%s\"\n",                        ptr->text);                errflag = TRUE;            }        }    }    return(errflag);}/* * Grab the mouse buttons according to the bindings list. */Grab_Buttons(){    Binding *bptr;    for(bptr = Blist; bptr; bptr = bptr->next)        if ((bptr->context & (WINDOW | ICON | ROOT)) == ROOT) {	    /* don't grab buttons if you don't have to - allow application	    access to buttons unless context includes window or icon */	    NeedRootInput = TRUE;	}	else { 	    /* context includes a window, so must grab */	    Grab(bptr->mask);	}}/* * Grab a mouse button according to the given mask. */Grab(mask)unsigned int mask;{    unsigned int m = LeftMask | MiddleMask | RightMask;    switch (mask & m) {    case LeftMask:        XGrabButton(dpy, LeftButton,  mask & ModMask,		RootWindow(dpy, scr), TRUE, EVENTMASK,		GrabModeAsync, GrabModeAsync, None, LeftButtonCursor);        break;    case MiddleMask:        XGrabButton(dpy, MiddleButton,  mask & ModMask,		RootWindow(dpy, scr), TRUE, EVENTMASK,		GrabModeAsync, GrabModeAsync, None, MiddleButtonCursor);        break;    case RightMask:        XGrabButton(dpy, RightButton,  mask & ModMask,		RootWindow(dpy, scr), TRUE, EVENTMASK,		GrabModeAsync, GrabModeAsync, None, RightButtonCursor);        break;    }}/* * Restore cursor to normal state. */ResetCursor(button)int button;{    switch (button) {    case LeftButton:        XChangeActivePointerGrab(		dpy, EVENTMASK, LeftButtonCursor, CurrentTime);        break;    case MiddleButton:        XChangeActivePointerGrab(		dpy, EVENTMASK, MiddleButtonCursor, CurrentTime);        break;    case RightButton:        XChangeActivePointerGrab(		dpy, EVENTMASK, RightButtonCursor, CurrentTime);        break;    }}/* * error routine for .uwmrc parser */yyerror(s)char*s;{    fprintf(stderr, "uwm: %s: %d: %s\n", sfilename, Lineno, s);    Startup_File_Error = TRUE;}/* * Print usage message and quit. */Usage(){    fprintf (stderr,	     "usage:  %s [-display host:dpy] [-b] [-f filename]\n\n",	     Argv[0]);    fputs("The -b option bypasses system and default bindings\n", stderr);    fputs("The -f option specifies an additional startup file\n", stderr);    exit(1);}/* * error handler for X I/O errors */XIOError(dsp)Display *dsp;{    perror("uwm");    exit(3);}SetVarDefaults(){    strcpy(IFontName, DEF_FONT);    strcpy(PFontName, DEF_FONT);    strcpy(MFontName, DEF_FONT);    Delta = DEF_DELTA;    IBorderWidth = DEF_ICON_BORDER_WIDTH;    HIconPad = DEF_ICON_PADDING;    VIconPad = DEF_ICON_PADDING;    PBorderWidth = DEF_POP_BORDER_WIDTH;    PPadding = DEF_POP_PADDING;    MBorderWidth = DEF_MENU_BORDER_WIDTH;    HMenuPad = DEF_MENU_PADDING;    VMenuPad = DEF_MENU_PADDING;    Volume = DEF_VOLUME;    Pushval = DEF_PUSH;    FocusSetByUser = FALSE;}

⌨️ 快捷键说明

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