Added layer_shell_surfaces to get_output in swayipc

This commit is contained in:
Erik Reider 2023-04-22 13:01:10 +02:00
parent 1030f08b06
commit 63c7e95332
2 changed files with 77 additions and 3 deletions

View file

@ -10,6 +10,7 @@
#include "log.h" #include "log.h"
#include "sway/config.h" #include "sway/config.h"
#include "sway/ipc-json.h" #include "sway/ipc-json.h"
#include "sway/layers.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
#include "sway/tree/workspace.h" #include "sway/tree/workspace.h"
@ -273,7 +274,8 @@ static json_object *ipc_json_create_node(int id, const char* type, char *name,
return object; return object;
} }
static void ipc_json_describe_wlr_output(struct wlr_output *wlr_output, json_object *object) { static void ipc_json_describe_wlr_output(struct wlr_output *wlr_output,
struct sway_output *output, json_object *object) {
json_object_object_add(object, "primary", json_object_new_boolean(false)); json_object_object_add(object, "primary", json_object_new_boolean(false));
json_object_object_add(object, "make", json_object_object_add(object, "make",
json_object_new_string(wlr_output->make ? wlr_output->make : "Unknown")); json_object_new_string(wlr_output->make ? wlr_output->make : "Unknown"));
@ -299,7 +301,7 @@ static void ipc_json_describe_wlr_output(struct wlr_output *wlr_output, json_obj
static void ipc_json_describe_output(struct sway_output *output, static void ipc_json_describe_output(struct sway_output *output,
json_object *object) { json_object *object) {
ipc_json_describe_wlr_output(output->wlr_output, object); ipc_json_describe_wlr_output(output->wlr_output, output, object);
} }
static void ipc_json_describe_enabled_output(struct sway_output *output, static void ipc_json_describe_enabled_output(struct sway_output *output,
@ -331,6 +333,51 @@ static void ipc_json_describe_enabled_output(struct sway_output *output,
json_object_object_add(object, "adaptive_sync_status", json_object_object_add(object, "adaptive_sync_status",
json_object_new_string(adaptive_sync_status)); json_object_new_string(adaptive_sync_status));
struct json_object *layers = json_object_new_array();
size_t len = sizeof(output->layers) / sizeof(output->layers[0]);
for (size_t i = 0; i < len; ++i) {
struct sway_layer_surface *lsurface;
wl_list_for_each(lsurface, &output->layers[i], link) {
json_object *layer = json_object_new_object();
json_object_object_add(layer, "namespace",
json_object_new_string(lsurface->layer_surface->namespace));
char *layer_name;
switch (lsurface->layer) {
case ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND:
layer_name = "background";
break;
case ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM:
layer_name = "bottom";
break;
case ZWLR_LAYER_SHELL_V1_LAYER_TOP:
layer_name = "top";
break;
case ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY:
layer_name = "overlay";
break;
}
json_object_object_add(layer, "layer",
json_object_new_string(layer_name));
json_object *extent = json_object_new_object();
json_object_object_add(extent, "width",
json_object_new_int(lsurface->extent.width));
json_object_object_add(extent, "height",
json_object_new_int(lsurface->extent.height));
json_object_object_add(extent, "x",
json_object_new_int(lsurface->extent.x));
json_object_object_add(extent, "y",
json_object_new_int(lsurface->extent.y));
json_object_object_add(layer, "extent", extent);
json_object_array_add(layers, layer);
}
}
json_object_object_add(object, "layer_shell_surfaces", layers);
struct sway_workspace *ws = output_get_active_workspace(output); struct sway_workspace *ws = output_get_active_workspace(output);
if (!sway_assert(ws, "Expected output to have a workspace")) { if (!sway_assert(ws, "Expected output to have a workspace")) {
return; return;
@ -413,7 +460,7 @@ json_object *ipc_json_describe_non_desktop_output(struct sway_output_non_desktop
json_object *object = json_object_new_object(); json_object *object = json_object_new_object();
ipc_json_describe_wlr_output(wlr_output, object); ipc_json_describe_wlr_output(wlr_output, NULL, object);
json_object_object_add(object, "non_desktop", json_object_new_boolean(true)); json_object_object_add(object, "non_desktop", json_object_new_boolean(true));
json_object_object_add(object, "type", json_object_new_string("output")); json_object_object_add(object, "type", json_object_new_string("output"));

View file

@ -230,6 +230,11 @@ following properties:
: string : string
: The transform currently in use for the output. This can be _normal_, _90_, : The transform currently in use for the output. This can be _normal_, _90_,
_180_, _270_, _flipped-90_, _flipped-180_, or _flipped-270_ _180_, _270_, _flipped-90_, _flipped-180_, or _flipped-270_
|- layer_shell_surfaces
: array
: An array of all layer-shell surfaces attached to the output. Each object
contains _namespace_, _layer_, and _extent_ object that contains _x_, _y_
_width_, and _height_
|- current_workspace |- current_workspace
: string : string
: The workspace currently visible on the output or _null_ for disabled outputs : The workspace currently visible on the output or _null_ for disabled outputs
@ -259,6 +264,28 @@ following properties:
"scale": 1.0, "scale": 1.0,
"subpixel_hinting": "rgb", "subpixel_hinting": "rgb",
"transform": "normal", "transform": "normal",
"layer_shell_surfaces": [
{
"namespace": "wallpaper",
"layer": "background",
"extent": {
"width": 2560,
"height": 1440,
"x": 0,
"y": 0
}
},
{
"namespace": "waybar",
"layer": "top",
"extent": {
"width": 2548,
"height": 31,
"x": 6,
"y": 6
}
}
],
"current_workspace": "1", "current_workspace": "1",
"modes": [ "modes": [
{ {