mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
bring together gathering, calculating and applying of size hints;
additionally, respect aspect ratio hints. ok oga@
This commit is contained in:
parent
09d88f4a18
commit
028a1778db
7
calmwm.h
7
calmwm.h
@ -121,8 +121,9 @@ struct client_ctx {
|
|||||||
|
|
||||||
u_int bwidth;
|
u_int bwidth;
|
||||||
struct {
|
struct {
|
||||||
int x, y, width, height;
|
int x, y, width, height, basew, baseh,
|
||||||
int min_dx, min_dy;
|
minw, minh, maxw, maxh, incw, inch;
|
||||||
|
float mina, maxa;
|
||||||
} geom, savegeom;
|
} geom, savegeom;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@ -349,6 +350,8 @@ void client_vertmaximize(struct client_ctx *);
|
|||||||
void client_map(struct client_ctx *);
|
void client_map(struct client_ctx *);
|
||||||
void client_mtf(struct client_ctx *);
|
void client_mtf(struct client_ctx *);
|
||||||
struct client_ctx *client_cycle(int);
|
struct client_ctx *client_cycle(int);
|
||||||
|
void client_getsizehints(struct client_ctx *);
|
||||||
|
void client_applysizehints(struct client_ctx *);
|
||||||
|
|
||||||
struct menu *menu_filter(struct menu_q *, char *, char *, int,
|
struct menu *menu_filter(struct menu_q *, char *, char *, int,
|
||||||
void (*)(struct menu_q *, struct menu_q *, char *),
|
void (*)(struct menu_q *, struct menu_q *, char *),
|
||||||
|
100
client.c
100
client.c
@ -50,7 +50,6 @@ client_new(Window win, struct screen_ctx *sc, int mapped)
|
|||||||
struct client_ctx *cc;
|
struct client_ctx *cc;
|
||||||
XWindowAttributes wattr;
|
XWindowAttributes wattr;
|
||||||
XWMHints *wmhints;
|
XWMHints *wmhints;
|
||||||
long tmp;
|
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
if (win == None)
|
if (win == None)
|
||||||
@ -65,14 +64,7 @@ client_new(Window win, struct screen_ctx *sc, int mapped)
|
|||||||
cc->win = win;
|
cc->win = win;
|
||||||
cc->size = XAllocSizeHints();
|
cc->size = XAllocSizeHints();
|
||||||
|
|
||||||
XGetWMNormalHints(X_Dpy, cc->win, cc->size, &tmp);
|
client_getsizehints(cc);
|
||||||
if (cc->size->flags & PBaseSize) {
|
|
||||||
cc->geom.min_dx = cc->size->base_width;
|
|
||||||
cc->geom.min_dy = cc->size->base_height;
|
|
||||||
} else if (cc->size->flags & PMinSize) {
|
|
||||||
cc->geom.min_dx = cc->size->min_width;
|
|
||||||
cc->geom.min_dy = cc->size->min_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
TAILQ_INIT(&cc->nameq);
|
TAILQ_INIT(&cc->nameq);
|
||||||
client_setname(cc);
|
client_setname(cc);
|
||||||
@ -628,6 +620,96 @@ client_mtf(struct client_ctx *cc)
|
|||||||
TAILQ_INSERT_HEAD(&sc->mruq, cc, mru_entry);
|
TAILQ_INSERT_HEAD(&sc->mruq, cc, mru_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
client_getsizehints(struct client_ctx *cc)
|
||||||
|
{
|
||||||
|
long tmp;
|
||||||
|
|
||||||
|
if (!XGetWMNormalHints(X_Dpy, cc->win, cc->size, &tmp))
|
||||||
|
cc->size->flags = PSize;
|
||||||
|
|
||||||
|
if (cc->size->flags & PBaseSize) {
|
||||||
|
cc->geom.basew = cc->size->base_width;
|
||||||
|
cc->geom.baseh = cc->size->base_height;
|
||||||
|
} else if (cc->size->flags & PMinSize) {
|
||||||
|
cc->geom.basew = cc->size->min_width;
|
||||||
|
cc->geom.baseh = cc->size->min_height;
|
||||||
|
}
|
||||||
|
if (cc->size->flags & PMinSize) {
|
||||||
|
cc->geom.minw = cc->size->min_width;
|
||||||
|
cc->geom.minh = cc->size->min_height;
|
||||||
|
} else if (cc->size->flags & PBaseSize) {
|
||||||
|
cc->geom.minw = cc->size->base_width;
|
||||||
|
cc->geom.minh = cc->size->base_height;
|
||||||
|
}
|
||||||
|
if (cc->size->flags & PMaxSize) {
|
||||||
|
cc->geom.maxw = cc->size->max_width;
|
||||||
|
cc->geom.maxh = cc->size->max_height;
|
||||||
|
}
|
||||||
|
if (cc->size->flags & PResizeInc) {
|
||||||
|
cc->geom.incw = cc->size->width_inc;
|
||||||
|
cc->geom.inch = cc->size->height_inc;
|
||||||
|
}
|
||||||
|
if (cc->size->flags & PAspect) {
|
||||||
|
if (cc->size->min_aspect.x > 0)
|
||||||
|
cc->geom.mina = (float)cc->size->min_aspect.y /
|
||||||
|
cc->size->min_aspect.x;
|
||||||
|
if (cc->size->max_aspect.y > 0)
|
||||||
|
cc->geom.maxa = (float)cc->size->max_aspect.x /
|
||||||
|
cc->size->max_aspect.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void
|
||||||
|
client_applysizehints(struct client_ctx *cc)
|
||||||
|
{
|
||||||
|
Bool baseismin;
|
||||||
|
|
||||||
|
baseismin = (cc->geom.basew == cc->geom.minw) &&
|
||||||
|
(cc->geom.baseh == cc->geom.minh);
|
||||||
|
|
||||||
|
/* temporarily remove base dimensions, ICCCM 4.1.2.3 */
|
||||||
|
if (!baseismin) {
|
||||||
|
cc->geom.width -= cc->geom.basew;
|
||||||
|
cc->geom.height -= cc->geom.baseh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* adjust for aspect limits */
|
||||||
|
if (cc->geom.mina > 0 && cc->geom.maxa > 0) {
|
||||||
|
if (cc->geom.maxa <
|
||||||
|
(float)cc->geom.width / cc->geom.height)
|
||||||
|
cc->geom.width = cc->geom.height * cc->geom.maxa;
|
||||||
|
else if (cc->geom.mina <
|
||||||
|
(float)cc->geom.height / cc->geom.width)
|
||||||
|
cc->geom.height = cc->geom.width * cc->geom.mina;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* remove base dimensions for increment */
|
||||||
|
if (baseismin) {
|
||||||
|
cc->geom.width -= cc->geom.basew;
|
||||||
|
cc->geom.height -= cc->geom.baseh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* adjust for increment value */
|
||||||
|
if (cc->geom.incw)
|
||||||
|
cc->geom.width -= cc->geom.width % cc->geom.incw;
|
||||||
|
if (cc->geom.inch)
|
||||||
|
cc->geom.height -= cc->geom.height % cc->geom.inch;
|
||||||
|
|
||||||
|
/* restore base dimensions */
|
||||||
|
cc->geom.width += cc->geom.basew;
|
||||||
|
cc->geom.height += cc->geom.baseh;
|
||||||
|
|
||||||
|
/* adjust for min width/height */
|
||||||
|
cc->geom.width = MAX(cc->geom.width, cc->geom.minw);
|
||||||
|
cc->geom.height = MAX(cc->geom.height, cc->geom.minh);
|
||||||
|
|
||||||
|
/* adjust for max width/height */
|
||||||
|
if (cc->geom.maxw)
|
||||||
|
cc->geom.width = MIN(cc->geom.width, cc->geom.maxw);
|
||||||
|
if (cc->geom.maxh)
|
||||||
|
cc->geom.height = MIN(cc->geom.height, cc->geom.maxh);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
client_gethints(struct client_ctx *cc)
|
client_gethints(struct client_ctx *cc)
|
||||||
{
|
{
|
||||||
|
24
mousefunc.c
24
mousefunc.c
@ -33,22 +33,7 @@ mousefunc_sweep_calc(struct client_ctx *cc, int x, int y, int mx, int my)
|
|||||||
cc->geom.width = abs(x - mx) - cc->bwidth;
|
cc->geom.width = abs(x - mx) - cc->bwidth;
|
||||||
cc->geom.height = abs(y - my) - cc->bwidth;
|
cc->geom.height = abs(y - my) - cc->bwidth;
|
||||||
|
|
||||||
if (cc->size->flags & PResizeInc) {
|
client_applysizehints(cc);
|
||||||
cc->geom.width -=
|
|
||||||
(cc->geom.width - cc->geom.min_dx) % cc->size->width_inc;
|
|
||||||
cc->geom.height -=
|
|
||||||
(cc->geom.height - cc->geom.min_dy) % cc->size->height_inc;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cc->size->flags & PMinSize) {
|
|
||||||
cc->geom.width = MAX(cc->geom.width, cc->size->min_width);
|
|
||||||
cc->geom.height = MAX(cc->geom.height, cc->size->min_height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cc->size->flags & PMaxSize) {
|
|
||||||
cc->geom.width = MIN(cc->geom.width, cc->size->max_width);
|
|
||||||
cc->geom.height = MIN(cc->geom.height, cc->size->max_height);
|
|
||||||
}
|
|
||||||
|
|
||||||
cc->geom.x = x <= mx ? x : x - cc->geom.width;
|
cc->geom.x = x <= mx ? x : x - cc->geom.width;
|
||||||
cc->geom.y = y <= my ? y : y - cc->geom.height;
|
cc->geom.y = y <= my ? y : y - cc->geom.height;
|
||||||
@ -64,8 +49,8 @@ mousefunc_sweep_draw(struct client_ctx *cc)
|
|||||||
int width, height, width_size, width_name;
|
int width, height, width_size, width_name;
|
||||||
|
|
||||||
snprintf(asize, sizeof(asize), "%dx%d",
|
snprintf(asize, sizeof(asize), "%dx%d",
|
||||||
(cc->geom.width - cc->geom.min_dx) / cc->size->width_inc,
|
(cc->geom.width - cc->geom.basew) / MAX(1, cc->geom.incw),
|
||||||
(cc->geom.height - cc->geom.min_dy) / cc->size->height_inc);
|
(cc->geom.height - cc->geom.baseh) / MAX(1, cc->geom.inch));
|
||||||
width_size = font_width(asize, strlen(asize)) + 4;
|
width_size = font_width(asize, strlen(asize)) + 4;
|
||||||
width_name = font_width(cc->name, strlen(cc->name)) + 4;
|
width_name = font_width(cc->name, strlen(cc->name)) + 4;
|
||||||
width = MAX(width_size, width_name);
|
width = MAX(width_size, width_name);
|
||||||
@ -90,9 +75,6 @@ mousefunc_window_resize(struct client_ctx *cc, void *arg)
|
|||||||
struct screen_ctx *sc = CCTOSC(cc);
|
struct screen_ctx *sc = CCTOSC(cc);
|
||||||
int x = cc->geom.x, y = cc->geom.y;
|
int x = cc->geom.x, y = cc->geom.y;
|
||||||
|
|
||||||
cc->size->width_inc = MAX(1, cc->size->width_inc);
|
|
||||||
cc->size->height_inc = MAX(1, cc->size->height_inc);
|
|
||||||
|
|
||||||
client_raise(cc);
|
client_raise(cc);
|
||||||
client_ptrsave(cc);
|
client_ptrsave(cc);
|
||||||
|
|
||||||
|
@ -171,12 +171,11 @@ xev_handle_propertynotify(XEvent *ee)
|
|||||||
{
|
{
|
||||||
XPropertyEvent *e = &ee->xproperty;
|
XPropertyEvent *e = &ee->xproperty;
|
||||||
struct client_ctx *cc;
|
struct client_ctx *cc;
|
||||||
long tmp;
|
|
||||||
|
|
||||||
if ((cc = client_find(e->window)) != NULL) {
|
if ((cc = client_find(e->window)) != NULL) {
|
||||||
switch (e->atom) {
|
switch (e->atom) {
|
||||||
case XA_WM_NORMAL_HINTS:
|
case XA_WM_NORMAL_HINTS:
|
||||||
XGetWMNormalHints(X_Dpy, cc->win, cc->size, &tmp);
|
client_getsizehints(cc);
|
||||||
break;
|
break;
|
||||||
case XA_WM_NAME:
|
case XA_WM_NAME:
|
||||||
client_setname(cc);
|
client_setname(cc);
|
||||||
|
Loading…
Reference in New Issue
Block a user