Skip to content

Commit

Permalink
output-layout: mark custom modes explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Jun 19, 2024
1 parent 1123ecd commit 77f6792
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/api/wayfire/output-layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ struct output_state_t
/** Only width, height and refresh fields are used. */
wlr_output_mode mode;

/** Whether a custom mode was requested for the output. */
bool uses_custom_mode = false;

/* The transform of the output */
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
/* The scale of the output */
Expand Down
2 changes: 1 addition & 1 deletion src/api/wayfire/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class plugin_interface_t
using wayfire_plugin_load_func = wf::plugin_interface_t * (*)();

/** The version of Wayfire's API/ABI */
constexpr uint32_t WAYFIRE_API_ABI_VERSION = 2024'04'16;
constexpr uint32_t WAYFIRE_API_ABI_VERSION = 2024'04'17;

/**
* Each plugin must also provide a function which returns the Wayfire API/ABI
Expand Down
14 changes: 10 additions & 4 deletions src/core/output-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static wl_output_transform get_transform_from_string(std::string transform)
}

wlr_output_mode *find_matching_mode(wlr_output *output,
const wlr_output_mode& reference)
const wlr_output_mode& reference, bool exact_match = false)
{
wlr_output_mode *mode;
wlr_output_mode *best = NULL;
Expand All @@ -82,6 +82,11 @@ wlr_output_mode *find_matching_mode(wlr_output *output,
return mode;
}

if (exact_match)
{
continue;
}

const int best_so_far = best ? std::abs(best->refresh - target_refresh) : INT_MAX;
const int current = std::abs(mode->refresh - target_refresh);
if (!best || (best_so_far > current))
Expand Down Expand Up @@ -601,7 +606,7 @@ struct output_layout_output_t
}

/** Change the output mode */
void apply_mode(const wlr_output_mode& mode)
void apply_mode(const wlr_output_mode& mode, bool custom_mode)
{
if (handle->current_mode)
{
Expand All @@ -620,7 +625,7 @@ struct output_layout_output_t
}

refresh_custom_modes();
auto built_in = find_matching_mode(handle, mode);
auto built_in = find_matching_mode(handle, mode, custom_mode);
if (built_in)
{
wlr_output_set_mode(handle, built_in);
Expand Down Expand Up @@ -892,7 +897,7 @@ struct output_layout_output_t
}

set_enabled(!(state.source & OUTPUT_IMAGE_SOURCE_NONE));
apply_mode(state.mode);
apply_mode(state.mode, state.uses_custom_mode);

if (state.source & OUTPUT_IMAGE_SOURCE_SELF)
{
Expand Down Expand Up @@ -1074,6 +1079,7 @@ class output_layout_t::impl
state.mode.width = head->state.custom_mode.width;
state.mode.height = head->state.custom_mode.height;
state.mode.refresh = head->state.custom_mode.refresh;
state.uses_custom_mode = true;
}

state.position = {head->state.x, head->state.y};
Expand Down

0 comments on commit 77f6792

Please sign in to comment.