From 9107b90fb3bf381797e0f0d73d34c7015df7f597 Mon Sep 17 00:00:00 2001 From: Lain Date: Mon, 2 Sep 2024 13:07:35 -0700 Subject: [PATCH] linux-capture: Fix xshm capturing first display on creation Like xcomposite, this was programmed to select the first display by default. Change it to not capture any display unless explicitly selected by the user. --- plugins/linux-capture/data/locale/en-US.ini | 1 + plugins/linux-capture/linux-capture.c | 2 + plugins/linux-capture/xshm-input.c | 59 +++++++++++++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/plugins/linux-capture/data/locale/en-US.ini b/plugins/linux-capture/data/locale/en-US.ini index 45184085e..ab8a00eff 100644 --- a/plugins/linux-capture/data/locale/en-US.ini +++ b/plugins/linux-capture/data/locale/en-US.ini @@ -12,4 +12,5 @@ CropBottom="Crop Bottom" IncludeXBorder="Include X Border" ExcludeAlpha="Use alpha-less texture format (Mesa workaround)" SelectAWindow="[Select a window to capture]" +SelectADisplay="[Select a display to capture]" UnknownWindow="[Unknown window]" diff --git a/plugins/linux-capture/linux-capture.c b/plugins/linux-capture/linux-capture.c index 60cf76a4a..b17880e3e 100644 --- a/plugins/linux-capture/linux-capture.c +++ b/plugins/linux-capture/linux-capture.c @@ -26,6 +26,7 @@ MODULE_EXPORT const char *obs_module_description(void) } extern struct obs_source_info xshm_input; +extern struct obs_source_info xshm_input_v2; bool obs_module_load(void) { @@ -33,6 +34,7 @@ bool obs_module_load(void) if (platform == OBS_NIX_PLATFORM_X11_EGL) { obs_register_source(&xshm_input); + obs_register_source(&xshm_input_v2); xcomposite_load(); } diff --git a/plugins/linux-capture/xshm-input.c b/plugins/linux-capture/xshm-input.c index 252625a06..cc11ebe17 100644 --- a/plugins/linux-capture/xshm-input.c +++ b/plugins/linux-capture/xshm-input.c @@ -32,6 +32,8 @@ along with this program. If not, see . #define blog(level, msg, ...) blog(level, "xshm-input: " msg, ##__VA_ARGS__) +#define INVALID_DISPLAY (-1) + struct xshm_data { obs_source_t *source; @@ -41,7 +43,7 @@ struct xshm_data { xcb_xcursor_t *cursor; char *server; - uint_fast32_t screen_id; + int_fast32_t screen_id; int_fast32_t x_org; int_fast32_t y_org; int_fast32_t width; @@ -225,6 +227,16 @@ static void xshm_capture_start(struct xshm_data *data) const char *server = (data->advanced && *data->server) ? data->server : NULL; + if (data->screen_id == -1) { + if (data->texture) { + gs_texture_destroy(data->texture); + data->texture = NULL; + } + data->adj_width = 0; + data->adj_height = 0; + return; + } + data->xcb = xcb_connect(server, NULL); if (!data->xcb || xcb_connection_has_error(data->xcb)) { blog(LOG_ERROR, "Unable to open X display !"); @@ -288,9 +300,10 @@ static void xshm_update(void *vptr, obs_data_t *settings) /** * Get the default settings for the capture */ -static void xshm_defaults(obs_data_t *defaults) +static void xshm_defaults(obs_data_t *defaults, int ver) { - obs_data_set_default_int(defaults, "screen", 0); + obs_data_set_default_int(defaults, "screen", + ver == 1 ? 0 : INVALID_DISPLAY); obs_data_set_default_bool(defaults, "show_cursor", true); obs_data_set_default_bool(defaults, "advanced", false); obs_data_set_default_int(defaults, "cut_top", 0); @@ -299,6 +312,16 @@ static void xshm_defaults(obs_data_t *defaults) obs_data_set_default_int(defaults, "cut_bot", 0); } +static void xshm_defaults_v1(obs_data_t *defaults) +{ + xshm_defaults(defaults, 1); +} + +static void xshm_defaults_v2(obs_data_t *defaults) +{ + xshm_defaults(defaults, 2); +} + /** * Toggle visibility of advanced settings */ @@ -335,6 +358,13 @@ static bool xshm_server_changed(obs_properties_t *props, obs_property_t *p, obs_property_list_clear(screens); + if (old_screen == INVALID_DISPLAY) { + obs_property_list_add_int(screens, + obs_module_text("SelectADisplay"), + INVALID_DISPLAY); + obs_property_list_item_disable(screens, 0, true); + } + xcb_connection_t *xcb = xcb_connect(server, NULL); if (!xcb || xcb_connection_has_error(xcb)) { obs_property_set_enabled(screens, false); @@ -579,12 +609,31 @@ struct obs_source_info xshm_input = { .id = "xshm_input", .type = OBS_SOURCE_TYPE_INPUT, .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW | - OBS_SOURCE_DO_NOT_DUPLICATE | OBS_SOURCE_SRGB, + OBS_SOURCE_DO_NOT_DUPLICATE | OBS_SOURCE_SRGB | + OBS_SOURCE_CAP_OBSOLETE, .get_name = xshm_getname, .create = xshm_create, .destroy = xshm_destroy, .update = xshm_update, - .get_defaults = xshm_defaults, + .get_defaults = xshm_defaults_v1, + .get_properties = xshm_properties, + .video_tick = xshm_video_tick, + .video_render = xshm_video_render, + .get_width = xshm_getwidth, + .get_height = xshm_getheight, + .icon_type = OBS_ICON_TYPE_DESKTOP_CAPTURE, +}; + +struct obs_source_info xshm_input_v2 = { + .id = "xshm_input_v2", + .type = OBS_SOURCE_TYPE_INPUT, + .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW | + OBS_SOURCE_DO_NOT_DUPLICATE | OBS_SOURCE_SRGB, + .get_name = xshm_getname, + .create = xshm_create, + .destroy = xshm_destroy, + .update = xshm_update, + .get_defaults = xshm_defaults_v2, .get_properties = xshm_properties, .video_tick = xshm_video_tick, .video_render = xshm_video_render,