Re: Keyboard focus lost in Swing applications (ex: Netbeans) after changing to window

2009-12-14 Thread Ole Jørgen Brønner
This http://code.google.com/p/xmonad/issues/detail?id=177 xmonad bug  
report is probably relevant. Preventing XSetInputFocus to be called on  
windows with WM_TAKE_FOCUS set seems to fix the issue for me (ion3plus,  
sun-java-6)


I will run with the change for a while and see if it breaks other apps.  
(and possible test other java versions)


On Thu, 15 Jan 2009 10:35:49 +0100, Daniel Clemente  
dcl441-b...@yahoo.com wrote:


Hi, sorry if this message comes twice (I posted yesterday via NNTP  
without being subscribed to the list).



  ion3 is stealing keyboard focus to Swing applications. This happens  
for instance with Netbeans 6.5:


1. Open netbeans and some other programs in tabs next to it.
2. Select netbeans and open an editor with some code; the cursor is  
inside the editor

3. Select another tab (either clicking teh tab or with keyboard).
4. Select netbeans again (either clicking the tab or with keyboard).
5. Try to continue typing, but you can't. The cursor is nowhere, and *no  
key* works (space, cursors, A-S-o, ... all gone). You must click again  
in the editor and then you can type again.


In fact any Swing application has this problem. You can use this one to  
test:


--- TypeInSwing.java 

import javax.swing.JFrame;
import javax.swing.JTextField;

public class TypeInSwing {
  public static void main(String[] args) {
JFrame frame = new JFrame(HelloWorldSwing);
final JTextField field = new JTextField(type here);

frame.getContentPane().add(field);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
  }
}

--

It happens with latest version 20090110 (with 20080207 too).

I am using:

$ java -version
java version 1.6.0_06
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Server VM (build 10.0-b22, mixed mode)


  Why is it so?


Daniel






--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

java-focus.patch
Description: Binary data


Re: Keyboard focus lost in Swing applications (ex: Netbeans) after changing to window

2009-03-01 Thread Daniel Clemente

  Sorry for the long wait; I had other compilation problems (I inform briefly 
about that).

 You could, again, try reversing the order of the
 finalise_focus and
 sendmsg in the TAKE_FOCUS branch of the clientwin focus
 function.
 

  That didn't work; with JDK 1.7 it still fails. It must be due to something 
new of JDK 1.7 since earlier versions work now.
  Your patch fixed the focus loss in Java 1.6 but makes Java 1.7 applications 
not receive focus; it is a bug for a bug but I think Java 1.6 apps are more 
important right now; so I will start using it.


-- Daniel





Re: Keyboard focus lost in Swing applications (ex: Netbeans) after changing to window

2009-02-10 Thread Tuomo Valkonen
On 2009-02-09, Daniel Clemente dcl441-b...@yahoo.com wrote:
   Well, it improved lots of things. It works perfectly with gtk, qt, tk,
   keyboard, mouse, … The example code now works when I use Java
   1.6.0_12-b04. But if I compile and run it with the unreleased
   1.7.0-ea-b43, the focus is still buggy: 

You could, again, try reversing the order of the finalise_focus and
sendmsg in the TAKE_FOCUS branch of the clientwin focus function.

-- 
Stop Gnomes and other pests! Purchase Windows today!




Re: Keyboard focus lost in Swing applications (ex: Netbeans) after changing to window

2009-02-08 Thread Daniel Clemente

Hi; thanks for the helpful explanations.

  I tried doing that change and it stayed the same. I also tried doing a 
sleep(2) before sending the WM_TAKE_FOCUS (with the +2s timestamp), but without 
success.

  What did work is this:

static void clientwin_do_set_focus(WClientWin *cwin, bool warp)
{
if(cwin-flagsCLIENTWIN_P_WM_TAKE_FOCUS){
Time stmp=ioncore_get_timestamp();
send_clientmsg(cwin-win, ioncore_g.atom_wm_take_focus, stmp);
} else {
region_finalise_focusing((WRegion*)cwin, cwin-win, warp);
}

XSync(ioncore_g.dpy, 0);
}


  I just added the „else“ keyword so that region_finalise_focusing is not 
called if the WM_TAKE_FOCUS is sent. I don't know the meaning of this, but only 
that it solves all problems with Netbeans and my example Swing application. 
Focus is set to the last active widget.
  This, however, makes Konqueror 4 stop receiving focus. This makes me think:
- Konqueror has flag CLIENTWIN_P_WM_TAKE_FOCUS and apparently needs both the 
WM_TAKE_FOCUS call and the region_finalise_focusing
- Netbeans/Swing also has flag CLIENTWIN_P_WM_TAKE_FOCUS, but if you run the 
region_finalise_focusing code on it, it loses focus

  Maybe region_finalise_focusing should sometimes be doing nothing in windows 
like Netbeans.
  Or maybe Swing should be correctly handling the XSetInputFocus(ioncore_g.dpy, 
win, RevertToParent, CurrentTime) in region_finalise_focusing.

  It is exactly at that XSetInputFocus where the text field at the Swing 
