Cursor XcursorLibraryLoadCursor (Display *dpy, const char *file) { int size = XcursorGetDefaultSize (dpy); char *theme = XcursorGetTheme (dpy); XcursorImages *images = XcursorLibraryLoadImages (file, theme, size); Cursor cursor; if (!file) return 0; if (!images) { int id = XcursorLibraryShape (file); if (id >= 0) return _XcursorCreateFontCursor (dpy, id); else return 0; } cursor = XcursorImagesLoadCursor (dpy, images); XcursorImagesDestroy (images); #if defined HAVE_XFIXES && XFIXES_MAJOR >= 2 XFixesSetCursorName (dpy, cursor, file); #endif return cursor; }
void StartupId::update_startupid() { int yoffset = 0; if( blinking ) { XSetWindowBackgroundPixmap( QX11Info::display(), startup_window, pixmaps[ color_to_pixmap[ color_index ]].handle()); XClearWindow( QX11Info::display(), startup_window ); if( ++color_index >= ( sizeof( color_to_pixmap ) / sizeof( color_to_pixmap[ 0 ] ))) color_index = 0; } else if( bouncing ) { yoffset = frame_to_yoffset[ frame ]; QPixmap pixmap = pixmaps[ frame_to_pixmap[ frame ] ]; XSetWindowBackgroundPixmap( QX11Info::display(), startup_window, pixmap.handle()); XClearWindow( QX11Info::display(), startup_window ); if ( !pixmap.mask().isNull() ) // set mask XShapeCombineMask( QX11Info::display(), startup_window, ShapeBounding, 0, 0, pixmap.mask().handle(), ShapeSet ); else // clear mask XShapeCombineMask( QX11Info::display(), startup_window, ShapeBounding, 0, 0, None, ShapeSet ); if ( ++frame >= ( sizeof( frame_to_yoffset ) / sizeof( frame_to_yoffset[ 0 ] ) ) ) frame = 0; } Window dummy1, dummy2; int x, y; int dummy3, dummy4; unsigned int dummy5; if( !XQueryPointer( QX11Info::display(), QX11Info::appRootWindow(), &dummy1, &dummy2, &x, &y, &dummy3, &dummy4, &dummy5 )) { XUnmapWindow( QX11Info::display(), startup_window ); update_timer.start( 100 ); return; } QPoint c_pos( x, y ); int cursor_size = 0; #ifdef HAVE_XCURSOR cursor_size = XcursorGetDefaultSize( QX11Info::display()); #endif int X_DIFF; if( cursor_size <= 16 ) X_DIFF = 8 + 7; else if( cursor_size <= 32 ) X_DIFF = 16 + 7; else if( cursor_size <= 48 ) X_DIFF = 24 + 7; else X_DIFF = 32 + 7; int Y_DIFF = X_DIFF; XMoveWindow( QX11Info::display(), startup_window, c_pos.x() + X_DIFF, c_pos.y() + Y_DIFF + yoffset ); XMapWindow( QX11Info::display(), startup_window ); XRaiseWindow( QX11Info::display(), startup_window ); update_timer.start( bouncing ? 30 : 100 ); QApplication::flush(); }
void StartupId::update_startupid() { int yoffset = 0; if( blinking ) { startup_widget->setBackgroundPixmap( pixmaps[ color_to_pixmap[ color_index ]] ); if( ++color_index >= ( sizeof( color_to_pixmap ) / sizeof( color_to_pixmap[ 0 ] ))) color_index = 0; } else if( bouncing ) { yoffset = frame_to_yoffset[ frame ]; QPixmap pm = pixmaps[ frame_to_pixmap[ frame ] ]; startup_widget->setBackgroundPixmap( pm ); if ( pm.mask() != NULL ) startup_widget->setMask( *pm.mask() ); else startup_widget->clearMask(); if ( ++frame >= ( sizeof( frame_to_yoffset ) / sizeof( frame_to_yoffset[ 0 ] ) ) ) frame = 0; } Window dummy1, dummy2; int x, y; int dummy3, dummy4; unsigned int dummy5; if( !XQueryPointer( qt_xdisplay(), qt_xrootwin(), &dummy1, &dummy2, &x, &y, &dummy3, &dummy4, &dummy5 )) { startup_widget->hide(); update_timer.start( 100, true ); return; } QPoint c_pos( x, y ); int cursor_size = 0; #ifdef HAVE_XCURSOR cursor_size = XcursorGetDefaultSize( qt_xdisplay()); #endif int X_DIFF; if( cursor_size <= 16 ) X_DIFF = 8 + 7; else if( cursor_size <= 32 ) X_DIFF = 16 + 7; else if( cursor_size <= 48 ) X_DIFF = 24 + 7; else X_DIFF = 32 + 7; int Y_DIFF = X_DIFF; if( startup_widget->x() != c_pos.x() + X_DIFF || startup_widget->y() != c_pos.y() + Y_DIFF + yoffset ) startup_widget->move( c_pos.x() + X_DIFF, c_pos.y() + Y_DIFF + yoffset ); startup_widget->show(); XRaiseWindow( qt_xdisplay(), startup_widget->winId()); update_timer.start( bouncing ? 30 : 100, true ); QApplication::flushX(); }
QImage XCursorThemeData::loadImage (const QString &name, int size) const { if (size == -1) size = XcursorGetDefaultSize(QX11Info::display()); // Load the image XcursorImage *xcimage = xcLoadImage(name, size); if (!xcimage) xcimage = xcLoadImage(findAlternative(name), size); // Fall back to a legacy cursor //if (!xcimage) return LegacyTheme::loadImage(name); if (!xcimage) return QImage(); // Convert the XcursorImage to a QImage, and auto-crop it QImage image((uchar *)xcimage->pixels, xcimage->width, xcimage->height, QImage::Format_ARGB32_Premultiplied); image = autoCropImage(image); XcursorImageDestroy(xcimage); return image; }
QCursor XCursorThemeData::loadCursor (const QString &name, int size) const { if (size == -1) size = XcursorGetDefaultSize(QX11Info::display()); // Load the cursor images XcursorImages *images = xcLoadImages(name, size); if (!images) images = xcLoadImages(findAlternative(name), size); // Fall back to a legacy cursor //if (!images) return LegacyTheme::loadCursor(name); if (!images) return false; // Create the cursor Cursor handle = XcursorImagesLoadCursor(QX11Info::display(), images); QCursor cursor = QCursor(Qt::HANDLE(handle)); // QCursor takes ownership of the handle XcursorImagesDestroy(images); //setCursorName(cursor, name); return cursor; }
XcursorCursors * XcursorLibraryLoadCursors (Display *dpy, const char *file) { int size = XcursorGetDefaultSize (dpy); char *theme = XcursorGetTheme (dpy); XcursorImages *images = XcursorLibraryLoadImages (file, theme, size); XcursorCursors *cursors; if (!file) return NULL; if (!images) { int id = XcursorLibraryShape (file); if (id >= 0) { cursors = XcursorCursorsCreate (dpy, 1); if (cursors) { cursors->cursors[0] = _XcursorCreateFontCursor (dpy, id); if (cursors->cursors[0] == None) { XcursorCursorsDestroy (cursors); cursors = NULL; } else cursors->ncursor = 1; } } else cursors = NULL; } else { cursors = XcursorImagesLoadCursors (dpy, images); XcursorImagesDestroy (images); } return cursors; }
QImage XCursorImage::image (int size) const { if (size == -1) size = XcursorGetDefaultSize(QX11Info::display()); if (!mImage) return QImage(); return mImage->copy(); }
void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { last_button_state=0; dpad_last[0]=0; dpad_last[1]=0; xmbstring=NULL; event_id=0; x11_window=0; last_click_ms=0; args=OS::get_singleton()->get_cmdline_args(); current_videomode=p_desired; main_loop=NULL; last_timestamp=0; last_mouse_pos_valid=false; last_keyrelease_time=0; if (get_render_thread_mode()==RENDER_SEPARATE_THREAD) { XInitThreads(); } /** XLIB INITIALIZATION **/ x11_display = XOpenDisplay(NULL); char * modifiers = XSetLocaleModifiers ("@im=none"); ERR_FAIL_COND( modifiers == NULL ); xim = XOpenIM (x11_display, NULL, NULL, NULL); if (xim == NULL) { WARN_PRINT("XOpenIM failed"); xim_style=NULL; } else { ::XIMStyles *xim_styles=NULL; xim_style=0; char *imvalret=NULL; imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL); if (imvalret != NULL || xim_styles == NULL) { fprintf (stderr, "Input method doesn't support any styles\n"); } if (xim_styles) { xim_style = 0; for (int i=0;i<xim_styles->count_styles;i++) { if (xim_styles->supported_styles[i] == (XIMPreeditNothing | XIMStatusNothing)) { xim_style = xim_styles->supported_styles[i]; break; } } XFree (xim_styles); } } /* char* windowid = getenv("GODOT_WINDOWID"); if (windowid) { //freopen("/home/punto/stdout", "w", stdout); //reopen("/home/punto/stderr", "w", stderr); x11_window = atol(windowid); XWindowAttributes xwa; XGetWindowAttributes(x11_display,x11_window,&xwa); current_videomode.width = xwa.width; current_videomode.height = xwa.height; }; */ // maybe contextgl wants to be in charge of creating the window //print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height)); #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); context_gl->initialize(); if (true) { rasterizer = memnew( RasterizerGLES2 ); } else { //rasterizer = memnew( RasterizerGLES1 ); }; #endif visual_server = memnew( VisualServerRaster(rasterizer) ); if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) { visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); } // borderless fullscreen window mode if (current_videomode.fullscreen) { // needed for lxde/openbox, possibly others Hints hints; Atom property; hints.flags = 2; hints.decorations = 0; property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); XWindowAttributes xwa; XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); // code for netwm-compliants XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); Atom fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); memset(&xev, 0, sizeof(xev)); xev.type = ClientMessage; xev.xclient.window = x11_window; xev.xclient.message_type = wm_state; xev.xclient.format = 32; xev.xclient.data.l[0] = 1; xev.xclient.data.l[1] = fullscreen; xev.xclient.data.l[2] = 0; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); } // disable resizeable window if (!current_videomode.resizable) { XSizeHints *xsh; xsh = XAllocSizeHints(); xsh->flags = PMinSize | PMaxSize; XWindowAttributes xwa; if (current_videomode.fullscreen) { XGetWindowAttributes(x11_display,DefaultRootWindow(x11_display),&xwa); } else { XGetWindowAttributes(x11_display,x11_window,&xwa); } xsh->min_width = xwa.width; xsh->max_width = xwa.width; xsh->min_height = xwa.height; xsh->max_height = xwa.height; XSetWMNormalHints(x11_display, x11_window, xsh); } AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { ERR_PRINT("Initializing audio failed."); } sample_manager = memnew( SampleManagerMallocSW ); audio_server = memnew( AudioServerSW(sample_manager) ); audio_server->init(); spatial_sound_server = memnew( SpatialSoundServerSW ); spatial_sound_server->init(); spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); spatial_sound_2d_server->init(); ERR_FAIL_COND(!visual_server); ERR_FAIL_COND(x11_window==0); XSetWindowAttributes new_attr; new_attr.event_mask=KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask | ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask | PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask; XChangeWindowAttributes(x11_display, x11_window,CWEventMask,&new_attr); XClassHint* classHint; /* set the titlebar name */ XStoreName(x11_display, x11_window, "Godot"); /* set the name and class hints for the window manager to use */ classHint = XAllocClassHint(); if (classHint) { classHint->res_name = "Godot"; classHint->res_class = "Godot"; } XSetClassHint(x11_display, x11_window, classHint); XFree(classHint); wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true); XSetWMProtocols(x11_display, x11_window, &wm_delete, 1); if (xim && xim_style) { xic = XCreateIC (xim,XNInputStyle, xim_style,XNClientWindow,x11_window,XNFocusWindow, x11_window, (char*)NULL); } else { xic=NULL; WARN_PRINT("XCreateIC couldn't create xic"); } XcursorSetTheme(x11_display,"default"); cursor_size = XcursorGetDefaultSize(x11_display); cursor_theme = XcursorGetTheme(x11_display); if (!cursor_theme) { print_line("not found theme"); cursor_theme="default"; } for(int i=0;i<CURSOR_MAX;i++) { cursors[i]=None; } current_cursor=CURSOR_ARROW; if (cursor_theme) { //print_line("cursor theme: "+String(cursor_theme)); for(int i=0;i<CURSOR_MAX;i++) { static const char *cursor_file[]={ "left_ptr", "xterm", "hand2", "cross", "watch", "left_ptr_watch", "fleur", "hand1", "X_cursor", "sb_v_double_arrow", "sb_h_double_arrow", "size_bdiag", "size_fdiag", "hand1", "sb_v_double_arrow", "sb_h_double_arrow", "question_arrow" }; XcursorImage *img = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size); if (img) { cursors[i]=XcursorImageLoadCursor(x11_display,img); //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])); } } } { Pixmap cursormask; XGCValues xgc; GC gc; 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); XFillRectangle(x11_display, cursormask, gc, 0, 0, 1, 1); col.pixel = 0; col.red = 0; col.flags = 4; cursor = XCreatePixmapCursor(x11_display, cursormask, cursormask, &col, &col, 0, 0); XFreePixmap(x11_display, cursormask); XFreeGC(x11_display, gc); if (cursor == None) { ERR_PRINT("FAILED CREATING CURSOR"); } null_cursor=cursor; } set_cursor_shape(CURSOR_BUSY); visual_server->init(); // physics_server = memnew( PhysicsServerSW ); physics_server->init(); physics_2d_server = memnew( Physics2DServerSW ); physics_2d_server->init(); input = memnew( InputDefault ); probe_joystick(); _ensure_data_dir(); net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False); //printf("got map notify\n"); }
void PreviewCursor::load(const QString &name, const QString &theme) { Display *dpy = QPaintDevice::x11AppDisplay(); if(m_pict) XRenderFreePicture(dpy, m_pict); if(m_handle) XFreeCursor(dpy, m_handle); m_pict = 0; m_handle = 0; m_width = m_height = 0; // Load the preview cursor image XcursorImage *image = XcursorLibraryLoadImage(name.latin1(), theme.latin1(), previewSize); // If the theme doesn't have this cursor, load the default cursor for now if(!image) image = XcursorLibraryLoadImage("left_ptr", theme.latin1(), previewSize); // TODO The old classic X cursors if(!image) return; // Auto-crop the image (some cursor themes use a fixed image size // for all cursors, and doing this results in correctly centered images) cropCursorImage(image); m_pict = createPicture(image); m_width = image->width; m_height = image->height; // Scale the image if its height is greater than 2x the requested size if(m_height > previewSize * 2.0) { double factor = double(previewSize * 2.0 / m_height); XTransform xform = {{{XDoubleToFixed(1.0), XDoubleToFixed(0), XDoubleToFixed(0)}, {XDoubleToFixed(0), XDoubleToFixed(1.0), XDoubleToFixed(0)}, {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(factor)}}}; XRenderSetPictureTransform(dpy, m_pict, &xform); m_width = int(m_width * factor); m_height = int(m_height * factor); } // We don't need this image anymore XcursorImageDestroy(image); // Load the actual cursor we will use int size = XcursorGetDefaultSize(dpy); XcursorImages *images = XcursorLibraryLoadImages(name.latin1(), theme.latin1(), size); if(images) { m_handle = XcursorImagesLoadCursor(dpy, images); XcursorImagesDestroy(images); } else { images = XcursorLibraryLoadImages("left_ptr", theme.latin1(), size); m_handle = XcursorImagesLoadCursor(dpy, images); XcursorImagesDestroy(images); } }