9
9
#include "pango.h"
10
10
#include "sway/config.h"
11
11
#include "sway/sway_text_node.h"
12
+ #include "sway/output.h"
12
13
13
14
struct cairo_buffer {
14
15
struct wlr_buffer base ;
@@ -163,6 +164,39 @@ static void render_backing_buffer(struct text_buffer *buffer) {
163
164
cairo_font_options_destroy (fo );
164
165
}
165
166
167
+ static void text_calc_size (struct text_buffer * buffer ) {
168
+ struct sway_text_node * props = & buffer -> props ;
169
+ props -> width = 0 ;
170
+
171
+ cairo_t * c = cairo_create (NULL );
172
+ if (!c ) {
173
+ sway_log (SWAY_ERROR , "cairo_t allocation failed" );
174
+ return ;
175
+ }
176
+
177
+ cairo_set_antialias (c , CAIRO_ANTIALIAS_BEST );
178
+ for (int i = 0 ; i < root -> outputs -> length ; ++ i ) {
179
+ struct sway_output * output = root -> outputs -> items [i ];
180
+ if (!output -> wlr_output -> enabled ) {
181
+ continue ;
182
+ }
183
+
184
+ int size , baseline ;
185
+ get_text_size (c , config -> font_description , & size , NULL ,
186
+ & baseline , output -> wlr_output -> scale , props -> pango_markup , "%s" , buffer -> text );
187
+
188
+ size = ceil ((float )size / output -> wlr_output -> scale );
189
+ if (props -> width < size ) {
190
+ props -> width = size ;
191
+ props -> baseline = (float )baseline / output -> wlr_output -> scale ;
192
+ }
193
+ }
194
+ cairo_destroy (c );
195
+
196
+ wlr_scene_buffer_set_dest_size (buffer -> buffer_node ,
197
+ get_text_width (props ), props -> height );
198
+ }
199
+
166
200
static void handle_outputs_update (struct wl_listener * listener , void * data ) {
167
201
struct text_buffer * buffer = wl_container_of (listener , buffer , outputs_update );
168
202
struct wlr_scene_outputs_update_event * event = data ;
@@ -194,6 +228,7 @@ static void handle_outputs_update(struct wl_listener *listener, void *data) {
194
228
if (scale != buffer -> scale || subpixel != buffer -> subpixel ) {
195
229
buffer -> scale = scale ;
196
230
buffer -> subpixel = subpixel ;
231
+ text_calc_size (buffer );
197
232
render_backing_buffer (buffer );
198
233
}
199
234
}
@@ -208,24 +243,6 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
208
243
free (buffer );
209
244
}
210
245
211
- static void text_calc_size (struct text_buffer * buffer ) {
212
- struct sway_text_node * props = & buffer -> props ;
213
-
214
- cairo_t * c = cairo_create (NULL );
215
- if (!c ) {
216
- sway_log (SWAY_ERROR , "cairo_t allocation failed" );
217
- return ;
218
- }
219
-
220
- cairo_set_antialias (c , CAIRO_ANTIALIAS_BEST );
221
- get_text_size (c , config -> font_description , & props -> width , NULL ,
222
- & props -> baseline , 1 , props -> pango_markup , "%s" , buffer -> text );
223
- cairo_destroy (c );
224
-
225
- wlr_scene_buffer_set_dest_size (buffer -> buffer_node ,
226
- get_text_width (props ), props -> height );
227
- }
228
-
229
246
struct sway_text_node * sway_text_node_create (struct wlr_scene_tree * parent ,
230
247
char * text , float color [4 ], bool pango_markup ) {
231
248
struct text_buffer * buffer = calloc (1 , sizeof (* buffer ));
0 commit comments