outputs.patch (7959B)
1 diff --git a/libswc/screen.c b/libswc/screen.c 2 index 54b1dc4..6d624d3 100644 3 --- a/libswc/screen.c 4 +++ b/libswc/screen.c 5 @@ -44,6 +44,7 @@ 6 7 #include "swc-server-protocol.h" 8 #include <stdlib.h> 9 +#include <wayland-server.h> 10 11 #define INTERNAL(s) ((struct screen *)(s)) 12 13 @@ -276,12 +277,51 @@ screen_new_virtual(struct output *output, const struct view_impl *impl) 14 return screen; 15 } 16 17 +/* the pointer may go anywhere on a screen and nowhere else */ 18 +static void 19 +pointer_region_update(void) 20 +{ 21 + struct screen *screen; 22 + pixman_region32_t region; 23 + 24 + if (!swc.seat) { 25 + return; 26 + } 27 + pixman_region32_init(®ion); 28 + wl_list_for_each(screen, &swc.screens, link) 29 + pixman_region32_union_rect(®ion, ®ion, 30 + screen->base.geometry.x, 31 + screen->base.geometry.y, 32 + screen->base.geometry.width, 33 + screen->base.geometry.height); 34 + pointer_set_region(swc.seat->pointer, ®ion); 35 + pixman_region32_fini(®ion); 36 +} 37 + 38 +/* the screen's area changed: what depends on it follows, and the window 39 + * manager is told */ 40 +static void 41 +screen_changed(struct screen *screen, bool resized) 42 +{ 43 + if (resized) { 44 + compositor_screen_resize(screen); 45 + } else { 46 + compositor_damage_all(); 47 + } 48 + pointer_region_update(); 49 + /* a change can leave origin and edges of the usable area as they 50 + * were, so it is told anyway */ 51 + screen->base.usable_geometry.width = 0; 52 + screen_update_usable_geometry(screen); 53 + if (screen->handler->geometry_changed) { 54 + screen->handler->geometry_changed(screen->handler_data); 55 + } 56 +} 57 + 58 void 59 screen_resize(struct screen *screen, uint32_t width, uint32_t height) 60 { 61 struct output *output; 62 - struct screen *other; 63 - pixman_region32_t region; 64 65 screen->planes.primary.view.geometry.width = width; 66 screen->planes.primary.view.geometry.height = height; 67 @@ -293,23 +333,140 @@ screen_resize(struct screen *screen, uint32_t width, uint32_t height) 68 wl_list_for_each(output, &screen->outputs, link) 69 output_set_size(output, width, height); 70 71 - compositor_screen_resize(screen); 72 - 73 - if (swc.seat) { 74 - pixman_region32_init(®ion); 75 - wl_list_for_each(other, &swc.screens, link) 76 - pixman_region32_union_rect(®ion, ®ion, 77 - other->base.geometry.x, 78 - other->base.geometry.y, 79 - other->base.geometry.width, 80 - other->base.geometry.height); 81 - pointer_set_region(swc.seat->pointer, ®ion); 82 - pixman_region32_fini(®ion); 83 + screen_changed(screen, true); 84 +} 85 + 86 +static struct output * 87 +screen_output(struct screen *screen) 88 +{ 89 + struct output *output; 90 + 91 + if (wl_list_empty(&screen->outputs)) { 92 + return NULL; 93 } 94 + return wl_container_of(screen->outputs.next, output, link); 95 +} 96 97 - /* a resize can leave origin and edges unchanged, notify anyway */ 98 - screen->base.usable_geometry.width = 0; 99 - screen_update_usable_geometry(screen); 100 +EXPORT const char * 101 +swc_screen_name(struct swc_screen *base) 102 +{ 103 + struct output *output = screen_output(INTERNAL(base)); 104 + 105 + return output ? output->name : ""; 106 +} 107 + 108 +EXPORT enum swc_screen_kind 109 +swc_screen_kind(struct swc_screen *base) 110 +{ 111 + struct screen *screen = INTERNAL(base); 112 + 113 + if (screen->virtual) { 114 + return SWC_SCREEN_WINDOW; 115 + } 116 +#ifdef ENABLE_DRM 117 + if (swc.video == SWC_VIDEO_DRM) { 118 + return SWC_SCREEN_DISPLAY; 119 + } 120 +#endif 121 + return SWC_SCREEN_FRAMEBUFFER; 122 +} 123 + 124 +EXPORT int 125 +swc_screen_modes(struct swc_screen *base, struct swc_mode *out, int max) 126 +{ 127 + struct screen *screen = INTERNAL(base); 128 + struct output *output = screen_output(screen); 129 + struct mode *mode; 130 + int n = 0; 131 + 132 + if (!output) { 133 + return 0; 134 + } 135 + wl_array_for_each(mode, &output->modes) 136 + { 137 + if (n < max) { 138 + out[n] = (struct swc_mode){ 139 + .width = mode->width, 140 + .height = mode->height, 141 + .refresh = mode->refresh, 142 + .preferred = mode->preferred, 143 + .current = mode_equal(&screen->planes.primary.mode, mode), 144 + }; 145 + } 146 + n++; 147 + } 148 + return n; 149 +} 150 + 151 +EXPORT bool 152 +swc_screen_set_mode(struct swc_screen *base, uint32_t width, uint32_t height, 153 + uint32_t refresh) 154 +{ 155 + struct screen *screen = INTERNAL(base); 156 + struct output *output = screen_output(screen); 157 + struct mode *mode, *best = NULL; 158 + struct wl_resource *resource; 159 + 160 + if (!output || swc_screen_kind(base) != SWC_SCREEN_DISPLAY) { 161 + return false; 162 + } 163 + wl_array_for_each(mode, &output->modes) 164 + { 165 + if (mode->width != width || mode->height != height) { 166 + continue; 167 + } 168 + if (refresh ? mode->refresh == refresh 169 + : !best || mode->refresh > best->refresh) { 170 + best = mode; 171 + } 172 + } 173 + if (!best) { 174 + return false; 175 + } 176 +#ifdef ENABLE_DRM 177 + screen->planes.primary.mode = *best; 178 + screen->planes.primary.need_modeset = true; 179 +#endif 180 + screen->planes.primary.view.geometry.width = width; 181 + screen->planes.primary.view.geometry.height = height; 182 + screen->base.geometry.width = width; 183 + screen->base.geometry.height = height; 184 + wl_resource_for_each(resource, &output->resources) 185 + { 186 + wl_output_send_mode(resource, 187 + WL_OUTPUT_MODE_CURRENT | 188 + (best->preferred ? WL_OUTPUT_MODE_PREFERRED : 0), 189 + best->width, best->height, best->refresh); 190 + if (wl_resource_get_version(resource) >= 2) { 191 + wl_output_send_done(resource); 192 + } 193 + } 194 + screen_changed(screen, true); 195 + return true; 196 +} 197 + 198 +EXPORT void 199 +swc_screen_move(struct swc_screen *base, int32_t x, int32_t y) 200 +{ 201 + struct screen *screen = INTERNAL(base); 202 + struct output *output = screen_output(screen); 203 + struct wl_resource *resource; 204 + 205 + view_move(&screen->planes.primary.view, x, y); 206 + screen->base.geometry.x = x; 207 + screen->base.geometry.y = y; 208 + if (output) { 209 + wl_resource_for_each(resource, &output->resources) 210 + { 211 + wl_output_send_geometry(resource, x, y, output->physical_width, 212 + output->physical_height, 0, "unknown", 213 + "unknown", WL_OUTPUT_TRANSFORM_NORMAL); 214 + if (wl_resource_get_version(resource) >= 2) { 215 + wl_output_send_done(resource); 216 + } 217 + } 218 + } 219 + screen_changed(screen, false); 220 } 221 222 void 223 diff --git a/libswc/swc.h b/libswc/swc.h 224 index b6b0c4c..b63fe98 100644 225 --- a/libswc/swc.h 226 +++ b/libswc/swc.h 227 @@ -302,6 +302,48 @@ void 228 swc_screen_set_handler(struct swc_screen *screen, 229 const struct swc_screen_handler *handler, void *data); 230 231 +/* what a screen shows on, which says what may be changed about it */ 232 +enum swc_screen_kind { 233 + /* a display: its modes are the hardware's, any of them may be set */ 234 + SWC_SCREEN_DISPLAY, 235 + /* a window of another compositor: its size is that window's */ 236 + SWC_SCREEN_WINDOW, 237 + /* a framebuffer: it has the one mode it was set to */ 238 + SWC_SCREEN_FRAMEBUFFER, 239 +}; 240 + 241 +struct swc_mode { 242 + uint32_t width, height; 243 + /* in mHz */ 244 + uint32_t refresh; 245 + bool preferred, current; 246 +}; 247 + 248 +/* the name of the screen's output, as wl_output names it (HDMI-A-1) */ 249 +const char * 250 +swc_screen_name(struct swc_screen *screen); 251 + 252 +enum swc_screen_kind 253 +swc_screen_kind(struct swc_screen *screen); 254 + 255 +/* the modes the screen may be set to, at most max into out; how many 256 + * there are */ 257 +int 258 +swc_screen_modes(struct swc_screen *screen, struct swc_mode *out, int max); 259 + 260 +/* sets the screen to the mode of that size and refresh, a refresh of 0 261 + * meaning the highest the size has. the change is made with the next 262 + * frame; geometry_changed follows. false when the screen has no such mode 263 + * or its modes are not the compositor's to set */ 264 +bool 265 +swc_screen_set_mode(struct swc_screen *screen, uint32_t width, 266 + uint32_t height, uint32_t refresh); 267 + 268 +/* places the screen's top left corner at x, y of the space the screens 269 + * share; geometry_changed follows */ 270 +void 271 +swc_screen_move(struct swc_screen *screen, int32_t x, int32_t y); 272 + 273 /* }}} */ 274 275 /* Windows {{{ */