📄 menus.c
字号:
} if (mi->menu == NULL) { fprintf(stderr, "Can't find requested menu: %s", mi->action); mi->func = F_NOP; } } if (mi == mr->last) break; else mi = mi->next; } } for (mb = scr->buttons; mb != NULL; mb = mb->next) { if (mb->func == F_POPUP || mb->func == F_W_POPUP) { for (k = 0; k < scr->num_popups; k++) { if (strcmp(scr->popups[k]->name, (char *)mb->menu) == 0) { mb->menu = scr->popups[k]; break; } } if (mb->menu == NULL) { fprintf(stderr, "Can't find requested menu: %s", mi->action); mb->func = F_NOP; } } } for (fk = scr->keys; fk != NULL; fk = fk->next) { if (fk->func == F_POPUP || fk->func == F_W_POPUP) { for (k = 0; k < scr->num_popups; k++) { if (strcmp(scr->popups[k]->name, fk->action) == 0) { fk->menu = scr->popups[k]; break; } } if (fk->menu == NULL) { fprintf(stderr, "Can't find requested menu: %s", mi->action); fk->func = F_NOP; } } }}/* * do a window menu popup */intMENU_WinMenu(ScreenInfo *scr, MenuRoot *menu, MwmWindow *win, Boolean button, Boolean icon){ int prevStashedX = 0, prevStashedY = 0; MenuRoot *PrevActiveMenu = 0; MenuItem *PrevActiveItem = 0; int retval = MENU_NOP; int x, y; /* this condition could get ugly */ if (menu->in_use) return MENU_ERROR; if (!win) return MENU_ERROR; /* * In case we wind up with a move from a menu which is * from a window border, we'll return to here to start * the move. At least, if we came from a button press */ x = y = 0; if (button && !icon) { XQueryPointer(dpy, scr->root_win, &JunkRoot, &JunkChild, &x, &y, &JunkX, &JunkY, &JunkMask); } else if ((win->flags & ICONIFIED) && win->icon_w != None) { /* the icon window had better be a child of the root window */ if (win->icon_pixmap_w != None) { XGetGeometry(dpy, win->icon_pixmap_w, &JunkRoot, &x, &y, &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); } else { XGetGeometry(dpy, win->icon_w, &JunkRoot, &x, &y, &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); } if (y - menu->height > 0) { y -= menu->height; } else { y += JunkHeight; } } else { XGetGeometry(dpy, win->w, &JunkRoot, &JunkX, &JunkY, &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); XTranslateCoordinates(dpy, win->w, scr->root_win, JunkX, JunkY, &x, &y, &JunkChild); x -= win->matte_width; y -= win->matte_width; } if (!MISC_Grab(scr, MENU_CURS)) { XBell(dpy, scr->screen); return MENU_DONE; } if (pop_up_menu(scr, menu, x, y)) { retval = update_menu(scr, win); } else { XBell(dpy, scr->screen); } ActiveMenu = PrevActiveMenu; ActiveItem = PrevActiveItem; if ((ActiveItem) && (menu_on)) { ActiveItem->state = 1; } Stashed_X = prevStashedX; Stashed_Y = prevStashedY; if (!menu_on) { MISC_Ungrab(scr); } return retval;}/* * Initiates a menu pop-up */intMENU_PopupMenu(ScreenInfo *scr, MenuRoot * menu){ int prevStashedX = 0, prevStashedY = 0; MenuRoot *PrevActiveMenu = 0; MenuItem *PrevActiveItem = 0; int retval = MENU_NOP; int x, y, d; /* this condition could get ugly */ if (menu->in_use) return MENU_ERROR; /* In case we wind up with a move from a menu which is * from a window border, we'll return to here to start * the move */ XQueryPointer(dpy, scr->root_win, &JunkRoot, &JunkChild, &x, &y, &JunkX, &JunkY, &JunkMask); x -= (menu->width >> 1); y -= ((scr->components[MWM_MENU].f_height + HEIGHT_EXTRA) >> 1); if (menu_on) { prevStashedX = Stashed_X; prevStashedY = Stashed_Y; PrevActiveMenu = ActiveMenu; PrevActiveItem = ActiveItem; /* this d is from paint_entry() */ d = (scr->components[MWM_MENU].f_height + HEIGHT_EXTRA - 7) / 2; if (ActiveMenu) x = Stashed_X + (ActiveMenu->width ) -d ; if (ActiveItem) y = ActiveItem->y_offset + MenuY + ((scr->components[MWM_MENU].f_height + HEIGHT_EXTRA) >> 2); } else { if (!MISC_Grab(scr, MENU_CURS)) { XBell(dpy, scr->screen); return MENU_DONE; } x += (menu->width >> 1) - 3; } if (pop_up_menu(scr, menu, x, y)) { retval = update_menu(scr, NULL); } else XBell(dpy, scr->screen); ActiveMenu = PrevActiveMenu; ActiveItem = PrevActiveItem; if ((ActiveItem) && (menu_on)) ActiveItem->state = 1; Stashed_X = prevStashedX; Stashed_Y = prevStashedY; if (!menu_on) MISC_Ungrab(scr); return retval;}/* * destroy one menu */voidMENU_Destroy(MenuRoot * menu){ MenuItem *mi, *tmp; if (!menu) return; XDestroyWindow(dpy, menu->w); for (mi = menu->first; mi != NULL; mi = tmp) { tmp = mi->next; XtFree((char *)mi); mi = tmp; } XtFree((char *)menu);}/* * destroy all menus */voidMENU_DestroyMenus(ScreenInfo *scr){ int i; for (i = 0; i < scr->num_popups; i++) if (scr->popups[i]->w != None) XDestroyWindow(dpy, scr->popups[i]->w);}/* * reset the menuing system */voidMENU_Reset(void){ ActiveItem = NULL; ActiveMenu = NULL;}#define INTERNAL_MENU "INTERNAL_MWM_WIN_MENU_"/* * if the user has a custom window menu, build it */voidMENU_BuildWindowMenu(ScreenInfo *scr, MwmWindow *win){ MenuRoot *mr, *def; char *buf; int i; MenuItem *mi, *tmp; mr = NULL; if (win->mwm_menu && strlen(win->mwm_menu) != 0) { buf = XtMalloc(strlen(win->mwm_menu) + 64); sprintf(buf, "Menu %s {\n", INTERNAL_MENU); strcat(buf, win->mwm_menu); strcat(buf, "\n}"); PARSE_buf(scr, buf); for (i = 0; i < scr->num_popups; i++) { if (strcmp(scr->popups[i]->name, INTERNAL_MENU) == 0) break; } if (i == scr->num_popups) { fprintf(stderr, "Couldn't find user defined menu!\n"); return; } mr = scr->popups[i]; MENU_Remove(scr, mr); win->custom_menu = mr; } for (i = 0; i < scr->num_popups; i++) { if (strcmp(scr->popups[i]->name, win->window_menu) == 0) break; } if (i == scr->num_popups) { fprintf(stderr, "Couldn't find default window menu!\n"); return; } def = scr->popups[i]; if (mr) { if (def->width > mr->width) mr->width = def->width; if (def->width2 > mr->width2) mr->width2 = def->width2; } else { mr = (MenuRoot *) XtMalloc(sizeof(MenuRoot)); memcpy(mr, def, sizeof(MenuRoot)); mr->first = mr->last = NULL; } for (mi = def->last; mi != NULL; mi = mi->prev) { tmp = (MenuItem *)XtMalloc(sizeof(MenuItem)); memcpy(tmp, mi, sizeof(MenuItem)); if (mr->first == NULL) { mr->first = tmp; tmp->prev = NULL; tmp->next = NULL; } else { tmp->next = mr->first; mr->first->prev = tmp; mr->first = tmp; } if (mr->last == NULL) mr->last = tmp; mr->items++; } MENU_Realize(scr, mr);}/* * if a window has a custom window menu, destroy it */voidMENU_DestroyWindowMenu(ScreenInfo *scr, MwmWindow *win){ if (!win->custom_menu) return; MENU_Destroy(win->custom_menu); win->custom_menu = NULL;}/* * convert a keysym and a mod mask into a string */char *MENU_AcceleratorString(ScreenInfo *scr, KeySym keysym, int modifiers){ Boolean haveone = False; static char buf[128]; char *key; buf[0] = 0; if (modifiers & ControlMask) { strcat(buf, "<Ctrl"); haveone = True; } if (modifiers & ShiftMask) { if (haveone) strcat(buf, "+"); else strcat(buf, "<"); strcat(buf, "Shift"); haveone = True; } if (modifiers & scr->alt_mask) { if (haveone) strcat(buf, "+"); else strcat(buf, "<"); strcat(buf, "Alt"); haveone = True; } if (modifiers & LockMask) { if (haveone) strcat(buf, "+"); else strcat(buf, "<"); strcat(buf, "Lock"); haveone = True; } if (modifiers & Mod1Mask && scr->alt_mask != Mod1Mask) { if (haveone) strcat(buf, "+"); else strcat(buf, "<"); strcat(buf, "Mod1"); haveone = True; } if (modifiers & Mod2Mask && scr->alt_mask != Mod2Mask) { if (haveone) strcat(buf, "+"); else strcat(buf, "<"); strcat(buf, "Mod2"); haveone = True; } if (modifiers & Mod3Mask && scr->alt_mask != Mod3Mask) { if (haveone) strcat(buf, "+"); else strcat(buf, "<"); strcat(buf, "Mod3"); haveone = True; } if (modifiers & Mod4Mask && scr->alt_mask != Mod4Mask) { if (haveone) strcat(buf, "+"); else strcat(buf, "<"); strcat(buf, "Mod4"); haveone = True; } if (modifiers & Mod5Mask && scr->alt_mask != Mod5Mask) { if (haveone) strcat(buf, "+"); else strcat(buf, "<"); strcat(buf, "Mod5"); haveone = True; } if ((key = XKeysymToString(keysym)) != NULL) { if (haveone) strcat(buf, ">"); strcat(buf, key); } return buf;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -