aboutsummaryrefslogtreecommitdiff
path: root/ags/modules/applauncher.js
diff options
context:
space:
mode:
authoreric.marin <maarin.eric@gmail.com>2024-12-26 14:33:06 +0100
committereric.marin <maarin.eric@gmail.com>2024-12-30 21:07:42 +0100
commit4de5a217c25fe83bb54063f8d842b78c9e6d7fb3 (patch)
tree0460bc0600492324f111524dfdff1ef85c9fbf8e /ags/modules/applauncher.js
parentee2b01a3fff043a8b977385227c2659bbcf2e59a (diff)
downloaddotfiles-4de5a217c25fe83bb54063f8d842b78c9e6d7fb3.tar.gz
dotfiles-4de5a217c25fe83bb54063f8d842b78c9e6d7fb3.zip
wallust
Diffstat (limited to 'ags/modules/applauncher.js')
-rw-r--r--ags/modules/applauncher.js107
1 files changed, 0 insertions, 107 deletions
diff --git a/ags/modules/applauncher.js b/ags/modules/applauncher.js
deleted file mode 100644
index f380185..0000000
--- a/ags/modules/applauncher.js
+++ /dev/null
@@ -1,107 +0,0 @@
-const { query } = await Service.import("applications")
-const WINDOW_NAME = "applauncher"
-
-/** @param {import('resource:///com/github/Aylur/ags/service/applications.js').Application} app */
-const AppItem = app => Widget.Button({
- on_clicked: () => {
- App.closeWindow(WINDOW_NAME)
- app.launch()
- },
- attribute: { app },
- child: Widget.Box({
- children: [
- Widget.Icon({
- icon: app.icon_name || "",
- size: 42,
- }),
- Widget.Label({
- class_name: "title",
- label: app.name,
- xalign: 0,
- vpack: "center",
- truncate: "end",
- }),
- ],
- }),
-})
-
-const Applauncher = ({ width = 500, height = 500, spacing = 12 }) => {
- // list of application buttons
- let applications = query("").map(AppItem)
-
- // container holding the buttons
- const list = Widget.Box({
- vertical: true,
- children: applications,
- spacing,
- })
-
- // repopulate the box, so the most frequent apps are on top of the list
- function repopulate() {
- applications = query("").map(AppItem)
- list.children = applications
- }
-
- // search entry
- const entry = Widget.Entry({
- hexpand: true,
- css: `margin-bottom: ${spacing}px;`,
-
- // to launch the first item on Enter
- on_accept: () => {
- // make sure we only consider visible (searched for) applications
- const results = applications.filter((item) => item.visible);
- if (results[0]) {
- App.toggleWindow(WINDOW_NAME)
- results[0].attribute.app.launch()
- }
- },
-
- // filter out the list
- on_change: ({ text }) => applications.forEach(item => {
- item.visible = item.attribute.app.match(text ?? "")
- }),
- })
-
- return Widget.Box({
- vertical: true,
- css: `margin: ${spacing * 2}px;`,
- children: [
- entry,
-
- // wrap the list in a scrollable
- Widget.Scrollable({
- hscroll: "never",
- css: `min-width: ${width}px;`
- + `min-height: ${height}px;`,
- child: list,
- }),
- ],
- setup: self => self.hook(App, (_, windowName, visible) => {
- if (windowName !== WINDOW_NAME)
- return
-
- // when the applauncher shows up
- if (visible) {
- repopulate()
- entry.text = ""
- entry.grab_focus()
- }
- }),
- })
-}
-
-// there needs to be only one instance
-export const applauncher = Widget.Window({
- name: WINDOW_NAME,
- setup: self => self.keybind("Escape", () => {
- App.closeWindow(WINDOW_NAME)
- }),
- visible: false,
- keymode: "exclusive",
- child: Applauncher({
- width: 500,
- height: 500,
- spacing: 12,
- }),
-})