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; }
Q_DECL_EXPORT void kcminit_mouse() { KConfig *config = new KConfig("kcminputrc", KConfig::NoGlobals ); MouseSettings settings; settings.load(config); settings.apply(true); // force #ifdef HAVE_XCURSOR KConfigGroup group = config->group("Mouse"); QString theme = group.readEntry("cursorTheme", QString()); QString size = group.readEntry("cursorSize", QString()); // Note: If you update this code, update kapplymousetheme as well. // use a default value for theme only if it's not configured at all, not even in X resources if( theme.isEmpty() && QByteArray( XGetDefault( QX11Info::display(), "Xcursor", "theme" )).isEmpty() && QByteArray( XcursorGetTheme( QX11Info::display())).isEmpty()) { theme = "default"; } // Apply the KDE cursor theme to ourselves if( !theme.isEmpty()) XcursorSetTheme(QX11Info::display(), QFile::encodeName(theme)); if (!size.isEmpty()) XcursorSetDefaultSize(QX11Info::display(), size.toUInt()); // Load the default cursor from the theme and apply it to the root window. Cursor handle = XcursorLibraryLoadCursor(QX11Info::display(), "left_ptr"); XDefineCursor(QX11Info::display(), QX11Info::appRootWindow(), handle); XFreeCursor(QX11Info::display(), handle); // Don't leak the cursor // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment // variables when launching applications. OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QDBusConnection::sessionBus()); if(!theme.isEmpty()) klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), theme); if( !size.isEmpty()) klauncher.setLaunchEnv(QStringLiteral("XCURSOR_SIZE"), size); #endif delete config; }
int CursorThemeModel::current() { // Get the name of the theme libXcursor currently uses QString currentTheme; if (QX11Info::isPlatformX11()) { currentTheme = XcursorGetTheme(QX11Info::display()); } // Get the name of the theme KDE is configured to use KConfig c(QStringLiteral("kcminputrc")); KConfigGroup cg(&c, "Mouse"); currentTheme = cg.readEntry("cursorTheme", currentTheme); return findIndex(currentTheme).row(); }
int main( int argc, char* argv[] ) { if( argc != 3 ) return 1; dpy = XOpenDisplay( NULL ); if( dpy == NULL ) return 2; int ret = 0; #ifdef HAVE_XCURSOR const char* theme = argv[ 1 ]; const char* size = argv[ 2 ]; // Note: If you update this code, update kapplymousetheme as well. // use a default value for theme only if it's not configured at all, not even in X resources if( isEmpty( theme ) && isEmpty( XGetDefault( trinity_qt_xdisplay(), "Xcursor", "theme" )) && isEmpty( XcursorGetTheme( trinity_qt_xdisplay()))) { theme = "default"; ret = 10; // means to switch to default } // Apply the KDE cursor theme to ourselves if( !isEmpty( theme )) XcursorSetTheme(trinity_qt_xdisplay(), theme ); if (!isEmpty( size )) XcursorSetDefaultSize(trinity_qt_xdisplay(), atoi( size )); // Load the default cursor from the theme and apply it to the root window. Cursor handle = XcursorLibraryLoadCursor(trinity_qt_xdisplay(), "left_ptr"); XDefineCursor(trinity_qt_xdisplay(), trinity_qt_xrootwin(), handle); XFreeCursor(trinity_qt_xdisplay(), handle); // Don't leak the cursor #else ( void ) trinity_qt_xdisplay(); ( void ) trinity_qt_xrootwin(); ( void ) argv; #endif XCloseDisplay( dpy ); return ret; }
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; }
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"); }
Q_DECL_EXPORT void kcminit_mouse() { KConfig *config = new KConfig("kcminputrc", KConfig::NoGlobals ); Display *dpy = nullptr; const bool platformX11 = QX11Info::isPlatformX11(); if (platformX11) { dpy = QX11Info::display(); } else { // let's hope we have a compatibility system like Xwayland ready dpy = XOpenDisplay(nullptr); } MouseSettings settings; settings.load(config, dpy); settings.apply(true); // force #ifdef HAVE_XCURSOR KConfigGroup group = config->group("Mouse"); QString theme = group.readEntry("cursorTheme", QString()); QString size = group.readEntry("cursorSize", QString()); // Note: If you update this code, update kapplymousetheme as well. // use a default value for theme only if it's not configured at all, not even in X resources if( theme.isEmpty() && (!dpy || (QByteArray( XGetDefault( dpy, "Xcursor", "theme" )).isEmpty() && QByteArray( XcursorGetTheme( dpy)).isEmpty()))) { theme = "breeze_cursors"; } // Apply the KDE cursor theme to ourselves if (dpy) { if( !theme.isEmpty()) XcursorSetTheme(dpy, QFile::encodeName(theme)); if (!size.isEmpty()) XcursorSetDefaultSize(dpy, size.toUInt()); // Load the default cursor from the theme and apply it to the root window. Cursor handle = XcursorLibraryLoadCursor(dpy, "left_ptr"); XDefineCursor(dpy, QX11Info::appRootWindow(), handle); XFreeCursor(dpy, handle); // Don't leak the cursor } // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment // variables when launching applications. OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QDBusConnection::sessionBus()); if(!theme.isEmpty()) klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), theme); if( !size.isEmpty()) klauncher.setLaunchEnv(QStringLiteral("XCURSOR_SIZE"), size); #endif if (!platformX11) { XFlush(dpy); XCloseDisplay(dpy); } delete config; }