|
25 | 25 | ;; and kept alive forever (GTK stores the raw pointer). |
26 | 26 |
|
27 | 27 | (require ffi/unsafe |
| 28 | + racket/file |
28 | 29 | racket/path |
29 | 30 | racket/string) |
30 | 31 |
|
|
128 | 129 | #:title [title "Glaze"] |
129 | 130 | #:width [width 1024] |
130 | 131 | #:height [height 768] |
| 132 | + #:devtools? [devtools? #f] |
131 | 133 | #:on-close [on-close (lambda () (void))]) |
132 | 134 | (unless (supported?) |
133 | 135 | (error 'open-webview "Linux WebView backend not available")) |
|
167 | 169 | (define u (webkit_web_view_get_uri (lin:webview-webview wv))) |
168 | 170 | (and (non-empty-string? u) u))) |
169 | 171 |
|
| 172 | +;; Window capture via GDK: gdk_pixbuf_get_from_window on the window's |
| 173 | +;; GdkWindow, then gdk_pixbuf_savev to PNG ("png" handler ships with GTK). |
| 174 | +(define gdk-pixbuf-lib |
| 175 | + (with-handlers ([exn:fail? (lambda (e) #f)]) |
| 176 | + (ffi-lib "gdk_pixbuf-2.0" '("0" #f)))) |
| 177 | +(define gtk_widget_get_window |
| 178 | + (maybe-bind gtk-lib "gtk_widget_get_window" (_fun _pointer -> _pointer))) |
| 179 | +(define gdk_pixbuf_get_from_window |
| 180 | + (and gdk-pixbuf-lib |
| 181 | + (get-ffi-obj "gdk_pixbuf_get_from_window" |
| 182 | + gdk-pixbuf-lib |
| 183 | + (_fun _pointer _int _int _int _int -> _pointer) |
| 184 | + (lambda () #f)))) |
| 185 | +(define gdk_pixbuf_savev |
| 186 | + (and gdk-pixbuf-lib |
| 187 | + (get-ffi-obj "gdk_pixbuf_savev" |
| 188 | + gdk-pixbuf-lib |
| 189 | + (_fun _pointer _string _string _pointer _pointer _pointer -> _bool) |
| 190 | + (lambda () #f)))) |
| 191 | + |
170 | 192 | (define (capture! wv [dest #f]) |
171 | | - #f) |
| 193 | + (and (not (unbox (lin:webview-closed?-box wv))) |
| 194 | + gtk_widget_get_window |
| 195 | + gdk_pixbuf_get_from_window |
| 196 | + gdk_pixbuf_savev |
| 197 | + (let () |
| 198 | + (define gdkwin (gtk_widget_get_window (lin:webview-window wv))) |
| 199 | + (and gdkwin |
| 200 | + (let () |
| 201 | + (define pixbuf (gdk_pixbuf_get_from_window gdkwin 0 0 -1 -1)) |
| 202 | + (and pixbuf |
| 203 | + (let () |
| 204 | + (define path |
| 205 | + (if dest |
| 206 | + (if (string? dest) (string->path dest) dest) |
| 207 | + (make-temporary-file "glaze-capture-~a.png"))) |
| 208 | + (define ok? |
| 209 | + (gdk_pixbuf_savev pixbuf |
| 210 | + (path->string path) |
| 211 | + "png" |
| 212 | + #f #f #f)) |
| 213 | + (and ok? path)))))))) |
0 commit comments