add new msg dispatch method for filtering events
This commit is contained in:
parent
943a9e444d
commit
1247e5c4e4
@ -143,7 +143,7 @@ namespace detail
|
|||||||
{
|
{
|
||||||
//Make a cleanup msg packet to infor the dispatcher the window is closed.
|
//Make a cleanup msg packet to infor the dispatcher the window is closed.
|
||||||
msg_packet_tag msg;
|
msg_packet_tag msg;
|
||||||
msg.kind = msg.kind_cleanup;
|
msg.kind = msg_packet_tag::pkt_family::cleanup;
|
||||||
msg.u.packet_window = wd;
|
msg.u.packet_window = wd;
|
||||||
thr->msg_queue.push_back(msg);
|
thr->msg_queue.push_back(msg);
|
||||||
}
|
}
|
||||||
@ -171,6 +171,30 @@ namespace detail
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename MsgFilter>
|
||||||
|
void dispatch(MsgFilter msg_filter_fn)
|
||||||
|
{
|
||||||
|
auto tid = nana::system::this_thread_id();
|
||||||
|
msg_packet_tag msg;
|
||||||
|
int qstate;
|
||||||
|
|
||||||
|
//Test whether the thread is registered for window, and retrieve the queue state for event
|
||||||
|
while((qstate = _m_read_queue(tid, msg, 0)))
|
||||||
|
{
|
||||||
|
//the queue is empty
|
||||||
|
if(-1 == qstate)
|
||||||
|
{
|
||||||
|
if(false == _m_wait_for_queue(tid))
|
||||||
|
proc_.timer_proc(tid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(msg_filter_fn(msg))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
void _m_msg_driver()
|
void _m_msg_driver()
|
||||||
{
|
{
|
||||||
@ -220,7 +244,7 @@ namespace detail
|
|||||||
switch(proc_.filter_proc(event, msg_pack))
|
switch(proc_.filter_proc(event, msg_pack))
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
msg_pack.kind = msg_pack.kind_xevent;
|
msg_pack.kind = msg_packet_tag::pkt_family::xevent;
|
||||||
msg_pack.u.xevent = event;
|
msg_pack.u.xevent = event;
|
||||||
_m_msg_dispatch(msg_pack);
|
_m_msg_dispatch(msg_pack);
|
||||||
break;
|
break;
|
||||||
@ -246,9 +270,9 @@ namespace detail
|
|||||||
{
|
{
|
||||||
switch(pack.kind)
|
switch(pack.kind)
|
||||||
{
|
{
|
||||||
case msg_packet_tag::kind_xevent:
|
case msg_packet_tag::pkt_family::xevent:
|
||||||
return _m_event_window(pack.u.xevent);
|
return _m_event_window(pack.u.xevent);
|
||||||
case msg_packet_tag::kind_mouse_drop:
|
case msg_packet_tag::pkt_family::mouse_drop:
|
||||||
return pack.u.mouse_drop.window;
|
return pack.u.mouse_drop.window;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -294,7 +318,7 @@ namespace detail
|
|||||||
//Check whether the event dispatcher is used for the modal window
|
//Check whether the event dispatcher is used for the modal window
|
||||||
//and when the modal window is closing, the event dispatcher would
|
//and when the modal window is closing, the event dispatcher would
|
||||||
//stop event pumping.
|
//stop event pumping.
|
||||||
if((modal == msg.u.packet_window) && (msg.kind == msg.kind_cleanup))
|
if((modal == msg.u.packet_window) && (msg.kind == msg_packet_tag::pkt_family::cleanup))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@ -10,8 +10,8 @@ namespace detail
|
|||||||
{
|
{
|
||||||
struct msg_packet_tag
|
struct msg_packet_tag
|
||||||
{
|
{
|
||||||
enum kind_t{kind_xevent, kind_mouse_drop, kind_cleanup};
|
enum class pkt_family{xevent, mouse_drop, cleanup};
|
||||||
kind_t kind;
|
pkt_family kind;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
XEvent xevent;
|
XEvent xevent;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user