Fullscreen: simplifications and fixes

Merges #69.
This commit is contained in:
Stivvo 2021-03-25 10:05:12 -05:00 committed by Devin J. Pohly
parent c2b53c2d8d
commit 38ba6d2277

44
dwl.c
View File

@ -175,7 +175,6 @@ struct Monitor {
unsigned int tagset[2]; unsigned int tagset[2];
double mfact; double mfact;
int nmaster; int nmaster;
Client *fullscreenclient;
}; };
typedef struct { typedef struct {
@ -249,7 +248,6 @@ static void keypressmod(struct wl_listener *listener, void *data);
static void killclient(const Arg *arg); static void killclient(const Arg *arg);
static void maplayersurfacenotify(struct wl_listener *listener, void *data); static void maplayersurfacenotify(struct wl_listener *listener, void *data);
static void mapnotify(struct wl_listener *listener, void *data); static void mapnotify(struct wl_listener *listener, void *data);
static void maximizeclient(Client *c);
static void monocle(Monitor *m); static void monocle(Monitor *m);
static void motionabsolute(struct wl_listener *listener, void *data); static void motionabsolute(struct wl_listener *listener, void *data);
static void motionnotify(uint32_t time); static void motionnotify(uint32_t time);
@ -485,8 +483,6 @@ arrange(Monitor *m)
{ {
if (m->lt[m->sellt]->arrange) if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m); m->lt[m->sellt]->arrange(m);
else if (m->fullscreenclient)
maximizeclient(m->fullscreenclient);
/* TODO recheck pointer focus here... or in resize()? */ /* TODO recheck pointer focus here... or in resize()? */
} }
@ -885,9 +881,6 @@ createnotify(struct wl_listener *listener, void *data)
if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL)
return; return;
wl_list_for_each(c, &clients, link)
if (c->isfullscreen && VISIBLEON(c, c->mon))
setfullscreen(c, 0);
/* Allocate a Client for this surface */ /* Allocate a Client for this surface */
c = xdg_surface->data = calloc(1, sizeof(*c)); c = xdg_surface->data = calloc(1, sizeof(*c));
@ -1042,14 +1035,8 @@ void
togglefullscreen(const Arg *arg) togglefullscreen(const Arg *arg)
{ {
Client *sel = selclient(); Client *sel = selclient();
setfullscreen(sel, !sel->isfullscreen); if (sel)
} setfullscreen(sel, !sel->isfullscreen);
void
maximizeclient(Client *c)
{
resize(c, c->mon->m.x, c->mon->m.y, c->mon->m.width, c->mon->m.height, 0);
/* used for fullscreen clients */
} }
void void
@ -1064,13 +1051,11 @@ setfullscreen(Client *c, int fullscreen)
c->prevy = c->geom.y; c->prevy = c->geom.y;
c->prevheight = c->geom.height; c->prevheight = c->geom.height;
c->prevwidth = c->geom.width; c->prevwidth = c->geom.width;
c->mon->fullscreenclient = c; resize(c, c->mon->m.x, c->mon->m.y, c->mon->m.width, c->mon->m.height, 0);
maximizeclient(c);
} else { } else {
/* restore previous size instead of arrange for floating windows since /* restore previous size instead of arrange for floating windows since
* client positions are set by the user and cannot be recalculated */ * client positions are set by the user and cannot be recalculated */
resize(c, c->prevx, c->prevy, c->prevwidth, c->prevheight, 0); resize(c, c->prevx, c->prevy, c->prevwidth, c->prevheight, 0);
c->mon->fullscreenclient = NULL;
arrange(c->mon); arrange(c->mon);
} }
} }
@ -1337,7 +1322,7 @@ void
mapnotify(struct wl_listener *listener, void *data) mapnotify(struct wl_listener *listener, void *data)
{ {
/* Called when the surface is mapped, or ready to display on-screen. */ /* Called when the surface is mapped, or ready to display on-screen. */
Client *c = wl_container_of(listener, c, map), *oldfocus = selclient(); Client *c = wl_container_of(listener, c, map);
if (client_is_unmanaged(c)) { if (client_is_unmanaged(c)) {
/* Insert this independent into independents lists. */ /* Insert this independent into independents lists. */
@ -1356,14 +1341,6 @@ mapnotify(struct wl_listener *listener, void *data)
/* Set initial monitor, tags, floating status, and focus */ /* Set initial monitor, tags, floating status, and focus */
applyrules(c); applyrules(c);
if (c->mon->fullscreenclient && c->mon->fullscreenclient == oldfocus
&& !c->isfloating && c->mon->lt[c->mon->sellt]->arrange) {
maximizeclient(c->mon->fullscreenclient);
focusclient(c->mon->fullscreenclient, 1);
/* give the focus back the fullscreen client on that monitor if exists,
* is focused and the new client isn't floating */
}
} }
void void
@ -1372,12 +1349,9 @@ monocle(Monitor *m)
Client *c; Client *c;
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || c->isfloating) if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
continue; continue;
if (c->isfullscreen) resize(c, m->w.x, m->w.y, m->w.width, m->w.height, 0);
maximizeclient(c);
else
resize(c, m->w.x, m->w.y, m->w.width, m->w.height, 0);
} }
} }
@ -2229,11 +2203,9 @@ tile(Monitor *m)
mw = m->w.width; mw = m->w.width;
i = my = ty = 0; i = my = ty = 0;
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || c->isfloating) if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
continue; continue;
if (c->isfullscreen) if (i < m->nmaster) {
maximizeclient(c);
else if (i < m->nmaster) {
h = (m->w.height - my) / (MIN(n, m->nmaster) - i); h = (m->w.height - my) / (MIN(n, m->nmaster) - i);
resize(c, m->w.x, m->w.y + my, mw, h, 0); resize(c, m->w.x, m->w.y + my, mw, h, 0);
my += c->geom.height; my += c->geom.height;