Add ags stuff, but will probably redo entirely
This commit is contained in:
30
config/general/ags/osd/OSD.scss
Normal file
30
config/general/ags/osd/OSD.scss
Normal file
@@ -0,0 +1,30 @@
|
||||
$fg-color: #{"@theme_fg_color"};
|
||||
$bg-color: #{"@theme_bg_color"};
|
||||
|
||||
window.OSD {
|
||||
box.OSD {
|
||||
border-radius: 100px;
|
||||
background-color: $bg-color;
|
||||
padding: 13px 16px;
|
||||
margin: 13px;
|
||||
box-shadow: 3px 3px 7px 0 rgba(0,0,0,.4);
|
||||
}
|
||||
|
||||
icon {
|
||||
font-size: 4rem;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 2.4rem;
|
||||
}
|
||||
|
||||
levelbar {
|
||||
trough {
|
||||
margin: 1 .6rem;
|
||||
}
|
||||
|
||||
block {
|
||||
min-height: 2rem;
|
||||
}
|
||||
}
|
||||
}
|
71
config/general/ags/osd/OSD.tsx
Normal file
71
config/general/ags/osd/OSD.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
// From examples on astal github page, since it looks good by default
|
||||
|
||||
import { App, Astal, Gdk, Gtk } from "astal/gtk3"
|
||||
import { timeout } from "astal/time"
|
||||
import Variable from "astal/variable"
|
||||
import Brightness from "./brightness"
|
||||
import Wp from "gi://AstalWp"
|
||||
|
||||
function OnScreenProgress({ visible }: { visible: Variable<boolean> }) {
|
||||
const brightness = Brightness.get_default()
|
||||
const speaker = Wp.get_default()!.get_default_speaker()
|
||||
|
||||
const iconName = Variable("")
|
||||
const value = Variable(0)
|
||||
|
||||
let count = 0
|
||||
function show(v: number, icon: string) {
|
||||
visible.set(true)
|
||||
value.set(v)
|
||||
iconName.set(icon)
|
||||
count++
|
||||
timeout(2000, () => {
|
||||
count--
|
||||
if (count === 0) visible.set(false)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<revealer
|
||||
setup={(self) => {
|
||||
self.hook(brightness, "notify::screen", () =>
|
||||
show(brightness.screen, "display-brightness-symbolic"),
|
||||
)
|
||||
|
||||
if (speaker) {
|
||||
self.hook(speaker, "notify::volume", () =>
|
||||
show(speaker.volume, speaker.volumeIcon),
|
||||
)
|
||||
}
|
||||
}}
|
||||
revealChild={visible()}
|
||||
transitionType={Gtk.RevealerTransitionType.SLIDE_UP}
|
||||
>
|
||||
<box className="OSD">
|
||||
<icon icon={iconName()} />
|
||||
<levelbar valign={Gtk.Align.CENTER} widthRequest={100} value={value()} />
|
||||
<label label={value(v => `${Math.floor(v * 100)}%`)} />
|
||||
</box>
|
||||
</revealer>
|
||||
)
|
||||
}
|
||||
|
||||
export default function OSD(monitor: Gdk.Monitor) {
|
||||
const visible = Variable(false)
|
||||
|
||||
return (
|
||||
<window
|
||||
gdkmonitor={monitor}
|
||||
className="OSD"
|
||||
namespace="osd"
|
||||
application={App}
|
||||
layer={Astal.Layer.OVERLAY}
|
||||
keymode={Astal.Keymode.ON_DEMAND}
|
||||
anchor={Astal.WindowAnchor.BOTTOM}
|
||||
>
|
||||
<eventbox onClick={() => visible.set(false)}>
|
||||
<OnScreenProgress visible={visible} />
|
||||
</eventbox>
|
||||
</window>
|
||||
)
|
||||
}
|
47
config/general/ags/osd/brightness.ts
Normal file
47
config/general/ags/osd/brightness.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
// From examples on Astal GitHub
|
||||
|
||||
import GObject, { register, property } from "astal/gobject"
|
||||
import { monitorFile, readFileAsync } from "astal/file"
|
||||
import { exec, execAsync } from "astal/process"
|
||||
|
||||
const get = (args: string) => Number(exec(`brightnessctl ${args}`))
|
||||
const screen = exec(`bash -c "ls -w1 /sys/class/backlight | head -1"`)
|
||||
|
||||
@register({ GTypeName: "Brightness" })
|
||||
export default class Brightness extends GObject.Object {
|
||||
static instance: Brightness
|
||||
static get_default() {
|
||||
if (!this.instance)
|
||||
this.instance = new Brightness()
|
||||
|
||||
return this.instance
|
||||
}
|
||||
|
||||
#screenMax = get("max")
|
||||
#screen = get("get") / (get("max") || 1)
|
||||
|
||||
@property(Number)
|
||||
get screen() { return this.#screen }
|
||||
|
||||
set screen(percent) {
|
||||
if (percent < 0)
|
||||
percent = 0
|
||||
|
||||
if (percent > 1)
|
||||
percent = 1
|
||||
|
||||
execAsync(`brightnessctl set ${Math.floor(percent * 100)}% -q`).then(() => {
|
||||
this.#screen = percent
|
||||
this.notify("screen")
|
||||
})
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
monitorFile(`/sys/class/backlight/${screen}/brightness`, async f => {
|
||||
const v = await readFileAsync(f)
|
||||
this.#screen = Number(v) / this.#screenMax
|
||||
this.notify("screen")
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user