add simple (nice) cascading
This commit is contained in:
parent
e6381d7b85
commit
d78def268e
5 changed files with 66 additions and 3 deletions
|
@ -102,6 +102,11 @@
|
||||||
* BEHAVIOR * [Everything in this section is optional unless otherwise noted]
|
* BEHAVIOR * [Everything in this section is optional unless otherwise noted]
|
||||||
***********/
|
***********/
|
||||||
|
|
||||||
|
/* If this is at least 2, pretty cascading is enabled, and newly spawned windows
|
||||||
|
* will try to respect it instead of centering */
|
||||||
|
|
||||||
|
#define CASCADE_DENSITY 4
|
||||||
|
|
||||||
/* This sets the size ratio for windows spawned via keyboard or
|
/* This sets the size ratio for windows spawned via keyboard or
|
||||||
* center-snapped; CENTERNUM should be >= 2, so use 2/4 instead of 1/2
|
* center-snapped; CENTERNUM should be >= 2, so use 2/4 instead of 1/2
|
||||||
*/
|
*/
|
||||||
|
|
3
dat.h
3
dat.h
|
@ -198,3 +198,6 @@ extern int kbLaunch;
|
||||||
|
|
||||||
extern int nmonitors;
|
extern int nmonitors;
|
||||||
extern XRRMonitorInfo* monitorinfo;
|
extern XRRMonitorInfo* monitorinfo;
|
||||||
|
|
||||||
|
extern int* xstep;
|
||||||
|
extern int* ystep;
|
14
event.c
14
event.c
|
@ -211,10 +211,16 @@ void configurereq(XConfigureRequestEvent* e) {
|
||||||
|
|
||||||
void mapreq(XMapRequestEvent* e) {
|
void mapreq(XMapRequestEvent* e) {
|
||||||
Client* c;
|
Client* c;
|
||||||
int i;
|
int i, m;
|
||||||
XRRMonitorInfo monitor;
|
XRRMonitorInfo monitor;
|
||||||
|
|
||||||
monitor = monitorinfo[getmonitorbymouse()];
|
#ifdef MONITORFOLLOWSMOUSE
|
||||||
|
m = getmonitorbymouse();
|
||||||
|
#else
|
||||||
|
m = getmonitorbyclient(current);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
monitor = monitorinfo[m];
|
||||||
|
|
||||||
curtime = CurrentTime;
|
curtime = CurrentTime;
|
||||||
c = getclient(e->window, 0);
|
c = getclient(e->window, 0);
|
||||||
|
@ -236,7 +242,7 @@ void mapreq(XMapRequestEvent* e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kbLaunch) {
|
if (kbLaunch && CASCADE_DENSITY < 2) {
|
||||||
// usleep(MICROSLEEP_DELAY);
|
// usleep(MICROSLEEP_DELAY);
|
||||||
#ifdef CENTERVMAX
|
#ifdef CENTERVMAX
|
||||||
centerclient(c, monitor, 1);
|
centerclient(c, monitor, 1);
|
||||||
|
@ -244,6 +250,8 @@ void mapreq(XMapRequestEvent* e) {
|
||||||
centerclient(c, monitor, 0);
|
centerclient(c, monitor, 0);
|
||||||
#endif
|
#endif
|
||||||
kbLaunch = 0;
|
kbLaunch = 0;
|
||||||
|
} else if (CASCADE_DENSITY >= 2 && c->trans == None) {
|
||||||
|
getcascadecoords(c->window, m, &(c->x), &(c->y));
|
||||||
}
|
}
|
||||||
switch (c->state) {
|
switch (c->state) {
|
||||||
case WithdrawnState:
|
case WithdrawnState:
|
||||||
|
|
1
fns.h
1
fns.h
|
@ -130,3 +130,4 @@ void fetchmonitorinfo();
|
||||||
int getmonitorbyclient(Client*);
|
int getmonitorbyclient(Client*);
|
||||||
int getmonitorbymouse();
|
int getmonitorbymouse();
|
||||||
void wrangle(Client*, XRRMonitorInfo);
|
void wrangle(Client*, XRRMonitorInfo);
|
||||||
|
void getcascadecoords(Window, int, int*, int*);
|
46
monitor.c
46
monitor.c
|
@ -8,12 +8,58 @@
|
||||||
|
|
||||||
int nmonitors = 0;
|
int nmonitors = 0;
|
||||||
XRRMonitorInfo* monitorinfo;
|
XRRMonitorInfo* monitorinfo;
|
||||||
|
int* xstep;
|
||||||
|
int* ystep;
|
||||||
|
|
||||||
void fetchmonitorinfo() {
|
void fetchmonitorinfo() {
|
||||||
if (monitorinfo)
|
if (monitorinfo)
|
||||||
XRRFreeMonitors(monitorinfo);
|
XRRFreeMonitors(monitorinfo);
|
||||||
|
if (xstep)
|
||||||
|
free(xstep);
|
||||||
|
if (ystep)
|
||||||
|
free(ystep);
|
||||||
|
|
||||||
monitorinfo = XRRGetMonitors(dpy, DefaultRootWindow(dpy), 1, &nmonitors);
|
monitorinfo = XRRGetMonitors(dpy, DefaultRootWindow(dpy), 1, &nmonitors);
|
||||||
|
xstep = malloc(nmonitors * sizeof(int));
|
||||||
|
ystep = malloc(nmonitors * sizeof(int));
|
||||||
|
for (int i = 0; i < nmonitors; i++) {
|
||||||
|
xstep[i] = monitorinfo[i].width / CASCADE_DENSITY;
|
||||||
|
ystep[i] = monitorinfo[i].height / CASCADE_DENSITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getcascadecoords(Window w, int monitor, int* x, int* y) {
|
||||||
|
int mappedclients = 0;
|
||||||
|
Client* c;
|
||||||
|
int ox = monitorinfo[monitor].x;
|
||||||
|
int oy = monitorinfo[monitor].y;
|
||||||
|
|
||||||
|
if (w == 0)
|
||||||
|
return;
|
||||||
|
for (c = clients; c; c = c->next) {
|
||||||
|
if (
|
||||||
|
c->window != w && c->state == NormalState &&
|
||||||
|
getmonitorbyclient(c) == monitor) {
|
||||||
|
mappedclients++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (;;) {
|
||||||
|
if (mappedclients < CASCADE_DENSITY) {
|
||||||
|
*x = ox + mappedclients * xstep[monitor];
|
||||||
|
*y = oy + mappedclients * ystep[monitor];
|
||||||
|
return;
|
||||||
|
} else if (mappedclients < 1.5 * CASCADE_DENSITY) {
|
||||||
|
*x = ox + (mappedclients - CASCADE_DENSITY + 1) * xstep[monitor];
|
||||||
|
*y = oy + (mappedclients - CASCADE_DENSITY) * ystep[monitor];
|
||||||
|
return;
|
||||||
|
} else if (mappedclients < 2 * CASCADE_DENSITY) {
|
||||||
|
*x = ox + (mappedclients - 1.5 * CASCADE_DENSITY) * xstep[monitor];
|
||||||
|
*y = oy + (mappedclients - 1.5 * CASCADE_DENSITY + 1) * ystep[monitor];
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
mappedclients -= 2 * CASCADE_DENSITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int getmonitorbyclient(Client* c) {
|
int getmonitorbyclient(Client* c) {
|
||||||
|
|
Loading…
Reference in a new issue