mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-11-04 00:33:12 +00:00
fix(linux): match the xrandr output name at the start of its line (#16590)
The pattern resolutions() and current_resolution() build from the output name is not anchored, so DP-1 also matches the eDP-1 line. On a laptop where xrandr lists eDP-1 first, the external DP-1 reports the built-in panel's current mode and mode list.
This commit is contained in:
1 parent
4e93a41ecc
commit
bd92623972
1 file changed
+21
-1
+21
-1
@@ -1935,7 +1935,7 @@ fn get_width_height_from_captures<'t>(caps: &Captures<'t>) -> Option<(i32, i32)>
|
||||
#[inline]
|
||||
fn get_xrandr_conn_pat(name: &str) -> String {
|
||||
format!(
|
||||
r"{}\s+connected.+?(?P<width>\d+)x(?P<height>\d+)\+(?P<x>\d+)\+(?P<y>\d+).*?\n",
|
||||
r"(?m)^{}\s+connected.+?(?P<width>\d+)x(?P<height>\d+)\+(?P<x>\d+)\+(?P<y>\d+).*?\n",
|
||||
name
|
||||
)
|
||||
}
|
||||
@@ -2017,6 +2017,26 @@ pub fn current_resolution(name: &str) -> ResultType<Resolution> {
|
||||
bail!("Failed to find current resolution for {}", name);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod xrandr_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn output_name_does_not_match_inside_another_name() {
|
||||
let xrandr_output = "Screen 0: minimum 320 x 200, current 4480 x 1440, maximum 16384 x 16384
|
||||
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 309mm x 174mm
|
||||
1920x1080 60.01*+ 59.97
|
||||
1280x720 60.00
|
||||
DP-1 connected 2560x1440+1920+0 (normal left inverted right x axis y axis) 597mm x 336mm
|
||||
2560x1440 59.95*+
|
||||
1920x1080 60.00
|
||||
";
|
||||
let re = Regex::new(&get_xrandr_conn_pat("DP-1")).unwrap();
|
||||
let caps = re.captures(xrandr_output).unwrap();
|
||||
assert_eq!(get_width_height_from_captures(&caps), Some((2560, 1440)));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn change_resolution_directly(name: &str, width: usize, height: usize) -> ResultType<()> {
|
||||
Command::new("xrandr")
|
||||
.args(vec![
|
||||
|
||||
Reference in new issue
Block a user