About Store Forum Documentation Contact



Post Reply 
[SOLVED] Mouse interaction problem on Linux
Author Message
cat555 Offline
Member

Post: #1
[SOLVED] Mouse interaction problem on Linux
Hi, i've installed Esenthel in Linux (Debian Wheezy), and it's working Ok... but in some examples that require mouse input, or in the world editor, and can't get good mouse interaction... for example, i want to rotate the terrain, but i can't get it to rotate Ok... some times rotates some degrees but stops... i click on mouse button and drag and world does not rotate, and when it rotates is just a few and then stops...

Any idea of what's going on? Maybe i'm doing something wrong?
(This post was last modified: 01-13-2014 03:16 PM by cat555.)
12-31-2013 07:11 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Mouse interaction problem on Linux
Hi,
Do you mean rotate the world or rotate the camera?
What mouse button are you using to do it?
You can rotate the camera in 2 ways using just the mouse:
-Hold LMB on the View Cube in top left corner
-Hold Middle Mouse Button on the viewport
Do both ways have issues?
01-02-2014 06:12 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #3
RE: Mouse interaction problem on Linux
Hi Esenthel, yes, i've tried both ways and in both i have the related problems:
-Hold LMB on the View Cube in top left corner
-Hold Middle Mouse Button on the viewport

Do you have an idea of what could be the issue?

Thanks!
01-02-2014 11:17 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #4
RE: Mouse interaction problem on Linux
Hi @Esenthel,

Besides world editor, one good example for this is the Pathfinding demo. In there, we should use RMB to rotate the world. If i click RMB and rapidly make a fast move, the world rotates a bit... but if i click RMB and wait for a little short of time, and keep it pressed, when moving mouse nothing happens... world does not rotate.

If you need some specific tests pelase ask so... i'm stuck with this problem, and can't start my world creation as you understand.

Thanks + Regards
01-03-2014 01:10 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #5
RE: Mouse interaction problem on Linux
Hey @Esenthel, it seems that mouse button clicks are blocking Update() methods. In the Earth demo i switched from:

bool Update()
{
...
if(Ms.b(0))d+=Ms.d();
...
}

to:

bool Update()
{
...
if(Kb.b(KB_LSHIFT)) d+=Ms.d();
...
}

And the rotations are Ok, since getting mouse coordinates is Ok... so it seems that's a problem with "Ms.b(...)" method blocking Update(...) method.

Maybe you already know this, but it was just to advance some information from my tests...

Regards,
(This post was last modified: 01-03-2014 05:15 PM by cat555.)
01-03-2014 05:01 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Mouse interaction problem on Linux
Hi,
I don't think it's blocking the Update, but rather your Linux for some reason releases the button on the same/next frame it's pushed?

How many buttons does your mouse have?

