From 0f6aa8fab6962d78a74b152ff37dff592fee88d3 Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Sun, 23 Feb 2014 10:34:40 +0100 Subject: [PATCH] server: Center overlays considering the available space Closes #76 --- src/server/wl_hawaii/desktop-shell.cpp | 27 +++++++++++++++++++++++++- src/server/wl_hawaii/desktop-shell.h | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/server/wl_hawaii/desktop-shell.cpp b/src/server/wl_hawaii/desktop-shell.cpp index 769ae187..c1760457 100644 --- a/src/server/wl_hawaii/desktop-shell.cpp +++ b/src/server/wl_hawaii/desktop-shell.cpp @@ -1026,6 +1026,30 @@ void DesktopShell::lockSurfaceDestroy(void *) m_lockSurface = nullptr; } +void DesktopShell::configureViewForAvailableSpace(weston_view *ev, Layer *layer) +{ + for (Output o: m_outputs) { + if (o.output == ev->output) { + weston_view_set_position(ev, o.rect.x, o.rect.y); + configure_static_view_no_position(ev, layer); + return; + } + } +} + +void DesktopShell::centerViewOnAvailableSpace(weston_view *ev) +{ + for (Output o: m_outputs) { + if (o.output == ev->output) { + float x = o.rect.x + (o.rect.width - ev->surface->width) / 2; + float y = o.rect.y + (o.rect.height - ev->surface->height) / 2; + + weston_view_set_position(ev, x, y); + return; + } + } +} + void DesktopShell::setBackground(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource, struct wl_resource *surface_resource) { @@ -1084,7 +1108,8 @@ void DesktopShell::setOverlay(struct wl_client *client, struct wl_resource *reso surface->configure = [](struct weston_surface *es, int32_t sx, int32_t sy) { DesktopShell *shell = static_cast(es->configure_private); weston_view *view = container_of(es->views.next, weston_view, surface_link); - configure_static_view(view, &shell->m_overlayLayer); + configure_static_view_no_position(view, &shell->m_overlayLayer); + shell->centerViewOnAvailableSpace(view); }; surface->configure_private = this; surface->output = static_cast(output_resource->data); diff --git a/src/server/wl_hawaii/desktop-shell.h b/src/server/wl_hawaii/desktop-shell.h index 6e05f34b..68ab3925 100644 --- a/src/server/wl_hawaii/desktop-shell.h +++ b/src/server/wl_hawaii/desktop-shell.h @@ -129,6 +129,9 @@ class DesktopShell : public Shell { void lockSurfaceDestroy(void *); + void configureViewForAvailableSpace(weston_view *ev, Layer *layer); + void centerViewOnAvailableSpace(weston_view *ev); + /* * wl_hawaii_shell */