def set_dgpu(self, state, notification=True): G14dir = self.G14dir # Just to be safe, let's get the current power scheme pwr_guid = list(get_active_windows_plan().values())[0] SW_DYNAMC_GRAPHICS = "e276e160-7cb0-43c6-b20b-73f5dce39954" GLOBAL_SETTINGS = "a1662ab2-9d34-4e53-ba8b-2639b9e20857" AC = "/setacvalueindex" DC = "/setdcvalueindex" def _set_dgpu(SETTING, AC_DC): return os.popen(" ".join([ "powercfg", AC_DC, pwr_guid, SW_DYNAMC_GRAPHICS, GLOBAL_SETTINGS, str(SETTING), ])) if state is True: # Activate dGPU _set_dgpu(2, AC) _set_dgpu(2, DC) time.sleep(0.25) if notification is True: self.notify("dGPU set to performance.") # Inform the user elif state is False: # Deactivate dGPU _set_dgpu(0, AC) _set_dgpu(0, DC) time.sleep(0.25) os.system('"' + str(G14dir) + "\\restartGPUcmd.bat" + '"') if notification is True: self.notify( "dGPU set to force power saver.") # Inform the user
def get_boost(self): # I know, it's ugly, but no other way to do that from py. pwr_guid = list( get_active_windows_plan().values())[0] # Parse the GUID SUB_PROCESSOR = " 54533251-82be-4824-96c1-47b60b740d00" PERFBOOSTMODE = " be337238-0d82-4146-a960-4f3749d470c7" # Let's get the boost option in the currently active power scheme pwr_settings = os.popen("powercfg /Q " + pwr_guid + SUB_PROCESSOR + PERFBOOSTMODE) output = pwr_settings.readlines( ) # We save the output to parse it afterwards # Parsing AC, assuming the DC is the same setting ac_boost = output[-3].rsplit(": ")[1].strip("\n") # battery_boost = parse_boolean(output[-2].rsplit(": ")[1].strip("\n")) # currently unused, we will set both return ac_boost
def get_dgpu(self): # Get active windows power scheme pwr_guid = list( get_active_windows_plan().values())[0] # Parse the GUID SW_DYNAMC_GRAPHICS = "e276e160-7cb0-43c6-b20b-73f5dce39954" GLOBAL_SETTINGS = "a1662ab2-9d34-4e53-ba8b-2639b9e20857" pwr_settings = os.popen(" ".join([ "powercfg", "/q", pwr_guid, SW_DYNAMC_GRAPHICS, GLOBAL_SETTINGS ])) # Let's get the dGPU status in the current power scheme output = pwr_settings.readlines( ) # We save the output to parse it afterwards # Convert to boolean for "On/Off" dgpu_ac = self.parse_boolean(output[-3].rsplit(": ")[1].strip("\n")) if dgpu_ac is None: return False else: return dgpu_ac
def set_boost(self, state, notification=True): """ Takes boost state as a boolean or integer value and modifies the boost parameter of the current windows plan by modifying and then activating the windows plan. The current hackish solution is to switch to another windows plan and then switch back. By default set_boost will cause a windows notification to appear indicating the boost value after it is set, you can silence the notification with the parameter notification=False. """ windows_plan_map = self.windows_plan_map pwr_guid = list(get_active_windows_plan().values())[0] switch_to = list( {val for key, val in windows_plan_map.items() if val != pwr_guid})[0] print(switch_to, "switch to guid") print(pwr_guid, "power guid") self.set_power_plan(switch_to) time.sleep(0.25) self.set_power_plan(pwr_guid) if state is True: # Activate boost self.do_boost(state) if notification is True: self.notify("Boost ENABLED") # Inform the user elif state is False: # Deactivate boost self.do_boost(state) if notification is True: self.notify("Boost DISABLED") # Inform the user elif state == 0: self.do_boost(state) if notification is True: self.notify("Boost DISABLED") # Inform the user elif state == 4: self.do_boost(state) if notification is True: # Inform the user self.notify("Boost Efficient Aggressive") elif state == 2: self.do_boost(state) if notification is True: self.notify("Boost Aggressive") # Inform the user self.set_power_plan(switch_to) time.sleep(0.25) self.set_power_plan(pwr_guid)
def do_boost(self, state): # Just to be safe, let's get the current power scheme SUB_PROCESSOR = "54533251-82be-4824-96c1-47b60b740d00" PERFBOOSTMODE = "be337238-0d82-4146-a960-4f3749d470c7" set_ac = "powercfg /setacvalueindex" set_dc = "powercfg /setdcvalueindex" pwr_guid = list(get_active_windows_plan().values())[0] if state is False: state = 0 SET_AC_VAL = "{0} {1} {2} {3} {4}".format(set_ac, pwr_guid, SUB_PROCESSOR, PERFBOOSTMODE, str(state)) SET_DC_VAL = "{0} {1} {2} {3} {4}".format(set_dc, pwr_guid, SUB_PROCESSOR, PERFBOOSTMODE, str(state)) sp.Popen(SET_AC_VAL, shell=True, creationflags=sp.CREATE_NO_WINDOW) sp.Popen(SET_DC_VAL, shell=True, creationflags=sp.CREATE_NO_WINDOW) if self.config["debug"]: print(SET_AC_VAL) print(SET_DC_VAL)