Thread: [Java-gnome-developer] Re: [Help] CustomEvents refresh problem
Brought to you by:
afcowie
From: Jonas B. <jb...@ni...> - 2003-09-09 02:50:01
|
On 2003-08-31 07:20, Mark Howard wrote: > Hi, > I've noticed a bug with CustomEvents class, but don't know how to fix > it (I wrote CustomEvents). > > My program calls custom events to update the gui and everything works > fine from a multithreaded pov (no more of those XLib errors). But: the > screen doesn't get refreshed until some gtk widget tells it to refresh. > e.g. when moving the mouse over certain places. Hello. I have a solution for your problem. I had the same problem myself=20 and I was just about to post my patch to the list anyway. The patch works just fine for me - it is pretty clean and unless I got=20 something fundamentally wrong, it should work fine for you too. =3D) The original implementation of CustomEvents does indeed what you said - i= t=20 doesn't run your events until some other event is received by the so=20 called glib main loop (which gtk uses). The basic problem is how to make=20 glib know when we have posted new events to be executed with CustomEvents= .=20 The current implementation just sits there and if glib-main-loop happens=20 to ask (which it does when some other event is received), only then does=20 it report whether it has events to serve or not. The obstacle here is that there is no function we can call in glib to tel= l=20 it that we have something for it. It basically sits waiting in a select()= =20 (or similar) call (a function for waiting for file, socket etc descriptor= s=20 without polling). Now, in CustomEvents, we could tell glib that we need t= o=20 be polled with certain intervals, basically making select return after a=20 certain delay if there was no data. This is what I tried first, and it=20 worked semi-well, but there was still a "lag" when I kept the timeout at=20 200 milliseconds, as I didn't really want to load the system by polling=20 too often. My current solution takes another approach - it makes a descriptor that I= =20 can register to glib, and then I make this descriptor "return data" when = I=20 want glib to wake up. It utilizes the pipe(2) function, which creates a=20 pair of file descriptors through which data can be piped. I give the=20 "reading end" to glib and keep the writing end for myself. So, whenever=20 there's an event that needs to be served, I write a byte to the pipe, and= =20 boom, in the main glib thread, select() returns immediately, and glib=20 starts checking for events, including CustomEvents. The solution provides perfect response for me. The patch is available here: http://xkr47.outerspace.dyndns.org/tmp/java-gnome-0.8.0-customevents-1.= diff To use, simply: tar xzf java-gnome-0.8.tar.gz patch -p0 < java-gnome-0.8.0-customevents-1.diff cd java-gnome-0.8 .. (continue normal installation) Alternatively you can use it with java-gtk as well: tar xzf java-gtk-0.8.tar.gz cd java-gtk-0.8 patch -p1 < java-gnome-0.8.0-customevents-1.diff .. (continue normal installation) If anyone have any comments on the implementation, the approach or the=20 problem in general, I'll be glad to discuss it. I'm not on the=20 java-gnome-developer mailing list myself, so I'd appreciate if you CC me=20 anything related. Thanks! =3D) While writing this, I started thinking, maybe this functionality could be= =20 a part of glib itself, which would allow one to provide this "missing"=20 function that could be called to trigger a poll for events. Probably this= =20 wouldn't benefit the java-gnome project itself, merely my patch could be=20 changed to make use of the function at that point. - xkr47 |
From: Mark H. <mh...@ti...> - 2003-09-09 13:28:48
|
Hi, I don't have time to look at it at the moment, but will try next week. Jeff - Calling widget.refresh requires you to know which widgets need refreshing. It also wastefully refreshes widgets if they don't need refreshing. Should probably also look at how other Gtk bindings tackle these issues. -- .''`. Mark Howard : :' : `. `' http://www.tildemh.com `- mh...@de... | mh...@ti... | mh...@ca... |
From: Mark H. <mh...@ti...> - 2003-09-11 20:28:38
|
On Mon, Sep 08, 2003 at 11:41:10PM +0300, Jonas Berlin wrote: > Hello. I have a solution for your problem. I had the same problem myself > and I was just about to post my patch to the list anyway. Thanks. Are you developing an application with java-gnome? I've not seen you on the list before. It's great to see new people working with java-gnome, especially people who aren't afraid to write patches :) > The patch works just fine for me - it is pretty clean and unless I got > something fundamentally wrong, it should work fine for you too. =) Looks good to me too. Works wonderfully. I've not checked with other bindings to see if it's the proper way yet, but it works well so I've committed to cvs. > While writing this, I started thinking, maybe this functionality could be > a part of glib itself, perhaps. I don't think any glib developers are on this list. Please try sending you patch to a glib list. -- .''`. Mark Howard : :' : `. `' http://www.tildemh.com `- mh...@de... | mh...@ti... | mh...@ca... |
From: Jonas B. <jb...@ni...> - 2003-09-12 00:39:02
|
On Thu, 11 Sep 2003 21:25:47 +0100, Mark Howard <mh...@ti...> wrote: > Thanks. Are you developing an application with java-gnome? I've not see= n > you on the list before. It's great to see new people working with > java-gnome, especially people who aren't afraid to write patches :) Yes, I am trying to write some basic tool to receive & display data from = a=20 java profiler a friend of mine wrote. It sends the data over UDP and I=20 then parse it & display it somehow, don't know exactly how yet. I kindof like the gtk interface, but I think it's a bit too=20 object-oriented to be elegant to code with in pure C. Otoh, I pretty much= =20 don't want to touch C++, so if I would have to choose, I would go with C=20 anyway. I have been coding a lot with java, but I think both awt & swing=20 sucks, both graphically and program-wise. I haven't tried SWT, but anyway= =20 I like gtk. So this Java-gtk binding is indeed interesting, and seems=20 quite promising I think. I understand it's still not finalized and that=20 interfaces might change, but I definately want to give it a try. Although= =20 I'm no expert on how object-oriented interfaces for GUIs should be=20 implemented, I think the current 0.8 version looks pretty much like java,= =20 which I like. And yep, I've not written to the list before. No problems writing patches= =20 here. I don't have that much experience in gtk2 and glib2 however, but if= =20 I run into a bug, I will probably gain more =3D) > Looks good to me too. Works wonderfully. I've not checked with other > bindings to see if it's the proper way yet, but it works well so I've > committed to cvs. Actually, when I looked at it again, I found that the read() call (in the= =20 native code) should be done from within the synchronized block that=20 executes the events. I didn't actually check the java right now, but I=20 think the write() call is called from within a synchronized block already= =20 (if it isn't, it should be too). This will add some minor overhead, but I= =20 tend to prefer correct operation to minimal performance gain =3D) > perhaps. I don't think any glib developers are on this list. Please try > sending you patch to a glib list. Well I don't have a patch for glib yet.. And I don't have that much time=20 to spend now.. BTW, I succeeded with my simple test program which receives approx 5 line= s=20 of text every second to jam the gtk thread. I append the text received to= =20 a TextView, and after appending text some 300-305 times, it just stops. I= =20 investigated a bit into this, and it seemed that the java native code=20 handling signals was receiving an internal event sent by the TextView to=20 its TextBuffer to perform the insertion of the text. And after this=20 300-305 times it jammed in the java native handler while trying to=20 allocate memory for the string argument. It always jammed after around=20 300-305 times. I didn't invent any good fix for this as I really didn't=20 know what was to blame.. I could write a simpler program for this to=20 illustrate how to reproduce the problem. I also succeeded in attaching=20 with gdb to the java thread that was jamming, and got a 45-line backtrace= .=20 I don't have it now, but I can try to get it when I get to making this=20 simple bug-reproducing program. Anyway, the TextView was just a test arena for showing the incoming data,= =20 so it's not a showstopper for me. I just hope the problem won't pop up=20 with other components :) BTW, what's your role in java-gnome? Are you a main developer or? --=20 ::: Jonas Berlin ::: +358-40-5884454 ::: ::: ::: ::: http://xkr47.outerspace.dyndns.org/ ::: |
From: Mark H. <mh...@ti...> - 2003-09-12 06:21:19
|
On Fri, Sep 12, 2003 at 03:38:51AM +0300, Jonas Berlin wrote: > I understand it's still not finalized and that > interfaces might change Unlike most gtk/gnome ports, we're not trying to clone its interface to java. We're trying to reproduce it in a nice Java style. For example in text views we pass data blocks around rather than integers and other things. The bits which will change are the bits which look ugly. For example at the moment you have to add UIInfo.end() to the end of all UIInfo arrays. That's something I want to fix. > Actually, when I looked at it again, I found that the read() call (in the ok. > Anyway, the TextView was just a test arena for showing the incoming data, > so it's not a showstopper for me. I just hope the problem won't pop up > with other components :) There are a few bugs in text view. One of my aims for this summer was to fix these and get a copy of the gtk-demo text view example running. Unfortunately I've not had any time to do this. > BTW, what's your role in java-gnome? Are you a main developer or? I'm just one of the developers. I did a lot of work on the graphical bits of the gtk widgets, before I knew much JNI. Then I moved on and sorted out the treeview and started the textview and wrote CustomEvents. I've written a very large application with java-gnome (bugwatcher - like an email client, but for bugs) - this has helped find bugs in java-gnome. There are a few developers who contribute occasionally. Unfortunately none of us have lots of time. -- .''`. Mark Howard : :' : `. `' http://www.tildemh.com `- mh...@de... | mh...@ti... | mh...@ca... |
From: Jonas B. <jb...@ni...> - 2003-09-12 08:42:05
|
On Fri, 12 Sep 2003 07:18:33 +0100, Mark Howard <mh...@ti...> wrote: > Unlike most gtk/gnome ports, we're not trying to clone its interface to > java. We're trying to reproduce it in a nice Java style. For example in > text views we pass data blocks around rather than integers and other > things. The bits which will change are the bits which look ugly. For > example at the moment you have to add UIInfo.end() to the end of all > UIInfo arrays. That's something I want to fix. Maybe that's something I could help out with, if I have time.. >> BTW, what's your role in java-gnome? Are you a main developer or? > I'm just one of the developers. I did a lot of work on the graphical > bits of the gtk widgets, before I knew much JNI. Then I moved on and > sorted out the treeview and started the textview and wrote CustomEvents= . > I've written a very large application with java-gnome (bugwatcher - lik= e > an email client, but for bugs) - this has helped find bugs in java-gnom= e. > There are a few developers who contribute occasionally. Unfortunately > none of us have lots of time. I've used JNI a bit, and have some experience in passing stuff from/to=20 java, even streaming stuff (I made a buffering wrapper for InputStream fo= r=20 example, that I then used directly for libjpeg, libpng and other librarie= s=20 that parse data gradually). The data was streamed (in java) from the=20 internet directly, so the native libraries could start decoding jpegs=20 while still downloading, for example. - xkr47 |