/** Compute the size of a dialog window. */ void ComputeDimensions(const ClientNode *np) { const ScreenType *sp; int width; int x; Assert(dialog); /* Get the min width from the size of the buttons. */ if(!minWidth) { minWidth = GetStringWidth(FONT_MENU, GetCancelString()) * 3; width = GetStringWidth(FONT_MENU, GetOKString()) * 3; if(width > minWidth) { minWidth = width; } minWidth += 16 * 3; } dialog->width = minWidth; /* Take into account the size of the message. */ for(x = 0; x < dialog->lineCount; x++) { width = GetStringWidth(FONT_MENU, dialog->message[x]); if(width > dialog->width) { dialog->width = width; } } dialog->lineHeight = GetStringHeight(FONT_MENU); dialog->width += 8; dialog->height = (dialog->lineCount + 2) * dialog->lineHeight; if(np) { dialog->x = np->x + (np->width - dialog->width) / 2; dialog->y = np->y + (np->height - dialog->height) / 2; if(dialog->x < 0) { dialog->x = 0; } if(dialog->y < 0) { dialog->y = 0; } if(dialog->x + dialog->width >= rootWidth) { dialog->x = rootWidth - dialog->width - (settings.borderWidth * 2); } if(dialog->y + dialog->height >= rootHeight) { dialog->y = rootHeight - dialog->height - (settings.borderWidth * 2 + settings.titleHeight); } } else { sp = GetMouseScreen(); dialog->x = (sp->width - dialog->width) / 2 + sp->x; dialog->y = (sp->height - dialog->height) / 2 + sp->y; } }
/** Compute the size of a dialog window. */ void ComputeDimensions(DialogType *dp) { const ScreenType *sp; int width; int x; Assert(dp); /* Get the min width from the size of the buttons. */ if(!minWidth) { minWidth = GetStringWidth(FONT_MENU, CANCEL_STRING) * 3; width = GetStringWidth(FONT_MENU, OK_STRING) * 3; if(width > minWidth) { minWidth = width; } minWidth += 16 * 3; } dp->width = minWidth; /* Take into account the size of the message. */ for(x = 0; x < dp->lineCount; x++) { width = GetStringWidth(FONT_MENU, dp->message[x]); if(width > dp->width) { dp->width = width; } } dp->lineHeight = GetStringHeight(FONT_MENU); dp->width += 8; dp->height = (dp->lineCount + 2) * dp->lineHeight; if(dp->client) { dp->x = dp->client->x + (dp->client->width - dp->width) / 2; dp->y = dp->client->y + (dp->client->height - dp->height) / 2; if(dp->x < 0) { dp->x = 0; } if(dp->y < 0) { dp->y = 0; } if(dp->x + dp->width >= rootWidth) { dp->x = rootWidth - dp->width - (borderWidth * 2); } if(dp->y + dp->height >= rootHeight) { dp->y = rootHeight - dp->height - (borderWidth * 2 + titleHeight); } } else { sp = GetMouseScreen(); dp->x = (sp->width - dp->width) / 2 + sp->x; dp->y = (sp->height - dp->height) / 2 + sp->y; } }
/** Cascade placement. */ void CascadeClient(const BoundingBox *box, ClientNode *np) { const ScreenType *sp; int north, south, east, west; int cascadeIndex; char overflow; GetBorderSize(&np->state, &north, &south, &east, &west); sp = GetMouseScreen(); cascadeIndex = sp->index * settings.desktopCount + currentDesktop; /* Set the cascaded location. */ np->x = box->x + west + cascadeOffsets[cascadeIndex]; np->y = box->y + north + cascadeOffsets[cascadeIndex]; cascadeOffsets[cascadeIndex] += settings.borderWidth + settings.titleHeight; /* Check for cascade overflow. */ overflow = 0; if(np->x + np->width - box->x > box->width) { overflow = 1; } else if(np->y + np->height - box->y > box->height) { overflow = 1; } if(overflow) { cascadeOffsets[cascadeIndex] = settings.borderWidth + settings.titleHeight; np->x = box->x + west + cascadeOffsets[cascadeIndex]; np->y = box->y + north + cascadeOffsets[cascadeIndex]; /* Check for client overflow and update cascade position. */ if(np->x + np->width - box->x > box->width) { np->x = box->x + west; } else if(np->y + np->height - box->y > box->height) { np->y = box->y + north; } else { cascadeOffsets[cascadeIndex] += settings.borderWidth + settings.titleHeight; } } ConstrainSize(np); ConstrainPosition(np); }
/** Place a client on the screen. */ void PlaceClient(ClientNode *np, char alreadyMapped) { BoundingBox box; const ScreenType *sp; Assert(np); if(alreadyMapped || (!(np->state.status & STAT_PIGNORE) && (np->sizeFlags & (PPosition | USPosition)))) { GravitateClient(np, 0); if(!alreadyMapped) { ConstrainSize(np); ConstrainPosition(np); } } else { sp = GetMouseScreen(); GetScreenBounds(sp, &box); SubtractTrayBounds(GetTrays(), &box, np->state.layer); SubtractStrutBounds(&box, np); /* If tiled is specified, first attempt to use tiled placement. */ if(np->state.status & STAT_TILED) { if(TileClient(&box, np)) { return; } } /* Either tiled placement failed or was not specified. */ if(np->state.status & STAT_CENTERED) { CenterClient(&box, np); } else { CascadeClient(&box, np); } } }