Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: clipboard option freezes everything when used with slurp #109

Open
Gigas002 opened this issue Mar 27, 2024 · 14 comments · Fixed by #110
Open

Bug: clipboard option freezes everything when used with slurp #109

Gigas002 opened this issue Mar 27, 2024 · 14 comments · Fixed by #110

Comments

@Gigas002
Copy link

Built from freeze-feat-andreas branch. Just running wayshot --clipboard works fine, but when trying to run wayshot --clipboard -s "slurp" compositor freezes, until wayshot is killed from tty

@Shinyzenith
Copy link
Member

I think I misunderstood your issue. Apologies.

@Shinyzenith
Copy link
Member

CC: @CheerfulPianissimo

@CheerfulPianissimo
Copy link

CheerfulPianissimo commented Mar 28, 2024

Can reproduce. Sway does not actually freeze but you have to full-screen apps before you can interact with them. Likely a bad interaction between freeze-feat's use of callbacks+layer-shell and wl-clipboard-rs's thread use or our own daemonization functionality. Will look into it.

@CheerfulPianissimo
Copy link

CheerfulPianissimo commented Mar 28, 2024

My preliminary theory is that freeze-feat destroys the overlay shell surface as a side effect of the program terminating rather than removing it manually on completion of selection, so when wayshot persists instead of terminating immediately to keep the image on the clipboard, the layer shell does too. Could this be plausible @AndreasBackx ?

@CheerfulPianissimo
Copy link

yeah that seems to have been it. Have a patch solving this.

@AndreasBackx
Copy link
Member

@CheerfulPianissimo your assertion seems very likely. It made me look into why we're doing it this way in the first place and I looked into the unsafe code for the clipboard stuff.

@Shinyzenith, I don't fully understand why we need to fork here. Could you explain why we cnanot piggyback on the wl-clipboard implementation? It it because you did not want this to block and it's blocking for a long time?

