Are you talking about the display-rotating events, right? The monitor-sensor command can listen to the events. The command is in the iio-sensor-proxy RPM package on Fedora Linux.
$ sudo dnf install iio-sensor-proxy
Then I am using the following script to auto-rotate the display, hooking the events on Sway. Note that swaymsg output is Sway’s command.
You need to install the mawk command to run the script.
$ sudo dnf install mawk
If you are using Hyprland, you can check the following thread to find the equivalent script or program on Hyprland.