static void appicon_handle_menubutton(WAppIcon *aicon, XEvent *event) { WMenu *menu; WObjDescriptor *desc; WApplication *wapp; wapp = wApplicationOf(aicon->icon->owner->main_window); if (!wapp) return; if (event->xbutton.send_event && XGrabPointer(dpy, aicon->icon->core->window, True, ButtonMotionMask | ButtonReleaseMask | ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) { wwarning("pointer grab failed for appicon menu"); return; } menu = openApplicationMenu(wapp, event->xbutton.x_root, event->xbutton.y_root); /* allow drag select of menu */ desc = &menu->core->descriptor; event->xbutton.send_event = True; (*desc->handle_mousedown) (desc, event); wMenuDestroy(menu); }
void DestroyWindowMenu(WScreen *scr) { if (scr->window_menu) { scr->window_menu->entries[MC_MINIATURIZE]->text = NULL; scr->window_menu->entries[MC_MAXIMIZE]->text = NULL; scr->window_menu->entries[MC_SHADE]->text = NULL; scr->window_menu->entries[MC_SELECT]->text = NULL; wMenuDestroy(scr->window_menu, True); scr->window_menu = NULL; } }
static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int count, int *index) { WMenu *menu; int command; int code, pos; char title[300]; char rtext[300]; if (strlen(slist[*index]) > sizeof(title) - 1) { wwarning("appmenu: menu command size exceeded in window %lx", win); return NULL; } if (sscanf(slist[*index], "%i %i %n", &command, &code, &pos) < 2 || command != wmBeginMenu) { wwarning("appmenu: bad menu entry \"%s\" in window %lx", slist[*index], win); return NULL; } strcpy(title, &slist[*index][pos]); menu = wMenuCreateForApp(scr, title, *index == 1); if (!menu) return NULL; *index += 1; while (*index < count) { int ecode, etag, enab; if (sscanf(slist[*index], "%i", &command) != 1) { wMenuDestroy(menu, True); wwarning("appmenu: bad menu entry \"%s\" in window %lx", slist[*index], win); return NULL; } if (command == wmEndMenu) { *index += 1; break; } else if (command == wmNormalItem || command == wmDoubleItem) { WAppMenuData *data; WMenuEntry *entry; if (command == wmNormalItem) { if (sscanf(slist[*index], "%i %i %i %i %n", &command, &ecode, &etag, &enab, &pos) != 4 || ecode != code) { wMenuDestroy(menu, True); wwarning("appmenu: bad menu entry \"%s\" in window %lx", slist[*index], win); return NULL; } strcpy(title, &slist[*index][pos]); rtext[0] = 0; } else { if (sscanf(slist[*index], "%i %i %i %i %s %n", &command, &ecode, &etag, &enab, rtext, &pos) != 5 || ecode != code) { wMenuDestroy(menu, True); wwarning("appmenu: bad menu entry \"%s\" in window %lx", slist[*index], win); return NULL; } strcpy(title, &slist[*index][pos]); } if (!(data = malloc(sizeof(WAppMenuData)))) { wwarning("appmenu: out of memory making menu for window %lx", win); wMenuDestroy(menu, True); return NULL; } data->code = code; data->tag = etag; data->window = win; entry = wMenuAddCallback(menu, title, notifyClient, data); if (!entry) { wMenuDestroy(menu, True); wwarning("appmenu: out of memory creating menu for window %lx", win); free(data); return NULL; } if (rtext[0] != 0) entry->rtext = wstrdup(rtext); else entry->rtext = NULL; entry->free_cdata = free; *index += 1; } else if (command == wmSubmenuItem) { int ncode; WMenuEntry *entry; WMenu *submenu; if (sscanf(slist[*index], "%i %i %i %i %i %n", &command, &ecode, &etag, &enab, &ncode, &pos) != 5 || ecode != code) { wMenuDestroy(menu, True); wwarning("appmenu: bad menu entry \"%s\" in window %lx", slist[*index], win); return NULL; } strcpy(title, &slist[*index][pos]); *index += 1; submenu = parseMenuCommand(scr, win, slist, count, index); entry = wMenuAddCallback(menu, title, NULL, NULL); if (!entry) { wMenuDestroy(menu, True); wMenuDestroy(submenu, True); wwarning("appmenu: out of memory creating menu for window %lx", win); return NULL; } wMenuEntrySetCascade(menu, entry, submenu); } else { wMenuDestroy(menu, True); wwarning("appmenu: bad menu entry \"%s\" in window %lx", slist[*index], win); return NULL; } } return menu; }
void wAppMenuDestroy(WMenu * menu) { if (menu) wMenuDestroy(menu, True); }