Merge pull request #53 from Stivvo/fullscreen

Fullscreen support
main
Devin J. Pohly 2020-12-24 21:35:57 -05:00 committed by GitHub
commit c5087d413f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 106 additions and 21 deletions

View File

@ -64,7 +64,6 @@ dwl is a work in progress, and it has not yet reached its feature goals in a num
- Urgent/attention/focus-request ([not yet supported](https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/9) by xdg-shell protocol) - Urgent/attention/focus-request ([not yet supported](https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/9) by xdg-shell protocol)
- Statusbar support (built-in or external) - Statusbar support (built-in or external)
- Damage tracking - Damage tracking
- Fullscreen/fixed windows (or whatever the Wayland analogues are)
## Acknowledgements ## Acknowledgements

View File

@ -80,6 +80,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} }, { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XKB_KEY_space, setlayout, {0} }, { MODKEY, XKB_KEY_space, setlayout, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} },
{ MODKEY, XKB_KEY_0, view, {.ui = ~0} }, { MODKEY, XKB_KEY_0, view, {.ui = ~0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} },
{ MODKEY, XKB_KEY_comma, focusmon, {.i = -1} }, { MODKEY, XKB_KEY_comma, focusmon, {.i = -1} },

95
dwl.c
View File

@ -99,6 +99,7 @@ typedef struct {
struct wl_listener map; struct wl_listener map;
struct wl_listener unmap; struct wl_listener unmap;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener fullscreen;
struct wlr_box geom; /* layout-relative, includes border */ struct wlr_box geom; /* layout-relative, includes border */
Monitor *mon; Monitor *mon;
#ifdef XWAYLAND #ifdef XWAYLAND
@ -108,6 +109,11 @@ typedef struct {
unsigned int tags; unsigned int tags;
int isfloating; int isfloating;
uint32_t resize; /* configure serial of a pending resize */ uint32_t resize; /* configure serial of a pending resize */
int prevx;
int prevy;
int prevwidth;
int prevheight;
int isfullscreen;
} Client; } Client;
typedef struct { typedef struct {
@ -163,6 +169,7 @@ struct Monitor {
unsigned int tagset[2]; unsigned int tagset[2];
double mfact; double mfact;
int nmaster; int nmaster;
Client *fullscreenclient;
}; };
typedef struct { typedef struct {
@ -222,6 +229,7 @@ static Monitor *dirtomon(int dir);
static void focusclient(Client *old, Client *c, int lift); static void focusclient(Client *old, Client *c, int lift);
static void focusmon(const Arg *arg); static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg); static void focusstack(const Arg *arg);
static void fullscreennotify(struct wl_listener *listener, void *data);
static Client *focustop(Monitor *m); static Client *focustop(Monitor *m);
static void getxdecomode(struct wl_listener *listener, void *data); static void getxdecomode(struct wl_listener *listener, void *data);
static void incnmaster(const Arg *arg); static void incnmaster(const Arg *arg);
@ -232,6 +240,7 @@ 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 maprequest(struct wl_listener *listener, void *data); static void maprequest(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);
@ -252,6 +261,7 @@ static void setcursor(struct wl_listener *listener, void *data);
static void setpsel(struct wl_listener *listener, void *data); static void setpsel(struct wl_listener *listener, void *data);
static void setsel(struct wl_listener *listener, void *data); static void setsel(struct wl_listener *listener, void *data);
static void setfloating(Client *c, int floating); static void setfloating(Client *c, int floating);
static void setfullscreen(Client *c, int fullscreen);
static void setlayout(const Arg *arg); static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg); static void setmfact(const Arg *arg);
static void setmon(Client *c, Monitor *m, unsigned int newtags); static void setmon(Client *c, Monitor *m, unsigned int newtags);
@ -263,6 +273,7 @@ static void tag(const Arg *arg);
static void tagmon(const Arg *arg); static void tagmon(const Arg *arg);
static void tile(Monitor *m); static void tile(Monitor *m);
static void togglefloating(const Arg *arg); static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
static void toggletag(const Arg *arg); static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg); static void toggleview(const Arg *arg);
static void unmaplayersurface(LayerSurface *layersurface); static void unmaplayersurface(LayerSurface *layersurface);
@ -468,6 +479,8 @@ 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);
/* XXX recheck pointer focus here... or in resize()? */ /* XXX recheck pointer focus here... or in resize()? */
} }
@ -854,6 +867,10 @@ createnotify(struct wl_listener *listener, void *data)
wl_signal_add(&xdg_surface->events.unmap, &c->unmap); wl_signal_add(&xdg_surface->events.unmap, &c->unmap);
c->destroy.notify = destroynotify; c->destroy.notify = destroynotify;
wl_signal_add(&xdg_surface->events.destroy, &c->destroy); wl_signal_add(&xdg_surface->events.destroy, &c->destroy);
c->fullscreen.notify = fullscreennotify;
wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen, &c->fullscreen);
c->isfullscreen = 0;
} }
void void
@ -931,7 +948,6 @@ createxdeco(struct wl_listener *listener, void *data)
getxdecomode(&d->request_mode, wlr_deco); getxdecomode(&d->request_mode, wlr_deco);
} }
void void
cursorframe(struct wl_listener *listener, void *data) cursorframe(struct wl_listener *listener, void *data)
{ {
@ -973,6 +989,7 @@ destroynotify(struct wl_listener *listener, void *data)
wl_list_remove(&c->map.link); wl_list_remove(&c->map.link);
wl_list_remove(&c->unmap.link); wl_list_remove(&c->unmap.link);
wl_list_remove(&c->destroy.link); wl_list_remove(&c->destroy.link);
wl_list_remove(&c->fullscreen.link);
#ifdef XWAYLAND #ifdef XWAYLAND
if (c->type == X11Managed) if (c->type == X11Managed)
wl_list_remove(&c->activate.link); wl_list_remove(&c->activate.link);
@ -993,6 +1010,56 @@ destroyxdeco(struct wl_listener *listener, void *data)
free(d); free(d);
} }
void
togglefullscreen(const Arg *arg)
{
Client *sel = selclient();
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
setfullscreen(Client *c, int fullscreen)
{
c->isfullscreen = fullscreen;
c->bw = (1 - fullscreen) * borderpx;
#ifdef XWAYLAND
if (c->type == X11Managed)
wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen);
else
#endif
wlr_xdg_toplevel_set_fullscreen(c->surface.xdg, fullscreen);
if (fullscreen) {
c->prevx = c->geom.x;
c->prevy = c->geom.y;
c->prevheight = c->geom.height;
c->prevwidth = c->geom.width;
c->mon->fullscreenclient = c;
maximizeclient(c);
} else {
/* restore previous size instead of arrange for floating windows since
* client positions are set by the user and cannot be recalculated */
resize(c, c->prevx, c->prevy, c->prevwidth, c->prevheight, 0);
c->mon->fullscreenclient = NULL;
arrange(c->mon);
}
}
void
fullscreennotify(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, fullscreen);
setfullscreen(c, !c->isfullscreen);
}
Monitor * Monitor *
dirtomon(int dir) dirtomon(int dir)
{ {
@ -1243,7 +1310,7 @@ void
maprequest(struct wl_listener *listener, void *data) maprequest(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); Client *c = wl_container_of(listener, c, map), *oldfocus = selclient();
#ifdef XWAYLAND #ifdef XWAYLAND
if (c->type == X11Unmanaged) { if (c->type == X11Unmanaged) {
@ -1274,6 +1341,14 @@ maprequest(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, 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
@ -1284,6 +1359,9 @@ monocle(Monitor *m)
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)
continue; continue;
if (c->isfullscreen)
maximizeclient(c);
else
resize(c, m->w.x, m->w.y, m->w.width, m->w.height, 0); resize(c, m->w.x, m->w.y, m->w.width, m->w.height, 0);
} }
} }
@ -1541,6 +1619,8 @@ renderclients(Monitor *m, struct timespec *now)
ox = c->geom.x, oy = c->geom.y; ox = c->geom.x, oy = c->geom.y;
wlr_output_layout_output_coords(output_layout, m->wlr_output, wlr_output_layout_output_coords(output_layout, m->wlr_output,
&ox, &oy); &ox, &oy);
if (c->bw) {
w = surface->current.width; w = surface->current.width;
h = surface->current.height; h = surface->current.height;
borders = (struct wlr_box[4]) { borders = (struct wlr_box[4]) {
@ -1557,6 +1637,7 @@ renderclients(Monitor *m, struct timespec *now)
wlr_render_rect(drw, &borders[i], color, wlr_render_rect(drw, &borders[i], color,
m->wlr_output->transform_matrix); m->wlr_output->transform_matrix);
} }
}
/* This calls our render function for each surface among the /* This calls our render function for each surface among the
* xdg_surface's toplevel and popups. */ * xdg_surface's toplevel and popups. */
@ -1760,8 +1841,6 @@ setcursor(struct wl_listener *listener, void *data)
void void
setfloating(Client *c, int floating) setfloating(Client *c, int floating)
{ {
if (c->isfloating == floating)
return;
c->isfloating = floating; c->isfloating = floating;
arrange(c->mon); arrange(c->mon);
} }
@ -2051,7 +2130,9 @@ tile(Monitor *m)
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)
continue; continue;
if (i < m->nmaster) { if (c->isfullscreen)
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;
@ -2265,6 +2346,10 @@ createnotifyx11(struct wl_listener *listener, void *data)
wl_signal_add(&xwayland_surface->events.request_activate, &c->activate); wl_signal_add(&xwayland_surface->events.request_activate, &c->activate);
c->destroy.notify = destroynotify; c->destroy.notify = destroynotify;
wl_signal_add(&xwayland_surface->events.destroy, &c->destroy); wl_signal_add(&xwayland_surface->events.destroy, &c->destroy);
c->fullscreen.notify = fullscreennotify;
wl_signal_add(&xwayland_surface->events.request_fullscreen, &c->fullscreen);
c->isfullscreen = 0;
} }
Atom Atom