summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--gjs/src/application.ts2
-rw-r--r--gjs/src/astalify.ts27
-rw-r--r--gjs/src/imports.ts1
-rw-r--r--gjs/src/jsx/jsx-runtime.ts7
-rw-r--r--lua/astal/application.lua2
-rw-r--r--lua/astal/init.lua2
-rw-r--r--lua/astal/widget.lua9
-rw-r--r--node/src/application.ts2
-rw-r--r--node/src/astalify.ts15
-rw-r--r--node/src/imports.ts1
-rw-r--r--node/src/index.ts2
-rw-r--r--python/astal/__init__.py5
-rw-r--r--python/astal/widget.py4
14 files changed, 54 insertions, 28 deletions
diff --git a/README.md b/README.md
index 0829179..cb5d17c 100644
--- a/README.md
+++ b/README.md
@@ -201,11 +201,8 @@ templates and examples instead to get started with development.
## Help needed
-- packaging
- - I am not familiar with python or lua ecosystem at all how should they be distributed?
- node-gtk promise issue
- python types
- - I don't know much python, and quite honestly I hate python
## TODO
diff --git a/gjs/src/application.ts b/gjs/src/application.ts
index 42bbb72..b42492f 100644
--- a/gjs/src/application.ts
+++ b/gjs/src/application.ts
@@ -1,7 +1,7 @@
import { Astal, GObject, Gio } from "./imports.js"
type RequestHandler = {
- (request: string, res: (response: string) => void): void
+ (request: string, res: (response: any) => void): void
}
type Config = Partial<{
diff --git a/gjs/src/astalify.ts b/gjs/src/astalify.ts
index 3a613a5..4b4145c 100644
--- a/gjs/src/astalify.ts
+++ b/gjs/src/astalify.ts
@@ -1,5 +1,6 @@
import Binding, { kebabify, type Connectable, type Subscribable } from "./binding.js"
import { Astal, Gtk } from "./imports.js"
+import { execAsync } from "./process.js"
export type Widget<C extends { new(...args: any): Gtk.Widget }> = InstanceType<C> & {
className: string
@@ -97,8 +98,15 @@ function ctor(self: any, config: any, ...children: Gtk.Widget[]) {
self.add(child)
}
- for (const [signal, callback] of onHandlers)
- self.connect(signal, callback)
+ for (const [signal, callback] of onHandlers) {
+ if (typeof callback === "function") {
+ self.connect(signal, callback)
+ }
+ else {
+ self.connect(signal, () => execAsync(callback)
+ .then(print).catch(console.error))
+ }
+ }
if (self instanceof Gtk.Container) {
if (pchildren) {
@@ -172,14 +180,19 @@ type BindableProps<T> = {
[K in keyof T]: Binding<NonNullable<T[K]>> | T[K];
}
+type SigHandler<
+ W extends { new(...args: any): Gtk.Widget },
+ Args extends Array<unknown>,
+> = ((self: Widget<W>, ...args: Args) => unknown) | string | string[]
+
export type ConstructProps<
Self extends { new(...args: any[]): any },
Props = unknown,
- Signals extends Record<string, Array<unknown>> = Record<string, []>
-> = {
- [Key in `on${string}`]: (self: Widget<Self>) => unknown
-} & Partial<{
- [sig in keyof Signals]: (self: Widget<Self>, ...args: Signals[sig]) => unknown
+ Signals extends Record<`on${string}`, Array<unknown>> = Record<`on${string}`, any[]>
+> = Partial<{
+ [S in keyof Signals]: SigHandler<Self, Signals[S]>
+}> & Partial<{
+ [Key in `on${string}`]: SigHandler<Self, any[]>
}> & BindableProps<Props & {
className?: string
css?: string
diff --git a/gjs/src/imports.ts b/gjs/src/imports.ts
index c6724c1..cbed004 100644
--- a/gjs/src/imports.ts
+++ b/gjs/src/imports.ts
@@ -6,4 +6,5 @@ export { default as Astal } from "gi://Astal?version=0.1"
export { default as GObject } from "gi://GObject?version=2.0"
export { default as Gio } from "gi://Gio?version=2.0"
export { default as Gtk } from "gi://Gtk?version=3.0"
+export { default as Gdk } from "gi://Gdk?version=3.0"
export { default as GLib } from "gi://GLib?version=2.0"
diff --git a/gjs/src/jsx/jsx-runtime.ts b/gjs/src/jsx/jsx-runtime.ts
index 3d9cc49..7a90dc5 100644
--- a/gjs/src/jsx/jsx-runtime.ts
+++ b/gjs/src/jsx/jsx-runtime.ts
@@ -17,6 +17,8 @@ export function jsx(
if (!Array.isArray(children))
children = [children]
+ else
+ children = children.flat()
if (ctor === "centerbox") {
if (children[0])
@@ -27,11 +29,6 @@ export function jsx(
props.endWidget = w(children[2])
}
- else if (ctor === "label" && children[0]) {
- props.label = children[0]
- delete props.children
- }
-
else if (children.length === 1) {
props.child = w(children[0])
delete props.children
diff --git a/lua/astal/application.lua b/lua/astal/application.lua
index 551367a..8402a59 100644
--- a/lua/astal/application.lua
+++ b/lua/astal/application.lua
@@ -25,7 +25,7 @@ local app = AstalLua()
---@field cursor_theme? string
---@field css? string
---@field hold? boolean
----@field request_handler? fun(msg: string, response: fun(res: string))
+---@field request_handler? fun(msg: string, response: fun(res: any))
---@param config StartConfig | nil
---@param callback function | nil
diff --git a/lua/astal/init.lua b/lua/astal/init.lua
index c247533..37c7119 100644
--- a/lua/astal/init.lua
+++ b/lua/astal/init.lua
@@ -1,6 +1,7 @@
local lgi = require("lgi")
local Astal = lgi.require("Astal", "0.1")
local Gtk = lgi.require("Gtk", "3.0")
+local Gdk = lgi.require("Gdk", "3.0")
local GObject = lgi.require("GObject", "2.0")
local Widget = require("astal.widget")
local Variable = require("astal.variable")
@@ -23,6 +24,7 @@ return {
Astal = Astal,
Gtk = Gtk,
+ Gdk = Gdk,
GObject = GObject,
GLib = lgi.require("GLib", "2.0"),
Gio = lgi.require("Gio", "2.0"),
diff --git a/lua/astal/widget.lua b/lua/astal/widget.lua
index 2f58b7a..7be240f 100644
--- a/lua/astal/widget.lua
+++ b/lua/astal/widget.lua
@@ -3,6 +3,7 @@ local Astal = lgi.require("Astal", "0.1")
local Gtk = lgi.require("Gtk", "3.0")
local GObject = lgi.require("GObject", "2.0")
local Binding = require("astal.binding")
+local exec_async = require("astal.process").exec_async
local function filter(tbl, fn)
local copy = {}
@@ -101,6 +102,14 @@ local function astalify(ctor)
end
end
+ for prop, value in pairs(props) do
+ if string.sub(prop, 0, 2) == "on" and type(value) ~= "function" then
+ props[prop] = function()
+ exec_async(value, print, print)
+ end
+ end
+ end
+
local widget = ctor(props)
for prop, binding in pairs(bindings) do
diff --git a/node/src/application.ts b/node/src/application.ts
index 552f2a9..13a999c 100644
--- a/node/src/application.ts
+++ b/node/src/application.ts
@@ -2,7 +2,7 @@ import gi from "node-gtk"
const Astal = gi.require("Astal", "0.1")
type RequestHandler = {
- (request: string, res: (response: string) => void): void
+ (request: string, res: (response: any) => void): void
}
type Config = Partial<{
diff --git a/node/src/astalify.ts b/node/src/astalify.ts
index bae6cc7..9f83e71 100644
--- a/node/src/astalify.ts
+++ b/node/src/astalify.ts
@@ -167,14 +167,19 @@ type BindableProps<T> = {
[K in keyof T]: Binding<NonNullable<T[K]>> | T[K];
}
+type SigHandler<
+ W extends { new(...args: any): Gtk.Widget },
+ Args extends Array<unknown>,
+> = ((self: Widget<W>, ...args: Args) => unknown) | string | string[]
+
export type ConstructProps<
Self extends { new(...args: any[]): any },
Props = unknown,
- Signals extends Record<string, Array<unknown>> = Record<string, []>
-> = {
- [Key in `on${string}`]: (self: Widget<Self>) => unknown
-} & Partial<{
- [sig in keyof Signals]: (self: Widget<Self>, ...args: Signals[sig]) => unknown
+ Signals extends Record<`on${string}`, Array<unknown>> = Record<`on${string}`, any[]>
+> = Partial<{
+ [S in keyof Signals]: SigHandler<Self, Signals[S]>
+}> & Partial<{
+ [Key in `on${string}`]: SigHandler<Self, any[]>
}> & BindableProps<Props & {
className?: string
css?: string
diff --git a/node/src/imports.ts b/node/src/imports.ts
index 47f582a..c2a9c71 100644
--- a/node/src/imports.ts
+++ b/node/src/imports.ts
@@ -2,6 +2,7 @@ import gi from "node-gtk"
export { gi }
export const Gtk = gi.require("Gtk", "3.0")
+export const Gdk = gi.require("Gdk", "3.0")
export const GLib = gi.require("GLib", "2.0")
export const Gio = gi.require("Gio", "3.0")
export const GObject = gi.require("GObject", "2.0")
diff --git a/node/src/index.ts b/node/src/index.ts
index 77fba88..5270469 100644
--- a/node/src/index.ts
+++ b/node/src/index.ts
@@ -6,4 +6,4 @@ export * as Widget from "./widgets.js"
export { App } from "./application.js"
// for convinience
-export { Astal, Gtk, GLib, GObject, Gio, gi } from "./imports.js"
+export { Astal, Gtk, Gdk, GLib, GObject, Gio, gi } from "./imports.js"
diff --git a/python/astal/__init__.py b/python/astal/__init__.py
index c679c4a..58d0a0d 100644
--- a/python/astal/__init__.py
+++ b/python/astal/__init__.py
@@ -2,10 +2,11 @@ import gi
gi.require_version("Astal", "0.1")
gi.require_version("Gtk", "3.0")
+gi.require_version("Gdk", "3.0")
gi.require_version("GLib", "2.0")
gi.require_version("Gio", "2.0")
gi.require_version("GObject", "2.0")
-from gi.repository import Astal, Gtk, GLib, Gio, GObject
+from gi.repository import Astal, Gtk, GLib, Gio, GObject, Gdk
from .application import App
from .variable import Variable
from .binding import Binding
@@ -13,4 +14,4 @@ from . import widget as Widget
bind = Binding
-__all__ = ["App", "Variable", "Widget" "bind", "Astal", "Gtk", "GLib", "Gio", "GObject"]
+__all__ = ["App", "Variable", "Widget" "bind", "Astal", "Gtk", "Gdk", "GLib", "Gio", "GObject"]
diff --git a/python/astal/widget.py b/python/astal/widget.py
index 7070e8f..7a458bf 100644
--- a/python/astal/widget.py
+++ b/python/astal/widget.py
@@ -1,5 +1,5 @@
from gi.repository import Astal, Gtk
-from .binding import Binding
+from .binding import Binding, kebabify
def set_child(self, child):
@@ -46,7 +46,7 @@ def astalify(ctor):
self.connect("destroy", lambda _: unsub())
for key, value in handlers.items():
- self.connect(key.replace("on_", ""), value)
+ self.connect(kebabify(key.replace("on_", "")), value)
if setup:
setup(self)