2 This file is part of fxwt, the window system toolkit of 3dengfx.
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
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
21 /* main fxwt event handling and system abstraction.
23 * Author: John Tsiombikas 2004
26 #include "3dengfx_config.h"
28 #if GFX_LIBRARY == NATIVE && NATIVE_LIB == NATIVE_X11
30 #include "gfx_library.h"
32 #include "3dengfx/3denginefx.hpp"
33 #include "common/err_msg.h"
37 #ifdef _POSIX_PRIORITY_SCHEDULING
39 #endif // _POSIX_PRIORITY_SCHEDULING
45 static void handle_event(const XEvent &event);
47 extern Display *fxwt_x_dpy;
48 extern ::Window fxwt_x_win;
50 Vector2 fxwt::get_mouse_pos_normalized() {
54 void fxwt::set_window_title(const char *title) {
55 XTextProperty tp_wname;
56 XStringListToTextProperty((char**)&title, 1, &tp_wname);
57 XSetWMName(fxwt_x_dpy, fxwt_x_win, &tp_wname);
58 XFree(tp_wname.value);
61 void fxwt::swap_buffers() {
62 glXSwapBuffers(fxwt_x_dpy, fxwt_x_win);
63 #ifdef _POSIX_PRIORITY_SCHEDULING
68 int fxwt::main_loop() {
72 if(!idle_handlers.empty()) {
73 while(XPending(fxwt_x_dpy)) {
75 XNextEvent(fxwt_x_dpy, &event);
79 list<void (*)()>::iterator iter = idle_handlers.begin();
80 while(iter != idle_handlers.end()) {
85 XNextEvent(fxwt_x_dpy, &event);
93 static void handle_event(const XEvent &event) {
94 static int window_mapped;
106 if(window_mapped && event.xexpose.count == 0) {
107 list<void (*)()>::iterator iter = disp_handlers.begin();
108 while(iter != disp_handlers.end()) {
116 char *atom_name = XGetAtomName(fxwt_x_dpy, event.xclient.message_type);
117 if(!strcmp(atom_name, "WM_PROTOCOLS")) {
127 KeySym keysym = XLookupKeysym((XKeyEvent*)&event.xkey, 0);
128 //key_state[keysym] = 1;
130 list<void (*)(int)>::iterator iter = keyb_handlers.begin();
131 while(iter != keyb_handlers.end()) {
132 (*iter++)(keysym & 0xff);
139 list<void (*)(int, int)>::iterator iter = motion_handlers.begin();
140 while(iter != motion_handlers.end()) {
141 (*iter++)(event.xmotion.x, event.xmotion.y);
156 button_state[event.xbutton.button] = state;
158 list<void (*)(int, int, int, int)>::iterator iter = button_handlers.begin();
159 while(iter != button_handlers.end()) {
160 (*iter++)(event.xbutton.button, state, event.xbutton.x, event.xbutton.y);
170 #endif // GFX_LIBRARY == NATIVE && NATIVE_LIB == NATIVE_X11