Skip to content

Commit

Permalink
squash me: Daves version
Browse files Browse the repository at this point in the history
  • Loading branch information
davidedmundson committed Apr 30, 2024
1 parent 7965e97 commit 20b9572
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 95 deletions.
10 changes: 5 additions & 5 deletions src/video/wayland/SDL_waylandvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,8 @@ static void display_handle_global(void *data, struct wl_registry *registry, uint
}
} else if (SDL_strcmp(interface, "zxdg_exporter_v2") == 0) {
d->zxdg_exporter_v2 = wl_registry_bind(d->registry, id, &zxdg_exporter_v2_interface, 1);
} else if (SDL_strcmp(interface, "xdg_toplevel_icon_v1") == 0) {
d->xdg_toplevel_icon_v1 = wl_registry_bind(d->registry, id, &xdg_toplevel_icon_v1_interface, 1);
} else if (SDL_strcmp(interface, "xdg_toplevel_icon_manager_v1") == 0) {
d->xdg_toplevel_icon_manager_v1 = wl_registry_bind(d->registry, id, &xdg_toplevel_icon_manager_v1_interface, 1);
} else if (SDL_strcmp(interface, "kde_output_order_v1") == 0) {
d->kde_output_order = wl_registry_bind(d->registry, id, &kde_output_order_v1_interface, 1);
kde_output_order_v1_add_listener(d->kde_output_order, &kde_output_order_listener, d);
Expand Down Expand Up @@ -1350,9 +1350,9 @@ static void Wayland_VideoCleanup(SDL_VideoDevice *_this)
data->zxdg_exporter_v2 = NULL;
}

