Compare commits

...

59 Commits

Author SHA1 Message Date
Mark Stosberg
5b993db1ce
Merge 6a2fb63cd1 into 4cfcb3643b 2024-11-05 18:39:32 +08:00
Alexander Orzechowski
4cfcb3643b container: Properly constrain title bar padding
Important for centered titles
2024-11-04 19:02:16 +01:00
Simon Ser
d417a8fcd0 release.sh: read meson-rewrite output from stdout
Since version 1.6, Meson now uses stdout:
3f4957c713
2024-10-31 10:31:38 +01:00
Kenny Levinsen
f38719f575 desktop/output: Add missing output config allocation checks 2024-10-30 19:56:07 -04:00
Kenny Levinsen
1e53007bc3 desktop/output: Store output config on request_state
An output backend might request any change to an output state at any
time, although currently only this is currently only used for changing
window size on the wayland and x11 backend.

Applying the configuration directly means that the current output state
becomes inconsistent with the configured state, which can cause the new
state to be reverted later if apply_stored_output_configs is called.

Before 4f9ce4675c. the output geometry would be updated by
arrange_outputs, but this is only done by the modeset logic now,
resulting in the stored geometry never being updated on wayland backend
window resize. This was not discovered as the stored geometry is not
used particularly often.

Solve both by storing a new output configuration and relying on the
modeset logic to apply a new state.

Fixes: 4f9ce4675c ("tree/arrange: Remove redundant output geometry update")
2024-10-30 19:56:07 -04:00
AsciiWolf
e7c972b04a Remove language bars from remaining non-English README files 2024-10-28 14:06:01 +01:00
llyyr
839434abc0 sway/server: bind to presentation-time-v2
Depends on: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4858
2024-10-27 19:20:20 -04:00
Kirill Primak
015e357fce desktop/output: chase wlroots private fields update
This will be replaced with a proper solution later.
2024-10-25 17:42:35 +02:00
Kenny Levinsen
a63027245a config/output: Remove remaining logs from queue_output_config
The job of queue_output_config is now just to fill out a
wlr_output_state according to the output configuration, but it still has
a lot of logging from before we had wlr_output_state or the new modeset
logic, when queue_output_state instead touched the implicit pending
state of wlr_output.

Whatever debug logs it had would already be covered by the output state
debug logs or the command debug logs, so let's just remove it.
2024-10-20 12:22:12 +02:00
Kenny Levinsen
17ecb9eb1d config/output: Remove initial values in find_output_config
Starting by setting some special initial output config values settings
was something sway used to do when the config was initially being
processed. This was later changed to always happen, as there shouldn't
be differences in how output config is calculated during config load and
after.

Most of these values are redundant, as they are either the zero value or
a value that would be selected if the unset (-1) value was found.

For output transforms, the automatic panel orientation code would only
trigger if the final output config has an unset transform, which the
initial values set in find_output_config made impossible.

Remove these initial values and instead use a fresh output config as is.
2024-10-20 12:22:12 +02:00
Kenny Levinsen
af0d4a048a config/output: Always set all output fields on finalize 2024-10-20 12:22:12 +02:00
Kenny Levinsen
7e0c0dda42 config/output: Always set output states from config
queue_output_config had some remaining logic that would avoid setting
output states if they already appeared to be in effect. That is not what
most of the states did nor what is currently expected, so clean that up.
2024-10-20 12:22:12 +02:00
Kenny Levinsen
7d93652105 config/output: Improve modeset state logging
Include scale and subpixel in the output state log, and log the output
state on first commit attempt instead of just during fallback search.
2024-10-20 12:22:12 +02:00
Simon Ser
35d8adefc4 input/seatop_default: refactor move/resize button logic
Make it so config->floating_mod_inverse only applies when pressing
mod, not when clicking on titlebars.

Centralize logic into shared variables.
2024-10-20 00:26:09 -04:00
Alexander Orzechowski
8363699f14 layer_shell: Restore sway 1.9 ordering 2024-10-18 14:10:28 +02:00
Alexander Orzechowski
ce6b2db0f2 layer_shell: Arrange exclusive zone clients first
This makes layer_shell more stable against the order of clients.
2024-10-18 14:10:28 +02:00
Jan Palus
db76fefd0c trigger container update after disabling urgent in timer
switching workspace directly to urgent window creates timer which delays
reset of urgent state so user is able to notice it. make sure state
change is reflected visually as well (border change) by triggering
container update

Fixes: #8377
2024-10-16 13:57:32 -04:00
Simon Ser
dd063a0ef7 input/keyboard: add support for pointer keys
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4775
2024-10-14 21:27:07 +02:00
Simon Ser
17e2e52c6d server: check backend support for timelines
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4848
2024-10-11 13:26:54 -04:00
Furkan Sahin
7f1cd0b73b
input/mouse: bugfix button2 being interpreted as trying to move the container
Man sway(5) specifies that when tiling_drag is enable, the floating_mod
can be used to drag tiling, as well as floating containers. However the
current code indiscriminately assumes any button press to be intended
for moving the container, consequently causing an unintended call to
`seatop_move_tilting:handle_button` rather than
`seatop_default:handle_button` to pass
`state=WL_POINTER_BUTTON_STATE_RELEASED` to `get_active_mouse_binding`

My idea was to make 'Handle moving a tiling container' follow the same
path as 'Handle moving a floating container' because the initial call to
handle moving a floating correctly exits that branch and ends up passing
the RELEASED state to `get_active_mouse_binding`.

Fixes #8334
2024-10-08 18:09:57 +02:00
ShootingStarDragons
f855b0898b fix: sway crashes if switch to another workspace with surface when IME popup is shown
in pr https://github.com/swaywm/sway/pull/8196, when im_popup_surface is unmapped, author set the popup->relative to NULL, butt popup is still in popup groups, where assert the relative is not NULL, this cause the panic

Take the suggestion of Nefsen402, remove the line where set relative to
NULL, and add NULL check in scene_descriptor_destory
2024-10-07 23:07:25 -04:00
Kenny Levinsen
c90cb37b2a Re-init renderer for all outputs on lost context
sway_root.outputs only include enabled outputs. We also need to re-init
the renderer for any disabled outputs, so use sway_root.all_outputs
instead.

Resolves the following heap-use-after-free accessing the render formats
when a disabled output is modeset after a GPU reset has occurred.
2024-10-02 21:09:55 -04:00
Alexander Orzechowski
9a9be01ad4 Fix alpha-modifier-v1 2024-09-29 23:01:14 +02:00
Simon Ser
a2757e5f16 release: push tags before creating GitHub release
Otherwise the GitHub release isn't attached to the Git tag.
2024-09-29 17:44:47 +02:00
Simon Ser
a0b3606f17 Add support for alpha-modifier-v1 2024-09-29 17:19:22 +02:00
Furkan Sahin
00e9a94152 swaybar: Fix 100% cpu usage if dbus dies.
Currently, swaybar does not gracefully die if it detects
that the dbus connection was lost. Although it's not recommended
to restart dbus without restarting the compositor, it can very
easily happen. In the case it does, compositor's tray should
not consume 100% cpu until it has to be force killed.

apply suggestions

just setting the bar to not running will call teardown and unref the
dbus.
2024-09-28 16:23:21 +02:00
Kenny Levinsen
63345977e2 desktop/output: Clear modeset timer on output manager apply
If a modeset timer exists at the time we apply an output manager config,
clear it to avoid a useless double commit.
2024-09-21 17:50:24 -04:00
Kenny Levinsen
cdff4f7c74 config: Batch input/output configuration on load
We batch modesets and input configuration performed during config reload
but commit for every command during the intial config load. There is no
need to perform commits during the initial config load as outputs have
not yet been created, but swaybg spawn should still be batched.

At the same time, replace direct calls to apply output configuration
with request_modeset to properly handle the modeset timer.
2024-09-21 17:50:24 -04:00
Kenny Levinsen
b73f54a966 desktop/output: Expose request_modeset
We remove the struct sway_server argument for consistency with the rest
of our internal APIs which rely on the global server instance.
2024-09-21 17:50:24 -04:00
Olivia Taliesin
b6da218974 Removed destination-is-ancestor check from container_move_to_container to match i3 behaviour 2024-09-21 17:46:20 -04:00
Kenny Levinsen
861dde100a commands/gaps: Check config->reading instead
Checking if the config is not active or is reloading is just a
convoluted way of checking if the config is being read.
2024-09-21 16:16:19 +02:00
Alexander Orzechowski
e9dd218231 text_input: Inline input_popup_update into input_popup_set_focus
This seems to be the intention of input_popup_update in the first place:
handle the scenario where the focus moves.
2024-09-20 19:40:18 +02:00
Alexander Orzechowski
74e507962e text_input: Properly handle map/unmap events
The last implementation would ignore these and get it could get into
a bad state where it would start crashing sway.
2024-09-20 19:40:18 +02:00
Alexander Orzechowski
023f6b0a50 transaction: Allow no popup descriptor in popup list
Input method popups in the future will destroy the scene descriptor when
it isn't mapped and therefore shouldn't be tampered with here.
2024-09-20 19:40:18 +02:00
Alexander Orzechowski
1537c9dae5 text_input: Move popup placement to own function 2024-09-20 19:40:18 +02:00
Alexander Orzechowski
48069097ea text_input: Check for allocation failure 2024-09-20 19:40:18 +02:00
Scott Dubinsky
266cd4515a Remove unguarded double include 2024-09-20 17:18:26 +02:00
Emil Engberg
e940acd374 Add toggle for output adaptive_sync 2024-09-20 15:38:27 +02:00
Kenny Levinsen
9765c29be1 config/output: Stringify render format when logging it 2024-09-20 14:08:04 +02:00
Kenny Levinsen
034d02f8a5 config/output: Add support for 6-bit render fmt
GUD devices uses RGB565 by default for performance reasons. Allow
specifying render_bit_depth 6 to pick this format. The definition works
out if you consider the maximum number of bits per channel instead of
the average.
2024-09-20 14:08:04 +02:00
Kenny Levinsen
785a459a55 ext-session-lock: Do not use commit listener to arrange
Arranging lock surfaces rely on the sway_output width and height being
updated, but these are only updated after the commit has been completed
and all commit listeners have executed. This means that the lock
surfaces will not be appropriately scaled to match a change in output
dimensions, and may reveal what is under the lock background.

Replace the implicit arrange through the output commit listener with an
explicit arrange after the output configuration is finalized.

This might have regressed by other transition away from output commit
listeners for other arrange tasks, but even then it would have
erroneously relied on signalling order.
2024-09-20 00:26:36 -04:00
Steffen Dirkwinkel
f957c7e658 config/output: support DRM_FORMAT_ARGB8888
Some display output hardware [1] doesn't support any of the current
formats, but works with ARGB8888. Fall back to it if available.

[1] 196145c606/drivers/gpu/drm/xlnx/zynqmp_disp.c (L313)

Signed-off-by: Steffen Dirkwinkel <s.dirkwinkel@beckhoff.com>
2024-09-13 13:09:48 +02:00
Kenny Levinsen
d7a76d381b config/output: Rename to apply_stored_output_configs 2024-09-10 14:13:36 -04:00
Kenny Levinsen
29b3f00e6f config/output: Accept a list of output_configs to use
Instead of using a single finalized output config per output, accept a
regular list of output configs like the one ultimately stored for
configuration purposes. This allows the output management code to test
an augmented configuration while still using the same output config
logic, without having to mutate the stored configuration.

This in turn allows us to make a few APIs private. A bug note about an
existing issue with derade to off is added as well.
2024-09-10 14:13:36 -04:00
Kenny Levinsen
0496477f92 config/output: Always start with default in find_output_config
We always need to start out with the default configuration, regardless
of whether the config is reloading or not to ensure that config
decisions are stable given a specific configuration.
2024-09-10 14:13:36 -04:00
Kenny Levinsen
a0c0349934 config/output: Support multiple matches in find_output_config
Simplify find_output_config and inline the search through the output
configs instead of using list_seq_find with a comparator function. The
new implementation will merge any amount of matched configs in order,
which will be relied upon in a future commit.
2024-09-10 14:13:36 -04:00
Adam Chovanec
fb5eadc363 readme: update Czech translation 2024-09-08 16:06:26 +02:00
llyyr
c5ba7f23a5 sway/input/keyboard: always set active keyboard if there is none
Previously, we incorrectly only set active keyboard for non-virtual
devices. 4c3c060211 incorrectly put
unrelated code in `sway_keyboard_set_layout`.

Fixes: 4c3c060211
2024-09-08 14:18:01 +02:00
Kenny Levinsen
f4a6b0395f tree/arrange; Skip arranging disabled outputs
Disabled outputs might not have a geometry to arrange for, so skip the
arrange to avoid messing up the workspace geometry.
2024-09-07 20:11:30 -04:00
Kenny Levinsen
14bff7b451 desktop/transaction: Deactivate workspace on inactive outputs
If the output is not active, it might not have a valid geometry to
arrange for. Outputs do not gain a geometry until modeset, so if an
output is connected with a configuration present to disable it, it will
not have a geometry. If the output has a past workspace restored, this
will be attemtped arranged to fit a 0x0 rectangle, which asserts when
trying to sort out borders.

