From 569d938024e866d7f17aed7e71124751b9339d5f Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 14 Jul 2016 21:56:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20linux=20=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit x11 貌似无法接收其它线程中发过来的事件,现在暂时将 X11_WaitEvent() 改为最长阻塞等待 10 毫秒,避免耽误 LCUI 任务处理。 Signed-off-by: Liu Chao --- include/LCUI/platform/linux/linux_events.h | 39 ++++++++++++++ include/LCUI/platform/linux/linux_fbdisplay.h | 38 ++++++++++++++ include/LCUI/platform/linux/linux_mouse.h | 4 +- .../LCUI/platform/linux/linux_x11display.h | 38 ++++++++++++++ include/LCUI/platform/linux/linux_x11events.h | 39 ++++++++++++++ src/platform/linux/linux_x11events.c | 52 +++++++++++++++++-- 6 files changed, 203 insertions(+), 7 deletions(-) diff --git a/include/LCUI/platform/linux/linux_events.h b/include/LCUI/platform/linux/linux_events.h index 8a29efce..585a917e 100644 --- a/include/LCUI/platform/linux/linux_events.h +++ b/include/LCUI/platform/linux/linux_events.h @@ -1,3 +1,42 @@ +/* *************************************************************************** + * linux_events.c -- event loop support for linux. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_events.c -- linux 平台的事件驱动支持。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + #ifndef LCUI_LINUX_EVENTS_H #define LCUI_LINUX_EVENTS_H diff --git a/include/LCUI/platform/linux/linux_fbdisplay.h b/include/LCUI/platform/linux/linux_fbdisplay.h index 8b137891..5323d41e 100644 --- a/include/LCUI/platform/linux/linux_fbdisplay.h +++ b/include/LCUI/platform/linux/linux_fbdisplay.h @@ -1 +1,39 @@ +/* *************************************************************************** + * linux_fbdisplay.h -- surface support for linux framebuffer. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_fbdisplay.h -- linux 平台的图形显示功能支持,基于帧缓存(FrameBuffer)。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ diff --git a/include/LCUI/platform/linux/linux_mouse.h b/include/LCUI/platform/linux/linux_mouse.h index b72b8d8f..31ae4901 100644 --- a/include/LCUI/platform/linux/linux_mouse.h +++ b/include/LCUI/platform/linux/linux_mouse.h @@ -1,5 +1,5 @@ /* *************************************************************************** - * linux_x11mouse.h -- mouse support for linux. + * linux_mouse.h -- mouse support for linux. * * Copyright (C) 2016 by Liu Chao * @@ -20,7 +20,7 @@ * ****************************************************************************/ /* **************************************************************************** - * linux_x11mouse.h -- linux 平台的鼠标支持 + * linux_mouse.h -- linux 平台的鼠标支持 * * 版权所有 (C) 2016 归属于 刘超 * diff --git a/include/LCUI/platform/linux/linux_x11display.h b/include/LCUI/platform/linux/linux_x11display.h index d0d32d07..646e6198 100644 --- a/include/LCUI/platform/linux/linux_x11display.h +++ b/include/LCUI/platform/linux/linux_x11display.h @@ -1,3 +1,41 @@ +/* *************************************************************************** + * linux_x11display.h -- surface support for linux xwindow. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11display.h -- linux 平台的图形显示功能支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ #ifndef LCUI_LINUX_X11_DISPLAY_H #define LCUI_LINUX_X11_DISPLAY_H diff --git a/include/LCUI/platform/linux/linux_x11events.h b/include/LCUI/platform/linux/linux_x11events.h index 6aad4ab3..0d5637c4 100644 --- a/include/LCUI/platform/linux/linux_x11events.h +++ b/include/LCUI/platform/linux/linux_x11events.h @@ -1,3 +1,42 @@ +/* *************************************************************************** + * linux_x11events.c -- event loop support for linux xwindow. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11events.c -- linux 平台的事件驱动支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + #ifndef LCUI_LINUX_X11_EVENTS_H #define LCUI_LINUX_X11_EVENTS_H diff --git a/src/platform/linux/linux_x11events.c b/src/platform/linux/linux_x11events.c index 961a084f..076b0a62 100644 --- a/src/platform/linux/linux_x11events.c +++ b/src/platform/linux/linux_x11events.c @@ -1,3 +1,41 @@ +/* *************************************************************************** + * linux_x11events.c -- event loop support for linux xwindow. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11events.c -- linux 平台的事件驱动支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ #include #include @@ -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 );