/** Draw a specific tray. */ void DrawSpecificTray(const TrayType *tp) { TrayComponentType *cp; for(cp = tp->components; cp; cp = cp->next) { UpdateSpecificTray(tp, cp); } if(settings.trayDecorations == DECO_MOTIF) { JXSetForeground(display, rootGC, colors[COLOR_TRAY_UP]); JXDrawLine(display, tp->window, rootGC, 0, 0, tp->width - 1, 0); JXDrawLine(display, tp->window, rootGC, 0, tp->height - 1, 0, 0); JXSetForeground(display, rootGC, colors[COLOR_TRAY_DOWN]); JXDrawLine(display, tp->window, rootGC, 0, tp->height - 1, tp->width - 1, tp->height - 1); JXDrawLine(display, tp->window, rootGC, tp->width - 1, 0, tp->width - 1, tp->height - 1); } else { JXSetForeground(display, rootGC, colors[COLOR_TRAY_DOWN]); JXDrawRectangle(display, tp->window, rootGC, 0, 0, tp->width - 1, tp->height - 1); } }
/** Clear the last outline. */ void ClearOutline() { if(outlineDrawn) { JXDrawRectangle(display, rootWindow, outlineGC, lastX, lastY, lastWidth, lastHeight); outlineDrawn = 0; JXUngrabServer(display); JXSync(display, False); } }
/** Draw an outline. */ void DrawOutline(int x, int y, int width, int height) { if(!outlineDrawn) { JXSync(display, False); JXGrabServer(display); JXDrawRectangle(display, rootWindow, outlineGC, x, y, width, height); lastX = x; lastY = y; lastWidth = width; lastHeight = height; outlineDrawn = 1; } }
/** Draw a button. */ void DrawButton(ButtonNode *bp) { ColorType fg; long bg1, bg2; long up, down; DecorationsType decorations; Drawable drawable; GC gc; int x, y; int width, height; int xoffset, yoffset; int iconWidth, iconHeight; int textWidth, textHeight; Assert(bp); drawable = bp->drawable; x = bp->x; y = bp->y; width = bp->width; height = bp->height; gc = JXCreateGC(display, drawable, 0, NULL); /* Determine the colors to use. */ switch(bp->type) { case BUTTON_LABEL: fg = COLOR_MENU_FG; bg1 = colors[COLOR_MENU_BG]; bg2 = colors[COLOR_MENU_BG]; up = colors[COLOR_MENU_UP]; down = colors[COLOR_MENU_DOWN]; decorations = settings.menuDecorations; break; case BUTTON_MENU_ACTIVE: fg = COLOR_MENU_ACTIVE_FG; bg1 = colors[COLOR_MENU_ACTIVE_BG1]; bg2 = colors[COLOR_MENU_ACTIVE_BG2]; down = colors[COLOR_MENU_ACTIVE_UP]; up = colors[COLOR_MENU_ACTIVE_DOWN]; decorations = settings.menuDecorations; break; case BUTTON_TRAY: fg = COLOR_TRAYBUTTON_FG; bg1 = colors[COLOR_TRAYBUTTON_BG1]; bg2 = colors[COLOR_TRAYBUTTON_BG2]; up = colors[COLOR_TRAYBUTTON_UP]; down = colors[COLOR_TRAYBUTTON_DOWN]; decorations = settings.trayDecorations; break; case BUTTON_TRAY_ACTIVE: fg = COLOR_TRAYBUTTON_ACTIVE_FG; bg1 = colors[COLOR_TRAYBUTTON_ACTIVE_BG1]; bg2 = colors[COLOR_TRAYBUTTON_ACTIVE_BG2]; down = colors[COLOR_TRAYBUTTON_ACTIVE_UP]; up = colors[COLOR_TRAYBUTTON_ACTIVE_DOWN]; decorations = settings.trayDecorations; break; case BUTTON_TASK: fg = COLOR_TASKLIST_FG; bg1 = colors[COLOR_TASKLIST_BG1]; bg2 = colors[COLOR_TASKLIST_BG2]; up = colors[COLOR_TASKLIST_UP]; down = colors[COLOR_TASKLIST_DOWN]; decorations = settings.trayDecorations; break; case BUTTON_TASK_ACTIVE: fg = COLOR_TASKLIST_ACTIVE_FG; bg1 = colors[COLOR_TASKLIST_ACTIVE_BG1]; bg2 = colors[COLOR_TASKLIST_ACTIVE_BG2]; down = colors[COLOR_TASKLIST_ACTIVE_UP]; up = colors[COLOR_TASKLIST_ACTIVE_DOWN]; decorations = settings.trayDecorations; break; case BUTTON_MENU: default: fg = COLOR_MENU_FG; bg1 = colors[COLOR_MENU_BG]; bg2 = colors[COLOR_MENU_BG]; up = colors[COLOR_MENU_UP]; down = colors[COLOR_MENU_DOWN]; decorations = settings.menuDecorations; break; } /* Draw the background. */ if(bp->fill) { /* Draw the button background. */ JXSetForeground(display, gc, bg1); if(bg1 == bg2) { /* single color */ JXFillRectangle(display, drawable, gc, x, y, width, height); } else { /* gradient */ DrawHorizontalGradient(drawable, gc, bg1, bg2, x, y, width, height); } } /* Draw the border. */ if(bp->border) { if(decorations == DECO_MOTIF) { JXSetForeground(display, gc, up); JXDrawLine(display, drawable, gc, x, y, x + width - 1, y); JXDrawLine(display, drawable, gc, x, y, x, y + height - 1); JXSetForeground(display, gc, down); JXDrawLine(display, drawable, gc, x, y + height - 1, x + width - 1, y + height - 1); JXDrawLine(display, drawable, gc, x + width - 1, y, x + width - 1, y + height - 1); } else { JXSetForeground(display, gc, down); JXDrawRectangle(display, drawable, gc, x, y, width - 1, height - 1); } } /* Determine the size of the icon (if any) to display. */ iconWidth = 0; iconHeight = 0; if(bp->icon) { if(bp->icon == &emptyIcon) { iconWidth = Min(width - 4, height - 4); iconHeight = iconWidth; } else { const int ratio = (bp->icon->width << 16) / bp->icon->height; iconHeight = height - 4; iconWidth = (iconHeight * ratio) >> 16; if(iconWidth > width - 4) { iconWidth = width - 4; iconHeight = (iconWidth << 16) / ratio; } } } /* Determine how much room is left for text. */ textWidth = 0; textHeight = 0; if(bp->text && (width > height || !bp->icon)) { textWidth = GetStringWidth(bp->font, bp->text); textHeight = GetStringHeight(bp->font); if(iconWidth > 0 && textWidth + iconWidth + 7 > width) { textWidth = width - iconWidth - 7; } else if(iconWidth == 0 && textWidth + 5 > width) { textWidth = width - 5; } textWidth = textWidth < 0 ? 0 : textWidth; } /* Determine the offset of the text in the button. */ if(bp->alignment == ALIGN_CENTER || width <= height) { xoffset = (width - iconWidth - textWidth + 1) / 2; if(xoffset < 0) { xoffset = 0; } } else { xoffset = 2; } /* Display the icon. */ if(bp->icon) { yoffset = (height - iconHeight + 1) / 2; PutIcon(bp->icon, drawable, colors[fg], x + xoffset, y + yoffset, iconWidth, iconHeight); xoffset += iconWidth + 2; } /* Display the label. */ if(textWidth > 0) { yoffset = (height - textHeight + 1) / 2; RenderString(drawable, bp->font, fg, x + xoffset, y + yoffset, textWidth, bp->text); } JXFreeGC(display, gc); }
/** Draw a button. */ void DrawButton(ButtonNode *bp) { long outlinePixel; long topPixel, bottomPixel; ColorType fg; long bg1, bg2; Drawable drawable; GC gc; int x, y; int width, height; int xoffset, yoffset; int iconWidth, iconHeight; int textWidth, textHeight; Assert(bp); drawable = bp->drawable; gc = bp->gc; x = bp->x; y = bp->y; width = bp->width; height = bp->height; /* Determine the colors to use. */ switch(bp->type) { case BUTTON_LABEL: fg = COLOR_MENU_FG; bg1 = colors[COLOR_MENU_BG]; bg2 = colors[COLOR_MENU_BG]; outlinePixel = colors[COLOR_MENU_BG]; topPixel = colors[COLOR_MENU_BG]; bottomPixel = colors[COLOR_MENU_BG]; break; case BUTTON_MENU_ACTIVE: fg = COLOR_MENU_ACTIVE_FG; bg1 = colors[COLOR_MENU_ACTIVE_BG1]; bg2 = colors[COLOR_MENU_ACTIVE_BG2]; if(bg1 == bg2) { outlinePixel = colors[COLOR_MENU_ACTIVE_OL]; } else { outlinePixel = colors[COLOR_MENU_ACTIVE_DOWN]; } topPixel = colors[COLOR_MENU_ACTIVE_UP]; bottomPixel = colors[COLOR_MENU_ACTIVE_DOWN]; break; case BUTTON_TASK: fg = COLOR_TASK_FG; bg1 = colors[COLOR_TASK_BG1]; bg2 = colors[COLOR_TASK_BG2]; topPixel = colors[COLOR_TASK_UP]; bottomPixel = colors[COLOR_TASK_DOWN]; outlinePixel = bottomPixel; break; case BUTTON_TASK_ACTIVE: fg = COLOR_TASK_ACTIVE_FG; bg1 = colors[COLOR_TASK_ACTIVE_BG1]; bg2 = colors[COLOR_TASK_ACTIVE_BG2]; topPixel = colors[COLOR_TASK_ACTIVE_DOWN]; bottomPixel = colors[COLOR_TASK_ACTIVE_UP]; outlinePixel = bottomPixel; break; case BUTTON_MENU: default: fg = COLOR_MENU_FG; bg1 = colors[COLOR_MENU_BG]; bg2 = colors[COLOR_MENU_BG]; outlinePixel = colors[COLOR_MENU_DOWN]; topPixel = colors[COLOR_MENU_UP]; bottomPixel = colors[COLOR_MENU_DOWN]; break; } /* Draw the background. */ switch(bp->type) { case BUTTON_TASK: /* Flat taskbuttons (only icon) for widths < 48 */ if(width < 48) { break; } /* conditional fallthrough is intended */ default: /* Draw the button background. */ JXSetForeground(display, gc, bg1); if(bg1 == bg2) { /* single color */ JXFillRectangle(display, drawable, gc, x + 1, y + 1, width - 1, height - 1); } else { /* gradient */ DrawHorizontalGradient(drawable, gc, bg1, bg2, x + 1, y + 1, width - 2, height - 1); } /* Draw the outline. */ JXSetForeground(display, gc, outlinePixel); #ifdef USE_XMU XmuDrawRoundedRectangle(display, drawable, gc, x, y, width, height, 3, 3); #else JXDrawRectangle(display, drawable, gc, x, y, width, height); #endif break; } /* Determine the size of the icon (if any) to display. */ iconWidth = 0; iconHeight = 0; if (bp->icon) { if(width < height) { GetScaledIconSize(bp->icon, width - 5, &iconWidth, &iconHeight); } else { GetScaledIconSize(bp->icon, height - 5, &iconWidth, &iconHeight); } } /* Determine how much room is left for text. */ textWidth = 0; textHeight = 0; if(bp->text) { textWidth = GetStringWidth(bp->font, bp->text); textHeight = GetStringHeight(bp->font); if(textWidth + iconWidth + 8 > width) { textWidth = width - iconWidth - 8; if(textWidth < 0) { textWidth = 0; } } } /* Determine the offset of the text in the button. */ switch(bp->alignment) { case ALIGN_CENTER: xoffset = width / 2 - (iconWidth + textWidth) / 2; if(xoffset < 0) { xoffset = 0; } break; case ALIGN_LEFT: default: xoffset = 3; break; } /* Display the icon. */ if(bp->icon) { yoffset = height / 2 - iconHeight / 2; PutIcon(bp->icon, drawable, x + xoffset, y + yoffset, iconWidth, iconHeight); xoffset += iconWidth + 2; } /* Display the label. */ if(bp->text && textWidth) { yoffset = height / 2 - textHeight / 2; RenderString(drawable, bp->font, fg, x + xoffset, y + yoffset, textWidth, NULL, bp->text); } }
/** Draw a button. */ void DrawButton(ButtonNode *bp) { ColorType fg; long bg1, bg2; long up, down; DecorationsType decorations; Drawable drawable; GC gc; int x, y; int width, height; int xoffset, yoffset; int iconWidth, iconHeight; int textWidth, textHeight; Assert(bp); char *printableName = bp->text; /* Check for E2 80 AA (LEFT-TO-RIGHT-EMBEDDING) character in the beginning and trim it (for Midori) */ if(strncmp(printableName, "\xe2\x80\xaa", 3) == 0) { printableName += 3; } drawable = bp->drawable; x = bp->x; y = bp->y; width = bp->width; height = bp->height; gc = JXCreateGC(display, drawable, 0, NULL); /* Determine the colors to use. */ switch(bp->type) { case BUTTON_LABEL: fg = COLOR_MENU_FG; bg1 = colors[COLOR_MENU_BG]; bg2 = colors[COLOR_MENU_BG]; up = colors[COLOR_MENU_UP]; down = colors[COLOR_MENU_DOWN]; decorations = settings.menuDecorations; break; case BUTTON_MENU_ACTIVE: fg = COLOR_MENU_ACTIVE_FG; bg1 = colors[COLOR_MENU_ACTIVE_BG1]; bg2 = colors[COLOR_MENU_ACTIVE_BG2]; down = colors[COLOR_MENU_ACTIVE_UP]; up = colors[COLOR_MENU_ACTIVE_DOWN]; decorations = settings.menuDecorations; break; case BUTTON_TRAY: case BUTTON_TASK: fg = COLOR_TRAY_FG; bg1 = colors[COLOR_TRAY_BG1]; bg2 = colors[COLOR_TRAY_BG2]; up = colors[COLOR_TRAY_UP]; down = colors[COLOR_TRAY_DOWN]; decorations = settings.trayDecorations; break; case BUTTON_TRAY_ACTIVE: case BUTTON_TASK_ACTIVE: fg = COLOR_TRAY_ACTIVE_FG; bg1 = colors[COLOR_TRAY_ACTIVE_BG1]; bg2 = colors[COLOR_TRAY_ACTIVE_BG2]; down = colors[COLOR_TRAY_ACTIVE_UP]; up = colors[COLOR_TRAY_ACTIVE_DOWN]; decorations = settings.trayDecorations; break; case BUTTON_MENU: default: fg = COLOR_MENU_FG; bg1 = colors[COLOR_MENU_BG]; bg2 = colors[COLOR_MENU_BG]; up = colors[COLOR_MENU_UP]; down = colors[COLOR_MENU_DOWN]; decorations = settings.menuDecorations; break; } /* Draw the background. */ if(bp->fill) { /* Draw the button background. */ JXSetForeground(display, gc, bg1); /* single color */ JXFillRectangle(display, drawable, gc, x, y, width, height); } /* Draw the border. */ if(bp->border) { JXSetForeground(display, gc, down); JXDrawRectangle(display, drawable, gc, x, y, width - 1, height - 1); } /* Determine the size of the icon (if any) to display. */ iconWidth = 0; iconHeight = 0; if(bp->icon) { if(bp->icon == &emptyIcon) { iconWidth = Min(width/2, height/2); iconHeight = iconWidth; } else { const int ratio = (bp->icon->images->width << 16) / bp->icon->images->height; iconHeight = height/2; iconWidth = (iconHeight * ratio) >> 16; if(iconWidth > width/2) { iconWidth = width/2; iconHeight = (iconWidth << 16) / ratio; } } } /* Determine how much room is left for text. */ textWidth = 0; textHeight = 0; if(printableName) { textWidth = GetStringWidth(bp->font, printableName); textHeight = GetStringHeight(bp->font); if(iconWidth > 0 && textWidth + iconWidth + 7 > width) { textWidth = width - iconWidth - textHeight*3/2; } else if(iconWidth == 0 && textWidth + 5 > width) { textWidth = width - 5; } textWidth = textWidth < 0 ? 0 : textWidth; } /* Determine the offset of the text in the button. */ if(bp->alignment == ALIGN_CENTER) { xoffset = (width - iconWidth - textWidth + 1) / 2; if(xoffset < 0) { xoffset = 0; } } else { xoffset = textHeight/2; } /* Display the icon. */ if(bp->icon) { yoffset = (height - iconHeight + 1) / 2; PutIcon(bp->icon, drawable, colors[fg], x + xoffset, y + yoffset, iconWidth, iconHeight); xoffset += iconWidth + textHeight/2; } /* Display the label. */ if(textWidth > 0) { yoffset = (height - textHeight + 1) / 2; RenderString(drawable, bp->font, fg, x + xoffset, y + yoffset, textWidth, printableName); } JXFreeGC(display, gc); }
/** Show a popup window. */ void ShowPopup(int x, int y, const char *text, const PopupMaskType context) { const ScreenType *sp; Assert(text); if(!(settings.popupMask & context)) { return; } if(popup.text) { if(x == popup.x && y == popup.y && !strcmp(popup.text, text)) { // This popup is already shown. return; } Release(popup.text); popup.text = NULL; } if(text[0] == 0) { return; } GetMousePosition(&popup.mx, &popup.my, &popup.mw); popup.text = CopyString(text); popup.height = GetStringHeight(FONT_POPUP) + 2; popup.width = GetStringWidth(FONT_POPUP, popup.text) + 9; sp = GetCurrentScreen(x, y); if(popup.width > sp->width) { popup.width = sp->width; } popup.x = x; if(y + 2 * popup.height + 2 >= sp->height) { popup.y = y - popup.height - 2; } else { popup.y = y + popup.height + 2; } if(popup.width + popup.x > sp->x + sp->width) { popup.x = sp->x + sp->width - popup.width - 2; } if(popup.height + popup.y > sp->y + sp->height) { popup.y = sp->y + sp->height - popup.height - 2; } if(popup.x < 2) { popup.x = 2; } if(popup.y < 2) { popup.y = 2; } if(popup.window == None) { XSetWindowAttributes attr; unsigned long attrMask = 0; attrMask |= CWEventMask; attr.event_mask = ExposureMask | PointerMotionMask | PointerMotionHintMask; attrMask |= CWSaveUnder; attr.save_under = True; attrMask |= CWDontPropagate; attr.do_not_propagate_mask = PointerMotionMask | ButtonPressMask | ButtonReleaseMask; popup.window = JXCreateWindow(display, rootWindow, popup.x, popup.y, popup.width, popup.height, 0, CopyFromParent, InputOutput, CopyFromParent, attrMask, &attr); SetAtomAtom(popup.window, ATOM_NET_WM_WINDOW_TYPE, ATOM_NET_WM_WINDOW_TYPE_NOTIFICATION); JXMapRaised(display, popup.window); } else { JXMoveResizeWindow(display, popup.window, popup.x, popup.y, popup.width, popup.height); JXFreePixmap(display, popup.pmap); } popup.pmap = JXCreatePixmap(display, popup.window, popup.width, popup.height, rootDepth); JXSetForeground(display, rootGC, colors[COLOR_POPUP_BG]); JXFillRectangle(display, popup.pmap, rootGC, 0, 0, popup.width - 1, popup.height - 1); JXSetForeground(display, rootGC, colors[COLOR_POPUP_OUTLINE]); JXDrawRectangle(display, popup.pmap, rootGC, 0, 0, popup.width - 1, popup.height - 1); RenderString(popup.pmap, FONT_POPUP, COLOR_POPUP_FG, 4, 1, popup.width, popup.text); JXCopyArea(display, popup.pmap, popup.window, rootGC, 0, 0, popup.width, popup.height, 0, 0); }