Consider the workspace activated only if the output itself is active to
get the scene nodes disabled.
2024-09-07 20:11:30 -04:00
Kenny Levinsen
4f9ce4675c tree/arrange: Remove redundant output geometry update
This is handled by apply_output_configs.
2024-09-07 20:11:30 -04:00
Alexander Orzechowski
fc6b8d6af2 container: Skip % char if it doesn't match a view property
The else condition was missed here and we would never skip the % char
if it didn't end up matching with any property. Since we fail to skip
we would re-evaluate the % in an infinite loop never achieving any
forward-progress.

Fixes: https://github.com/swaywm/sway/issues/8333
2024-09-07 01:19:31 +02:00
Kenny Levinsen
4fe054c6db tree/output: Avoid duplicate input mapping configure 2024-09-05 18:19:16 -04:00
Kenny Levinsen
cfb292cca7 desktop/output: Avoid duplicate output manager update 2024-09-05 18:19:16 -04:00
Kenny Levinsen
af28ac04a4 (desktop|tree)/output: Do not use layout listener to arrange
Output layout changes originate from the centralized modeset
infrastructure and request_state which already takes care of arranging
and updating outputs as needed.
2024-09-04 13:49:35 -04:00
Kenny Levinsen
6045ad9a02 tree/output: Rely on modeset arranging root
output_enable/output_disable are only called from modeset, and from
output destroy which requests modeset. As such, they can rely on the
modeset handling arrange.
2024-09-04 13:49:35 -04:00
Kenny Levinsen
b83e5aaa54 desktop/output: Do not use commit listener to arrange
The reasoning for using a commit handler is to ensure that all paths for
output changes are correctly handled. With the centralized modeset
infrastructure in place, we can move the logic there. This allows us to
be smarter and avoid extraneous arranges, output manager updates and
transaction commits.

The side-effect is a minor duplication for the special-case
request_state, but the shared path will be relied upon further in future
commits to justify this duplication.
2024-09-04 13:49:35 -04:00
Norbert Bolanowski
be840f730e move title_format to container 2024-09-02 16:49:05 -04:00
Mark Stosberg
6a2fb63cd1 docs: Clarify how to use a custom XKB symbol file.
This was not covered in `man sway-input` nor `man xkeyboard-config`

Fixes #7229
2022-11-16 13:58:41 -05:00
41 changed files with 740 additions and 629 deletions

View File

@ -1,7 +1,5 @@
# sway
[English][en] - **[Česky][cs]** - [Deutsch][de] - [Dansk][dk] - [Español][es] - [Français][fr] - [Svenska][sv] - [Ελληνικά][gr] - [हिन्दी][hi] - [Magyar][hu] - [فارسی][ir] - [Italiano][it] - [日本語][ja] - [한국어][ko] - [Nederlands][nl] - [Polski][pl] - [Português][pt] - [Română][ro] - [Русский][ru] - [Türkçe][tr] - [Українська][uk] - [中文-简体][zh-CN] - [中文-繁體][zh-TW]
sway je s [i3] kompatibilní [Wayland] kompozitor. Přečtěte si [FAQ]. Připojte se na
[IRC kanál][IRC channel] \(#sway na irc.libera.chat).
@ -32,10 +30,11 @@ Nainstalujte závislosti:
* pango
* cairo
* gdk-pixbuf2 (volitelné: oznamovací oblast)
* [swaybg] (volitelné: tapeta)
* [scdoc] (volitelné: manuálové stránky) \*
* git (volitelné: informace o verzi) \*
_\* Závislost pouze pro sestavení_
_\* Závislost pouze pro kompilaci_
Spusťte tyto příkazy:
@ -56,12 +55,13 @@ Spusťte `sway` z TTY. Některé správce zobrazení mohou fungovat, ale nejsou
podporovány sway (je známo, že gdm funguje docela dobře).
[en]: https://github.com/swaywm/sway#readme
[ar]: README.ar.md
[cs]: README.cs.md
[de]: README.de.md
[dk]: README.dk.md
[es]: README.es.md
[fr]: README.fr.md
[sv]: README.sv.md
[ge]: README.ge.md
[gr]: README.gr.md
[hi]: README.hi.md
[hu]: README.hu.md
@ -70,10 +70,12 @@ podporovány sway (je známo, že gdm funguje docela dobře).
[ja]: README.ja.md
[ko]: README.ko.md
[nl]: README.nl.md
[no]: README.no.md
[pl]: README.pl.md
[pt]: README.pt.md
[ro]: README.ro.md
[ru]: README.ru.md
[sv]: README.sv.md
[tr]: README.tr.md
[uk]: README.uk.md
[zh-CN]: README.zh-CN.md
@ -86,4 +88,5 @@ podporovány sway (je známo, že gdm funguje docela dobře).
[GitHub releases]: https://github.com/swaywm/sway/releases
[Development setup]: https://github.com/swaywm/sway/wiki/Development-Setup
[wlroots]: https://gitlab.freedesktop.org/wlroots/wlroots
[swaybg]: https://github.com/swaywm/swaybg/
[scdoc]: https://git.sr.ht/~sircmpwn/scdoc

View File

@ -1,7 +1,5 @@
# sway
[English][en] - [Deutsch][de] - [Dansk][dk] - [Español][es] - [Français][fr] - **[Svenska][sv]** - [Ελληνικά][gr] - [Magyar][hu] - [فارسی][ir] - [Italiano][it] - [日本語][ja] - [한국어][ko] - [Nederlands][nl] - [Polski][pl] - [Português][pt] - [Română][ro] - [Русский][ru] - [Türkçe][tr] - [Українська][uk] - [中文-简体][zh-CN] - [中文-繁體][zh-TW]
sway är en [i3]-kompatibel [Wayland] compositor. Läs våran [FAQ]-sida. Gå med i vår
[IRC-kanal] \(#sway på irc.libera.chat).

View File

@ -262,6 +262,7 @@ enum scale_filter_mode {
enum render_bit_depth {
RENDER_BIT_DEPTH_DEFAULT, // the default is currently 8
RENDER_BIT_DEPTH_6,
RENDER_BIT_DEPTH_8,
RENDER_BIT_DEPTH_10,
};
@ -296,14 +297,6 @@ struct output_config {
char *background_fallback;
};
/**
* An output config pre-matched to an output
*/
struct matched_output_config {
struct sway_output *output;
struct output_config *config;
};
/**
* Stores size of gaps for each side
*/
@ -693,13 +686,10 @@ const char *sway_output_scale_filter_to_string(enum scale_filter_mode scale_filt
struct output_config *new_output_config(const char *name);
bool apply_output_configs(struct matched_output_config *configs,
size_t configs_len, bool test_only, bool degrade_to_off);
bool apply_output_configs(struct output_config **ocs, size_t ocs_len,
bool test_only, bool degrade_to_off);
void apply_all_output_configs(void);
void sort_output_configs_by_priority(struct matched_output_config *configs,
size_t configs_len);
void apply_stored_output_configs(void);
/**
* store_output_config stores a new output config. An output may be matched by
@ -714,6 +704,8 @@ struct output_config *find_output_config(struct sway_output *output);
void free_output_config(struct output_config *oc);
void request_modeset(void);
bool spawn_swaybg(void);
int workspace_output_cmp_workspace(const void *a, const void *b);

View File

@ -9,11 +9,14 @@ struct sway_input_popup {
struct wlr_scene_tree *scene_tree;
struct sway_popup_desc desc;
struct wlr_input_popup_surface_v2 *popup_surface;
struct wlr_output *fixed_output;
struct wl_list link;
struct wl_listener popup_destroy;
struct wl_listener popup_surface_commit;
struct wl_listener popup_surface_map;
struct wl_listener popup_surface_unmap;
struct wl_listener focused_surface_unmap;
};

6
include/sway/lock.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef _SWAY_LOCK_H
#define _SWAY_LOCK_H
void arrange_locks(void);
#endif

View File

@ -57,7 +57,6 @@ struct sway_output {
struct wl_listener layout_destroy;
struct wl_listener destroy;
struct wl_listener commit;
struct wl_listener present;
struct wl_listener frame;
struct wl_listener request_state;
@ -135,8 +134,6 @@ enum sway_container_layout output_get_default_layout(
enum wlr_direction opposite_direction(enum wlr_direction d);
void handle_output_layout_change(struct wl_listener *listener, void *data);
void handle_output_manager_apply(struct wl_listener *listener, void *data);
void handle_output_manager_test(struct wl_listener *listener, void *data);
@ -146,4 +143,6 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener,
struct sway_output_non_desktop *output_non_desktop_create(struct wlr_output *wlr_output);
void update_output_manager_config(struct sway_server *server);
#endif

View File

@ -45,7 +45,6 @@ struct sway_server {
struct sway_input_manager *input;
struct wl_listener new_output;
struct wl_listener output_layout_change;
struct wl_listener renderer_lost;
struct wlr_idle_notifier_v1 *idle_notifier_v1;

View File

@ -102,6 +102,8 @@ struct sway_container {
char *title; // The view's title (unformatted)
char *formatted_title; // The title displayed in the title bar
int title_width;
char *title_format;
enum sway_container_layout prev_split_layout;
@ -183,6 +185,8 @@ void container_update_title_bar(struct sway_container *container);
void container_update_marks(struct sway_container *container);
size_t parse_title_format(struct sway_container *container, char *buffer);
size_t container_build_representation(enum sway_container_layout layout,
list_t *children, char *buffer);

View File

@ -16,8 +16,6 @@ struct sway_root {
struct sway_node node;
struct wlr_output_layout *output_layout;
struct wl_listener output_layout_change;
// scene node layout:
// - root
// - staging

View File

@ -80,8 +80,6 @@ struct sway_view {
// Used when changing a view from tiled to floating.
int natural_width, natural_height;
char *title_format;
bool using_csd;
struct timespec urgent;

View File

@ -1,7 +1,7 @@
#!/bin/sh -eu
prev=$(git describe --tags --abbrev=0)
next=$(meson rewrite kwargs info project / 2>&1 >/dev/null | jq -r '.kwargs["project#/"].version')
next=$(meson rewrite kwargs info project / | jq -r '.kwargs["project#/"].version')
case "$next" in
*-dev)
@ -28,4 +28,5 @@ archive=$prefix.tar.gz
git archive --prefix="$prefix/" -o "$archive" "$next"
gpg --output "$archive".sig --detach-sig "$archive"
git push --follow-tags
gh release create "sway $next" -t "$next" -n "" -d "$archive" "$archive.sig"

View File

@ -215,15 +215,13 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
return error;
}
bool config_loading = !config->active || config->reloading;
if (argc == 2) {
return gaps_set_defaults(argc, argv);
}
if (argc == 4 && !config_loading) {
if (argc == 4 && !config->reading) {
return gaps_set_runtime(argc, argv);
}
if (config_loading) {
if (config->reading) {
return cmd_results_new(CMD_INVALID, "Expected %s", expected_defaults);
}
return cmd_results_new(CMD_INVALID, "Expected %s or %s",

View File

@ -94,7 +94,7 @@ struct cmd_results *cmd_input(int argc, char **argv) {
return res;
}
if (!config->reloading) {
if (!config->reading) {
input_manager_apply_input_config(ic);
}
} else {

View File

@ -240,7 +240,6 @@ static void container_move_to_workspace(struct sway_container *container,
static void container_move_to_container(struct sway_container *container,
struct sway_container *destination) {
if (container == destination
|| container_has_ancestor(container, destination)
|| container_has_ancestor(destination, container)) {
return;
}

View File

@ -107,17 +107,16 @@ struct cmd_results *cmd_output(int argc, char **argv) {
store_output_config(output);
// If reloading, the output configs will be applied after reading the
// entire config and before the deferred commands so that an auto generated
// workspace name is not given to re-enabled outputs.
if (!config->reloading && !config->validating) {
apply_all_output_configs();
if (background) {
if (!spawn_swaybg()) {
return cmd_results_new(CMD_FAILURE,
"Failed to apply background configuration");
}
}
if (config->reading) {
// When reading the config file, we wait till the end to do a single
// modeset and swaybg spawn.
return cmd_results_new(CMD_SUCCESS, NULL);
}
request_modeset();
if (background && !spawn_swaybg()) {
return cmd_results_new(CMD_FAILURE,
"Failed to apply background configuration");
}
return cmd_results_new(CMD_SUCCESS, NULL);

View File

@ -1,5 +1,7 @@
#include <strings.h>
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/output.h"
#include "util.h"
struct cmd_results *output_cmd_adaptive_sync(int argc, char **argv) {
@ -10,12 +12,26 @@ struct cmd_results *output_cmd_adaptive_sync(int argc, char **argv) {
return cmd_results_new(CMD_INVALID, "Missing adaptive_sync argument");
}
if (parse_boolean(argv[0], true)) {
config->handler_context.output_config->adaptive_sync = 1;
} else {
config->handler_context.output_config->adaptive_sync = 0;
bool current_value = true;
if (strcasecmp(argv[0], "toggle") == 0) {
const char *oc_name = config->handler_context.output_config->name;
if (strcmp(oc_name, "*") == 0) {
return cmd_results_new(CMD_INVALID,
"Cannot apply toggle to all outputs");
}
struct sway_output *sway_output = all_output_by_name_or_id(oc_name);
if (!sway_output || !sway_output->wlr_output) {
return cmd_results_new(CMD_FAILURE,
"Cannot apply toggle to unknown output %s", oc_name);
}
current_value =
sway_output->wlr_output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED;
}
config->handler_context.output_config->adaptive_sync = parse_boolean(argv[0], current_value);
config->handler_context.leftovers.argc = argc - 1;
config->handler_context.leftovers.argv = argv + 1;
return NULL;

View File

@ -11,7 +11,10 @@ struct cmd_results *output_cmd_render_bit_depth(int argc, char **argv) {
return cmd_results_new(CMD_INVALID, "Missing bit depth argument.");
}
if (strcmp(*argv, "8") == 0) {
if (strcmp(*argv, "6") == 0) {
config->handler_context.output_config->render_bit_depth =
RENDER_BIT_DEPTH_6;
} else if (strcmp(*argv, "8") == 0) {
config->handler_context.output_config->render_bit_depth =
RENDER_BIT_DEPTH_8;
} else if (strcmp(*argv, "10") == 0) {
@ -19,7 +22,7 @@ struct cmd_results *output_cmd_render_bit_depth(int argc, char **argv) {
RENDER_BIT_DEPTH_10;
} else {
return cmd_results_new(CMD_INVALID,
"Invalid bit depth. Must be a value in (8|10).");
"Invalid bit depth. Must be a value in (6|8|10).");
}
config->handler_context.leftovers.argc = argc - 1;

View File

@ -1,3 +1,4 @@
#define _POSIX_C_SOURCE 200809L
#include <string.h>
#include "sway/commands.h"
#include "sway/config.h"
@ -11,16 +12,19 @@ struct cmd_results *cmd_title_format(int argc, char **argv) {
return error;
}
struct sway_container *container = config->handler_context.container;
if (!container || !container->view) {
if (!container) {
return cmd_results_new(CMD_INVALID,
"Only views can have a title_format");
"Only valid containers can have a title_format");
}
struct sway_view *view = container->view;
char *format = join_args(argv, argc);
if (view->title_format) {
free(view->title_format);
if (container->title_format) {
free(container->title_format);
}
container->title_format = format;
if (container->view) {
view_update_title(container->view, true);
} else {
container_update_representation(container);
}
view->title_format = format;
view_update_title(view, true);
return cmd_results_new(CMD_SUCCESS, NULL);
}

View File

@ -516,7 +516,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
// Only really necessary if not explicitly `font` is set in the config.
config_update_font_height();
if (is_active && !validating) {
if (!validating) {
input_manager_verify_fallback_seat();
for (int i = 0; i < config->input_configs->length; i++) {
@ -533,12 +533,14 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
}
sway_switch_retrigger_bindings_for_all();
apply_all_output_configs();
spawn_swaybg();
config->reloading = false;
if (config->swaynag_config_errors.client != NULL) {
swaynag_show(&config->swaynag_config_errors);
if (is_active) {
request_modeset();
if (config->swaynag_config_errors.client != NULL) {
swaynag_show(&config->swaynag_config_errors);
}
}
}

View File

@ -10,10 +10,15 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_swapchain_manager.h>
#include <xf86drm.h>
#include "sway/config.h"
#include "sway/desktop/transaction.h"
#include "sway/input/cursor.h"
#include "sway/layers.h"
#include "sway/lock.h"
#include "sway/output.h"
#include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/root.h"
#include "log.h"
#include "util.h"
@ -22,13 +27,6 @@
#include <wlr/backend/drm.h>
#endif
int output_name_cmp(const void *item, const void *data) {
const struct output_config *output = item;
const char *name = data;
return strcmp(output->name, name);
}
void output_get_identifier(char *identifier, size_t len,
struct sway_output *output) {
struct wlr_output *wlr_output = output->wlr_output;
@ -287,7 +285,6 @@ static void set_mode(struct wlr_output *output, struct wlr_output_state *pending
mhz = mhz <= 0 ? INT_MAX : mhz;
if (wl_list_empty(&output->modes) || custom) {
sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name);
wlr_output_state_set_custom_mode(pending, width, height,
refresh_rate > 0 ? mhz : 0);
return;
@ -307,10 +304,7 @@ static void set_mode(struct wlr_output *output, struct wlr_output_state *pending
}
}
}
if (best) {
sway_log(SWAY_INFO, "Assigning configured mode (%dx%d@%.3fHz) to %s",
best->width, best->height, best->refresh / 1000.f, output->name);
} else {
if (!best) {
best = wlr_output_preferred_mode(output);
sway_log(SWAY_INFO, "Configured mode (%dx%d@%.3fHz) not available, "
"applying preferred mode (%dx%d@%.3fHz)",
@ -327,7 +321,6 @@ static void set_modeline(struct wlr_output *output,
sway_log(SWAY_ERROR, "Modeline can only be set to DRM output");
return;
}
sway_log(SWAY_DEBUG, "Assigning custom modeline to %s", output->name);
struct wlr_output_mode *mode = wlr_drm_connector_add_mode(output, drm_mode);
if (mode) {
wlr_output_state_set_mode(pending, mode);
@ -393,7 +386,6 @@ static int compute_default_scale(struct wlr_output *output,
double dpi_x = (double) width / (output->phys_width / MM_PER_INCH);
double dpi_y = (double) height / (output->phys_height / MM_PER_INCH);
sway_log(SWAY_DEBUG, "Output DPI: %fx%f", dpi_x, dpi_y);
if (dpi_x <= HIDPI_DPI_LIMIT || dpi_y <= HIDPI_DPI_LIMIT) {
return 1;
}
@ -401,9 +393,15 @@ static int compute_default_scale(struct wlr_output *output,
return 2;
}
static bool render_format_is_10bit(uint32_t render_format) {
return render_format == DRM_FORMAT_XRGB2101010 ||
render_format == DRM_FORMAT_XBGR2101010;
static enum render_bit_depth bit_depth_from_format(uint32_t render_format) {
if (render_format == DRM_FORMAT_XRGB2101010 || render_format == DRM_FORMAT_XBGR2101010) {
return RENDER_BIT_DEPTH_10;
} else if (render_format == DRM_FORMAT_XRGB8888 || render_format == DRM_FORMAT_ARGB8888) {
return RENDER_BIT_DEPTH_8;
} else if (render_format == DRM_FORMAT_RGB565) {
return RENDER_BIT_DEPTH_6;
}
return RENDER_BIT_DEPTH_DEFAULT;
}
static bool render_format_is_bgr(uint32_t fmt) {
@ -423,90 +421,73 @@ static void queue_output_config(struct output_config *oc,
struct wlr_output *wlr_output = output->wlr_output;
if (output_config_is_disabling(oc)) {
sway_log(SWAY_DEBUG, "Turning off output %s", wlr_output->name);
wlr_output_state_set_enabled(pending, false);
return;
}
sway_log(SWAY_DEBUG, "Turning on output %s", wlr_output->name);
wlr_output_state_set_enabled(pending, true);
if (oc && oc->drm_mode.type != 0 && oc->drm_mode.type != (uint32_t) -1) {
sway_log(SWAY_DEBUG, "Set %s modeline",
wlr_output->name);
set_modeline(wlr_output, pending, &oc->drm_mode);
} else if (oc && oc->width > 0 && oc->height > 0) {
sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)",
wlr_output->name, oc->width, oc->height, oc->refresh_rate);
set_mode(wlr_output, pending, oc->width, oc->height,
oc->refresh_rate, oc->custom_mode == 1);
} else if (!wl_list_empty(&wlr_output->modes)) {
sway_log(SWAY_DEBUG, "Set preferred mode");
struct wlr_output_mode *preferred_mode =
wlr_output_preferred_mode(wlr_output);
wlr_output_state_set_mode(pending, preferred_mode);
}
if (oc && (oc->subpixel != WL_OUTPUT_SUBPIXEL_UNKNOWN || config->reloading)) {
sway_log(SWAY_DEBUG, "Set %s subpixel to %s", oc->name,
sway_wl_output_subpixel_to_string(oc->subpixel));
if (oc && oc->subpixel != WL_OUTPUT_SUBPIXEL_UNKNOWN) {
wlr_output_state_set_subpixel(pending, oc->subpixel);
} else {
wlr_output_state_set_subpixel(pending, output->detected_subpixel);
}
enum wl_output_transform tr = WL_OUTPUT_TRANSFORM_NORMAL;
if (oc && oc->transform >= 0) {
tr = oc->transform;
wlr_output_state_set_transform(pending, oc->transform);
#if WLR_HAS_DRM_BACKEND
} else if (wlr_output_is_drm(wlr_output)) {
tr = wlr_drm_connector_get_panel_orientation(wlr_output);
sway_log(SWAY_DEBUG, "Auto-detected output transform: %d", tr);
wlr_output_state_set_transform(pending,
wlr_drm_connector_get_panel_orientation(wlr_output));
#endif
}
if (wlr_output->transform != tr) {
sway_log(SWAY_DEBUG, "Set %s transform to %d", wlr_output->name, tr);
wlr_output_state_set_transform(pending, tr);
} else {
wlr_output_state_set_transform(pending, WL_OUTPUT_TRANSFORM_NORMAL);
}
// Apply the scale last before the commit, because the scale auto-detection
// reads the pending output size
float scale;
// Apply the scale after sorting out the mode, because the scale
// auto-detection reads the pending output size
if (oc && oc->scale > 0) {
scale = oc->scale;
// The factional-scale-v1 protocol uses increments of 120ths to send
// the scale factor to the client. Adjust the scale so that we use the
// same value as the clients'.
float adjusted_scale = round(scale * 120) / 120;
if (scale != adjusted_scale) {
sway_log(SWAY_INFO, "Adjusting output scale from %f to %f",
scale, adjusted_scale);
scale = adjusted_scale;
}
wlr_output_state_set_scale(pending, round(oc->scale * 120) / 120);
} else {
scale = compute_default_scale(wlr_output, pending);
sway_log(SWAY_DEBUG, "Auto-detected output scale: %f", scale);
}
if (scale != wlr_output->scale) {
sway_log(SWAY_DEBUG, "Set %s scale to %f", wlr_output->name, scale);
wlr_output_state_set_scale(pending, scale);
wlr_output_state_set_scale(pending,
compute_default_scale(wlr_output, pending));
}
if (oc && oc->adaptive_sync != -1 && wlr_output->adaptive_sync_supported) {
sway_log(SWAY_DEBUG, "Set %s adaptive sync to %d", wlr_output->name,
oc->adaptive_sync);
wlr_output_state_set_adaptive_sync_enabled(pending, oc->adaptive_sync == 1);
if (wlr_output->adaptive_sync_supported) {
if (oc && oc->adaptive_sync != -1) {
wlr_output_state_set_adaptive_sync_enabled(pending, oc->adaptive_sync == 1);
} else {
wlr_output_state_set_adaptive_sync_enabled(pending, false);
}
}
if (oc && oc->render_bit_depth != RENDER_BIT_DEPTH_DEFAULT) {
if (oc->render_bit_depth == RENDER_BIT_DEPTH_10 &&
render_format_is_10bit(output->wlr_output->render_format)) {
bit_depth_from_format(output->wlr_output->render_format) == oc->render_bit_depth) {
// 10-bit was set successfully before, try to save some tests by reusing the format
wlr_output_state_set_render_format(pending, output->wlr_output->render_format);
} else if (oc->render_bit_depth == RENDER_BIT_DEPTH_10) {
wlr_output_state_set_render_format(pending, DRM_FORMAT_XRGB2101010);
} else if (oc->render_bit_depth == RENDER_BIT_DEPTH_6){
wlr_output_state_set_render_format(pending, DRM_FORMAT_RGB565);
} else {
wlr_output_state_set_render_format(pending, DRM_FORMAT_XRGB8888);
}
} else {
wlr_output_state_set_render_format(pending, DRM_FORMAT_XRGB8888);
}
}
@ -525,24 +506,23 @@ static bool finalize_output_config(struct output_config *oc, struct sway_output
return true;
}
if (oc) {
enum scale_filter_mode scale_filter_old = output->scale_filter;
switch (oc->scale_filter) {
case SCALE_FILTER_DEFAULT:
case SCALE_FILTER_SMART:
output->scale_filter = ceilf(wlr_output->scale) == wlr_output->scale ?
SCALE_FILTER_NEAREST : SCALE_FILTER_LINEAR;
break;
case SCALE_FILTER_LINEAR:
case SCALE_FILTER_NEAREST:
output->scale_filter = oc->scale_filter;
break;
}
if (scale_filter_old != output->scale_filter) {
sway_log(SWAY_DEBUG, "Set %s scale_filter to %s", oc->name,
sway_output_scale_filter_to_string(output->scale_filter));
wlr_damage_ring_add_whole(&output->scene_output->damage_ring);
}
enum scale_filter_mode scale_filter_old = output->scale_filter;
enum scale_filter_mode scale_filter_new = oc ? oc->scale_filter : SCALE_FILTER_DEFAULT;
switch (scale_filter_new) {
case SCALE_FILTER_DEFAULT:
case SCALE_FILTER_SMART:
output->scale_filter = ceilf(wlr_output->scale) == wlr_output->scale ?
SCALE_FILTER_NEAREST : SCALE_FILTER_LINEAR;
break;
case SCALE_FILTER_LINEAR:
case SCALE_FILTER_NEAREST:
output->scale_filter = scale_filter_new;
break;
}
if (scale_filter_old != output->scale_filter) {
sway_log(SWAY_DEBUG, "Set %s scale_filter to %s", oc->name,
sway_output_scale_filter_to_string(output->scale_filter));
wlr_damage_ring_add_whole(&output->scene_output->damage_ring);
}
// Find position for it
@ -565,92 +545,60 @@ static bool finalize_output_config(struct output_config *oc, struct sway_output
output_enable(output);
}
if (oc && oc->max_render_time >= 0) {
sway_log(SWAY_DEBUG, "Set %s max render time to %d",
oc->name, oc->max_render_time);
output->max_render_time = oc->max_render_time;
}
if (oc && oc->set_color_transform) {
if (oc->color_transform) {
wlr_color_transform_ref(oc->color_transform);
}
wlr_color_transform_unref(output->color_transform);
output->color_transform = oc->color_transform;
} else {
wlr_color_transform_unref(output->color_transform);
output->color_transform = NULL;
}
if (oc && oc->allow_tearing >= 0) {
sway_log(SWAY_DEBUG, "Set %s allow tearing to %d",
oc->name, oc->allow_tearing);
output->allow_tearing = oc->allow_tearing;
}
output->max_render_time = oc && oc->max_render_time > 0 ? oc->max_render_time : 0;
output->allow_tearing = oc && oc->allow_tearing > 0;
return true;
}
static void default_output_config(struct output_config *oc,
struct wlr_output *wlr_output) {
oc->enabled = 1;
oc->power = 1;
struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
if (mode != NULL) {
oc->width = mode->width;
oc->height = mode->height;
oc->refresh_rate = mode->refresh / 1000.f;
}
oc->x = oc->y = -1;
oc->scale = 0; // auto
oc->scale_filter = SCALE_FILTER_DEFAULT;
struct sway_output *output = wlr_output->data;
oc->subpixel = output->detected_subpixel;
oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
oc->max_render_time = 0;
oc->allow_tearing = 0;
}
// find_output_config returns a merged output_config containing all stored
// configuration that applies to the specified output.
struct output_config *find_output_config(struct sway_output *sway_output) {
// find_output_config_from_list returns a merged output_config containing all
// stored configuration that applies to the specified output.
static struct output_config *find_output_config_from_list(
struct output_config **configs, size_t configs_len,
struct sway_output *sway_output) {
const char *name = sway_output->wlr_output->name;
struct output_config *oc = NULL;
struct output_config *result = new_output_config(name);
if (config->reloading) {
default_output_config(result, sway_output->wlr_output);
if (result == NULL) {
return NULL;
}
char id[128];
output_get_identifier(id, sizeof(id), sway_output);
int i;
bool match = false;
if ((i = list_seq_find(config->output_configs, output_name_cmp, "*")) >= 0) {
match = true;
oc = config->output_configs->items[i];
merge_output_config(result, oc);
}
if ((i = list_seq_find(config->output_configs, output_name_cmp, name)) >= 0) {
match = true;
oc = config->output_configs->items[i];
merge_output_config(result, oc);
}
if ((i = list_seq_find(config->output_configs, output_name_cmp, id)) >= 0) {
match = true;
oc = config->output_configs->items[i];
merge_output_config(result, oc);
}
if (!match && !config->reloading) {
// No name, identifier, or wildcard config. Since we are not
// reloading with defaults, the output config will be empty, so
// just return NULL
free_output_config(result);
return NULL;
// We take a new config and merge on top, in order, the wildcard config,
// output config by name, and output config by identifier to form the final
// config. If there are multiple matches, they are merged in order.
struct output_config *oc = NULL;
const char *names[] = {"*", name, id, NULL};
for (const char **name = &names[0]; *name; name++) {
for (size_t idx = 0; idx < configs_len; idx++) {
oc = configs[idx];
if (strcmp(oc->name, *name) == 0) {
merge_output_config(result, oc);
}
}
}
return result;
}
struct output_config *find_output_config(struct sway_output *sway_output) {
return find_output_config_from_list(
(struct output_config **)config->output_configs->items,
config->output_configs->length, sway_output);
}
static bool config_has_manual_mode(struct output_config *oc) {
if (!oc) {
return false;
@ -663,6 +611,14 @@ static bool config_has_manual_mode(struct output_config *oc) {
return false;
}
/**
* An output config pre-matched to an output
*/
struct matched_output_config {
struct sway_output *output;
struct output_config *config;
};
struct search_context {
struct wlr_output_swapchain_manager *swapchain_mgr;
struct wlr_backend_output_state *states;
@ -677,7 +633,9 @@ static void dump_output_state(struct wlr_output *wlr_output, struct wlr_output_s
sway_log(SWAY_DEBUG, " enabled: %s", state->enabled ? "yes" : "no");
}
if (state->committed & WLR_OUTPUT_STATE_RENDER_FORMAT) {
sway_log(SWAY_DEBUG, " render_format: %d", state->render_format);
char *format_name = drmGetFormatName(state->render_format);
sway_log(SWAY_DEBUG, " render_format: %s", format_name);
free(format_name);
}
if (state->committed & WLR_OUTPUT_STATE_MODE) {
if (state->mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM) {
@ -693,6 +651,13 @@ static void dump_output_state(struct wlr_output *wlr_output, struct wlr_output_s
sway_log(SWAY_DEBUG, " adaptive_sync: %s",
state->adaptive_sync_enabled ? "enabled": "disabled");
}
if (state->committed & WLR_OUTPUT_STATE_SCALE) {
sway_log(SWAY_DEBUG, " scale: %f", state->scale);
}
if (state->committed & WLR_OUTPUT_STATE_SUBPIXEL) {
sway_log(SWAY_DEBUG, " subpixel: %s",
sway_wl_output_subpixel_to_string(state->subpixel));
}
}
static bool search_valid_config(struct search_context *ctx, size_t output_idx);
@ -796,6 +761,8 @@ static bool search_render_format(struct search_context *ctx, size_t output_idx)
DRM_FORMAT_XRGB2101010,
DRM_FORMAT_XBGR2101010,
DRM_FORMAT_XRGB8888,
DRM_FORMAT_ARGB8888,
DRM_FORMAT_RGB565,
DRM_FORMAT_INVALID,
};
if (render_format_is_bgr(wlr_output->render_format)) {
@ -806,9 +773,13 @@ static bool search_render_format(struct search_context *ctx, size_t output_idx)
const struct wlr_drm_format_set *primary_formats =
wlr_output_get_primary_formats(wlr_output, WLR_BUFFER_CAP_DMABUF);
bool need_10bit = cfg->config && cfg->config->render_bit_depth == RENDER_BIT_DEPTH_10;
enum render_bit_depth needed_bits = RENDER_BIT_DEPTH_8;
if (cfg->config && cfg->config->render_bit_depth != RENDER_BIT_DEPTH_DEFAULT) {
needed_bits = cfg->config->render_bit_depth;
}
for (size_t idx = 0; fmts[idx] != DRM_FORMAT_INVALID; idx++) {
if (!need_10bit && render_format_is_10bit(fmts[idx])) {
enum render_bit_depth format_bits = bit_depth_from_format(fmts[idx]);
if (needed_bits < format_bits) {
continue;
}
if (!wlr_drm_format_set_get(primary_formats, fmts[idx])) {
@ -881,12 +852,12 @@ static int compare_matched_output_config_priority(const void *a, const void *b)
return 0;
}
void sort_output_configs_by_priority(struct matched_output_config *configs,
size_t configs_len) {
static void sort_output_configs_by_priority(
struct matched_output_config *configs, size_t configs_len) {
qsort(configs, configs_len, sizeof(*configs), compare_matched_output_config_priority);
}
bool apply_output_configs(struct matched_output_config *configs,
static bool apply_resolved_output_configs(struct matched_output_config *configs,
size_t configs_len, bool test_only, bool degrade_to_off) {
struct wlr_backend_output_state *states = calloc(configs_len, sizeof(*states));
if (!states) {
@ -901,9 +872,8 @@ bool apply_output_configs(struct matched_output_config *configs,
backend_state->output = cfg->output->wlr_output;
wlr_output_state_init(&backend_state->base);
sway_log(SWAY_DEBUG, "Preparing config for %s",
cfg->output->wlr_output->name);
queue_output_config(cfg->config, cfg->output, &backend_state->base);
dump_output_state(cfg->output->wlr_output, &backend_state->base);
}
struct wlr_output_swapchain_manager swapchain_mgr;
@ -963,8 +933,14 @@ bool apply_output_configs(struct matched_output_config *configs,
sway_log(SWAY_DEBUG, "Finalizing config for %s",
cfg->output->wlr_output->name);
finalize_output_config(cfg->config, cfg->output);
arrange_layers(cfg->output);
}
arrange_root();
arrange_locks();
update_output_manager_config(&server);
transaction_commit_dirty();
out:
wlr_output_swapchain_manager_finish(&swapchain_mgr);
for (size_t idx = 0; idx < configs_len; idx++) {
@ -989,11 +965,12 @@ out:
return ok;
}
void apply_all_output_configs(void) {
bool apply_output_configs(struct output_config **ocs, size_t ocs_len,
bool test_only, bool degrade_to_off) {
size_t configs_len = wl_list_length(&root->all_outputs);
struct matched_output_config *configs = calloc(configs_len, sizeof(*configs));
if (!configs) {
return;
return false;
}
int config_idx = 0;
@ -1006,16 +983,22 @@ void apply_all_output_configs(void) {
struct matched_output_config *config = &configs[config_idx++];
config->output = sway_output;
config->config = find_output_config(sway_output);
config->config = find_output_config_from_list(ocs, ocs_len, sway_output);
}
sort_output_configs_by_priority(configs, configs_len);
apply_output_configs(configs, configs_len, false, true);
bool ok = apply_resolved_output_configs(configs, configs_len, test_only, degrade_to_off);
for (size_t idx = 0; idx < configs_len; idx++) {
struct matched_output_config *cfg = &configs[idx];
free_output_config(cfg->config);
}
free(configs);
return ok;
}
void apply_stored_output_configs(void) {
apply_output_configs((struct output_config **)config->output_configs->items,
config->output_configs->length, false, true);
}
void free_output_config(struct output_config *oc) {

View File

@ -54,7 +54,7 @@ struct wlr_layer_surface_v1 *toplevel_layer_surface_from_surface(
}
static void arrange_surface(struct sway_output *output, const struct wlr_box *full_area,
struct wlr_box *usable_area, struct wlr_scene_tree *tree) {
struct wlr_box *usable_area, struct wlr_scene_tree *tree, bool exclusive) {
struct wlr_scene_node *node;
wl_list_for_each(node, &tree->children, link) {
struct sway_layer_surface *surface = scene_descriptor_try_get(node,
@ -68,6 +68,10 @@ static void arrange_surface(struct sway_output *output, const struct wlr_box *fu
continue;
}
if ((surface->scene->layer_surface->current.exclusive_zone > 0) != exclusive) {
continue;
}
wlr_scene_layer_surface_v1_configure(surface->scene, full_area, usable_area);
}
}
@ -78,10 +82,15 @@ void arrange_layers(struct sway_output *output) {
&usable_area.width, &usable_area.height);
const struct wlr_box full_area = usable_area;
arrange_surface(output, &full_area, &usable_area, output->layers.shell_background);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_bottom);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_top);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_overlay);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_overlay, true);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_top, true);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_bottom, true);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_background, true);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_overlay, false);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_top, false);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_bottom, false);
arrange_surface(output, &full_area, &usable_area, output->layers.shell_background, false);
if (!wlr_box_equal(&usable_area, &output->usable_area)) {
sway_log(SWAY_DEBUG, "Usable area changed, rearranging output");

View File

@ -8,6 +8,7 @@
#include <wlr/render/swapchain.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_alpha_modifier_v1.h>
#include <wlr/types/wlr_gamma_control_v1.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_layout.h>
@ -187,8 +188,8 @@ static enum wlr_scale_filter_mode get_scale_filter(struct sway_output *output,
struct wlr_scene_buffer *buffer) {
// if we are scaling down, we should always choose linear
if (buffer->dst_width > 0 && buffer->dst_height > 0 && (
buffer->dst_width < buffer->buffer_width ||
buffer->dst_height < buffer->buffer_height)) {
buffer->dst_width < buffer->WLR_PRIVATE.buffer_width ||
buffer->dst_height < buffer->WLR_PRIVATE.buffer_height)) {
return WLR_SCALE_FILTER_BILINEAR;
}
@ -216,6 +217,15 @@ static void output_configure_scene(struct sway_output *output,
if (node->type == WLR_SCENE_NODE_BUFFER) {
struct wlr_scene_buffer *buffer = wlr_scene_buffer_from_node(node);
struct wlr_scene_surface *surface = wlr_scene_surface_try_from_buffer(buffer);
if (surface) {
const struct wlr_alpha_modifier_surface_v1_state *alpha_modifier_state =
wlr_alpha_modifier_v1_get_surface_state(surface->surface);
if (alpha_modifier_state != NULL) {
opacity *= (float)alpha_modifier_state->multiplier;
}
}
// hack: don't call the scene setter because that will damage all outputs
// We don't want to damage outputs that aren't our current output that
@ -356,7 +366,7 @@ static void handle_frame(struct wl_listener *listener, void *user_data) {
wlr_scene_output_for_each_buffer(output->scene_output, send_frame_done_iterator, &data);
}
static void update_output_manager_config(struct sway_server *server) {
void update_output_manager_config(struct sway_server *server) {
struct wlr_output_configuration_v1 *config =
wlr_output_configuration_v1_create();
@ -386,24 +396,19 @@ static int timer_modeset_handle(void *data) {
wl_event_source_remove(server->delayed_modeset);
server->delayed_modeset = NULL;
apply_all_output_configs();
transaction_commit_dirty();
update_output_manager_config(server);
apply_stored_output_configs();
return 0;
}
static void request_modeset(struct sway_server *server) {
if (server->delayed_modeset == NULL) {
server->delayed_modeset = wl_event_loop_add_timer(server->wl_event_loop,
timer_modeset_handle, server);
wl_event_source_timer_update(server->delayed_modeset, 10);
void request_modeset(void) {
if (server.delayed_modeset == NULL) {
server.delayed_modeset = wl_event_loop_add_timer(server.wl_event_loop,
timer_modeset_handle, &server);
wl_event_source_timer_update(server.delayed_modeset, 10);
}
}
static void begin_destroy(struct sway_output *output) {
struct sway_server *server = output->server;
if (output->enabled) {
output_disable(output);
}
@ -414,7 +419,6 @@ static void begin_destroy(struct sway_output *output) {
wl_list_remove(&output->layout_destroy.link);
wl_list_remove(&output->destroy.link);
wl_list_remove(&output->commit.link);
wl_list_remove(&output->present.link);
wl_list_remove(&output->frame.link);
wl_list_remove(&output->request_state.link);
@ -424,7 +428,7 @@ static void begin_destroy(struct sway_output *output) {
output->wlr_output->data = NULL;
output->wlr_output = NULL;
request_modeset(server);
request_modeset();
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@ -437,26 +441,6 @@ static void handle_layout_destroy(struct wl_listener *listener, void *data) {
begin_destroy(output);
}
static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, commit);
struct wlr_output_event_commit *event = data;
if (!output->enabled) {
return;
}
if (event->state->committed & (
WLR_OUTPUT_STATE_MODE |
WLR_OUTPUT_STATE_TRANSFORM |
WLR_OUTPUT_STATE_SCALE)) {
arrange_layers(output);
arrange_output(output);
transaction_commit_dirty();
update_output_manager_config(output->server);
}
}
static void handle_present(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, present);
struct wlr_output_event_present *output_event = data;
@ -473,7 +457,48 @@ static void handle_request_state(struct wl_listener *listener, void *data) {
struct sway_output *output =
wl_container_of(listener, output, request_state);
const struct wlr_output_event_request_state *event = data;
wlr_output_commit_state(output->wlr_output, event->state);
const struct wlr_output_state *state = event->state;
// Store the requested changes so that the active configuration is
// consistent with the current state, and to avoid duplicate logic to apply
// the changes.
struct output_config *oc = new_output_config(output->wlr_output->name);
if (!oc) {
sway_log(SWAY_ERROR, "Allocation failed");
return;
}
int committed = state->committed;
if (committed & WLR_OUTPUT_STATE_MODE) {
if (state->mode != NULL) {
oc->width = state->mode->width;
oc->height = state->mode->height;
oc->refresh_rate = state->mode->refresh / 1000.f;
} else {
oc->width = state->custom_mode.width;
oc->height = state->custom_mode.height;
oc->refresh_rate = state->custom_mode.refresh / 1000.f;
}
committed &= ~WLR_OUTPUT_STATE_MODE;
}
if (committed & WLR_OUTPUT_STATE_SCALE) {
oc->scale = state->scale;
committed &= ~WLR_OUTPUT_STATE_SCALE;
}
if (committed & WLR_OUTPUT_STATE_TRANSFORM) {
oc->transform = state->transform;
committed &= ~WLR_OUTPUT_STATE_TRANSFORM;
}
// We do not expect or support any other changes here
assert(committed == 0);
store_output_config(oc);
apply_stored_output_configs();
if (server.delayed_modeset != NULL) {
wl_event_source_remove(server.delayed_modeset);
server.delayed_modeset = NULL;
}
}
static unsigned int last_headless_num = 0;
@ -537,8 +562,6 @@ void handle_new_output(struct wl_listener *listener, void *data) {
output->layout_destroy.notify = handle_layout_destroy;
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
output->destroy.notify = handle_destroy;
wl_signal_add(&wlr_output->events.commit, &output->commit);
output->commit.notify = handle_commit;
wl_signal_add(&wlr_output->events.present, &output->present);
output->present.notify = handle_present;
wl_signal_add(&wlr_output->events.frame, &output->frame);
@ -553,20 +576,16 @@ void handle_new_output(struct wl_listener *listener, void *data) {
sway_session_lock_add_output(server->session_lock.lock, output);
}
request_modeset(server);
}
void handle_output_layout_change(struct wl_listener *listener,
void *data) {
struct sway_server *server =
wl_container_of(listener, server, output_layout_change);
update_output_manager_config(server);
request_modeset();
}
static struct output_config *output_config_for_config_head(
struct wlr_output_configuration_head_v1 *config_head,
struct sway_output *output) {
struct output_config *oc = new_output_config(output->wlr_output->name);
struct wlr_output_configuration_head_v1 *config_head) {
struct output_config *oc = new_output_config(config_head->state.output->name);
if (!oc) {
return NULL;
}
oc->enabled = config_head->state.enabled;
if (!oc->enabled) {
return oc;
@ -592,71 +611,59 @@ static struct output_config *output_config_for_config_head(
}
static void output_manager_apply(struct sway_server *server,
struct wlr_output_configuration_v1 *config, bool test_only) {
size_t configs_len = wl_list_length(&root->all_outputs);
struct matched_output_config *configs = calloc(configs_len, sizeof(*configs));
struct wlr_output_configuration_v1 *cfg, bool test_only) {
bool ok = false;
size_t configs_len = config->output_configs->length + wl_list_length(&cfg->heads);
struct output_config **configs = calloc(configs_len, sizeof(*configs));
if (!configs) {
return;
sway_log(SWAY_ERROR, "Allocation failed");
goto error;
}
size_t start_new_configs = config->output_configs->length;
for (size_t idx = 0; idx < start_new_configs; idx++) {
configs[idx] = config->output_configs->items[idx];
}
int config_idx = 0;
struct sway_output *sway_output;
wl_list_for_each(sway_output, &root->all_outputs, link) {
if (sway_output == root->fallback_output) {
configs_len--;
continue;
}
struct matched_output_config *cfg = &configs[config_idx++];
cfg->output = sway_output;
struct wlr_output_configuration_head_v1 *config_head;
wl_list_for_each(config_head, &config->heads, link) {
if (config_head->state.output == sway_output->wlr_output) {
cfg->config = output_config_for_config_head(config_head, sway_output);
break;
}
}
if (!cfg->config) {
cfg->config = find_output_config(sway_output);
size_t config_idx = start_new_configs;
struct wlr_output_configuration_head_v1 *config_head;
wl_list_for_each(config_head, &cfg->heads, link) {
// Generate the configuration and store it as a temporary
// config. We keep a record of it so we can remove it later.
struct output_config *oc = output_config_for_config_head(config_head);
if (!oc) {
sway_log(SWAY_ERROR, "Allocation failed");
goto error_config;
}
configs[config_idx++] = oc;
}
sort_output_configs_by_priority(configs, configs_len);
bool ok = apply_output_configs(configs, configs_len, test_only, false);
for (size_t idx = 0; idx < configs_len; idx++) {
struct matched_output_config *cfg = &configs[idx];
// Try to commit without degrade to off enabled. Note that this will fail
// if any output configured for enablement fails to be enabled, even if it
// was not part of the config heads we were asked to configure.
ok = apply_output_configs(configs, configs_len, test_only, false);
// Only store new configs for successful non-test commits. Old configs,
// test-only and failed commits just get freed.
bool store_config = false;
error_config:
for (size_t idx = start_new_configs; idx < configs_len; idx++) {
struct output_config *cfg = configs[idx];
if (!test_only && ok) {
struct wlr_output_configuration_head_v1 *config_head;
wl_list_for_each(config_head, &config->heads, link) {
if (config_head->state.output == cfg->output->wlr_output) {
store_config = true;
break;
}
}
}
if (store_config) {
store_output_config(cfg->config);
store_output_config(cfg);
} else {
free_output_config(cfg->config);
free_output_config(cfg);
}
}
free(configs);
error:
if (ok) {
wlr_output_configuration_v1_send_succeeded(config);
wlr_output_configuration_v1_send_succeeded(cfg);
if (server->delayed_modeset != NULL) {
wl_event_source_remove(server->delayed_modeset);
server->delayed_modeset = NULL;
}
} else {
wlr_output_configuration_v1_send_failed(config);
}
wlr_output_configuration_v1_destroy(config);
if (!test_only) {
update_output_manager_config(server);
wlr_output_configuration_v1_send_failed(cfg);
}
wlr_output_configuration_v1_destroy(cfg);
}
void handle_output_manager_apply(struct wl_listener *listener, void *data) {
@ -681,6 +688,11 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener,
struct sway_output *output = event->output->data;
struct output_config *oc = new_output_config(output->wlr_output->name);
if (!oc) {
sway_log(SWAY_ERROR, "Allocation failed");
return;
}
switch (event->mode) {
case ZWLR_OUTPUT_POWER_V1_MODE_OFF:
oc->power = 0;
@ -690,5 +702,5 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener,
break;
}
store_output_config(oc);
request_modeset(output->server);
request_modeset();
}

View File

@ -559,7 +559,7 @@ static void arrange_output(struct sway_output *output, int width, int height) {
for (int i = 0; i < output->current.workspaces->length; i++) {
struct sway_workspace *child = output->current.workspaces->items[i];
bool activated = output->current.active_workspace == child;
bool activated = output->current.active_workspace == child && output->wlr_output->enabled;
wlr_scene_node_reparent(&child->layers.tiling->node, output->layers.tiling);
wlr_scene_node_reparent(&child->layers.fullscreen->node, output->layers.fullscreen);
@ -612,9 +612,11 @@ void arrange_popups(struct wlr_scene_tree *popups) {
struct sway_popup_desc *popup = scene_descriptor_try_get(node,
SWAY_SCENE_DESC_POPUP);
int lx, ly;
wlr_scene_node_coords(popup->relative, &lx, &ly);
wlr_scene_node_set_position(node, lx, ly);
if (popup) {
int lx, ly;
wlr_scene_node_coords(popup->relative, &lx, &ly);
wlr_scene_node_set_position(node, lx, ly);
}
}
}

View File

@ -4,7 +4,6 @@
#include <math.h>
#include <assert.h>
#include <wlr/config.h>
#include <wlr/backend/libinput.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_keyboard_group.h>
#include <wlr/types/wlr_virtual_keyboard_v1.h>

View File

@ -4,6 +4,7 @@
#include <wlr/config.h>
#include <wlr/backend/multi.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_keyboard_group.h>
#include <xkbcommon/xkbcommon-names.h>
@ -267,6 +268,7 @@ static bool keyboard_execute_compositor_binding(struct sway_keyboard *keyboard,
const xkb_keysym_t *pressed_keysyms, uint32_t modifiers, size_t keysyms_len) {
for (size_t i = 0; i < keysyms_len; ++i) {
xkb_keysym_t keysym = pressed_keysyms[i];
if (keysym >= XKB_KEY_XF86Switch_VT_1 &&
keysym <= XKB_KEY_XF86Switch_VT_12) {
#if WLR_HAS_SESSION
@ -282,6 +284,36 @@ static bool keyboard_execute_compositor_binding(struct sway_keyboard *keyboard,
return false;
}
static bool keyboard_execute_pointer_keysyms(struct sway_keyboard *keyboard,
uint32_t time, const xkb_keysym_t *pressed_keysyms, size_t keysyms_len,
enum wl_keyboard_key_state state) {
struct sway_cursor *cursor = keyboard->seat_device->sway_seat->cursor;
for (size_t i = 0; i < keysyms_len; ++i) {
xkb_keysym_t keysym = pressed_keysyms[i];
uint32_t button = wlr_keyboard_keysym_to_pointer_button(keysym);
if (button != 0) {
dispatch_cursor_button(cursor, &keyboard->wlr->base, time, button,
(enum wl_pointer_button_state)state);
wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat);
return true;
}
int dx, dy;
wlr_keyboard_keysym_to_pointer_motion(keysym, &dx, &dy);
if (state == WL_KEYBOARD_KEY_STATE_PRESSED && (dx != 0 || dy != 0)) {
dx *= 10;
dy *= 10;
pointer_motion(cursor, time, &keyboard->wlr->base, dx, dy, dx, dy);
wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat);
return true;
}
}
return false;
}
/**
* Get keysyms and modifiers from the keyboard as xkb sees them.
*
@ -507,6 +539,11 @@ static void handle_key_event(struct sway_keyboard *keyboard,
keyboard, keyinfo.raw_keysyms, keyinfo.raw_modifiers,
keyinfo.raw_keysyms_len);
}
if (!handled) {
handled = keyboard_execute_pointer_keysyms(keyboard, event->time_msec,
keyinfo.translated_keysyms, keyinfo.translated_keysyms_len,
event->state);
}
if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
// If the pressed event was sent to a client and we have a focused
@ -1028,13 +1065,6 @@ static void sway_keyboard_set_layout(struct sway_keyboard *keyboard,
}
}
// If the seat has no active keyboard, set this one
struct wlr_seat *seat = keyboard->seat_device->sway_seat->wlr_seat;
struct wlr_keyboard *current_keyboard = seat->keyboard_state.keyboard;
if (current_keyboard == NULL) {
wlr_seat_set_keyboard(seat, keyboard->wlr);
}
if (keymap_changed) {
ipc_event_input("xkb_keymap",
keyboard->seat_device->input_device);
@ -1078,6 +1108,13 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
sway_keyboard_set_layout(keyboard, input_config);
}
// If the seat has no active keyboard, set this one
struct wlr_seat *seat = keyboard->seat_device->sway_seat->wlr_seat;
struct wlr_keyboard *current_keyboard = seat->keyboard_state.keyboard;
if (current_keyboard == NULL) {
wlr_seat_set_keyboard(seat, keyboard->wlr);
}
wl_list_remove(&keyboard->keyboard_key.link);
wl_signal_add(&keyboard->wlr->events.key, &keyboard->keyboard_key);
keyboard->keyboard_key.notify = handle_keyboard_key;

View File

@ -1094,6 +1094,7 @@ static void seat_send_unfocus(struct sway_node *node, struct sway_seat *seat) {
static int handle_urgent_timeout(void *data) {
struct sway_view *view = data;
view_set_urgent(view, false);
container_update_itself_and_parents(view->container);
return 0;
}

View File

@ -355,6 +355,13 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
bool mod_pressed = modifiers & config->floating_mod;
uint32_t mod_move_btn = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT;
uint32_t mod_resize_btn = config->floating_mod_inverse ? BTN_LEFT : BTN_RIGHT;
bool mod_move_btn_pressed = mod_pressed && button == mod_move_btn;
bool mod_resize_btn_pressed = mod_pressed && button == mod_resize_btn;
bool titlebar_left_btn_pressed = on_titlebar && button == BTN_LEFT;
// Handle mouse bindings
if (trigger_pointer_button_binding(seat, device, button, state, modifiers,
on_titlebar, on_border, on_contents, on_workspace)) {
@ -403,33 +410,28 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
}
// Handle tiling resize via mod
bool mod_pressed = modifiers & config->floating_mod;
if (cont && !is_floating_or_child && mod_pressed &&
if (cont && !is_floating_or_child && mod_pressed && mod_resize_btn_pressed &&
state == WL_POINTER_BUTTON_STATE_PRESSED) {
uint32_t btn_resize = config->floating_mod_inverse ?
BTN_LEFT : BTN_RIGHT;
if (button == btn_resize) {
edge = 0;
edge |= cursor->cursor->x > cont->pending.x + cont->pending.width / 2 ?
WLR_EDGE_RIGHT : WLR_EDGE_LEFT;
edge |= cursor->cursor->y > cont->pending.y + cont->pending.height / 2 ?
WLR_EDGE_BOTTOM : WLR_EDGE_TOP;
edge = 0;
edge |= cursor->cursor->x > cont->pending.x + cont->pending.width / 2 ?
WLR_EDGE_RIGHT : WLR_EDGE_LEFT;
edge |= cursor->cursor->y > cont->pending.y + cont->pending.height / 2 ?
WLR_EDGE_BOTTOM : WLR_EDGE_TOP;
const char *image = NULL;
if (edge == (WLR_EDGE_LEFT | WLR_EDGE_TOP)) {
image = "nw-resize";
} else if (edge == (WLR_EDGE_TOP | WLR_EDGE_RIGHT)) {
image = "ne-resize";
} else if (edge == (WLR_EDGE_RIGHT | WLR_EDGE_BOTTOM)) {
image = "se-resize";
} else if (edge == (WLR_EDGE_BOTTOM | WLR_EDGE_LEFT)) {
image = "sw-resize";
}
cursor_set_image(seat->cursor, image, NULL);
seat_set_focus_container(seat, cont);
seatop_begin_resize_tiling(seat, cont, edge);
return;
const char *image = NULL;
if (edge == (WLR_EDGE_LEFT | WLR_EDGE_TOP)) {
image = "nw-resize";
} else if (edge == (WLR_EDGE_TOP | WLR_EDGE_RIGHT)) {
image = "ne-resize";
} else if (edge == (WLR_EDGE_RIGHT | WLR_EDGE_BOTTOM)) {
image = "se-resize";
} else if (edge == (WLR_EDGE_BOTTOM | WLR_EDGE_LEFT)) {
image = "sw-resize";
}
cursor_set_image(seat->cursor, image, NULL);
seat_set_focus_container(seat, cont);
seatop_begin_resize_tiling(seat, cont, edge);
return;
}
// Handle changing focus when clicking on a container
@ -454,12 +456,10 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
// Handle beginning floating move
if (cont && is_floating_or_child && !is_fullscreen_or_child &&
state == WL_POINTER_BUTTON_STATE_PRESSED) {
uint32_t btn_move = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT;
if (button == btn_move && (mod_pressed || on_titlebar)) {
seatop_begin_move_floating(seat, container_toplevel_ancestor(cont));
return;
}
state == WL_POINTER_BUTTON_STATE_PRESSED &&
(mod_move_btn_pressed || titlebar_left_btn_pressed)) {
seatop_begin_move_floating(seat, container_toplevel_ancestor(cont));
return;
}
// Handle beginning floating resize
@ -473,9 +473,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
}
// Via mod+click
uint32_t btn_resize = config->floating_mod_inverse ?
BTN_LEFT : BTN_RIGHT;
if (mod_pressed && button == btn_resize) {
if (mod_resize_btn_pressed) {
struct sway_container *floater = container_toplevel_ancestor(cont);
edge = 0;
edge |= cursor->cursor->x > floater->pending.x + floater->pending.width / 2 ?
@ -489,7 +487,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
}
// Handle moving a tiling container
if (config->tiling_drag && (mod_pressed || on_titlebar) &&
if (config->tiling_drag && (mod_move_btn_pressed || titlebar_left_btn_pressed) &&
state == WL_POINTER_BUTTON_STATE_PRESSED && !is_floating_or_child &&
cont && cont->pending.fullscreen_mode == FULLSCREEN_NONE) {
// If moving a container by its title bar, use a threshold for the drag
@ -498,7 +496,6 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
} else {
seatop_begin_move_tiling(seat, cont);
}
return;
}

View File

@ -11,8 +11,6 @@
#include "sway/layers.h"
#include "sway/server.h"
static void input_popup_update(struct sway_input_popup *popup);
static struct sway_text_input *relay_get_focusable_text_input(
struct sway_input_method_relay *relay) {
struct sway_text_input *text_input = NULL;
@ -128,6 +126,89 @@ static void handle_im_destroy(struct wl_listener *listener, void *data) {
}
}
static void constrain_popup(struct sway_input_popup *popup) {
struct sway_text_input *text_input =
relay_get_focused_text_input(popup->relay);
if (!popup->desc.relative) {
return;
}
struct wlr_box parent = {0};
wlr_scene_node_coords(&popup->desc.relative->parent->node, &parent.x, &parent.y);
struct wlr_box geo = {0};
struct wlr_output *output;
if (popup->desc.view) {
struct sway_view *view = popup->desc.view;
output = wlr_output_layout_output_at(root->output_layout,
view->container->pending.content_x + view->geometry.x,
view->container->pending.content_y + view->geometry.y);
parent.width = view->geometry.width;
parent.height = view->geometry.height;
geo = view->geometry;
} else {
output = popup->fixed_output;
}
struct wlr_box output_box;
wlr_output_layout_get_box(root->output_layout, output, &output_box);
bool cursor_rect = text_input->input->current.features &
WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE;
struct wlr_box cursor_area;
if (cursor_rect) {
cursor_area = text_input->input->current.cursor_rectangle;
} else {
cursor_area = (struct wlr_box) {
.width = parent.width,
.height = parent.height,
};
}
int popup_width = popup->popup_surface->surface->current.width;
int popup_height = popup->popup_surface->surface->current.height;
int x1 = parent.x + cursor_area.x;
int x2 = parent.x + cursor_area.x + cursor_area.width;
int y1 = parent.y + cursor_area.y;
int y2 = parent.y + cursor_area.y + cursor_area.height;
int x = x1;
int y = y2;
int available_right = output_box.x + output_box.width - x1;
int available_left = x2 - output_box.x;
if (available_right < popup_width && available_left > available_right) {
x = x2 - popup_width;
}
int available_down = output_box.y + output_box.height - y2;
int available_up = y1 - output_box.y;
if (available_down < popup_height && available_up > available_down) {
y = y1 - popup_height;
}
wlr_scene_node_set_position(popup->desc.relative, x - parent.x - geo.x, y - parent.y - geo.y);
if (cursor_rect) {
struct wlr_box box = {
.x = x1 - x,
.y = y1 - y,
.width = cursor_area.width,
.height = cursor_area.height,
};
wlr_input_popup_surface_v2_send_text_input_rectangle(
popup->popup_surface, &box);
}
if (popup->scene_tree) {
wlr_scene_node_set_position(&popup->scene_tree->node, x - geo.x, y - geo.y);
}
}
static void input_popup_set_focus(struct sway_input_popup *popup,
struct wlr_surface *surface);
static void relay_send_im_state(struct sway_input_method_relay *relay,
struct wlr_text_input_v3 *input) {
struct wlr_input_method_v2 *input_method = relay->input_method;
@ -148,10 +229,16 @@ static void relay_send_im_state(struct sway_input_method_relay *relay,
input->current.content_type.hint,
input->current.content_type.purpose);
}
struct sway_text_input *text_input = relay_get_focused_text_input(relay);
struct sway_input_popup *popup;
wl_list_for_each(popup, &relay->input_popups, link) {
// send_text_input_rectangle is called in this function
input_popup_update(popup);
if (text_input != NULL) {
input_popup_set_focus(popup, text_input->input->focused_surface);
} else {
input_popup_set_focus(popup, NULL);
}
}
wlr_input_method_v2_send_done(input_method);
// TODO: pass intent, display popup size
@ -275,72 +362,52 @@ static void relay_handle_text_input(struct wl_listener *listener,
sway_text_input_create(relay, wlr_text_input);
}
static void input_popup_update(struct sway_input_popup *popup) {
struct sway_text_input *text_input =
relay_get_focused_text_input(popup->relay);
static void input_popup_set_focus(struct sway_input_popup *popup,
struct wlr_surface *surface) {
wl_list_remove(&popup->focused_surface_unmap.link);
if (text_input == NULL || text_input->input->focused_surface == NULL) {
if (!popup->scene_tree) {
wl_list_init(&popup->focused_surface_unmap.link);
return;
}
if (popup->scene_tree != NULL) {
wlr_scene_node_destroy(&popup->scene_tree->node);
popup->scene_tree = NULL;
}
if (popup->desc.relative != NULL) {
if (popup->desc.relative) {
scene_descriptor_destroy(&popup->scene_tree->node, SWAY_SCENE_DESC_POPUP);
wlr_scene_node_destroy(popup->desc.relative);
popup->desc.relative = NULL;
}
popup->desc.view = NULL;
if (!popup->popup_surface->surface->mapped) {
if (surface == NULL) {
wl_list_init(&popup->focused_surface_unmap.link);
wlr_scene_node_set_enabled(&popup->scene_tree->node, false);
return;
}
bool cursor_rect = text_input->input->current.features
& WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE;
struct wlr_surface *focused_surface = text_input->input->focused_surface;
struct wlr_box cursor_area = text_input->input->current.cursor_rectangle;
struct wlr_box output_box;
struct wlr_box parent = {0};
struct wlr_layer_surface_v1 *layer_surface =
wlr_layer_surface_v1_try_from_wlr_surface(focused_surface);
wlr_layer_surface_v1_try_from_wlr_surface(surface);
struct wlr_scene_tree *relative_parent;
if (layer_surface) {
wl_signal_add(&layer_surface->surface->events.unmap,
&popup->focused_surface_unmap);
struct wlr_box geo = {0};
popup->scene_tree = wlr_scene_subsurface_tree_create(root->layers.popup, popup->popup_surface->surface);
if (layer_surface != NULL) {
struct sway_layer_surface *layer =
layer_surface->data;
struct sway_layer_surface *layer = layer_surface->data;
if (layer == NULL) {
return;
}
relative_parent = layer->scene->tree;
struct wlr_output *output = layer->layer_surface->output;
wlr_output_layout_get_box(root->output_layout, output, &output_box);
int lx, ly;
wlr_scene_node_coords(&layer->tree->node, &lx, &ly);
parent.x = lx;
parent.y = ly;
popup->desc.view = NULL;
} else {
struct sway_view *view = view_from_wlr_surface(focused_surface);
relative_parent = view->scene_tree;
geo = view->geometry;
int lx, ly;
wlr_scene_node_coords(&view->scene_tree->node, &lx, &ly);
struct wlr_output *output = wlr_output_layout_output_at(root->output_layout,
view->container->pending.content_x + view->geometry.x,
view->container->pending.content_y + view->geometry.y);
wlr_output_layout_get_box(root->output_layout, output, &output_box);
parent.x = lx;
parent.y = ly;
parent.width = view->geometry.width;
parent.height = view->geometry.height;
// we don't need to add an event here to NULL out this field because
// this field will only be initialized if the popup is part of a layer
// surface. Layer surfaces get destroyed as part of the output being
// destroyed, thus also trickling down to popups.
popup->fixed_output = layer->layer_surface->output;
} else {
struct sway_view *view = view_from_wlr_surface(surface);
wl_signal_add(&view->events.unmap, &popup->focused_surface_unmap);
relative_parent = view->scene_tree;
popup->desc.view = view;
}
@ -354,93 +421,59 @@ static void input_popup_update(struct sway_input_popup *popup) {
return;
}
if (!cursor_rect) {
cursor_area.x = 0;
cursor_area.y = 0;
cursor_area.width = parent.width;
cursor_area.height = parent.height;
}
int popup_width = popup->popup_surface->surface->current.width;
int popup_height = popup->popup_surface->surface->current.height;
int x1 = parent.x + cursor_area.x;
int x2 = parent.x + cursor_area.x + cursor_area.width;
int y1 = parent.y + cursor_area.y;
int y2 = parent.y + cursor_area.y + cursor_area.height;
int x = x1;
int y = y2;
int available_right = output_box.x + output_box.width - x1;
int available_left = x2 - output_box.x;
if (available_right < popup_width && available_left > available_right) {
x = x2 - popup_width;
}
int available_down = output_box.y + output_box.height - y2;
int available_up = y1 - output_box.y;
if (available_down < popup_height && available_up > available_down) {
y = y1 - popup_height;
}
wlr_scene_node_set_position(&relative->node, x - parent.x - geo.x, y - parent.y - geo.y);
if (cursor_rect) {
struct wlr_box box = {
.x = x1 - x,
.y = y1 - y,
.width = cursor_area.width,
.height = cursor_area.height,
};
wlr_input_popup_surface_v2_send_text_input_rectangle(
popup->popup_surface, &box);
}
wlr_scene_node_set_position(&popup->scene_tree->node, x - geo.x, y - geo.y);
}
static void input_popup_set_focus(struct sway_input_popup *popup,
struct wlr_surface *surface) {
wl_list_remove(&popup->focused_surface_unmap.link);
if (surface == NULL) {
wl_list_init(&popup->focused_surface_unmap.link);
input_popup_update(popup);
return;
}
struct wlr_layer_surface_v1 *layer_surface =
wlr_layer_surface_v1_try_from_wlr_surface(surface);
if (layer_surface != NULL) {
wl_signal_add(
&layer_surface->surface->events.unmap, &popup->focused_surface_unmap);
input_popup_update(popup);
return;
}
struct sway_view *view = view_from_wlr_surface(surface);
wl_signal_add(&view->events.unmap, &popup->focused_surface_unmap);
constrain_popup(popup);
wlr_scene_node_set_enabled(&popup->scene_tree->node, true);
}
static void handle_im_popup_destroy(struct wl_listener *listener, void *data) {
struct sway_input_popup *popup =
wl_container_of(listener, popup, popup_destroy);
wlr_scene_node_destroy(&popup->scene_tree->node);
wl_list_remove(&popup->focused_surface_unmap.link);
wl_list_remove(&popup->popup_surface_commit.link);
wl_list_remove(&popup->popup_surface_map.link);
wl_list_remove(&popup->popup_surface_unmap.link);
wl_list_remove(&popup->popup_destroy.link);
wl_list_remove(&popup->link);
free(popup);
}
static void handle_im_popup_surface_commit(struct wl_listener *listener,
void *data) {
static void handle_im_popup_surface_map(struct wl_listener *listener, void *data) {
struct sway_input_popup *popup =
wl_container_of(listener, popup, popup_surface_map);
struct sway_text_input *text_input = relay_get_focused_text_input(popup->relay);
if (text_input != NULL) {
input_popup_set_focus(popup, text_input->input->focused_surface);
} else {
input_popup_set_focus(popup, NULL);
}
}
static void handle_im_popup_surface_unmap(struct wl_listener *listener, void *data) {
struct sway_input_popup *popup =
wl_container_of(listener, popup, popup_surface_unmap);
scene_descriptor_destroy(&popup->scene_tree->node, SWAY_SCENE_DESC_POPUP);
// relative should already be freed as it should be a child of the just unmapped scene
popup->desc.relative = NULL;
input_popup_set_focus(popup, NULL);
}
static void handle_im_popup_surface_commit(struct wl_listener *listener, void *data) {
struct sway_input_popup *popup =
wl_container_of(listener, popup, popup_surface_commit);
input_popup_update(popup);
constrain_popup(popup);
}
static void handle_im_focused_surface_unmap(
struct wl_listener *listener, void *data) {
struct sway_input_popup *popup =
wl_container_of(listener, popup, focused_surface_unmap);
input_popup_update(popup);
input_popup_set_focus(popup, NULL);
}
static void handle_im_new_popup_surface(struct wl_listener *listener,
@ -448,16 +481,38 @@ static void handle_im_new_popup_surface(struct wl_listener *listener,
struct sway_input_method_relay *relay = wl_container_of(listener, relay,
input_method_new_popup_surface);
struct sway_input_popup *popup = calloc(1, sizeof(*popup));
if (!popup) {
sway_log(SWAY_ERROR, "Failed to allocate an input method popup");
return;
}
popup->relay = relay;
popup->popup_surface = data;
popup->popup_surface->data = popup;
wl_signal_add(
&popup->popup_surface->events.destroy, &popup->popup_destroy);
popup->scene_tree = wlr_scene_tree_create(root->layers.popup);
if (!popup->scene_tree) {
sway_log(SWAY_ERROR, "Failed to allocate scene tree");
free(popup);
return;
}
if (!wlr_scene_subsurface_tree_create(popup->scene_tree,
popup->popup_surface->surface)) {
sway_log(SWAY_ERROR, "Failed to allocate subsurface tree");
wlr_scene_node_destroy(&popup->scene_tree->node);
free(popup);
return;
}
wl_signal_add(&popup->popup_surface->events.destroy, &popup->popup_destroy);
popup->popup_destroy.notify = handle_im_popup_destroy;
wl_signal_add(&popup->popup_surface->surface->events.commit,
&popup->popup_surface_commit);
wl_signal_add(&popup->popup_surface->surface->events.commit, &popup->popup_surface_commit);
popup->popup_surface_commit.notify = handle_im_popup_surface_commit;
wl_signal_add(&popup->popup_surface->surface->events.map, &popup->popup_surface_map);
popup->popup_surface_map.notify = handle_im_popup_surface_map;
wl_signal_add(&popup->popup_surface->surface->events.unmap, &popup->popup_surface_unmap);
popup->popup_surface_unmap.notify = handle_im_popup_surface_unmap;
wl_list_init(&popup->focused_surface_unmap.link);
popup->focused_surface_unmap.notify = handle_im_focused_surface_unmap;

View File

@ -8,6 +8,7 @@
#include "sway/layers.h"
#include "sway/output.h"
#include "sway/server.h"
#include "sway/lock.h"
struct sway_session_lock_output {
struct wlr_scene_tree *tree;
@ -19,7 +20,6 @@ struct sway_session_lock_output {
struct wl_list link; // sway_session_lock::outputs
struct wl_listener destroy;
struct wl_listener commit;
struct wlr_session_lock_surface_v1 *surface;
@ -89,6 +89,17 @@ static void lock_output_reconfigure(struct sway_session_lock_output *output) {
}
}
void arrange_locks(void) {
if (server.session_lock.lock == NULL) {
return;
}
struct sway_session_lock_output *lock_output;
wl_list_for_each(lock_output, &server.session_lock.lock->outputs, link) {
lock_output_reconfigure(lock_output);
}
}
static void handle_new_surface(struct wl_listener *listener, void *data) {
struct sway_session_lock *lock = wl_container_of(listener, lock, new_surface);
struct wlr_session_lock_surface_v1 *lock_surface = data;
@ -125,7 +136,6 @@ static void sway_session_lock_output_destroy(struct sway_session_lock_output *ou
wl_list_remove(&output->surface_map.link);
}
wl_list_remove(&output->commit.link);
wl_list_remove(&output->destroy.link);
wl_list_remove(&output->link);
@ -138,18 +148,6 @@ static void lock_node_handle_destroy(struct wl_listener *listener, void *data) {
sway_session_lock_output_destroy(output);
}
static void lock_output_handle_commit(struct wl_listener *listener, void *data) {
struct wlr_output_event_commit *event = data;
struct sway_session_lock_output *output =
wl_container_of(listener, output, commit);
if (event->state->committed & (
WLR_OUTPUT_STATE_MODE |
WLR_OUTPUT_STATE_SCALE |
WLR_OUTPUT_STATE_TRANSFORM)) {
lock_output_reconfigure(output);
}
}
static struct sway_session_lock_output *session_lock_output_create(
struct sway_session_lock *lock, struct sway_output *output) {
struct sway_session_lock_output *lock_output = calloc(1, sizeof(*lock_output));
@ -186,9 +184,6 @@ static struct sway_session_lock_output *session_lock_output_create(
lock_output->destroy.notify = lock_node_handle_destroy;
wl_signal_add(&tree->node.events.destroy, &lock_output->destroy);
lock_output->commit.notify = lock_output_handle_commit;
wl_signal_add(&output->wlr_output->events.commit, &lock_output->commit);
lock_output_reconfigure(lock_output);
wl_list_insert(&lock->outputs, &lock_output->link);

View File

@ -39,6 +39,9 @@ void *scene_descriptor_try_get(struct wlr_scene_node *node,
void scene_descriptor_destroy(struct wlr_scene_node *node,
enum sway_scene_descriptor_type type) {
struct scene_descriptor *desc = scene_node_get_descriptor(node, type);
if (!desc) {
return;
}
descriptor_destroy(desc);
}

View File

@ -9,6 +9,7 @@
#include <wlr/config.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_alpha_modifier_v1.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_content_type_v1.h>
#include <wlr/types/wlr_cursor_shape_v1.h>
@ -69,6 +70,7 @@
#define SWAY_XDG_SHELL_VERSION 5
#define SWAY_LAYER_SHELL_VERSION 4
#define SWAY_FOREIGN_TOPLEVEL_LIST_VERSION 1
#define SWAY_PRESENTATION_VERSION 2
bool allow_unsupported_gpu = false;
@ -204,8 +206,8 @@ static void handle_renderer_lost(struct wl_listener *listener, void *data) {
wlr_compositor_set_renderer(server->compositor, renderer);
for (int i = 0; i < root->outputs->length; ++i) {
struct sway_output *output = root->outputs->items[i];
struct sway_output *output;
wl_list_for_each(output, &root->all_outputs, link) {
wlr_output_init_render(output->wlr_output,
server->allocator, server->renderer);
}
@ -250,7 +252,8 @@ bool server_init(struct sway_server *server) {
}
}
if (wlr_renderer_get_drm_fd(server->renderer) >= 0 &&
server->renderer->features.timeline) {
server->renderer->features.timeline &&
server->backend->features.timeline) {
wlr_linux_drm_syncobj_manager_v1_create(server->wl_display, 1,
wlr_renderer_get_drm_fd(server->renderer));
}
@ -277,9 +280,6 @@ bool server_init(struct sway_server *server) {
server->new_output.notify = handle_new_output;
wl_signal_add(&server->backend->events.new_output, &server->new_output);
server->output_layout_change.notify = handle_output_layout_change;
wl_signal_add(&root->output_layout->events.change,
&server->output_layout_change);
server->xdg_output_manager_v1 =
wlr_xdg_output_manager_v1_create(server->wl_display, root->output_layout);
@ -328,7 +328,8 @@ bool server_init(struct sway_server *server) {
wl_signal_add(&server->pointer_constraints->events.new_constraint,
&server->pointer_constraint);
wlr_presentation_create(server->wl_display, server->backend);
wlr_presentation_create(server->wl_display, server->backend, SWAY_PRESENTATION_VERSION);
wlr_alpha_modifier_v1_create(server->wl_display);
server->output_manager_v1 =
wlr_output_manager_v1_create(server->wl_display);

View File

@ -56,6 +56,10 @@ For more information on these xkb configuration options, see
Sets all xkb configurations from a complete .xkb file. This file can be
dumped from _xkbcomp $DISPLAY keymap.xkb_. This setting overrides
xkb_layout, xkb_model, xkb_options, xkb_rules, and xkb_variant settings.
Custom XKB symbol files may placed in _$XDG_CONFIG_HOME/xkb/symbols_ and
other locations. See
https://xkbcommon.org/doc/current/md_doc_user_configuration.html
for details.
*input* <identifier> xkb_layout <layout_name>
Sets the layout of the keyboard like _us_ or _de_.

View File

@ -154,7 +154,7 @@ must be separated by one space. For example:
This setting only has an effect on Wayland and DRM backends, as support for
presentation timestamps and predicted output refresh rate is required.
*output* <name> adaptive_sync on|off
*output* <name> adaptive_sync on|off|toggle
Enables or disables adaptive synchronization (often referred to as Variable
Refresh Rate, or by the vendor-specific names FreeSync/G-Sync).
@ -163,9 +163,9 @@ must be separated by one space. For example:
adaptive sync can improve latency, but can cause flickering on some
hardware.
*output* <name> render_bit_depth 8|10
Controls the color channel bit depth at which frames are rendered; the
default is currently 8 bits per channel.
*output* <name> render_bit_depth 6|8|10
Controls the maximum color channel bit depth at which frames are
rendered; the default is currently 8 bits per channel.
Setting higher values will not have an effect if hardware and software lack
support for such bit depths. Successfully increasing the render bit depth

View File

@ -314,14 +314,9 @@ void arrange_output(struct sway_output *output) {
if (config->reloading) {
return;
}
struct wlr_box output_box;
wlr_output_layout_get_box(root->output_layout,
output->wlr_output, &output_box);
output->lx = output_box.x;
output->ly = output_box.y;
output->width = output_box.width;
output->height = output_box.height;
if (!output->wlr_output->enabled) {
return;
}
for (int i = 0; i < output->workspaces->length; ++i) {
struct sway_workspace *workspace = output->workspaces->items[i];
arrange_workspace(workspace);

View File

@ -22,6 +22,7 @@
#include "sway/tree/workspace.h"
#include "sway/xdg_decoration.h"
#include "list.h"
#include "pango.h"
#include "log.h"
#include "stringop.h"
@ -348,7 +349,7 @@ void container_arrange_title_bar(struct sway_container *con) {
h_padding = width - config->titlebar_h_padding - marks_buffer_width;
}
h_padding = MAX(h_padding, 0);
h_padding = MAX(h_padding, config->titlebar_h_padding);
int alloc_width = MIN((int)node->width,
width - h_padding - config->titlebar_h_padding);
@ -374,7 +375,7 @@ void container_arrange_title_bar(struct sway_container *con) {
h_padding = config->titlebar_h_padding;
}
h_padding = MAX(h_padding, 0);
h_padding = MAX(h_padding, config->titlebar_h_padding);
int alloc_width = MIN((int) node->width,
width - h_padding - config->titlebar_h_padding);
@ -499,6 +500,7 @@ void container_destroy(struct sway_container *con) {
}
free(con->title);
free(con->formatted_title);
free(con->title_format);
list_free(con->pending.children);
list_free(con->current.children);
@ -645,6 +647,91 @@ bool container_has_ancestor(struct sway_container *descendant,
return false;
}
static char *escape_pango_markup(const char *buffer) {
size_t length = escape_markup_text(buffer, NULL);
char *escaped_title = calloc(length + 1, sizeof(char));
escape_markup_text(buffer, escaped_title);
return escaped_title;
}
static size_t append_prop(char *buffer, const char *value) {
if (!value) {
return 0;
}
// If using pango_markup in font, we need to escape all markup chars
// from values to make sure tags are not inserted by clients
if (config->pango_markup) {
char *escaped_value = escape_pango_markup(value);
lenient_strcat(buffer, escaped_value);
size_t len = strlen(escaped_value);
free(escaped_value);
return len;
} else {
lenient_strcat(buffer, value);
return strlen(value);
}
}
/**
* Calculate and return the length of the formatted title.
* If buffer is not NULL, also populate the buffer with the formatted title.
*/
size_t parse_title_format(struct sway_container *container, char *buffer) {
if (!container->title_format || strcmp(container->title_format, "%title") == 0) {
if (container->view) {
return append_prop(buffer, view_get_title(container->view));
} else {
return container_build_representation(container->pending.layout, container->pending.children, buffer);
}
}
size_t len = 0;
char *format = container->title_format;
char *next = strchr(format, '%');
while (next) {
// Copy everything up to the %
lenient_strncat(buffer, format, next - format);
len += next - format;
format = next;
if (strncmp(next, "%title", 6) == 0) {
if (container->view) {
len += append_prop(buffer, view_get_title(container->view));
} else {
len += container_build_representation(container->pending.layout, container->pending.children, buffer);
}
format += 6;
} else if (container->view) {
if (strncmp(next, "%app_id", 7) == 0) {
len += append_prop(buffer, view_get_app_id(container->view));
format += 7;
} else if (strncmp(next, "%class", 6) == 0) {
len += append_prop(buffer, view_get_class(container->view));
format += 6;
} else if (strncmp(next, "%instance", 9) == 0) {
len += append_prop(buffer, view_get_instance(container->view));
format += 9;
} else if (strncmp(next, "%shell", 6) == 0) {
len += append_prop(buffer, view_get_shell(container->view));
format += 6;
} else {
lenient_strcat(buffer, "%");
++format;
++len;
}
} else {
lenient_strcat(buffer, "%");
++format;
++len;
}
next = strchr(format, '%');
}
lenient_strcat(buffer, format);
len += strlen(format);
return len;
}
/**
* Calculate and return the length of the tree representation.
* An example tree representation is: V[Terminal, Firefox]
@ -700,16 +787,14 @@ size_t container_build_representation(enum sway_container_layout layout,
void container_update_representation(struct sway_container *con) {
if (!con->view) {
size_t len = container_build_representation(con->pending.layout,
con->pending.children, NULL);
size_t len = parse_title_format(con, NULL);
free(con->formatted_title);
con->formatted_title = calloc(len + 1, sizeof(char));
if (!sway_assert(con->formatted_title,
"Unable to allocate title string")) {
return;
}
container_build_representation(con->pending.layout, con->pending.children,
con->formatted_title);
parse_title_format(con, con->formatted_title);
if (con->title_bar.title_text) {
sway_text_node_set_text(con->title_bar.title_text, con->formatted_title);

View File

@ -180,12 +180,7 @@ void output_enable(struct sway_output *output) {
ws->layout = output_get_default_layout(output);
}
input_manager_configure_xcursor();
wl_signal_emit_mutable(&root->events.new_node, &output->node);
arrange_layers(output);
arrange_root();
}
static void evacuate_sticky(struct sway_workspace *old_ws,
@ -300,13 +295,6 @@ void output_disable(struct sway_output *output) {
list_del(root->outputs, index);
output->enabled = false;
arrange_root();
// Reconfigure all devices, since devices with map_to_output directives for
// an output that goes offline should stop sending events as long as the
// output remains offline.
input_manager_configure_all_input_mappings();
}
void output_begin_destroy(struct sway_output *output) {

View File

@ -19,12 +19,6 @@
struct sway_root *root;
static void output_layout_handle_change(struct wl_listener *listener,
void *data) {
arrange_root();
transaction_commit_dirty();
}
struct sway_root *root_create(struct wl_display *wl_display) {
struct sway_root *root = calloc(1, sizeof(struct sway_root));
if (!root) {
@ -81,14 +75,10 @@ struct sway_root *root_create(struct wl_display *wl_display) {
root->non_desktop_outputs = create_list();
root->scratchpad = create_list();
root->output_layout_change.notify = output_layout_handle_change;
wl_signal_add(&root->output_layout->events.change,
&root->output_layout_change);
return root;
}
void root_destroy(struct sway_root *root) {
wl_list_remove(&root->output_layout_change.link);
list_free(root->scratchpad);
list_free(root->non_desktop_outputs);
list_free(root->outputs);

View File

@ -34,7 +34,6 @@
#include "sway/tree/workspace.h"
#include "sway/config.h"
#include "sway/xdg_decoration.h"
#include "pango.h"
#include "stringop.h"
bool view_init(struct sway_view *view, enum sway_view_type type,
@ -81,8 +80,6 @@ void view_destroy(struct sway_view *view) {
view_assign_ctx(view, NULL);
wlr_scene_node_destroy(&view->scene_tree->node);
free(view->title_format);
if (view->impl->destroy) {
view->impl->destroy(view);
} else {
@ -991,77 +988,6 @@ struct sway_view *view_from_wlr_surface(struct wlr_surface *wlr_surface) {
return NULL;
}
static char *escape_pango_markup(const char *buffer) {
size_t length = escape_markup_text(buffer, NULL);
char *escaped_title = calloc(length + 1, sizeof(char));
escape_markup_text(buffer, escaped_title);
return escaped_title;
}
static size_t append_prop(char *buffer, const char *value) {
if (!value) {
return 0;
}
// If using pango_markup in font, we need to escape all markup chars
// from values to make sure tags are not inserted by clients
if (config->pango_markup) {
char *escaped_value = escape_pango_markup(value);
lenient_strcat(buffer, escaped_value);
size_t len = strlen(escaped_value);
free(escaped_value);
return len;
} else {
lenient_strcat(buffer, value);
return strlen(value);
}
}
/**
* Calculate and return the length of the formatted title.
* If buffer is not NULL, also populate the buffer with the formatted title.
*/
static size_t parse_title_format(struct sway_view *view, char *buffer) {
if (!view->title_format || strcmp(view->title_format, "%title") == 0) {
return append_prop(buffer, view_get_title(view));
}
size_t len = 0;
char *format = view->title_format;
char *next = strchr(format, '%');
while (next) {
// Copy everything up to the %
lenient_strncat(buffer, format, next - format);
len += next - format;
format = next;
if (strncmp(next, "%title", 6) == 0) {
len += append_prop(buffer, view_get_title(view));
format += 6;
} else if (strncmp(next, "%app_id", 7) == 0) {
len += append_prop(buffer, view_get_app_id(view));
format += 7;
} else if (strncmp(next, "%class", 6) == 0) {
len += append_prop(buffer, view_get_class(view));
format += 6;
} else if (strncmp(next, "%instance", 9) == 0) {
len += append_prop(buffer, view_get_instance(view));
format += 9;
} else if (strncmp(next, "%shell", 6) == 0) {
len += append_prop(buffer, view_get_shell(view));
format += 6;
} else {
lenient_strcat(buffer, "%");
++format;
++len;
}
next = strchr(format, '%');
}
lenient_strcat(buffer, format);
len += strlen(format);
return len;
}
void view_update_app_id(struct sway_view *view) {
const char *app_id = view_get_app_id(view);
@ -1090,7 +1016,7 @@ void view_update_title(struct sway_view *view, bool force) {
free(view->container->title);
free(view->container->formatted_title);
size_t len = parse_title_format(view, NULL);
size_t len = parse_title_format(view->container, NULL);
if (len) {
char *buffer = calloc(len + 1, sizeof(char));
@ -1098,7 +1024,7 @@ void view_update_title(struct sway_view *view, bool force) {
return;
}
parse_title_format(view, buffer);
parse_title_format(view->container, buffer);
view->container->formatted_title = buffer;
} else {
view->container->formatted_title = NULL;

View File

@ -508,7 +508,7 @@ void bar_run(struct swaybar *bar) {
}
#if HAVE_TRAY
if (bar->tray) {
loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar->tray->bus);
loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar);
}
#endif
while (bar->running) {

View File

@ -518,8 +518,7 @@ static bool handle_barconfig_update(struct swaybar *bar, const char *payload,
#if HAVE_TRAY
if (oldcfg->tray_hidden && !newcfg->tray_hidden) {
bar->tray = create_tray(bar);
loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in,
bar->tray->bus);
loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar);
} else if (bar->tray && newcfg->tray_hidden) {
loop_remove_fd(bar->eventloop, bar->tray->fd);
destroy_tray(bar->tray);

View File

@ -1,4 +1,5 @@
#include <cairo.h>
#include <poll.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@ -90,9 +91,16 @@ void destroy_tray(struct swaybar_tray *tray) {
}
void tray_in(int fd, short mask, void *data) {
sd_bus *bus = data;
struct swaybar *bar = data;
int ret;
while ((ret = sd_bus_process(bus, NULL)) > 0) {
if (mask & (POLLHUP | POLLERR)) {
sway_log(SWAY_ERROR, "D-Bus connection closed unexpectedly");
bar->running = false;
return;
}
while ((ret = sd_bus_process(bar->tray->bus, NULL)) > 0) {
// This space intentionally left blank
}
if (ret < 0) {