Because maprequest immediately calls wl_list_insert(&fstack, &c->flink),
in the following call to setmon(), the selclient() which is passed to
focusclient() as the old client is actually the newly mapped client, and
the real old one is never deactivated. You can see this by, for example,
opening Chromium's devtools, then spawning a terminal. The background of
the focused line in the devtools doesn't change from light blue to grey.
We can't just remove wl_list_insert(&fstack, &c->flink) from maprequest,
because calling wl_list_remove in focusclient() with a client that has
not been added to the list causes a segmentation fault.
Therefore we fix the focusclient call by not passing it the old client
every time, but instead using the wlroots function that gets the focused
surface and deactivate that, like in TinyWL.
This also avoids getting the selected client and passing it to
focusclient() on every call unnecessarily, and will allow removing
shouldfocusclients in a future commit by checking if old is a layer
surface instead.
It makes wl-clipboard work properly in neovim, without having to create
a transparent surface that steals focus and causes flickering. It's also
required for clipman.
The code in this else completely freezes my system when I run the
swayidle command to replicate xset dpms force off. No idea if it works
on multiple monitors, but for now avoid running when there's 1 monitor.
Also remove the comment with the function name in sway.
Since wlr_output_enable doesn't have any effect before finishing all the
procedure, a little hack allows to make use of focusmon(), which must
know the latest in about which output is currently disabled
Also improve performance in focusmon() and cleaner code in
outputmgrapplyortest()
With the recent changes in output-management, the extra argument in
closemon() would be needed only when unplugging the monitor, so it isn't
worth it anymore. Also now is more efficient.
m->link.next leads to errors if the monitor to disable doesn't have a
"next" (right) monitor and is currently focused. dirtmon() does more
checks.
In some previous commits m->link.next is told to be left monitor, which
is wrong
Also focusclient() explicitly checks for disabled monitors (this fixes
in case of more than one disabled monitor)
Focus the top client on newmon, which we know for sure that it isn't
going to be unplugged or disabled and actually set that as the focused
monitor to move the focus. This is necessary to prevent crash when
disabling monitors with the output-management patch.
This allows to fix output-management: move clients to the monitor on the
left of the disabled one, instead of the leftmost (which might happen to
be the disabled one)
Also using wl_list_foreach() and then brake after the first iteration is
ugly and inefficient
When using wlr-randr every monitor's configuration is reevaluated, so it
must check which monitors are actually being disabled. The only way to
correctly do that is to compare the names.
When a monitor is disabled with wlr_randr, all clients on that monitor
aren't lost but they are moved to the leftmost monitor with the same
method that handles monitor hot unplug
There is no need to repeat this. This needs to be reculalculated in my
output-management implementation too, and since I'm already calling
updatemons, this patch avoids having to repeat the assignment again.
Floating widndows with "x < removed monitor's width" aren't resized
(they used to disappear in negative coordinates).
Actually delete monitors when they are unplugged, recalculate sgeom and
give a new monitor to clients that were on the removed one with setmon()
arrangefloat() funcion has been exploded to save iterations in
cleanupmon().
Also if a monitor that supports auto suspension is turned off, dwl will
count it as unplugged (it will become unreachable and all clients will
be moved to the leftmost monitor). However, if at least one monitor
isn't plugged in, dwl will still crash the same as before.
Unlike sway, when the output configuration is changed and restored,
(unplug + plug the same monitor for example) previous application
positions aren't kept. This is due to the fact that on sway every
workspace is unique among all monitors.
Compensate the coordinate changes when adding a new monitor.
Every test so far confirms that monitors are always added to the left,
on top of the list, so every floating window's x coordinate has to be
incremented by the width of the new monitor.
When a monitor is created or removed, the geometries of the old ones
must be updated. This is also more efficient than before since we
calculate the monitor geometries only when creating and destroying
monitors. arrangelayers() is needed to recalculate m->w. arrange() is so
clients don't move to the left monitor when plugging or unplugging
monitors (clients keep the same coordinates but the field below them
changes).