summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-03-27 21:35:48 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-03-27 21:35:48 +1100
commit88547233e24876958799e73dbd34d8df0dadee97 (patch)
tree20ed3c86369bf4ef35738fa423482c0ff874b279
parentbar: change onclick to sidebar (diff)
downloadcaelestia-shell-88547233e24876958799e73dbd34d8df0dadee97.tar.gz
caelestia-shell-88547233e24876958799e73dbd34d8df0dadee97.tar.bz2
caelestia-shell-88547233e24876958799e73dbd34d8df0dadee97.zip
launcher: transparency action
-rw-r--r--src/config/funcs.ts10
-rw-r--r--src/modules/launcher/actions.tsx41
2 files changed, 50 insertions, 1 deletions
diff --git a/src/config/funcs.ts b/src/config/funcs.ts
index 473c502..93a8ef5 100644
--- a/src/config/funcs.ts
+++ b/src/config/funcs.ts
@@ -1,4 +1,4 @@
-import { GLib, monitorFile, readFileAsync, Variable } from "astal";
+import { GLib, monitorFile, readFileAsync, Variable, writeFileAsync } from "astal";
import config from ".";
import { loadStyleAsync } from "../../app";
import defaults from "./defaults";
@@ -92,3 +92,11 @@ export const initConfig = () => {
monitorFile(CONFIG, () => updateConfig().catch(e => console.warn(`Invalid config: ${e}`)));
updateConfig().catch(e => console.warn(`Invalid config: ${e}`));
};
+
+export const setConfig = async (path: string, value: any) => {
+ const conf = JSON.parse(await readFileAsync(CONFIG));
+ let obj = conf;
+ for (const p of path.split(".").slice(0, -1)) obj = obj[p];
+ obj[path.split(".").at(-1)!] = value;
+ await writeFileAsync(CONFIG, JSON.stringify(conf, null, 4));
+};
diff --git a/src/modules/launcher/actions.tsx b/src/modules/launcher/actions.tsx
index 053387c..11b07d0 100644
--- a/src/modules/launcher/actions.tsx
+++ b/src/modules/launcher/actions.tsx
@@ -8,6 +8,7 @@ import { setupCustomTooltip, type FlowBox } from "@/utils/widgets";
import { bind, execAsync, GLib, readFile, register, type Variable } from "astal";
import { Gtk, Widget } from "astal/gtk3";
import { launcher as config } from "config";
+import { setConfig } from "config/funcs";
import fuzzysort from "fuzzysort";
import AstalHyprland from "gi://AstalHyprland";
import { close, ContentBox, type LauncherContent, type Mode } from "./util";
@@ -24,6 +25,24 @@ interface ActionMap {
[k: string]: IAction;
}
+const transparencyActions = {
+ off: {
+ icon: "blur_off",
+ name: "Off",
+ description: "Completely opaque",
+ },
+ normal: {
+ icon: "blur_linear",
+ name: "Normal",
+ description: "Somewhat transparent",
+ },
+ high: {
+ icon: "blur_on",
+ name: "High",
+ description: "Extremely transparent",
+ },
+};
+
const autocomplete = (entry: Widget.Entry, action: string) => {
entry.set_text(`${config.actionPrefix.get()}${action} `);
entry.set_position(-1);
@@ -89,6 +108,12 @@ const actions = (mode: Variable<Mode>, entry: Widget.Entry): ActionMap => ({
description: "Change the current wallpaper",
action: () => autocomplete(entry, "wallpaper"),
},
+ transparency: {
+ icon: "opacity",
+ name: "Transparency",
+ description: "Change shell's transparency",
+ action: () => autocomplete(entry, "transparency"),
+ },
todo: {
icon: "checklist",
name: "Todo",
@@ -333,6 +358,17 @@ const Category = ({ path, wallpapers }: ICategory) => (
</Gtk.FlowBoxChild>
);
+const Transparency = ({ amount }: { amount: keyof typeof transparencyActions }) => (
+ <Action
+ {...transparencyActions[amount]}
+ args={[]}
+ action={() => {
+ setConfig("style.transparency", amount).catch(console.error);
+ close();
+ }}
+ />
+);
+
@register()
export default class Actions extends Widget.Box implements LauncherContent {
#map: ActionMap;
@@ -380,6 +416,11 @@ export default class Actions extends Widget.Box implements LauncherContent {
for (const { obj } of fuzzysort.go(term, list, { all: true, key: "path" }))
this.#content.add(random ? <Category {...(obj as ICategory)} /> : <Wallpaper {...obj} />);
+ } else if (action === "transparency") {
+ const list = Object.keys(transparencyActions);
+
+ for (const { target } of fuzzysort.go(args[1], list, { all: true }))
+ this.#content.add(<Transparency amount={target} />);
} else {
const list = this.#list.filter(
a => this.#map[a].available?.() ?? !config.disabledActions.get().includes(a)