summaryrefslogtreecommitdiff
path: root/pkgs/astal/src
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-06-19 22:53:20 -0400
committerFreya Murphy <freya@freyacat.org>2025-06-19 22:53:34 -0400
commit424e62dc79793187c46a222acf2a3fd88b9a7bd4 (patch)
tree092209fe447ce9a53107811828242babf95a241d /pkgs/astal/src
parentunofficial-homestuck-collection: 2.6.6 -> 2.6.7 (diff)
downloaddotfiles-nix-424e62dc79793187c46a222acf2a3fd88b9a7bd4.tar.gz
dotfiles-nix-424e62dc79793187c46a222acf2a3fd88b9a7bd4.tar.bz2
dotfiles-nix-424e62dc79793187c46a222acf2a3fd88b9a7bd4.zip
new astal app launcher, refactor astal build fn
Diffstat (limited to 'pkgs/astal/src')
-rw-r--r--pkgs/astal/src/launcher.lua10
-rw-r--r--pkgs/astal/src/lib.lua11
-rw-r--r--pkgs/astal/src/shell.lua (renamed from pkgs/astal/src/init.lua)2
-rw-r--r--pkgs/astal/src/style/style.scss4
-rw-r--r--pkgs/astal/src/style/widget/deck.scss4
-rw-r--r--pkgs/astal/src/style/widget/launcher.scss41
-rw-r--r--pkgs/astal/src/widget/launcher.lua113
7 files changed, 180 insertions, 5 deletions
diff --git a/pkgs/astal/src/launcher.lua b/pkgs/astal/src/launcher.lua
new file mode 100644
index 0000000..e645ac4
--- /dev/null
+++ b/pkgs/astal/src/launcher.lua
@@ -0,0 +1,10 @@
+local App = require("astal.gtk3.app")
+local lib = require("lib")
+
+local Launcher = require("widget.launcher")
+
+App:start({
+ instance_name = "launcher",
+ css = lib.src("main.css"),
+ main = Launcher,
+})
diff --git a/pkgs/astal/src/lib.lua b/pkgs/astal/src/lib.lua
index 8b1e443..98a5ecc 100644
--- a/pkgs/astal/src/lib.lua
+++ b/pkgs/astal/src/lib.lua
@@ -34,6 +34,17 @@ lib = {
return new_arr
end,
+ --- slices a list
+ slice = function(array, first, last, step)
+ local new_arr = {}
+
+ for i = first or 1, last or #array, step or 1 do
+ new_arr[#new_arr+1] = array[i]
+ end
+
+ return new_arr
+ end,
+
--- sort an array of object on a key
sort = function(array, func)
diff --git a/pkgs/astal/src/init.lua b/pkgs/astal/src/shell.lua
index 5bdfb03..c370349 100644
--- a/pkgs/astal/src/init.lua
+++ b/pkgs/astal/src/shell.lua
@@ -1,4 +1,3 @@
-local astal = require("astal")
local App = require("astal.gtk3.app")
local lib = require("lib")
@@ -7,6 +6,7 @@ local Corners = require("widget.corners")
local Deck = require("widget.deck")
App:start({
+ instance_name = "shell",
css = lib.src("main.css"),
main = function()
for _, mon in pairs(App.monitors) do
diff --git a/pkgs/astal/src/style/style.scss b/pkgs/astal/src/style/style.scss
index 0c66051..ddef6c7 100644
--- a/pkgs/astal/src/style/style.scss
+++ b/pkgs/astal/src/style/style.scss
@@ -4,6 +4,10 @@
@import "./theme";
+@function gtkalpha($c, $a) {
+ @return string.unquote("alpha(#{$c},#{$a})");
+}
+
* {
all: unset;
}
diff --git a/pkgs/astal/src/style/widget/deck.scss b/pkgs/astal/src/style/widget/deck.scss
index d7dd69c..adf8c00 100644
--- a/pkgs/astal/src/style/widget/deck.scss
+++ b/pkgs/astal/src/style/widget/deck.scss
@@ -1,8 +1,4 @@
-@function gtkalpha($c, $a) {
- @return string.unquote("alpha(#{$c},#{$a})");
-}
-
$deck-scale: $font-size * 4;
.deck {
diff --git a/pkgs/astal/src/style/widget/launcher.scss b/pkgs/astal/src/style/widget/launcher.scss
new file mode 100644
index 0000000..b39d292
--- /dev/null
+++ b/pkgs/astal/src/style/widget/launcher.scss
@@ -0,0 +1,41 @@
+
+.launcher {
+ > box {
+ padding: 5em;
+ background: gtkalpha($bg, 0.7);
+ border-radius: $outer-radius;
+ }
+
+ .search {
+ margin-bottom: 5em;
+ color: $surface-fg;
+ background: $surface-bg;
+ padding: $outer-gap;
+ border-radius: $outer-radius;
+ min-width: 20em;
+ }
+
+ .app {
+ background: transparent;
+ padding: $outer-gap;
+ margin: $outer-gap;
+ border-radius: $outer-radius;
+ min-width: 15em;
+ min-height: 15em;
+
+ &:hover {
+ background: gtkalpha($hover-bg, .5);
+ }
+
+ icon {
+ font-size: 9em;
+ }
+
+ .name {
+ margin-top: $outer-gap;
+ font-size: 1.25em;
+ color: gtkalpha($fg, 0.9);
+ }
+ }
+
+}
diff --git a/pkgs/astal/src/widget/launcher.lua b/pkgs/astal/src/widget/launcher.lua
new file mode 100644
index 0000000..cbac6c3
--- /dev/null
+++ b/pkgs/astal/src/widget/launcher.lua
@@ -0,0 +1,113 @@
+local astal = require("astal")
+local Widget = require("astal.gtk3.widget")
+local App = require("astal.gtk3.app")
+local Gdk = require("astal.gtk3").Gdk
+local Gtk = require("astal.gtk3").Gtk
+local astalify = require("astal.gtk3").astalify
+local Apps = astal.require("AstalApps")
+local Variable = astal.Variable
+local lib = require("lib")
+
+local MAX_ENTRIES = 20
+
+local FlowBox = astalify(Gtk.FlowBox)
+local FlowBoxChild = astalify(Gtk.FlowBoxChild)
+
+local apps = Apps.Apps()
+local text = Variable("")
+local list = text(function(text)
+ return lib.slice(apps:exact_query(text), 0, MAX_ENTRIES)
+end)
+
+function on_show()
+ text:set("")
+end
+
+function close()
+ App:quit()
+end
+
+function on_key_press(self, event)
+ if event.keyval == Gdk.KEY_Escape then
+ close()
+ end
+end
+
+function on_enter()
+ local found = apps:exact_query(text:get())[1]
+ if found then
+ found:launch()
+ close()
+ end
+end
+
+function Application(app)
+ return FlowBoxChild({
+ Widget.Button({
+ class_name = "app",
+ on_clicked = function()
+ app:launch()
+ close()
+ end,
+ Widget.Box({
+ halign = "CENTER",
+ valign = "CENTER",
+ vertical = true,
+ Widget.Icon({
+ icon = app.icon_name,
+ }),
+ Widget.Label({
+ class_name = "name",
+ label = app.name,
+ valign = "CENTER",
+ ellipsize = "END",
+ max_width_chars = 20,
+ }),
+ }),
+ }),
+ })
+end
+
+function Applications(apps)
+ return FlowBox({
+ hexpand = true,
+ homogeneous = true,
+ class_name = "apps",
+ lib.map(apps, Application)
+ })
+end
+
+function Launcher()
+ return Widget.Box({
+ vertical = true,
+ Widget.Entry({
+ class_name = "search",
+ placeholder_text = "Search",
+ halign = "CENTER",
+ text = text(),
+ on_changed = function(self)
+ text:set(self.text)
+ end,
+ on_activate = on_enter,
+ }),
+ Widget.Box({
+ class_name = "apps",
+ list:as(Applications),
+ }),
+ })
+end
+
+return function()
+ local Anchor = astal.require('Astal').WindowAnchor
+
+ return Widget.Window({
+ class_name = "launcher",
+ anchor = Anchor.TOP + Anchor.BOTTOM + Anchor.LEFT + Anchor.RIGHT,
+ exclusivity = "EXCLUSIVE",
+ keymode = "ON_DEMAND",
+ application = App,
+ on_show = on_show,
+ on_key_press_event = on_key_press,
+ Launcher(),
+ })
+end