application loses the keyboard focus (I tested it inserting sleeps between 
calls).


  I filed this bug to Sun but I don't know whether they think the bug is in 
JDK. The bug report is at http://bugs.sun.com/view_bug.do?bug_id=6798064

  Greetings,
Daniel




Re: Keyboard focus lost in Swing applications (ex: Netbeans) after changing to window

2009-02-08 Thread Tuomo Valkonen
On 2009-02-08 21:52 +0100, Daniel Clemente wrote:
 
 Hi; thanks for the helpful explanations.
 
   I tried doing that change and it stayed the same. I also tried doing a 
 sleep(2) before sending the WM_TAKE_FOCUS (with the +2s timestamp), but 
 without success.
 
   What did work is this:

Try the attached patch. (Disclaimer: I haven't particularly tried it; 
just quickly threw it together.)

-- 
Stop Gnomes and other pests! Purchase Windows today!

diff -rN -u old-ion-3/ioncore/clientwin.c new-ion-3/ioncore/clientwin.c
--- old-ion-3/ioncore/clientwin.c   2009-02-09 00:35:07.380883290 +0200
+++ new-ion-3/ioncore/clientwin.c   2009-02-09 00:35:07.488878930 +0200
@@ -1015,10 +1015,11 @@
 {
 if(cwin-flagsCLIENTWIN_P_WM_TAKE_FOCUS){
 Time stmp=ioncore_get_timestamp();
+region_finalise_focusing((WRegion*)cwin, cwin-win, warp, stmp);
 send_clientmsg(cwin-win, ioncore_g.atom_wm_take_focus, stmp);
+}else{
+region_finalise_focusing((WRegion*)cwin, cwin-win, warp, CurrentTime);
 }
-
-region_finalise_focusing((WRegion*)cwin, cwin-win, warp);
 
 XSync(ioncore_g.dpy, 0);
 }
diff -rN -u old-ion-3/ioncore/focus.c new-ion-3/ioncore/focus.c
--- old-ion-3/ioncore/focus.c   2009-02-09 00:35:07.368883774 +0200
+++ new-ion-3/ioncore/focus.c   2009-02-09 00:35:07.484879092 +0200
@@ -347,7 +347,7 @@
 /*Time ioncore_focus_time=CurrentTime;*/
 
 
-void region_finalise_focusing(WRegion* reg, Window win, bool warp)
+void region_finalise_focusing(WRegion* reg, Window win, bool warp, Time time)
 {
 if(warp)
 region_do_warp(reg);
@@ -356,10 +356,7 @@
 return;
 
 region_set_await_focus(reg);
-/*xwindow_do_set_focus(win);*/
-XSetInputFocus(ioncore_g.dpy, win, RevertToParent, 
-   CurrentTime/*ioncore_focus_time*/);
-/*ioncore_focus_time=CurrentTime;*/
+XSetInputFocus(ioncore_g.dpy, win, RevertToParent, time);
 }
 
 
diff -rN -u old-ion-3/ioncore/focus.h new-ion-3/ioncore/focus.h
--- old-ion-3/ioncore/focus.h   2009-02-09 00:35:07.368883774 +0200
+++ new-ion-3/ioncore/focus.h   2009-02-09 00:35:07.484879092 +0200
@@ -23,7 +23,7 @@
 extern void region_warp(WRegion *reg); /* maybewarp TRUE */
 extern void region_set_focus(WRegion *reg); /* maybewarp FALSE */
 
-extern void region_finalise_focusing(WRegion* reg, Window win, bool warp);
+extern void region_finalise_focusing(WRegion* reg, Window win, bool warp, Time 
time);
 
 DYNFUN void region_do_set_focus(WRegion *reg, bool warp);
 extern void region_do_warp(WRegion *reg);
diff -rN -u old-ion-3/ioncore/group.c new-ion-3/ioncore/group.c
--- old-ion-3/ioncore/group.c   2009-02-09 00:35:07.272887653 +0200
+++ new-ion-3/ioncore/group.c   2009-02-09 00:35:07.460880061 +0200
@@ -241,7 +241,7 @@
 if(st!=NULL  st-reg!=NULL)
 region_do_set_focus(st-reg, warp);
 else
-region_finalise_focusing((WRegion*)ws, ws-dummywin, warp);
+region_finalise_focusing((WRegion*)ws, ws-dummywin, warp, 
CurrentTime);
 }
 
 
diff -rN -u old-ion-3/ioncore/window.c new-ion-3/ioncore/window.c
--- old-ion-3/ioncore/window.c  2009-02-09 00:35:07.332885230 +0200
+++ new-ion-3/ioncore/window.c  2009-02-09 00:35:07.480879252 +0200
@@ -182,7 +182,7 @@
 
 void window_do_set_focus(WWindow *wwin, bool warp)
 {
-region_finalise_focusing((WRegion*)wwin, wwin-win, warp);
+region_finalise_focusing((WRegion*)wwin, wwin-win, warp, CurrentTime);
 }
 
 
