modkavartini / catppuccin

soothing pastel suite for rainmeter
https://github.com/catppuccin/catppuccin
271 stars 6 forks source link

Properly making a custom widget #14

Closed pupbrained closed 10 months ago

pupbrained commented 10 months ago

Hi! I'm trying to write a custom widget/snippet for this skin so I can see what komorebi workspace I'm currently on at any given time. I currently have the following:

[Rainmeter]
Update=100
AccurateText=1
DynamicVariables=1
OnUpdateAction=[!CommandMeasure Command_1 Run]

[Variables]
customIcon=EA6F
customDisp=1

[Command_1]
Measure=Plugin
Plugin=RunCommand
Parameter=Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "[int]((komorebic query focused-workspace-index) | Out-String) + 1"
OutputType=ANSI
FinishAction=[!UpdateMeasure Command_1][!UpdateMeter customDisp][!Redraw]

[customDisp]
Meter=String
MeasureName=Command_1
FontFace=JetBrains Mono
FontSize=12
AntiAlias=1
Y=60
Text=[Command_1]

[custom]
Meter=String
MeterStyle=info|icon|dispI

This current iteration has a few issues though, mainly that I have to manually set the Y value for the text to be aligned with the rest of the widgets on the bar, and the separator doesn't show:

image

How would I go about fixing these issues? Apologies if these are easy fixes, I'm new to rainmeter. Thanks!

modkavartini commented 10 months ago

welp, there's quite a lot of things wrong here lol, you probably didn't read through/understand the first 17 lines of guiding i provided :(

but it's fine, since you asked for help, help you shall receieve!

so you see, the whole working of a custom info snippet is based on the naming of the three [sections] let's take our name to be komorebi. thus:

  1. [mKomorebiDisp] (follows the format of [mNameDisp]) (the measure that provides the string value to be displayed next to the icon)
  2. [komorebiDisp] (follows the format of [nameDisp]) (the meter for the text displayed next to the icon) (should compulsorily be followed by the line: meterstyle=info|dispT)
  3. [komorebi] (follows the format of [name]) (the meter for the icon next to the text) (should compulsorily be followed by the line: meterstyle=info|icon|dispI)

(note that these section names are case-insensitive, i just gave them different cases for better readibility)

sooo,

one of your mistakes was naming it [Command_1] and not [mCustomDisp] (because the name is custom in this case)

also, you removed the meterstyle from [customDisp] which resulted in it not being positioned correctly and you having to manually add the font attributes, anti-alias and the text field. (and also the separator not being shown)

the meterstyle IS what is supposed to automagically do all of that for you lol, that's why this specific naming sequence exists for this functionality

also, the snippets.inc is merely an .inc file, it can only ADD to what's already in the main bar.ini file, which already has a [rainmeter] section, thus, you're kinda not achieving anything with that section lol

if you really wanna know how most of this works, you can refer to the rainmeter docs

from my observation, it probably would not be fun running the command as frequent as the skin updates we can make it update only every few seconds

anyways... the final code should be:

[variables]
komorebiIcon=EA6F
komorebiDisp=1

[mKomorebiDisp]
Measure=Plugin
Plugin=RunCommand
Parameter=Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "[int]((komorebic query focused-workspace-index) | Out-String) + 1"
OutputType=ANSI
;update only every #updateRate# seconds
OnUpdateAction=[!CommandMeasure [#CurrentSection] Run]
updatedivider=-1
group=rate

[komorebiDisp]
meter=string
meterstyle=info|dispT

[komorebi]
meter=string
meterstyle=info|icon|dispI

i haven't gotten to setting up komorebi on my pc yet, so i can't personally test this, but do let me know if this helped! :3

modkavartini commented 10 months ago

never mind lol, i got it to work on my pc:

Rainmeter_XIDZalVXp5

so THIS is because the text outputted from the measure has a newline in it. simplest fix is substituting it out of the output:

[mKomorebiDisp]
Measure=Plugin
Plugin=RunCommand
Parameter=Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "[int]((komorebic query focused-workspace-index) | Out-String) + 1"
OutputType=ANSI
;update only every #updateRate# seconds
OnUpdateAction=[!CommandMeasure [#CurrentSection] Run]
updatedivider=-1
group=rate
regexpsubstitute=1
substitute="\n":""

which produces the desired result:

Rainmeter_S79P1oB9Bh

pupbrained commented 10 months ago

Thank you so much! Apologies for not reading the top comments in the template file, I think I honestly just glazed over it haha

This works perfectly :) (Originally asked a question but realized you answered it already, oops)

melMass commented 9 months ago

@modkavartini Sorry I'm a RM noob, I tried it years ago but reinstalled it now for this project in combo with komorebi like the OP. I was wondering if in the meantime there could be a way to manually trigger updates?

I've seen that we are apparently able to send bangs to RM from the cli: https://docs.rainmeter.net/manual/bangs/ But I don't understand most of it especially in the context of the "snippet.inc" case.

My thinking it to wrap the shortcut to change workspace to also call RM just after the komorebi command, would you have a suggestion for such a flow?

Thanks