Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gtk_layer_set_exclusive_edge #184

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions include/gtk-layer-shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,26 @@ void gtk_layer_set_margin (GtkWindow *window, GtkLayerShellEdge edge, int margin
*/
int gtk_layer_get_margin (GtkWindow *window, GtkLayerShellEdge edge);

/**
* gtk_layer_set_exclusive_edge:
* @window: A layer surface.
* @exclusive_edge: The edge for which to set the exclusive zone.
*
* Set the edge for which the exclusive zone should apply. This is required if
* the edge cannot be automatically deduced from the anchor points.
*/
void gtk_layer_set_exclusive_edge (GtkWindow *window, int exclusive_edge);

/**
* gtk_layer_set_exclusive_zone:
* @window: A layer surface.
* @exclusive_zone: The size of the exclusive zone.
*
* Has no effect unless the surface is anchored to an edge. Requests that the compositor
* does not place other surfaces within the given exclusive zone of the anchored edge.
* For example, a panel can request to not be covered by maximized windows. See
* wlr-layer-shell-unstable-v1.xml for details.
* Has no effect unless the surface is anchored to an edge, or has an exclusive
* edge set with gtk_layer_set_exclusive_edge(). Requests that the compositor
* does not place other surfaces within the given exclusive zone of the
* anchored edge. For example, a panel can request to not be covered by
* maximized windows. See wlr-layer-shell-unstable-v1.xml for details.
*
* Default is 0
*/
Expand Down
21 changes: 19 additions & 2 deletions protocol/wlr-layer-shell-unstable-v1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
THIS SOFTWARE.
</copyright>

<interface name="zwlr_layer_shell_v1" version="4">
<interface name="zwlr_layer_shell_v1" version="5">
<description summary="create surfaces that are layers of the desktop">
Clients can use this interface to assign the surface_layer role to
wl_surfaces. Such surfaces are assigned to a "layer" of the output and
Expand Down Expand Up @@ -100,7 +100,7 @@
</request>
</interface>

<interface name="zwlr_layer_surface_v1" version="4">
<interface name="zwlr_layer_surface_v1" version="5">
<description summary="layer metadata interface">
An interface that may be implemented by a wl_surface, for surfaces that
are designed to be rendered as a layer of a stacked desktop-like
Expand Down Expand Up @@ -367,6 +367,7 @@
<entry name="invalid_size" value="1" summary="size is invalid"/>
<entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
<entry name="invalid_keyboard_interactivity" value="3" summary="keyboard interactivity is invalid"/>
<entry name="invalid_exclusive_edge" value="4" summary="exclusive edge is invalid given the surface anchors"/>
</enum>

<enum name="anchor" bitfield="true">
Expand All @@ -386,5 +387,21 @@
</description>
<arg name="layer" type="uint" enum="zwlr_layer_shell_v1.layer" summary="layer to move this surface to"/>
</request>

<!-- Version 5 additions -->

<request name="set_exclusive_edge" since="5">
<description summary="set the edge the exclusive zone will be applied to">
Requests an edge for the exclusive zone to apply. The exclusive
edge will be automatically deduced from anchor points when possible,
but when the surface is anchored to a corner, it will be necessary
to set it explicitly to disambiguate, as it is not possible to deduce
which one of the two corner edges should be used.

The edge must be one the surface is anchored to, otherwise the
invalid_exclusive_edge protocol error will be raised.
</description>
<arg name="edge" type="uint" enum="anchor"/>
</request>
</interface>
</protocol>
27 changes: 27 additions & 0 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@ gtk_layer_get_margin (GtkWindow *window, GtkLayerShellEdge edge)
return layer_surface->margins[edge];
}

void
gtk_layer_set_exclusive_edge (GtkWindow *window, int exclusive_edge)
{
LayerSurface *layer_surface = gtk_window_get_layer_surface (window);
if (!layer_surface) return; // Error message already shown in gtk_window_get_layer_surface
int wlr_anchor;
switch (exclusive_edge)
{
case GTK_LAYER_SHELL_EDGE_LEFT:
wlr_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
break;
case GTK_LAYER_SHELL_EDGE_RIGHT:
wlr_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
break;
case GTK_LAYER_SHELL_EDGE_TOP:
wlr_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
break;
case GTK_LAYER_SHELL_EDGE_BOTTOM:
wlr_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
break;
default:
g_critical ("Invalid exclusive edge %d", exclusive_edge);
return;
}
layer_surface_set_exclusive_edge (layer_surface, wlr_anchor);
}

