Skip to content

Commit

Permalink
refactor 4.9.5 screen size handling
Browse files Browse the repository at this point in the history
  • Loading branch information
TuxVinyards committed Jun 23, 2024
1 parent 79a735b commit e2e1d96
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 61 deletions.
121 changes: 66 additions & 55 deletions qqX.main/qqX_configuration_items
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ custom_conf_notes () {

function check_screen_percentage_and_output {

SDL_ScreenPercent=
SDL_ScreenSize_Error=
SDL_ScreenSize_Cmd=
HeadlessCmd=

Expand All @@ -69,25 +69,49 @@ function check_screen_percentage_and_output {
if [[ $SetGL_DefaultAsOff ]]; then qqX_GL_Mode="off" ; else qqX_GL_Mode="on" ; fi
fi

SDL_ScreenPercent=

[[ $Custom_SDL_ScreenPercent ]] && SDL_ScreenPercent="$Custom_SDL_ScreenPercent"
[[ $Default_SDL_ScreenPercent ]] && [[ ! $SDL_ScreenPercent ]] && SDL_ScreenPercent="$Default_SDL_ScreenPercent"

if [[ $SDL_ScreenPercent ]]; then

SDL_ScreenPercent="$(tr -cd "[:digit:]" <<< "$SDL_ScreenPercent")"
[[ SDL_ScreenPercent -lt 25 ]] && SDL_ScreenPercent="25"
[[ SDL_ScreenPercent -gt 97 ]] && SDL_ScreenPercent="97"

if grep -q -s -e 'screenpct' "/tmp/qmod-case-temp" ; then
SDL_ScreenSize_Cmd=" --screenpct $SDL_ScreenPercent"
else
if [[ ! $QE_495_Script ]]; then
printColor "\n\n WARNING: SDL_ScreenPercent needs quickemu 4.8+ \n\n "
SDL_ScreenSize_Error="> not possible with this qe-version"
fi
fi

fi

xRes=
yRes=
Mon_xRes=
Mon_yRes=
SDL_ScreenSize_Error=
SDL_ScreenSize=
MacScreenRes=
SDL_ScreenSize_Cmd97=

if [[ $QE_495_Script ]] && [[ $XDG_SESSION_TYPE == "x11" || $XDG_SESSION_TYPE == "wayland" ]]; then

if [[ $PhysicalMonitor ]]; then
Mon_xRes="$(cut -d 'x' -f 1 <<< "$PhysicalMonitor")"
Mon_yRes="$(cut -d 'x' -f 2 <<< "$PhysicalMonitor")"
else
Mon_xRes=$(xrandr --listmonitors | grep -v Monitors | cut -d' ' -f4 | cut -d'/' -f1 | head -n1)
Mon_yRes=$(xrandr --listmonitors | grep -v Monitors | cut -d' ' -f4 | cut -d'/' -f2 | cut -d'x' -f2 | head -n1)
fi
Mon_xRes="$(tr -cd "[:digit:]" <<< "$Mon_xRes")"
Mon_yRes="$(tr -cd "[:digit:]" <<< "$Mon_yRes")"

Mon_xRes="$(tr -cd "[:digit:]" <<< "$Mon_xRes")"
Mon_yRes="$(tr -cd "[:digit:]" <<< "$Mon_yRes")"

if [[ ! $Mon_xRes || ! $Mon_yRes ]]; then
if [[ $PhysicalMonitor ]]; then printColor "\n\n ERROR: check monitor size in general settings \n\n "
else printColor "\n\n ERROR: xrandr detection > set manually in general settings \n\n "
Expand All @@ -98,66 +122,53 @@ function check_screen_percentage_and_output {
[[ $Custom_SDL_ScreenSize ]] && SDL_ScreenSize="$Custom_SDL_ScreenSize"
[[ $MacScreenRes ]] && SDL_ScreenSize="$MacScreenRes"
[[ $Default_SDL_ScreenSize ]] && [[ ! $SDL_ScreenSize ]] && SDL_ScreenSize="$Default_SDL_ScreenSize"
fi

if [[ $SDL_ScreenSize ]]; then
SDL_ScreenPercent=
xRes="$(cut -d 'x' -f 1 <<< "$SDL_ScreenSize")"
yRes="$(cut -d 'x' -f 2 <<< "$SDL_ScreenSize")"
xRes="$(tr -cd "[:digit:]" <<< "$xRes")"
yRes="$(tr -cd "[:digit:]" <<< "$yRes")"
if [[ ! $xRes || ! $yRes ]]; then
printColor "\n\n ERROR: check specified sizes in settings \n\n "
SDL_ScreenSize_Error="> display size error"
# MacOS REVIEW # ? 1360 x 768 ? 1920 x 1080 (max ovmf) ? 1280 x 720 (max default qxl)
# The newer variable SDL_ScreenSize is functionally identical to MacScreenRes
# but MacScreenRes has been left in place to emphasise that size options are more limited if used with Mac.
# Sonoma default is 2560 x 1440 low res. In other words 1280 x 720 at x2 Hi-DPI res.
# Mac seems to be able to use 1280 and then takes control of the outcome itself, once set up.
# Unless it's Sequoia where it needs to be specified in the conf file:
if [[ $guest_os == "macos" ]]; then
if [[ $MacScreenRes && ! $Custom_SDL_ScreenSize ]]; then
SDL_ScreenSize="$MacScreenRes"
else xRes=1280 && yRes=720
fi
fi
SDL_ScreenSize_Cmd=" --width $xRes --height $yRes"
xRes97="$(bc <<< "scale=0; $Mon_xRes*97/100")"
xRes97="$(bc <<< "scale=0; $Mon_yRes*97/100")"
SDL_ScreenSize_Cmd97=" --width $xRes97 --height $xRes97"
fi

if [[ $SDL_ScreenPercent ]]; then

SDL_ScreenPercent="$(tr -cd "[:digit:]" <<< "$SDL_ScreenPercent")"

if (( 24 < SDL_ScreenPercent && SDL_ScreenPercent < 100 )); then

if grep -q -s -e 'screenpct' "/tmp/qmod-case-temp" ; then SDL_ScreenSize_Cmd=" --screenpct $SDL_ScreenPercent"

elif [[ $QE_495_Script ]] && [[ $Mon_xRes && $Mon_yRes ]]; then

xRes="$(bc <<< "scale=0; $Mon_xRes*$SDL_ScreenPercent/100")"
yRes="$(bc <<< "scale=0; $Mon_yRes*$SDL_ScreenPercent/100")"
if [[ $SDL_ScreenSize ]]; then

xRes="$(cut -d 'x' -f 1 <<< "$SDL_ScreenSize")"
yRes="$(cut -d 'x' -f 2 <<< "$SDL_ScreenSize")"
xRes="$(tr -cd "[:digit:]" <<< "$xRes")"
yRes="$(tr -cd "[:digit:]" <<< "$yRes")"

if [[ ! $xRes || ! $yRes ]]; then
printColor "\n\n ERROR: check specified sizes in settings \n\n "
SDL_ScreenSize_Error="> display size error"
fi

# MacOS REVIEW # ? 1360 x 768 ? 1920 x 1080 (max ovmf) ? 1280 x 720 (max default qxl)
# Sonoma default is 2560 x 1440 low res. In other words 1280 x 720 at x2 Hi-DPI res.
# Mac seems to be able to use 1280 and then takes control of the outcome itself, once set up.
# Unless it's Sequoia where it needs to be specified in the conf file:
elif [[ $SDL_ScreenPercent ]]; then

if [[ $guest_os == "macos" ]]; then
[[ $SDL_ScreenSize && ! $MacScreenRes ]] && MacScreenRes="$SDL_ScreenSize"
if [[ $MacScreenRes ]]; then
xRes="$(cut -d 'x' -f 1 <<< "$MacScreenRes")"
yRes="$(cut -d 'x' -f 2 <<< "$MacScreenRes")"
xRes="$(tr -cd "[:digit:]" <<< "$xRes")"
yRes="$(tr -cd "[:digit:]" <<< "$yRes")"
else xRes=1280 && yRes=720
fi
fi
xRes="$(bc <<< "scale=0; $Mon_xRes*$SDL_ScreenPercent/100")"
yRes="$(bc <<< "scale=0; $Mon_yRes*$SDL_ScreenPercent/100")"
SDL_ScreenSize_Cmd=" --width $xRes --height $yRes"
SDL_ScreenSize="${xRes}x${yRes}"

[[ ! $xRes || ! $yRes ]] && xRes=1152 && yRes=648
SDL_ScreenSize_Cmd=" --width $xRes --height $yRes"
else
xRes=1152 && yRes=648
fi

else
printColor "\n\n WARNING: SDL_ScreenPercent needs quickemu 4.8+ \n\n "
SDL_ScreenSize_Error="> not possible with this qe-version"
fi
SDL_ScreenSize_Cmd=" --width $xRes --height $yRes"

# Windows and Mac REVIEW

if [[ $guest_os == "windows" || $guest_os == "macos" ]]; then
SDL_ScreenSize_Cmd97=
else

printColor "\n\n ERROR: SDL_ScreenPercent = %s Range is 25 to 99 \n\n " "$SDL_ScreenPercent"
SDL_ScreenSize_Error="Out of Range"

xRes97="$(bc <<< "scale=0; $Mon_xRes*97/100")"
yRes97="$(bc <<< "scale=0; $Mon_yRes*97/100")"
SDL_ScreenSize_Cmd97=" --width $xRes97 --height $yRes97"
fi

fi
Expand Down
2 changes: 1 addition & 1 deletion qqX.main/qqX_main_menu_actions
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function main_menu_actions {

if [[ $MainMenuChoice == "df" ]]; then
if [[ "$SDL_ScreenSize_Cmd" == *width* ]]; then eval quickemu "-vm $VM_Conf_File --vm_boot --display sdl $SDL_ScreenSize_Cmd97 $Extra_QE_Params"
else eval quickemu "-vm $VM_Conf_File --vm_boot --display sdl --screenpct 99 $Extra_QE_Params"
else eval quickemu "-vm $VM_Conf_File --vm_boot --display sdl --screenpct 97 $Extra_QE_Params"
fi
else eval quickemu "-vm $VM_Conf_File --vm_boot --display sdl $SDL_ScreenSize_Cmd $Extra_QE_Params"
fi
Expand Down
11 changes: 6 additions & 5 deletions qqX.main/qqX_main_menu_interface
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ else

printColor "\n\n [d] start with SDL display"

if [[ "$VM_InstanceName" =~ 'windows' ]]; then printColor " (sizes to Windows > display, useful for Windows updates)"
elif [[ "$VM_InstanceName" =~ 'macos' ]]; then printColor " (size determined by MacOS with this QE version)"
elif [[ "$SDL_ScreenSize_Cmd" == *screenpct* ]]; then printColor " (%s%%) [df] 99%% " "$SDL_ScreenPercent"; [[ $qqX_GL_Mode == "off" ]] && printColor " (scaleable)"
elif [[ "$SDL_ScreenSize_Cmd" == *width* ]]; then printColor " (%s) [df] 97%% " "$SDL_ScreenSize"; [[ $qqX_GL_Mode == "off" ]] && printColor " (scaleable)"
if [[ $guest_os == "windows" ]]; then printColor " (size as set in Windows)"
elif [[ $guest_os == "macos" ]] && [[ ! $QE_495_Script ]]; then printColor " (size determined by MacOS with this QE version)"
elif [[ "$SDL_ScreenSize_Cmd" == *screenpct* ]]; then printColor " (%s%%) [df] 97%% " "$SDL_ScreenPercent"
elif [[ "$SDL_ScreenSize_Cmd" == *width* ]] && [[ $guest_os == "macos" || $guest_os == "windows" ]]; then printColor " (%s) " "$SDL_ScreenSize"
elif [[ "$SDL_ScreenSize_Cmd" == *width* ]]; then printColor " (%s) [df] 97%% " "$SDL_ScreenSize"
elif [[ $SDL_ScreenSize_Error ]]; then printf " (%s%% %s > see settings)" "$SDL_ScreenPercent" "$SDL_ScreenSize_Error"
fi

Expand Down Expand Up @@ -262,7 +263,7 @@ else

fi

printf "\n\n [h] show help & info [set] open settings file in text editor [conf] open .conf file"
printf "\n\n [h] show help & info [set] open settings file in text editor [conf] view or edit .conf file"
printf "\n\n"

if [[ $qqX_UpdaterPID ]]; then
Expand Down

1 comment on commit e2e1d96

@TuxVinyards
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might help with quickemu-project/quickemu#1465 ?

Please sign in to comment.