aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2016-07-14 18:57:37 -0400
committerGitHub <noreply@github.com>2016-07-14 18:57:37 -0400
commit6abbe04e7590f3bfba13351eb87ada70ac3d506e (patch)
treef7c64d6e9d082bd080960c42e21e54edf01839de /sway
parent1e95191900d1f16b4d195f2d05f1eb7cb1f62ad5 (diff)
parent8a232c8cfd60c1469ceaaa911f31a6d75e8ad851 (diff)
Merge pull request #743 from deklov/panel-as-shell-03
Set panels/backgrounds' geometries correctly and don't render them ex…
Diffstat (limited to 'sway')
-rw-r--r--sway/extensions.c1
-rw-r--r--sway/handlers.c126
2 files changed, 75 insertions, 52 deletions
diff --git a/sway/extensions.c b/sway/extensions.c
index 1fe15ac5..ab425fa7 100644
--- a/sway/extensions.c
+++ b/sway/extensions.c
@@ -73,7 +73,6 @@ 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);
struct background_config *config = malloc(sizeof(struct background_config));
- config->client = client;
config->output = output;
config->surface = wlc_resource_from_wl_surface_resource(surface);
config->wl_surface_res = surface;
diff --git a/sway/handlers.c b/sway/handlers.c
index 4336b6c7..a7a87564 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -33,6 +33,66 @@
// Event handled by sway and should not be sent to client
#define EVENT_HANDLED true
+static struct panel_config *if_panel_find_config(struct wl_client *client) {
+ int i;
+ for (i = 0; i < desktop_shell.panels->length; i++) {
+ struct panel_config *config = desktop_shell.panels->items[i];
+ if (config->client == client) {
+ return config;
+ }
+ }
+ return NULL;
+}
+
+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_geometry *old = wlc_view_get_geometry(config->handle);
+ struct wlc_geometry new;
+
+ switch (config->panel_position) {
+ case DESKTOP_SHELL_PANEL_POSITION_TOP:
+ new.origin.x = 0;
+ new.origin.y = 0;
+ new.size.w = resolution.w;
+ new.size.h = old->size.h;
+ break;
+ case DESKTOP_SHELL_PANEL_POSITION_BOTTOM:
+ new.origin.x = 0;
+ new.origin.y = resolution.h - old->size.h;
+ new.size.w = resolution.w;
+ new.size.h = old->size.h;
+ break;
+ case DESKTOP_SHELL_PANEL_POSITION_LEFT:
+ new.origin.x = 0;
+ new.origin.y = 0;
+ new.size.w = old->size.w;
+ new.size.h = resolution.h;
+ break;
+ case DESKTOP_SHELL_PANEL_POSITION_RIGHT:
+ new.origin.x = resolution.w - old->size.w;
+ new.origin.y = 0;
+ new.size.w = old->size.w;
+ new.size.h = resolution.h;
+ break;
+ }
+
+ return new;
+}
+
+static void update_panel_geometry(struct panel_config *config) {
+ struct wlc_geometry geometry = compute_panel_geometry(config);
+ wlc_view_set_geometry(config->handle, 0, &geometry);
+}
+
+static void update_panel_geometries(wlc_handle output) {
+ for (int i = 0; i < desktop_shell.panels->length; i++) {
+ struct panel_config *config = desktop_shell.panels->items[i];
+ if (config->output == output) {
+ update_panel_geometry(config);
+ }
+ }
+}
+
/* Handles */
static bool handle_input_created(struct libinput_device *device) {
@@ -119,32 +179,6 @@ static void handle_output_pre_render(wlc_handle output) {
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 (config->panel_position) {
- case DESKTOP_SHELL_PANEL_POSITION_TOP:
- geo.origin = (struct wlc_point){ 0, 0 };
- break;
- case DESKTOP_SHELL_PANEL_POSITION_BOTTOM:
- geo.origin = (struct wlc_point){ 0, resolution.h - size.h };
- break;
- case DESKTOP_SHELL_PANEL_POSITION_LEFT:
- geo.origin = (struct wlc_point){ 0, 0 };
- break;
- case DESKTOP_SHELL_PANEL_POSITION_RIGHT:
- geo.origin = (struct wlc_point){ resolution.w - size.w, 0 };
- break;
- }
- wlc_surface_render(config->surface, &geo);
- break;
- }
- }
}
static void handle_output_post_render(wlc_handle output) {
@@ -158,10 +192,16 @@ static void handle_view_pre_render(wlc_handle view) {
static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) {
sway_log(L_DEBUG, "Output %u resolution changed to %d x %d", (unsigned int)output, to->w, to->h);
+
swayc_t *c = swayc_by_handle(output);
- if (!c) return;
+ if (!c) {
+ return;
+ }
c->width = to->w;
c->height = to->h;
+
+ update_panel_geometries(output);
+
arrange_windows(&root_container, -1, -1);
}
@@ -176,28 +216,6 @@ static void handle_output_focused(wlc_handle output, bool focus) {
}
}
-static bool client_is_background(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 true;
- }
- }
- return false;
-}
-
-static bool client_is_panel(struct wl_client *client) {
- int i;
- for (i = 0; i < desktop_shell.panels->length; i++) {
- struct panel_config *config = desktop_shell.panels->items[i];
- if (config->client == client) {
- return true;
- }
- }
- return false;
-}
-
static void ws_cleanup() {
swayc_t *op, *ws;
int i = 0, j;
@@ -228,8 +246,14 @@ static bool handle_view_created(wlc_handle handle) {
bool return_to_workspace = false;
struct wl_client *client = wlc_view_get_wl_client(handle);
pid_t pid;
-
- if (client_is_background(client) || client_is_panel(client)) {
+ struct panel_config *panel_config = NULL;
+
+ panel_config = if_panel_find_config(client);
+ if (panel_config) {
+ panel_config->handle = handle;
+ update_panel_geometry(panel_config);
+ wlc_view_set_mask(handle, VISIBLE);
+ wlc_view_set_output(handle, panel_config->output);
return true;
}