diff --git a/app.js b/app.js
index a6254b7..14d0d8d 100644
--- a/app.js
+++ b/app.js
@@ -38,6 +38,15 @@ bind($('.btn4'), 'click', async function () {
// native.clipboard.clear()
})
+bind($('.btn5'), 'click', async function () {
+ native.tray()
+})
+
+bind($('.btn6'), 'click', async function () {
+ console.log(await native.screen.getAllDisplays())
+ console.log(await native.screen.getPrimaryDisplay())
+})
+
bind($('textarea'), 'paste', async function (ev) {
let items = ev.clipboardData.items
for (let it of items) {
diff --git a/index.html b/index.html
index 7b4e8b5..aca0cc8 100644
--- a/index.html
+++ b/index.html
@@ -34,6 +34,8 @@
+
+
diff --git a/inject.js b/inject.js
index a3e7149..8c608ae 100644
--- a/inject.js
+++ b/inject.js
@@ -185,5 +185,13 @@ Object.assign(native, {
return handler('clipboard', { action: 'clear' })
}
},
+ screen: {
+ getAllDisplays() {
+ return handler('monitor', { action: 'get-all' })
+ },
+ getPrimaryDisplay() {
+ return handler('monitor', { action: 'get-primary' })
+ }
+ },
handler
})
diff --git a/main.py b/main.py
index 41ea53b..bf67661 100755
--- a/main.py
+++ b/main.py
@@ -18,6 +18,22 @@ except (ValueError, ImportError):
AppIndicator3 = None
+def get_monitor_info(monitor):
+ return {
+ "model": monitor.props.model,
+ "scale_factor": monitor.props.scale_factor,
+ "manufacturer": monitor.props.manufacturer,
+ "refresh_rate": monitor.props.refresh_rate,
+ "is_primary": monitor.is_primary(),
+ "geometry": {
+ "width": monitor.props.geometry.width,
+ "height": monitor.props.geometry.height,
+ "x": monitor.props.geometry.x,
+ "y": monitor.props.geometry.y,
+ }
+ }
+
+
class WebKitWindow(Gtk.Window):
def __init__(self):
@@ -59,8 +75,8 @@ class WebKitWindow(Gtk.Window):
- # self.webview.load_uri("http://127.0.0.1:10086/index.html")
- self.webview.load_uri("https://benchmark.wkit.fun")
+ self.webview.load_uri("http://127.0.0.1:10086/index.html")
+ # self.webview.load_uri("https://benchmark.wkit.fun")
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
@@ -72,6 +88,8 @@ class WebKitWindow(Gtk.Window):
+
+
def create_tray(self):
if AppIndicator3 :
@@ -190,6 +208,25 @@ class WebKitWindow(Gtk.Window):
self.webview.send_message_to_page(WebKit2.UserMessage.new('blabla'))
self.webview.evaluate_javascript(scripts, -1)
+
+ case 'monitor':
+ if params['action'] == 'get-all':
+ display = Gdk.Display.get_default()
+ monitor_num = display.get_n_monitors()
+ monitors = [display.get_monitor(i) for i in range(monitor_num)]
+ monitors = [get_monitor_info(m) for m in monitors]
+
+ scripts = 'native.$emit("' + callback + '",' + json.dumps(monitors) + ')'
+ self.webview.evaluate_javascript(scripts, -1)
+
+ elif params['action'] == 'get-primary':
+ display = Gdk.Display.get_default()
+ monitor = display.get_primary_monitor()
+ info = get_monitor_info(monitor)
+
+ scripts = 'native.$emit("' + callback + '",' + json.dumps(info) + ')'
+ self.webview.evaluate_javascript(scripts, -1)
+
case _:
if callback :
res = {"foo": 123, "bar": (11,22,33)}
@@ -206,6 +243,11 @@ win = WebKitWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
+
+
+
+
+
tray = win.create_tray()
Gtk.main()
\ No newline at end of file
diff --git a/notes/monitor.py b/notes/monitor.py
new file mode 100644
index 0000000..d800d9b
--- /dev/null
+++ b/notes/monitor.py
@@ -0,0 +1,30 @@
+import gi
+
+gi.require_version("Gtk", "3.0")
+gi.require_version("WebKit2", "4.1")
+
+from gi.repository import Gtk, Gdk
+
+
+
+def get_monitor_info(monitor):
+ return {
+ "model": monitor.props.model,
+ "scale_factor": monitor.props.scale_factor,
+ "manufacturer": monitor.props.manufacturer,
+ "refresh_rate": monitor.props.refresh_rate,
+ "is_primary": monitor.is_primary(),
+ "geometry": {
+ "width": monitor.props.geometry.width,
+ "height": monitor.props.geometry.height,
+ "x": monitor.props.geometry.x,
+ "y": monitor.props.geometry.y,
+ }
+ }
+
+
+
+display = Gdk.Display.get_default()
+monitor_num = display.get_n_monitors()
+monitors = [display.get_monitor(i) for i in range(monitor_num)]
+monitors = [get_monitor_info(m) for m in monitors]
\ No newline at end of file