Also, from my understanding of daemonisation (I'm using it quite extensively at work as a "hack" to make sure terminals exit quickly and can do some work afterwards), this is not daemonisation. We are forking, but we are not "daemonising" the process. That requires a second fork and a setsid call. Unless the Rust stuff does it differently somewhat, the current behaviour simply has 2 processes but should not exit earlier than without this forking code. Though please correct me if I'm wrong.

@CheerfulPianissimo
Copy link

The rationale for doing the fork is explained here: #89 (comment)

It it because you did not want this to block and it's blocking for a long time?

Yes, it blocks till the user copies something else to the clipboard. We could just block stdout and not exit till this happens but that would be surprising behavior imo and would not be in line with the other clipboard tools in the ecosystem like wl-copy.

Unless the Rust stuff does it differently somewhat, the current behaviour simply has 2 processes but should not exit earlier than without this forking code.

Presently wayshot forks and exits while the forked child process sets wl-clipboard's foreground option to true and calls copy. Only one process remains as the parent process' clipboard_daemonize returns Ok and immediately reaches the end of the main function.

My goal here was to basically disconnect wayshot from the terminal it's running in along with the stdout/stdin/stderr. I searched around a bit and this seemed to be the idiomatic unix way to do this. Do you have any suggestions to improve this @AndreasBackx ?

Shinyzenith pushed a commit that referenced this issue Apr 6, 2024
…#109 (#110)

* feat(clipboard): fix interaction with freeze and select feature:  Issue #109

* feat(clipboard): handle callback fails
@Gigas002
Copy link
Author

Checked out running after merging #110, have this error after slurp is done with selecting:

Protocol error 1 on object wl_display@1: invalid method 1 (since 1 < 3), object zwlr_layer_shell_v1@12
Error: dispatch error: Backend error: Protocol error 1 on object wl_display@1: invalid method 1 (since 1 < 3), object zwlr_layer_shell_v1@12

Caused by:
   0: Backend error: Protocol error 1 on object wl_display@1: invalid method 1 (since 1 < 3), object zwlr_layer_shell_v1@12
   1: Protocol error 1 on object wl_display@1: invalid method 1 (since 1 < 3), object zwlr_layer_shell_v1@12

Location:
    wayshot/src/wayshot.rs:71:9

@CheerfulPianissimo
Copy link

Can reproduce this but not consistently (about 1 in 6 times?). Happens without the --clipboard flag too. Does this reproduce consistently for you @Gigas002 ? What command are you using?

@CheerfulPianissimo
Copy link

Some logs:

Logs

 WAYLAND_DEBUG=1 cargo run -- -s ""
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/wayshot -s ''`
[4252678.226][rs] -> [email protected]_registry(wl_registry@2)
[4252678.291][rs] -> [email protected](wl_callback@3)
[4252678.473][rs] <- [email protected], (1, Some("wl_shm"), 1)
[4252678.568][rs] <- [email protected], (2, Some("wl_drm"), 2)
[4252678.634][rs] <- [email protected], (3, Some("zwp_linux_dmabuf_v1"), 4)
[4252678.726][rs] <- [email protected], (4, Some("wl_compositor"), 6)
[4252678.802][rs] <- [email protected], (5, Some("wl_subcompositor"), 1)
[4252678.889][rs] <- [email protected], (6, Some("wl_data_device_manager"), 3)
[4252678.990][rs] <- [email protected], (7, Some("zwlr_gamma_control_manager_v1"), 1)
[4252679.102][rs] <- [email protected], (8, Some("zxdg_output_manager_v1"), 3)
[4252679.204][rs] <- [email protected], (9, Some("ext_idle_notifier_v1"), 1)
[4252679.287][rs] <- [email protected], (10, Some("zwp_idle_inhibit_manager_v1"), 1)
[4252679.441][rs] <- [email protected], (11, Some("zwlr_layer_shell_v1"), 4)
[4252679.585][rs] <- [email protected], (12, Some("xdg_wm_base"), 2)
[4252679.671][rs] <- [email protected], (13, Some("zwp_tablet_manager_v2"), 1)
[4252679.773][rs] <- [email protected], (14, Some("org_kde_kwin_server_decoration_manager"), 1)
[4252679.896][rs] <- [email protected], (15, Some("zxdg_decoration_manager_v1"), 1)
[4252679.970][rs] <- [email protected], (16, Some("zwp_relative_pointer_manager_v1"), 1)
[4252680.095][rs] <- [email protected], (17, Some("zwp_pointer_constraints_v1"), 1)
[4252680.211][rs] <- [email protected], (18, Some("wp_presentation"), 1)
[4252680.302][rs] <- [email protected], (19, Some("zwlr_output_manager_v1"), 4)
[4252680.433][rs] <- [email protected], (20, Some("zwlr_output_power_manager_v1"), 1)
[4252680.555][rs] <- [email protected], (21, Some("zwp_input_method_manager_v2"), 1)
[4252680.663][rs] <- [email protected], (22, Some("zwp_text_input_manager_v3"), 1)
[4252680.778][rs] <- [email protected], (23, Some("zwlr_foreign_toplevel_manager_v1"), 3)
[4252680.916][rs] <- [email protected], (24, Some("ext_session_lock_manager_v1"), 1)
[4252681.063][rs] <- [email protected], (25, Some("wp_drm_lease_device_v1"), 1)
[4252681.168][rs] <- [email protected], (26, Some("zwlr_export_dmabuf_manager_v1"), 1)
[4252681.277][rs] <- [email protected], (27, Some("zwlr_screencopy_manager_v1"), 3)
[4252681.479][rs] <- [email protected], (28, Some("zwlr_data_control_manager_v1"), 2)
[4252681.600][rs] <- [email protected], (29, Some("wp_security_context_manager_v1"), 1)
[4252681.712][rs] <- [email protected], (30, Some("wp_viewporter"), 1)
[4252681.794][rs] <- [email protected], (31, Some("wp_single_pixel_buffer_manager_v1"), 1)
[4252681.919][rs] <- [email protected], (32, Some("wp_content_type_manager_v1"), 1)
[4252682.031][rs] <- [email protected], (33, Some("wp_fractional_scale_manager_v1"), 1)
[4252682.150][rs] <- [email protected], (34, Some("zxdg_exporter_v1"), 1)
[4252682.248][rs] <- [email protected], (35, Some("zxdg_importer_v1"), 1)
[4252682.334][rs] <- [email protected], (36, Some("zxdg_exporter_v2"), 1)
[4252682.437][rs] <- [email protected], (37, Some("zxdg_importer_v2"), 1)
[4252682.518][rs] <- [email protected], (38, Some("xdg_activation_v1"), 1)
[4252682.608][rs] <- [email protected], (39, Some("wp_cursor_shape_manager_v1"), 1)
[4252682.724][rs] <- [email protected], (40, Some("zwp_virtual_keyboard_manager_v1"), 1)
[4252682.883][rs] <- [email protected], (41, Some("zwlr_virtual_pointer_manager_v1"), 2)
[4252683.024][rs] <- [email protected], (42, Some("zwlr_input_inhibit_manager_v1"), 1)
[4252683.161][rs] <- [email protected], (43, Some("zwp_keyboard_shortcuts_inhibit_manager_v1"), 1)
[4252683.316][rs] <- [email protected], (44, Some("zwp_pointer_gestures_v1"), 3)
[4252683.422][rs] <- [email protected], (45, Some("wl_seat"), 8)
[4252683.481][rs] <- [email protected], (47, Some("zwp_primary_selection_device_manager_v1"), 1)
[4252683.595][rs] <- [email protected], (48, Some("wl_output"), 4)
[4252683.656][rs] <- [email protected], (212556)
[4252683.689][rs] <- [email protected]_id, (3)
[4252683.810][rs] -> [email protected](8, Some("zxdg_output_manager_v1"), 3, zxdg_output_manager_v1@3)
[4252683.990][rs] -> [email protected]_registry(wl_registry@4)
[4252684.045][rs] -> [email protected](wl_callback@5)
[4252684.324][rs] <- [email protected], (1, Some("wl_shm"), 1)
[4252684.444][rs] <- [email protected], (2, Some("wl_drm"), 2)
[4252684.509][rs] <- [email protected], (3, Some("zwp_linux_dmabuf_v1"), 4)
[4252684.584][rs] <- [email protected], (4, Some("wl_compositor"), 6)
[4252684.650][rs] <- [email protected], (5, Some("wl_subcompositor"), 1)
[4252684.731][rs] <- [email protected], (6, Some("wl_data_device_manager"), 3)
[4252684.814][rs] <- [email protected], (7, Some("zwlr_gamma_control_manager_v1"), 1)
[4252684.918][rs] <- [email protected], (8, Some("zxdg_output_manager_v1"), 3)
[4252685.006][rs] <- [email protected], (9, Some("ext_idle_notifier_v1"), 1)
[4252685.091][rs] <- [email protected], (10, Some("zwp_idle_inhibit_manager_v1"), 1)
[4252685.183][rs] <- [email protected], (11, Some("zwlr_layer_shell_v1"), 4)
[4252685.263][rs] <- [email protected], (12, Some("xdg_wm_base"), 2)
[4252685.324][rs] <- [email protected], (13, Some("zwp_tablet_manager_v2"), 1)
[4252685.433][rs] <- [email protected], (14, Some("org_kde_kwin_server_decoration_manager"), 1)
[4252685.578][rs] <- [email protected], (15, Some("zxdg_decoration_manager_v1"), 1)
[4252685.706][rs] <- [email protected], (16, Some("zwp_relative_pointer_manager_v1"), 1)
[4252685.841][rs] <- [email protected], (17, Some("zwp_pointer_constraints_v1"), 1)
[4252685.974][rs] <- [email protected], (18, Some("wp_presentation"), 1)
[4252686.065][rs] <- [email protected], (19, Some("zwlr_output_manager_v1"), 4)
[4252686.176][rs] <- [email protected], (20, Some("zwlr_output_power_manager_v1"), 1)
[4252686.305][rs] <- [email protected], (21, Some("zwp_input_method_manager_v2"), 1)
[4252686.440][rs] <- [email protected], (22, Some("zwp_text_input_manager_v3"), 1)
[4252686.551][rs] <- [email protected], (23, Some("zwlr_foreign_toplevel_manager_v1"), 3)
[4252686.650][rs] <- [email protected], (24, Some("ext_session_lock_manager_v1"), 1)
[4252686.743][rs] <- [email protected], (25, Some("wp_drm_lease_device_v1"), 1)
[4252686.839][rs] <- [email protected], (26, Some("zwlr_export_dmabuf_manager_v1"), 1)
[4252686.935][rs] <- [email protected], (27, Some("zwlr_screencopy_manager_v1"), 3)
[4252687.039][rs] <- [email protected], (28, Some("zwlr_data_control_manager_v1"), 2)
[4252687.140][rs] <- [email protected], (29, Some("wp_security_context_manager_v1"), 1)
[4252687.240][rs] <- [email protected], (30, Some("wp_viewporter"), 1)
[4252687.311][rs] <- [email protected], (31, Some("wp_single_pixel_buffer_manager_v1"), 1)
[4252687.432][rs] <- [email protected], (32, Some("wp_content_type_manager_v1"), 1)
[4252687.526][rs] <- [email protected], (33, Some("wp_fractional_scale_manager_v1"), 1)
[4252687.635][rs] <- [email protected], (34, Some("zxdg_exporter_v1"), 1)
[4252687.708][rs] <- [email protected], (35, Some("zxdg_importer_v1"), 1)
[4252687.783][rs] <- [email protected], (36, Some("zxdg_exporter_v2"), 1)
[4252687.857][rs] <- [email protected], (37, Some("zxdg_importer_v2"), 1)
[4252687.928][rs] <- [email protected], (38, Some("xdg_activation_v1"), 1)
[4252688.008][rs] <- [email protected], (39, Some("wp_cursor_shape_manager_v1"), 1)
[4252688.109][rs] <- [email protected], (40, Some("zwp_virtual_keyboard_manager_v1"), 1)
[4252688.212][rs] <- [email protected], (41, Some("zwlr_virtual_pointer_manager_v1"), 2)
[4252688.319][rs] <- [email protected], (42, Some("zwlr_input_inhibit_manager_v1"), 1)
[4252688.450][rs] <- [email protected], (43, Some("zwp_keyboard_shortcuts_inhibit_manager_v1"), 1)
[4252688.563][rs] <- [email protected], (44, Some("zwp_pointer_gestures_v1"), 3)
[4252688.643][rs] <- [email protected], (45, Some("wl_seat"), 8)
[4252688.716][rs] <- [email protected], (47, Some("zwp_primary_selection_device_manager_v1"), 1)
[4252688.859][rs] <- [email protected], (48, Some("wl_output"), 4)
[4252688.933][rs] <- [email protected], (212556)
[4252688.964][rs] <- [email protected]_id, (5)
[4252689.096][rs] -> [email protected](48, Some("wl_output"), 4, wl_output@5)
[4252689.210][rs] -> [email protected]_xdg_output(zxdg_output_v1@6, wl_output@5)
[4252689.261][rs] -> [email protected](wl_callback@7)
[4252689.549][rs] <- [email protected], (0, 0, 340, 190, 0, Some("AU Optronics"), Some("0x499F"), 0)
[4252689.708][rs] <- [email protected], (1, 1920, 1080, 60056)
[4252689.753][rs] <- [email protected], (1)
[4252689.785][rs] <- [email protected], (Some("eDP-1"))
[4252689.838][rs] <- [email protected], (Some("AU Optronics 0x499F (eDP-1)"))
[4252689.933][rs] <- [email protected], ()
[4252689.963][rs] <- [email protected], (Some("eDP-1"))
[4252690.021][rs] <- [email protected], (Some("AU Optronics 0x499F (eDP-1)"))
[4252690.118][rs] <- [email protected]_position, (0, 0)
[4252690.165][rs] <- [email protected]_size, (1920, 1080)
[4252690.201][rs] <- [email protected], ()
[4252690.233][rs] <- [email protected], (212556)
[4252690.269][rs] <- [email protected]_id, (7)
[4252690.459][rs] -> [email protected]()
[4252691.346][rs] -> [email protected](27, Some("zwlr_screencopy_manager_v1"), 3, zwlr_screencopy_manager_v1@7)
[4252691.612][rs] -> [email protected]_output(zwlr_screencopy_frame_v1@8, 0, wl_output@5)
[4252691.871][rs] <- [email protected]_id, (6)
[4252691.912][rs] <- [email protected], (875709016, 1920, 1080, 7680)
[4252692.001][rs] <- [email protected]_dmabuf, (875713112, 1920, 1080)
[4252692.052][rs] <- [email protected]_done, ()
[4252692.169][rs] -> [email protected](1, Some("wl_shm"), 1, wl_shm@6)
[4252692.274][rs] -> [email protected]_pool(wl_shm_pool@9, 4, 8294400)
[4252692.344][rs] -> [email protected]_buffer(wl_buffer@10, 0, 1920, 1080, 7680, 875709016)
[4252692.455][rs] -> [email protected](wl_buffer@10)
[4252692.657][rs] <- [email protected], (0)
[4252692.706][rs] <- [email protected], (1)
[4252692.741][rs] <- [email protected], (875709016)
[4252692.775][rs] <- [email protected], (875708993)
[4252692.812][rs] <- [email protected], (875710274)
[4252692.849][rs] <- [email protected], (842094674)
[4252692.887][rs] <- [email protected], (842088786)
[4252692.924][rs] <- [email protected], (892426322)
[4252692.962][rs] <- [email protected], (892420434)
[4252693.009][rs] <- [email protected], (909199186)
[4252693.050][rs] <- [email protected], (808665688)
[4252693.091][rs] <- [email protected], (808665665)
[4252693.130][rs] <- [email protected], (1211384408)
[4252693.165][rs] <- [email protected], (1211384385)
[4252693.211][rs] <- [email protected], (942948952)
[4252693.246][rs] <- [email protected], (942948929)
[4252717.769][rs] <- [email protected], (0)
[4252717.832][rs] <- [email protected], (0, 113940, 722237399)
[4252717.870][rs] <- [email protected], ()
[4252718.382][rs] -> [email protected](4, Some("wl_compositor"), 3, wl_compositor@11)
[4252718.649][rs] -> [email protected](11, Some("zwlr_layer_shell_v1"), 1, zwlr_layer_shell_v1@12)
[4252718.767][rs] -> [email protected]_surface(wl_surface@13)
[4252718.853][rs] -> [email protected]_layer_surface(zwlr_layer_surface_v1@14, wl_surface@13, wl_output@5, 2, Some("wayshot"))
[4252718.972][rs] -> [email protected]_exclusive_zone(-1)
[4252719.011][rs] -> [email protected]_anchor(5)
[4252719.051][rs] -> [email protected]_size(1920, 1080)
[4252719.096][rs] -> [email protected]()
[4252719.432][rs] <- [email protected], (wl_output@5)
[4252719.516][rs] <- [email protected], (212558, 1920, 1080)
[4252719.594][rs] <- [email protected], (212561, 1920, 1080)
[4252719.717][rs] -> [email protected]_configure(212558)
[4252719.777][rs] -> [email protected]_configure(212561)
[4252719.833][rs] -> [email protected]_buffer_transform(0)
[4252719.887][rs] -> [email protected](wl_buffer@10, 0, 0)
[4252719.954][rs] -> [email protected]()
[4252727.892][rs] <- [email protected], (212565, 1920, 1080)
[4252728.031][rs] <- [email protected], ()
[4252728.222][rs] -> [email protected]_configure(212565)
[4253394.079][rs] -> [email protected]()
[4253394.235][rs] <- [email protected], (212569, 1920, 1080)
[4253394.294][rs] <- [email protected], (212573, 1920, 1080)
[4253394.339][rs] <- [email protected], (212578, 1920, 1080)
[4253394.427][rs] <- [email protected], (212589, 1920, 1080)
[4253394.524][rs] <- [email protected], (1, 1, Some("invalid method 1 (since 1 < 3), object zwlr_layer_shell_v1@12"))
Protocol error 1 on object wl_display@1: invalid method 1 (since 1 < 3), object zwlr_layer_shell_v1@12
[4253394.766][rs] -> [email protected]()
[4253394.807][rs] -> [email protected]()
Error: dispatch error: Backend error: Protocol error 1 on object wl_display@1: invalid method 1 (since 1 < 3), object zwlr_layer_shell_v1@12

Caused by:
   0: Backend error: Protocol error 1 on object wl_display@1: invalid method 1 (since 1 < 3), object zwlr_layer_shell_v1@12
   1: Protocol error 1 on object wl_display@1: invalid method 1 (since 1 < 3), object zwlr_layer_shell_v1@12

Location:
    wayshot/src/wayshot.rs:71:9

Could be a case of use after destroy? [email protected]() is called but the error is that method 1(get_layer_surface?) is getting called on zwlr_layer_shell_v1@12 after the fact.

@Gigas002
Copy link
Author

Does this reproduce consistently for you @Gigas002 ? What command are you using?

Yeah, happens every time for me. Running wayshot --clipboard -s "d"

@CheerfulPianissimo
Copy link

Which compositor are you using @Gigas002 ?

@Gigas002
Copy link
Author

I'm using hyprland

@CheerfulPianissimo
Copy link

CheerfulPianissimo commented Apr 12, 2024

I'm using sway. Alright, I have a patch that solves this. The existing code destroys the layer_shell object instead of the layer_surface objects, destroying only layer_surface objects seems to solve the issue but destroying both in that order doesn't. It isn't clear to me why this is the case but I'll create a PR for you to test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants