History

wayland: further xdg-decoration/border refinements

The value of the border option should always match what the actual state of the window is. Previously if a compositor rejected the request by mpv, it did not correct itself. Also add some code to keep track of decoration requests. Anytime the state is changed, make the last saved request again (doesn't hurt and seems like intuitive behavior). Unfortunately, this isn't foolproof since options only send callback if the value is changed. (ex. on sway if the floating window has no border, and then is titled, setting the border value to "yes" does nothing since tiling the window already set the border value to "yes").

Dudemanguy committed 5 years ago

Commit 2d348981 parent 940f8712 files · +40 −26Browse files

Unified · Split

2 files
  1. video/out/wayland_common.c +39 −26
  2. video/out/wayland_common.h +1 −0
video/out/wayland_common.c+39−26
@@ -153,7 +153,7 @@ static int spawn_cursor(struct vo_wayland_state *wl); · 152 unmodified lines
153153 static void greatest_common_divisor(struct vo_wayland_state *wl, int a, int b);
154154 static void queue_new_sync(struct vo_wayland_state *wl);
155155 static void remove_output(struct vo_wayland_output *out);
156−static void set_border_decorations(struct vo_wayland_state *wl, uint32_t mode);
156+static void request_decoration_mode(struct vo_wayland_state *wl, uint32_t mode);
157157 static void set_geometry(struct vo_wayland_state *wl);
158158 static void set_surface_scaling(struct vo_wayland_state *wl);
159159 static void sync_shift(struct vo_wayland_state *wl);
@@ -828,6 +828,9 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel, · 668 unmodified lines
828828 m_config_cache_write_opt(wl->vo_opts_cache, &vo_opts->window_maximized);
829829 }
830830
831+ if (wl->requested_decoration)
832+ request_decoration_mode(wl, wl->requested_decoration);
833+
831834 if (wl->activated != is_activated) {
832835 wl->activated = is_activated;
833836 if ((!wl->focused && wl->activated && wl->has_keyboard_input) ||
@@ -905,7 +908,18 @@ static void configure_decorations(void *data, · 71 unmodified lines
905908 uint32_t mode)
906909 {
907910 struct vo_wayland_state *wl = data;
908− set_border_decorations(wl, mode);
911+ struct mp_vo_opts *opts = wl->vo_opts;
912+
913+ if (wl->requested_decoration == mode)
914+ wl->requested_decoration = 0;
915+
916+ if (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE) {
917+ MP_VERBOSE(wl, "Enabling server decorations\n");
918+ } else {
919+ MP_VERBOSE(wl, "Disabling server decorations\n");
920+ }
921+ opts->border = mode - 1;
922+ m_config_cache_write_opt(wl->vo_opts_cache, &opts->border);
909923 }
910924
911925 static const struct zxdg_toplevel_decoration_v1_listener decoration_listener = {
@@ -1311,6 +1325,12 @@ static void queue_new_sync(struct vo_wayland_state *wl) · 399 unmodified lines
13111325 sync_shift(wl);
13121326 }
13131327
1328+static void request_decoration_mode(struct vo_wayland_state *wl, uint32_t mode)
1329+{
1330+ wl->requested_decoration = mode;
1331+ zxdg_toplevel_decoration_v1_set_mode(wl->xdg_toplevel_decoration, mode);
1332+}
1333+
13141334 static void remove_output(struct vo_wayland_output *out)
13151335 {
13161336 if (!out)
@@ -1325,25 +1345,6 @@ static void remove_output(struct vo_wayland_output *out) · 8 unmodified lines
13251345 return;
13261346 }
13271347
1328−static void set_border_decorations(struct vo_wayland_state *wl, uint32_t mode)
1329−{
1330− if (!wl->xdg_toplevel_decoration) {
1331− wl->vo_opts->border = false;
1332− m_config_cache_write_opt(wl->vo_opts_cache,
1333− &wl->vo_opts->border);
1334− return;
1335− }
1336− if (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE) {
1337− MP_VERBOSE(wl, "Enabling server decorations\n");
1338− wl->vo_opts->border = true;
1339− } else {
1340− MP_VERBOSE(wl, "Disabling server decorations\n");
1341− wl->vo_opts->border = false;
1342− }
1343− m_config_cache_write_opt(wl->vo_opts_cache,
1344− &wl->vo_opts->border);
1345−}
1346−
13471348 static int set_cursor_visibility(struct vo_wayland_state *wl, bool on)
13481349 {
13491350 wl->cursor_visible = on;
@@ -1562,9 +1563,22 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) · 212 unmodified lines
15621563 while (m_config_cache_get_next_changed(wl->vo_opts_cache, &opt)) {
15631564 if (opt == &opts->appid)
15641565 update_app_id(wl);
1565− if (opt == &opts->border && wl->xdg_toplevel_decoration)
1566− // The enum in xdg-decoration starts at 1.
1567− zxdg_toplevel_decoration_v1_set_mode(wl->xdg_toplevel_decoration, opts->border + 1);
1566+ if (opt == &opts->border)
1567+ {
1568+ // This is stupid but the value of border shouldn't be written
1569+ // unless we get a configure event. Change it back to its old
1570+ // value and let configure_decorations handle it after the request.
1571+ if (wl->xdg_toplevel_decoration) {
1572+ opts->border = !opts->border;
1573+ m_config_cache_write_opt(wl->vo_opts_cache,
1574+ &opts->border);
1575+ request_decoration_mode(wl, !opts->border + 1);
1576+ } else {
1577+ opts->border = false;
1578+ m_config_cache_write_opt(wl->vo_opts_cache,
1579+ &wl->vo_opts->border);
1580+ }
1581+ }
15681582 if (opt == &opts->fullscreen)
15691583 toggle_fullscreen(wl);
15701584 if (opt == &opts->hidpi_window_scale)
@@ -1736,8 +1750,7 @@ int vo_wayland_init(struct vo *vo) · 165 unmodified lines
17361750 if (wl->xdg_decoration_manager) {
17371751 wl->xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(wl->xdg_decoration_manager, wl->xdg_toplevel);
17381752 zxdg_toplevel_decoration_v1_add_listener(wl->xdg_toplevel_decoration, &decoration_listener, wl);
1739− // The enum in xdg-decoration starts at 1.
1740− zxdg_toplevel_decoration_v1_set_mode(wl->xdg_toplevel_decoration, wl->vo_opts->border + 1);
1753+ request_decoration_mode(wl, wl->vo_opts->border + 1);
17411754 } else {
17421755 wl->vo_opts->border = false;
17431756 m_config_cache_write_opt(wl->vo_opts_cache,
video/out/wayland_common.h+1−0
@@ -79,6 +79,7 @@ struct vo_wayland_state { · 78 unmodified lines
7979 /* xdg-decoration */
8080 struct zxdg_decoration_manager_v1 *xdg_decoration_manager;
8181 struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration;
82+ int requested_decoration;
8283
8384 /* xdg-shell */
8485 struct xdg_wm_base *wm_base;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t