Fork me on GitHub

Is there a Membrane way to do a popup/take UI focus from the desktop background? I've made a global keypress handler (via JNativeInput), but I need to bring my program to the forefront of the desktop. In the CljFx/Java2D code, I use (.requestFocus node) on an & just toggle the visibility on/off. I note that (.setVisible (:membrane.java2d/frame x) false) works to change visibility using the Swing API. I think I can get this working if I wrap Swing &, but would anyone recommend a different approach?


That approach sounds reasonable to me. For Swing, this stackoverflow answer also looks like you might be able to avoid OS specific code, I haven't tried it though.

👀 1

I'll take a look, nice to avoid OS custom impls. Is stuff like supporting toplevel "visibility" in-scope for Membrane to eventually support, or is this fundamentally not something the library should tackle? (I think the idea is excellent & might be able to add some PRs eventually)


Yea, that sounds great! If there's a way to abstract it across backends, we can make a common API. If there's not, it's totally fine to just have implementations that support individual backends/OS's

👍 1

Good to know! If I can get my app off the ground then I'll need to support multiple platforms, so I'll be thinking about how to PR this as I code. Thanks for the advice & hope you're having a good weekend 👋☀️

😄 1

I had a repl open, so I just tried out the stackoverflow code. Seems to work on Mac OSX

(ns focus
  (:require [membrane.java2d :as backend]
            [membrane.ui :as ui]))

(def window-info (backend/run #(ui/label "ui")))
(def frame (::backend/frame window-info))

;; manually minimize or send window to bottom

;; bring window to front
 (fn []
   (.requestFocusInWindow frame)
   (.setVisible frame true)))


Also, thanks for trying membrane. I would love to hear your feedback (including the good, bad, or ugly).

👍 1

I'm just getting into Membrane. So far, I find the stricter decoupling of the events & UI makes the code easier to grok than CljFx. While there's less references to Google, I'm used to diving into library code & am interested in leveraging the benefits (hierarchical UI composability, multiplatform views)


just to note on this thread this is also the a thing I cooked up to use in electron so it's probably a common requirement, might be useful inbuilt