diff -rN -u old-ion-3/mod_tiling/tiling.c new-ion-3/mod_tiling/tiling.c
--- old-ion-3/mod_tiling/tiling.c   2009-02-09 00:35:07.124893627 +0200
+++ new-ion-3/mod_tiling/tiling.c   2009-02-09 00:35:07.416881837 +0200
@@ -158,7 +158,7 @@
 
 void tiling_fallback_focus(WTiling *ws, bool warp)
 {
-region_finalise_focusing((WRegion*)ws, ws-dummywin, warp);
+region_finalise_focusing((WRegion*)ws, ws-dummywin, warp, CurrentTime);
 }
 
 



Re: Keyboard focus lost in Swing applications (ex: Netbeans) after changing to window

2009-02-08 Thread Daniel Clemente


 Try the attached patch. (Disclaimer: I haven't particularly tried it; 
 just quickly threw it together.)

  Well, it improved lots of things. It works perfectly with gtk, qt, tk, 
keyboard, mouse, …
  The example code now works when I use Java 1.6.0_12-b04. But if I compile and 
run it with the unreleased 1.7.0-ea-b43, the focus is still buggy: not only the 
text field misses focus after going to that window, but also I can't restore 
the focus to the text field even if I click into it many times. Even with JDK 
1.7, this doesn't happen in other window managers (I tried wmaker).




Re: Keyboard focus lost in Swing applications (ex: Netbeans) after changing to window

2009-01-20 Thread Daniel Clemente
Daniel Clemente dcl441-b...@yahoo.com writes:


   I will check it again in other systems. 


Hi,
  I tried it with Sun's Java 1.6.0_10 on Debian (another machine). The bug is 
still present.
  However, on the same machine, Sun's Java 1.5.0_16-b02 makes my example work 
as expected (focus is not lost).

  And with libgcj... well, the example didn't work correctly and I didn't see 
the text field. My version:
java version 1.5.0
gij (GNU libgcj) version 4.3.3 20090110 (prerelease)

  With OpenJDK 1.6.0_0-b11, the bug shows up.
  With the unreleased Java 1.7.0-ea-b43, the same (bug present).

  So the focus problem seems to be a regression introduced in version 1.6 of 
Java and still not corrected...
  Or maybe it is indeed a bug in ion3; since other window managers (ex: icewm) 
do work with Java 1.6.

  In any case, I sent this bug to Java (sorry, it's not public yet). I will 
report progress here.

-- Daniel



Re: Keyboard focus lost in Swing applications (ex: Netbeans) after changing to window

2009-01-16 Thread Tuomo Valkonen
On 2009-01-16, Daniel Clemente dcl441-b...@yahoo.com wrote:
   I was using Ubuntu GNU/Linux 8.04.1 with these packages:

 ii  sun-java6-bin  6-06-0ubuntu1  Sun Java(TM) 
 Runtime Environment (JRE) 6 (architecture dependent fil

Etch, sun-java5-bin.
Also, just now whatever they've got on this FC4. (
$ java --version
java version 1.4.2
gij (GNU libgcj) version 4.0.2 20051125 (Red Hat 4.0.2-8)
)

-- 
[Fashion] is usually a form of ugliness so intolerable that we have
 to alter it every six months. -- Oscar Wilde
The computer industry is the only industry that is more fashion-driven
 than women's fashion. -- RMS



Re: Keyboard focus lost in Swing applications (ex: Netbeans) after changing to window

2009-01-15 Thread Tuomo Valkonen
On 2009-01-15, Daniel Clemente dcl441-b...@yahoo.com wrote:
 In fact any Swing application has this problem. You can use this one to test:

CBA going through all the trouble of installing java compilers
and whatever dependencies there may be. Java on Linux is pain;
already been too much trouble installing the VM back in the day.

   Why is it so?

Probably because Swing is crap and sets the focus somewhere where
it shouldn't be -- in violation of the ICCCM. X doesn't forward 
focus changes to the WM is requests, but rather obeys each and 
every one (unless the target window is hidden, etc.), so the 
WM should have to start fighting agianst them.

-- 
In 1995, Linux was almost a bicycle; an alternative way of live to the
Windows petrol beasts that had to be taken to the dealer for service.
By 2008, Linux has bloated into a gas-guzzler, and the cycle paths 
have been replaced with polluted motorways.



Re: Keyboard focus lost in Swing applications (ex: Netbeans) after changing to window

2009-01-15 Thread Sylvain Abélard
 Java on Linux is pain
But the MacOS JVM sucks,
the Windows ecosystem makes Java not portable,
the exotic platforms Java Editions lacks the libraries (not portable again),
and Java for the web was stillborn, dead, resurrected and will keep
being a zombie.

Java is pain is enough.

-- 
Sylvain Abélard
J'ai décidé d'être heureux, c'est meilleur pour la santé. -Voltaire