Simplify display width/height code
With this commit, display width/height is only grabbed once. This means we don't need to deal with all that X11 and Xinerama code when we're simply resizing the window.
This commit is contained in:
parent
bd49d876cd
commit
336bdd5830
|
@ -34,11 +34,14 @@ void handle_wl(void) {
|
|||
|
||||
create_layer(&state, "spmenu");
|
||||
|
||||
sp.mw = (menuwidth > 0 ? menuwidth : output_width);
|
||||
mo.output_width = output_width;
|
||||
mo.output_height = output_height;
|
||||
|
||||
sp.mw = (menuwidth > 0 ? menuwidth : mo.output_width);
|
||||
get_mh();
|
||||
|
||||
if (menuposition == 2) {
|
||||
sp.mw = MIN(MAX(max_textw() + sp.promptw, minwidth), output_width);
|
||||
sp.mw = MIN(MAX(max_textw() + sp.promptw, minwidth), mo.output_width);
|
||||
}
|
||||
|
||||
state.width = sp.mw;
|
||||
|
|
|
@ -72,14 +72,6 @@ void set_prop_x11(void) {
|
|||
void resizeclient_x11(void) {
|
||||
int mh = sp.mh;
|
||||
int x, y;
|
||||
#if USEXINERAMA
|
||||
int j, di, a, n, area = 0;
|
||||
XineramaScreenInfo *info;
|
||||
Window pw;
|
||||
unsigned int du;
|
||||
Window w, dw, *dws;
|
||||
#endif
|
||||
XWindowAttributes wa;
|
||||
struct item *item;
|
||||
int ic = 0; // item count
|
||||
|
||||
|
@ -102,63 +94,14 @@ void resizeclient_x11(void) {
|
|||
sp.mh -= sp.bh;
|
||||
}
|
||||
|
||||
// init xinerama screens
|
||||
#if USEXINERAMA
|
||||
int i = 0;
|
||||
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
|
||||
XGetInputFocus(dpy, &w, &di);
|
||||
if (mon >= 0 && mon < n) {
|
||||
i = mon;
|
||||
} else if (w != root && w != PointerRoot && w != None) {
|
||||
do {
|
||||
if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws)
|
||||
XFree(dws);
|
||||
} while (w != root && w != pw);
|
||||
if (XGetWindowAttributes(dpy, pw, &wa)) {
|
||||
for (j = 0; j < n; j++) {
|
||||
if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
|
||||
area = a;
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mon < 0 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) {
|
||||
for (i = 0; i < n; i++) {
|
||||
if (INTERSECT(x, y, 1, 1, info[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// calculate x/y position
|
||||
if (menuposition == 2) { // centered
|
||||
sp.mw = MIN(MAX(max_textw() + sp.promptw, minwidth), info[i].width);
|
||||
x = info[i].x_org + ((info[i].width - sp.mw) / 2);
|
||||
y = info[i].y_org + ((info[i].height - sp.mh) / 2);
|
||||
} else { // top or bottom
|
||||
x = info[i].x_org + xpos;
|
||||
y = info[i].y_org + (menuposition ? 0 : info[i].height - sp.mh - ypos);
|
||||
sp.mw = (menuwidth>0 ? menuwidth : info[i].width);
|
||||
}
|
||||
|
||||
XFree(info);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (!XGetWindowAttributes(dpy, parentwin, &wa))
|
||||
die("spmenu: could not get embedding window attributes: 0x%lx",
|
||||
parentwin); // die because unable to get attributes for the parent window
|
||||
if (menuposition == 2) { // centered
|
||||
sp.mw = MIN(MAX(max_textw() + sp.promptw, minwidth), wa.width);
|
||||
x = (wa.width - sp.mw) / 2;
|
||||
y = (wa.height - sp.mh) / 2;
|
||||
} else { // top or bottom
|
||||
x = 0;
|
||||
y = menuposition ? 0 : wa.height - sp.mh - ypos;
|
||||
sp.mw = (menuwidth > 0 ? menuwidth : wa.width);
|
||||
}
|
||||
if (menuposition == 2) { // centered
|
||||
sp.mw = MIN(MAX(max_textw() + sp.promptw, minwidth), mo.output_width);
|
||||
x = (mo.output_width - sp.mw) / 2 + xpos;
|
||||
y = (mo.output_height - sp.mh) / 2 - ypos;
|
||||
} else { // top or bottom
|
||||
x = 0;
|
||||
y = menuposition ? 0 : mo.output_width - sp.mh - ypos;
|
||||
sp.mw = (menuwidth > 0 ? menuwidth : mo.output_width);
|
||||
}
|
||||
|
||||
// no window/invalid window or menu height we had before is the same as the current window height
|
||||
|
|
|
@ -49,16 +49,8 @@ void setupdisplay_x11(void) {
|
|||
if (INTERSECT(x, y, 1, 1, info[i]))
|
||||
break;
|
||||
|
||||
// calculate x/y position
|
||||
if (menuposition == 2) { // centered
|
||||
sp.mw = MIN(MAX(max_textw() + sp.promptw, minwidth), info[i].width);
|
||||
x = info[i].x_org + xpos + ((info[i].width - sp.mw) / 2);
|
||||
y = info[i].y_org - ypos + ((info[i].height - sp.mh) / 2);
|
||||
} else { // top or bottom
|
||||
x = info[i].x_org + xpos;
|
||||
y = info[i].y_org + (menuposition ? 0 : info[i].height - sp.mh - ypos);
|
||||
sp.mw = (menuwidth > 0 ? menuwidth : info[i].width);
|
||||
}
|
||||
mo.output_width = info[i].width;
|
||||
mo.output_height = info[i].height;
|
||||
|
||||
XFree(info);
|
||||
} else
|
||||
|
@ -68,15 +60,18 @@ void setupdisplay_x11(void) {
|
|||
die("spmenu: could not get embedding window attributes: 0x%lx",
|
||||
parentwin); // die because unable to get attributes for the parent window
|
||||
|
||||
if (menuposition == 2) { // centered
|
||||
sp.mw = MIN(MAX(max_textw() + sp.promptw, minwidth), wa.width);
|
||||
x = (wa.width - sp.mw) / 2 + xpos;
|
||||
y = (wa.height - sp.mh) / 2 - ypos;
|
||||
} else { // top or bottom
|
||||
x = 0;
|
||||
y = menuposition ? 0 : wa.width - sp.mh - ypos;
|
||||
sp.mw = (menuwidth > 0 ? menuwidth : wa.width);
|
||||
}
|
||||
mo.output_width = wa.width;
|
||||
mo.output_height = wa.height;
|
||||
}
|
||||
|
||||
if (menuposition == 2) { // centered
|
||||
sp.mw = MIN(MAX(max_textw() + sp.promptw, minwidth), mo.output_width);
|
||||
x = (mo.output_width - sp.mw) / 2 + xpos;
|
||||
y = (mo.output_height - sp.mh) / 2 - ypos;
|
||||
} else { // top or bottom
|
||||
x = 0;
|
||||
y = menuposition ? 0 : mo.output_width - sp.mh - ypos;
|
||||
sp.mw = (menuwidth > 0 ? menuwidth : mo.output_width);
|
||||
}
|
||||
|
||||
// create menu window and set properties for it
|
||||
|
|
6
spmenu.c
6
spmenu.c
|
@ -138,6 +138,11 @@ struct sp {
|
|||
int ignoreglobalmouse; // same for mouse
|
||||
};
|
||||
|
||||
struct mo {
|
||||
int output_width; // output width
|
||||
int output_height; // output height
|
||||
};
|
||||
|
||||
#if USEIMAGE
|
||||
struct img {
|
||||
int setlines; // actual lines
|
||||
|
@ -170,6 +175,7 @@ struct x11 {
|
|||
|
||||
static struct sp sp = {0};
|
||||
static struct tx tx = {0};
|
||||
static struct mo mo = {0};
|
||||
#if USEIMAGE
|
||||
static struct img img = {0};
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue