Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use this from a repl? #168

Open
rgkirch opened this issue Oct 28, 2021 · 6 comments
Open

How do I use this from a repl? #168

rgkirch opened this issue Oct 28, 2021 · 6 comments

Comments

@rgkirch
Copy link
Contributor

rgkirch commented Oct 28, 2021

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
Copy link
Contributor Author

rgkirch commented Oct 28, 2021

I'm on windows.

@rgkirch
Copy link
Contributor Author

rgkirch commented Oct 28, 2021

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

@tonsky
Copy link
Collaborator

tonsky commented Oct 29, 2021

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
Copy link
Collaborator

tonsky commented Oct 29, 2021

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

@rgkirch
Copy link
Contributor Author

rgkirch commented Oct 29, 2021

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!

@tonsky
Copy link
Collaborator

tonsky commented Oct 29, 2021

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?

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

No branches or pull requests

2 participants