前言
QNX系统下界面是以screen为单位,纵向分层显示。工作中遇到screenA的touch事件被screenB截获,导致screenA监测release事件一直未释放而无响应的问题。考虑在出现问题的时候,模拟屏幕点击release事件,可激活screenA重新接收新的touch事件。
1、初始化
1.1 上下文
screen_context_t screen_context = 0;
screen_create_context(&screen_context,SCREEN_APPLICATION_CONTEXT | SCREEN_INPUT_PROVIDER_CONTEXT);
1.2 显示设备
screen_display_t displaylist[5];
screen_get_context_property_pv(screen_context, SCREEN_PROPERTY_DISPLAYS, (void **)&displaylist);
m_screendisplay = displaylist[0];
1.3 创建屏幕事件句柄
screen_event_t m_screenevent;
screen_create_event(&m_screenevent);
1.4 模拟触摸的位置点
typedef struct {
int action;
int touchid;
uint32_t x;
uint32_t y;
uint32_t width;
uint32_t height;
}touch_para_t;
touch_para_t points[3];
points[0].action = 1;
points[0].touchid = 0;
points[0].x = 600;
points[0].y = 1000;
points[0].width = 30;
points[0].height = 50;
points[1].action = 1;
points[1].touchid = 1;
points[1].x = 700;
points[1].y = 1000;
points[1].width = 30;
points[1].height = 50;
points[2].action = 1;
points[2].touchid = 2;
points[2].x = 800;
points[2].y = 1000;
points[2].width = 30;
points[2].height = 50;
touch_event(3, points);
其中,action参数代表touch事件类型,由枚举值定义,如: SCREEN_EVENT_MTOUCH_TOUCH, SCREEN_EVENT_MTOUCH_RELEASE, SCREEN_EVENT_MTOUCH_MOVE,touchid代表不同的触摸点
2、事件下发
const static int touchevent[] = { SCREEN_EVENT_MTOUCH_TOUCH, SCREEN_EVENT_MTOUCH_RELEASE, SCREEN_EVENT_MTOUCH_MOVE};
int touch_event(int num, touch_para_t para[])
{
int rv = 0;
int type = SCREEN_EVENT_MTOUCH_TOUCH;
int coords[2];
int touch_size[2];
static int m_seqid = 0;
for (int i = 0; i < num; ++i)
{
type = touchevent[para[i].action];
rv = screen_set_event_property_iv(m_screenevent, SCREEN_PROPERTY_TYPE, &type);
if (rv)
{
break;
}
rv = screen_set_event_property_iv(m_screenevent, SCREEN_PROPERTY_TOUCH_ID, ¶[i].touchid);
if (rv)
{
break;
}
coords[0] = para[i].x;
coords[1] = para[i].y;
rv = screen_set_event_property_iv(m_screenevent, SCREEN_PROPERTY_POSITION, (int*)&coords);
if (rv)
{
break;
}
touch_size[0] = para[i].width;
touch_size[1] = para[i].height;
rv = screen_set_event_property_iv(m_screenevent, SCREEN_PROPERTY_SIZE, (int*)&touch_size);
if (rv)
{
break;
}
rv = screen_set_event_property_iv(m_screenevent, SCREEN_PROPERTY_SEQUENCE_ID, (int*)&m_seqid);
if (rv)
{
break;
}
rv = screen_inject_event(m_screendisplay, m_screenevent);
if (rv)
{
break;
}
++m_seqid;
}
return rv;
}
总结
最终实验效果在screenA可能被截获的场景下,启动定时器模拟下发release事件可以重新激活screenA的touch流程,满足产品需求。