Support desktop shell panels in compositor
This commit is contained in:
parent
60e76cf932
commit
e59cffcea2
|
@ -1,6 +1,7 @@
|
||||||
#ifndef _SWAY_EXTENSIONS_H
|
#ifndef _SWAY_EXTENSIONS_H
|
||||||
#define _SWAY_EXTENSIONS_H
|
#define _SWAY_EXTENSIONS_H
|
||||||
|
|
||||||
|
#include "wayland-desktop-shell-server-protocol.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "wlc/wlc-wayland.h"
|
#include "wlc/wlc-wayland.h"
|
||||||
|
|
||||||
|
@ -9,8 +10,16 @@ struct background_config {
|
||||||
wlc_resource surface;
|
wlc_resource surface;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct panel_config {
|
||||||
|
wlc_handle output;
|
||||||
|
wlc_resource surface;
|
||||||
|
};
|
||||||
|
|
||||||
struct desktop_shell_state {
|
struct desktop_shell_state {
|
||||||
list_t *backgrounds;
|
list_t *backgrounds;
|
||||||
|
list_t *panels;
|
||||||
|
enum desktop_shell_panel_position panel_position;
|
||||||
|
struct wlc_size panel_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct desktop_shell_state desktop_shell;
|
extern struct desktop_shell_state desktop_shell;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <wlc/wlc.h>
|
#include <wlc/wlc.h>
|
||||||
#include <wlc/wlc-wayland.h>
|
#include <wlc/wlc-wayland.h>
|
||||||
#include "wayland-desktop-shell-server-protocol.h"
|
#include "wayland-desktop-shell-server-protocol.h"
|
||||||
|
#include "layout.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "extensions.h"
|
#include "extensions.h"
|
||||||
|
|
||||||
|
@ -20,13 +21,55 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc
|
||||||
list_add(desktop_shell.backgrounds, config);
|
list_add(desktop_shell.backgrounds, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_panel(struct wl_client *client, struct wl_resource *resource,
|
||||||
|
struct wl_resource *_output, struct wl_resource *surface) {
|
||||||
|
wlc_handle output = wlc_handle_from_wl_output_resource(_output);
|
||||||
|
if (!output) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sway_log(L_DEBUG, "Setting surface %p as panel for output %d", surface, (int)output);
|
||||||
|
struct panel_config *config = malloc(sizeof(struct panel_config));
|
||||||
|
config->output = output;
|
||||||
|
config->surface = wlc_resource_from_wl_surface_resource(surface);
|
||||||
|
list_add(desktop_shell.panels, config);
|
||||||
|
desktop_shell.panel_size = *wlc_surface_get_size(config->surface);
|
||||||
|
arrange_windows(&root_container, -1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_lock_surface(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface) {
|
||||||
|
sway_log(L_ERROR, "desktop_set_lock_surface is not currently supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unlock(struct wl_client *client, struct wl_resource *resource) {
|
||||||
|
sway_log(L_ERROR, "desktop_unlock is not currently supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_grab_surface(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface) {
|
||||||
|
sway_log(L_ERROR, "desktop_set_grab_surface is not currently supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void desktop_ready(struct wl_client *client, struct wl_resource *resource) {
|
||||||
|
// nop
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_panel_position(struct wl_client *client, struct wl_resource *resource, uint32_t position) {
|
||||||
|
desktop_shell.panel_position = position;
|
||||||
|
arrange_windows(&root_container, -1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
static struct desktop_shell_interface desktop_shell_implementation = {
|
static struct desktop_shell_interface desktop_shell_implementation = {
|
||||||
.set_background = set_background
|
.set_background = set_background,
|
||||||
|
.set_panel = set_panel,
|
||||||
|
.set_lock_surface = set_lock_surface,
|
||||||
|
.unlock = unlock,
|
||||||
|
.set_grab_surface = set_grab_surface,
|
||||||
|
.desktop_ready = desktop_ready,
|
||||||
|
.set_panel_position = set_panel_position
|
||||||
};
|
};
|
||||||
|
|
||||||
static void desktop_shell_bind(struct wl_client *client, void *data,
|
static void desktop_shell_bind(struct wl_client *client, void *data,
|
||||||
unsigned int version, unsigned int id) {
|
unsigned int version, unsigned int id) {
|
||||||
if (version > 1) {
|
if (version > 3) {
|
||||||
// Unsupported version
|
// Unsupported version
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +83,8 @@ static void desktop_shell_bind(struct wl_client *client, void *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_extensions(void) {
|
void register_extensions(void) {
|
||||||
wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 1, NULL, desktop_shell_bind);
|
wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind);
|
||||||
desktop_shell.backgrounds = create_list();
|
desktop_shell.backgrounds = create_list();
|
||||||
|
desktop_shell.panels = create_list();
|
||||||
|
desktop_shell.panel_position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,11 +72,43 @@ static void handle_output_destroyed(wlc_handle output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_output_pre_render(wlc_handle output) {
|
static void handle_output_pre_render(wlc_handle output) {
|
||||||
|
struct wlc_size resolution = *wlc_output_get_resolution(output);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < desktop_shell.backgrounds->length; ++i) {
|
for (i = 0; i < desktop_shell.backgrounds->length; ++i) {
|
||||||
struct background_config *config = desktop_shell.backgrounds->items[i];
|
struct background_config *config = desktop_shell.backgrounds->items[i];
|
||||||
if (config->output == output) {
|
if (config->output == output) {
|
||||||
wlc_surface_render(config->surface, &(struct wlc_geometry){ wlc_origin_zero, *wlc_output_get_resolution(output) });
|
wlc_surface_render(config->surface, &(struct wlc_geometry){ wlc_origin_zero, resolution });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < desktop_shell.panels->length; ++i) {
|
||||||
|
struct panel_config *config = desktop_shell.panels->items[i];
|
||||||
|
if (config->output == output) {
|
||||||
|
struct wlc_size size = *wlc_surface_get_size(config->surface);
|
||||||
|
struct wlc_geometry geo = {
|
||||||
|
.size = size
|
||||||
|
};
|
||||||
|
switch (desktop_shell.panel_position) {
|
||||||
|
case DESKTOP_SHELL_PANEL_POSITION_TOP:
|
||||||
|
geo.origin = (struct wlc_origin){ 0, 0 };
|
||||||
|
break;
|
||||||
|
case DESKTOP_SHELL_PANEL_POSITION_BOTTOM:
|
||||||
|
geo.origin = (struct wlc_origin){ 0, resolution.h - size.h };
|
||||||
|
break;
|
||||||
|
case DESKTOP_SHELL_PANEL_POSITION_LEFT:
|
||||||
|
geo.origin = (struct wlc_origin){ 0, 0 };
|
||||||
|
break;
|
||||||
|
case DESKTOP_SHELL_PANEL_POSITION_RIGHT:
|
||||||
|
geo.origin = (struct wlc_origin){ resolution.w - size.w, 0 };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wlc_surface_render(config->surface, &geo);
|
||||||
|
if (size.w != desktop_shell.panel_size.w || size.h != desktop_shell.panel_size.h) {
|
||||||
|
desktop_shell.panel_size = size;
|
||||||
|
arrange_windows(&root_container, -1, -1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <wlc/wlc.h>
|
#include <wlc/wlc.h>
|
||||||
|
#include "extensions.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
@ -426,6 +427,27 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case C_OUTPUT:
|
case C_OUTPUT:
|
||||||
|
for (i = 0; i < desktop_shell.panels->length; ++i) {
|
||||||
|
struct panel_config *config = desktop_shell.panels->items[i];
|
||||||
|
if (config->output == container->handle) {
|
||||||
|
struct wlc_size size = *wlc_surface_get_size(config->surface);
|
||||||
|
switch (desktop_shell.panel_position) {
|
||||||
|
case DESKTOP_SHELL_PANEL_POSITION_TOP:
|
||||||
|
y += size.h; height -= size.h;
|
||||||
|
break;
|
||||||
|
case DESKTOP_SHELL_PANEL_POSITION_BOTTOM:
|
||||||
|
height -= size.h;
|
||||||
|
break;
|
||||||
|
case DESKTOP_SHELL_PANEL_POSITION_LEFT:
|
||||||
|
x += size.w; width -= size.w;
|
||||||
|
break;
|
||||||
|
case DESKTOP_SHELL_PANEL_POSITION_RIGHT:
|
||||||
|
width -= size.w;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
container->width = width;
|
container->width = width;
|
||||||
container->height = height;
|
container->height = height;
|
||||||
x = 0, y = 0;
|
x = 0, y = 0;
|
||||||
|
|
|
@ -25,34 +25,34 @@ struct colors {
|
||||||
struct registry *registry;
|
struct registry *registry;
|
||||||
struct window *window;
|
struct window *window;
|
||||||
struct colors colors = {
|
struct colors colors = {
|
||||||
.background = 0x00000000,
|
.background = 0x000000FF,
|
||||||
.statusline = 0xffffffff,
|
.statusline = 0xFFFFFFFF,
|
||||||
.seperator = 0x666666ff,
|
.seperator = 0x666666FF,
|
||||||
|
|
||||||
.focused_workspace = {
|
.focused_workspace = {
|
||||||
.border = 0x4c7899ff,
|
.border = 0x4C7899FF,
|
||||||
.background = 0x285577ff,
|
.background = 0x285577FF,
|
||||||
.text = 0xffffffff
|
.text = 0xFFFFFFFF
|
||||||
},
|
},
|
||||||
.active_workspace = {
|
.active_workspace = {
|
||||||
.border = 0x333333ff,
|
.border = 0x333333FF,
|
||||||
.background = 0x5f676aff,
|
.background = 0x5F676AFF,
|
||||||
.text = 0xffffffff
|
.text = 0xFFFFFFFF
|
||||||
},
|
},
|
||||||
.inactive_workspace = {
|
.inactive_workspace = {
|
||||||
.border = 0x333333ff,
|
.border = 0x333333FF,
|
||||||
.background = 0x222222ff,
|
.background = 0x222222FF,
|
||||||
.text = 0x888888ff
|
.text = 0x888888FF
|
||||||
},
|
},
|
||||||
.urgent_workspace = {
|
.urgent_workspace = {
|
||||||
.border = 0x2f343aff,
|
.border = 0x2F343AFF,
|
||||||
.background = 0x900000ff,
|
.background = 0x900000FF,
|
||||||
.text = 0xffffffff
|
.text = 0xFFFFFFFF
|
||||||
},
|
},
|
||||||
.binding_mode = {
|
.binding_mode = {
|
||||||
.border = 0x2f343aff,
|
.border = 0x2F343AFF,
|
||||||
.background = 0x900000ff,
|
.background = 0x900000FF,
|
||||||
.text = 0xffffffff
|
.text = 0xFFFFFFFF
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue