mirror of
https://github.com/swaywm/sway.git
synced 2024-11-13 05:54:11 +01:00
Turn swaybg into a shell surface
This commit is contained in:
parent
c8917395c0
commit
6d971af5c3
@ -11,6 +11,8 @@ struct background_config {
|
|||||||
wlc_resource surface;
|
wlc_resource surface;
|
||||||
// we need the wl_resource of the surface in the destructor
|
// we need the wl_resource of the surface in the destructor
|
||||||
struct wl_resource *wl_surface_res;
|
struct wl_resource *wl_surface_res;
|
||||||
|
struct wl_client *client;
|
||||||
|
wlc_handle handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct panel_config {
|
struct panel_config {
|
||||||
|
@ -904,7 +904,6 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (oc && oc->background) {
|
if (oc && oc->background) {
|
||||||
|
|
||||||
if (output->bg_pid != 0) {
|
if (output->bg_pid != 0) {
|
||||||
terminate_swaybg(output->bg_pid);
|
terminate_swaybg(output->bg_pid);
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,7 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc
|
|||||||
}
|
}
|
||||||
sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output);
|
sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output);
|
||||||
struct background_config *config = malloc(sizeof(struct background_config));
|
struct background_config *config = malloc(sizeof(struct background_config));
|
||||||
|
config->client = client;
|
||||||
config->output = output;
|
config->output = output;
|
||||||
config->surface = wlc_resource_from_wl_surface_resource(surface);
|
config->surface = wlc_resource_from_wl_surface_resource(surface);
|
||||||
config->wl_surface_res = surface;
|
config->wl_surface_res = surface;
|
||||||
|
@ -44,6 +44,17 @@ static struct panel_config *if_panel_find_config(struct wl_client *client) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct background_config *if_background_find_config(struct wl_client *client) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < desktop_shell.backgrounds->length; i++) {
|
||||||
|
struct background_config *config = desktop_shell.backgrounds->items[i];
|
||||||
|
if (config->client == client) {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static struct wlc_geometry compute_panel_geometry(struct panel_config *config) {
|
static struct wlc_geometry compute_panel_geometry(struct panel_config *config) {
|
||||||
const struct wlc_size resolution = *wlc_output_get_resolution(config->output);
|
const struct wlc_size resolution = *wlc_output_get_resolution(config->output);
|
||||||
const struct wlc_geometry *old = wlc_view_get_geometry(config->handle);
|
const struct wlc_geometry *old = wlc_view_get_geometry(config->handle);
|
||||||
@ -93,6 +104,21 @@ static void update_panel_geometries(wlc_handle output) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void update_background_geometry(struct background_config *config) {
|
||||||
|
struct wlc_geometry geometry = { 0 };
|
||||||
|
geometry.size = *wlc_output_get_resolution(config->output);
|
||||||
|
wlc_view_set_geometry(config->handle, 0, &geometry);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void update_background_geometries(wlc_handle output) {
|
||||||
|
for (int i = 0; i < desktop_shell.backgrounds->length; i++) {
|
||||||
|
struct background_config *config = desktop_shell.backgrounds->items[i];
|
||||||
|
if (config->output == output) {
|
||||||
|
update_background_geometry(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Handles */
|
/* Handles */
|
||||||
|
|
||||||
static bool handle_input_created(struct libinput_device *device) {
|
static bool handle_input_created(struct libinput_device *device) {
|
||||||
@ -168,19 +194,6 @@ static void handle_output_destroyed(wlc_handle output) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_output_pre_render(wlc_handle output) {
|
|
||||||
struct wlc_size resolution = *wlc_output_get_resolution(output);
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < desktop_shell.backgrounds->length; ++i) {
|
|
||||||
struct background_config *config = desktop_shell.backgrounds->items[i];
|
|
||||||
if (config->output == output) {
|
|
||||||
wlc_surface_render(config->surface, &(struct wlc_geometry){ wlc_origin_zero, resolution });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handle_output_post_render(wlc_handle output) {
|
static void handle_output_post_render(wlc_handle output) {
|
||||||
ipc_get_pixels(output);
|
ipc_get_pixels(output);
|
||||||
arrange_windows(swayc_by_handle(output), -1, -1);
|
arrange_windows(swayc_by_handle(output), -1, -1);
|
||||||
@ -201,6 +214,7 @@ static void handle_output_resolution_change(wlc_handle output, const struct wlc_
|
|||||||
c->height = to->h;
|
c->height = to->h;
|
||||||
|
|
||||||
update_panel_geometries(output);
|
update_panel_geometries(output);
|
||||||
|
update_background_geometries(output);
|
||||||
|
|
||||||
arrange_windows(&root_container, -1, -1);
|
arrange_windows(&root_container, -1, -1);
|
||||||
}
|
}
|
||||||
@ -247,6 +261,7 @@ static bool handle_view_created(wlc_handle handle) {
|
|||||||
struct wl_client *client = wlc_view_get_wl_client(handle);
|
struct wl_client *client = wlc_view_get_wl_client(handle);
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
struct panel_config *panel_config = NULL;
|
struct panel_config *panel_config = NULL;
|
||||||
|
struct background_config *background_config = NULL;
|
||||||
|
|
||||||
panel_config = if_panel_find_config(client);
|
panel_config = if_panel_find_config(client);
|
||||||
if (panel_config) {
|
if (panel_config) {
|
||||||
@ -254,6 +269,17 @@ static bool handle_view_created(wlc_handle handle) {
|
|||||||
update_panel_geometry(panel_config);
|
update_panel_geometry(panel_config);
|
||||||
wlc_view_set_mask(handle, VISIBLE);
|
wlc_view_set_mask(handle, VISIBLE);
|
||||||
wlc_view_set_output(handle, panel_config->output);
|
wlc_view_set_output(handle, panel_config->output);
|
||||||
|
wlc_view_bring_to_front(handle);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
background_config = if_background_find_config(client);
|
||||||
|
if (background_config) {
|
||||||
|
background_config->handle = handle;
|
||||||
|
update_background_geometry(background_config);
|
||||||
|
wlc_view_set_mask(handle, VISIBLE);
|
||||||
|
wlc_view_set_output(handle, background_config->output);
|
||||||
|
wlc_view_send_to_back(handle);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -883,7 +909,6 @@ void register_wlc_handlers() {
|
|||||||
wlc_set_output_destroyed_cb(handle_output_destroyed);
|
wlc_set_output_destroyed_cb(handle_output_destroyed);
|
||||||
wlc_set_output_resolution_cb(handle_output_resolution_change);
|
wlc_set_output_resolution_cb(handle_output_resolution_change);
|
||||||
wlc_set_output_focus_cb(handle_output_focused);
|
wlc_set_output_focus_cb(handle_output_focused);
|
||||||
wlc_set_output_render_pre_cb(handle_output_pre_render);
|
|
||||||
wlc_set_output_render_post_cb(handle_output_post_render);
|
wlc_set_output_render_post_cb(handle_output_post_render);
|
||||||
wlc_set_view_created_cb(handle_view_created);
|
wlc_set_view_created_cb(handle_view_created);
|
||||||
wlc_set_view_destroyed_cb(handle_view_destroyed);
|
wlc_set_view_destroyed_cb(handle_view_destroyed);
|
||||||
|
@ -54,6 +54,7 @@ int main(int argc, const char **argv) {
|
|||||||
sway_abort("Failed to create surfaces.");
|
sway_abort("Failed to create surfaces.");
|
||||||
}
|
}
|
||||||
desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
|
desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
|
||||||
|
window_make_shell(window);
|
||||||
list_add(surfaces, window);
|
list_add(surfaces, window);
|
||||||
|
|
||||||
#ifdef WITH_GDK_PIXBUF
|
#ifdef WITH_GDK_PIXBUF
|
||||||
|
Loading…
Reference in New Issue
Block a user