4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdisplay.h"
23 #include "bcsignals.h"
24 #include "bcwindowbase.h"
25 #include "bcwindowevents.h"
27 #include "condition.h"
30 BC_WindowEvents::BC_WindowEvents(BC_WindowBase *window)
33 this->window = window;
39 BC_WindowEvents::BC_WindowEvents(BC_Display *display)
42 this->display = display;
47 BC_WindowEvents::~BC_WindowEvents()
49 // First set done, then send dummy event through XSendEvent to unlock the loop in ::run()
50 //printf("BC_WindowEvents::~BC_WindowEvents %d %s\n", __LINE__, window->title);
53 XClientMessageEvent *ptr = (XClientMessageEvent*)&event;
54 event.type = ClientMessage;
55 ptr->message_type = XInternAtom(window->display, "DUMMY_XATOM", False);
57 XSendEvent(window->display,
64 //printf("BC_WindowEvents::~BC_WindowEvents %d %s\n", __LINE__, window->title);
67 void BC_WindowEvents::start()
74 void BC_WindowEvents::run()
76 // Can't cancel in XNextEvent because X server never figures out it's not
77 // listening anymore and XCloseDisplay locks up.
80 int x_fd = ConnectionNumber(window->display);
88 // Can't cancel in XNextEvent because X server never figures out it's not
89 // listening anymore and XCloseDisplay locks up.
92 XNextEvent(display->display, event);
93 display->put_event(event);
95 // This came from a linuxquestions post.
96 // We can get a file descriptor for the X display & use select instead of XNextEvent.
97 // The newest X11 library requires locking the display to use XNextEvent.
100 FD_SET(x_fd, &x_fds);
102 tv.tv_sec = 0; tv.tv_usec = 200000;
103 //printf("BC_WindowEvents::run %d %s\n", __LINE__, window->title);
104 select(x_fd + 1, &x_fds, 0, 0, &tv);
105 XLockDisplay(window->display);
106 while(!done && XPending(window->display))
109 XNextEvent(window->display, event);
110 if( event->type == BC_WindowBase::shm_completion_event ) {
111 window->top_level->active_bitmaps.reque(event);
115 // HACK: delay is required to get the close event
117 //if(window && event)
118 //printf("BC_WindowEvents::run %d %s %d\n", __LINE__, window->title, event->type);
119 window->put_event(event);
121 XUnlockDisplay(window->display);
122 //printf("BC_WindowEvents::run %d %s\n", __LINE__, window->title);