Skip to content
Closed
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 116 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct wf_recorder_output
zxdg_output_v1 *zxdg_output;
std::string name, description;
int32_t x, y, width, height;
enum wl_output_transform transform;
};

std::list<wf_recorder_output> available_outputs;
Expand Down Expand Up @@ -461,6 +462,67 @@ static const struct zwp_linux_dmabuf_feedback_v1_listener dmabuf_feedback_listen
.tranche_flags = dmabuf_feedback_tranche_flags,
};

static void
display_handle_geometry(void *data,
struct wl_output *,
int32_t, int32_t,
int32_t,
int32_t,
int32_t,
const char *,
const char *,
int32_t transform)
{
wf_recorder_output *wo = (wf_recorder_output*) data;

wo->transform = (wl_output_transform) transform;
}

static void
display_handle_mode(void *,
struct wl_output *,
uint32_t,
int32_t,
int32_t,
int32_t)
{
}

static void
display_handle_done(void *, struct wl_output *)
{
}

static void
display_handle_scale(void *,
struct wl_output *,
int32_t)
{
}

static void
display_handle_name(void *,
struct wl_output *,
const char *)
{
}

static void
display_handle_description(void *,
struct wl_output *,
const char *)
{
}

static const struct wl_output_listener output_listener = {
display_handle_geometry,
display_handle_mode,
display_handle_done,
display_handle_scale,
display_handle_name,
display_handle_description
};

static void handle_global(void*, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t) {

Expand All @@ -470,6 +532,7 @@ static void handle_global(void*, struct wl_registry *registry,
wf_recorder_output wro;
wro.output = output;
available_outputs.push_back(wro);
wl_output_add_listener(output, &output_listener, &available_outputs.back());
}
else if (strcmp(interface, wl_shm_interface.name) == 0)
{
Expand Down Expand Up @@ -730,7 +793,6 @@ static void sync_wayland()
wl_display_roundtrip(display);
}


static void load_output_info()
{
for (auto& wo : available_outputs)
Expand Down Expand Up @@ -771,13 +833,39 @@ struct capture_region
{
int32_t x, y;
int32_t width, height;
int transform = WL_OUTPUT_TRANSFORM_NORMAL;

capture_region()
: capture_region(0, 0, 0, 0) {}

capture_region(int32_t _x, int32_t _y, int32_t _width, int32_t _height)
: x(_x), y(_y), width(_width), height(_height) { }

void set_transform(const wf_recorder_output& wo) {
transform = wo.transform;
switch (transform) {
case WL_OUTPUT_TRANSFORM_NORMAL:
case WL_OUTPUT_TRANSFORM_180:
case WL_OUTPUT_TRANSFORM_FLIPPED:
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
case WL_OUTPUT_TRANSFORM_90:
fprintf(stderr, "WL_OUTPUT_TRANSFORM_90\n");
std::swap(x, y);
x = -x;
break;
case WL_OUTPUT_TRANSFORM_270:
fprintf(stderr, "WL_OUTPUT_TRANSFORM_270\n");
std::swap(x, y);
y = -y;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
default:
fprintf(stderr, "Transform not found.\n");
break;
}
}

void set_from_string(std::string geometry_string)
{
if (sscanf(geometry_string.c_str(), "%d,%d %dx%d", &x, &y, &width, &height) != 4)
Expand All @@ -796,12 +884,32 @@ struct capture_region

bool contained_in(const capture_region& output) const
{
return
output.x <= x &&
output.x + output.width >= x + width &&
output.y <= y &&
output.y + output.height >= y + height;
}
switch (transform) {
case WL_OUTPUT_TRANSFORM_180:
case WL_OUTPUT_TRANSFORM_FLIPPED:
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
case WL_OUTPUT_TRANSFORM_90:
return
output.x <= abs(x) &&
output.x + output.width >= x + width &&
output.y <= y &&
output.y + output.height >= y + height;
case WL_OUTPUT_TRANSFORM_270:
return
output.x <= x &&
output.x + output.width >= -x + width &&
output.y <= abs(y) &&
output.y + output.height >= y + height;
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
default: //WL_OUTPUT_TRANSFORM_NORMAL
return
output.x <= x &&
output.x + output.width >= x + width &&
output.y <= y &&
output.y + output.height >= y + height;
}
};
};

static wf_recorder_output* detect_output_from_region(const capture_region& region)
Expand Down Expand Up @@ -1269,6 +1377,7 @@ int main(int argc, char *argv[])

if (selected_region.is_selected())
{
selected_region.set_transform(*chosen_output);
if (!selected_region.contained_in({chosen_output->x, chosen_output->y,
chosen_output->width, chosen_output->height}))
{
Expand Down