You are not logged in.
Pages: 1
As i cannot find a replacement for Compiz's hot corner functionality (tell me if you know of one), i decided to write my own in Java. I can do that no problem, but i do have a question. How are events normally detected? All i can think of is have a infinite loop, and constantly polling the cursor position and checking. This would work, but also take 100% of 1 cpu core. If i add a delay, say 30ms for about 30fps detection, its better, but still has high CPU usage. How are events normally done, so they don't take so much CPU while providing fast response?
Offline
There are a few approaches. Normally for something like this you would poll the mouse position as you have done. 30ms will be low enough that you won't notice any CPU usage with a language like C. I'm not sure how expensive the equivalent operation is in Java, but it sounds like it's much worse.
Another alternative is to use a hook, so that your function is called whenever the mouse cursor moves. This has the advantage that if the mouse cursor is not moving, there is zero CPU impact. But as a downside, you may incur a significant CPU hit every time you move the mouse, depending on how much work you are trying to do in response to each 'mouse moved' notification.
A third way, which I think is the way Compiz does (used to?) do it, is to create a four tiny invisible windows in the corners of each screen. These windows sit on top of all other windows, but don't get in the way because they're invisible. When the mouse moves close enough to a corner, the invisible windows start receiving mouseover events, which are your cue that the mouse is in the corner (or close to it, depending on how large you make the windows.) This is probably the most efficient way, but it relies on your language of choice being able to create invisible always-on-top windows across all desktops. You may also want to have a timer that runs every few seconds to make sure the windows really are always on top, as I remember when I used to use Compiz that sometimes the hot corners would mysteriously stop working when suddenly application windows would appear over the top of the invisible corner-windows.
As a side note, any reason why you are using Java? I'm not sure how you would link this in with Compiz, and Java has a fairly significant memory footprint for something small like monitoring a mouse cursor. If you wrote it as a Compiz plugin you might be able to get away with next to no memory/CPU impact.
Offline
Java only because I know Java, but I know a little bit of C, so i will look into that. The point is to make a stand alone progam, not a plugin for compiz, because Gnome 3 doesn't support compiz.
Offline
Oh sorry I thought you meant Compiz had removed hot corner functionality, not that you had stopped using Compiz but still wanted the functionality.
C is not terribly different to Java, but I think you will have a hard time achieving this in Java. Java is designed more for application writing rather than low-level integration with other programs, which is what you'd likely need to achieve nicely integrated hot-corner functionality.
Offline
Pages: 1