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

Draft: Json chooser v2: A complex chooser to handle options #228

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .builds/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ packages:
- scdoc
- libdrm
- mesa-dev
- json-c-dev
sources:
- https://github.com/emersion/xdg-desktop-portal-wlr
tasks:
Expand Down
1 change: 1 addition & 0 deletions .builds/archlinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages:
- libinih
- scdoc
- mesa
- json-c
sources:
- https://github.com/emersion/xdg-desktop-portal-wlr
tasks:
Expand Down
1 change: 1 addition & 0 deletions .builds/freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ packages:
- scdoc
- graphics/libdrm
- graphics/mesa-libs
- json-c
sources:
- https://github.com/emersion/xdg-desktop-portal-wlr
tasks:
Expand Down
53 changes: 53 additions & 0 deletions chooser-protocol.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"request": {
"version": 1,
"revision": 0,
"monitors": [
{
"name": "Name1",
"make": "Make1",
"model": "Model1",
"id": 1
},
{
"name": "Name2",
"make": "Make2",
"model": "Model2",
"id": 2
}
],
"windows": [
{
"title": "Title1",
"app_id": "App_Id1",
"id": 1
},
{
"title": "Title2",
"app_id": "App_Id2",
"id": 2
}
],
"options": {
"persist_mode": [
{"none": 0},
{"transient": 1},
{"permanent": 2}
]
}
},
"response": {
"version": 1,
"revision": 0,
"target_type": "output",
"target": {
"name": "Name1",
"make": "Make1",
"model": "Model1",
"id": 1
},
"options": {
"persist_mode": 0
}
}
}
30 changes: 30 additions & 0 deletions contrib/dmenu-chooser-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

chooser=$1

read -r json
echo "$json" >&2
output=$(echo $json | jq '.monitors | .[] | (.id|tostring) + ":" + .name + ":" + .make + ":" + .model' | tr -d '"' | ${chooser:="wofi -d"})
ret=$!
version=$(echo $json | jq '.version|tostring')
revision=$(echo $json | jq '.revision|tostring')
target_type=monitor
IFS=":" read -r id name make model <<<"$output"
echo "version:$version" >&2
echo "revision:$revision" >&2
echo "target_type:$target_type" >&2
echo "name:$name" >&2
echo "model:$model" >&2
echo "make:$make" >&2
echo "id $id" >&2

jq -c --null-input \
--argjson version $version \
--argjson revision $revision \
--arg target_type "$target_type" \
--arg name "$name" \
--arg model "$model" \
--arg make "$make" \
--argjson id $id \
'{"version": $version, "revision": $revision, "target_type": $target_type, "target": { "name": $name, "model": $model, "make": $make, "id": $id }}'
exit $ret
12 changes: 12 additions & 0 deletions include/screencast_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum xdpw_chooser_types {
XDPW_CHOOSER_NONE,
XDPW_CHOOSER_SIMPLE,
XDPW_CHOOSER_DMENU,
XDPW_CHOOSER_JSON,
};

enum xdpw_frame_state {
Expand All @@ -56,6 +57,17 @@ struct xdpw_output_chooser {
char *cmd;
};

struct xdpw_chooser_opts {
struct wl_list *output_list;

// XDPW_CHOOSER_JSON
uint32_t target_mask;
enum persist_modes persist_mode;

// XDPW_CHOOSER_NONE
char *outputname;
};

struct xdpw_frame_damage {
uint32_t x;
uint32_t y;
Expand Down
3 changes: 2 additions & 1 deletion include/wlr_screencast.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ struct xdpw_state;
int xdpw_wlr_screencopy_init(struct xdpw_state *state);
void xdpw_wlr_screencopy_finish(struct xdpw_screencast_context *ctx);

bool xdpw_wlr_target_chooser(struct xdpw_screencast_context *ctx, struct xdpw_screencast_target *target);
bool xdpw_wlr_target_chooser(struct xdpw_output_chooser *chooser, struct xdpw_chooser_opts *opts,
struct xdpw_screencast_target *target);
bool xdpw_wlr_target_from_data(struct xdpw_screencast_context *ctx, struct xdpw_screencast_target *target,
struct xdpw_screencast_restore_data *data);

Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ wayland_protos = dependency('wayland-protocols', version: '>=1.24')
iniparser = dependency('inih')
gbm = dependency('gbm')
drm = dependency('libdrm')
jsonc = dependency('json-c')

epoll = dependency('', required: false)
if (not cc.has_function('timerfd_create', prefix: '#include <sys/timerfd.h>') or
Expand Down Expand Up @@ -90,6 +91,7 @@ executable(
iniparser,
gbm,
drm,
jsonc,
epoll,
],
include_directories: [inc],
Expand Down
28 changes: 11 additions & 17 deletions src/screencast/screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,17 @@ bool setup_target(struct xdpw_screencast_context *ctx, struct xdpw_session *sess
target_initialized = xdpw_wlr_target_from_data(ctx, target, data);
}
if (!target_initialized) {
target_initialized = xdpw_wlr_target_chooser(ctx, target);
//TODO: Chooser option to confirm the persist mode
const char *env_persist_str = getenv("XDPW_PERSIST_MODE");
if (env_persist_str) {
if (strcmp(env_persist_str, "transient") == 0) {
sess->screencast_data.persist_mode = sess->screencast_data.persist_mode > PERSIST_TRANSIENT
? PERSIST_TRANSIENT : sess->screencast_data.persist_mode;
} else if (strcmp(env_persist_str, "permanent") == 0) {
sess->screencast_data.persist_mode = sess->screencast_data.persist_mode > PERSIST_PERMANENT
? PERSIST_PERMANENT : sess->screencast_data.persist_mode;
} else {
sess->screencast_data.persist_mode = PERSIST_NONE;
}

} else {
sess->screencast_data.persist_mode = PERSIST_NONE;
}
struct xdpw_output_chooser chooser = {
.cmd = ctx->state->config->screencast_conf.chooser_cmd,
.type = ctx->state->config->screencast_conf.chooser_type,
};
struct xdpw_chooser_opts chooser_opts = {
.output_list = &ctx->output_list,
.target_mask = (1<<MONITOR),
.persist_mode = sess->screencast_data.persist_mode,
.outputname = ctx->state->config->screencast_conf.output_name,
};
target_initialized = xdpw_wlr_target_chooser(&chooser, &chooser_opts, target);
}
if (!target_initialized) {
logprint(ERROR, "wlroots: no output found");
Expand Down
4 changes: 4 additions & 0 deletions src/screencast/screencast_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ enum xdpw_chooser_types get_chooser_type(const char *chooser_type) {
return XDPW_CHOOSER_SIMPLE;
} else if (strcmp(chooser_type, "dmenu") == 0) {
return XDPW_CHOOSER_DMENU;
} else if (strcmp(chooser_type, "json") == 0) {
return XDPW_CHOOSER_JSON;
}
fprintf(stderr, "Could not understand chooser type %s\n", chooser_type);
exit(1);
Expand All @@ -406,6 +408,8 @@ const char *chooser_type_str(enum xdpw_chooser_types chooser_type) {
return "simple";
case XDPW_CHOOSER_DMENU:
return "dmenu";
case XDPW_CHOOSER_JSON:
return "json";
}
fprintf(stderr, "Could not find chooser type %d\n", chooser_type);
abort();
Expand Down