Merge remote-tracking branch 'upstream/main' into wlroots-next

This commit is contained in:
Leonardo Hernández Hernández 2022-10-29 16:56:23 -05:00
commit 6a0ec2a8c3
No known key found for this signature in database
GPG Key ID: E538897EE11B9624
6 changed files with 241 additions and 163 deletions

View File

@ -5,7 +5,8 @@ include config.mk
# flags for compiling # flags for compiling
DWLCPPFLAGS = -I. -DWLR_USE_UNSTABLE -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XWAYLAND) DWLCPPFLAGS = -I. -DWLR_USE_UNSTABLE -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XWAYLAND)
DWLDEVCFLAGS = -pedantic -Wall -Wextra -Wdeclaration-after-statement -Wno-unused-parameter -Wno-sign-compare -Wshadow -Wunused-macros DWLDEVCFLAGS = -pedantic -Wall -Wextra -Wdeclaration-after-statement -Wno-unused-parameter -Wno-sign-compare -Wshadow -Wunused-macros\
-Werror=strict-prototypes -Werror=implicit -Werror=return-type -Werror=incompatible-pointer-types
# CFLAGS / LDFLAGS # CFLAGS / LDFLAGS
PKGS = wlroots wayland-server xkbcommon libinput $(XLIBS) PKGS = wlroots wayland-server xkbcommon libinput $(XLIBS)

111
README.md
View File

