✨ ags: new window management system, adjustments, use adwaita sans
This commit is contained in:
+99
-93
@@ -4,108 +4,114 @@ import { cleanExec, getAstalApps } from "../scripts/apps";
|
||||
import AstalApps from "gi://AstalApps";
|
||||
|
||||
const { TOP, LEFT, RIGHT, BOTTOM } = Astal.WindowAnchor;
|
||||
const searchString = new Variable<string>("");
|
||||
let searchSubscription: () => void;
|
||||
|
||||
export const AppsWindow = new Widget.Window({
|
||||
namespace: "apps-window",
|
||||
layer: Astal.Layer.OVERLAY,
|
||||
exclusivity: Astal.Exclusivity.IGNORE,
|
||||
anchor: TOP | LEFT | RIGHT | BOTTOM,
|
||||
visible: false,
|
||||
keymode: Astal.Keymode.EXCLUSIVE,
|
||||
onDestroy: () => searchSubscription(),
|
||||
setup: (window) => {
|
||||
const flowbox = new Gtk.FlowBox({
|
||||
rowSpacing: 6,
|
||||
homogeneous: true,
|
||||
columnSpacing: 6,
|
||||
expand: false,
|
||||
orientation: Gtk.Orientation.HORIZONTAL,
|
||||
visible: true
|
||||
} as Gtk.FlowBox.ConstructorProps);
|
||||
export const AppsWindow = (mon: number): (Widget.Window) => {
|
||||
const searchString = new Variable<string>("");
|
||||
let searchSubscription: () => void;
|
||||
|
||||
const entry = new Widget.Entry({
|
||||
className: "entry",
|
||||
halign: Gtk.Align.CENTER,
|
||||
primary_icon_name: "system-search",
|
||||
onChanged: (entry) => {
|
||||
searchString.set(entry.text);
|
||||
}
|
||||
} as Widget.EntryProps);
|
||||
return new Widget.Window({
|
||||
namespace: "apps-window",
|
||||
layer: Astal.Layer.OVERLAY,
|
||||
exclusivity: Astal.Exclusivity.IGNORE,
|
||||
anchor: TOP | LEFT | RIGHT | BOTTOM,
|
||||
keymode: Astal.Keymode.EXCLUSIVE,
|
||||
monitor: mon,
|
||||
onDestroy: () => {
|
||||
searchString.set("");
|
||||
searchSubscription()
|
||||
},
|
||||
setup: (window) => {
|
||||
const flowbox = new Gtk.FlowBox({
|
||||
rowSpacing: 6,
|
||||
homogeneous: true,
|
||||
columnSpacing: 6,
|
||||
expand: false,
|
||||
orientation: Gtk.Orientation.HORIZONTAL,
|
||||
visible: true
|
||||
} as Gtk.FlowBox.ConstructorProps);
|
||||
|
||||
searchSubscription = searchString.subscribe((str: string) => {
|
||||
const results: Array<AstalApps.Application> = getAstalApps().fuzzy_query(str);
|
||||
const entry = new Widget.Entry({
|
||||
className: "entry",
|
||||
halign: Gtk.Align.CENTER,
|
||||
primary_icon_name: "system-search",
|
||||
onChanged: (entry) => {
|
||||
searchString.set(entry.text);
|
||||
}
|
||||
} as Widget.EntryProps);
|
||||
|
||||
// Destroy is handled by GnomeJS
|
||||
flowbox.get_children().map(flowboxChild => flowbox.remove(flowboxChild));
|
||||
searchSubscription = searchString.subscribe((str: string) => {
|
||||
const results: Array<AstalApps.Application> = getAstalApps().fuzzy_query(str);
|
||||
|
||||
results.map(app => {
|
||||
flowbox.insert(new Widget.Button({
|
||||
onClick: (_button, event: Astal.ClickEvent) => {
|
||||
if(event.button === Astal.MouseButton.PRIMARY) {
|
||||
searchString.set("");
|
||||
entry.text = "";
|
||||
window.hide();
|
||||
cleanExec(app);
|
||||
// Destroy is handled by GnomeJS
|
||||
flowbox.get_children().map(flowboxChild => flowbox.remove(flowboxChild));
|
||||
|
||||
return;
|
||||
}
|
||||
results.map(app => {
|
||||
flowbox.insert(new Widget.Button({
|
||||
onClick: (_button, event: Astal.ClickEvent) => {
|
||||
if(event.button === Astal.MouseButton.PRIMARY) {
|
||||
searchString.set("");
|
||||
entry.text = "";
|
||||
window.close();
|
||||
cleanExec(app);
|
||||
|
||||
// select app launch options TODO
|
||||
},
|
||||
child: new Widget.Box({
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
children: [
|
||||
new Widget.Icon({
|
||||
className: "icon",
|
||||
expand: true,
|
||||
icon: app.get_icon_name()
|
||||
} as Widget.IconProps),
|
||||
new Widget.Label({
|
||||
className: "name",
|
||||
truncate: true,
|
||||
label: app.get_name()
|
||||
} as Widget.LabelProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.ButtonProps), -1);
|
||||
return;
|
||||
}
|
||||
|
||||
const flowboxchild = flowbox.get_children()[flowbox.get_children().length-1];
|
||||
flowboxchild.set_valign(Gtk.Align.START);
|
||||
// select app launch options TODO
|
||||
},
|
||||
child: new Widget.Box({
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
children: [
|
||||
new Widget.Icon({
|
||||
className: "icon",
|
||||
expand: true,
|
||||
icon: app.get_icon_name()
|
||||
} as Widget.IconProps),
|
||||
new Widget.Label({
|
||||
className: "name",
|
||||
truncate: true,
|
||||
label: app.get_name()
|
||||
} as Widget.LabelProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.ButtonProps), -1);
|
||||
|
||||
const flowboxchild = flowbox.get_children()[flowbox.get_children().length-1];
|
||||
flowboxchild.set_valign(Gtk.Align.START);
|
||||
});
|
||||
|
||||
const firstChild = flowbox.get_child_at_index(0);
|
||||
firstChild && flowbox.select_child(firstChild);
|
||||
});
|
||||
|
||||
const firstChild = flowbox.get_child_at_index(0);
|
||||
firstChild && flowbox.select_child(firstChild);
|
||||
});
|
||||
|
||||
window.add(new Widget.EventBox({
|
||||
onClick: () => {
|
||||
searchString.set("");
|
||||
entry.text = "";
|
||||
window.hide();
|
||||
},
|
||||
onKeyPressEvent: (_, event: Gdk.Event) => {
|
||||
if(event.get_keyval()[1] === Gdk.KEY_Escape) {
|
||||
window.add(new Widget.EventBox({
|
||||
onClick: () => {
|
||||
searchString.set("");
|
||||
entry.text = "";
|
||||
window.hide();
|
||||
}
|
||||
},
|
||||
child: new Widget.Box({
|
||||
className: "apps-window-container",
|
||||
expand: true,
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
children: [
|
||||
entry,
|
||||
new Widget.Scrollable({
|
||||
vscroll: Gtk.PolicyType.AUTOMATIC,
|
||||
hscroll: Gtk.PolicyType.NEVER,
|
||||
expand: true,
|
||||
child: flowbox
|
||||
} as Widget.ScrollableProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.EventBoxProps));
|
||||
}
|
||||
} as Widget.WindowProps);
|
||||
window.close();
|
||||
},
|
||||
onKeyPressEvent: (_, event: Gdk.Event) => {
|
||||
if(event.get_keyval()[1] === Gdk.KEY_Escape) {
|
||||
searchString.set("");
|
||||
entry.text = "";
|
||||
window.close();
|
||||
}
|
||||
},
|
||||
child: new Widget.Box({
|
||||
className: "apps-window-container",
|
||||
expand: true,
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
children: [
|
||||
entry,
|
||||
new Widget.Scrollable({
|
||||
vscroll: Gtk.PolicyType.AUTOMATIC,
|
||||
hscroll: Gtk.PolicyType.NEVER,
|
||||
expand: true,
|
||||
child: flowbox
|
||||
} as Widget.ScrollableProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.EventBoxProps));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user