spmenu/libs/client.c

86 lines
2.1 KiB
C
Raw Normal View History

2023-03-08 17:20:32 +01:00
void
prepare_window_size(void)
{
2023-03-31 12:42:15 +02:00
// set horizontal and vertical padding
2023-03-08 17:20:32 +01:00
sp = menupaddingh;
vp = (menuposition == 1) ? menupaddingv : - menupaddingv;
2023-03-31 12:42:15 +02:00
return;
2023-03-08 17:20:32 +01:00
}
void
create_window(int x, int y, int w, int h)
{
XSetWindowAttributes swa;
swa.override_redirect = managed ? False : True;
swa.background_pixel = 0;
swa.colormap = cmap;
2023-03-31 12:42:15 +02:00
swa.event_mask =
ExposureMask | // mapping the drawing
KeyPressMask | // keypresses
VisibilityChangeMask | // whether or not client is visible
ButtonPressMask | // see buttonpress in libs/mouse.c for usage
PointerMotionMask; // we need pointer for selecting entries using the mouse
2023-03-12 21:03:35 +01:00
// create client
win = XCreateWindow(dpy, parentwin, x, y, w, h, borderwidth,
depth, InputOutput, visual,
CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &swa);
return;
}
void
set_window(void)
{
XClassHint ch = { class, class };
2023-03-31 12:42:15 +02:00
// set border and class
XSetWindowBorder(dpy, win, scheme[SchemeBorder][ColBg].pixel);
XSetClassHint(dpy, win, &ch);
return;
}
void
set_prop(void)
{
2023-03-31 12:42:15 +02:00
// TODO: add toggle for this
XChangeProperty(dpy, win, types, XA_ATOM, 32, PropModeReplace, (unsigned char *) &dock, 1); // set dock property
return;
}
2023-03-13 22:45:04 +01:00
void
resizeclient(void)
{
int omh = mh;
struct item *item;
int itemCount = 0;
// walk through all items
for (item = items; item && item->text; item++)
itemCount++;
2023-03-13 22:45:04 +01:00
2023-03-18 21:20:00 +01:00
bh = MAX(drw->font->h, drw->font->h + 2 + lineheight);
lines = MIN(itemCount, MAX(lines, 0));
2023-03-18 21:20:00 +01:00
reallines = lines;
2023-03-13 22:45:04 +01:00
2023-03-31 12:42:15 +02:00
// resize client to image height
2023-03-13 22:45:04 +01:00
#if USEIMAGE
2023-03-31 12:42:15 +02:00
if (image) resizetoimageheight(imageheight);
2023-03-13 22:45:04 +01:00
#endif
mh = (lines + 1) * bh;
2023-03-31 12:42:15 +02:00
// why have an empty line? when there's nothing to draw there anyway?
if (hideprompt && hideinput && hidemode && hidematchcount)
mh += bh;
2023-03-31 12:42:15 +02:00
// no window/invalid window or menu height we had before is the same as the current window height
2023-03-13 22:45:04 +01:00
if (!win || omh == mh) return;
XResizeWindow(dpy, win, mw, mh);
drw_resize(drw, mw, mh);
}