@@ -37,6 +37,8 @@ const UI = {
3737
3838 controlbarGrabbed : false ,
3939 controlbarDrag : false ,
40+ controlbarMouseDownClientX : 0 ,
41+ controlbarMouseDownOffsetX : 0 ,
4042 controlbarMouseDownClientY : 0 ,
4143 controlbarMouseDownOffsetY : 0 ,
4244
@@ -741,9 +743,14 @@ const UI = {
741743 UI . controlbarDrag = true ;
742744 }
743745
744- const eventY = ptr . clientY - UI . controlbarMouseDownOffsetY ;
745-
746- UI . moveControlbarHandle ( eventY ) ;
746+ const pos = WebUtil . readSetting ( 'controlbar_pos' ) ;
747+ if ( pos === 'left' || pos === 'right' ) {
748+ const eventY = ptr . clientY - UI . controlbarMouseDownOffsetY ;
749+ UI . moveControlbarHandle ( eventY , true ) ;
750+ } else if ( pos === 'top' || pos === 'bottom' ) {
751+ const eventX = ptr . clientX - UI . controlbarMouseDownOffsetX ;
752+ UI . moveControlbarHandle ( eventX , false ) ;
753+ }
747754
748755 e . preventDefault ( ) ;
749756 e . stopPropagation ( ) ;
@@ -752,49 +759,70 @@ const UI = {
752759 } ,
753760
754761 // Move the handle but don't allow any position outside the bounds
755- moveControlbarHandle ( viewportRelativeY ) {
762+ moveControlbarHandle ( viewportRelativeCoord , isVertical ) {
756763 const handle = document . getElementById ( "noVNC_control_bar_handle" ) ;
757- const handleHeight = handle . getBoundingClientRect ( ) . height ;
764+
765+ const handleSpan = isVertical
766+ ? handle . getBoundingClientRect ( ) . height
767+ : handle . getBoundingClientRect ( ) . width ;
768+
758769 const controlbarBounds = document . getElementById ( "noVNC_control_bar" )
759- . getBoundingClientRect ( ) ;
770+ . getBoundingClientRect ( ) ;
771+ const controlbarBoundsStart = isVertical
772+ ? controlbarBounds . top
773+ : controlbarBounds . left ;
774+ const controlbarBoundsSpan = isVertical
775+ ? controlbarBounds . height
776+ : controlbarBounds . width ;
777+
760778 const margin = 10 ;
761779
762780 // These heights need to be non-zero for the below logic to work
763- if ( handleHeight === 0 || controlbarBounds . height === 0 ) {
781+ if ( handleSpan === 0 || controlbarBoundsSpan === 0 ) {
764782 return ;
765783 }
766784
767- let newY = viewportRelativeY ;
785+ let newCoord = viewportRelativeCoord ;
768786
769787 // Check if the coordinates are outside the control bar
770- if ( newY < controlbarBounds . top + margin ) {
771- // Force coordinates to be below the top of the control bar
772- newY = controlbarBounds . top + margin ;
788+ if ( newCoord < controlbarBoundsStart + margin ) {
789+ // Force coordinates to be below the start of the control bar
790+ newCoord = controlbarBoundsStart + margin ;
773791
774- } else if ( newY > controlbarBounds . top +
775- controlbarBounds . height - handleHeight - margin ) {
776- // Force coordinates to be above the bottom of the control bar
777- newY = controlbarBounds . top +
778- controlbarBounds . height - handleHeight - margin ;
792+ } else if ( newCoord > controlbarBoundsStart +
793+ controlbarBoundsSpan - handleSpan - margin ) {
794+ // Force coordinates to be before the end of the control bar
795+ newCoord = controlbarBoundsStart +
796+ controlbarBoundsSpan - handleSpan - margin ;
779797 }
780798
781799 // Corner case: control bar too small for stable position
782- if ( controlbarBounds . height < ( handleHeight + margin * 2 ) ) {
783- newY = controlbarBounds . top +
784- ( controlbarBounds . height - handleHeight ) / 2 ;
800+ if ( controlbarBoundsSpan < ( handleSpan + margin * 2 ) ) {
801+ newCoord = controlbarBoundsStart +
802+ ( controlbarBoundsSpan - handleSpan ) / 2 ;
785803 }
786804
787805 // The transform needs coordinates that are relative to the parent
788- const parentRelativeY = newY - controlbarBounds . top ;
789- handle . style . transform = "translateY(" + parentRelativeY + "px)" ;
806+ const parentRelativeCoord = newCoord - controlbarBoundsStart ;
807+ if ( isVertical ) {
808+ handle . style . transform = "translateY(" + parentRelativeCoord + "px)" ;
809+ } else {
810+ handle . style . transform = "translateX(" + parentRelativeCoord + "px)" ;
811+ }
790812 } ,
791813
792814 updateControlbarHandle ( ) {
793815 // Since the control bar is fixed on the viewport and not the page,
794816 // the move function expects coordinates relative the the viewport.
795817 const handle = document . getElementById ( "noVNC_control_bar_handle" ) ;
796818 const handleBounds = handle . getBoundingClientRect ( ) ;
797- UI . moveControlbarHandle ( handleBounds . top ) ;
819+
820+ const pos = WebUtil . readSetting ( 'controlbar_pos' ) ;
821+ if ( pos === 'left' || pos === 'right' ) {
822+ UI . moveControlbarHandle ( handleBounds . top , true ) ;
823+ } else if ( pos === 'top' || pos === 'bottom' ) {
824+ UI . moveControlbarHandle ( handleBounds . left , false ) ;
825+ }
798826 } ,
799827
800828 controlbarHandleMouseUp ( e ) {
@@ -832,6 +860,8 @@ const UI = {
832860
833861 UI . controlbarMouseDownClientY = ptr . clientY ;
834862 UI . controlbarMouseDownOffsetY = ptr . clientY - bounds . top ;
863+ UI . controlbarMouseDownClientX = ptr . clientX ;
864+ UI . controlbarMouseDownOffsetX = ptr . clientX - bounds . left ;
835865 e . preventDefault ( ) ;
836866 e . stopPropagation ( ) ;
837867 UI . keepControlbar ( ) ;
0 commit comments