Skip to content

Commit

Permalink
screencast: restore window share by class
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed May 25, 2023
1 parent 4f0c575 commit ca077cc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
3 changes: 2 additions & 1 deletion include/screencast_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct xdpw_frame {
uint64_t tv_sec;
uint32_t tv_nsec;
struct xdpw_frame_damage damage[4];
uint32_t damage_count;
uint32_t damage_count;
struct xdpw_buffer *xdpw_buffer;
struct pw_buffer *pw_buffer;
};
Expand Down Expand Up @@ -164,6 +164,7 @@ struct xdpw_share {
struct xdph_restore_token {
char *token;
char *outputPort; // NULL if not set
char *windowClass; // NULL if not set
uint64_t windowHandle; // 0 if not set
struct wl_list link;
bool withCursor;
Expand Down
47 changes: 35 additions & 12 deletions src/screencast/screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,26 @@ bool setup_outputs(struct xdpw_screencast_context *ctx, struct xdpw_session *ses
if (token) {
// attempt to restore
if (token->outputPort) {
struct xdpw_wlr_output *output;
wl_list_for_each(output, &ctx->output_list, link) {
if (strcmp(output->name, token->outputPort) == 0) {
out.output = output;
tokenSuccess = true;
break;
if (strncmp(token->outputPort, "class:", 6) == 0) {
struct SToplevelEntry *current;
wl_list_for_each(current, &ctx->toplevel_resource_list, link) {
if (strcmp(token->outputPort + 6, current->clazz) == 0) {
out.window_handle = token->windowHandle;
tokenSuccess = true;
break;
}
}
} else {
struct xdpw_wlr_output *output;
wl_list_for_each(output, &ctx->output_list, link) {
if (strcmp(output->name, token->outputPort) == 0) {
out.output = output;
tokenSuccess = true;
break;
}
}
}

} else if (token->windowHandle > 0) {
struct SToplevelEntry *current;
wl_list_for_each(current, &ctx->toplevel_resource_list, link) {
Expand Down Expand Up @@ -249,6 +261,16 @@ static struct xdph_restore_token *getRestoreToken(char *sessionToken, struct xdp
restoreToken->token = uuid_str;
restoreToken->withCursor = withCursor;

if (windowSelected) {
struct SToplevelEntry *current;
wl_list_for_each(current, &state->screencast.toplevel_resource_list, link) {
if (current->handle == restoreToken->windowHandle) {
restoreToken->windowClass = getFormat("class:%x", current->clazz);
break;
}
}
}

return restoreToken;
}

Expand Down Expand Up @@ -644,12 +666,13 @@ static int method_screencast_start(sd_bus_message *msg, void *data, sd_bus_error

logprint(DEBUG, "dbus: start: returning node %d", (int)cast->node_id);
if (restoreToken)
ret = sd_bus_message_append(reply, "ua{sv}", PORTAL_RESPONSE_SUCCESS, 3, "streams", "a(ua{sv})", 1, cast->node_id, 3, "position", "(ii)", 0,
0, "size", "(ii)", cast->screencopy_frame_info[WL_SHM].width, cast->screencopy_frame_info[WL_SHM].height,
"source_type", "u", (cast->target.output ? (1 << MONITOR) : (1 << WINDOW)), "persist_mode", "u", sess->persist,
"restore_data", "(suv)", "hyprland", 2, "(susbt)" /* amogus */, restoreToken->token, restoreToken->windowHandle,
(restoreToken->outputPort == NULL ? "" : restoreToken->outputPort), restoreToken->withCursor,
(unsigned long)time(NULL));
ret = sd_bus_message_append(
reply, "ua{sv}", PORTAL_RESPONSE_SUCCESS, 3, "streams", "a(ua{sv})", 1, cast->node_id, 3, "position", "(ii)", 0, 0, "size", "(ii)",
cast->screencopy_frame_info[WL_SHM].width, cast->screencopy_frame_info[WL_SHM].height, "source_type", "u",
(cast->target.output ? (1 << MONITOR) : (1 << WINDOW)), "persist_mode", "u", sess->persist, "restore_data", "(suv)", "hyprland", 2,
"(susbt)" /* amogus */, restoreToken->token, restoreToken->windowHandle,
(restoreToken->outputPort == NULL ? (restoreToken->windowHandle ? restoreToken->windowClass : "") : restoreToken->outputPort),
restoreToken->withCursor, (unsigned long)time(NULL));
else
ret = sd_bus_message_append(reply, "ua{sv}", PORTAL_RESPONSE_SUCCESS, 1, "streams", "a(ua{sv})", 1, cast->node_id, 3, "position", "(ii)", 0,
0, "size", "(ii)", cast->screencopy_frame_info[WL_SHM].width, cast->screencopy_frame_info[WL_SHM].height,
Expand Down

0 comments on commit ca077cc

Please sign in to comment.