JWM icon indicating copy to clipboard operation
JWM copied to clipboard

How do I use this from a repl?

Open rgkirch opened this issue 4 years ago • 6 comments

I'm trying to use this from clojure. I have a persistent connection to a clojure repl and I'd like to develop without restarting my repl to incorporate a code change. If I launch the app, close the window by clicking the windows X button, and then eval (example) I don't get a working window. I get a window with a blank screen that just reports that it's "not responding". I also tried running the example in a thread but I get the same behavior: (async/thread-call example) Thanks!

(ns rgkirch.core
  (:require [clojure.core.async :as async])
  (:import [io.github.humbleui.jwm
            App
            Event
            EventWindowCloseRequest
            EventWindowScreenChange
            EventWindowResize
            EventFrame
            LayerGL]
           [java.util.function Consumer]))


(defn example
  []
  (defonce init (App/init))
  (def window (App/makeWindow))
  (def layer (LayerGL.))
  (defn paint []
    (.makeCurrent layer)
    (.swapBuffers layer))
  (.attach layer window)
  (.setTitle window "Hello World")
  (.setEventListener window (reify Consumer
                              (accept [this e]
                                (do
                                  (println e)
                                  (cond
                                    (instance? EventWindowCloseRequest e)
                                    (do (.close window)
                                        (App/terminate)) ;; terminate here? or this kills my jvm process?

                                    (instance? EventWindowScreenChange e)
                                    (do
                                      (println "screen change")
                                      (.reconfigure layer)
                                      (let [rect (.getContentRect window)]
                                        (.resize layer (.getWidth rect) (.getHeight rect)))
                                      (paint))

                                    (instance? EventWindowResize e)
                                    (do
                                      (println "resize")
                                      (.resize layer (.getContentWidth e) (.getContentHeight e))
                                      (paint))

                                    (instance? EventFrame e)
                                    (do
                                      (paint)
                                      (.requestFrame window)))))))
  (.setVisible window true)
  (.requestFrame window)
  (defonce start (App/start)))                ;; defonce here or no? same behavior either way...

(example)

rgkirch avatar Oct 28 '21 23:10 rgkirch

I'm on windows.

rgkirch avatar Oct 28 '21 23:10 rgkirch

mvnrepository lists "0.2.4" and "main" so I tried both e.g. io.github.humbleui.jwm/jwm {:mvn/version "0.2.4"}

rgkirch avatar Oct 28 '21 23:10 rgkirch

I was just about to try it from Clojure, literally tomorrow :) I’ll take a look

From what I see right now, you probably shouldn’t call App/terminate at all, after it nothing will ever work

tonsky avatar Oct 29 '21 00:10 tonsky

Might also be an edge case with closing last window, will have to check

tonsky avatar Oct 29 '21 00:10 tonsky

Thanks for the heads up. I tried running without the call to App/terminate but I still don't get my repl back. Thanks for looking into it!

rgkirch avatar Oct 29 '21 01:10 rgkirch

So I created Clojure repo here https://github.com/HumbleUI/HumbleUI It seems to work on macOS but on Windows I get the same symptoms you got. Good thing is that I can reproduce. I’ll look into it more next week, might be a JWM bug. For now, try not to close last window?

tonsky avatar Oct 29 '21 21:10 tonsky