Commit ec909bdf authored by Guido Gunther's avatar Guido Gunther
Browse files

Merge branch 'phosh-private-cleanup' into 'f/phosh-private'

Phosh private cleanup

See merge request Librem5/wlroots!14
parents d825a8f1 1d70192b
......@@ -5,10 +5,12 @@
struct phosh {
struct wl_resource* resource;
struct wl_display* display;
struct wl_global *global;
struct roots_desktop *desktop;
struct wl_listener layer_shell_surface;
struct {
struct wl_listener layer_shell_new_surface;
struct wl_listener panel_surface_destroy;
} listeners;
struct wlr_layer_surface *panel;
};
......
......@@ -888,6 +888,7 @@ struct roots_desktop *desktop_create(struct roots_server *server,
void desktop_destroy(struct roots_desktop *desktop) {
phosh_destroy(desktop->phosh);
desktop->phosh = NULL;
}
struct roots_output *desktop_output_from_wlr_output(
......
#define _POSIX_C_SOURCE 200112L
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <wayland-server.h>
#include <wlr/config.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/log.h>
#include <phosh-mobile-shell-protocol.h>
#include "rootston/config.h"
#include "rootston/server.h"
#include "rootston/desktop.h"
#include "rootston/desktop-shell.h"
#if 0
static void
recalc_output_box (struct mobile_shell *shell)
{
struct wlr_surface_state *state = shell->panel.wlr_surface->current;
const struct wlr_box *output_box =
wlr_output_layout_get_box(shell->desktop->layout, shell->panel.output);
memcpy(&shell->panel.output_box, output_box, sizeof(struct wlr_box));
wlr_trace ("x: %d, y: %d, width: %d, height: %d",
output_box->x,
output_box->y,
output_box->width,
output_box->height);
switch (shell->panel.position) {
case PHOSH_MOBILE_SHELL_PANEL_POSITION_TOP:
shell->panel.output_box.y += state->height;
shell->panel.output_box.height -= state->height;
break;
case PHOSH_MOBILE_SHELL_PANEL_POSITION_BOTTOM:
shell->panel.y = output_box->height - state->height;
shell->panel.output_box.height = output_box->height - state->height;
break;
case PHOSH_MOBILE_SHELL_PANEL_POSITION_LEFT:
shell->panel.output_box.x += state->width;
shell->panel.output_box.width -= state->width;
break;
case PHOSH_MOBILE_SHELL_PANEL_POSITION_RIGHT:
shell->panel.x = output_box->width - state->width;
shell->panel.output_box.width = output_box->width - state->width;
break;
}
wlr_trace ("x: %d, y: %d, width: %d, height: %d",
shell->panel.output_box.x,
shell->panel.output_box.y,
shell->panel.output_box.width,
shell->panel.output_box.height);
}
#endif
static void
mobile_shell_rotate_display(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *surface_resource,
uint32_t degrees)
{
struct mobile_shell *shell = wl_resource_get_user_data(resource);
enum wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
wlr_trace("rotation: %d", degrees);
if (degrees % 90 != 0)
wl_resource_post_error(resource,
PHOSH_MOBILE_SHELL_ERROR_INVALID_ARGUMENT,
"Can only rotate in 90 degree steps");
degrees %= 360;
switch (degrees) {
case 0:
transform = WL_OUTPUT_TRANSFORM_NORMAL;
break;
case 90:
transform = WL_OUTPUT_TRANSFORM_90;
break;
case 180:
transform = WL_OUTPUT_TRANSFORM_180;
break;
case 270:
transform = WL_OUTPUT_TRANSFORM_270;
break;
}
wlr_output_set_transform(shell->panel.output, transform);
const struct wlr_box *output_box =
wlr_output_layout_get_box(shell->desktop->layout,
shell->panel.output);
/* Tell the shell about the new size due to rotation */
phosh_mobile_shell_send_configure(resource, 0,
surface_resource,
output_box->width,
output_box->height);
recalc_output_box (shell);
/* Tell notify surfaces about their new size */
struct roots_view *view;
wl_list_for_each(view, &shell->desktop->views, link) {
if (view->maximized == true) {
view_move_resize(view,
shell->panel.output_box.x,
shell->panel.output_box.y,
shell->panel.output_box.width,
shell->panel.output_box.height);
}
}
}
static void
unbind_mobile_shell(struct wl_resource *resource)
{
struct mobile_shell *shell = wl_resource_get_user_data(resource);
mobile_shell_destroy (shell);
}
static const struct phosh_mobile_shell_interface mobile_shell_impl = {
mobile_shell_rotate_display,
};
static void
bind_mobile_shell(struct wl_client *client,
void *data, uint32_t version, uint32_t id)
{
struct mobile_shell *shell = data;
struct wl_resource *resource;
resource = wl_resource_create(client, &phosh_mobile_shell_interface,
1, id);
/* FIXME: unsafe needs client == shell->child.client */
if (true) {
wlr_log(L_ERROR, "FIXME: allowing every client to bind as desktop-shell");
wl_resource_set_implementation(resource,
&mobile_shell_impl,
shell, unbind_mobile_shell);
shell->resource = resource;
lockscreen_create(shell->desktop, shell->display);
return;
}
wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
"permission to bind mobile_shell denied");
}
struct mobile_shell*
mobile_shell_create(struct roots_desktop *desktop, struct wl_display *display)
{
struct mobile_shell *shell;
shell = calloc(1, sizeof (struct mobile_shell));
shell->desktop = desktop;
shell->display = display;
shell->ready = false;
shell->panel.position = PHOSH_MOBILE_SHELL_PANEL_POSITION_TOP;
shell->lock.locked = false;
wl_list_init(&shell->menus);
desktop->mobile_shell = shell;
wlr_log(L_INFO, "Initializing desktop shell");
if (wl_global_create(display,
&phosh_mobile_shell_interface, 1,
shell , bind_mobile_shell) == NULL)
return NULL;
return shell;
}
......@@ -12,7 +12,7 @@
#include "rootston/desktop.h"
#include "rootston/phosh.h"
static void phosh_rotate_display(struct wl_client *client,
static void phosh_rotate_output(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *surface_resource,
uint32_t degrees)
......@@ -20,7 +20,7 @@ static void phosh_rotate_display(struct wl_client *client,
struct phosh *shell = wl_resource_get_user_data(resource);
enum wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
wlr_trace("rotation: %d", degrees);
wlr_log(WLR_DEBUG, "rotation: %d", degrees);
if (degrees % 90 != 0) {
wl_resource_post_error(resource,
PHOSH_PRIVATE_ERROR_INVALID_ARGUMENT,
......@@ -43,66 +43,73 @@ static void phosh_rotate_display(struct wl_client *client,
break;
}
wlr_output_set_transform(shell->panel->output, transform);
const struct wlr_box *output_box =
wlr_output_layout_get_box(shell->desktop->layout,
shell->panel->output);
/* Notify surfaces about their new size */
struct roots_view *view;
wl_list_for_each(view, &shell->desktop->views, link) {
if (view->maximized == true) {
view_move_resize(view,
output_box->x,
output_box->y,
output_box->width,
output_box->height);
}
if (!shell->panel) {
wlr_log(WLR_ERROR, "Tried to rotate inexistent panel");
return;
}
wlr_output_set_transform(shell->panel->output, transform);
}
static void handle_phosh_layer_shell_surface(struct wl_listener *listener, void *data) {
struct wlr_layer_surface *surface = data;
static void handle_phosh_panel_surface_destroy (struct wl_listener *listener, void *data) {
struct phosh *phosh =
wl_container_of(listener, phosh, layer_shell_surface);
wl_container_of(listener, phosh, listeners.panel_surface_destroy);
if (!strcmp(surface->namespace, "phosh")) {
phosh->panel = surface;
if (phosh->panel) {
phosh->panel = NULL;
wl_list_remove(&phosh->listeners.panel_surface_destroy.link);
}
}
void phosh_destroy(struct phosh *shell) {
shell->resource = NULL;
wl_list_remove(&shell->layer_shell_surface.link);
static void handle_phosh_layer_shell_new_surface(struct wl_listener *listener, void *data) {
struct wlr_layer_surface *surface = data;
struct phosh *phosh =
wl_container_of(listener, phosh, listeners.layer_shell_new_surface);
/* We're only interested in the panel */
if (strcmp(surface->namespace, "phosh"))
return;
phosh->panel = surface;
wl_signal_add(&surface->events.destroy,
&phosh->listeners.panel_surface_destroy);
phosh->listeners.panel_surface_destroy.notify = handle_phosh_panel_surface_destroy;
}
static void unbind_phosh(struct wl_resource *resource) {
struct phosh *shell = wl_resource_get_user_data(resource);
phosh_destroy (shell);
static void phosh_resource_destroy(struct wl_resource *resource) {
struct phosh *phosh = wl_resource_get_user_data(resource);
phosh->resource = NULL;
phosh->panel = NULL;
}
static const struct phosh_private_interface phosh_impl = {
phosh_rotate_display,
phosh_rotate_output,
};
static void
bind_phosh(struct wl_client *client, void *data, uint32_t version, uint32_t id) {
struct phosh *shell = data;
struct phosh *phosh = data;
struct wl_resource *resource = wl_resource_create(client, &phosh_private_interface,
1, id);
if (phosh->resource) {
wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
"Only a single client can bind to phosh's private protocol");
}
/* FIXME: unsafe needs client == shell->child.client */
if (true) {
wlr_log(L_ERROR, "FIXME: allowing every client to bind as phosh");
wlr_log(WLR_ERROR, "FIXME: allowing every client to bind as phosh");
wl_resource_set_implementation(resource,
&phosh_impl,
shell, unbind_phosh);
shell->resource = resource;
phosh, phosh_resource_destroy);
phosh->resource = resource;
return;
}
......@@ -113,22 +120,27 @@ bind_phosh(struct wl_client *client, void *data, uint32_t version, uint32_t id)
struct phosh*
phosh_create(struct roots_desktop *desktop, struct wl_display *display) {
struct phosh *shell;
shell = calloc(1, sizeof (struct phosh));
struct phosh *shell = calloc(1, sizeof (struct phosh));
if (!shell)
return NULL;
shell->desktop = desktop;
shell->display = display;
wl_signal_add(&desktop->layer_shell->events.new_surface,
&shell->layer_shell_surface);
shell->layer_shell_surface.notify = handle_phosh_layer_shell_surface;
desktop->phosh = shell;
&shell->listeners.layer_shell_new_surface);
shell->listeners.layer_shell_new_surface.notify = handle_phosh_layer_shell_new_surface;
wlr_log(L_INFO, "Initializing mobile shell");
if (wl_global_create(display, &phosh_private_interface, 1, shell , bind_phosh) == NULL) {
wlr_log(WLR_INFO, "Initializing phosh private inrerface");
shell->global = wl_global_create(display, &phosh_private_interface, 1, shell, bind_phosh);
if (!shell->global) {
return NULL;
}
return shell;
}
void phosh_destroy(struct phosh *shell) {
wl_list_remove(&shell->listeners.layer_shell_new_surface.link);
wl_global_destroy(shell->global);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment