summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-09-07 18:00:17 +0200
committerAylur <[email protected]>2024-09-07 18:00:17 +0200
commite06ae737ef0a29e98363d6453ae3049aed164a64 (patch)
treec41bd26dcf2411400cdc8c6601f22af6ca25b1f6 /core
parent3c68f1eda2d0ad89e2c55560c25947615296168f (diff)
feat: App monitor signals
Diffstat (limited to 'core')
-rw-r--r--core/gjs/src/application.ts6
-rw-r--r--core/src/astal.vala33
2 files changed, 35 insertions, 4 deletions
diff --git a/core/gjs/src/application.ts b/core/gjs/src/application.ts
index 0ba247e..bf82cbe 100644
--- a/core/gjs/src/application.ts
+++ b/core/gjs/src/application.ts
@@ -22,7 +22,7 @@ type Config = Partial<{
import { setConsoleLogDomain } from "console"
import { exit, programArgs } from "system"
-class AstalJS extends Astal.Application {
+export default new (class AstalJS extends Astal.Application {
static { GObject.registerClass(this) }
eval(body: string): Promise<any> {
@@ -100,6 +100,4 @@ class AstalJS extends Astal.Application {
this.runAsync([])
}
-}
-
-export default new AstalJS()
+})
diff --git a/core/src/astal.vala b/core/src/astal.vala
index 316da6b..134293b 100644
--- a/core/src/astal.vala
+++ b/core/src/astal.vala
@@ -9,6 +9,27 @@ public class Application : Gtk.Application {
public string socket_path { get; private set; }
[DBus (visible=false)]
+ public signal void monitor_added(Gdk.Monitor monitor);
+
+ [DBus (visible=false)]
+ public signal void monitor_removed(Gdk.Monitor monitor);
+
+ [DBus (visible=false)]
+ public List<weak Gdk.Monitor> monitors {
+ owned get {
+ var display = Gdk.Display.get_default();
+ var list = new List<weak Gdk.Monitor>();
+ for (var i = 0; i <= display.get_n_monitors(); ++i) {
+ var mon = display.get_monitor(i);
+ if (mon != null) {
+ list.append(mon);
+ }
+ }
+ return list;
+ }
+ }
+
+ [DBus (visible=false)]
public string instance_name {
get { return _instance_name; }
set {
@@ -219,6 +240,18 @@ public class Application : Gtk.Application {
if (instance_name == null)
instance_name = "astal";
+ activate.connect(() => {
+ var display = Gdk.Display.get_default();
+ display.monitor_added.connect((mon) => {
+ monitor_added(mon);
+ notify_property("monitors");
+ });
+ display.monitor_removed.connect((mon) => {
+ monitor_removed(mon);
+ notify_property("monitors");
+ });
+ });
+
shutdown.connect(() => { try { quit(); } catch(Error err) {} });
Unix.signal_add(1, () => { try { quit(); } catch(Error err) {} }, Priority.HIGH);
Unix.signal_add(2, () => { try { quit(); } catch(Error err) {} }, Priority.HIGH);