@osmn-byhn/widget-core-windows 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +154 -162
- package/binding.gyp +44 -69
- package/dist/autostart.d.ts +1 -7
- package/dist/autostart.d.ts.map +1 -1
- package/dist/autostart.js +8 -106
- package/dist/autostart.js.map +1 -1
- package/dist/autostart.test.js +4 -20
- package/dist/autostart.test.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -16
- package/dist/index.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +53 -53
- package/native/WidgetManager.h +29 -26
- package/native/host.cpp +70 -70
- package/native/main.cpp +65 -57
- package/native/win32/WidgetManager.cpp +246 -246
- package/package.json +49 -49
- package/native/linux/WidgetManager.cpp +0 -278
- package/native/macos/WidgetManager.mm +0 -87
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@osmn-byhn/widget-core-windows",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Windows desktop widget manager library.",
|
|
5
|
-
"author": "Osman Beyhan",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/osmn-byhn/widget-core-windows.git"
|
|
10
|
-
},
|
|
11
|
-
"bugs": {
|
|
12
|
-
"url": "https://github.com/osmn-byhn/widget-core-windows/issues"
|
|
13
|
-
},
|
|
14
|
-
"homepage": "https://widget-core-windows.osmanbeyhan.com",
|
|
15
|
-
"type": "module",
|
|
16
|
-
"main": "dist/index.js",
|
|
17
|
-
"types": "dist/index.d.ts",
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build": "tsc",
|
|
20
|
-
"test": "vitest run",
|
|
21
|
-
"test:watch": "vitest",
|
|
22
|
-
"install": "node-gyp rebuild"
|
|
23
|
-
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
"widget",
|
|
26
|
-
"desktop",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"electron-alternative"
|
|
31
|
-
],
|
|
32
|
-
"files": [
|
|
33
|
-
"dist",
|
|
34
|
-
"native",
|
|
35
|
-
"binding.gyp",
|
|
36
|
-
"README.md",
|
|
37
|
-
"LICENSE"
|
|
38
|
-
],
|
|
39
|
-
"publishConfig": {
|
|
40
|
-
"access": "public"
|
|
41
|
-
},
|
|
42
|
-
"gypfile": true,
|
|
43
|
-
"devDependencies": {
|
|
44
|
-
"@types/node": "^25.5.0",
|
|
45
|
-
"node-addon-api": "^8.7.0",
|
|
46
|
-
"typescript": "^6.0.2",
|
|
47
|
-
"vitest": "^4.1.2"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@osmn-byhn/widget-core-windows",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Windows-only desktop widget manager library.",
|
|
5
|
+
"author": "Osman Beyhan",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/osmn-byhn/widget-core-windows.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/osmn-byhn/widget-core-windows/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://widget-core-windows.osmanbeyhan.com",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"test:watch": "vitest",
|
|
22
|
+
"install": "node-gyp rebuild"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"widget",
|
|
26
|
+
"desktop",
|
|
27
|
+
"gui",
|
|
28
|
+
"win32",
|
|
29
|
+
"webView2",
|
|
30
|
+
"electron-alternative"
|
|
31
|
+
],
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"native",
|
|
35
|
+
"binding.gyp",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"gypfile": true,
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^25.5.0",
|
|
45
|
+
"node-addon-api": "^8.7.0",
|
|
46
|
+
"typescript": "^6.0.2",
|
|
47
|
+
"vitest": "^4.1.2"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
#include "WidgetManager.h"
|
|
2
|
-
#include <gtk/gtk.h>
|
|
3
|
-
#include <webkit2/webkit2.h>
|
|
4
|
-
#include <thread>
|
|
5
|
-
#include <mutex>
|
|
6
|
-
#include <condition_variable>
|
|
7
|
-
|
|
8
|
-
// Try to use gtk-layer-shell for Wayland support
|
|
9
|
-
#ifdef HAVE_GTK_LAYER_SHELL
|
|
10
|
-
#include <gtk-layer-shell/gtk-layer-shell.h>
|
|
11
|
-
#endif
|
|
12
|
-
|
|
13
|
-
// X11 backend
|
|
14
|
-
#include <gdk/gdk.h>
|
|
15
|
-
#ifdef GDK_WINDOWING_X11
|
|
16
|
-
#include <X11/Xlib.h>
|
|
17
|
-
#include <X11/Xatom.h>
|
|
18
|
-
#include <gdk/gdkx.h>
|
|
19
|
-
#endif
|
|
20
|
-
|
|
21
|
-
struct GtkWidgetContext {
|
|
22
|
-
GtkWidget* window;
|
|
23
|
-
GtkWidget* webview;
|
|
24
|
-
bool wayland;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
struct PosTask {
|
|
28
|
-
GtkWidget* w;
|
|
29
|
-
int x;
|
|
30
|
-
int y;
|
|
31
|
-
bool wayland;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
static GMainContext* gtk_context = nullptr;
|
|
35
|
-
|
|
36
|
-
void run_gtk_loop() {
|
|
37
|
-
// Force XWayland (X11 compat layer) to enable EWMH keep-below on GNOME Wayland
|
|
38
|
-
setenv("GDK_BACKEND", "x11", 1);
|
|
39
|
-
gtk_init(NULL, NULL);
|
|
40
|
-
gtk_context = g_main_context_default();
|
|
41
|
-
gtk_main();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
struct CreateTask {
|
|
45
|
-
const std::string* url;
|
|
46
|
-
const WidgetOptions* options;
|
|
47
|
-
void* result;
|
|
48
|
-
std::mutex mutex;
|
|
49
|
-
std::condition_variable cv;
|
|
50
|
-
bool done;
|
|
51
|
-
CreateTask(const std::string* u, const WidgetOptions* o)
|
|
52
|
-
: url(u), options(o), result(nullptr), done(false) {}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
#ifdef GDK_WINDOWING_X11
|
|
56
|
-
// Proper EWMH way: send _NET_WM_STATE_BELOW client message to the WM
|
|
57
|
-
static void send_wm_below(Display* dpy, Window xid) {
|
|
58
|
-
XClientMessageEvent ev = {};
|
|
59
|
-
ev.type = ClientMessage;
|
|
60
|
-
ev.display = dpy;
|
|
61
|
-
ev.window = xid;
|
|
62
|
-
ev.message_type = XInternAtom(dpy, "_NET_WM_STATE", False);
|
|
63
|
-
ev.format = 32;
|
|
64
|
-
ev.data.l[0] = 1; // _NET_WM_STATE_ADD
|
|
65
|
-
ev.data.l[1] = (long)XInternAtom(dpy, "_NET_WM_STATE_BELOW", False);
|
|
66
|
-
ev.data.l[2] = 0;
|
|
67
|
-
ev.data.l[3] = 1;
|
|
68
|
-
ev.data.l[4] = 0;
|
|
69
|
-
XSendEvent(dpy, DefaultRootWindow(dpy), False,
|
|
70
|
-
SubstructureRedirectMask | SubstructureNotifyMask,
|
|
71
|
-
(XEvent*)&ev);
|
|
72
|
-
XFlush(dpy);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
struct KeepBelowData {
|
|
76
|
-
Display* dpy;
|
|
77
|
-
Window xid;
|
|
78
|
-
};
|
|
79
|
-
#endif
|
|
80
|
-
|
|
81
|
-
gboolean create_widget_idle(gpointer data) {
|
|
82
|
-
CreateTask* task = (CreateTask*)data;
|
|
83
|
-
|
|
84
|
-
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
85
|
-
gtk_window_set_default_size(GTK_WINDOW(window), task->options->width, task->options->height);
|
|
86
|
-
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
|
|
87
|
-
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE);
|
|
88
|
-
gtk_window_set_skip_pager_hint(GTK_WINDOW(window), TRUE);
|
|
89
|
-
gtk_window_set_accept_focus(GTK_WINDOW(window), task->options->interactive);
|
|
90
|
-
gtk_window_set_focus_on_map(GTK_WINDOW(window), task->options->interactive);
|
|
91
|
-
|
|
92
|
-
bool wayland_pinned = false;
|
|
93
|
-
|
|
94
|
-
// === WAYLAND: Use gtk-layer-shell ===
|
|
95
|
-
#ifdef HAVE_GTK_LAYER_SHELL
|
|
96
|
-
if (gtk_layer_is_supported()) {
|
|
97
|
-
gtk_layer_init_for_window(GTK_WINDOW(window));
|
|
98
|
-
gtk_layer_set_layer(GTK_WINDOW(window), GTK_LAYER_SHELL_LAYER_BACKGROUND);
|
|
99
|
-
gtk_layer_set_anchor(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_LEFT, TRUE);
|
|
100
|
-
gtk_layer_set_anchor(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_TOP, TRUE);
|
|
101
|
-
gtk_layer_set_margin(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_LEFT, task->options->x);
|
|
102
|
-
gtk_layer_set_margin(GTK_WINDOW(window), GTK_LAYER_SHELL_EDGE_TOP, task->options->y);
|
|
103
|
-
gtk_layer_set_exclusive_zone(GTK_WINDOW(window), -1);
|
|
104
|
-
gtk_layer_set_keyboard_mode(GTK_WINDOW(window), task->options->interactive ? GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND : GTK_LAYER_SHELL_KEYBOARD_MODE_NONE);
|
|
105
|
-
wayland_pinned = true;
|
|
106
|
-
}
|
|
107
|
-
#endif
|
|
108
|
-
|
|
109
|
-
// === X11 / XWayland: EWMH keep-below ===
|
|
110
|
-
if (!wayland_pinned && task->options->sticky) {
|
|
111
|
-
gtk_window_stick(GTK_WINDOW(window));
|
|
112
|
-
// Set keep_below hint BEFORE showing — WM respects this on map
|
|
113
|
-
gtk_window_set_keep_below(GTK_WINDOW(window), TRUE);
|
|
114
|
-
// DESKTOP hint removes the window from all WM management lists
|
|
115
|
-
gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DESKTOP);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
GdkScreen* screen = gtk_widget_get_screen(window);
|
|
119
|
-
GdkVisual* visual = gdk_screen_get_rgba_visual(screen);
|
|
120
|
-
if (visual) gtk_widget_set_visual(window, visual);
|
|
121
|
-
|
|
122
|
-
GtkWidget* webview = webkit_web_view_new();
|
|
123
|
-
gtk_container_add(GTK_CONTAINER(window), webview);
|
|
124
|
-
|
|
125
|
-
if (!task->options->html.empty()) {
|
|
126
|
-
webkit_web_view_load_html(WEBKIT_WEB_VIEW(webview), task->options->html.c_str(), task->url->empty() ? NULL : task->url->c_str());
|
|
127
|
-
} else {
|
|
128
|
-
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), task->url->c_str());
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Apply opacity from options
|
|
132
|
-
if (task->options->opacity < 1.0) {
|
|
133
|
-
gtk_widget_set_opacity(window, task->options->opacity);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
gtk_widget_set_app_paintable(window, TRUE);
|
|
137
|
-
|
|
138
|
-
// Apply blur: inject CSS into webview for backdrop blur effect
|
|
139
|
-
if (task->options->blur) {
|
|
140
|
-
const char* blur_css = "body { backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }";
|
|
141
|
-
WebKitUserContentManager* ucm = webkit_web_view_get_user_content_manager(WEBKIT_WEB_VIEW(webview));
|
|
142
|
-
WebKitUserStyleSheet* sheet = webkit_user_style_sheet_new(
|
|
143
|
-
blur_css,
|
|
144
|
-
WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
|
|
145
|
-
WEBKIT_USER_STYLE_LEVEL_USER,
|
|
146
|
-
NULL, NULL);
|
|
147
|
-
webkit_user_content_manager_add_style_sheet(ucm, sheet);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Hide Scrollbars and handle Overflow
|
|
151
|
-
{
|
|
152
|
-
std::string scroll_css = "::-webkit-scrollbar { display: none !important; width: 0 !important; } ";
|
|
153
|
-
if (!task->options->scroll) {
|
|
154
|
-
scroll_css += "body { overflow: hidden !important; }";
|
|
155
|
-
}
|
|
156
|
-
WebKitUserContentManager* ucm = webkit_web_view_get_user_content_manager(WEBKIT_WEB_VIEW(webview));
|
|
157
|
-
WebKitUserStyleSheet* sheet = webkit_user_style_sheet_new(
|
|
158
|
-
scroll_css.c_str(),
|
|
159
|
-
WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
|
|
160
|
-
WEBKIT_USER_STYLE_LEVEL_USER,
|
|
161
|
-
NULL, NULL);
|
|
162
|
-
webkit_user_content_manager_add_style_sheet(ucm, sheet);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Aggressive Transparency
|
|
166
|
-
GdkRGBA rgba = {0, 0, 0, 0};
|
|
167
|
-
webkit_web_view_set_background_color(WEBKIT_WEB_VIEW(webview), &rgba);
|
|
168
|
-
|
|
169
|
-
// Explicitly set window background to transparent too
|
|
170
|
-
gtk_widget_override_background_color(window, GTK_STATE_FLAG_NORMAL, &rgba);
|
|
171
|
-
|
|
172
|
-
gtk_widget_show_all(window);
|
|
173
|
-
|
|
174
|
-
// Move AFTER show so the WM respects the position
|
|
175
|
-
gtk_window_move(GTK_WINDOW(window), task->options->x, task->options->y);
|
|
176
|
-
|
|
177
|
-
// X11: after show, send proper EWMH below request and start periodic re-enforcement
|
|
178
|
-
if (!wayland_pinned) {
|
|
179
|
-
#ifdef GDK_WINDOWING_X11
|
|
180
|
-
GdkWindow* gdk_win = gtk_widget_get_window(window);
|
|
181
|
-
if (GDK_IS_X11_WINDOW(gdk_win)) {
|
|
182
|
-
Display* dpy = GDK_WINDOW_XDISPLAY(gdk_win);
|
|
183
|
-
Window xid = GDK_WINDOW_XID(gdk_win);
|
|
184
|
-
|
|
185
|
-
// Force exact position via X11 (more reliable than GTK on XWayland)
|
|
186
|
-
XMoveWindow(dpy, xid, task->options->x, task->options->y);
|
|
187
|
-
|
|
188
|
-
// Initial below request
|
|
189
|
-
send_wm_below(dpy, xid);
|
|
190
|
-
XLowerWindow(dpy, xid);
|
|
191
|
-
XFlush(dpy);
|
|
192
|
-
|
|
193
|
-
// Periodic timer: re-send every 500ms to fight any WM restacking
|
|
194
|
-
auto* kd = new KeepBelowData{dpy, xid};
|
|
195
|
-
g_timeout_add(500, [](gpointer d) -> gboolean {
|
|
196
|
-
auto* data = static_cast<KeepBelowData*>(d);
|
|
197
|
-
send_wm_below(data->dpy, data->xid);
|
|
198
|
-
XLowerWindow(data->dpy, data->xid);
|
|
199
|
-
XFlush(data->dpy);
|
|
200
|
-
return G_SOURCE_CONTINUE;
|
|
201
|
-
}, kd);
|
|
202
|
-
}
|
|
203
|
-
#endif
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
GtkWidgetContext* ctx = new GtkWidgetContext();
|
|
207
|
-
ctx->window = window;
|
|
208
|
-
ctx->webview = webview;
|
|
209
|
-
ctx->wayland = wayland_pinned;
|
|
210
|
-
|
|
211
|
-
task->result = ctx;
|
|
212
|
-
{
|
|
213
|
-
std::lock_guard<std::mutex> lock(task->mutex);
|
|
214
|
-
task->done = true;
|
|
215
|
-
}
|
|
216
|
-
task->cv.notify_one();
|
|
217
|
-
return FALSE;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
void* WidgetManager::CreateWidget(const std::string& url, const WidgetOptions& options) {
|
|
221
|
-
static std::once_flag init_flag;
|
|
222
|
-
std::call_once(init_flag, []() {
|
|
223
|
-
std::thread(run_gtk_loop).detach();
|
|
224
|
-
while (!gtk_context) std::this_thread::yield();
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
CreateTask task(&url, &options);
|
|
228
|
-
g_main_context_invoke(gtk_context, create_widget_idle, &task);
|
|
229
|
-
|
|
230
|
-
std::unique_lock<std::mutex> lock(task.mutex);
|
|
231
|
-
task.cv.wait(lock, [&]{ return task.done; });
|
|
232
|
-
|
|
233
|
-
return task.result;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
void WidgetManager::UpdateOpacity(void* handle, double opacity) {
|
|
237
|
-
if (!handle) return;
|
|
238
|
-
g_main_context_invoke(gtk_context, [](gpointer data) -> gboolean {
|
|
239
|
-
auto pair = (std::pair<GtkWidget*, double>*)data;
|
|
240
|
-
gtk_widget_set_opacity(pair->first, pair->second);
|
|
241
|
-
delete pair;
|
|
242
|
-
return FALSE;
|
|
243
|
-
}, new std::pair<GtkWidget*, double>(((GtkWidgetContext*)handle)->window, opacity));
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
void WidgetManager::UpdatePosition(void* handle, int x, int y) {
|
|
247
|
-
if (!handle) return;
|
|
248
|
-
auto* ctx = static_cast<GtkWidgetContext*>(handle);
|
|
249
|
-
if (!ctx->window) return;
|
|
250
|
-
|
|
251
|
-
g_main_context_invoke(gtk_context, [](gpointer data) -> gboolean {
|
|
252
|
-
auto t = static_cast<PosTask*>(data);
|
|
253
|
-
if (!t->w) {
|
|
254
|
-
delete t;
|
|
255
|
-
return FALSE;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (t->wayland) {
|
|
259
|
-
#ifdef HAVE_GTK_LAYER_SHELL
|
|
260
|
-
gtk_layer_set_margin(GTK_WINDOW(t->w), GTK_LAYER_SHELL_EDGE_LEFT, t->x);
|
|
261
|
-
gtk_layer_set_margin(GTK_WINDOW(t->w), GTK_LAYER_SHELL_EDGE_TOP, t->y);
|
|
262
|
-
#endif
|
|
263
|
-
} else {
|
|
264
|
-
gtk_window_move(GTK_WINDOW(t->w), t->x, t->y);
|
|
265
|
-
#ifdef GDK_WINDOWING_X11
|
|
266
|
-
GdkWindow* gdk_win = gtk_widget_get_window(t->w);
|
|
267
|
-
if (gdk_win && GDK_IS_X11_WINDOW(gdk_win)) {
|
|
268
|
-
Display* dpy = GDK_WINDOW_XDISPLAY(gdk_win);
|
|
269
|
-
Window xid = GDK_WINDOW_XID(gdk_win);
|
|
270
|
-
XMoveWindow(dpy, xid, t->x, t->y);
|
|
271
|
-
XFlush(dpy);
|
|
272
|
-
}
|
|
273
|
-
#endif
|
|
274
|
-
}
|
|
275
|
-
delete t;
|
|
276
|
-
return FALSE;
|
|
277
|
-
}, new PosTask{ctx->window, x, y, ctx->wayland});
|
|
278
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#include "WidgetManager.h"
|
|
2
|
-
#import <AppKit/AppKit.h>
|
|
3
|
-
#import <WebKit/WebKit.h>
|
|
4
|
-
|
|
5
|
-
struct MacOSWidgetContext {
|
|
6
|
-
NSWindow* window;
|
|
7
|
-
WKWebView* webview;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
void* WidgetManager::CreateWidget(const std::string& url, const WidgetOptions& options) {
|
|
11
|
-
NSRect frame = NSMakeRect(options.x, options.y, options.width, options.height);
|
|
12
|
-
|
|
13
|
-
NSWindow* window = [[NSWindow alloc] initWithContentRect:frame
|
|
14
|
-
styleMask:NSWindowStyleMaskBorderless
|
|
15
|
-
backing:NSBackingStoreBuffered
|
|
16
|
-
defer:NO];
|
|
17
|
-
|
|
18
|
-
[window setBackgroundColor:[NSColor clearColor]];
|
|
19
|
-
[window setOpaque:NO];
|
|
20
|
-
[window setHasShadow:NO];
|
|
21
|
-
|
|
22
|
-
if (options.sticky) {
|
|
23
|
-
[window setLevel:kCGDesktopWindowLevel - 1]; // Pin to desktop
|
|
24
|
-
[window setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorStationary];
|
|
25
|
-
} else {
|
|
26
|
-
[window setLevel:NSFloatingWindowLevel];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (options.blur) {
|
|
30
|
-
NSVisualEffectView* blurView = [[NSVisualEffectView alloc] initWithFrame:frame];
|
|
31
|
-
[blurView setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
|
|
32
|
-
[blurView setMaterial:NSVisualEffectMaterialDark];
|
|
33
|
-
[blurView setState:NSVisualEffectStateActive];
|
|
34
|
-
[window setContentView:blurView];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
WKWebViewConfiguration* config = [[WKWebViewConfiguration alloc] init];
|
|
38
|
-
// Security Shield: Sandbox settings
|
|
39
|
-
[[config preferences] setJavaScriptEnabled:YES];
|
|
40
|
-
|
|
41
|
-
// Inject CSS to hide scrollbars and handle overflow
|
|
42
|
-
std::string scroll_css = "var style = document.createElement('style');"
|
|
43
|
-
"style.innerHTML = '::-webkit-scrollbar { display: none !important; width: 0 !important; } ';";
|
|
44
|
-
if (!options.scroll) {
|
|
45
|
-
scroll_css += "style.innerHTML += 'body { overflow: hidden !important; }';";
|
|
46
|
-
}
|
|
47
|
-
scroll_css += "document.head.appendChild(style);";
|
|
48
|
-
|
|
49
|
-
WKUserScript* script = [[WKUserScript alloc] initWithSource:[NSString stringWithUTF8String:scroll_css.c_str()]
|
|
50
|
-
injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
|
|
51
|
-
forMainFrameOnly:YES];
|
|
52
|
-
[[config userContentController] addUserScript:script];
|
|
53
|
-
|
|
54
|
-
WKWebView* webview = [[WKWebView alloc] initWithFrame:[[window contentView] bounds] configuration:config];
|
|
55
|
-
[webview setNavigationDelegate:nil];
|
|
56
|
-
[webview setValue:@(NO) forKey:@"drawsBackground"];
|
|
57
|
-
|
|
58
|
-
[[window contentView] addSubview:webview];
|
|
59
|
-
|
|
60
|
-
if (!options.html.empty()) {
|
|
61
|
-
[webview loadHTMLString:[NSString stringWithUTF8String:options.html.c_str()] baseURL:nil];
|
|
62
|
-
} else {
|
|
63
|
-
NSURL* nsUrl = [NSURL URLWithString:[NSString stringWithUTF8String:url.c_str()]];
|
|
64
|
-
[webview loadRequest:[NSURLRequest requestWithURL:nsUrl]];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
[window makeKeyAndOrderFront:nil];
|
|
68
|
-
|
|
69
|
-
MacOSWidgetContext* ctx = new MacOSWidgetContext();
|
|
70
|
-
ctx->window = window;
|
|
71
|
-
ctx->webview = webview;
|
|
72
|
-
|
|
73
|
-
return ctx;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
void WidgetManager::UpdateOpacity(void* handle, double opacity) {
|
|
77
|
-
MacOSWidgetContext* ctx = (MacOSWidgetContext*)handle;
|
|
78
|
-
[ctx->window setAlphaValue:opacity];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
void WidgetManager::UpdatePosition(void* handle, int x, int y) {
|
|
82
|
-
MacOSWidgetContext* ctx = (MacOSWidgetContext*)handle;
|
|
83
|
-
NSRect frame = [ctx->window frame];
|
|
84
|
-
frame.origin.x = x;
|
|
85
|
-
frame.origin.y = y;
|
|
86
|
-
[ctx->window setFrame:frame display:YES];
|
|
87
|
-
}
|