@ -1,20 +1,29 @@
# dwl - dwm for Wayland # dwl - dwm for Wayland
Join us on our [Discord server](https://discord.gg/jJxZnrGPWN) or at [#dwl](https://web.libera.chat/?channels=#dwl) on irc.libera.chat. Join us on our [Discord server] or at [#dwl] on irc.libera.chat.
dwl is a compact, hackable compositor for Wayland based on [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots/). It is intended to fill the same space in the Wayland world that dwm does in X11, primarily in terms of philosophy, and secondarily in terms of functionality. Like dwm, dwl is: dwl is a compact, hackable compositor for [Wayland] based on [wlroots]. It is
intended to fill the same space in the Wayland world that dwm does in X11,
primarily in terms of philosophy, and secondarily in terms of functionality.
Like dwm, dwl is:
- Easy to understand, hack on, and extend with patches - Easy to understand, hack on, and extend with patches
- One C source file (or a very small number) configurable via `config.h` - One C source file (or a very small number) configurable via `config.h`
- Limited to 2200 SLOC to promote hackability - Limited to 2200 SLOC to promote hackability
- Tied to as few external dependencies as possible - Tied to as few external dependencies as possible
dwl is not meant to provide every feature under the sun. Instead, like dwm, it sticks to features which are necessary, simple, and straightforward to implement given the base on which it is built. Implemented default features are: dwl is not meant to provide every feature under the sun. Instead, like dwm, it
sticks to features which are necessary, simple, and straightforward to implement
given the base on which it is built. Implemented default features are:
- Any features provided by dwm/Xlib: simple window borders, tags, keybindings, client rules, mouse move/resize. Providing a built-in status bar is an exception to this goal, to avoid dependencies on font rendering and/or drawing libraries when an external bar could work well. - Any features provided by dwm/Xlib: simple window borders, tags, keybindings,
client rules, mouse move/resize. Providing a built-in status bar is an
exception to this goal, to avoid dependencies on font rendering and/or
drawing libraries when an external bar could work well.
- Configurable multi-monitor layout support, including position and rotation - Configurable multi-monitor layout support, including position and rotation
- Configurable HiDPI/multi-DPI support - Configurable HiDPI/multi-DPI support
- Idle-inhibit protocol which lets applications such as mpv disable idle monitoring - Idle-inhibit protocol which lets applications such as mpv disable idle
monitoring
- Provide information to external status bars via stdout/stdin - Provide information to external status bars via stdout/stdin
- Urgency hints via xdg-activate protocol - Urgency hints via xdg-activate protocol
- Support screen lockers via input-inhibitor protocol - Support screen lockers via input-inhibitor protocol
@ -27,37 +36,68 @@ dwl is not meant to provide every feature under the sun. Instead, like dwm, it s
Features under consideration (possibly as patches) are: Features under consideration (possibly as patches) are:
- Protocols made trivial by wlroots - Protocols made trivial by wlroots
- Implement the text-input and input-method protocols to support IME once ibus implements input-method v2 (see https://github.com/ibus/ibus/pull/2256 and https://github.com/djpohly/dwl/pull/235) - Implement the text-input and input-method protocols to support IME once ibus
implements input-method v2 (see https://github.com/ibus/ibus/pull/2256 and
https://github.com/djpohly/dwl/pull/235)
Feature *non-goals* for the main codebase include: Feature *non-goals* for the main codebase include:
- Client-side decoration (any more than is necessary to tell the clients not to) - Client-side decoration (any more than is necessary to tell the clients not to)
- Client-initiated window management, such as move, resize, and close, which can be done through the compositor - Client-initiated window management, such as move, resize, and close, which can
be done through the compositor
- Animations and visual effects - Animations and visual effects
## Building dwl ## Building dwl
dwl has only two dependencies: `wlroots` and `wayland-protocols`. dwl has only two dependencies: `wlroots` and `wayland-protocols`.
Simply install these (and their `-devel` versions if your distro has separate development packages) and run `make`. If you wish to build against a Git version of wlroots, check out the [wlroots-next branch](https://github.com/djpohly/dwl/tree/wlroots-next). Simply install these (and their `-devel` versions if your distro has separate
development packages) and run `make`. If you wish to build against a Git
version of wlroots, check out the [wlroots-next branch].
To enable XWayland, you should also install xorg-xwayland and uncomment its flag in `config.mk`. To enable XWayland, you should also install xorg-xwayland and uncomment its flag
in `config.mk`.
## Configuration ## Configuration
All configuration is done by editing `config.h` and recompiling, in the same manner as dwm. There is no way to separately restart the window manager in Wayland without restarting the entire display server, so any changes will take effect the next time dwl is executed. All configuration is done by editing `config.h` and recompiling, in the same
manner as dwm. There is no way to separately restart the window manager in
Wayland without restarting the entire display server, so any changes will take
effect the next time dwl is executed.
As in the dwm community, we encourage users to share patches they have created. Check out the [patches page on our wiki](https://github.com/djpohly/dwl/wiki/Patches)! As in the dwm community, we encourage users to share patches they have created.
Check out the [patches page on our wiki]!
## Running dwl ## Running dwl
dwl can be run on any of the backends supported by wlroots. This means you can run it as a separate window inside either an X11 or Wayland session, as well as directly from a VT console. Depending on your distro's setup, you may need to add your user to the `video` and `input` groups before you can run dwl on a VT. dwl can be run on any of the backends supported by wlroots. This means you can
run it as a separate window inside either an X11 or Wayland session, as well
as directly from a VT console. Depending on your distro's setup, you may need
to add your user to the `video` and `input` groups before you can run dwl on
a VT. If you are using `elogind` or `systemd-logind` you need to install
polkit; otherwise you need to add yourself in the `seat` group and
enable/start the seatd daemon.
When dwl is run with no arguments, it will launch the server and begin handling any shortcuts configured in `config.h`. There is no status bar or other decoration initially; these are instead clients that can be run within the Wayland session. When dwl is run with no arguments, it will launch the server and begin handling
any shortcuts configured in `config.h`. There is no status bar or other
decoration initially; these are instead clients that can be run within
the Wayland session.
If you would like to run a script or command automatically at startup, you can specify the command using the `-s` option. This command will be executed as a shell command using `/bin/sh -c`. It serves a similar function to `.xinitrc`, but differs in that the display server will not shut down when this process terminates. Instead, dwl will send this process a SIGTERM at shutdown and wait for it to terminate (if it hasn't already). This makes it ideal for execing into a user service manager like [s6](https://skarnet.org/software/s6/), [anopa](https://jjacky.com/anopa/), [runit](http://smarden.org/runit/faq.html#userservices), or [`systemd --user`](https://wiki.archlinux.org/title/Systemd/User). If you would like to run a script or command automatically at startup, you can
specify the command using the `-s` option. This command will be executed as a
shell command using `/bin/sh -c`. It serves a similar function to `.xinitrc`,
but differs in that the display server will not shut down when this process
terminates. Instead, dwl will send this process a SIGTERM at shutdown and wait
for it to terminate (if it hasn't already). This makes it ideal for execing into
a user service manager like [s6], [anopa], [runit], or [`systemd --user`].
Note: The `-s` command is run as a *child process* of dwl, which means that it does not have the ability to affect the environment of dwl or of any processes that it spawns. If you need to set environment variables that affect the entire dwl session, these must be set prior to running dwl. For example, Wayland requires a valid `XDG_RUNTIME_DIR`, which is usually set up by a session manager such as `elogind` or `systemd-logind`. If your system doesn't do this automatically, you will need to configure it prior to launching `dwl`, e.g.: Note: The `-s` command is run as a *child process* of dwl, which means that it
does not have the ability to affect the environment of dwl or of any processes
that it spawns. If you need to set environment variables that affect the entire
dwl session, these must be set prior to running dwl. For example, Wayland
requires a valid `XDG_RUNTIME_DIR`, which is usually set up by a session manager
such as `elogind` or `systemd-logind`. If your system doesn't do this
automatically, you will need to configure it prior to launching `dwl`, e.g.:
export XDG_RUNTIME_DIR=/tmp/xdg-runtime-$(id -u) export XDG_RUNTIME_DIR=/tmp/xdg-runtime-$(id -u)
mkdir -p $XDG_RUNTIME_DIR mkdir -p $XDG_RUNTIME_DIR
@ -65,26 +105,53 @@ Note: The `-s` command is run as a *child process* of dwl, which means that it d
### Status information ### Status information
Information about selected layouts, current window title, and selected/occupied/urgent tags is written to the stdin of the `-s` command (see the `printstatus()` function for details). This information can be used to populate an external status bar with a script that parses the information. Failing to read this information will cause dwl to block, so if you do want to run a startup command that does not consume the status information, you can close standard input with the `<&-` shell redirection, for example: Information about selected layouts, current window title, and
selected/occupied/urgent tags is written to the stdin of the `-s` command (see
the `printstatus()` function for details). This information can be used to
populate an external status bar with a script that parses the information.
Failing to read this information will cause dwl to block, so if you do want to
run a startup command that does not consume the status information, you can
close standard input with the `<&-` shell redirection, for example:
dwl -s 'foot --server <&-' dwl -s 'foot --server <&-'
If your startup command is a shell script, you can achieve the same inside the script with the line If your startup command is a shell script, you can achieve the same inside the
script with the line
exec <&- exec <&-
To get a list of status bars that work with dwl consult our [wiki](https://github.com/djpohly/dwl/wiki#compatible-status-bars). To get a list of status bars that work with dwl consult our [wiki].
## Replacements for X applications ## Replacements for X applications
You can find a [list of useful resources on our wiki](https://github.com/djpohly/dwl/wiki#migrating-from-x). You can find a [list of useful resources on our wiki].
## Acknowledgements ## Acknowledgements
dwl began by extending the TinyWL example provided (CC0) by the sway/wlroots developers. This was made possible in many cases by looking at how sway accomplished something, then trying to do the same in as suckless a way as possible. dwl began by extending the TinyWL example provided (CC0) by the sway/wlroots
developers. This was made possible in many cases by looking at how sway
accomplished something, then trying to do the same in as suckless a way as
possible.
Many thanks to suckless.org and the dwm developers and community for the inspiration, and to the various contributors to the project, including: Many thanks to suckless.org and the dwm developers and community for the
inspiration, and to the various contributors to the project, including:
- Alexander Courtis for the XWayland implementation - Alexander Courtis for the XWayland implementation
- Guido Cella for the layer-shell protocol implementation, patch maintenance, and for helping to keep the project running - Guido Cella for the layer-shell protocol implementation, patch maintenance,
and for helping to keep the project running
- Stivvo for output management and fullscreen support, and patch maintenance - Stivvo for output management and fullscreen support, and patch maintenance
[Discord server]: https://discord.gg/jJxZnrGPWN
[#dwl]: https://web.libera.chat/?channels=#dwl
[Wayland]: https://wayland.freedesktop.org/
[wlroots]: https://gitlab.freedesktop.org/wlroots/wlroots/
[wlroots-next branch]: https://github.com/djpohly/dwl/tree/wlroots-next
[patches page on our wiki]: https://github.com/djpohly/dwl/wiki/Patches
[s6]: https://skarnet.org/software/s6/
[anopa]: https://jjacky.com/anopa/
[runit]: http://smarden.org/runit/faq.html#userservices
[`systemd --user`]: https://wiki.archlinux.org/title/Systemd/User
[wiki]: https://github.com/djpohly/dwl/wiki#compatible-status-bars
[list of useful resources on our wiki]:
https://github.com/djpohly/dwl/wiki#migrating-from-x

View File

@ -286,6 +286,17 @@ client_surface_at(Client *c, double cx, double cy, double *sx, double *sy)
return wlr_xdg_surface_surface_at(c->surface.xdg, cx, cy, sx, sy); return wlr_xdg_surface_surface_at(c->surface.xdg, cx, cy, sx, sy);
} }
static inline int
client_wants_focus(Client *c)
{
#ifdef XWAYLAND
return client_is_unmanaged(c)
&& wlr_xwayland_or_surface_wants_focus(c->surface.xwayland)
&& wlr_xwayland_icccm_input_model(c->surface.xwayland) != WLR_ICCCM_INPUT_MODEL_NONE;
#endif
return 0;
}
static inline int static inline int
client_wants_fullscreen(Client *c) client_wants_fullscreen(Client *c)
{ {
@ -318,3 +329,18 @@ toplevel_from_popup(struct wlr_xdg_popup *popup)
} }
} }
} }
static inline void *
toplevel_from_wlr_layer_surface(struct wlr_surface *s)
{
Client *c;
struct wlr_layer_surface_v1 *wlr_layer_surface;
if ((c = client_from_wlr_surface(s)))
return c;
else if (s && wlr_surface_is_layer_surface(s)
&& (wlr_layer_surface = wlr_layer_surface_v1_from_wlr_surface(s)))
return wlr_layer_surface->data;
return NULL;
}

179
dwl.c
View File

@ -73,7 +73,7 @@
/* enums */ /* enums */
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
enum { XDGShell, LayerShell, X11Managed, X11Unmanaged }; /* client types */ enum { XDGShell, LayerShell, X11Managed, X11Unmanaged }; /* client types */
enum { LyrBg, LyrBottom, LyrTop, LyrOverlay, LyrTile, LyrFloat, LyrNoFocus, NUM_LAYERS }; /* scene layers */ enum { LyrBg, LyrBottom, LyrTop, LyrOverlay, LyrTile, LyrFloat, LyrDragIcon, NUM_LAYERS }; /* scene layers */
#ifdef XWAYLAND #ifdef XWAYLAND
enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar, enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar,
NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */ NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */
@ -225,11 +225,11 @@ static void createmon(struct wl_listener *listener, void *data);
static void createnotify(struct wl_listener *listener, void *data); static void createnotify(struct wl_listener *listener, void *data);
static void createpointer(struct wlr_pointer *pointer); static void createpointer(struct wlr_pointer *pointer);
static void cursorframe(struct wl_listener *listener, void *data); static void cursorframe(struct wl_listener *listener, void *data);
static void destroydragicon(struct wl_listener *listener, void *data);
static void destroyidleinhibitor(struct wl_listener *listener, void *data); static void destroyidleinhibitor(struct wl_listener *listener, void *data);
static void destroylayersurfacenotify(struct wl_listener *listener, void *data); static void destroylayersurfacenotify(struct wl_listener *listener, void *data);
static void destroynotify(struct wl_listener *listener, void *data); static void destroynotify(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir); static Monitor *dirtomon(enum wlr_direction dir);
static void dragicondestroy(struct wl_listener *listener, void *data);
static void focusclient(Client *c, int lift); static void focusclient(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);
@ -337,6 +337,7 @@ static struct wl_listener cursor_button = {.notify = buttonpress};
static struct wl_listener cursor_frame = {.notify = cursorframe}; static struct wl_listener cursor_frame = {.notify = cursorframe};
static struct wl_listener cursor_motion = {.notify = motionrelative}; static struct wl_listener cursor_motion = {.notify = motionrelative};
static struct wl_listener cursor_motion_absolute = {.notify = motionabsolute}; static struct wl_listener cursor_motion_absolute = {.notify = motionabsolute};
static struct wl_listener drag_icon_destroy = {.notify = destroydragicon};
static struct wl_listener idle_inhibitor_create = {.notify = createidleinhibitor}; static struct wl_listener idle_inhibitor_create = {.notify = createidleinhibitor};
static struct wl_listener idle_inhibitor_destroy = {.notify = destroyidleinhibitor}; static struct wl_listener idle_inhibitor_destroy = {.notify = destroyidleinhibitor};
static struct wl_listener layout_change = {.notify = updatemons}; static struct wl_listener layout_change = {.notify = updatemons};
@ -353,7 +354,6 @@ static struct wl_listener request_set_psel = {.notify = setpsel};
static struct wl_listener request_set_sel = {.notify = setsel}; static struct wl_listener request_set_sel = {.notify = setsel};
static struct wl_listener request_start_drag = {.notify = requeststartdrag}; static struct wl_listener request_start_drag = {.notify = requeststartdrag};
static struct wl_listener start_drag = {.notify = startdrag}; static struct wl_listener start_drag = {.notify = startdrag};
static struct wl_listener drag_icon_destroy = {.notify = dragicondestroy};
#ifdef XWAYLAND #ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data); static void activatex11(struct wl_listener *listener, void *data);
@ -390,9 +390,9 @@ applybounds(Client *c, struct wlr_box *bbox)
c->geom.height = MAX(min.height + (2 * c->bw), c->geom.height); c->geom.height = MAX(min.height + (2 * c->bw), c->geom.height);
/* Some clients set them max size to INT_MAX, which does not violates /* Some clients set them max size to INT_MAX, which does not violates
* the protocol but its innecesary, they can set them max size to zero. */ * the protocol but its innecesary, they can set them max size to zero. */
if (max.width > 0 && !(2 * c->bw > INT_MAX - max.width)) // Checks for overflow if (max.width > 0 && !(2 * c->bw > INT_MAX - max.width)) /* Checks for overflow */
c->geom.width = MIN(max.width + (2 * c->bw), c->geom.width); c->geom.width = MIN(max.width + (2 * c->bw), c->geom.width);
if (max.height > 0 && !(2 * c->bw > INT_MAX - max.height)) // Checks for overflow if (max.height > 0 && !(2 * c->bw > INT_MAX - max.height)) /* Checks for overflow */
c->geom.height = MIN(max.height + (2 * c->bw), c->geom.height); c->geom.height = MIN(max.height + (2 * c->bw), c->geom.height);
} }
@ -538,8 +538,7 @@ buttonpress(struct wl_listener *listener, void *data)
case WLR_BUTTON_PRESSED: case WLR_BUTTON_PRESSED:
/* Change focus if the button was _pressed_ over a client */ /* Change focus if the button was _pressed_ over a client */
xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL); xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
/* Don't focus unmanaged clients */ if (c && (!client_is_unmanaged(c) || client_wants_focus(c)))
if (c && !client_is_unmanaged(c))
focusclient(c, 1); focusclient(c, 1);
keyboard = wlr_seat_get_keyboard(seat); keyboard = wlr_seat_get_keyboard(seat);
@ -642,7 +641,15 @@ void
cleanupmon(struct wl_listener *listener, void *data) cleanupmon(struct wl_listener *listener, void *data)
{ {
Monitor *m = wl_container_of(listener, m, destroy); Monitor *m = wl_container_of(listener, m, destroy);
int nmons, i = 0; LayerSurface *l, *tmp;
int i;
for (i = 0; i <= ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY; i++) {
wl_list_for_each_safe(l, tmp, &m->layers[i], link) {
wlr_scene_node_set_enabled(&l->scene->node, 0);
wlr_layer_surface_v1_destroy(l->layer_surface);
}
}
wl_list_remove(&m->destroy.link); wl_list_remove(&m->destroy.link);
wl_list_remove(&m->frame.link); wl_list_remove(&m->frame.link);
@ -651,12 +658,6 @@ cleanupmon(struct wl_listener *listener, void *data)
wlr_output_layout_remove(output_layout, m->wlr_output); wlr_output_layout_remove(output_layout, m->wlr_output);
wlr_scene_output_destroy(m->scene_output); wlr_scene_output_destroy(m->scene_output);
if ((nmons = wl_list_length(&mons)))
do /* don't switch to disabled mons */
selmon = wl_container_of(mons.prev, selmon, link);
while (!selmon->wlr_output->enabled && i++ < nmons);
focusclient(focustop(selmon), 1);
closemon(m); closemon(m);
free(m); free(m);
} }
@ -664,16 +665,26 @@ cleanupmon(struct wl_listener *listener, void *data)
void void
closemon(Monitor *m) closemon(Monitor *m)
{ {
/* move closed monitor's clients to the focused one */ /* update selmon if needed and
* move closed monitor's clients to the focused one */
Client *c; Client *c;
if (wl_list_empty(&mons)) {
selmon = NULL;
} else if (m == selmon) {
int nmons = wl_list_length(&mons), i = 0;
do /* don't switch to disabled mons */
selmon = wl_container_of(mons.next, selmon, link);
while (!selmon->wlr_output->enabled && i++ < nmons);
}
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
if (c->isfloating && c->geom.x > m->m.width) if (c->isfloating && c->geom.x > m->m.width)
resize(c, (struct wlr_box){.x = c->geom.x - m->w.width, .y = c->geom.y, resize(c, (struct wlr_box){.x = c->geom.x - m->w.width, .y = c->geom.y,
.width = c->geom.width, .height = c->geom.height}, 0); .width = c->geom.width, .height = c->geom.height}, 0);
if (c->mon == m) if (c->mon == m)
setmon(c, selmon == m ? NULL : selmon, c->tags); setmon(c, selmon, c->tags);
} }
focusclient(focustop(selmon), 1);
printstatus(); printstatus();
} }
@ -973,6 +984,16 @@ cursorframe(struct wl_listener *listener, void *data)
wlr_seat_pointer_notify_frame(seat); wlr_seat_pointer_notify_frame(seat);
} }
void
destroydragicon(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 void
destroyidleinhibitor(struct wl_listener *listener, void *data) destroyidleinhibitor(struct wl_listener *listener, void *data)
{ {
@ -1019,26 +1040,18 @@ Monitor *
dirtomon(enum wlr_direction dir) dirtomon(enum wlr_direction dir)
{ {
struct wlr_output *next; struct wlr_output *next;
if ((next = wlr_output_layout_adjacent_output(output_layout, if (wlr_output_layout_get(output_layout, selmon->wlr_output)
&& (next = wlr_output_layout_adjacent_output(output_layout,
dir, selmon->wlr_output, selmon->m.x, selmon->m.y))) dir, selmon->wlr_output, selmon->m.x, selmon->m.y)))
return next->data; return next->data;
if ((next = wlr_output_layout_farthest_output(output_layout, if (wlr_output_layout_get(output_layout, selmon->wlr_output)
&& (next = wlr_output_layout_farthest_output(output_layout,
dir ^ (WLR_DIRECTION_LEFT|WLR_DIRECTION_RIGHT), dir ^ (WLR_DIRECTION_LEFT|WLR_DIRECTION_RIGHT),
selmon->wlr_output, selmon->m.x, selmon->m.y))) selmon->wlr_output, selmon->m.x, selmon->m.y)))
return next->data; return next->data;
return selmon; 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 void
focusclient(Client *c, int lift) focusclient(Client *c, int lift)
{ {
@ -1053,15 +1066,14 @@ focusclient(Client *c, int lift)
return; return;
/* Put the new client atop the focus stack and select its monitor */ /* Put the new client atop the focus stack and select its monitor */
if (c) { if (c && !client_is_unmanaged(c)) {
wl_list_remove(&c->flink); wl_list_remove(&c->flink);
wl_list_insert(&fstack, &c->flink); wl_list_insert(&fstack, &c->flink);
selmon = c->mon; selmon = c->mon;
c->isurgent = 0; c->isurgent = 0;
client_restack_surface(c); client_restack_surface(c);
/* Don't change border color if there is a exclusive focus /* Don't change border color if there is an exclusive focus */
* (at this moment it means that a layer surface is focused) */
if (!exclusive_focus) if (!exclusive_focus)
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
wlr_scene_rect_set_color(c->border[i], focuscolor); wlr_scene_rect_set_color(c->border[i], focuscolor);
@ -1072,6 +1084,7 @@ focusclient(Client *c, int lift)
/* If an overlay is focused, don't focus or activate the client, /* If an overlay is focused, don't focus or activate the client,
* but only update its position in fstack to render its border with focuscolor * but only update its position in fstack to render its border with focuscolor
* and focus it after the overlay is closed. */ * and focus it after the overlay is closed. */
Client *w = client_from_wlr_surface(old);
if (wlr_surface_is_layer_surface(old)) { if (wlr_surface_is_layer_surface(old)) {
struct wlr_layer_surface_v1 *wlr_layer_surface = struct wlr_layer_surface_v1 *wlr_layer_surface =
wlr_layer_surface_v1_from_wlr_surface(old); wlr_layer_surface_v1_from_wlr_surface(old);
@ -1080,9 +1093,11 @@ focusclient(Client *c, int lift)
&& (wlr_layer_surface->current.layer == ZWLR_LAYER_SHELL_V1_LAYER_TOP && (wlr_layer_surface->current.layer == ZWLR_LAYER_SHELL_V1_LAYER_TOP
|| wlr_layer_surface->current.layer == ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY)) || wlr_layer_surface->current.layer == ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY))
return; return;
} else { } else if (w && w == exclusive_focus && client_wants_focus(w)) {
Client *w; return;
if ((w = client_from_wlr_surface(old))) /* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg
* and probably other clients */
} else if (w && !client_is_unmanaged(w) && (!c || !client_wants_focus(c))) {
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
wlr_scene_rect_set_color(w->border[i], bordercolor); wlr_scene_rect_set_color(w->border[i], bordercolor);
@ -1322,6 +1337,10 @@ mapnotify(struct wl_listener *listener, void *data)
wlr_scene_node_reparent(&c->scene->node, layers[LyrFloat]); wlr_scene_node_reparent(&c->scene->node, layers[LyrFloat]);
wlr_scene_node_set_position(&c->scene->node, c->geom.x + borderpx, wlr_scene_node_set_position(&c->scene->node, c->geom.x + borderpx,
c->geom.y + borderpx); c->geom.y + borderpx);
if (client_wants_focus(c)) {
focusclient(c, 1);
exclusive_focus = c;
}
return; return;
} }
#endif #endif
@ -1380,7 +1399,8 @@ monocle(Monitor *m)
continue; continue;
resize(c, m->w, 0); resize(c, m->w, 0);
} }
focusclient(focustop(m), 1); if ((c = focustop(m)))
wlr_scene_node_raise_to_top(&c->scene->node);
} }
void void
@ -1402,6 +1422,7 @@ motionnotify(uint32_t time)
{ {
double sx = 0, sy = 0; double sx = 0, sy = 0;
Client *c = NULL; Client *c = NULL;
LayerSurface *l;
struct wlr_surface *surface = NULL; struct wlr_surface *surface = NULL;
struct wlr_drag_icon *icon; struct wlr_drag_icon *icon;
@ -1433,17 +1454,19 @@ motionnotify(uint32_t time)
/* Find the client under the pointer and send the event along. */ /* Find the client under the pointer and send the event along. */
xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy); xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy);
if (cursor_mode == CurPressed) { if (cursor_mode == CurPressed && !seat->drag) {
if ((l = toplevel_from_wlr_layer_surface(
seat->pointer_state.focused_surface))) {
surface = seat->pointer_state.focused_surface; surface = seat->pointer_state.focused_surface;
c = client_from_wlr_surface(surface); sx = cursor->x - l->geom.x;
sx = c ? cursor->x - c->geom.x : 0; sy = cursor->y - l->geom.y;
sy = c ? cursor->y - c->geom.y : 0; }
} }
/* If there's no client surface under the cursor, set the cursor image to a /* If there's no client surface under the cursor, set the cursor image to a
* default. This is what makes the cursor image appear when you move it * default. This is what makes the cursor image appear when you move it
* off of a client or over its border. */ * off of a client or over its border. */
if (!surface && (!cursor_image || strcmp(cursor_image, "left_ptr"))) if (!surface && !seat->drag && (!cursor_image || strcmp(cursor_image, "left_ptr")))
wlr_xcursor_manager_set_cursor_image(cursor_mgr, (cursor_image = "left_ptr"), cursor); wlr_xcursor_manager_set_cursor_image(cursor_mgr, (cursor_image = "left_ptr"), cursor);
pointerfocus(c, surface, sx, sy, time); pointerfocus(c, surface, sx, sy, time);
@ -1467,7 +1490,7 @@ motionrelative(struct wl_listener *listener, void *data)
void void
moveresize(const Arg *arg) moveresize(const Arg *arg)
{ {
if (cursor_mode != CurNormal) if (cursor_mode != CurNormal && cursor_mode != CurPressed)
return; return;
xytonode(cursor->x, cursor->y, NULL, &grabc, NULL, NULL, NULL); xytonode(cursor->x, cursor->y, NULL, &grabc, NULL, NULL, NULL);
if (!grabc || client_is_unmanaged(grabc)) if (!grabc || client_is_unmanaged(grabc))
@ -1512,28 +1535,13 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test)
struct wlr_output_configuration_head_v1 *config_head; struct wlr_output_configuration_head_v1 *config_head;
int ok = 1; int ok = 1;
/* First disable outputs we need to disable */
wl_list_for_each(config_head, &config->heads, link) {
struct wlr_output *wlr_output = config_head->state.output;
if (!wlr_output->enabled || config_head->state.enabled)
continue;
wlr_output_enable(wlr_output, 0);
if (test) {
ok &= wlr_output_test(wlr_output);
wlr_output_rollback(wlr_output);
} else {
ok &= wlr_output_commit(wlr_output);
}
}
/* Then enable outputs that need to */
wl_list_for_each(config_head, &config->heads, link) { wl_list_for_each(config_head, &config->heads, link) {
struct wlr_output *wlr_output = config_head->state.output; struct wlr_output *wlr_output = config_head->state.output;
Monitor *m = wlr_output->data; Monitor *m = wlr_output->data;
if (!config_head->state.enabled)
continue;
wlr_output_enable(wlr_output, 1); wlr_output_enable(wlr_output, config_head->state.enabled);
if (!config_head->state.enabled)
goto apply_or_test;
if (config_head->state.mode) if (config_head->state.mode)
wlr_output_set_mode(wlr_output, config_head->state.mode); wlr_output_set_mode(wlr_output, config_head->state.mode);
else else
@ -1550,6 +1558,7 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test)
wlr_output_set_transform(wlr_output, config_head->state.transform); wlr_output_set_transform(wlr_output, config_head->state.transform);
wlr_output_set_scale(wlr_output, config_head->state.scale); wlr_output_set_scale(wlr_output, config_head->state.scale);
apply_or_test:
if (test) { if (test) {
ok &= wlr_output_test(wlr_output); ok &= wlr_output_test(wlr_output);
wlr_output_rollback(wlr_output); wlr_output_rollback(wlr_output);
@ -1559,7 +1568,7 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test)
* we test if that mode does not fail rather than just call wlr_output_commit(). * we test if that mode does not fail rather than just call wlr_output_commit().
* We do not test normal modes because (at least in my hardware (@sevz17)) * We do not test normal modes because (at least in my hardware (@sevz17))
* wlr_output_test() fails even if that mode can actually be set */ * wlr_output_test() fails even if that mode can actually be set */
if (!config_head->state.mode) if (!config_head->state.mode && config_head->state.enabled)
ok &= (output_ok = wlr_output_test(wlr_output) ok &= (output_ok = wlr_output_test(wlr_output)
&& wlr_output_commit(wlr_output)); && wlr_output_commit(wlr_output));
else else
@ -1579,6 +1588,9 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test)
else else
wlr_output_configuration_v1_send_failed(config); wlr_output_configuration_v1_send_failed(config);
wlr_output_configuration_v1_destroy(config); wlr_output_configuration_v1_destroy(config);
/* TODO: use a wrapper function? */
updatemons(NULL, NULL);
} }
void void
@ -1805,7 +1817,7 @@ setcursor(struct wl_listener *listener, void *data)
/* If we're "grabbing" the cursor, don't use the client's image, we will /* If we're "grabbing" the cursor, don't use the client's image, we will
* restore it after "grabbing" sending a leave event, followed by a enter * restore it after "grabbing" sending a leave event, followed by a enter
* event, which will result in the client requesting set the cursor surface */ * event, which will result in the client requesting set the cursor surface */
if (cursor_mode != CurNormal) if (cursor_mode != CurNormal && cursor_mode != CurPressed)
return; return;
cursor_image = NULL; cursor_image = NULL;
/* This can be sent by any client, so we check to make sure this one is /* This can be sent by any client, so we check to make sure this one is
@ -1980,7 +1992,7 @@ setup(void)
layers[LyrFloat] = wlr_scene_tree_create(&scene->tree); layers[LyrFloat] = wlr_scene_tree_create(&scene->tree);
layers[LyrTop] = wlr_scene_tree_create(&scene->tree); layers[LyrTop] = wlr_scene_tree_create(&scene->tree);
layers[LyrOverlay] = wlr_scene_tree_create(&scene->tree); layers[LyrOverlay] = wlr_scene_tree_create(&scene->tree);
layers[LyrNoFocus] = wlr_scene_tree_create(&scene->tree); layers[LyrDragIcon] = wlr_scene_tree_create(&scene->tree);
/* Create a renderer with the default implementation */ /* Create a renderer with the default implementation */
if (!(drw = wlr_renderer_autocreate(backend))) if (!(drw = wlr_renderer_autocreate(backend)))
@ -2143,7 +2155,7 @@ startdrag(struct wl_listener *listener, void *data)
if (!drag->icon) if (!drag->icon)
return; return;
drag->icon->data = wlr_scene_subsurface_tree_create(layers[LyrNoFocus], drag->icon->surface); drag->icon->data = wlr_scene_subsurface_tree_create(layers[LyrDragIcon], drag->icon->surface);
motionnotify(0); motionnotify(0);
wl_signal_add(&drag->icon->events.destroy, &drag_icon_destroy); wl_signal_add(&drag->icon->events.destroy, &drag_icon_destroy);
} }
@ -2278,14 +2290,17 @@ unmapnotify(struct wl_listener *listener, void *data)
if (c->mon) if (c->mon)
c->mon->un_map = 1; c->mon->un_map = 1;
if (client_is_unmanaged(c)) if (client_is_unmanaged(c)) {
goto end; if (c == exclusive_focus)
exclusive_focus = NULL;
if (client_surface(c) == seat->keyboard_state.focused_surface)
focusclient(selclient(), 1);
} else {
wl_list_remove(&c->link); wl_list_remove(&c->link);
setmon(c, NULL, 0); setmon(c, NULL, 0);
wl_list_remove(&c->flink); wl_list_remove(&c->flink);
}
end:
wl_list_remove(&c->commit.link); wl_list_remove(&c->commit.link);
wlr_scene_node_destroy(&c->scene->node); wlr_scene_node_destroy(&c->scene->node);
printstatus(); printstatus();
@ -2305,14 +2320,32 @@ updatemons(struct wl_listener *listener, void *data)
struct wlr_output_configuration_v1 *config = struct wlr_output_configuration_v1 *config =
wlr_output_configuration_v1_create(); wlr_output_configuration_v1_create();
Client *c; Client *c;
struct wlr_output_configuration_head_v1 *config_head;
Monitor *m; Monitor *m;
/* First remove from the layout the disabled monitors */
wl_list_for_each(m, &mons, link) {
if (m->wlr_output->enabled)
continue;
config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output);
config_head->state.enabled = 0;
/* Remove this output from the layout to avoid cursor enter inside it */
wlr_output_layout_remove(output_layout, m->wlr_output);
closemon(m);
memset(&m->m, 0, sizeof(m->m));
memset(&m->w, 0, sizeof(m->w));
}
/* Insert outputs that need to */
wl_list_for_each(m, &mons, link)
if (m->wlr_output->enabled
&& !wlr_output_layout_get(output_layout, m->wlr_output))
wlr_output_layout_add_auto(output_layout, m->wlr_output);
/* Now that we update the output layout we can get its box */
wlr_output_layout_get_box(output_layout, NULL, &sgeom); wlr_output_layout_get_box(output_layout, NULL, &sgeom);
wl_list_for_each(m, &mons, link) { wl_list_for_each(m, &mons, link) {
struct wlr_output_configuration_head_v1 *config_head = if (!m->wlr_output->enabled)
wlr_output_configuration_head_v1_create(config, m->wlr_output); continue;
config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output);
/* TODO: move clients off disabled monitors */
/* TODO: move focus if selmon is disabled */
/* Get the effective monitor geometry to use for surfaces */ /* Get the effective monitor geometry to use for surfaces */
wlr_output_layout_get_box(output_layout, m->wlr_output, &(m->m)); wlr_output_layout_get_box(output_layout, m->wlr_output, &(m->m));
@ -2323,7 +2356,7 @@ updatemons(struct wl_listener *listener, void *data)
/* Don't move clients to the left output when plugging monitors */ /* Don't move clients to the left output when plugging monitors */
arrange(m); arrange(m);
config_head->state.enabled = m->wlr_output->enabled; config_head->state.enabled = 1;
config_head->state.mode = m->wlr_output->current_mode; config_head->state.mode = m->wlr_output->current_mode;
config_head->state.x = m->m.x; config_head->state.x = m->m.x;
config_head->state.y = m->m.y; config_head->state.y = m->m.y;

View File

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="idle">
<copyright><![CDATA[
Copyright (C) 2015 Martin Gräßlin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
]]></copyright>
<interface name="org_kde_kwin_idle" version="1">
<description summary="User idle time manager">
This interface allows to monitor user idle time on a given seat. The interface
allows to register timers which trigger after no user activity was registered
on the seat for a given interval. It notifies when user activity resumes.
This is useful for applications wanting to perform actions when the user is not
interacting with the system, e.g. chat applications setting the user as away, power
management features to dim screen, etc..
</description>
<request name="get_idle_timeout">
<arg name="id" type="new_id" interface="org_kde_kwin_idle_timeout"/>
<arg name="seat" type="object" interface="wl_seat"/>
<arg name="timeout" type="uint" summary="The idle timeout in msec"/>
</request>
</interface>
<interface name="org_kde_kwin_idle_timeout" version="1">
<request name="release" type="destructor">
<description summary="release the timeout object"/>
</request>
<request name="simulate_user_activity">
<description summary="Simulates user activity for this timeout, behaves just like real user activity on the seat"/>
</request>
<event name="idle">
<description summary="Triggered when there has not been any user activity in the requested idle time interval"/>
</event>
<event name="resumed">
<description summary="Triggered on the first user activity after an idle event"/>
</event>
</interface>
</protocol>

20
util.c
View File

@ -6,16 +6,6 @@
#include "util.h" #include "util.h"
void *
ecalloc(size_t nmemb, size_t size)
{
void *p;
if (!(p = calloc(nmemb, size)))
die("calloc:");
return p;
}
void void
die(const char *fmt, ...) { die(const char *fmt, ...) {
va_list ap; va_list ap;
@ -33,3 +23,13 @@ die(const char *fmt, ...) {
exit(1); exit(1);
} }
void *
ecalloc(size_t nmemb, size_t size)
{
void *p;
if (!(p = calloc(nmemb, size)))
die("calloc:");
return p;
}