[PATCH xrandr] Feature: clockwise/counter clockwise rotation
Romain
romain at rgarbage.fr
Mon Jan 30 23:23:48 UTC 2023
Add commandline switches for display rotation: --rotate-cw and
--rotate-ccw.
Currently the display orientation can be changed with the --orientation
switch, with an absolute orientation.
The new switches allow to change the orientation relatively to the
current orientation of the display, either by rotating it clockwise or
counter clockwise.
Signed-off-by: Romain GARBAGE <rogarb at rgarbage.fr>
---
xrandr.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/xrandr.c b/xrandr.c
index 95a9988..e145f50 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -114,6 +114,8 @@ usage(void)
" -v or --version\n"
" -x (reflect in x)\n"
" -y (reflect in y)\n"
+ " --rotate-cw\n"
+ " --rotate-ccw\n"
" --screen <screen>\n"
" --verbose\n"
" --current\n"
@@ -2627,6 +2629,8 @@ main (int argc, char **argv)
Bool current = False;
Bool toggle_x = False;
Bool toggle_y = False;
+ Bool rotate_cw = False;
+ Bool rotate_ccw = False;
program_name = argv[0];
for (int i = 1; i < argc; i++) {
@@ -2732,6 +2736,22 @@ main (int argc, char **argv)
action_requested = True;
continue;
}
+ if (!strcmp ("--rotate-cw", argv[i])) {
+ if (rotate_ccw)
+ argerr("--rotate-cw and --rotate-ccw cannot be set simultaneously");
+ rotate_cw = True;
+ setit = True;
+ action_requested = True;
+ continue;
+ }
+ if (!strcmp ("--rotate-ccw", argv[i])) {
+ if (rotate_cw)
+ argerr("--rotate-cw and --rotate-ccw cannot be set simultaneously");
+ rotate_ccw = True;
+ setit = True;
+ action_requested = True;
+ continue;
+ }
if (!strcmp ("--prop", argv[i]) ||
!strcmp ("--props", argv[i]) ||
!strcmp ("--madprops", argv[i]) ||
@@ -4108,6 +4128,15 @@ main (int argc, char **argv)
RRScreenChangeNotifyMask);
if (setit && !dryrun) {
Rotation rotation = 1 << rot;
+ if (rotate_cw) {
+ rotation = (current_rotation >> 1) & 0xf;
+ if (rotation == 0)
+ rotation = (1 << 3) & 0xf;
+ } else if (rotate_ccw) {
+ rotation = (current_rotation << 1) & 0xf;
+ if (rotation == 0)
+ rotation = 1;
+ }
status = XRRSetScreenConfigAndRate (dpy, sc, root, (SizeID) size,
(Rotation) (rotation | reflection),
rate, CurrentTime);
--
2.38.1
More information about the xorg-devel
mailing list