mirror of
https://github.com/pikvm/pikvm.git
synced 2026-03-02 18:16:56 -05:00
Add display orientation buttons to web ui #703
Labels
No labels
component:documentation
help wanted
resolution:delayed
resolution:duplicate
resolution:fixed
resolution:invalid
resolution:rejected
resolution:wontfix
success story
type:bug
type:bug
type:feature
type:question
type:question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/pikvm-pikvm#703
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @plia7 on GitHub (Jul 28, 2023).
Originally assigned to: @mdevaev on GitHub.
Describe the bug
Windows 11 Display orientation Portrait is not working. It sometimes useful to rotate a monitor that is capable of portrait orientation to see more screen real estate for many lines of text.
To Reproduce
Steps to reproduce the behavior, like:
Expected behavior
Display fills in full in portrait mode. Mouse movement should be able to navigate through the entire portrait display.
Actual behavior
Display rotates 90 degrees and not filling the entire black space. The mouse movement also doesn't seem to be right.
Screenshots
Initial state in host pc landscape:
After changing host pc to portrait:
For reference, here is what I can see in the same browser where pikvm tab is open, with another tab where I opened some book:
Desktop (please complete the following information):
Windows 11
Google Chrome Version 114.0.5735.199 (Official Build) (64-bit)
or
Microsoft Edge Version 115.0.1901.183 (Official build) (64-bit)
PiKVM info:
PiKVM v3 Pre-Assembled
pacman -Q | grep kvmdkvmd 3.236-1
kvmd-fan 0.26-1
kvmd-oled 0.24-1
kvmd-platform-v3-hdmi-rpi4 3.238-1
kvmd-webterm 0.43-1
pacman -Q | grep ustreamerustreamer 5.41-1
uname -aLinux pikvm 5.15.68-3-rpi-ARCH #1 SMP Mon Oct 31 20:56:54 MSK 2022 armv7l GNU/Linux
Additional context
It sometimes useful to rotate a monitor that is capable of portrait orientation to see more screen real estate for many lines of text.
@mdevaev commented on GitHub (Aug 6, 2023):
Do you REALLY need this? Orientation support is not part of HDMI, it is purely a soft feature and you need to flip the monitor physically for this.
@plia7 commented on GitHub (Aug 7, 2023):
Hi @mdevaev, yes please this is super useful. I have a $350 lg view 16+ gram portable lightweight monitor that auto rotates to portrait when you physically rotate it (not to mention other capable monitors/tablets/phones) and there is great benefit with portrait orientation when it comes to screen real estate (such as academic article reading, seeing more programming lines, etc). I compared it with some other machine/device streamer software based on h264 and it works great if you flip the monitor and/or it has a right mouse click option on the stream which will flip it and fill in the entire screen.
Thank you.
@mdevaev commented on GitHub (Aug 10, 2023):
It didn't work out quickly, there were some problems with video scaling. A note for myself not to forget: use css transform and swap x/y/width/height in getGeometry
@BhupiMAD commented on GitHub (Aug 20, 2023):
Any fix for this? i tried your CSS rotate solution, but mouse coordinates does not rotate with screen,
@plia7 commented on GitHub (Aug 20, 2023):
I don't think @mdevaev solved it yet, it's still considered work in progress, I think he's busy with other priorities at the moment.
@plia7 commented on GitHub (Oct 1, 2023):
Hi @mdevaev, just checking to see if there are any updates on this? Your last action was on Aug 10.
Thank you.
CC: @BhupiMAD
@BhupiMAD commented on GitHub (Oct 1, 2023):
This is what @mdevaev replied
You can invert the mouse range. Run kvmd -m and find options tree with mouse_x_range and mouse_y_range.
@plia7 commented on GitHub (Oct 1, 2023):
So you got it to work? It's not just the mouse movement it's also the screen that's not correctly oriented
@BhupiMAD commented on GitHub (Oct 1, 2023):
For me screen orientation was working, the problem was with the mouse not inverting as per screen. I haven’t tried the mouse solution yet.
@plia7 commented on GitHub (Oct 1, 2023):
Not sure what are you saying but there is an issue: Display rotates 90 degrees and not filling the entire black space. The mouse movement also doesn't seem to be right.
So I guess we'll have to wait for it to be resolved, it looks like the dev started to work on it but hasn't finished yet.
@mdevaev commented on GitHub (Oct 2, 2023):
No progress here, sorry.
@spcharc commented on GitHub (Oct 2, 2023):
I like this issue. Some webpages and e-books / pdfs are more suitable on a vertical display than horizontal.
This may fix the web version. Many people use VNC which may need some other adjustments
@plia7 commented on GitHub (Oct 2, 2023):
Thank you. I think the web version is more commonly used and functional including where you could place the ui button to activate this mode.
But I'm all for adding the support to VNC as well, it should probably go in a separate ticket with a link to this ticket.
@mdevaev commented on GitHub (Oct 3, 2023):
I can't add it to VNC because there is now the protocol doesn't have any rotation feature and uStreamer can't perform it at all.
@spcharc commented on GitHub (Oct 3, 2023):
sad
I checked tigervnc client and it cannot rotate images. Guess there's no way to add this to vnc without some major software changes.
@plia7 commented on GitHub (Nov 29, 2023):
Hello @mdevaev, what about adding it to PiKVM UI, using css transform and swap x/y/width/height in getGeometry - Any progress on that or did you hit a plateau?
Thank you.
@plia7 commented on GitHub (Mar 11, 2024):
@mdevaev From ChatGPT: "To use CSS transform and swap the x, y, width, and height properties in getBoundingClientRect() or any similar method, you'll need to follow these steps:
Apply CSS Transform: Apply the necessary CSS transform to the element whose geometry you want to manipulate. This can be done using the transform property in CSS.
Get Transformed Geometry: After applying the transform, you need to get the transformed geometry of the element. You can do this by using the getBoundingClientRect() method in JavaScript.
Swap Properties: Once you have the transformed geometry, swap the x and y coordinates, as well as the width and height properties, to get the desired result.
Here's a basic example:
HTML:
<div id="element"></div>CSS:
JavaScript:
In this example, we apply a rotate(45deg) transform to the element. Then, we use getBoundingClientRect() to get the transformed geometry. Finally, we swap the x and y coordinates as well as the width and height properties to get the geometry as if it were not transformed."
Hopefully this helps.
Thanks.
@mdevaev commented on GitHub (Mar 12, 2024):
I don't need GPT's help, I've already tried a similar approach and the problem is scaling, as I wrote.
@plia7 commented on GitHub (Mar 15, 2024):
You mean aspect ratio?
To ensure that the video scales properly within the portrait dimensions while maintaining its aspect ratio, you can set the
object-fitproperty for the video element. Here's how you can modify the CSS:By setting
object-fit: cover;, the video will be scaled to maintain its aspect ratio while covering the entire area of the container. This ensures that the video fills the portrait dimensions completely without distorting or cropping the video content.With this adjustment, the video will scale properly within the portrait dimensions while maintaining its aspect ratio.
Transform technique:
To transform a video stream from landscape (1920x1080) to portrait (1080x1920) while ensuring that the video scales properly, you can use CSS transforms along with appropriate scaling techniques. Here's a basic approach using CSS:
HTML:
CSS:
In this example:
#videoContainerelement is styled to have the dimensions of a portrait orientation (1080x1920).overflow: hidden;property ensures that any overflow content (which may occur due to the rotation) is hidden.rotate(90deg)transform to the video container to rotate the video by 90 degrees clockwise, effectively changing it from landscape to portrait.translateY(-100%)transform is used to reposition the rotated video to the top-left corner of the container.transform-origin: top left;ensures that the rotation and translation are applied from the top-left corner of the container.#videoelement inside the container is positioned absolutely to fill the container's height and maintain proper aspect ratio.With this setup, the video will be transformed from landscape to portrait and will scale appropriately to fit within the portrait dimensions while maintaining its aspect ratio. Adjust the dimensions in CSS according to your specific requirements and make sure to replace
"your_video_source.mp4"with the actual video source.Hopefully this helps.
If not, could you please show an example/screenshot when you say the video doesn't scale? I'll see if I can help further but I want to ensure I understand where the problem is.
Thank you.
@mdevaev commented on GitHub (Mar 15, 2024):
If you want to figure out the problem on your own, then I'm not stopping you. But please don't ask ChatGPT questions and then ask me to check it all out. ChatGPT does not know the context and does not see the code, and offers only common advice. This will not help solve the problem.
@RSATom commented on GitHub (Mar 15, 2024):
Just an idea, maybe it can be done different way? - If I understand correctly RTP video frames can contain information about video orientation and WebRTC client (browser in our case) can take it into account. So maybe there is a way to set that video orientation info on Janus side?
I can look at it, but unfortunately have some other tasks with higher priority right now, so it could be only at least some time later...
Also I'm agree with @mdevaev it's wrong Idea to do it on html/css/js level. And one more thing: ChatGPT gives a feeling everything is simple. But actually it's not - usually there are too many small details it doesn't take into account, and it can make solution very complicated finally or even wrong...
@mdevaev commented on GitHub (Mar 15, 2024):
@RSATom I like the idea about RTP. I also have a higher priority issue right now, so let me know when you have time, maybe we can do something together.
@plia7 commented on GitHub (Mar 15, 2024):
ChatGPT agrees with you too 🤣:
Yes, you're absolutely correct! If the video frames contain orientation information, the WebRTC client (browser) can utilize this information to properly render the video without the need for manual transformations on the client side.
In the context of Janus, you can indeed set video orientation information on the server side. Janus itself doesn't directly manipulate video frames at this level, but you can use external tools or libraries to handle video processing and orientation metadata.
Here's a potential approach:
Video Processing: Use a video processing library or tool to analyze and modify the video frames to include orientation metadata. You can extract metadata from the original video, modify it to reflect the desired orientation (e.g., 90-degree rotation for portrait mode), and then repackage the video frames with the updated metadata.
Janus Integration: Once the video frames contain orientation metadata, Janus can stream them as usual. Janus doesn't need to be aware of the specific orientation metadata; it simply forwards the video frames to the WebRTC clients.
WebRTC Client: The WebRTC client (browser) receives the video stream with orientation metadata. Modern browsers, such as Chrome and Firefox, have built-in support for processing this metadata and rendering the video correctly according to the specified orientation.
By setting the orientation metadata at the server side (before streaming through Janus), you can ensure that the video is rendered properly in portrait mode without requiring additional transformations or adjustments on the client side. This approach can lead to a more seamless and efficient viewing experience.
Thanks.
@mdevaev commented on GitHub (Mar 15, 2024):
Can you stop posting ChatGPT here? I have a strong desire to close this issue, because since you are so good at communicating with ChatGPT, then let it write the code for you. It is unlikely that you need our help in this case.
@plia7 commented on GitHub (Mar 15, 2024):
Sorry, I'm done with it.
Just one thing, for this new web ui portrait flip switch, is it possible to expose it please to the api also so I can add a shortcut trigger when my screen flips to portrait mode, it automatically sends a pikvm api call to flip the orientation? (say mode parameter value 0 is landscape and 1 is portrait). I won't bother anymore :)
Thank you.
@mdevaev commented on GitHub (Mar 15, 2024):
We can't detect screen orientation automatically.
@plia7 commented on GitHub (Mar 15, 2024):
Sorry, what I meant to say is my own connecting pc will have it's own program running in the background that can detect the screen orientation change in my connecting pc and will send to the pikvm api to switch the stream orientation accordingly.
Thanks.
@mdevaev commented on GitHub (Mar 17, 2024):
It's done, but since this is a client-side feature, we have no API on the server side to change orientation.
@plia7 commented on GitHub (Mar 17, 2024):
Thank you. Given that it's done as a client-side feature, is it possible to handle it in addition in window orientationchange so when you detect a change there you pass it to the streamer (you can get the info from screen.orientation.type)?
I tried to register it in stream.js for testing purpose as follows:
But it's not being fired when I change the display orientation. Do you know why? (I suppose something special about registering the event for regular window versus stream-window) Or maybe because it's already registered by it's parent window container:
I do see that you register this event already inside wm.js and it it being fired there when the display orientation changes - But I'm not sure how to access the streamer object from the windows manager class - Can you use the tools object from wm.js to actually simulate a click in the system menu for the right orientation and then click reset stream? Or maybe it can be consolidated somehow (session.js)? (I guess if we can get the orientationchange event to fire from stream.js that will be the easiest way)
Thanks again.
@mdevaev commented on GitHub (Mar 17, 2024):
I don't know why this might not work. And for my taste, this is not so necessary because it is always easy to press the button to explicitly specify the orientation. Especially considering that mobile devices support is limited.
@plia7 commented on GitHub (Mar 17, 2024):
This is mostly to allow displays that have an auto pivot/rotate function when you physically rotate the display, it changes automatically the display orientation and that fires into the browser orientationchange function so it's a shame not to take advantage of that given that the hook for it already exists.
I also tried to register it for the stream-window element but it still didn't fire (I put the breakpoint on the first line inside the function):
Update: Ok, I was able to get it fired. orientationchange is deprecated and what you need to use instead is:
I made the change locally for myself, but I think it's a good change for everybody, I'll let you decide :)
Here is the updated code:
Thanks.
@mdevaev commented on GitHub (Mar 18, 2024):
I really don't think anyone else would need it. The application of this is too specific.
@plia7 commented on GitHub (Apr 7, 2024):
Yes, I had to wrap around my new code with if (!tools.browser.is_mobile) { ... } else { your original code }
otherwise it would break my iOS safari webkit pikvm page. It doesn't seem to know about screen.orientation there, so it still needs window orientationchange, but I don't need it for mobile right now, so it's fine the way it is.
Thanks again for the feature, it works great and really improves productivity.