Skip to content

Instantly share code, notes, and snippets.

@yogthos
Last active March 13, 2023 19:19
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yogthos/81d560da28da7dd5b86dcda3003b35e7 to your computer and use it in GitHub Desktop.
Save yogthos/81d560da28da7dd5b86dcda3003b35e7 to your computer and use it in GitHub Desktop.
Gjs ClojureScript example
(ns gjs-example.core)
(defn main []
(set! (-> js/imports .-gi .-versions .-Gtk) "3.0")
(let [Gtk (doto (-> js/imports .-gi .-Gtk) (.init nil))
window (Gtk.Window.
(clj->js
{:type (-> Gtk .-WindowType .-TOPLEVEL)
:title "A default title"
:default_width 300
:default_height 250
:window_position (-> Gtk .-WindowPosition .-CENTER)}))
button (Gtk.Button.
(clj->js
{:label "close"
:visible true
:valign (-> Gtk .-Align .-CENTER)
:halign (-> Gtk .-Align .-CENTER)}))]
(set! (.-title window) "Hello World")
(.connect window "delete-event" #(boolean (js/log "delete event")))
(.connect window "destroy" #(.main_quit Gtk))
(.connect button "clicked" #(.destroy window))
(.add window button)
(.show window)
(.main Gtk)))
(main)
(defproject gjs-test "0.1.0"
:dependencies [[org.clojure/clojure "1.10.1"]
[org.clojure/clojurescript "1.10.520"]]
:plugins [[lein-cljsbuild "1.1.7"]]
:cljsbuild {:builds [{:source-paths ["src"]
:compiler {:output-to "target/app.js"
:optimizations :simple
:target :nodejs
:pretty-print true}}]})
@ieugen
Copy link

ieugen commented Apr 28, 2020

That sounds great. I'll give it a try at some point.

@titonbarua
Copy link

I have implemented a new target for shadow-cljs to compile Clojurescript for Gjs environment, with some additional import syntax sugar. If anyone is interested, please take a look at https://github.com/titonbarua/shadow-cljs-gjs-target . Contributions and feed-backs are welcome.

@yogthos
Copy link
Author

yogthos commented Jun 28, 2020

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment