[PATCH] add an optional flag to --scale option to let users selecting nearest filter
Benoit Gschwind
gschwind at gnu-log.net
Thu Aug 7 09:54:49 PDT 2014
This patch change the --scale parameter to <x>x<y>[-n] where "-n" is
optional flag to request xrandr to use nearest filter instead of the default
bilinear filter.
known bug: switching between bilinear and nearest filter without
changing scale factor do nothing.
---
xrandr.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/xrandr.c b/xrandr.c
index 366f6dc..e5fd39f 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -132,7 +132,7 @@ usage(void)
" --below <output>\n"
" --same-as <output>\n"
" --set <property> <value>\n"
- " --scale <x>x<y>\n"
+ " --scale <x>x<y>[-n]\n"
" --scale-from <w>x<h>\n"
" --transform <a>,<b>,<c>,<d>,<e>,<f>,<g>,<h>,<i>\n"
" --off\n"
@@ -2875,18 +2875,29 @@ main (int argc, char **argv)
if (!strcmp ("--scale", argv[i]))
{
double sx, sy;
+ char c0, c1;
+ int n_scan;
if (!config_output) argerr ("%s must be used after --output\n", argv[i]);
if (++i >= argc) argerr ("%s requires an argument\n", argv[i-1]);
- if (sscanf (argv[i], "%lfx%lf", &sx, &sy) != 2)
- argerr ("failed to parse '%s' as a scaling factor\n", argv[i]);
+ n_scan = sscanf (argv[i], "%lfx%lf%c%c", &sx, &sy, &c0, &c1);
+ if (n_scan != 2 && n_scan != 4)
+ argerr ("failed to parse '%s' as a scaling factor %d\n", argv[i], n_scan);
+ if(n_scan == 4 && (c0 != '-' || c1 != 'n'))
+ argerr ("unknown sufix '%c%c' in '%s'\n", c0, c1, argv[i]);
init_transform (&config_output->transform);
config_output->transform.transform.matrix[0][0] = XDoubleToFixed (sx);
config_output->transform.transform.matrix[1][1] = XDoubleToFixed (sy);
config_output->transform.transform.matrix[2][2] = XDoubleToFixed (1.0);
- if (sx != 1 || sy != 1)
- config_output->transform.filter = "bilinear";
- else
- config_output->transform.filter = "nearest";
+ /* default transform to bilinear */
+ config_output->transform.filter = "bilinear";
+ /* if the screen is at his native resolution */
+ if(sx == 1 && sy == 1)
+ config_output->transform.filter = "nearest";
+ /* if --scale <sx>x<sy> is suffixed by -n, force nearest transform */
+ if(n_scan == 4 && c0 == '-' && c1 == 'n')
+ {
+ config_output->transform.filter = "nearest";
+ }
config_output->transform.nparams = 0;
config_output->transform.params = NULL;
config_output->changes |= changes_transform;
--
1.8.5.5
More information about the xorg-devel
mailing list