void
gtk_layer_set_exclusive_zone (GtkWindow *window, int exclusive_zone)
{
Expand Down
26 changes: 26 additions & 0 deletions src/layer-surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ layer_surface_map (CustomShellSurface *super, struct wl_surface *wl_surface)
zwlr_layer_surface_v1_set_exclusive_zone (self->layer_surface, self->exclusive_zone);
layer_surface_send_set_anchor (self);
layer_surface_send_set_margin (self);

uint32_t version = zwlr_layer_surface_v1_get_version (self->layer_surface);
if (version >= ZWLR_LAYER_SURFACE_V1_SET_EXCLUSIVE_EDGE_SINCE_VERSION) {
zwlr_layer_surface_v1_set_exclusive_edge (self->layer_surface, self->exclusive_edge);
}

if (self->cached_layer_size.width >= 0 && self->cached_layer_size.height >= 0) {
zwlr_layer_surface_v1_set_size (self->layer_surface,
self->cached_layer_size.width,
Expand Down Expand Up @@ -316,6 +322,7 @@ layer_surface_new (GtkWindow *gtk_window)
self->monitor = NULL;
self->layer = GTK_LAYER_SHELL_LAYER_TOP;
self->name_space = NULL;
self->exclusive_edge = 0;
self->exclusive_zone = 0;
self->auto_exclusive_zone = FALSE;
self->keyboard_mode = GTK_LAYER_SHELL_KEYBOARD_MODE_NONE;
Expand Down Expand Up @@ -406,6 +413,25 @@ layer_surface_set_margin (LayerSurface *self, GtkLayerShellEdge edge, int margin
}
}

void
layer_surface_set_exclusive_edge (LayerSurface *self, int exclusive_edge)
{
if (self->exclusive_edge != exclusive_edge) {
self->exclusive_edge = exclusive_edge;
if (self->layer_surface) {
uint32_t version = zwlr_layer_surface_v1_get_version (self->layer_surface);
if (version >= ZWLR_LAYER_SURFACE_V1_SET_EXCLUSIVE_EDGE_SINCE_VERSION) {
zwlr_layer_surface_v1_set_exclusive_edge (self->layer_surface, self->exclusive_edge);
custom_shell_surface_needs_commit ((CustomShellSurface *)self);
} else {
g_warning (
"Compositor uses layer shell version %d, which does not support exclusive edge",
version);
}
}
}
}

void
layer_surface_set_exclusive_zone (LayerSurface *self, int exclusive_zone)
{
Expand Down
2 changes: 2 additions & 0 deletions src/layer-surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct _LayerSurface
// Can be set at any time
gboolean anchors[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]; // The current anchor
int margins[GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER]; // The current margins
int exclusive_edge; // The current exclusive edge
int exclusive_zone; // The current exclusive zone (set either explicitly or automatically)
gboolean auto_exclusive_zone; // If to automatically change the exclusive zone to match the window size
GtkLayerShellKeyboardMode keyboard_mode; // Type of keyboard interactivity enabled for this surface
Expand Down Expand Up @@ -58,6 +59,7 @@ void layer_surface_set_name_space (LayerSurface *self, char const* name_space);
void layer_surface_set_layer (LayerSurface *self, GtkLayerShellLayer layer); // Remaps surface on old layer shell versions
void layer_surface_set_anchor (LayerSurface *self, GtkLayerShellEdge edge, gboolean anchor_to_edge);
void layer_surface_set_margin (LayerSurface *self, GtkLayerShellEdge edge, int margin_size);
void layer_surface_set_exclusive_edge (LayerSurface *self, int exclusive_edge);
void layer_surface_set_exclusive_zone (LayerSurface *self, int exclusive_zone);
void layer_surface_auto_exclusive_zone_enable (LayerSurface *self);
void layer_surface_set_keyboard_mode (LayerSurface *self, GtkLayerShellKeyboardMode mode);
Expand Down
Loading