/** Show a confirm dialog. */ void ShowConfirmDialog(ClientNode *np, void (*action)(ClientNode*), ...) { va_list ap; DialogType *dp; XSetWindowAttributes attrs; XSizeHints shints; Window window; char *str; int x; Assert(action); dp = Allocate(sizeof(DialogType)); dp->client = np; dp->action = action; dp->buttonState = DBS_NORMAL; dp->prev = NULL; dp->next = dialogList; if(dialogList) { dialogList->prev = dp; } dialogList = dp; /* Get the number of lines. */ va_start(ap, action); for(dp->lineCount = 0; va_arg(ap, char*); dp->lineCount++); va_end(ap); dp->message = Allocate(dp->lineCount * sizeof(char*)); va_start(ap, action); for(x = 0; x < dp->lineCount; x++) { str = va_arg(ap, char*); dp->message[x] = CopyString(str); } va_end(ap); ComputeDimensions(dp); attrs.background_pixel = colors[COLOR_TRAY_BG]; attrs.event_mask = ButtonReleaseMask | ExposureMask; window = JXCreateWindow(display, rootWindow, dp->x, dp->y, dp->width, dp->height, 0, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWEventMask, &attrs); shints.x = dp->x; shints.y = dp->y; shints.flags = PPosition; JXSetWMNormalHints(display, window, &shints); JXStoreName(display, window, "Confirm"); dp->node = AddClientWindow(window, 0, 0); Assert(dp->node); if(np) { dp->node->owner = np->window; } dp->node->state.status |= STAT_WMDIALOG; FocusClient(dp->node); DrawConfirmDialog(dp); JXGrabButton(display, AnyButton, AnyModifier, window, True, ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None); }
/** Show a confirm dialog. */ void ShowConfirmDialog(ClientNode *np, void (*action)(ClientNode*), ...) { va_list ap; XSetWindowAttributes attrs; XSizeHints shints; Window window; char *str; int x; Assert(action); /* Only allow one dialog at a time. */ if(dialog) { DestroyConfirmDialog(); } dialog = Allocate(sizeof(DialogType)); dialog->client = np ? np->window : None; dialog->action = action; dialog->buttonState = DBS_NORMAL; /* Get the number of lines. */ va_start(ap, action); for(dialog->lineCount = 0; va_arg(ap, char*); dialog->lineCount++); va_end(ap); dialog->message = Allocate(dialog->lineCount * sizeof(char*)); va_start(ap, action); for(x = 0; x < dialog->lineCount; x++) { str = va_arg(ap, char*); dialog->message[x] = CopyString(str); } va_end(ap); ComputeDimensions(np); /* Create the pixmap used for rendering. */ dialog->pmap = JXCreatePixmap(display, rootWindow, dialog->width, dialog->height, rootDepth); /* Create the window. */ attrs.background_pixel = colors[COLOR_MENU_BG]; attrs.event_mask = ButtonPressMask | ButtonReleaseMask | KeyPressMask | ExposureMask; window = JXCreateWindow(display, rootWindow, dialog->x, dialog->y, dialog->width, dialog->height, 0, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWEventMask, &attrs); shints.x = dialog->x; shints.y = dialog->y; shints.flags = PPosition; JXSetWMNormalHints(display, window, &shints); JXStoreName(display, window, _("Confirm")); SetAtomAtom(window, ATOM_NET_WM_WINDOW_TYPE, ATOM_NET_WM_WINDOW_TYPE_DIALOG); /* Draw the dialog. */ DrawDialog(); /* Add the client and give it focus. */ dialog->node = AddClientWindow(window, 0, 0); Assert(dialog->node); if(np) { dialog->node->owner = np->window; } dialog->node->state.status |= STAT_WMDIALOG; FocusClient(dialog->node); /* Grab the mouse. */ JXGrabButton(display, AnyButton, AnyModifier, window, True, ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None); }
/** Startup trays. */ void StartupTray(void) { XSetWindowAttributes attr; Atom atom; unsigned long attrMask; TrayType *tp; TrayComponentType *cp; int variableSize; int variableRemainder; int width, height; int xoffset, yoffset; for(tp = trays; tp; tp = tp->next) { LayoutTray(tp, &variableSize, &variableRemainder); /* Create the tray window. */ /* The window is created larger for a border. */ attrMask = CWOverrideRedirect; attr.override_redirect = True; /* We can't use PointerMotionHintMask since the exact position * of the mouse on the tray is important for popups. */ attrMask |= CWEventMask; attr.event_mask = ButtonPressMask | ButtonReleaseMask | SubstructureNotifyMask | ExposureMask | KeyPressMask | KeyReleaseMask | EnterWindowMask | PointerMotionMask; attrMask |= CWBackPixel; attr.background_pixel = colors[COLOR_TRAY_BG2]; attrMask |= CWBorderPixel; attr.border_pixel = colors[COLOR_TRAY_OUTLINE]; Assert(tp->width > 0); Assert(tp->height > 0); tp->window = JXCreateWindow(display, rootWindow, tp->x, tp->y, tp->width, tp->height, TRAY_BORDER_SIZE, rootVisual.depth, InputOutput, rootVisual.visual, attrMask, &attr); if(settings.trayOpacity < UINT_MAX) { /* Can't use atoms yet as it hasn't been initialized. */ atom = JXInternAtom(display, opacityAtom, False); JXChangeProperty(display, tp->window, atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&settings.trayOpacity, 1); } SetDefaultCursor(tp->window); /* Create and layout items on the tray. */ xoffset = 0; yoffset = 0; for(cp = tp->components; cp; cp = cp->next) { if(cp->Create) { if(tp->layout == LAYOUT_HORIZONTAL) { height = tp->height; width = cp->width; if(width == 0) { width = variableSize; if(variableRemainder) { width += 1; variableRemainder -= 1; } } } else { width = tp->width; height = cp->height; if(height == 0) { height = variableSize; if(variableRemainder) { height += 1; variableRemainder -= 1; } } } cp->width = Max(1, width); cp->height = Max(1, height); (cp->Create)(cp); } cp->x = xoffset; cp->y = yoffset; cp->screenx = tp->x + xoffset; cp->screeny = tp->y + yoffset; if(cp->window != None) { JXReparentWindow(display, cp->window, tp->window, xoffset, yoffset); } if(tp->layout == LAYOUT_HORIZONTAL) { xoffset += cp->width; } else { yoffset += cp->height; } } /* Show the tray. */ JXMapWindow(display, tp->window); trayCount += 1; } RequirePagerUpdate(); RequireTaskUpdate(); }
/** Reparent a client window. */ void ReparentClient(ClientNode *np, char notOwner) { XSetWindowAttributes attr; int attrMask; int x, y, width, height; int north, south, east, west; Assert(np); if(notOwner) { JXAddToSaveSet(display, np->window); attr.event_mask = EnterWindowMask | ColormapChangeMask | PropertyChangeMask | KeyReleaseMask | StructureNotifyMask; attr.do_not_propagate_mask = NoEventMask; JXChangeWindowAttributes(display, np->window, CWEventMask | CWDontPropagate, &attr); } JXGrabButton(display, AnyButton, AnyModifier, np->window, True, ButtonPressMask, GrabModeSync, GrabModeAsync, None, None); if((np->state.border & (BORDER_TITLE | BORDER_OUTLINE)) == 0) { return; } attrMask = 0; /* We can't use PointerMotionHint mask here since the exact location * of the mouse on the frame is important. */ attrMask |= CWEventMask; attr.event_mask = ButtonPressMask | ButtonReleaseMask | ExposureMask | PointerMotionMask | SubstructureRedirectMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask | KeyPressMask | KeyReleaseMask; attrMask |= CWDontPropagate; attr.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask; attrMask |= CWBackPixel; attr.background_pixel = colors[COLOR_TITLE_BG2]; attrMask |= CWBorderPixel; attr.border_pixel = 0; x = np->x; y = np->y; width = np->width; height = np->height; GetBorderSize(&np->state, &north, &south, &east, &west); x -= west; y -= north; width += east + west; height += north + south; /* Create the frame window. */ np->parent = JXCreateWindow(display, rootWindow, x, y, width, height, 0, rootDepth, InputOutput, rootVisual, attrMask, &attr); /* Update the window to get only the events we want. */ attrMask = CWDontPropagate; attr.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | KeyPressMask | KeyReleaseMask; /* Make sure client doesn't muck with these. */ attrMask |= CWBackingStore; attr.backing_store = NotUseful; attrMask |= CWWinGravity; attr.win_gravity = NorthWestGravity; JXChangeWindowAttributes(display, np->window, attrMask, &attr); JXSetWindowBorderWidth(display, np->window, 0); /* Reparent the client window. */ JXReparentWindow(display, np->window, np->parent, west, north); }
/** 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); }
/** Startup trays. */ void StartupTray() { XSetWindowAttributes attr; Atom opacityAtom; unsigned long attrMask; TrayType *tp; TrayComponentType *cp; int variableSize; int variableRemainder; int width, height; int xoffset, yoffset; for(tp = trays; tp; tp = tp->next) { LayoutTray(tp, &variableSize, &variableRemainder); /* Create the tray window. */ /* The window is created larger for a border. */ attrMask = CWOverrideRedirect; attr.override_redirect = True; /* We can't use PointerMotionHintMask since the exact position * of the mouse on the tray is important for popups. */ attrMask |= CWEventMask; attr.event_mask = ButtonPressMask | ButtonReleaseMask | SubstructureNotifyMask | ExposureMask | KeyPressMask | KeyReleaseMask | EnterWindowMask | PointerMotionMask; attrMask |= CWBackPixel; attr.background_pixel = colors[COLOR_TRAY_BG]; tp->window = JXCreateWindow(display, rootWindow, tp->x, tp->y, tp->width, tp->height, 0, rootDepth, InputOutput, rootVisual, attrMask, &attr); if(trayOpacity < UINT_MAX) { /* Can't use atoms yet as it hasn't been initialized. */ opacityAtom = JXInternAtom(display, "_NET_WM_WINDOW_OPACITY", False); JXChangeProperty(display, tp->window, opacityAtom, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&trayOpacity, 1); JXSync(display, False); } SetDefaultCursor(tp->window); /* Create and layout items on the tray. */ xoffset = tp->border; yoffset = tp->border; for(cp = tp->components; cp; cp = cp->next) { if(cp->Create) { if(tp->layout == LAYOUT_HORIZONTAL) { height = tp->height - 2 * tp->border; width = cp->width; if(width == 0) { width = variableSize; if(variableRemainder) { ++width; --variableRemainder; } } } else { width = tp->width - 2 * tp->border; height = cp->height; if(height == 0) { height = variableSize; if(variableRemainder) { ++height; --variableRemainder; } } } cp->width = width; cp->height = height; (cp->Create)(cp); } cp->x = xoffset; cp->y = yoffset; cp->screenx = tp->x + xoffset; cp->screeny = tp->y + yoffset; if(cp->window != None) { JXReparentWindow(display, cp->window, tp->window, xoffset, yoffset); } if(tp->layout == LAYOUT_HORIZONTAL) { xoffset += cp->width; } else { yoffset += cp->height; } } /* Show the tray. */ JXMapWindow(display, tp->window); ++trayCount; } UpdatePager(); UpdateTaskBar(); }