更新 linux 事件处理支持

x11 貌似无法接收其它线程中发过来的事件,现在暂时将 X11_WaitEvent() 改为最长阻塞等待 10 毫秒,避免耽误 LCUI 任务处理。

Signed-off-by: Liu Chao <lc-soft@live.cn>
This commit is contained in:
Liu Chao
2016-07-14 21:56:06 +08:00
parent 46d281381b
commit 569d938024
6 changed files with 203 additions and 7 deletions
@@ -1,3 +1,42 @@
/* ***************************************************************************
* linux_events.c -- event loop support for linux.
*
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
*
* This file is part of the LCUI project, and may only be used, modified, and
* distributed under the terms of the GPLv2.
*
* (GPLv2 is abbreviation of GNU General Public License Version 2)
*
* By continuing to use, modify, or distribute this file you indicate that you
* have read the license and understand and accept it fully.
*
* The LCUI project is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
*
* You should have received a copy of the GPLv2 along with this file. It is
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
* ****************************************************************************/
/* ****************************************************************************
* linux_events.c -- linux 平台的事件驱动支持。
*
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
*
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
*
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
*
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
*
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
* 定用途的隐含担保,详情请参照GPLv2许可协议。
*
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
* 没有,请查看:<http://www.gnu.org/licenses/>.
* ****************************************************************************/
#ifndef LCUI_LINUX_EVENTS_H
#define LCUI_LINUX_EVENTS_H
@@ -1 +1,39 @@
/* ***************************************************************************
* linux_fbdisplay.h -- surface support for linux framebuffer.
*
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
*
* This file is part of the LCUI project, and may only be used, modified, and
* distributed under the terms of the GPLv2.
*
* (GPLv2 is abbreviation of GNU General Public License Version 2)
*
* By continuing to use, modify, or distribute this file you indicate that you
* have read the license and understand and accept it fully.
*
* The LCUI project is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
*
* You should have received a copy of the GPLv2 along with this file. It is
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
* ****************************************************************************/
/* ****************************************************************************
* linux_fbdisplay.h -- linux 平台的图形显示功能支持,基于帧缓存(FrameBuffer)。
*
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
*
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
*
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
*
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
*
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
* 定用途的隐含担保,详情请参照GPLv2许可协议。
*
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
* 没有,请查看:<http://www.gnu.org/licenses/>.
* ****************************************************************************/
+2 -2
View File
@@ -1,5 +1,5 @@
/* ***************************************************************************
* linux_x11mouse.h -- mouse support for linux.
* linux_mouse.h -- mouse support for linux.
*
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
*
@@ -20,7 +20,7 @@
* ****************************************************************************/
/* ****************************************************************************
* linux_x11mouse.h -- linux 平台的鼠标支持
* linux_mouse.h -- linux 平台的鼠标支持
*
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
*
@@ -1,3 +1,41 @@
/* ***************************************************************************
* linux_x11display.h -- surface support for linux xwindow.
*
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
*
* This file is part of the LCUI project, and may only be used, modified, and
* distributed under the terms of the GPLv2.
*
* (GPLv2 is abbreviation of GNU General Public License Version 2)
*
* By continuing to use, modify, or distribute this file you indicate that you
* have read the license and understand and accept it fully.
*
* The LCUI project is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
*
* You should have received a copy of the GPLv2 along with this file. It is
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
* ****************************************************************************/
/* ****************************************************************************
* linux_x11display.h -- linux 平台的图形显示功能支持,基于 xwindow。
*
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
*
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
*
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
*
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
*
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
* 定用途的隐含担保,详情请参照GPLv2许可协议。
*
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
* 没有,请查看:<http://www.gnu.org/licenses/>.
* ****************************************************************************/
#ifndef LCUI_LINUX_X11_DISPLAY_H
#define LCUI_LINUX_X11_DISPLAY_H
@@ -1,3 +1,42 @@
/* ***************************************************************************
* linux_x11events.c -- event loop support for linux xwindow.
*
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
*
* This file is part of the LCUI project, and may only be used, modified, and
* distributed under the terms of the GPLv2.
*
* (GPLv2 is abbreviation of GNU General Public License Version 2)
*
* By continuing to use, modify, or distribute this file you indicate that you
* have read the license and understand and accept it fully.
*
* The LCUI project is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
*
* You should have received a copy of the GPLv2 along with this file. It is
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
* ****************************************************************************/
/* ****************************************************************************
* linux_x11events.c -- linux 平台的事件驱动支持,基于 xwindow。
*
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
*
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
*
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
*
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
*
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
* 定用途的隐含担保,详情请参照GPLv2许可协议。
*
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
* 没有,请查看:<http://www.gnu.org/licenses/>.
* ****************************************************************************/
#ifndef LCUI_LINUX_X11_EVENTS_H
#define LCUI_LINUX_X11_EVENTS_H
+47 -5
View File
@@ -1,3 +1,41 @@
/* ***************************************************************************
* linux_x11events.c -- event loop support for linux xwindow.
*
* Copyright (C) 2016 by Liu Chao <lc-soft@live.cn>
*
* This file is part of the LCUI project, and may only be used, modified, and
* distributed under the terms of the GPLv2.
*
* (GPLv2 is abbreviation of GNU General Public License Version 2)
*
* By continuing to use, modify, or distribute this file you indicate that you
* have read the license and understand and accept it fully.
*
* The LCUI project is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for more details.
*
* You should have received a copy of the GPLv2 along with this file. It is
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
* ****************************************************************************/
/* ****************************************************************************
* linux_x11events.c -- linux 平台的事件驱动支持,基于 xwindow。
*
* 版权所有 (C) 2016 归属于 刘超 <lc-soft@live.cn>
*
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
*
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
*
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
*
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
* 定用途的隐含担保,详情请参照GPLv2许可协议。
*
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
* 没有,请查看:<http://www.gnu.org/licenses/>.
* ****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
@@ -29,7 +67,7 @@ static LCUI_BOOL X11_PostTask( LCUI_AppTask task )
ev.xclient.window = x11.win_main;
ev.xclient.format = 32;
ev.xclient.message_type = x11.wm_lcui;
XSendEvent(x11.display, x11.win_main, FALSE, NoEventMask, &ev);
XSendEvent( x11.display, x11.win_main, FALSE, NoEventMask, &ev );
return TRUE;
}
@@ -37,7 +75,7 @@ static LCUI_BOOL X11_WaitEvent( void )
{
int fd;
fd_set fdset;
struct timeval zero_time;
struct timeval tv;
XFlush( x11.display );
fd = ConnectionNumber( x11.display );
if( XEventsQueued(x11.display, QueuedAlready) ) {
@@ -45,7 +83,9 @@ static LCUI_BOOL X11_WaitEvent( void )
}
FD_ZERO( &fdset );
FD_SET( fd, &fdset );
if( select(fd + 1, &fdset, NULL, NULL, &zero_time) == 1 ) {
tv.tv_sec = 0;
tv.tv_usec = 10000;
if( select(fd + 1, &fdset, NULL, NULL, &tv) == 1 ) {
return XPending( x11.display );
}
return FALSE;
@@ -54,10 +94,12 @@ static LCUI_BOOL X11_WaitEvent( void )
static void X11_DispatchEvent( void )
{
XEvent xevent;
if( !XEventsQueued(x11.display, QueuedAlready) ) {
return;
}
XNextEvent( x11.display, &xevent );
DEBUG_MSG("%d\n", xevent.type);
switch( xevent.type ) {
case ClientMessage:
case ClientMessage:
default: break;
}
EventTrigger_Trigger( x11.trigger, xevent.type, &xevent );