Fork me on GitHub
#membrane
<
2022-05-22
>
Quest17:05:13

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 https://githubhot.com/repo/cljfx/cljfx/issues/94 & 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 & https://www.b4x.com/android/forum/threads/solved-how-to-set-the-focus-to-a-non-java-application-in-windows.99253/#post-624929, but would anyone recommend a different approach?

phronmophobic17:05:42

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

👀 1
Quest17:05:15

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)

phronmophobic17:05:09

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
Quest17:05:13

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
phronmophobic17:05:59

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
(javax.swing.SwingUtilities/invokeLater
 (fn []
   (.requestFocusInWindow frame)
   (.setVisible frame true)))

phronmophobic17:05:45

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

1
👍 1
Quest18:05:52

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)

zimablue13:05:40

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

1