aboutsummaryrefslogtreecommitdiff
path: root/linux/home/.config/ags/widget/overview/Window.ts
blob: 02f71eb2dd805c1a84eceabedd322278bd796c1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { type Client } from "types/service/hyprland"
import { createSurfaceFromWidget, icon } from "lib/utils"
import Gdk from "gi://Gdk"
import Gtk from "gi://Gtk?version=3.0"
import options from "options"
import icons from "lib/icons"

const monochrome = options.overview.monochromeIcon
const TARGET = [Gtk.TargetEntry.new("text/plain", Gtk.TargetFlags.SAME_APP, 0)]
const hyprland = await Service.import("hyprland")
const apps = await Service.import("applications")
const dispatch = (args: string) => hyprland.messageAsync(`dispatch ${args}`)

export default ({ address, size: [w, h], class: c, title }: Client) => Widget.Button({
    class_name: "client",
    attribute: { address },
    tooltip_text: `${title}`,
    child: Widget.Icon({
        css: options.overview.scale.bind().as(v => `
            min-width: ${(v / 100) * w}px;
            min-height: ${(v / 100) * h}px;
        `),
        icon: monochrome.bind().as(m => {
            const app = apps.list.find(app => app.match(c))
            if (!app)
                return icons.fallback.executable + (m ? "-symbolic" : "")


            return icon(
                app.icon_name + (m ? "-symbolic" : ""),
                icons.fallback.executable + (m ? "-symbolic" : ""),
            )
        }),
    }),
    on_secondary_click: () => dispatch(`closewindow address:${address}`),
    on_clicked: () => {
        dispatch(`focuswindow address:${address}`)
        App.closeWindow("overview")
    },
    setup: btn => btn
        .on("drag-data-get", (_w, _c, data) => data.set_text(address, address.length))
        .on("drag-begin", (_, context) => {
            Gtk.drag_set_icon_surface(context, createSurfaceFromWidget(btn))
            btn.toggleClassName("hidden", true)
        })
        .on("drag-end", () => btn.toggleClassName("hidden", false))
        .drag_source_set(Gdk.ModifierType.BUTTON1_MASK, TARGET, Gdk.DragAction.COPY),
})