Can you do this test:
in Draw()
{
..
D.text(0, 0, S+Ms.b(0)+Ms.b(1)+Ms.b(2)+Ms.b(3));

it should display 1 all the time a button is being pressed down, 0-LMB, 1-RMB, 2-MMB, 3-4th mouse button
4th mouse button is processed differently than LMB/RMB/MMB and I'm curious if you have the same issue with it as with others.
Does your mouse have 4 buttons or just 3?
01-03-2014 10:48 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #7
RE: Mouse interaction problem on Linux
Hi,

My mouse has 3 buttons.

And yes, you're right... it's not blocking... i've made your test and it works like you expected. As long i press a button, a '1' is shown.

But in this case, if it was the button release issue your refer, your test would not show up '1' (maybe just in a couple of frames) always, since the button would be released in the same or next frame...

...do you agree?

Hey, accidently i found that the problem is somehow related with window focus.

For example: i have the running game window, but another window has the focus (important). In this case if i click with mouse button on the game window and drag (of course the game window gains focus at this time), the rotation is executed correctly. If i release mouse button and click again on game window, can't rotate again...

I can reproduce this behavior in any running game window, which would be a workaround, but it does NOT work in the Esenthel Editor :(

Another thing is, in Esenthel Editor, when i press mouse button and drag, the mouse pointer does not move, it stays on the same point i clicked first, till i release button...

In a game window, when i click and drag, the scene does not rotate but the mouse pointer moves...
(This post was last modified: 01-04-2014 02:19 AM by cat555.)
01-04-2014 01:57 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #8
RE: Mouse interaction problem on Linux
Hi,

Just to make things clear:
D.text(0, 0, S+Ms.b(0)+Ms.b(1)+Ms.b(2)+Ms.b(3));

This will display '1' for your mouse buttons for:
-frame when you press button for the first time
-and next frames as long as you keep it pressed?

So this works correctly?

What happens if you add following line in Init:
Bool Init()
{
Ms.clip(NULL, true); // this clips your mouse cursor position to your application window

will the mouse display 1 for all buttons as long as you keep having them pressed-down? (will it work the same or differently)

Quote:Another thing is, in Esenthel Editor, when i press mouse button and drag, the mouse pointer does not move, it stays on the same point i clicked first, till i release button...
In some places this is made on purpose (just like camera rotation)
01-04-2014 02:33 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #9
RE: Mouse interaction problem on Linux
Hi,

Quote:Just to make things clear:
D.text(0, 0, S+Ms.b(0)+Ms.b(1)+Ms.b(2)+Ms.b(3));

This will display '1' for your mouse buttons for:
-frame when you press button for the first time
-and next frames as long as you keep it pressed?

So this works correctly?

As long i keep a button pressed, the corresponding '1' is shown... so is shown for all frames in that period.

Quote:What happens if you add following line in Init:
Bool Init()
{
Ms.clip(NULL, true); // this clips your mouse cursor position to your application window

will the mouse display 1 for all buttons as long as you keep having them pressed-down? (will it work the same or differently)

The behavior is the same... as long i keep a button pressed, the corresponding '1' is shown. But in this case, i can't get any rotation at all when moving mouse.
01-04-2014 09:46 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #10
RE: Mouse interaction problem on Linux
Hi,

okey so the button state is detected properly,

can you try executing this program:
Code:
/******************************************************************************/
void InitPre()
{
   EE_INIT();
}
bool Init()
{
   return true;
}
void Shut()
{
}
bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   Ms.freeze();
   Gui.update();
   return true;
}
void Draw()
{
   D.clear(WHITE);
   Gui.draw();
   D.text(0, 0, S+Ms.d());
}
/******************************************************************************/
It should freeze your mouse position.
However when you move your mouse around, it should display mouse movement delta values. (when moving it shouldn't be displaying "0,0")
Can you please confirm that when you move the mouse, you have values different than "0,0" on the screen?
01-05-2014 05:54 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #11
RE: Mouse interaction problem on Linux
Hi,

I've made your test... mouse pointer does not move, as you are expecting, but when moving mouse, "0,0" is displayed all the time.
01-05-2014 04:35 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #12
RE: Mouse interaction problem on Linux
Hi,

Thanks, so we know what's the issue.

Could you test this version:
Code:
/******************************************************************************/
void InitPre()
{
    EE_INIT();
}
bool Init()
{
    Ms.clip(NULL, true);
    return true;
}
void Shut()
{
}
bool Update()
{
    if(Kb.bp(KB_ESC))return false;
    Gui.update();
    return true;
}
void Draw()
{
    D.clear(WHITE);
    Gui.draw();
    D.text(0, 0, S+Ms.d());
}
/******************************************************************************/

Please let me know if here you get "0,0" always too, or do they display properly.

Thank you
01-07-2014 05:24 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #13
RE: Mouse interaction problem on Linux
Hi Esenthel,

I've executed the latest test, and i get always "0,0" too.

Regards,
01-07-2014 02:51 PM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #14
RE: Mouse interaction problem on Linux
Hi Esenthel,

Did you manage to find a fix for this issue? Do you need some more tests on my side?

Regards
01-12-2014 12:20 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #15
RE: Mouse interaction problem on Linux
Hi,

I'm using this code to get the mouse deltas:
Code:
for(; XEventsQueued(XDisplay, QueuedAfterFlush); )
   {
      XEvent event; XNextEvent(XDisplay, &event);

      switch(event.type)
      {
         case GenericEvent: if(event.xcookie.extension==XInput2Extension)
         {
            if(XGetEventData(XDisplay, &event.xcookie))
            {
               switch(event.xcookie.evtype)
               {
                  case XI_RawMotion:
                  {
                     XIRawEvent &raw=*(XIRawEvent*)event.xcookie.data;
                     Dbl delta[2]; SetXInputValues(raw.raw_values, raw.valuators.mask, raw.valuators.mask_len, delta, Elms(delta));
                     Ms._dir_d.x+=delta[0];
                     Ms._dir_d.y-=delta[1];
                  }break;
And this code to clip the mouse cursor:
Code:
if(XDisplay)
   {
      if(!rect)XUngrabPointer(XDisplay, CurrentTime);else
      {
         Bool custom=(*rect!=RectI(0, 0, D.x(), D.y()));
         if(custom)
         {
            VecI2 pos=0; XWindow child=NULL; XTranslateCoordinates(XDisplay, App.Hwnd(), DefaultRootWindow(XDisplay), 0, 0, &pos.x, &pos.y, &child); // convert to desktop space
               XMoveResizeWindow(XDisplay, Grab, rect->min.x+pos.x, rect->min.y+pos.y, rect->w(), rect->h());
         }else XMoveResizeWindow(XDisplay, Grab, -1, -1, 1, 1); // move outside of desktop area
         XFlush(XDisplay);
         XGrabPointer(XDisplay, App.Hwnd(), false, ButtonPressMask|ButtonReleaseMask|EnterWindowMask|LeaveWindowMask, GrabModeAsync, GrabModeAsync, custom ? Grab : App.Hwnd(), NULL, CurrentTime);
      }
   }
The code works on Ubuntu, but apparently not on your Linux (on Ubuntu even when you clip the mouse cursor you still get raw deltas). I don't have your Linux installed so I can't do any tests.
If you want and you think you would know how to solve this (you have some Xlib/Xinput programming experience), then I could attach a small C++ file for NetBeans that does this as a raw sample native Linux project (not related to Esenthel Engine).
01-12-2014 12:56 AM
Find all posts by this user Quote this message in a reply
Post Reply