if (data->xdg_toplevel_icon_v1) {
xdg_toplevel_icon_v1_destroy(data->xdg_toplevel_icon_v1);
data->xdg_toplevel_icon_v1 = NULL;
if (data->xdg_toplevel_icon_manager_v1) {
xdg_toplevel_icon_manager_v1_destroy(data->xdg_toplevel_icon_manager_v1);
data->xdg_toplevel_icon_manager_v1 = NULL;
}

if (data->kde_output_order) {
Expand Down
2 changes: 1 addition & 1 deletion src/video/wayland/SDL_waylandvideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct SDL_VideoData
struct wp_fractional_scale_manager_v1 *fractional_scale_manager;
struct zwp_input_timestamps_manager_v1 *input_timestamps_manager;
struct zxdg_exporter_v2 *zxdg_exporter_v2;
struct xdg_toplevel_icon_v1 *xdg_toplevel_icon_v1;
struct xdg_toplevel_icon_manager_v1 *xdg_toplevel_icon_manager_v1;
struct kde_output_order_v1 *kde_output_order;

struct xkb_context *xkb_context;
Expand Down
26 changes: 16 additions & 10 deletions src/video/wayland/SDL_waylandwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,12 @@ void Wayland_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
zxdg_exported_v2_add_listener(data->exported, &exported_v2_listener, data);
}

if (c->xdg_toplevel_icon_v1 && data->icon.wl_buffer) {
xdg_toplevel_icon_v1_set_icon_buffer(_this->driverdata->xdg_toplevel_icon_v1, libdecor_frame_get_xdg_toplevel(data->shell_surface.libdecor.frame), data->icon.wl_buffer, 1);
if (c->xdg_toplevel_icon_manager_v1 && data->icon.wl_buffer) {
struct xdg_toplevel_icon_v1 *xdg_icon = xdg_toplevel_icon_manager_v1_create_icon(_this->driverdata->xdg_toplevel_icon_manager_v1);
xdg_toplevel_icon_v1_set_icon_buffer(xdg_icon, data->icon.wl_buffer, 1);
xdg_toplevel_icon_manager_v1_set_icon(_this->driverdata->xdg_toplevel_icon_manager_v1,
libdecor_frame_get_xdg_toplevel(data->shell_surface.libdecor.frame),
xdg_icon);
}

SDL_SetProperty(props, SDL_PROP_WINDOW_WAYLAND_XDG_SURFACE_POINTER, libdecor_frame_get_xdg_surface(data->shell_surface.libdecor.frame));
Expand Down Expand Up @@ -1653,8 +1657,12 @@ void Wayland_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
zxdg_exported_v2_add_listener(data->exported, &exported_v2_listener, data);
}

if (c->xdg_toplevel_icon_v1 && data->icon.wl_buffer) {
xdg_toplevel_icon_v1_set_icon_buffer(_this->driverdata->xdg_toplevel_icon_v1, data->shell_surface.xdg.roleobj.toplevel, data->icon.wl_buffer, 1);
if (c->xdg_toplevel_icon_manager_v1 && data->icon.wl_buffer) {
struct xdg_toplevel_icon_v1 *xdg_icon = xdg_toplevel_icon_manager_v1_create_icon(_this->driverdata->xdg_toplevel_icon_manager_v1);
xdg_toplevel_icon_v1_set_icon_buffer(xdg_icon, data->icon.wl_buffer, 1);
xdg_toplevel_icon_manager_v1_set_icon(_this->driverdata->xdg_toplevel_icon_manager_v1,
data->shell_surface.xdg.roleobj.toplevel,
xdg_icon);
}

SDL_SetProperty(props, SDL_PROP_WINDOW_WAYLAND_XDG_TOPLEVEL_POINTER, data->shell_surface.xdg.roleobj.toplevel);
Expand Down Expand Up @@ -2505,7 +2513,7 @@ int Wayland_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surfac
SDL_WindowData *wind = window->driverdata;
struct xdg_toplevel *toplevel = NULL;

if (!_this->driverdata->xdg_toplevel_icon_v1) {
if (!_this->driverdata->xdg_toplevel_icon_manager_v1) {
return SDL_SetError("wayland: cannot set icon; xdg_toplevel_icon_v1 protocol not supported");
}

Expand All @@ -2530,11 +2538,9 @@ int Wayland_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surfac
SDL_PremultiplyAlpha(icon->w, icon->h, icon->format->format, icon->pixels, icon->pitch, SDL_PIXELFORMAT_ARGB8888, wind->icon.shm_data, icon->w * 4);

if (toplevel) {
/* If the new icon size doesn't match the old one, it will be added as an additional size instead
* of overwriting the existing one, so the window icon must be explicitly cleared first.
*/
xdg_toplevel_icon_v1_set_icon_name(_this->driverdata->xdg_toplevel_icon_v1, toplevel, NULL);
xdg_toplevel_icon_v1_set_icon_buffer(_this->driverdata->xdg_toplevel_icon_v1, toplevel, wind->icon.wl_buffer, 1);
struct xdg_toplevel_icon_v1 *xdg_icon = xdg_toplevel_icon_manager_v1_create_icon(_this->driverdata->xdg_toplevel_icon_manager_v1);
xdg_toplevel_icon_v1_set_icon_buffer(xdg_icon, wind->icon.wl_buffer, 1);
xdg_toplevel_icon_manager_v1_set_icon(_this->driverdata->xdg_toplevel_icon_manager_v1, toplevel, xdg_icon);
}

return 0;
Expand Down
149 changes: 70 additions & 79 deletions wayland-protocols/xdg-toplevel-icon-v1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,64 @@
only be done by creating a new major version of the extension.
</description>

<interface name="xdg_toplevel_icon_manager_v1" version="1">
<description summary="interface to set toplevel window icons">
</description>

<request name="destroy" type="destructor">
<description summary="destroys the toplevel icon manager">
Destroy the toplevel icon manager. This doesn't destroy objects created with the manager.
</description>
</request>

<request name="create_icon">
<description summary="create new icon instance">
Creates a new icon object. This icon can then be attached to a
window via the set_icon request.
</description>
<arg name="id" type="new_id" interface="xdg_toplevel_icon_v1"/>
</request>

<request name="set_icon">
<description summary="sets an icon on a window">
Sets the window to the provided icon.

This state is double-buffered and is applied on the next
wl_surface.commit of the toplevel.

After making this call xdg_toplevel_icon_v1 is now inert
any changes will be ignored.
The same xdg_toplevel_icon_v1 icon cannot be set on multple windows.

Setting the icon to null will clear any previously set icon.
</description>
<arg name="toplevel" type="object" interface="xdg_toplevel"/>
<arg name="icon" type="object" interface="xdg_toplevel_icon_v1" allow-null="true"/>
</request>

<event name="icon_size">
<description summary="describes a supported icon size">
This event indicates an icon size the compositor prefers to be
available if the client can render it.

Multiple icon_size events will be sent on binding to this interface,
or if the preferred size changes.

A sequence of 'icon_size' events is finished with a 'done' event.
</description>
<arg name="size" type="int"
summary="the edge size of the square icon in surface-local coordinates, e.g. 64"/>
<arg name="scale" type="int"
summary="the scaling factor of the icon, e.g. 1"/>
</event>

<event name="done">
<description summary="all information has been sent">
This event is sent after all 'icon_size' events have been sent.
</description>
</event>
</interface>

<interface name="xdg_toplevel_icon_v1" version="1">
<description summary="interface to set toplevel window icons">
This interface provides a way for clients to set a dedicated icon for
Expand All @@ -68,43 +126,31 @@
value="1"/>
</enum>

<request name="destroy" type="destructor">
<description summary="destroys the icon object">
Destroys the xdg_toplevel_icon_v1 object. The icon remains set on the window.
</description>
</request>

<request name="set_icon_name">
<description summary="set the toplevel icon via a stock icon name, or clear the icon">
<description summary="set icon name">
This request assigns an icon to 'toplevel' using its XDG icon-theme
name, or clears the toplevel icon.
This state is double-buffered and is applied on the next
wl_surface.commit of the toplevel.
name, overriding any previously set name.

The request must specify an icon name for a stock icon in the icon
theme.
If 'icon_name' is set to null, the icon of the respective toplevel is
reset to its default icon (usually the icon of the application,
derived from its desktop-entry file, or a placeholder icon).

The compositor must resolve 'icon_name' according to the lookup rules
described in the XDG icon theme specification[1] using the
environment's current icon theme.

This request must be honored if sent as part of the xdg_toplevel's
configure sequence. The client can send it at a later time to request
an update of the icon.

If a compositor does not support setting an icon by its name, it should
ignore all 'set_icon_name' requests that do not have 'icon_name' set
to null.

[1]: https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
</description>
<arg name="toplevel" type="object" interface="xdg_toplevel" summary="the toplevel to act on"/>
<arg name="icon_name" type="string" allow-null="true"/>
<arg name="icon_name" type="string"/>
</request>

<request name="set_icon_buffer">
<description summary="set a toplevel icon from a pixel buffer">
This request assigns a window icon to 'toplevel' using pixel data
supplied as wl_buffer.
This state is double-buffered and is applied on the next
wl_surface.commit of the toplevel.
This request assigns adds pixel data
supplied as wl_buffer to the icon.

This request provides the compositor with pixel data for the window
icon of 'toplevel' for the scaling factor 'scale'.
Expand All @@ -118,69 +164,14 @@

The client may invoke this request multiple times to provide an icon in
multiple sizes.

If the compositor already has a buffer of the same size and scale from
a previous 'set_icon_buffer' request, data from the latest request
overrides the preexisting pixel data.

To reset the icon to the compositor's default and clear all submitted
buffers, the client should perform a 'set_icon_name' request with an
'icon_name' of null.
</description>
<arg name="toplevel" type="object" interface="xdg_toplevel" summary="the toplevel to act on"/>
<arg name="icon" type="object" interface="wl_buffer"/>
<arg name="scale" type="int"
summary="the scaling factor of the icon, e.g. 1"/>
</request>

<request name="get_icon_sizes">
<description summary="retrieve a list of preferred toplevel icon sizes">
When rendering a vector graphic icon, it is useful for the client to
know which icon sizes it should preferrably provide to the compositor.

The compositor must reply to this request with 'icon_size' events, one
for each size that it may need in future (icons may be used within the
compositor, but also by other desktop components, which the compositor
should take into account).

After all 'icon_size' events are emitted, a 'done' event must be sent.
The client may the render its icons to the appropriate sizes and
submit them using 'set_icon_buffer'.

If the compositor does not want to provide any preferences at all,
it must reply solely with a 'done' event, without emitting any
'icon_size' events.

The provided icon sizes are not toplevel-specific and the client may
cache and use them for all its toplevel surfaces.

If the compositor preferences change, it may emit a new 'icon_size'
sequence to update the client information, even if a 'get_icon_sizes'
request was not explicitly made again (but the request must have been
made at least once prior).
</description>
</request>

<event name="icon_size">
<description summary="describes a supported icon size">
This event indicates an icon size the compositor prefers to be
available if the client can render it.
Multiple 'icon_size' events are emitted in response to the client
performing a 'get_icon_sizes' request.

A sequence of 'icon_size' events is finished with a 'done' event.
</description>
<arg name="size" type="int"
summary="the edge size of the square icon in surface-local coordinates, e.g. 64"/>
<arg name="scale" type="int"
summary="the scaling factor of the icon, e.g. 1"/>
</event>

<event name="done">
<description summary="all information has been sent">
This event is sent after all 'icon_size' events have been sent.
</description>
</event>

</interface>

</protocol>

0 comments on commit 20b9572

Please sign in to comment.