[PATCH xrandr] Feature: clockwise/counter clockwise rotation

0 views
Skip to first unread message

Romain

unread,
Jan 31, 2023, 3:52:27 AM1/31/23
to xorg-...@lists.x.org
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 <rog...@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

Reply all
Reply to author
Forward
0 new messages