Skip to content

Commit a5ff6fa

Browse files
committed
fix: format and do not double capture
1 parent e6fb19a commit a5ff6fa

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

main.v

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ fn main() {
197197
mut cm_output := color_manager.get_output(output.wl_output.proxy)
198198
cm_output.add_listener(&cm_output_listener, state)
199199
mut description := cm_output.get_image_description()
200-
description.add_listener(&cm_image_description_listener, output.state)
201-
if C.wl_display_roundtrip(display_proxy) < 0 {
202-
panic('wl_display_roundtrip failed')
203-
}
200+
description.add_listener(&cm_image_description_listener, output.state)
201+
if C.wl_display_roundtrip(display_proxy) < 0 {
202+
panic('wl_display_roundtrip failed')
203+
}
204204
}
205205
}
206206

@@ -228,7 +228,8 @@ fn main() {
228228
} else {
229229
// capture output
230230
for output in state.outputs {
231-
if !geometry_is_cmd && geometry != Geometry{} && !geometry.intersect(output.logical_geometry) {
231+
if !geometry_is_cmd && geometry != Geometry{}
232+
&& !geometry.intersect(output.logical_geometry) {
232233
continue
233234
}
234235
if output.logical_scale > scale {
@@ -244,16 +245,16 @@ fn main() {
244245
// dispatch initial captures to get buffer data for overlays
245246
mut done := false
246247
expected_cm := if state.wp_color_manager_v1 != none { state.outputs.len } else { 0 }
247-
for !done && C.wl_display_dispatch(display_proxy) != -1{
248+
for !done && C.wl_display_dispatch(display_proxy) != -1 {
248249
done = state.n_done == state.captures.len && state.n_cm_done >= expected_cm
249250
}
250251

251252
// run geometry command with freeze
252253
if geometry_is_cmd {
253-
mut geometry_cmd_overlays := []&Overlay{}
254+
mut overlays := []&Overlay{}
254255
for capture in state.captures {
255256
overlay := Overlay.new(capture)
256-
geometry_cmd_overlays << overlay
257+
overlays << overlay
257258
}
258259

259260
// run command in background thread
@@ -263,7 +264,7 @@ fn main() {
263264
ch <- result.output
264265
}(geometry_cmd, result_ch)
265266

266-
// process Wayland events while waiting for command
267+
// process events while waiting for command
267268
mut cmd_output := ''
268269
for {
269270
C.wl_display_dispatch(display_proxy)
@@ -275,35 +276,15 @@ fn main() {
275276
}
276277
}
277278
}
278-
for mut overlay in geometry_cmd_overlays {
279+
280+
for mut overlay in overlays {
279281
overlay.destroy()
280282
}
281-
geometry = Geometry.new(cmd_output.trim('\n')) or { panic('invalid geometry from command') }
282-
state.captures = []
283-
state.n_done = 0
284-
state.n_cm_done = 0
285-
for output in state.outputs {
286-
if geometry != Geometry{} && !geometry.intersect(output.logical_geometry) {
287-
continue
288-
}
289-
if output.logical_scale > scale {
290-
scale = output.logical_scale
291-
}
292-
state.capture_output(output, include_cursor)
293-
}
294-
if state.captures.len == 0 {
295-
panic('no captures found after geometry command')
296-
}
297-
// re-dispatch for new captures
298-
done = false
299-
for !done && C.wl_display_dispatch(display_proxy) != -1{
300-
done = state.n_done == state.captures.len && state.n_cm_done >= expected_cm
301-
}
302-
}
303283

304-
// freeze screen overlay
305-
mut overlays := []&Overlay{}
306-
if freeze_screen_cmd != '' {
284+
// get geometry from command output
285+
geometry = Geometry.new(cmd_output.trim('\n')) or { panic('invalid geometry from command') }
286+
} else if freeze_screen_cmd != '' {
287+
mut overlays := []&Overlay{}
307288
for capture in state.captures {
308289
overlay := Overlay.new(capture)
309290
overlays << overlay
@@ -322,17 +303,20 @@ fn main() {
322303
C.wl_display_flush(display_proxy)
323304
select {
324305
exit_code := <-ch {
325-
for mut overlay in overlays {
326-
overlay.destroy()
327-
}
328306
if exit_code != 0 {
329307
eprintln('freeze command exited with code ${exit_code}')
330308
}
331309
break
332310
}
333311
}
334312
}
313+
314+
for mut overlay in overlays {
315+
overlay.destroy()
316+
}
335317
}
318+
319+
// get default geometry if none provided
336320
if geometry == Geometry{0, 0, 0, 0} {
337321
geometry = state.get_extents()
338322
}
@@ -367,7 +351,9 @@ fn main() {
367351
mut stdout := os.stdout()
368352
stdout.write(encoded) or { panic('Failed to write to stdout') }
369353
} else {
370-
os.write_bytes(output_filename, encoded) or { panic('Failed to write to file ${output_filename}') }
354+
os.write_bytes(output_filename, encoded) or {
355+
panic('Failed to write to file ${output_filename}')
356+
}
371357
}
372358

373359
// destroy

0 commit comments

Comments
 (0)