summaryrefslogtreecommitdiff
path: root/platform/x11/os_x11.cpp
diff options
context:
space:
mode:
authorAnton Yabchinskiy <arn@bestmx.ru>2015-11-02 20:25:01 +0300
committerAnton Yabchinskiy <arn@bestmx.ru>2015-11-02 20:25:01 +0300
commit3b9868d2e44740c03861c64020a8b5d4d6da031d (patch)
tree8ff5f9671122f946487848ce286d336c9b650c2c /platform/x11/os_x11.cpp
parentdc8df8a91a995796f0f330bf6bb6b209f6dfce08 (diff)
parentb2f9acb8c96aed0505cbac21661e21e4acef710f (diff)
Merge branch 'master' of github.com:okamstudio/godot
Diffstat (limited to 'platform/x11/os_x11.cpp')
-rw-r--r--platform/x11/os_x11.cpp167
1 files changed, 122 insertions, 45 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 1084d619e1..4c5b9793e3 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -74,20 +74,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();
}
@@ -154,6 +152,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
XFree (xim_styles);
}
+ XFree( imvalret );
}
/*
@@ -257,7 +256,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;
@@ -352,6 +350,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;
@@ -380,16 +379,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]));
}
}
-
}
@@ -400,9 +398,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;
@@ -438,13 +436,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)
@@ -476,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();
}
@@ -505,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,
@@ -519,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;
}
}
@@ -540,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
@@ -656,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;
}
@@ -681,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;
@@ -697,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;
@@ -739,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 {
@@ -754,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 {
@@ -861,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;
}
@@ -958,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;
@@ -1124,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;
@@ -1151,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);
@@ -1174,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);
@@ -1245,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.
@@ -1785,7 +1852,6 @@ void OS_X11::set_cursor_shape(CursorShape p_shape) {
XDefineCursor(x11_display,x11_window,cursors[CURSOR_ARROW]);
}
-
current_cursor=p_shape;
}
@@ -1806,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);
@@ -1840,7 +1918,6 @@ void OS_X11::set_icon(const Image& p_icon) {
XDeleteProperty(x11_display, x11_window, net_wm_icon);
}
XFlush(x11_display);
-
}