diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-12-04 07:32:25 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-12-04 07:32:25 -0500 |
commit | 0896b6867536e7c12e5345ca5df94b9467c8bf24 (patch) | |
tree | 2240f512d2e55102b2ad16b4ff13a6c8124947d9 | |
parent | xwayland shell (diff) | |
parent | Merge pull request #1493 from acrisci/feature/wl-shell (diff) | |
download | sway-0896b6867536e7c12e5345ca5df94b9467c8bf24.tar.gz sway-0896b6867536e7c12e5345ca5df94b9467c8bf24.tar.zst sway-0896b6867536e7c12e5345ca5df94b9467c8bf24.zip |
Merge branch 'wlroots' into feature/xwayland
-rw-r--r-- | include/sway/server.h | 4 | ||||
-rw-r--r-- | include/sway/view.h | 16 | ||||
-rw-r--r-- | sway/desktop/wl_shell.c | 115 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/server.c | 6 |
5 files changed, 141 insertions, 1 deletions
diff --git a/include/sway/server.h b/include/sway/server.h index 30b15e75..3fa72e84 100644 --- a/include/sway/server.h +++ b/include/sway/server.h | |||
@@ -33,6 +33,9 @@ struct sway_server { | |||
33 | 33 | ||
34 | struct wlr_xwayland *xwayland; | 34 | struct wlr_xwayland *xwayland; |
35 | struct wl_listener xwayland_surface; | 35 | struct wl_listener xwayland_surface; |
36 | |||
37 | struct wlr_wl_shell *wl_shell; | ||
38 | struct wl_listener wl_shell_surface; | ||
36 | }; | 39 | }; |
37 | 40 | ||
38 | struct sway_server server; | 41 | struct sway_server server; |
@@ -46,5 +49,6 @@ void output_remove_notify(struct wl_listener *listener, void *data); | |||
46 | 49 | ||
47 | void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); | 50 | void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); |
48 | void handle_xwayland_surface(struct wl_listener *listener, void *data); | 51 | void handle_xwayland_surface(struct wl_listener *listener, void *data); |
52 | void handle_wl_shell_surface(struct wl_listener *listener, void *data); | ||
49 | 53 | ||
50 | #endif | 54 | #endif |
diff --git a/include/sway/view.h b/include/sway/view.h index 2d9b4ef5..83ac8285 100644 --- a/include/sway/view.h +++ b/include/sway/view.h | |||
@@ -33,6 +33,18 @@ struct sway_xwayland_surface { | |||
33 | int pending_width, pending_height; | 33 | int pending_width, pending_height; |
34 | }; | 34 | }; |
35 | 35 | ||
36 | struct sway_wl_shell_surface { | ||
37 | struct sway_view *view; | ||
38 | |||
39 | struct wl_listener commit; | ||
40 | struct wl_listener request_move; | ||
41 | struct wl_listener request_resize; | ||
42 | struct wl_listener request_maximize; | ||
43 | struct wl_listener destroy; | ||
44 | |||
45 | int pending_width, pending_height; | ||
46 | }; | ||
47 | |||
36 | enum sway_view_type { | 48 | enum sway_view_type { |
37 | SWAY_WL_SHELL_VIEW, | 49 | SWAY_WL_SHELL_VIEW, |
38 | SWAY_XDG_SHELL_V6_VIEW, | 50 | SWAY_XDG_SHELL_V6_VIEW, |
@@ -43,9 +55,9 @@ enum sway_view_type { | |||
43 | 55 | ||
44 | enum sway_view_prop { | 56 | enum sway_view_prop { |
45 | VIEW_PROP_TITLE, | 57 | VIEW_PROP_TITLE, |
58 | VIEW_PROP_APP_ID, | ||
46 | VIEW_PROP_CLASS, | 59 | VIEW_PROP_CLASS, |
47 | VIEW_PROP_INSTANCE, | 60 | VIEW_PROP_INSTANCE, |
48 | VIEW_PROP_APP_ID, | ||
49 | }; | 61 | }; |
50 | 62 | ||
51 | /** | 63 | /** |
@@ -61,11 +73,13 @@ struct sway_view { | |||
61 | union { | 73 | union { |
62 | struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; | 74 | struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; |
63 | struct wlr_xwayland_surface *wlr_xwayland_surface; | 75 | struct wlr_xwayland_surface *wlr_xwayland_surface; |
76 | struct wlr_wl_shell_surface *wlr_wl_shell_surface; | ||
64 | }; | 77 | }; |
65 | 78 | ||
66 | union { | 79 | union { |
67 | struct sway_xdg_surface_v6 *sway_xdg_surface_v6; | 80 | struct sway_xdg_surface_v6 *sway_xdg_surface_v6; |
68 | struct sway_xwayland_surface *sway_xwayland_surface; | 81 | struct sway_xwayland_surface *sway_xwayland_surface; |
82 | struct sway_wl_shell_surface *sway_wl_shell_surface; | ||
69 | }; | 83 | }; |
70 | 84 | ||
71 | struct { | 85 | struct { |
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c new file mode 100644 index 00000000..9641b911 --- /dev/null +++ b/sway/desktop/wl_shell.c | |||
@@ -0,0 +1,115 @@ | |||
1 | #define _POSIX_C_SOURCE 199309L | ||
2 | #include <stdbool.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <wayland-server.h> | ||
5 | #include <wlr/types/wlr_wl_shell.h> | ||
6 | #include "sway/container.h" | ||
7 | #include "sway/layout.h" | ||
8 | #include "sway/server.h" | ||
9 | #include "sway/view.h" | ||
10 | #include "log.h" | ||
11 | |||
12 | static bool assert_wl_shell(struct sway_view *view) { | ||
13 | return sway_assert(view->type == SWAY_WL_SHELL_VIEW, | ||
14 | "Expecting wl_shell view!"); | ||
15 | } | ||
16 | |||
17 | static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) { | ||
18 | if (!assert_wl_shell(view)) { | ||
19 | return NULL; | ||
20 | } | ||
21 | switch (prop) { | ||
22 | case VIEW_PROP_TITLE: | ||
23 | return view->wlr_wl_shell_surface->title; | ||
24 | case VIEW_PROP_CLASS: | ||
25 | return view->wlr_wl_shell_surface->class; | ||
26 | default: | ||
27 | return NULL; | ||
28 | } | ||
29 | } | ||
30 | |||
31 | static void set_size(struct sway_view *view, int width, int height) { | ||
32 | if (!assert_wl_shell(view)) { | ||
33 | return; | ||
34 | } | ||
35 | view->sway_wl_shell_surface->pending_width = width; | ||
36 | view->sway_wl_shell_surface->pending_height = height; | ||
37 | wlr_wl_shell_surface_configure(view->wlr_wl_shell_surface, 0, width, height); | ||
38 | } | ||
39 | |||
40 | static void handle_commit(struct wl_listener *listener, void *data) { | ||
41 | struct sway_wl_shell_surface *sway_surface = | ||
42 | wl_container_of(listener, sway_surface, commit); | ||
43 | struct sway_view *view = sway_surface->view; | ||
44 | sway_log(L_DEBUG, "wl_shell surface commit %dx%d", | ||
45 | sway_surface->pending_width, sway_surface->pending_height); | ||
46 | // NOTE: We intentionally discard the view's desired width here | ||
47 | // TODO: Let floating views do whatever | ||
48 | view->width = sway_surface->pending_width; | ||
49 | view->height = sway_surface->pending_height; | ||
50 | } | ||
51 | |||
52 | static void handle_destroy(struct wl_listener *listener, void *data) { | ||
53 | struct sway_wl_shell_surface *sway_surface = | ||
54 | wl_container_of(listener, sway_surface, destroy); | ||
55 | wl_list_remove(&sway_surface->commit.link); | ||
56 | wl_list_remove(&sway_surface->destroy.link); | ||
57 | swayc_t *parent = destroy_view(sway_surface->view->swayc); | ||
58 | free(sway_surface->view); | ||
59 | free(sway_surface); | ||
60 | arrange_windows(parent, -1, -1); | ||
61 | } | ||
62 | |||
63 | void handle_wl_shell_surface(struct wl_listener *listener, void *data) { | ||
64 | struct sway_server *server = wl_container_of( | ||
65 | listener, server, wl_shell_surface); | ||
66 | struct wlr_wl_shell_surface *shell_surface = data; | ||
67 | |||
68 | if (shell_surface->state != WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL) { | ||
69 | // TODO: transient and popups should be floating | ||
70 | return; | ||
71 | } | ||
72 | |||
73 | sway_log(L_DEBUG, "New wl_shell toplevel title='%s' app_id='%s'", | ||
74 | shell_surface->title, shell_surface->class); | ||
75 | wlr_wl_shell_surface_ping(shell_surface); | ||
76 | |||
77 | struct sway_wl_shell_surface *sway_surface = | ||
78 | calloc(1, sizeof(struct sway_wl_shell_surface)); | ||
79 | if (!sway_assert(sway_surface, "Failed to allocate surface!")) { | ||
80 | return; | ||
81 | } | ||
82 | |||
83 | struct sway_view *sway_view = calloc(1, sizeof(struct sway_view)); | ||
84 | if (!sway_assert(sway_view, "Failed to allocate view!")) { | ||
85 | return; | ||
86 | } | ||
87 | sway_view->type = SWAY_WL_SHELL_VIEW; | ||
88 | sway_view->iface.get_prop = get_prop; | ||
89 | sway_view->iface.set_size = set_size; | ||
90 | sway_view->wlr_wl_shell_surface = shell_surface; | ||
91 | sway_view->sway_wl_shell_surface = sway_surface; | ||
92 | sway_view->surface = shell_surface->surface; | ||
93 | sway_surface->view = sway_view; | ||
94 | |||
95 | // TODO: | ||
96 | // - Wire up listeners | ||
97 | // - Handle popups | ||
98 | // - Look up pid and open on appropriate workspace | ||
99 | // - Set new view to maximized so it behaves nicely | ||
100 | // - Criteria | ||
101 | |||
102 | sway_surface->commit.notify = handle_commit; | ||
103 | wl_signal_add(&shell_surface->events.commit, &sway_surface->commit); | ||
104 | sway_surface->destroy.notify = handle_destroy; | ||
105 | wl_signal_add(&shell_surface->events.destroy, &sway_surface->destroy); | ||
106 | |||
107 | // TODO: actual focus semantics | ||
108 | swayc_t *parent = root_container.children->items[0]; | ||
109 | parent = parent->children->items[0]; // workspace | ||
110 | |||
111 | swayc_t *cont = new_view(parent, sway_view); | ||
112 | sway_view->swayc = cont; | ||
113 | |||
114 | arrange_windows(cont->parent, -1, -1); | ||
115 | } | ||
diff --git a/sway/meson.build b/sway/meson.build index e8e9013f..9f92f5d1 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -6,6 +6,7 @@ sway_sources = files( | |||
6 | 'ipc-json.c', | 6 | 'ipc-json.c', |
7 | 'ipc-server.c', | 7 | 'ipc-server.c', |
8 | 'desktop/output.c', | 8 | 'desktop/output.c', |
9 | 'desktop/wl_shell.c', | ||
9 | 'desktop/xdg_shell_v6.c', | 10 | 'desktop/xdg_shell_v6.c', |
10 | 'desktop/xwayland.c', | 11 | 'desktop/xwayland.c', |
11 | 'tree/container.c', | 12 | 'tree/container.c', |
diff --git a/sway/server.c b/sway/server.c index 2694cea0..024d8429 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <wlr/render.h> | 7 | #include <wlr/render.h> |
8 | #include <wlr/render/gles2.h> | 8 | #include <wlr/render/gles2.h> |
9 | #include <wlr/types/wlr_compositor.h> | 9 | #include <wlr/types/wlr_compositor.h> |
10 | #include <wlr/types/wlr_wl_shell.h> | ||
10 | // TODO WLR: make Xwayland optional | 11 | // TODO WLR: make Xwayland optional |
11 | #include <wlr/xwayland.h> | 12 | #include <wlr/xwayland.h> |
12 | #include "sway/server.h" | 13 | #include "sway/server.h" |
@@ -47,6 +48,11 @@ bool server_init(struct sway_server *server) { | |||
47 | &server->xwayland_surface); | 48 | &server->xwayland_surface); |
48 | server->xwayland_surface.notify = handle_xwayland_surface; | 49 | server->xwayland_surface.notify = handle_xwayland_surface; |
49 | 50 | ||
51 | server->wl_shell = wlr_wl_shell_create(server->wl_display); | ||
52 | wl_signal_add(&server->wl_shell->events.new_surface, | ||
53 | &server->wl_shell_surface); | ||
54 | server->wl_shell_surface.notify = handle_wl_shell_surface; | ||
55 | |||
50 | server->socket = wl_display_add_socket_auto(server->wl_display); | 56 | server->socket = wl_display_add_socket_auto(server->wl_display); |
51 | if (!sway_assert(server->socket, "Unable to open wayland socket")) { | 57 | if (!sway_assert(server->socket, "Unable to open wayland socket")) { |
52 | wlr_backend_destroy(server->backend); | 58 | wlr_backend_destroy(server->backend); |