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

Permits configuring an output transformation. #104

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions etc/wlmaker.plist
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@
Autostart = (
"/usr/bin/foot"
);
Output = {
Transformation = Normal;
};
}
64 changes: 58 additions & 6 deletions src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ static void handle_output_frame(struct wl_listener *listener_ptr,
static void handle_request_state(struct wl_listener *listener_ptr,
void *data_ptr);

/* == Data ================================================================= */

/** Name of the plist dict describing the (default) output configuration. */
static const char *_wlmaker_output_dict_name = "Output";

/** Descriptor for output transformations. */
static const wlmcfg_enum_desc_t _wlmaker_output_transformation_desc[] = {
WLMCFG_ENUM("Normal", WL_OUTPUT_TRANSFORM_NORMAL),
WLMCFG_ENUM("Rotate90", WL_OUTPUT_TRANSFORM_90),
WLMCFG_ENUM("Rotate180", WL_OUTPUT_TRANSFORM_180),
WLMCFG_ENUM("Rotate270", WL_OUTPUT_TRANSFORM_270),
WLMCFG_ENUM("Flip", WL_OUTPUT_TRANSFORM_FLIPPED),
WLMCFG_ENUM("FlipAndRotate90", WL_OUTPUT_TRANSFORM_FLIPPED_90),
WLMCFG_ENUM("FlipAndRotate180", WL_OUTPUT_TRANSFORM_FLIPPED_180),
WLMCFG_ENUM("FlipAndRotate270", WL_OUTPUT_TRANSFORM_FLIPPED_270),
WLMCFG_ENUM_SENTINEL(),
};

/** Descriptor for the output configuration. */
static const wlmcfg_desc_t _wlmaker_output_config_desc[] = {
WLMCFG_DESC_ENUM("Transformation", true, wlmaker_output_t, transformation,
WL_OUTPUT_TRANSFORM_NORMAL,
_wlmaker_output_transformation_desc),
WLMCFG_DESC_SENTINEL()
};

/* == Exported Methods ===================================================== */

/* ------------------------------------------------------------------------- */
Expand All @@ -54,6 +80,25 @@ wlmaker_output_t *wlmaker_output_create(
output_ptr->wlr_scene_ptr = wlr_scene_ptr;
output_ptr->server_ptr = server_ptr;

wlmcfg_dict_t *output_dict_ptr = wlmcfg_dict_get_dict(
server_ptr->config_dict_ptr, _wlmaker_output_dict_name);
if (NULL == output_dict_ptr) {
bs_log(BS_ERROR, "No '%s' dict.", _wlmaker_output_dict_name);
wlmaker_output_destroy(output_ptr);
return NULL;
}
bool decoded = wlmcfg_decode_dict(
output_dict_ptr,
_wlmaker_output_config_desc,
output_ptr);
wlmcfg_dict_unref(output_dict_ptr);
if (!decoded) {
bs_log(BS_ERROR, "Failed to decode '%s' dict",
_wlmaker_output_dict_name);
wlmaker_output_destroy(output_ptr);
return NULL;
}

wlmtk_util_connect_listener_signal(
&output_ptr->wlr_output_ptr->events.destroy,
&output_ptr->output_destroy_listener,
Expand All @@ -79,30 +124,37 @@ wlmaker_output_t *wlmaker_output_create(
wlmaker_output_destroy(output_ptr);
return NULL;
}
wlr_output_enable(output_ptr->wlr_output_ptr, true);

struct wlr_output_state state;
wlr_output_state_init(&state);
wlr_output_state_set_enabled(&state, true);
wlr_output_state_set_transform(&state, output_ptr->transformation);

// Set modes for backends that have them.
if (!wl_list_empty(&output_ptr->wlr_output_ptr->modes)) {
struct wlr_output_mode *mode_ptr = wlr_output_preferred_mode(
output_ptr->wlr_output_ptr);
bs_log(BS_INFO, "Setting mode %dx%d @ %.2fHz",
mode_ptr->width, mode_ptr->height, 1e-3 * mode_ptr->refresh);
wlr_output_set_mode(output_ptr->wlr_output_ptr, mode_ptr);
wlr_output_state_set_mode(&state, mode_ptr);
} else {
bs_log(BS_INFO, "No modes available on %s",
output_ptr->wlr_output_ptr->name);
}

if (!wlr_output_test(output_ptr->wlr_output_ptr)) {
bs_log(BS_ERROR, "Failed wlr_output_test() on %s",
if (!wlr_output_test_state(output_ptr->wlr_output_ptr, &state)) {
bs_log(BS_ERROR, "Failed wlr_output_test_state() on %s",
output_ptr->wlr_output_ptr->name);
wlmaker_output_destroy(output_ptr);
wlr_output_state_finish(&state);
return NULL;
}

// Enable the output and commit.
if (!wlr_output_commit(output_ptr->wlr_output_ptr)) {
bs_log(BS_ERROR, "Failed wlr_output_commit() on %s",
bool rv = wlr_output_commit_state(output_ptr->wlr_output_ptr, &state);
wlr_output_state_finish(&state);
if (!rv) {
bs_log(BS_ERROR, "Failed wlr_output_commit_state() on %s",
output_ptr->wlr_output_ptr->name);
wlmaker_output_destroy(output_ptr);
return NULL;
Expand Down
3 changes: 3 additions & 0 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ struct _wlmaker_output_t {
struct wl_listener output_frame_listener;
/** Listener for `request_state` signals raised by `wlr_output`. */
struct wl_listener output_request_state_listener;

/** Default transformation for the output(s). */
enum wl_output_transform transformation;
};

/**
Expand Down
Loading