aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop/wl_shell.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-03 14:21:26 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-03 14:21:26 -0500
commit8239067da42545a59dbb43b941f69470d501f544 (patch)
treeede4a498ffd3f354ac85f296c4b45aed07aaa6ff /sway/desktop/wl_shell.c
parentsway wl_shell (diff)
downloadsway-8239067da42545a59dbb43b941f69470d501f544.tar.gz
sway-8239067da42545a59dbb43b941f69470d501f544.tar.zst
sway-8239067da42545a59dbb43b941f69470d501f544.zip
basic wl-shell
Diffstat (limited to 'sway/desktop/wl_shell.c')
-rw-r--r--sway/desktop/wl_shell.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c
index 8bfa605e..3a349425 100644
--- a/sway/desktop/wl_shell.c
+++ b/sway/desktop/wl_shell.c
@@ -28,3 +28,88 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) {
28 } 28 }
29} 29}
30 30
31static void set_dimensions(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
40static 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
52static 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
63void 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_dimensions = set_dimensions;
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}