clojure-emacs / orchard

A fertile ground for Clojure tooling
Eclipse Public License 1.0
326 stars 54 forks source link

orchard as dependency will cause problems with swing UI applications #162

Open cgrabenstein opened 2 years ago

cgrabenstein commented 2 years ago

This is basically a repost of https://github.com/clojure-emacs/cider-nrepl/issues/610, but the origin of the cider-nrepl issue can be found here, in this repository.

Expected behavior

Using orchard (or any other library that depends on it) on mac does not affect the way how java swing frames are being displayed.

Actual behavior

Using orchard (or, for example cider/cider-nrepl) causes swing frames to "hover" on mac. I can't use cmd+tab to switch to the frame which makes developing very cumbersome.

Steps to reproduce the problem

  1. Clone this repository
  2. run lein repl
  3. run the following commands
    user=> (require 'orchard.java.parser)
    nil
    user=> (import 'javax.swing.JFrame)
    javax.swing.JFrame
    user=> (doto (JFrame.) (.setSize 200 200) (.setVisible true))
    #object[javax.swing.JFrame 0x6b3a36ef "javax.swing.JFrame[frame0,0,25,200x200,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,28,200x172,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]"]
  4. compare with
    user=> (System/setProperty "apple.awt.UIElement" "false")
    nil
    user=> (require 'orchard.java.parser)
    nil
    user=> (import 'javax.swing.JFrame)
    javax.swing.JFrame
    user=> (doto (JFrame.) (.setSize 200 200) (.setVisible true))
    #object[javax.swing.JFrame 0x6b3a36ef "javax.swing.JFrame[frame0,0,25,200x200,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,28,200x172,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]"]

The reason for this behaviour can be found here: https://github.com/clojure-emacs/orchard/blob/master/src-newer-jdks/orchard/java/parser.clj#L134

Environment & Version information

Clojure version

$ clj --version
Clojure CLI version 1.11.1.1155

Java version

$ java --version
openjdk 18.0.2 2022-07-19
OpenJDK Runtime Environment Homebrew (build 18.0.2+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.2+0, mixed mode, sharing)

Operating system

macOS Monterey 12.3.1

bbatsov commented 2 years ago

The reason for this behaviour can be found here: https://github.com/clojure-emacs/orchard/blob/master/src-newer-jdks/orchard/java/parser.clj#L134

But that's supposedly the solution for the problem, right?

vemv commented 2 years ago

It's not - that line of code is meant to prevent a GUI nuisance from popping up in non GUI projects.

The issue is with GUI projects.

However that same line of code suggests a fix: set apple.awt.UIElement in advance for whatever value is best for your GUI app.

Non-GUI apps need to do nothing.

I'd suggest to close this issue by documenting the behavior in cider.

bbatsov commented 2 years ago

Ah, yeah - I didn't read the ticket carefully enough. I agree we should document it as the simplest solution.