-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add mode option to mirror #59
Open
TRPB
wants to merge
1
commit into
WayfireWM:master
Choose a base branch
from
TRPB:feature/mirror-with-resolution
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1044,6 +1044,18 @@ wf::output_config::mode_t::mode_t(const std::string& mirror_from) | |
this->mirror_from = mirror_from; | ||
} | ||
|
||
/** | ||
* Initialize a mirror mode with a display mode. | ||
*/ | ||
wf::output_config::mode_t::mode_t(const std::string& mirror_from, int32_t width, int32_t height, int32_t refresh) | ||
{ | ||
this->type = MODE_MIRROR; | ||
this->mirror_from = mirror_from; | ||
this->width = width; | ||
this->height = height; | ||
this->refresh = refresh; | ||
} | ||
|
||
/** @return The type of this mode. */ | ||
wf::output_config::mode_type_t wf::output_config::mode_t::get_type() const | ||
{ | ||
|
@@ -1108,29 +1120,26 @@ stdx::optional<wf::output_config::mode_t> wf::option_type::from_string( | |
return wf::output_config::mode_t{true}; | ||
} | ||
|
||
std::string resolution,from; | ||
|
||
if (string.substr(0, 6) == "mirror") | ||
{ | ||
std::stringstream ss(string); | ||
std::string from, dummy; | ||
ss >> from; // the mirror word | ||
if (!(ss >> from)) | ||
if (ss >> from) | ||
{ | ||
return {}; | ||
return wf::output_config::mode_t{from}; | ||
} | ||
|
||
// trailing garbage | ||
if (ss >> dummy) | ||
{ | ||
return {}; | ||
} | ||
|
||
return wf::output_config::mode_t{from}; | ||
ss >> resolution; | ||
} | ||
|
||
resolution = string; | ||
|
||
int w, h, rr = 0; | ||
char next; | ||
|
||
int read = std::sscanf(string.c_str(), "%d x %d @ %d%c", &w, &h, &rr, &next); | ||
int read = std::sscanf(resolution.c_str(), "%d x %d @ %d%c", &w, &h, &rr, &next); | ||
if ((read < 2) || (read > 3)) | ||
{ | ||
return {}; | ||
|
@@ -1147,7 +1156,11 @@ stdx::optional<wf::output_config::mode_t> wf::option_type::from_string( | |
rr *= 1000; | ||
} | ||
|
||
return wf::output_config::mode_t{w, h, rr}; | ||
if (from.empty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting: |
||
return wf::output_config::mode_t{w, h, rr}; | ||
} | ||
|
||
return wf::output_config::mode_t{from, w, h, rr}; | ||
} | ||
|
||
/** Represent the activator binding as a string. */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -437,6 +437,7 @@ TEST_CASE("wf::output_config::mode_t") | |
"1920x1080@59", | ||
"1920x 1080 @ 59000", | ||
"mirror eDP-1", | ||
"mirror DP-1 1920x1080@60000", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to also add some checks in the test that this is properly parsed. |
||
}; | ||
|
||
std::vector<std::string> invalid = { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused, is the code not supposed to continue running after that, so that we can parse the mode as well?
Also, I think it may be simpler (and more flexible wrt. whitespace handling) to try sscanf multiple times. One time with a format string like
mirror %s <optionally the mode>
, and if that fails, then scan a normal resolution, like the code below does.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
59-1.txt
I've modified the logic a bit so the program execution is not prematurely finished before the mode string parsed. So now it works - but the code is a bit ugly. I am not C++ expert ufortunately. But for personal use that works.