@@ -374,6 +374,11 @@ window.update_taskbar_position = async function(new_position) {
374374 $ ( '.taskbar-sortable' ) . sortable ( 'destroy' ) ;
375375 window . make_taskbar_sortable ( ) ;
376376
377+ // Adjust taskbar item sizes for the new position
378+ setTimeout ( ( ) => {
379+ window . adjust_taskbar_item_sizes ( ) ;
380+ } , 10 ) ;
381+
377382 // Reinitialize all taskbar item tooltips with new position
378383 $ ( '.taskbar-item' ) . each ( function ( ) {
379384 const $item = $ ( this ) ;
@@ -501,4 +506,126 @@ window.update_maximized_window_for_taskbar = function(el_window) {
501506 }
502507} ;
503508
509+ //-------------------------------------------
510+ // Dynamic taskbar item resizing for left/right positions
511+ //-------------------------------------------
512+ window . adjust_taskbar_item_sizes = function ( ) {
513+ const position = window . taskbar_position || 'bottom' ;
514+
515+ // Only apply to left and right positions
516+ if ( position !== 'left' && position !== 'right' ) {
517+ // Reset to default sizes for bottom position
518+ $ ( '.taskbar .taskbar-item' ) . css ( {
519+ 'width' : '40px' ,
520+ 'height' : '40px' ,
521+ 'min-width' : '40px' ,
522+ 'min-height' : '40px' ,
523+ } ) ;
524+ $ ( '.taskbar-icon' ) . css ( 'height' , '40px' ) ;
525+ return ;
526+ }
527+
528+ const taskbar = $ ( '.taskbar' ) [ 0 ] ;
529+ const taskbarItems = $ ( '.taskbar .taskbar-item:visible' ) ;
530+
531+ if ( ! taskbar || taskbarItems . length === 0 ) return ;
532+
533+ // Get available height (minus padding)
534+ const taskbarHeight = taskbar . clientHeight ;
535+ const paddingTop = 20 ; // from CSS
536+ const paddingBottom = 20 ; // from CSS
537+ const availableHeight = taskbarHeight - paddingTop - paddingBottom ;
538+
539+ // Calculate space needed with default sizes
540+ const defaultItemSize = 40 ;
541+ const defaultMargin = 5 ;
542+ const totalItemsNeeded = taskbarItems . length ;
543+ const spaceNeededDefault = ( totalItemsNeeded * defaultItemSize ) + ( ( totalItemsNeeded - 1 ) * defaultMargin ) ;
544+
545+ if ( spaceNeededDefault <= availableHeight ) {
546+ // No overflow, use default sizes
547+ taskbarItems . css ( {
548+ 'width' : defaultItemSize + 'px' ,
549+ 'height' : defaultItemSize + 'px' ,
550+ 'min-width' : defaultItemSize + 'px' ,
551+ 'min-height' : defaultItemSize + 'px' ,
552+ 'padding' : '6px 5px 10px 5px' // default padding
553+ } ) ;
554+ $ ( '.taskbar-icon' ) . css ( 'height' , defaultItemSize + 'px' ) ;
555+
556+ // Reset margins to default
557+ taskbarItems . css ( 'margin-bottom' , '5px' ) ;
558+ taskbarItems . last ( ) . css ( 'margin-bottom' , '0px' ) ;
559+ } else {
560+ // Overflow detected, calculate smaller sizes
561+ // Reserve some margin space (minimum 2px between items)
562+ const minMargin = 2 ;
563+ const marginSpace = ( totalItemsNeeded - 1 ) * minMargin ;
564+ const availableForItems = availableHeight - marginSpace ;
565+ const newItemSize = Math . floor ( availableForItems / totalItemsNeeded ) ;
566+
567+ // Ensure minimum size of 20px
568+ const finalItemSize = Math . max ( 20 , newItemSize ) ;
569+
570+ // Calculate proportional padding based on size ratio
571+ const sizeRatio = finalItemSize / defaultItemSize ;
572+ const paddingTop = Math . max ( 1 , Math . floor ( 6 * sizeRatio ) ) ;
573+ const paddingRight = Math . max ( 1 , Math . floor ( 5 * sizeRatio ) ) ;
574+ const paddingBottom = Math . max ( 1 , Math . floor ( 10 * sizeRatio ) ) ;
575+ const paddingLeft = Math . max ( 1 , Math . floor ( 5 * sizeRatio ) ) ;
576+
577+ // Apply new sizes and padding
578+ taskbarItems . css ( {
579+ 'width' : finalItemSize + 'px' ,
580+ 'height' : finalItemSize + 'px' ,
581+ 'padding' : `${ paddingTop } px ${ paddingRight } px ${ paddingBottom } px ${ paddingLeft } px`
582+ } ) ;
583+ $ ( '.taskbar-icon' ) . css ( 'height' , finalItemSize + 'px' ) ;
584+
585+ // Adjust margins
586+ taskbarItems . css ( 'margin-bottom' , minMargin + 'px' ) ;
587+ taskbarItems . last ( ) . css ( 'margin-bottom' , '0px' ) ;
588+ }
589+ } ;
590+
591+ // Hook into existing taskbar functionality
592+ $ ( document ) . ready ( function ( ) {
593+ // Watch for taskbar item changes
594+ const observer = new MutationObserver ( function ( mutations ) {
595+ mutations . forEach ( function ( mutation ) {
596+ if ( mutation . type === 'childList' || mutation . type === 'attributes' ) {
597+ // Delay to ensure DOM updates are complete
598+ setTimeout ( ( ) => {
599+ window . adjust_taskbar_item_sizes ( ) ;
600+ } , 10 ) ;
601+ }
602+ } ) ;
603+ } ) ;
604+
605+ // Start observing when taskbar is available
606+ const checkTaskbar = setInterval ( ( ) => {
607+ const taskbar = document . querySelector ( '.taskbar-sortable' ) ;
608+ if ( taskbar ) {
609+ observer . observe ( taskbar , {
610+ childList : true ,
611+ attributes : true ,
612+ subtree : true
613+ } ) ;
614+ clearInterval ( checkTaskbar ) ;
615+
616+ // Initial call
617+ setTimeout ( ( ) => {
618+ window . adjust_taskbar_item_sizes ( ) ;
619+ } , 100 ) ;
620+ }
621+ } , 100 ) ;
622+
623+ // Also watch for window resize events
624+ window . addEventListener ( 'resize' , ( ) => {
625+ setTimeout ( ( ) => {
626+ window . adjust_taskbar_item_sizes ( ) ;
627+ } , 10 ) ;
628+ } ) ;
629+ } ) ;
630+
504631export default UITaskbar ;
0 commit comments