Spark stealing foucs

http://issues.igniterealtime.org/browse/SPARK-948

It seems this issue is still affecting 2.6.0.

Is there any way this can get fixed for the next release? I have several users that had this issue sporadically on 2.5.8, but now it is constant. I’m not sure exactly what causes it, but it hasn’t been looked at for a while, it seems.

hallo adipose,

there is also another issue which might describe your problem:

http://issues.igniterealtime.org/browse/SPARK-1167

developers spend a lot of time to this issue, but it seems to be very hard to fix it completely.

try java 7beta and use this method:

setAutoRequestFocus(boolean)

but in my tests it didnt really work

What about the method discussed here:

http://www.java.net/node/671193

Set the window to not focusable, then set it back after you have shown it. Would that work?

when i tested that it didnt work, but feel free to check yourself

I have included a patch that fixes the problem for me. It seems that the issue has to do with being iconified. If you set the frame to visible before setting the window to being iconified, it does not steal the focus. I also set it to “Frame.NORMAL” before setting visible, but I assume that would be the default anyway.

Now, I have only tested this on windows 7, but it has solved my issue.

### Eclipse Workspace Patch 1.0
#P spark
Index: src/java/org/jivesoftware/spark/ui/ChatContainer.java
===================================================================
--- src/java/org/jivesoftware/spark/ui/ChatContainer.java    (revision 12439)
+++ src/java/org/jivesoftware/spark/ui/ChatContainer.java    (working copy)
@@ -1194,6 +1194,9 @@
         chatFrame = new ChatFrame();
     } +    +  chatFrame.setState(Frame.NORMAL);
+  chatFrame.setVisible(true);      if (SparkManager.getMainWindow().isActive() || pref.getWindowTakesFocus()) {
         chatFrame.setState(Frame.NORMAL);
@@ -1203,8 +1206,6 @@
     } -        chatFrame.setVisible(true);
-                 chatFrame.addWindowListener(new WindowAdapter() {
             public void windowActivated(WindowEvent windowEvent) {
                 stopFlashing();

it works but it has a really ugly display effect

either my eyes can see at 50FPS or it really does get visible on screen and then goes into tray

UPDATE: I changed this patch to use setFocusable() instead of setFocusableWindowState(). For some reason, on certain machines, the latter was causing the window to not ever appear in the taskbar (although it did appear if you alt-tabbed).

UPDATE2: Well, this seems to have the flashing issue again. Removing patch.

I see what you mean. The window briefly flashes on the screen using that method. Here is a slightly modified method which seems to avoid that artifact.

Actually I think the foreground app just loses focus, and regains it quickly. The change in focus makes it appear something is happening/popping up.

However, I think this may be preferable to actually stealing focus, and not returning it.

Ok, I have working code that does not cause the flash, and does not steal focus.

However, it only works on JDK 1.7. But at least it works…

Edit: Never mind, this only works on my win7 machine, but not others. May have something to do with a windows focus setting that makes it work for me, but a “Normal” win7 install doesn’t work with this fix.

This (setAutoRequestFocus) is working for me now on win7 and jre7. I also compiled with jdk17. The compiled version acts very strange on jre6. The chat windows cannot be closed, except by closing individual tabs.

### Eclipse Workspace Patch 1.0
#P spark
Index: src/java/org/jivesoftware/spark/ui/ChatContainer.java
===================================================================
--- src/java/org/jivesoftware/spark/ui/ChatContainer.java    (revision 12344)
+++ src/java/org/jivesoftware/spark/ui/ChatContainer.java    (working copy)
@@ -1199,6 +1199,7 @@
         chatFrame.setState(Frame.NORMAL);      } else {
+            chatFrame.setAutoRequestFocus(false);
         chatFrame.setState(Frame.ICONIFIED);
     }

works for me aswell, will be added into trunk in a minute


edit:

Completed: At revision: 12460

Nice, now we just have to wait for java7 to come out.

I hate to resurrect this old thread but it appears this is a problem in Java 8 now that the switch has been made. It looks like the previous fix was looking for Java 7 by name. We need to check for Java 8 by as well or just cut ties with Java 6 altogether and remove the if statement.

I am including a patch below:

Index: src/java/org/jivesoftware/spark/ui/ChatContainer.java ===================================================================

--- src/java/org/jivesoftware/spark/ui/ChatContainer.java (revision 2516)

+++ src/java/org/jivesoftware/spark/ui/ChatContainer.java (working copy)

@@ -1222,7 +1222,7 @@

chatFrame.setState(Frame.NORMAL);

} else {

- if (System.getProperty("java.version").startsWith("1.7.")) {

+ if (System.getProperty("java.version").startsWith("1.7.") || System.getProperty("java.version").startsWith("1.8.")) {

try {

// TODO UPDATE ON JAVA 1.7.0 release

// chatFrame.setAutoRequestFocus(false);

George wrote:

I hate to resurrect this old thread but it appears this is a problem in Java 8 now that the switch has been made. It looks like the previous fix was looking for Java 7 by name. We need to check for Java 8 by as well or just cut ties with Java 6 altogether and remove the if statement.

actually since java 6 and below have been dropped the code can be replaced completely, as documented in said code by myself

code should look like this then:

[Java] … if (SparkManager.getMainWindow().isActive() || pref.getWindowTakes - Pastebin.com

George and Wolf,

fyi, there are no active spark devs. If you guys are java devs (or know anyone that is), and would be interested in helping out, that would be great. the project is on github Ignite Realtime · GitHub . wroot helps maintain Spark.

speedy, Wolf surely is a java dev He was part of Walter’s Ebeling team and pushed Spark 2.6.3 and a few previous versions out i think.

Wolf, do you want to do a PR for this? Or should i do add this patch myself?

Although i can’t reproduce this issue on the latest build (2.7.2 b712), which has Java 1.8.0_60 built-in.

Well, i couldn’t reproduce this yesterday with 712 build. But i have applied Wolf’s changes and now it steals the focus on a new message (when bring window to front is on), though it also steals it on the older 712 build I have tried George’s variant too. Same result. I will leave Wolf’s change in there, as it doesn’t make difference, but the code looks cleaner. But maybe it needs more investigation.

Filed as https://igniterealtime.org/issues/browse/SPARK-1642

You can find this change in the 713 build here Ignite Realtime: Spark Nightly Builds

I agree, but wasn’t sure if there is still anyone using Java 6 out there for some reason. I would go with the patch as wolf suggested vs mine since we don’t need that much backward compatibility.