Skip to content

Commit

Permalink
- Basic Round-Robin no longer depends on Basic Window Layout
Browse files Browse the repository at this point in the history
- Basic Round-Robin now uses a list of profiles, each with different settings. Old settings will be automatically converted to a profile.
- Basic Round-Robin now correctly restores Focus Follows Mouse when disabled
  • Loading branch information
Joe Thaler committed Dec 6, 2020
1 parent ffed3fb commit d0c61a9
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 114 deletions.
210 changes: 167 additions & 43 deletions Basic Round-Robin/BasicRoundRobin.Common.iss
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
objectdef brrSettings
objectdef brrProfile
{
variable filepath AgentFolder="${Script.CurrentDirectory}"
variable string Name
variable bool DefaultAllow=TRUE
variable bool SwitchAsHotkey=TRUE
variable bool IncludeMouse=FALSE
variable jsonvalue Overrides
variable jsonvalue Hotkey

variable jsonvalue hotkeyToggleRoundRobin="$$>
variable bool Enabled

method Initialize(jsonvalue jo)
{
"controls":"F12"
This:FromJSON[jo]
}
<$$"

method Initialize()
{
Overrides:SetValue["$$>
method Shutdown()
{
"F12":{"ignore":true},
"${Input.Button[160]}":{"ignore":true},
"${Input.Button[161]}":{"ignore":true},
"${Input.Button[162]}":{"ignore":true},
"${Input.Button[163]}":{"ignore":true},
"${Input.Button[164]}":{"ignore":true},
"${Input.Button[165]}":{"ignore":true}
}<$$"]

This:Load
This:DisableHotkey
}

method Load()
method FromJSON(jsonvalueref jo)
{
variable jsonvalue jo
if !${AgentFolder.FileExists[brr.Settings.json]}
if !${jo.Type.Equal[object]}
return

if !${jo:ParseFile["${AgentFolder~}/brr.Settings.json"](exists)} || !${jo.Type.Equal[object]}
{
return
}

if ${jo.Has[enable]}
Enable:Set["${jo.Get[enable]~}"]

if ${jo.Has[includeMouse]}
IncludeMouse:Set["${jo.Get[includeMouse]~}"]
if ${jo.Has[defaultAllow]}
Expand All @@ -47,14 +34,141 @@ objectdef brrSettings
if ${jo.Has[overrides]}
Overrides:SetValue["${jo.Get[overrides].AsJSON~}"]

if ${jo.Has[hotkey]}
Hotkey:SetValue["${jo.Get[hotkey].AsJSON~}"]
}

member AsJSON()
{
variable jsonvalue jo
jo:SetValue["$$>
{
"includeMouse":${IncludeMouse.AsJSON~},
"overrides":${Overrides.AsJSON~},
"defaultAllow":${DefaultAllow.AsJSON~},
"switchAsHotkey":${SwitchAsHotkey.AsJSON~},
"hotkey":${Hotkey.AsJSON~}
}
<$$"]
return "${jo.AsJSON~}"
}

method EnableHotkey()
{
variable jsonvalue joBinding
variable string startCommand
if ${Hotkey.Type.Equal[object]} && ${Hotkey.Has[controls]}
{
joBinding:SetValue["${Hotkey.AsJSON~}"]
joBinding:Set[name,"\"brr.profile.${Name~}\""]

startCommand:Set["BRRSession:ToggleProfile[${Name.AsJSON~}]"]

joBinding:Set[eventHandler,"$$>
{
"type":"task",
"taskManager":"brrSession",
"task":{
"type":"ls1.code",
"start":${startCommand.AsJSON~}
}
}
<$$"]

LGUI2:AddBinding["${joBinding.AsJSON~}"]

Enabled:Set[1]
}
}

method DisableHotkey()
{
LGUI2:RemoveBinding["brr.profile.${Name~}"]
Enabled:Set[0]
}
}

objectdef brrSettings
{
variable filepath AgentFolder="${Script.CurrentDirectory}"



method Initialize()
{
This:Load

if !${Profiles.Used}
{
Profiles:Set[default,"$$>
{
"defaultAllow":true,
"includeMouse":false,
"switchAsHotkey":true,
"hotkey":{
"controls":"F12"
},
"overrides":{
"F12":{"ignore":true},
"${Input.Button[160]}":{"ignore":true},
"${Input.Button[161]}":{"ignore":true},
"${Input.Button[162]}":{"ignore":true},
"${Input.Button[163]}":{"ignore":true},
"${Input.Button[164]}":{"ignore":true},
"${Input.Button[165]}":{"ignore":true}
}
}
<$$"]
}


}

method Convert(jsonvalueref jo)
{
; make sure it hasnt already been converted
if ${jo.Has[profiles]}
return

variable jsonvalue joHotkeys
variable jsonvalue joWrapper
joWrapper:SetValue["${jo.AsJSON~}"]
joHotkeys:SetValue["${jo.Get[hotkeys].AsJSON~}"]

if ${joHotkeys.Type.Equal[object]}
{
if ${joHotkeys.Has[toggleRoundRobin]}
hotkeyToggleRoundRobin:SetValue["${joHotkeys.Get[toggleRoundRobin].AsJSON~}"]
joWrapper:Set["hotkey","${joHotkeys.Get[toggleRoundRobin].AsJSON~}"]
}

joWrapper:Erase[hotkeys]

jo:Clear
jo:Set["profiles","{\"original\":${joWrapper.AsJSON~}}"]

; Profiles:Set["original","${joWrapper.AsJSON~}"]

}

method Load()
{
variable jsonvalue jo
if !${AgentFolder.FileExists[brr.Settings.json]}
return

if !${jo:ParseFile["${AgentFolder~}/brr.Settings.json"](exists)} || !${jo.Type.Equal[object]}
{
return
}

This:Convert[jo]

if ${jo.Has[profiles]}
{
Profiles:FromJSON["${jo.Get[profiles].AsJSON~}"]
Profiles:ForEach["ForEach.Value.Name:Set[\"\${ForEach.Key~}\"]"]
}

}


Expand All @@ -70,22 +184,32 @@ objectdef brrSettings
variable jsonvalue jo
jo:SetValue["$$>
{
"enable":${Enable.AsJSON~},
"includeMouse":${IncludeMouse.AsJSON~},
"overrides":${Overrides.AsJSON~},
"defaultAllow":${DefaultAllow.AsJSON~},
"switchAsHotkey":${SwitchAsHotkey.AsJSON~},
"hotkeys":{
"toggleRoundRobin":${hotkeyToggleRoundRobin.AsJSON~}
}
"profiles":${Profiles.AsJSON~}
}
<$$"]
return "${jo.AsJSON~}"
}

variable bool Enable=FALSE
variable bool DefaultAllow=TRUE
variable bool SwitchAsHotkey=TRUE
variable bool IncludeMouse=FALSE
variable jsonvalue Overrides
method EnableHotkeys()
{
Profiles:ForEach["ForEach.Value:EnableHotkey"]
}

method DisableHotkeys()
{
Profiles:ForEach["ForEach.Value:DisableHotkey"]
}

method SetCurrentProfile(string newValue)
{
CurrentProfile:SetReference["Profiles.Get[${newValue.AsJSON~}]"]
}

method ClearCurrentProfile()
{
CurrentProfile:SetReference[NULL]
}

variable collection:brrProfile Profiles
variable weakref CurrentProfile
}
73 changes: 36 additions & 37 deletions Basic Round-Robin/BasicRoundRobin.Session.iss
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,57 @@ objectdef brrSession
{
variable taskmanager TaskManager=${LMAC.NewTaskManager["brrSession"]}
variable brrSettings Settings
variable bool Enabled

method Initialize()
{
LGUI2:LoadPackageFile[BasicRoundRobin.Session.lgui2Package.json]
if ${Settings.Enable}
This:Enable

This:EnableHotkeys
This.Settings:EnableHotkeys
}

method Shutdown()
{
This:Disable
This:DisableHotkeys
This.Settings:DisableHotkeys
TaskManager:Destroy
LGUI2:UnloadPackageFile[BasicRoundRobin.Session.lgui2Package.json]
}


method EnableHotkeys()

member:uint GetNextSlot()
{
variable jsonvalue joBinding
if ${Settings.hotkeyToggleRoundRobin.Type.Equal[object]} && ${Settings.hotkeyToggleRoundRobin.Has[controls]}
{
joBinding:SetValue["${Settings.hotkeyToggleRoundRobin.AsJSON~}"]
joBinding:Set[name,"\"brr.toggleRoundRobin\""]
joBinding:Set[eventHandler,"$$>
{
"type":"task",
"taskManager":"brrSession",
"task":{
"type":"ls1.code",
"start":"uplink BRRUplink:ToggleEnable"
}
}
<$$"]
variable uint Slot=${JMB.Slot}
if !${Slot}
return 0

LGUI2:AddBinding["${joBinding.AsJSON~}"]
}
}
Slot:Inc
if ${Slot}>${JMB.Slots.Used}
return 1

method DisableHotkeys()
{
LGUI2:RemoveBinding["brr.toggleRoundRobin"]
return ${Slot}
}

method NextWindow()
{
BWLSession:NextWindow[${Settings.SwitchAsHotkey}]
}
variable uint nextSlot=${This.GetNextSlot}
if !${nextSlot}
return

if !${Display.Window.IsForeground}
return

uplink focus "jmb${nextSlot}"
if ${Settings.CurrentProfile.SwitchAsHotkey}
relay "jmb${nextSlot}" "Event[OnHotkeyFocused]:Execute"
}

method OnControlHook(string controlName)
{
variable bool Advance=${Settings.DefaultAllow}
variable bool Advance=${Settings.CurrentProfile.DefaultAllow}

; check for overrides

variable jsonvalueref Override
Override:SetReference["Settings.Overrides[${controlName.AsJSON~}]"]
Override:SetReference["Settings.CurrentProfile.Overrides[${controlName.AsJSON~}]"]

if ${Override.Type.Equal[object]}
{
Expand Down Expand Up @@ -95,20 +87,27 @@ objectdef brrSession

method OnMouseButtonHook()
{
if ${This.IncludeMouse}
if ${Settings.CurrentProfile.IncludeMouse}
This:OnControlHook["${Context.Args[controlName]~}"]
}

method Enable()
method Enable(string profile)
{
Settings:SetCurrentProfile["${profile~}"]
LGUI2.Element[basicRoundRobin.allButtons]:Destroy
LGUI2:LoadJSON["${LGUI2.Template[brr.allButtons].AsJSON~}"]
Enabled:Set[1]
}

method Disable()
{
Settings:ClearCurrentProfile
LGUI2.Element[basicRoundRobin.allButtons]:Destroy
Enabled:Set[0]
}

; used by the GUI to indicate profile hotkey was pressed. pass to the uplink for processing
method ToggleProfile(string profile)
{
relay uplink "BRRUplink:ToggleProfile[${profile.AsJSON~}]"
}
}

Expand Down
5 changes: 5 additions & 0 deletions Basic Round-Robin/BasicRoundRobin.Session.lgui2package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
}
},
"elements": [
{
"type":"panel",
"visibility":"hidden",
"name":"basicRoundRobin.events"
},
{
"type": "window",
"name": "basicRoundRobin.window",
Expand Down
Loading

0 comments on commit d0c61a9

Please sign in to comment.