diff options
Diffstat (limited to 'platform/x11')
-rw-r--r-- | platform/x11/context_gl_x11.cpp | 10 | ||||
-rw-r--r-- | platform/x11/detect.py | 27 | ||||
-rw-r--r-- | platform/x11/os_x11.cpp | 179 | ||||
-rw-r--r-- | platform/x11/os_x11.h | 11 |
4 files changed, 162 insertions, 65 deletions
diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp index dc0dc063b9..3db1f6da25 100644 --- a/platform/x11/context_gl_x11.cpp +++ b/platform/x11/context_gl_x11.cpp @@ -46,7 +46,6 @@ struct ContextGL_X11_Private { ::GLXContext glx_context; }; - void ContextGL_X11::release_current() { glXMakeCurrent(x11_display, None, NULL); @@ -56,10 +55,12 @@ void ContextGL_X11::make_current() { glXMakeCurrent(x11_display, x11_window, p->glx_context); } + void ContextGL_X11::swap_buffers() { glXSwapBuffers(x11_display,x11_window); } + /* static GLWrapperFuncPtr wrapper_get_proc_address(const char* p_function) { @@ -154,6 +155,9 @@ Error ContextGL_X11::initialize() { */ //glXMakeCurrent(x11_display, None, NULL); + XFree( vi ); + XFree( fbc ); + return OK; } @@ -164,12 +168,12 @@ int ContextGL_X11::get_window_width() { return xwa.width; } + int ContextGL_X11::get_window_height() { XWindowAttributes xwa; XGetWindowAttributes(x11_display,x11_window,&xwa); return xwa.height; - } @@ -189,6 +193,8 @@ ContextGL_X11::ContextGL_X11(::Display *p_x11_display,::Window &p_x11_window,con ContextGL_X11::~ContextGL_X11() { + release_current(); + glXDestroyContext( x11_display, p->glx_context ); memdelete( p ); } diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 7fa1666c59..9a52a7c92b 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -63,7 +63,7 @@ def get_flags(): return [ ('builtin_zlib', 'no'), ("openssl", "yes"), - ("theora","no"), + #("theora","no"), ] @@ -109,11 +109,11 @@ def configure(env): if (env["target"]=="release"): - - if (env["debug_release"]): - env.Append(CCFLAGS=['-g2','-fomit-frame-pointer']) + + if (env["debug_release"]=="yes"): + env.Append(CCFLAGS=['-g2']) else: - env.Append(CCFLAGS=['-O2','-ffast-math','-fomit-frame-pointer']) + env.Append(CCFLAGS=['-O3','-ffast-math']) elif (env["target"]=="release_debug"): @@ -126,11 +126,22 @@ def configure(env): env.ParseConfig('pkg-config x11 --cflags --libs') env.ParseConfig('pkg-config xinerama --cflags --libs') env.ParseConfig('pkg-config xcursor --cflags --libs') - env.ParseConfig('pkg-config openssl --cflags --libs') + + if (env["openssl"]=="yes"): + env.ParseConfig('pkg-config openssl --cflags --libs') + + + if (env["freetype"]=="yes"): + env.ParseConfig('pkg-config freetype2 --cflags --libs') + + + if (env["freetype"]!="no"): + env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) + if (env["freetype"]=="builtin"): + env.Append(CPPPATH=['#tools/freetype']) + env.Append(CPPPATH=['#tools/freetype/freetype/include']) - env.ParseConfig('pkg-config freetype2 --cflags --libs') - env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) env.Append(CPPFLAGS=['-DOPENGL_ENABLED','-DGLEW_ENABLED']) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 67ec33f3a3..74ebad748a 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -34,6 +34,7 @@ #include <stdlib.h> #include "print_string.h" #include "servers/physics/physics_server_sw.h" +#include "errno.h" #include "X11/Xutil.h" @@ -72,20 +73,18 @@ #undef CursorShape int OS_X11::get_video_driver_count() const { - return 1; } -const char * OS_X11::get_video_driver_name(int p_driver) const { +const char * OS_X11::get_video_driver_name(int p_driver) const { return "GLES2"; } -OS::VideoMode OS_X11::get_default_video_mode() const { +OS::VideoMode OS_X11::get_default_video_mode() const { return OS::VideoMode(800,600,false); } int OS_X11::get_audio_driver_count() const { - return AudioDriverManagerSW::get_driver_count(); } @@ -152,6 +151,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XFree (xim_styles); } + XFree( imvalret ); } /* @@ -255,7 +255,6 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi } #endif - AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); audio_driver_index=p_audio_driver; @@ -266,6 +265,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi for(int i=0;i<AudioDriverManagerSW::get_driver_count();i++) { if (i==p_audio_driver) continue; + AudioDriverManagerSW::get_driver(i)->set_singleton(); if (AudioDriverManagerSW::get_driver(i)->init()==OK) { success=true; print_line("Audio Driver Failed: "+String(AudioDriverManagerSW::get_driver(p_audio_driver)->get_name())); @@ -317,8 +317,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi /* set the name and class hints for the window manager to use */ classHint = XAllocClassHint(); if (classHint) { - classHint->res_name = "Godot"; - classHint->res_class = "Godot"; + classHint->res_name = (char *)"Godot"; + classHint->res_class = (char *)"Godot"; } XSetClassHint(x11_display, x11_window, classHint); XFree(classHint); @@ -349,6 +349,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi for(int i=0;i<CURSOR_MAX;i++) { cursors[i]=None; + img[i]=NULL; } current_cursor=CURSOR_ARROW; @@ -377,16 +378,15 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi "question_arrow" }; - XcursorImage *img = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size); - if (img) { - cursors[i]=XcursorImageLoadCursor(x11_display,img); + img[i] = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size); + if (img[i]) { + cursors[i]=XcursorImageLoadCursor(x11_display,img[i]); //print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i])); } else { if (OS::is_stdout_verbose()) print_line("failed cursor: "+String(cursor_file[i])); } } - } @@ -397,9 +397,9 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XColor col; Cursor cursor; - cursormask = XCreatePixmap(x11_display, RootWindow(x11_display,DefaultScreen(x11_display)), 1, 1, 1); - xgc.function = GXclear; - gc = XCreateGC(x11_display, cursormask, GCFunction, &xgc); + cursormask = XCreatePixmap(x11_display, RootWindow(x11_display,DefaultScreen(x11_display)), 1, 1, 1); + xgc.function = GXclear; + gc = XCreateGC(x11_display, cursormask, GCFunction, &xgc); XFillRectangle(x11_display, cursormask, gc, 0, 0, 1, 1); col.pixel = 0; col.red = 0; @@ -426,7 +426,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi // physics_server = memnew( PhysicsServerSW ); physics_server->init(); - physics_2d_server = memnew( Physics2DServerSW ); + //physics_2d_server = memnew( Physics2DServerSW ); + physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>(); physics_2d_server->init(); input = memnew( InputDefault ); @@ -434,13 +435,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi probe_joystick(); _ensure_data_dir(); - - net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False); - - - //printf("got map notify\n"); - } + void OS_X11::finalize() { if(main_loop) @@ -456,9 +452,10 @@ void OS_X11::finalize() { // memdelete(debugger_connection_console); //} + memdelete(sample_manager); + audio_server->finish(); memdelete(audio_server); - memdelete(sample_manager); visual_server->finish(); memdelete(visual_server); @@ -472,14 +469,26 @@ void OS_X11::finalize() { memdelete(input); + XUnmapWindow( x11_display, x11_window ); + XDestroyWindow( x11_display, x11_window ); + #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) memdelete(context_gl); #endif - + for(int i=0;i<CURSOR_MAX;i++) { + if( cursors[i] != None ) + XFreeCursor( x11_display, cursors[i] ); + if( img[i] != NULL ) + XcursorImageDestroy( img[i] ); + }; + + XDestroyIC( xic ); + XCloseIM( xim ); XCloseDisplay(x11_display); if (xmbstring) memfree(xmbstring); + args.clear(); } @@ -501,6 +510,23 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) { mouse_mode=p_mode; if (mouse_mode==MOUSE_MODE_CAPTURED) { + + while(true) { + //flush pending motion events + + if (XPending(x11_display) > 0) { + XEvent event; + XPeekEvent(x11_display, &event); + if (event.type==MotionNotify) { + XNextEvent(x11_display,&event); + } else { + break; + } + } else { + break; + } + } + if (XGrabPointer(x11_display, x11_window, True, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, @@ -515,6 +541,8 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) { 0,0,0,0, (int)center.x, (int)center.y); input->set_mouse_pos(center); + } else { + do_mouse_warp=false; } } @@ -536,37 +564,29 @@ void OS_X11::warp_mouse_pos(const Point2& p_to) { } OS::MouseMode OS_X11::get_mouse_mode() const { - return mouse_mode; } - - int OS_X11::get_mouse_button_state() const { return last_button_state; } Point2 OS_X11::get_mouse_pos() const { - return last_mouse_pos; } void OS_X11::set_window_title(const String& p_title) { - XStoreName(x11_display,x11_window,p_title.utf8().get_data()); } void OS_X11::set_video_mode(const VideoMode& p_video_mode,int p_screen) { - - } -OS::VideoMode OS_X11::get_video_mode(int p_screen) const { +OS::VideoMode OS_X11::get_video_mode(int p_screen) const { return current_videomode; } -void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const { - +void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const { } //#ifdef NEW_WM_API @@ -652,14 +672,20 @@ Point2 OS_X11::get_screen_position(int p_screen) const { // Using Xinerama Extension int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); - if( !ext_okay ) return Point2i(0,0); + if( !ext_okay ) { + return Point2i(0,0); + } int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); - if( p_screen >= count ) return Point2i(0,0); + if( p_screen >= count ) { + return Point2i(0,0); + } Point2i position = Point2i(xsi[p_screen].x_org, xsi[p_screen].y_org); + XFree(xsi); + return position; } @@ -677,7 +703,6 @@ Size2 OS_X11::get_screen_size(int p_screen) const { XFree(xsi); return size; } - Point2 OS_X11::get_window_position() const { int x,y; @@ -693,6 +718,7 @@ Point2 OS_X11::get_window_position() const { void OS_X11::set_window_position(const Point2& p_position) { // Using EWMH -- Extended Window Manager Hints // to get the size of the decoration +#if 0 Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); Atom type; int format; @@ -735,6 +761,9 @@ void OS_X11::set_window_position(const Point2& p_position) { top -= screen_position.y; XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); +#else + XMoveWindow(x11_display,x11_window,p_position.x,p_position.y); +#endif } Size2 OS_X11::get_window_size() const { @@ -750,8 +779,6 @@ void OS_X11::set_window_size(const Size2 p_size) { void OS_X11::set_window_fullscreen(bool p_enabled) { set_wm_fullscreen(p_enabled); current_videomode.fullscreen = p_enabled; - - visual_server->init(); } bool OS_X11::is_window_fullscreen() const { @@ -857,7 +884,12 @@ void OS_X11::set_window_maximized(bool p_enabled) { xev.xclient.data.l[2] = wm_max_vert; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); - +/* sorry this does not fix it, fails on multi monitor + XWindowAttributes xwa; + XGetWindowAttributes(x11_display,DefaultRootWindow(x11_display),&xwa); + current_videomode.width = xwa.width; + current_videomode.height = xwa.height; +*/ maximized = p_enabled; } @@ -954,7 +986,6 @@ unsigned int OS_X11::get_mouse_button_state(unsigned int p_x11_state) { } void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { - // X11 functions don't know what const is XKeyEvent *xkeyevent = p_event; @@ -1120,15 +1151,13 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { //printf("key: %x\n",event.key.scancode); input->parse_input_event( event); - - } void OS_X11::process_xevents() { //printf("checking events %i\n", XPending(x11_display)); - bool do_mouse_warp=false; + do_mouse_warp=false; while (XPending(x11_display) > 0) { XEvent event; @@ -1147,13 +1176,26 @@ void OS_X11::process_xevents() { XVisibilityEvent * visibility = (XVisibilityEvent *)&event; minimized = (visibility->state == VisibilityFullyObscured); } break; + case LeaveNotify: { + + if (main_loop && mouse_mode!=MOUSE_MODE_CAPTURED) + main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_EXIT); + if (input) + input->set_mouse_in_window(false); + + } break; + case EnterNotify: { - case FocusIn: + if (main_loop && mouse_mode!=MOUSE_MODE_CAPTURED) + main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER); + if (input) + input->set_mouse_in_window(true); + } break; + case FocusIn: minimized = false; #ifdef NEW_WM_API if(current_videomode.fullscreen) { set_wm_fullscreen(true); - visual_server->init(); } #endif main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN); @@ -1170,7 +1212,6 @@ void OS_X11::process_xevents() { if(current_videomode.fullscreen) { set_wm_fullscreen(false); set_window_minimized(true); - visual_server->init(); } #endif main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); @@ -1241,8 +1282,38 @@ void OS_X11::process_xevents() { } break; case MotionNotify: { - + + // FUCK YOU X11 API YOU SERIOUSLY GROSS ME OUT + // YOU ARE AS GROSS AS LOOKING AT A PUTRID PILE + // OF POOP STICKING OUT OF A CLOGGED TOILET + // HOW THE FUCK I AM SUPPOSED TO KNOW WHICH ONE + // OF THE MOTION NOTIFY EVENTS IS THE ONE GENERATED + // BY WARPING THE MOUSE POINTER? + // YOU ARE FORCING ME TO FILTER ONE BY ONE TO FIND IT + // PLEASE DO ME A FAVOR AND DIE DROWNED IN A FECAL + // MOUNTAIN BECAUSE THAT'S WHERE YOU BELONG. + + while(true) { + if (mouse_mode==MOUSE_MODE_CAPTURED && event.xmotion.x==current_videomode.width/2 && event.xmotion.y==current_videomode.height/2) { + //this is likely the warp event since it was warped here + center=Vector2(event.xmotion.x,event.xmotion.y); + break; + } + + if (XPending(x11_display) > 0) { + XEvent tevent; + XPeekEvent(x11_display, &tevent); + if (tevent.type==MotionNotify) { + XNextEvent(x11_display,&event); + } else { + break; + } + } else { + break; + } + } + last_timestamp=event.xmotion.time; // Motion is also simple. @@ -1781,7 +1852,6 @@ void OS_X11::set_cursor_shape(CursorShape p_shape) { XDefineCursor(x11_display,x11_window,cursors[CURSOR_ARROW]); } - current_cursor=p_shape; } @@ -1802,8 +1872,20 @@ void OS_X11::swap_buffers() { context_gl->swap_buffers(); } +void OS_X11::alert(const String& p_alert,const String& p_title) { + + List<String> args; + args.push_back("-center"); + args.push_back("-title"); + args.push_back(p_title); + args.push_back(p_alert); + + execute("/usr/bin/xmessage",args,true); +} void OS_X11::set_icon(const Image& p_icon) { + Atom net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False); + if (!p_icon.empty()) { Image img=p_icon; img.convert(Image::FORMAT_RGBA); @@ -1836,7 +1918,6 @@ void OS_X11::set_icon(const Image& p_icon) { XDeleteProperty(x11_display, x11_window, net_wm_icon); } XFlush(x11_display); - } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 0036485f3f..ed61df8f0e 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -45,6 +45,8 @@ #include "drivers/alsa/audio_driver_alsa.h" #include "drivers/pulseaudio/audio_driver_pulseaudio.h" #include "servers/physics_2d/physics_2d_server_sw.h" +#include "servers/physics_2d/physics_2d_server_wrap_mt.h" +#include "main/input_default.h" #include <X11/keysym.h> #include <X11/Xlib.h> @@ -113,9 +115,11 @@ class OS_X11 : public OS_Unix { bool minimized; int dpad_last[2]; + bool do_mouse_warp; const char *cursor_theme; int cursor_size; + XcursorImage *img[CURSOR_MAX]; Cursor cursors[CURSOR_MAX]; Cursor null_cursor; CursorShape current_cursor; @@ -152,12 +156,7 @@ class OS_X11 : public OS_Unix { }; }; }; - - Atom net_wm_icon; - - int joystick_count; - Joystick joysticks[JOYSTICKS_MAX]; int audio_driver_index; @@ -241,7 +240,7 @@ public: virtual bool is_window_maximized() const; virtual void move_window_to_foreground(); - + virtual void alert(const String& p_alert,const String& p_title="ALERT!"); void run(); OS_X11(); |