| @@ -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) | ||||
| - Statusbar support (built-in or external) | ||||
| - Damage tracking | ||||
| - Fullscreen/fixed windows (or whatever the Wayland analogues are) | ||||
|  | ||||
|  | ||||
| ## Acknowledgements | ||||
|   | ||||
| @@ -80,6 +80,7 @@ static const Key keys[] = { | ||||
| 	{ MODKEY,                    XKB_KEY_m,          setlayout,      {.v = &layouts[2]} }, | ||||
| 	{ MODKEY,                    XKB_KEY_space,      setlayout,      {0} }, | ||||
| 	{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space,      togglefloating, {0} }, | ||||
| 	{ MODKEY, 					 XKB_KEY_e,    		togglefullscreen, {0} }, | ||||
| 	{ MODKEY,                    XKB_KEY_0,          view,           {.ui = ~0} }, | ||||
| 	{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag,            {.ui = ~0} }, | ||||
| 	{ MODKEY,                    XKB_KEY_comma,      focusmon,       {.i = -1} }, | ||||
|   | ||||
							
								
								
									
										125
									
								
								dwl.c
									
									
									
									
									
								
							
							
						
						
									
										125
									
								
								dwl.c
									
									
									
									
									
								
							| @@ -99,6 +99,7 @@ typedef struct { | ||||
| 	struct wl_listener map; | ||||
| 	struct wl_listener unmap; | ||||
| 	struct wl_listener destroy; | ||||
| 	struct wl_listener fullscreen; | ||||
| 	struct wlr_box geom;  /* layout-relative, includes border */ | ||||
| 	Monitor *mon; | ||||
| #ifdef XWAYLAND | ||||
| @@ -108,6 +109,11 @@ typedef struct { | ||||
| 	unsigned int tags; | ||||
| 	int isfloating; | ||||
| 	uint32_t resize; /* configure serial of a pending resize */ | ||||
| 	int prevx; | ||||
| 	int prevy; | ||||
| 	int prevwidth; | ||||
| 	int prevheight; | ||||
| 	int isfullscreen; | ||||
| } Client; | ||||
|  | ||||
| typedef struct { | ||||
| @@ -163,6 +169,7 @@ struct Monitor { | ||||
| 	unsigned int tagset[2]; | ||||
| 	double mfact; | ||||
| 	int nmaster; | ||||
| 	Client *fullscreenclient; | ||||
| }; | ||||
|  | ||||
| typedef struct { | ||||
| @@ -222,6 +229,7 @@ static Monitor *dirtomon(int dir); | ||||
| static void focusclient(Client *old, Client *c, int lift); | ||||
| static void focusmon(const Arg *arg); | ||||
| static void focusstack(const Arg *arg); | ||||
| static void fullscreennotify(struct wl_listener *listener, void *data); | ||||
| static Client *focustop(Monitor *m); | ||||
| static void getxdecomode(struct wl_listener *listener, void *data); | ||||
| 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 maplayersurfacenotify(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 motionabsolute(struct wl_listener *listener, void *data); | ||||
| 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 setsel(struct wl_listener *listener, void *data); | ||||
| static void setfloating(Client *c, int floating); | ||||
| static void setfullscreen(Client *c, int fullscreen); | ||||
| static void setlayout(const Arg *arg); | ||||
| static void setmfact(const Arg *arg); | ||||
| 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 tile(Monitor *m); | ||||
| static void togglefloating(const Arg *arg); | ||||
| static void togglefullscreen(const Arg *arg); | ||||
| static void toggletag(const Arg *arg); | ||||
| static void toggleview(const Arg *arg); | ||||
| static void unmaplayersurface(LayerSurface *layersurface); | ||||
| @@ -468,6 +479,8 @@ arrange(Monitor *m) | ||||
| { | ||||
| 	if (m->lt[m->sellt]->arrange) | ||||
| 		m->lt[m->sellt]->arrange(m); | ||||
| 	else if (m->fullscreenclient) | ||||
| 		maximizeclient(m->fullscreenclient); | ||||
| 	/* 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); | ||||
| 	c->destroy.notify = destroynotify; | ||||
| 	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 | ||||
| @@ -931,7 +948,6 @@ createxdeco(struct wl_listener *listener, void *data) | ||||
| 	getxdecomode(&d->request_mode, wlr_deco); | ||||
| } | ||||
|  | ||||
|  | ||||
| void | ||||
| 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->unmap.link); | ||||
| 	wl_list_remove(&c->destroy.link); | ||||
| 	wl_list_remove(&c->fullscreen.link); | ||||
| #ifdef XWAYLAND | ||||
| 	if (c->type == X11Managed) | ||||
| 		wl_list_remove(&c->activate.link); | ||||
| @@ -993,6 +1010,56 @@ destroyxdeco(struct wl_listener *listener, void *data) | ||||
| 	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 * | ||||
| dirtomon(int dir) | ||||
| { | ||||
| @@ -1243,7 +1310,7 @@ void | ||||
| maprequest(struct wl_listener *listener, void *data) | ||||
| { | ||||
| 	/* 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 | ||||
| 	if (c->type == X11Unmanaged) { | ||||
| @@ -1274,6 +1341,14 @@ maprequest(struct wl_listener *listener, void *data) | ||||
|  | ||||
| 	/* Set initial monitor, tags, floating status, and focus */ | ||||
| 	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 | ||||
| @@ -1284,7 +1359,10 @@ monocle(Monitor *m) | ||||
| 	wl_list_for_each(c, &clients, link) { | ||||
| 		if (!VISIBLEON(c, m) || c->isfloating) | ||||
| 			continue; | ||||
| 		resize(c, m->w.x, m->w.y, m->w.width, m->w.height, 0); | ||||
| 		if (c->isfullscreen) | ||||
| 			maximizeclient(c); | ||||
| 		else | ||||
| 			resize(c, m->w.x, m->w.y, m->w.width, m->w.height, 0); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -1541,21 +1619,24 @@ renderclients(Monitor *m, struct timespec *now) | ||||
| 		ox = c->geom.x, oy = c->geom.y; | ||||
| 		wlr_output_layout_output_coords(output_layout, m->wlr_output, | ||||
| 				&ox, &oy); | ||||
| 		w = surface->current.width; | ||||
| 		h = surface->current.height; | ||||
| 		borders = (struct wlr_box[4]) { | ||||
| 			{ox, oy, w + 2 * c->bw, c->bw},             /* top */ | ||||
| 			{ox, oy + c->bw, c->bw, h},                 /* left */ | ||||
| 			{ox + c->bw + w, oy + c->bw, c->bw, h},     /* right */ | ||||
| 			{ox, oy + c->bw + h, w + 2 * c->bw, c->bw}, /* bottom */ | ||||
| 		}; | ||||
|  | ||||
| 		/* Draw window borders */ | ||||
| 		color = (c == sel) ? focuscolor : bordercolor; | ||||
| 		for (i = 0; i < 4; i++) { | ||||
| 			scalebox(&borders[i], m->wlr_output->scale); | ||||
| 			wlr_render_rect(drw, &borders[i], color, | ||||
| 					m->wlr_output->transform_matrix); | ||||
| 		if (c->bw) { | ||||
| 			w = surface->current.width; | ||||
| 			h = surface->current.height; | ||||
| 			borders = (struct wlr_box[4]) { | ||||
| 				{ox, oy, w + 2 * c->bw, c->bw},             /* top */ | ||||
| 				{ox, oy + c->bw, c->bw, h},                 /* left */ | ||||
| 				{ox + c->bw + w, oy + c->bw, c->bw, h},     /* right */ | ||||
| 				{ox, oy + c->bw + h, w + 2 * c->bw, c->bw}, /* bottom */ | ||||
| 			}; | ||||
|  | ||||
| 			/* Draw window borders */ | ||||
| 			color = (c == sel) ? focuscolor : bordercolor; | ||||
| 			for (i = 0; i < 4; i++) { | ||||
| 				scalebox(&borders[i], m->wlr_output->scale); | ||||
| 				wlr_render_rect(drw, &borders[i], color, | ||||
| 						m->wlr_output->transform_matrix); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		/* This calls our render function for each surface among the | ||||
| @@ -1760,8 +1841,6 @@ setcursor(struct wl_listener *listener, void *data) | ||||
| void | ||||
| setfloating(Client *c, int floating) | ||||
| { | ||||
| 	if (c->isfloating == floating) | ||||
| 		return; | ||||
| 	c->isfloating = floating; | ||||
| 	arrange(c->mon); | ||||
| } | ||||
| @@ -2051,7 +2130,9 @@ tile(Monitor *m) | ||||
| 	wl_list_for_each(c, &clients, link) { | ||||
| 		if (!VISIBLEON(c, m) || c->isfloating) | ||||
| 			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); | ||||
| 			resize(c, m->w.x, m->w.y + my, mw, h, 0); | ||||
| 			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); | ||||
| 	c->destroy.notify = destroynotify; | ||||
| 	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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user