Home » U++ Library support » U++ Widgets - General questions or Mixed problems » capture mouse and limit all events to window
Re: capture mouse and limit all events to window [message #51704 is a reply to message #47441] |
Mon, 29 April 2019 09:16   |
slashupp
Messages: 231 Registered: July 2009
|
Experienced Member |
|
|
This applies to Linux-only.
To position the mouse-pointer anywhere in the window, or centered on a specific control in the window
I came up with this 'hack':
Header:
#ifndef _xfunc_h_
#define _xfunc_h_
#include <CtrlCore/CtrlCore.h>
namespace XFUNC
{
void set_Xmouse_pos(int x, int y);
void set_Xmouse_pos(Upp::Ctrl *pCtrl);
} //namespace XFUNC
#endif
Implementation:
#include "xfunc.h"
namespace XFUNC
{
#include <X11/Xlib.h>
void set_Xmouse_pos(int x, int y) //Ctrl *pCtrl)
{
Upp::GuiLock __;
static Display *disp=XOpenDisplay(0);
if (disp)
{
Window wroot=XRootWindow(disp, 0);
XWarpPointer(disp, 0, wroot, 0, 0, 0, 0, x, y);
XFlush(disp);
}
}
void set_Xmouse_pos(Upp::Ctrl *pCtrl)
{
if (!pCtrl) return;
Upp::GuiLock __;
int x, y;
Upp::Rect r=pCtrl->GetScreenRect();
x=(r.left+r.Width()/2);
y=(r.top+r.Height()/2);
static Display *disp=XOpenDisplay(0);
if (disp)
{
Window wroot=XRootWindow(disp, 0);
XWarpPointer(disp, 0, wroot, 0, 0, 0, 0, x, y);
XFlush(disp);
}
}
} //namespace XFUNC
Hope this helps someone
|
|
|
Goto Forum:
Current Time: Sat Jul 19 05:00:37 CEST 2025
Total time taken to generate the page: 0.03592 seconds
|