def perform(self):
if os.path.exists(self.oldfilename):
try:
os.remove(self.oldfilename)
except:
pass
if os.path.exists(self.filename):
if "ForceFullCompositionPipeline" in self.read():
return
content = self.read_and_backup()
content += '\n# Added by system76-driver.\n'
else:
content = '# Added by system76-driver.\n'
content += '# Force a full composition pipeline to prevent stuttering.\n\n'
content += '# Get the current display settings.\n'
content += 'oldmode=$(nvidia-settings -q CurrentMetaMode | sed -e \'s/.*:: //g\')\n\n'
content += '# If there were no old settings, then apply a default setting;\n'
content += '# otherwise, add ForceFullCompositionPipeline to the old settings.\n'
content += 'if [ -z "$oldmode" ]\n'
content += 'then\n'
content += ' newmode="nvidia-auto-select +0+0 { ForceFullCompositionPipeline = On}"\n'
content += 'else\n'
content += ' newmode=$(echo "$oldmode" | sed \'s/}/, ForceFullCompositionPipeline=On}/g\')\nfi\n\n'
content += '# Apply the new display settings.\n'
content += 'nvidia-settings --assign CurrentMetaMode="$newmode"\n'
self.atomic_write(content)