Leonardo Hernández Hernández 2022-04-05 23:04:04 -05:00
parent af741e586b
commit c00697e643
No known key found for this signature in database
GPG Key ID: E538897EE11B9624
1 changed files with 119 additions and 119 deletions

238
dwl.c
View File

@ -221,9 +221,9 @@ static void commitlayersurfacenotify(struct wl_listener *listener, void *data);
static void commitnotify(struct wl_listener *listener, void *data);
static void createidleinhibitor(struct wl_listener *listener, void *data);
static void createkeyboard(struct wlr_input_device *device);
static void createlayersurface(struct wl_listener *listener, void *data);
static void createmon(struct wl_listener *listener, void *data);
static void createnotify(struct wl_listener *listener, void *data);
static void createlayersurface(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_input_device *device);
static void cursorframe(struct wl_listener *listener, void *data);
static void destroyidleinhibitor(struct wl_listener *listener, void *data);
@ -234,8 +234,8 @@ static void dragicondestroy(struct wl_listener *listener, void *data);
static void focusclient(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 fullscreennotify(struct wl_listener *listener, void *data);
static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data);
static int keybinding(uint32_t mods, xkb_keysym_t sym);
@ -263,13 +263,13 @@ static void resize(Client *c, int x, int y, int w, int h, int interact);
static void run(char *startup_cmd);
static Client *selclient(void);
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);
static void setpsel(struct wl_listener *listener, void *data);
static void setsel(struct wl_listener *listener, void *data);
static void setup(void);
static void sigchld(int unused);
static void spawn(const Arg *arg);
@ -289,9 +289,9 @@ static void updatetitle(struct wl_listener *listener, void *data);
static void urgent(struct wl_listener *listener, void *data);
static void view(const Arg *arg);
static void virtualkeyboard(struct wl_listener *listener, void *data);
static Monitor *xytomon(double x, double y);
static struct wlr_scene_node *xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
static Monitor *xytomon(double x, double y);
static void zoom(const Arg *arg);
/* variables */
@ -818,6 +818,50 @@ createkeyboard(struct wlr_input_device *device)
wl_list_insert(&keyboards, &kb->link);
}
void
createlayersurface(struct wl_listener *listener, void *data)
{
struct wlr_layer_surface_v1 *wlr_layer_surface = data;
LayerSurface *layersurface;
Monitor *m;
struct wlr_layer_surface_v1_state old_state;
if (!wlr_layer_surface->output) {
wlr_layer_surface->output = selmon->wlr_output;
}
layersurface = ecalloc(1, sizeof(LayerSurface));
layersurface->type = LayerShell;
LISTEN(&wlr_layer_surface->surface->events.commit,
&layersurface->surface_commit, commitlayersurfacenotify);
LISTEN(&wlr_layer_surface->events.destroy, &layersurface->destroy,
destroylayersurfacenotify);
LISTEN(&wlr_layer_surface->events.map, &layersurface->map,
maplayersurfacenotify);
LISTEN(&wlr_layer_surface->events.unmap, &layersurface->unmap,
unmaplayersurfacenotify);
layersurface->layer_surface = wlr_layer_surface;
wlr_layer_surface->data = layersurface;
m = wlr_layer_surface->output->data;
layersurface->scene = wlr_layer_surface->surface->data =
wlr_scene_subsurface_tree_create(layers[wlr_layer_surface->pending.layer],
wlr_layer_surface->surface);
layersurface->scene->data = layersurface;
wl_list_insert(&m->layers[wlr_layer_surface->pending.layer],
&layersurface->link);
/* Temporarily set the layer's current state to pending
* so that we can easily arrange it
*/
old_state = wlr_layer_surface->current;
wlr_layer_surface->current = wlr_layer_surface->pending;
arrangelayers(m);
wlr_layer_surface->current = old_state;
}
void
createmon(struct wl_listener *listener, void *data)
{
@ -924,50 +968,6 @@ createnotify(struct wl_listener *listener, void *data)
c->isfullscreen = 0;
}
void
createlayersurface(struct wl_listener *listener, void *data)
{
struct wlr_layer_surface_v1 *wlr_layer_surface = data;
LayerSurface *layersurface;
Monitor *m;
struct wlr_layer_surface_v1_state old_state;
if (!wlr_layer_surface->output) {
wlr_layer_surface->output = selmon->wlr_output;
}
layersurface = ecalloc(1, sizeof(LayerSurface));
layersurface->type = LayerShell;
LISTEN(&wlr_layer_surface->surface->events.commit,
&layersurface->surface_commit, commitlayersurfacenotify);
LISTEN(&wlr_layer_surface->events.destroy, &layersurface->destroy,
destroylayersurfacenotify);
LISTEN(&wlr_layer_surface->events.map, &layersurface->map,
maplayersurfacenotify);
LISTEN(&wlr_layer_surface->events.unmap, &layersurface->unmap,
unmaplayersurfacenotify);
layersurface->layer_surface = wlr_layer_surface;
wlr_layer_surface->data = layersurface;
m = wlr_layer_surface->output->data;
layersurface->scene = wlr_layer_surface->surface->data =
wlr_scene_subsurface_tree_create(layers[wlr_layer_surface->pending.layer],
wlr_layer_surface->surface);
layersurface->scene->data = layersurface;
wl_list_insert(&m->layers[wlr_layer_surface->pending.layer],
&layersurface->link);
/* Temporarily set the layer's current state to pending
* so that we can easily arrange it
*/
old_state = wlr_layer_surface->current;
wlr_layer_surface->current = wlr_layer_surface->pending;
arrangelayers(m);
wlr_layer_surface->current = old_state;
}
void
createpointer(struct wlr_input_device *device)
{
@ -1049,57 +1049,6 @@ destroynotify(struct wl_listener *listener, void *data)
free(c);
}
void
dragicondestroy(struct wl_listener *listener, void *data)
{
struct wlr_drag_icon *icon = data;
wlr_scene_node_destroy(icon->data);
// Focus enter isn't sent during drag, so refocus the focused node.
focusclient(selclient(), 1);
motionnotify(0);
}
void
togglefullscreen(const Arg *arg)
{
Client *sel = selclient();
if (sel)
setfullscreen(sel, !sel->isfullscreen);
}
void
setfullscreen(Client *c, int fullscreen)
{
c->isfullscreen = fullscreen;
c->bw = fullscreen ? 0 : borderpx;
client_set_fullscreen(c, fullscreen);
if (fullscreen) {
c->prev = c->geom;
resize(c, c->mon->m.x, c->mon->m.y, c->mon->m.width, c->mon->m.height, 0);
} 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->prev.x, c->prev.y, c->prev.width, c->prev.height, 0);
}
arrange(c->mon);
printstatus();
}
void
fullscreennotify(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, fullscreen);
int fullscreen = client_wants_fullscreen(c);
if (!c->mon) {
/* if the client is not mapped yet, let mapnotify() call setfullscreen() */
c->isfullscreen = fullscreen;
return;
}
setfullscreen(c, fullscreen);
}
Monitor *
dirtomon(enum wlr_direction dir)
{
@ -1114,6 +1063,16 @@ dirtomon(enum wlr_direction dir)
return selmon;
}
void
dragicondestroy(struct wl_listener *listener, void *data)
{
struct wlr_drag_icon *icon = data;
wlr_scene_node_destroy(icon->data);
// Focus enter isn't sent during drag, so refocus the focused node.
focusclient(selclient(), 1);
motionnotify(0);
}
void
focusclient(Client *c, int lift)
{
@ -1229,6 +1188,20 @@ focustop(Monitor *m)
return NULL;
}
void
fullscreennotify(struct wl_listener *listener, void *data)
{
Client *c = wl_container_of(listener, c, fullscreen);
int fullscreen = client_wants_fullscreen(c);
if (!c->mon) {
/* if the client is not mapped yet, let mapnotify() call setfullscreen() */
c->isfullscreen = fullscreen;
return;
}
setfullscreen(c, fullscreen);
}
void
incnmaster(const Arg *arg)
{
@ -1692,6 +1665,18 @@ rendermon(struct wl_listener *listener, void *data)
m->un_map = 0;
}
void
requeststartdrag(struct wl_listener *listener, void *data)
{
struct wlr_seat_request_start_drag_event *event = data;
if (wlr_seat_validate_pointer_grab_serial(seat, event->origin,
event->serial))
wlr_seat_start_pointer_drag(seat, event->drag, event->serial);
else
wlr_data_source_destroy(event->drag->source);
}
void
resize(Client *c, int x, int y, int w, int h, int interact)
{
@ -1720,18 +1705,6 @@ resize(Client *c, int x, int y, int w, int h, int interact)
c->geom.height - 2 * c->bw);
}
void
requeststartdrag(struct wl_listener *listener, void *data)
{
struct wlr_seat_request_start_drag_event *event = data;
if (wlr_seat_validate_pointer_grab_serial(seat, event->origin,
event->serial))
wlr_seat_start_pointer_drag(seat, event->drag, event->serial);
else
wlr_data_source_destroy(event->drag->source);
}
void
run(char *startup_cmd)
{
@ -1830,6 +1803,25 @@ setfloating(Client *c, int floating)
printstatus();
}
void
setfullscreen(Client *c, int fullscreen)
{
c->isfullscreen = fullscreen;
c->bw = fullscreen ? 0 : borderpx;
client_set_fullscreen(c, fullscreen);
if (fullscreen) {
c->prev = c->geom;
resize(c, c->mon->m.x, c->mon->m.y, c->mon->m.width, c->mon->m.height, 0);
} 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->prev.x, c->prev.y, c->prev.width, c->prev.height, 0);
}
arrange(c->mon);
printstatus();
}
void
setlayout(const Arg *arg)
{
@ -2176,6 +2168,14 @@ togglefloating(const Arg *arg)
setfloating(sel, !sel->isfloating);
}
void
togglefullscreen(const Arg *arg)
{
Client *sel = selclient();
if (sel)
setfullscreen(sel, !sel->isfullscreen);
}
void
toggletag(const Arg *arg)
{
@ -2329,6 +2329,13 @@ virtualkeyboard(struct wl_listener *listener, void *data)
createkeyboard(device);
}
Monitor *
xytomon(double x, double y)
{
struct wlr_output *o = wlr_output_layout_output_at(output_layout, x, y);
return o ? o->data : NULL;
}
struct wlr_scene_node *
xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny)
@ -2362,13 +2369,6 @@ xytonode(double x, double y, struct wlr_surface **psurface,
return node;
}
Monitor *
xytomon(double x, double y)
{
struct wlr_output *o = wlr_output_layout_output_at(output_layout, x, y);
return o ? o->data : NULL;
}
void
zoom(const Arg *arg)
{