foreign-toplevel: support fullscreen state and request

This commit is contained in:
Ilia Bozhinov 2019-04-26 17:09:43 +02:00 committed by Simon Ser
parent a656e486f4
commit 4e6c17a7c9
3 changed files with 95 additions and 10 deletions

View File

@ -28,9 +28,10 @@ struct wlr_foreign_toplevel_manager_v1 {
}; };
enum wlr_foreign_toplevel_handle_v1_state { enum wlr_foreign_toplevel_handle_v1_state {
WLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MAXIMIZED = 1, WLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MAXIMIZED = (1 << 0),
WLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MINIMIZED = 2, WLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MINIMIZED = (1 << 1),
WLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED = 4, WLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED = (1 << 2),
WLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN = (1 << 3),
}; };
struct wlr_foreign_toplevel_handle_v1_output { struct wlr_foreign_toplevel_handle_v1_output {
@ -59,6 +60,8 @@ struct wlr_foreign_toplevel_handle_v1 {
struct wl_signal request_minimize; struct wl_signal request_minimize;
//wlr_foreign_toplevel_handle_v1_activated_event //wlr_foreign_toplevel_handle_v1_activated_event
struct wl_signal request_activate; struct wl_signal request_activate;
//wlr_foreign_toplevel_handle_v1_fullscreen_event
struct wl_signal request_fullscreen;
struct wl_signal request_close; struct wl_signal request_close;
//wlr_foreign_toplevel_handle_v1_set_rectangle_event //wlr_foreign_toplevel_handle_v1_set_rectangle_event
@ -84,6 +87,12 @@ struct wlr_foreign_toplevel_handle_v1_activated_event {
struct wlr_seat *seat; struct wlr_seat *seat;
}; };
struct wlr_foreign_toplevel_handle_v1_fullscreen_event {
struct wlr_foreign_toplevel_handle_v1 *toplevel;
bool fullscreen;
struct wlr_output *output;
};
struct wlr_foreign_toplevel_handle_v1_set_rectangle_event { struct wlr_foreign_toplevel_handle_v1_set_rectangle_event {
struct wlr_foreign_toplevel_handle_v1 *toplevel; struct wlr_foreign_toplevel_handle_v1 *toplevel;
struct wlr_surface *surface; struct wlr_surface *surface;
@ -116,5 +125,7 @@ void wlr_foreign_toplevel_handle_v1_set_minimized(
struct wlr_foreign_toplevel_handle_v1 *toplevel, bool minimized); struct wlr_foreign_toplevel_handle_v1 *toplevel, bool minimized);
void wlr_foreign_toplevel_handle_v1_set_activated( void wlr_foreign_toplevel_handle_v1_set_activated(
struct wlr_foreign_toplevel_handle_v1 *toplevel, bool activated); struct wlr_foreign_toplevel_handle_v1 *toplevel, bool activated);
void wlr_foreign_toplevel_handle_v1_set_fullscreen(
struct wlr_foreign_toplevel_handle_v1* toplevel, bool fullscreen);
#endif #endif

View File

@ -25,7 +25,7 @@
THIS SOFTWARE. THIS SOFTWARE.
</copyright> </copyright>
<interface name="zwlr_foreign_toplevel_manager_v1" version="1"> <interface name="zwlr_foreign_toplevel_manager_v1" version="2">
<description summary="list and control opened apps"> <description summary="list and control opened apps">
The purpose of this protocol is to enable the creation of taskbars The purpose of this protocol is to enable the creation of taskbars
and docks by providing them with a list of opened applications and and docks by providing them with a list of opened applications and
@ -68,7 +68,7 @@
</event> </event>
</interface> </interface>
<interface name="zwlr_foreign_toplevel_handle_v1" version="1"> <interface name="zwlr_foreign_toplevel_handle_v1" version="2">
<description summary="an opened toplevel"> <description summary="an opened toplevel">
A zwlr_foreign_toplevel_handle_v1 object represents an opened toplevel A zwlr_foreign_toplevel_handle_v1 object represents an opened toplevel
window. Each app may have multiple opened toplevels. window. Each app may have multiple opened toplevels.
@ -153,6 +153,7 @@
<entry name="maximized" value="0" summary="the toplevel is maximized"/> <entry name="maximized" value="0" summary="the toplevel is maximized"/>
<entry name="minimized" value="1" summary="the toplevel is minimized"/> <entry name="minimized" value="1" summary="the toplevel is minimized"/>
<entry name="activated" value="2" summary="the toplevel is active"/> <entry name="activated" value="2" summary="the toplevel is active"/>
<entry name="fullscreen" value="3" summary="the toplevel is fullscreen" since="2"/>
</enum> </enum>
<event name="state"> <event name="state">
@ -231,5 +232,28 @@
destruction of the object. destruction of the object.
</description> </description>
</request> </request>
<!-- Version 2 additions -->
<request name="set_fullscreen" since="2">
<description summary="request that the toplevel be fullscreened">
Requests that the toplevel be fullscreened on the given output. If the
fullscreen state and/or the outputs the toplevel is visible on actually
change, this will be indicated by the state and output_enter/leave
events.
The output parameter is only a hint to the compositor. Also, if output
is NULL, the compositor should decide which output the toplevel will be
fullscreened on, if at all.
</description>
<arg name="output" type="object" interface="wl_output" allow-null="true"/>
</request>
<request name="unset_fullscreen" since="2">
<description summary="request that the toplevel be unfullscreened">
Requests that the toplevel be unfullscreened. If the fullscreen state
actually changes, this will be indicated by the state event.
</description>
</request>
</interface> </interface>
</protocol> </protocol>

View File

@ -9,7 +9,7 @@
#include "util/signal.h" #include "util/signal.h"
#include "wlr-foreign-toplevel-management-unstable-v1-protocol.h" #include "wlr-foreign-toplevel-management-unstable-v1-protocol.h"
#define FOREIGN_TOPLEVEL_MANAGEMENT_V1_VERSION 1 #define FOREIGN_TOPLEVEL_MANAGEMENT_V1_VERSION 2
static const struct zwlr_foreign_toplevel_handle_v1_interface toplevel_handle_impl; static const struct zwlr_foreign_toplevel_handle_v1_interface toplevel_handle_impl;
@ -70,6 +70,36 @@ static void foreign_toplevel_handle_unset_minimized(struct wl_client *client,
toplevel_send_minimized_event(resource, false); toplevel_send_minimized_event(resource, false);
} }
static void toplevel_send_fullscreen_event(struct wl_resource *resource,
bool state, struct wl_resource *output_resource) {
struct wlr_foreign_toplevel_handle_v1 *toplevel =
toplevel_handle_from_resource(resource);
if (!toplevel) {
return;
}
struct wlr_output *output = NULL;
if (output_resource) {
output = wlr_output_from_resource(output_resource);
}
struct wlr_foreign_toplevel_handle_v1_fullscreen_event event = {
.toplevel = toplevel,
.fullscreen = state,
.output = output,
};
wlr_signal_emit_safe(&toplevel->events.request_fullscreen, &event);
}
static void foreign_toplevel_handle_set_fullscreen(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *output) {
toplevel_send_fullscreen_event(resource, true, output);
}
static void foreign_toplevel_handle_unset_fullscreen(struct wl_client *client,
struct wl_resource *resource) {
toplevel_send_fullscreen_event(resource, false, NULL);
}
static void foreign_toplevel_handle_activate(struct wl_client *client, static void foreign_toplevel_handle_activate(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat) { struct wl_resource *resource, struct wl_resource *seat) {
struct wlr_foreign_toplevel_handle_v1 *toplevel = struct wlr_foreign_toplevel_handle_v1 *toplevel =
@ -136,7 +166,9 @@ static const struct zwlr_foreign_toplevel_handle_v1_interface toplevel_handle_im
.activate = foreign_toplevel_handle_activate, .activate = foreign_toplevel_handle_activate,
.close = foreign_toplevel_handle_close, .close = foreign_toplevel_handle_close,
.set_rectangle = foreign_toplevel_handle_set_rectangle, .set_rectangle = foreign_toplevel_handle_set_rectangle,
.destroy = foreign_toplevel_handle_destroy .destroy = foreign_toplevel_handle_destroy,
.set_fullscreen = foreign_toplevel_handle_set_fullscreen,
.unset_fullscreen = foreign_toplevel_handle_unset_fullscreen,
}; };
static void toplevel_idle_send_done(void *data) { static void toplevel_idle_send_done(void *data) {
@ -299,6 +331,13 @@ static bool fill_array_from_toplevel_state(struct wl_array *array,
} }
*index = ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED; *index = ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED;
} }
if (state & WLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN) {
uint32_t *index = wl_array_add(array, sizeof(uint32_t));
if (index == NULL) {
return false;
}
*index = ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN;
}
return true; return true;
} }
@ -356,6 +395,16 @@ void wlr_foreign_toplevel_handle_v1_set_activated(
toplevel_send_state(toplevel); toplevel_send_state(toplevel);
} }
void wlr_foreign_toplevel_handle_v1_set_fullscreen(
struct wlr_foreign_toplevel_handle_v1 * toplevel, bool fullscreen) {
if (fullscreen) {
toplevel->state |= WLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN;
} else {
toplevel->state &= ~WLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN;
}
toplevel_send_state(toplevel);
}
void wlr_foreign_toplevel_handle_v1_destroy( void wlr_foreign_toplevel_handle_v1_destroy(
struct wlr_foreign_toplevel_handle_v1 *toplevel) { struct wlr_foreign_toplevel_handle_v1 *toplevel) {
if (!toplevel) { if (!toplevel) {
@ -430,6 +479,7 @@ wlr_foreign_toplevel_handle_v1_create(
wl_signal_init(&toplevel->events.request_maximize); wl_signal_init(&toplevel->events.request_maximize);
wl_signal_init(&toplevel->events.request_minimize); wl_signal_init(&toplevel->events.request_minimize);
wl_signal_init(&toplevel->events.request_activate); wl_signal_init(&toplevel->events.request_activate);
wl_signal_init(&toplevel->events.request_fullscreen);
wl_signal_init(&toplevel->events.request_close); wl_signal_init(&toplevel->events.request_close);
wl_signal_init(&toplevel->events.set_rectangle); wl_signal_init(&toplevel->events.set_rectangle);
wl_signal_init(&toplevel->events.destroy); wl_signal_init(&toplevel->events.destroy);