Use Lua dispatches and options for Hyprland 0.57
Hyprland 0.57 removed hyprctl keyword and name-style dispatches, and hyprglass 1.1 dropped its layer namespace options. Move workspace, window, logout, glass and Game Mode calls to hl.dsp and hyprctl eval. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bfbfc8961e
commit
c716a20e04
6 files changed
+31
-13
No files matched your search
@@ -199,7 +199,7 @@ GlassPill {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: root.pacman
|
hoverEnabled: root.pacman
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: Hyprland.dispatch("workspace " + (slot.index + 1))
|
onClicked: Hyprland.dispatch("hl.dsp.focus({ workspace = '" + (slot.index + 1) + "' })")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ Singleton {
|
|||||||
return s ? s.devicePixelRatio : 1;
|
return s ? s.devicePixelRatio : 1;
|
||||||
}
|
}
|
||||||
function switchToWorkspace(workspace) {
|
function switchToWorkspace(workspace) {
|
||||||
Hyprland.dispatch("workspace " + (workspace && workspace.id !== undefined ? workspace.id : workspace));
|
Hyprland.dispatch("hl.dsp.focus({ workspace = '" + (workspace && workspace.id !== undefined ? workspace.id : workspace) + "' })");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,12 +27,20 @@ def get_many(keys):
|
|||||||
nxt=out.find('{',pos+1)
|
nxt=out.find('{',pos+1)
|
||||||
if nxt<0:break
|
if nxt<0:break
|
||||||
pos=nxt;continue
|
pos=nxt;continue
|
||||||
if isinstance(data,dict) and 'int' in data:found[str(data.get('option',''))]=data['int']
|
if isinstance(data,dict) and ('int' in data or 'bool' in data):found[str(data.get('option',''))]=int(data.get('int',data.get('bool')))
|
||||||
return {k:found[k] for k in keys if k in found}
|
return {k:found[k] for k in keys if k in found}
|
||||||
|
|
||||||
|
def lua_set(key,value):
|
||||||
|
# "decoration:blur:enabled" -> hl.config({ decoration = { blur = { enabled = false } } })
|
||||||
|
path=key.split(':');text='true' if value else 'false'
|
||||||
|
target='hl.config('
|
||||||
|
if path[0]=='plugin':target='hl.plugin.%s.config('%path[1];path=path[2:]
|
||||||
|
for part in reversed(path):text='{ '+part+' = '+text+' }'
|
||||||
|
return target+text+')'
|
||||||
|
|
||||||
def put_many(values):
|
def put_many(values):
|
||||||
if not values:return
|
if not values:return
|
||||||
out=run(['--batch',';'.join('keyword %s %d'%(k,v) for k,v in values.items())])
|
out=run(['--batch',';'.join('eval '+lua_set(k,v) for k,v in values.items())])
|
||||||
bad=[line for line in out.splitlines() if line.strip() and line.strip()!='ok']
|
bad=[line for line in out.splitlines() if line.strip() and line.strip()!='ok']
|
||||||
if bad:raise ValueError(bad[0][:350])
|
if bad:raise ValueError(bad[0][:350])
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ RANGES={'blur_strength':(0,5),'blur_iterations':(1,5),'refraction_strength':(0,8
|
|||||||
'chromatic_aberration':(0,1),'fresnel_strength':(0,1),'specular_strength':(0,1),
|
'chromatic_aberration':(0,1),'fresnel_strength':(0,1),'specular_strength':(0,1),
|
||||||
'edge_thickness':(0,.15),'lens_distortion':(0,1),'brightness':(.2,2),
|
'edge_thickness':(0,.15),'lens_distortion':(0,1),'brightness':(.2,2),
|
||||||
'contrast':(.2,2),'saturation':(0,2),'vibrancy':(0,1),'adaptive_dim':(0,1)}
|
'contrast':(.2,2),'saturation':(0,2),'vibrancy':(0,1),'adaptive_dim':(0,1)}
|
||||||
|
BOOLS={'enabled','layers:enabled'}
|
||||||
GHOSTTY={'blur_strength':.45,'blur_iterations':2,'refraction_strength':3,
|
GHOSTTY={'blur_strength':.45,'blur_iterations':2,'refraction_strength':3,
|
||||||
'chromatic_aberration':.45,'fresnel_strength':.5,'specular_strength':.8,
|
'chromatic_aberration':.45,'fresnel_strength':.5,'specular_strength':.8,
|
||||||
'edge_thickness':.065,'lens_distortion':.25,'brightness':.95,
|
'edge_thickness':.065,'lens_distortion':.25,'brightness':.95,
|
||||||
@@ -21,8 +22,8 @@ def run(args):
|
|||||||
|
|
||||||
def get(key):
|
def get(key):
|
||||||
data=json.loads(run(['-j','getoption',PREFIX+key]))
|
data=json.loads(run(['-j','getoption',PREFIX+key]))
|
||||||
for field in ['str','int','float']:
|
for field in ['str','int','float','bool']:
|
||||||
if field in data:return data[field]
|
if field in data:return int(data[field]) if field=='bool' else data[field]
|
||||||
raise ValueError('HyprGlass option unavailable: '+key)
|
raise ValueError('HyprGlass option unavailable: '+key)
|
||||||
|
|
||||||
def get_many(keys):
|
def get_many(keys):
|
||||||
@@ -33,14 +34,23 @@ def get_many(keys):
|
|||||||
while pos<len(out) and out[pos].isspace():pos+=1
|
while pos<len(out) and out[pos].isspace():pos+=1
|
||||||
if pos>=len(out):break
|
if pos>=len(out):break
|
||||||
data,pos=decoder.raw_decode(out,pos)
|
data,pos=decoder.raw_decode(out,pos)
|
||||||
value=next((data[f] for f in ['str','int','float'] if f in data),None)
|
value=next((data[f] for f in ['str','int','float','bool'] if f in data),None)
|
||||||
|
if isinstance(value,bool):value=int(value)
|
||||||
if value is not None:found[str(data.get('option','')).removeprefix(PREFIX)]=value
|
if value is not None:found[str(data.get('option','')).removeprefix(PREFIX)]=value
|
||||||
missing=[k for k in keys if k not in found]
|
missing=[k for k in keys if k not in found]
|
||||||
if missing:raise ValueError('HyprGlass option unavailable: '+missing[0])
|
if missing:raise ValueError('HyprGlass option unavailable: '+missing[0])
|
||||||
return found
|
return found
|
||||||
|
|
||||||
|
def lua_table(key,value):
|
||||||
|
# "dark:brightness" -> { dark = { brightness = 0.9 } }
|
||||||
|
if key in BOOLS:text='true' if value else 'false'
|
||||||
|
elif isinstance(value,str):text="'"+value+"'"
|
||||||
|
else:text=repr(value)
|
||||||
|
for part in reversed(key.split(':')):text='{ '+part+' = '+text+' }'
|
||||||
|
return text
|
||||||
|
|
||||||
def put(key,value):
|
def put(key,value):
|
||||||
result=run(['keyword',PREFIX+key,str(value)])
|
result=run(['eval','hl.plugin.hyprglass.config('+lua_table(key,value)+')'])
|
||||||
if result!='ok':raise ValueError(result[:350])
|
if result!='ok':raise ValueError(result[:350])
|
||||||
if get(key)!=value:raise ValueError('HyprGlass did not accept '+key)
|
if get(key)!=value:raise ValueError('HyprGlass did not accept '+key)
|
||||||
|
|
||||||
@@ -73,9 +83,9 @@ def save(path,data):
|
|||||||
|
|
||||||
def probe():
|
def probe():
|
||||||
try:
|
try:
|
||||||
o=get_many(['default_preset','enabled','layers:enabled','layers:namespaces','layers:exclude_namespaces','layers:namespace_presets'])
|
o=get_many(['default_preset','enabled','layers:enabled'])
|
||||||
return dict(available=True,preset=o['default_preset'],enabled=bool(o['enabled']),layers=bool(o['layers:enabled']),
|
return dict(available=True,preset=o['default_preset'],enabled=bool(o['enabled']),layers=bool(o['layers:enabled']),
|
||||||
namespaces=o['layers:namespaces'],exclusions=o['layers:exclude_namespaces'],overrides=o['layers:namespace_presets'])
|
namespaces='',exclusions='',overrides='')
|
||||||
except (OSError,ValueError,subprocess.TimeoutExpired) as error:return dict(available=False,reason=str(error)[:200])
|
except (OSError,ValueError,subprocess.TimeoutExpired) as error:return dict(available=False,reason=str(error)[:200])
|
||||||
|
|
||||||
def dispatch(req):
|
def dispatch(req):
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ def action(req):
|
|||||||
if value in ['logout','reboot','shutdown'] and req.get('confirmed') is not True:raise ValueError('Explicit confirmation required')
|
if value in ['logout','reboot','shutdown'] and req.get('confirmed') is not True:raise ValueError('Explicit confirmation required')
|
||||||
if not power(options['power']).get(value):raise ValueError('Power action unavailable')
|
if not power(options['power']).get(value):raise ValueError('Power action unavailable')
|
||||||
if value=='lock':subprocess.Popen(lock_command(options['power']),stdin=subprocess.DEVNULL,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,start_new_session=True)
|
if value=='lock':subprocess.Popen(lock_command(options['power']),stdin=subprocess.DEVNULL,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,start_new_session=True)
|
||||||
elif value=='logout':run(['hyprctl','dispatch','exit'])
|
elif value=='logout':run(['hyprctl','dispatch','hl.dsp.exit()'])
|
||||||
else:run(['busctl','--system','--auto-start=no','--timeout=10','call','org.freedesktop.login1','/org/freedesktop/login1','org.freedesktop.login1.Manager',{'suspend':'Suspend','reboot':'Reboot','shutdown':'PowerOff'}[value],'b','true'],15)
|
else:run(['busctl','--system','--auto-start=no','--timeout=10','call','org.freedesktop.login1','/org/freedesktop/login1','org.freedesktop.login1.Manager',{'suspend':'Suspend','reboot':'Reboot','shutdown':'PowerOff'}[value],'b','true'],15)
|
||||||
elif kind=='manager':
|
elif kind=='manager':
|
||||||
executable={'network':'nm-connection-editor','bluetooth':'blueman-manager'}.get(value)
|
executable={'network':'nm-connection-editor','bluetooth':'blueman-manager'}.get(value)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ Singleton {
|
|||||||
if (window.handle)
|
if (window.handle)
|
||||||
window.handle.activate();
|
window.handle.activate();
|
||||||
else if (/^(0x)?[0-9a-f]+$/i.test(address))
|
else if (/^(0x)?[0-9a-f]+$/i.test(address))
|
||||||
Hyprland.dispatch("focuswindow address:" + (address.startsWith("0x") ? address : "0x" + address));
|
Hyprland.dispatch("hl.dsp.focus({ window = 'address:" + (address.startsWith("0x") ? address : "0x" + address) + "' })");
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -56,7 +56,7 @@ Singleton {
|
|||||||
if (window.handle)
|
if (window.handle)
|
||||||
window.handle.close();
|
window.handle.close();
|
||||||
else if (/^(0x)?[0-9a-f]+$/i.test(address))
|
else if (/^(0x)?[0-9a-f]+$/i.test(address))
|
||||||
Hyprland.dispatch("closewindow address:" + (address.startsWith("0x") ? address : "0x" + address));
|
Hyprland.dispatch("hl.dsp.window.close({ window = 'address:" + (address.startsWith("0x") ? address : "0x" + address) + "' })");
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in new issue
Block a user