aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-27 13:35:34 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-28 14:25:19 -0400
commiteccf0b25987b2b194031edf3415e9f09a7ad7119 (patch)
tree1392beed8f4745a36047d8194f3ac9eb20117f44
parentMerge pull request #1641 from swaywm/transformed-events (diff)
downloadsway-eccf0b25987b2b194031edf3415e9f09a7ad7119.tar.gz
sway-eccf0b25987b2b194031edf3415e9f09a7ad7119.tar.zst
sway-eccf0b25987b2b194031edf3415e9f09a7ad7119.zip
Add client protocols and swaybg skeleton
-rw-r--r--meson.build2
-rw-r--r--protocols/meson.build49
-rw-r--r--protocols/wlr-layer-shell-unstable-v1.xml281
-rw-r--r--swaybg/main.c189
-rw-r--r--swaybg/meson.build8
5 files changed, 347 insertions, 182 deletions
diff --git a/meson.build b/meson.build
index f27ac451..622769a3 100644
--- a/meson.build
+++ b/meson.build
@@ -85,9 +85,11 @@ add_project_arguments('-DSWAY_VERSION=@0@'.format(version), language: 'c')
85 85
86sway_inc = include_directories('include') 86sway_inc = include_directories('include')
87 87
88subdir('protocols')
88subdir('common') 89subdir('common')
89subdir('sway') 90subdir('sway')
90subdir('swaymsg') 91subdir('swaymsg')
92subdir('swaybg')
91 93
92config = configuration_data() 94config = configuration_data()
93config.set('sysconfdir', join_paths(prefix, sysconfdir)) 95config.set('sysconfdir', join_paths(prefix, sysconfdir))
diff --git a/protocols/meson.build b/protocols/meson.build
new file mode 100644
index 00000000..73a6fda5
--- /dev/null
+++ b/protocols/meson.build
@@ -0,0 +1,49 @@
1wl_protocol_dir = wayland_protos.get_pkgconfig_variable('pkgdatadir')
2
3wayland_scanner = find_program('wayland-scanner')
4
5wayland_scanner_server = generator(
6 wayland_scanner,
7 output: '@BASENAME@-protocol.h',
8 arguments: ['server-header', '@INPUT@', '@OUTPUT@'],
9)
10
11wayland_scanner_code = generator(
12 wayland_scanner,
13 output: '@BASENAME@-protocol.c',
14 arguments: ['code', '@INPUT@', '@OUTPUT@'],
15)
16
17wayland_scanner_client = generator(
18 wayland_scanner,
19 output: '@BASENAME@-client-protocol.h',
20 arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
21)
22
23protocols = []
24
25client_protocols = [
26 'wlr-layer-shell-unstable-v1.xml',
27]
28
29wl_protos_src = []
30wl_protos_headers = []
31
32foreach p : protocols
33 xml = join_paths(p)
34 wl_protos_src += wayland_scanner_code.process(xml)
35 wl_protos_headers += wayland_scanner_server.process(xml)
36endforeach
37
38foreach p : client_protocols
39 xml = join_paths(p)
40 wl_protos_headers += wayland_scanner_client.process(xml)
41endforeach
42
43lib_wl_protos = static_library('wl_protos', wl_protos_src + wl_protos_headers,
44 dependencies: [wayland_client]) # for the include directory
45
46sway_protos = declare_dependency(
47 link_with: lib_wl_protos,
48 sources: wl_protos_headers,
49)
diff --git a/protocols/wlr-layer-shell-unstable-v1.xml b/protocols/wlr-layer-shell-unstable-v1.xml
new file mode 100644
index 00000000..3181c0bb
--- /dev/null
+++ b/protocols/wlr-layer-shell-unstable-v1.xml
@@ -0,0 +1,281 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<protocol name="wlr_layer_shell_unstable_v1">
3 <copyright>
4 Copyright © 2017 Drew DeVault
5
6 Permission to use, copy, modify, distribute, and sell this
7 software and its documentation for any purpose is hereby granted
8 without fee, provided that the above copyright notice appear in
9 all copies and that both that copyright notice and this permission
10 notice appear in supporting documentation, and that the name of
11 the copyright holders not be used in advertising or publicity
12 pertaining to distribution of the software without specific,
13 written prior permission. The copyright holders make no
14 representations about the suitability of this software for any
15 purpose. It is provided "as is" without express or implied
16 warranty.
17
18 THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
19 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
23 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25 THIS SOFTWARE.
26 </copyright>
27
28 <interface name="zwlr_layer_shell_v1" version="1">
29 <description summary="create surfaces that are layers of the desktop">
30 Clients can use this interface to assign the surface_layer role to
31 wl_surfaces. Such surfaces are assigned to a "layer" of the output and
32 rendered with a defined z-depth respective to each other. They may also be
33 anchored to the edges and corners of a screen and specify input handling
34 semantics. This interface should be suitable for the implementation of
35 many desktop shell components, and a broad number of other applications
36 that interact with the desktop.
37 </description>
38
39 <request name="get_layer_surface">
40 <description summary="create a layer_surface from a surface">
41 Create a layer surface for an existing surface. This assigns the role of
42 layer_surface, or raises a protocol error if another role is already
43 assigned.
44
45 Creating a layer surface from a wl_surface which has a buffer attached
46 or committed is a client error, and any attempts by a client to attach
47 or manipulate a buffer prior to the first layer_surface.configure call
48 must also be treated as errors.
49
50 Clients can specify a namespace that defines the purpose of the layer
51 surface.
52 </description>
53 <arg name="id" type="new_id" interface="zwlr_layer_surface_v1"/>
54 <arg name="surface" type="object" interface="wl_surface"/>
55 <arg name="output" type="object" interface="wl_output"/>
56 <arg name="layer" type="uint" enum="layer" summary="layer to add this surface to"/>
57 <arg name="namespace" type="string" summary="namespace for the layer surface"/>
58 </request>
59
60 <enum name="error">
61 <entry name="role" value="0" summary="wl_surface has another role"/>
62 <entry name="invalid_layer" value="1" summary="layer value is invalid"/>
63 <entry name="already_constructed" value="2" summary="wl_surface has a buffer attached or committed"/>
64 </enum>
65
66 <enum name="layer">
67 <description summary="available layers for surfaces">
68 These values indicate which layers a surface can be rendered in. They
69 are ordered by z depth, bottom-most first. Traditional shell surfaces
70 will typically be rendered between the bottom and top layers.
71 Fullscreen shell surfaces are typically rendered at the top layer.
72 Multiple surfaces can share a single layer, and ordering within a
73 single layer is undefined.
74 </description>
75
76 <entry name="background" value="0"/>
77 <entry name="bottom" value="1"/>
78 <entry name="top" value="2"/>
79 <entry name="overlay" value="3"/>
80 </enum>
81 </interface>
82
83 <interface name="zwlr_layer_surface_v1" version="1">
84 <description summary="layer metadata interface">
85 An interface that may be implemented by a wl_surface, for surfaces that
86 are designed to be rendered as a layer of a stacked desktop-like
87 environment.
88
89 Layer surface state (size, anchor, exclusive zone, margin, interactivity)
90 is double-buffered, and will be applied at the time wl_surface.commit of
91 the corresponding wl_surface is called.
92 </description>
93
94 <request name="set_size">
95 <description summary="sets the size of the surface">
96 Sets the size of the surface in surface-local coordinates. The
97 compositor will display the surface centered with respect to its
98 anchors.
99
100 If you pass 0 for either value, the compositor will assign it and
101 inform you of the assignment in the configure event. You must set your
102 anchor to opposite edges in the dimensions you omit; not doing so is a
103 protocol error. Both values are 0 by default.
104
105 Size is double-buffered, see wl_surface.commit.
106 </description>
107 <arg name="width" type="uint"/>
108 <arg name="height" type="uint"/>
109 </request>
110
111 <request name="set_anchor">
112 <description summary="configures the anchor point of the surface">
113 Requests that the compositor anchor the surface to the specified edges
114 and corners. If two orthoginal edges are specified (e.g. 'top' and
115 'left'), then the anchor point will be the intersection of the edges
116 (e.g. the top left corner of the output); otherwise the anchor point
117 will be centered on that edge, or in the center if none is specified.
118
119 Anchor is double-buffered, see wl_surface.commit.
120 </description>
121 <arg name="anchor" type="uint" enum="anchor"/>
122 </request>
123
124 <request name="set_exclusive_zone">
125 <description summary="configures the exclusive geometry of this surface">
126 Requests that the compositor avoids occluding an area of the surface
127 with other surfaces. The compositor's use of this information is
128 implementation-dependent - do not assume that this region will not
129 actually be occluded.
130
131 A positive value is only meaningful if the surface is anchored to an
132 edge, rather than a corner. The zone is the number of surface-local
133 coordinates from the edge that are considered exclusive.
134
135 Surfaces that do not wish to have an exclusive zone may instead specify
136 how they should interact with surfaces that do. If set to zero, the
137 surface indicates that it would like to be moved to avoid occluding
138 surfaces with a positive excluzive zone. If set to -1, the surface
139 indicates that it would not like to be moved to accomodate for other
140 surfaces, and the compositor should extend it all the way to the edges
141 it is anchored to.
142
143 For example, a panel might set its exclusive zone to 10, so that
144 maximized shell surfaces are not shown on top of it. A notification
145 might set its exclusive zone to 0, so that it is moved to avoid
146 occluding the panel, but shell surfaces are shown underneath it. A
147 wallpaper or lock screen might set their exclusive zone to -1, so that
148 they stretch below or over the panel.
149
150 The default value is 0.
151
152 Exclusive zone is double-buffered, see wl_surface.commit.
153 </description>
154 <arg name="zone" type="int"/>
155 </request>
156
157 <request name="set_margin">
158 <description summary="sets a margin from the anchor point">
159 Requests that the surface be placed some distance away from the anchor
160 point on the output, in surface-local coordinates. Setting this value
161 for edges you are not anchored to has no effect.
162
163 The exclusive zone includes the margin.
164
165 Margin is double-buffered, see wl_surface.commit.
166 </description>
167 <arg name="top" type="int"/>
168 <arg name="right" type="int"/>
169 <arg name="bottom" type="int"/>
170 <arg name="left" type="int"/>
171 </request>
172
173 <request name="set_keyboard_interactivity">
174 <description summary="requests keyboard events">
175 Set to 1 to request that the seat send keyboard events to this layer
176 surface. For layers below the shell surface layer, the seat will use
177 normal focus semantics. For layers above the shell surface layers, the
178 seat will always give exclusive keyboard focus to the top-most layer
179 which has keyboard interactivity set to true.
180
181 Layer surfaces receive pointer, touch, and tablet events normally. If
182 you do not want to receive them, set the input region on your surface
183 to an empty region.
184
185 Events is double-buffered, see wl_surface.commit.
186 </description>
187 <arg name="keyboard_interactivity" type="uint"/>
188 </request>
189
190 <request name="get_popup">
191 <description summary="assign this layer_surface as an xdg_popup parent">
192 This assigns an xdg_popup's parent to this layer_surface. This popup
193 should have been created via xdg_surface::get_popup with the parent set
194 to NULL, and this request must be invoked before committing the popup's
195 initial state.
196
197 See the documentation of xdg_popup for more details about what an
198 xdg_popup is and how it is used.
199 </description>
200 <arg name="popup" type="object" interface="xdg_popup"/>
201 </request>
202
203 <request name="ack_configure">
204 <description summary="ack a configure event">
205 When a configure event is received, if a client commits the
206 surface in response to the configure event, then the client
207 must make an ack_configure request sometime before the commit
208 request, passing along the serial of the configure event.
209
210 If the client receives multiple configure events before it
211 can respond to one, it only has to ack the last configure event.
212
213 A client is not required to commit immediately after sending
214 an ack_configure request - it may even ack_configure several times
215 before its next surface commit.
216
217 A client may send multiple ack_configure requests before committing, but
218 only the last request sent before a commit indicates which configure
219 event the client really is responding to.
220 </description>
221 <arg name="serial" type="uint" summary="the serial from the configure event"/>
222 </request>
223
224 <request name="destroy" type="destructor">
225 <description summary="destroy the layer_surface">
226 This request destroys the layer surface.
227 </description>
228 </request>
229
230 <event name="configure">
231 <description summary="suggest a surface change">
232 The configure event asks the client to resize its surface.
233
234 Clients should arrange their surface for the new states, and then send
235 an ack_configure request with the serial sent in this configure event at
236 some point before committing the new surface.
237
238 The client is free to dismiss all but the last configure event it
239 received.
240
241 The width and height arguments specify the size of the window in
242 surface-local coordinates.
243
244 The size is a hint, in the sense that the client is free to ignore it if
245 it doesn't resize, pick a smaller size (to satisfy aspect ratio or
246 resize in steps of NxM pixels). If the client picks a smaller size and
247 is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the
248 surface will be centered on this axis.
249
250 If the width or height arguments are zero, it means the client should
251 decide its own window dimension.
252 </description>
253 <arg name="serial" type="uint"/>
254 <arg name="width" type="uint"/>
255 <arg name="height" type="uint"/>
256 </event>
257
258 <event name="closed">
259 <description summary="surface should be closed">
260 The closed event is sent by the compositor when the surface will no
261 longer be shown. The output may have been destroyed or the user may
262 have asked for it to be removed. Further changes to the surface will be
263 ignored. The client should destroy the resource after receiving this
264 event, and create a new surface if they so choose.
265 </description>
266 </event>
267
268 <enum name="error">
269 <entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
270 <entry name="invalid_size" value="1" summary="size is invalid"/>
271 <entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
272 </enum>
273
274 <enum name="anchor" bitfield="true">
275 <entry name="top" value="1" summary="the top edge of the anchor rectangle"/>
276 <entry name="bottom" value="2" summary="the bottom edge of the anchor rectangle"/>
277 <entry name="left" value="4" summary="the left edge of the anchor rectangle"/>
278 <entry name="right" value="8" summary="the right edge of the anchor rectangle"/>
279 </enum>
280 </interface>
281</protocol>
diff --git a/swaybg/main.c b/swaybg/main.c
index 2fdd4220..94e98228 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -1,20 +1,11 @@
1#include "wayland-desktop-shell-client-protocol.h" 1#include <ctype.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#include <stdio.h> 3#include <stdio.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <ctype.h>
6#include <wayland-client.h>
7#include <time.h>
8#include <string.h> 5#include <string.h>
9#include "client/window.h" 6#include <time.h>
10#include "client/registry.h" 7#include <wayland-client.h>
11#include "client/cairo.h" 8#include <wlr/util/log.h>
12#include "log.h"
13#include "list.h"
14#include "util.h"
15
16list_t *surfaces;
17struct registry *registry;
18 9
19enum scaling_mode { 10enum scaling_mode {
20 SCALING_MODE_STRETCH, 11 SCALING_MODE_STRETCH,
@@ -24,21 +15,11 @@ enum scaling_mode {
24 SCALING_MODE_TILE, 15 SCALING_MODE_TILE,
25}; 16};
26 17
27void sway_terminate(int exit_code) {
28 int i;
29 for (i = 0; i < surfaces->length; ++i) {
30 struct window *window = surfaces->items[i];
31 window_teardown(window);
32 }
33 list_free(surfaces);
34 registry_teardown(registry);
35 exit(exit_code);
36}
37
38bool is_valid_color(const char *color) { 18bool is_valid_color(const char *color) {
39 int len = strlen(color); 19 int len = strlen(color);
40 if (len != 7 || color[0] != '#') { 20 if (len != 7 || color[0] != '#') {
41 sway_log(L_ERROR, "%s is not a valid color for swaybg. Color should be specified as #rrggbb (no alpha).", color); 21 wlr_log(L_ERROR, "%s is not a valid color for swaybg. "
22 "Color should be specified as #rrggbb (no alpha).", color);
42 return false; 23 return false;
43 } 24 }
44 25
@@ -53,162 +34,6 @@ bool is_valid_color(const char *color) {
53} 34}
54 35
55int main(int argc, const char **argv) { 36int main(int argc, const char **argv) {
56 init_log(L_INFO); 37 wlr_log_init(L_DEBUG, NULL);
57 surfaces = create_list();
58 registry = registry_poll();
59
60 if (argc != 4) {
61 sway_abort("Do not run this program manually. See man 5 sway and look for output options.");
62 }
63
64 if (!registry->desktop_shell) {
65 sway_abort("swaybg requires the compositor to support the desktop-shell extension.");
66 }
67
68 int desired_output = atoi(argv[1]);
69 sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length);
70 int i;
71 struct output_state *output = registry->outputs->items[desired_output];
72 struct window *window = window_setup(registry,
73 output->width, output->height, output->scale, false);
74 if (!window) {
75 sway_abort("Failed to create surfaces.");
76 }
77 desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
78 window_make_shell(window);
79 list_add(surfaces, window);
80
81 if (strcmp(argv[3], "solid_color") == 0 && is_valid_color(argv[2])) {
82 cairo_set_source_u32(window->cairo, parse_color(argv[2]));
83 cairo_paint(window->cairo);
84 window_render(window);
85 } else {
86#ifdef WITH_GDK_PIXBUF
87 GError *err = NULL;
88 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[2], &err);
89 if (!pixbuf) {
90 sway_abort("Failed to load background image.");
91 }
92 cairo_surface_t *image = gdk_cairo_image_surface_create_from_pixbuf(pixbuf);
93 g_object_unref(pixbuf);
94#else
95 cairo_surface_t *image = cairo_image_surface_create_from_png(argv[2]);
96#endif //WITH_GDK_PIXBUF
97 if (!image) {
98 sway_abort("Failed to read background image.");
99 }
100 if (cairo_surface_status(image) != CAIRO_STATUS_SUCCESS) {
101 sway_abort("Failed to read background image: %s."
102#ifndef WITH_GDK_PIXBUF
103 "\nSway was compiled without gdk_pixbuf support, so only"
104 "\nPNG images can be loaded. This is the likely cause."
105#endif //WITH_GDK_PIXBUF
106 , cairo_status_to_string(cairo_surface_status(image)));
107 }
108 double width = cairo_image_surface_get_width(image);
109 double height = cairo_image_surface_get_height(image);
110
111 const char *scaling_mode_str = argv[3];
112 enum scaling_mode scaling_mode = SCALING_MODE_STRETCH;
113 if (strcmp(scaling_mode_str, "stretch") == 0) {
114 scaling_mode = SCALING_MODE_STRETCH;
115 } else if (strcmp(scaling_mode_str, "fill") == 0) {
116 scaling_mode = SCALING_MODE_FILL;
117 } else if (strcmp(scaling_mode_str, "fit") == 0) {
118 scaling_mode = SCALING_MODE_FIT;
119 } else if (strcmp(scaling_mode_str, "center") == 0) {
120 scaling_mode = SCALING_MODE_CENTER;
121 } else if (strcmp(scaling_mode_str, "tile") == 0) {
122 scaling_mode = SCALING_MODE_TILE;
123 } else {
124 sway_abort("Unsupported scaling mode: %s", scaling_mode_str);
125 }
126
127 int wwidth = window->width * window->scale;
128 int wheight = window->height * window->scale;
129
130 for (i = 0; i < surfaces->length; ++i) {
131 struct window *window = surfaces->items[i];
132 if (window_prerender(window) && window->cairo) {
133 switch (scaling_mode) {
134 case SCALING_MODE_STRETCH:
135 cairo_scale(window->cairo,
136 (double) wwidth / width,
137 (double) wheight / height);
138 cairo_set_source_surface(window->cairo, image, 0, 0);
139 break;
140 case SCALING_MODE_FILL:
141 {
142 double window_ratio = (double) wwidth / wheight;
143 double bg_ratio = width / height;
144
145 if (window_ratio > bg_ratio) {
146 double scale = (double) wwidth / width;
147 cairo_scale(window->cairo, scale, scale);
148 cairo_set_source_surface(window->cairo, image,
149 0,
150 (double) wheight/2 / scale - height/2);
151 } else {
152 double scale = (double) wheight / height;
153 cairo_scale(window->cairo, scale, scale);
154 cairo_set_source_surface(window->cairo, image,
155 (double) wwidth/2 / scale - width/2,
156 0);
157 }
158 break;
159 }
160 case SCALING_MODE_FIT:
161 {
162 double window_ratio = (double) wwidth / wheight;
163 double bg_ratio = width / height;
164
165 if (window_ratio > bg_ratio) {
166 double scale = (double) wheight / height;
167 cairo_scale(window->cairo, scale, scale);
168 cairo_set_source_surface(window->cairo, image,
169 (double) wwidth/2 / scale - width/2,
170 0);
171 } else {
172 double scale = (double) wwidth / width;
173 cairo_scale(window->cairo, scale, scale);
174 cairo_set_source_surface(window->cairo, image,
175 0,
176 (double) wheight/2 / scale - height/2);
177 }
178 break;
179 }
180 case SCALING_MODE_CENTER:
181 cairo_set_source_surface(window->cairo, image,
182 (double) wwidth/2 - width/2,
183 (double) wheight/2 - height/2);
184 break;
185 case SCALING_MODE_TILE:
186 {
187 cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image);
188 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
189 cairo_set_source(window->cairo, pattern);
190 break;
191 }
192 default:
193 sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str);
194 }
195
196 cairo_paint(window->cairo);
197
198 window_render(window);
199 }
200 }
201
202 cairo_surface_destroy(image);
203 }
204
205 while (wl_display_dispatch(registry->display) != -1);
206
207 for (i = 0; i < surfaces->length; ++i) {
208 struct window *window = surfaces->items[i];
209 window_teardown(window);
210 }
211 list_free(surfaces);
212 registry_teardown(registry);
213 return 0; 38 return 0;
214} 39}
diff --git a/swaybg/meson.build b/swaybg/meson.build
new file mode 100644
index 00000000..47315023
--- /dev/null
+++ b/swaybg/meson.build
@@ -0,0 +1,8 @@
1executable(
2 'swaybg',
3 'main.c',
4 include_directories: [sway_inc],
5 dependencies: [wayland_client, sway_protos, jsonc, wlroots],
6 link_with: [lib_sway_common],
7 install: true
8)