static void init() { int dummy; ENTER; if (!XkbQueryExtension(GDK_DISPLAY(), &dummy, &xkb_event_type, &dummy, &dummy, &dummy)) { ERR("no XKB extension\n"); exit(1); } XSetLocaleModifiers(""); XSetErrorHandler((XErrorHandler) Xerror_handler); dpy = GDK_DISPLAY(); if (chdir(IMGPREFIX)) { ERR("can't chdir to %s\n", IMGPREFIX); exit(1); } if (!(default_flag = get_flag("zz"))) { ERR("can't load default flag image\n"); exit(1); } XkbSelectEventDetails(dpy, XkbUseCoreKbd, XkbStateNotify, XkbAllStateComponentsMask, XkbGroupStateMask); gdk_window_add_filter(NULL, (GdkFilterFunc)filter, NULL); RET(); }
bool X11Window::internalSetupWindowInput() { // try to set a latin1 locales, otherwise fallback to standard C locale static char locales[4][32] = { "en_US.iso88591", "iso88591", "en_US", "C" }; for(int i=0;i<4;++i) { if(setlocale(LC_ALL, locales[i])) break; } // create input context (to have better key input handling) if(!XSupportsLocale()) { g_logger.error("X11 doesn't support the current locale"); return false; } XSetLocaleModifiers(""); m_xim = XOpenIM(m_display, NULL, NULL, NULL); if(!m_xim) { g_logger.error("XOpenIM failed"); return false; } m_xic = XCreateIC(m_xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_window, NULL); if(!m_xic) { g_logger.error("Unable to create the input context"); return false; } return true; }
/* Checking whether input method is running. */ bool rxvt_term::IMisRunning () { char *p; Atom atom; Window win; char server[IMBUFSIZ]; /* get current locale modifier */ if ((p = XSetLocaleModifiers (NULL)) != NULL) { strcpy (server, "@server="); strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ *p = '\0'; atom = XInternAtom (dpy, server, False); win = XGetSelectionOwner (dpy, atom); if (win != None) return True; } return False; }
void QXIMInputContext::init_xim() { #ifndef QT_NO_XIM if(!isInitXIM) isInitXIM = TRUE; bool codesetIsUtf8 = (QString::compare(nl_langinfo(CODESET), "UTF-8") == 0); if (!codesetIsUtf8) { setlocale(LC_CTYPE, "en_US.UTF-8"); } qt_xim = 0; QString ximServerName(qt_ximServer); if (qt_ximServer) ximServerName.prepend("@im="); else ximServerName = ""; if ( !XSupportsLocale() ) qWarning("Qt: Locales not supported on X server"); #ifdef USE_X11R6_XIM else if ( XSetLocaleModifiers (ximServerName.ascii()) == 0 ) qWarning( "Qt: Cannot set locale modifiers: %s", ximServerName.ascii()); else { Display *dpy = QPaintDevice::x11AppDisplay(); XWindowAttributes attr; // XIM unselects all events on the root window XGetWindowAttributes( dpy, QPaintDevice::x11AppRootWindow(), &attr ); XRegisterIMInstantiateCallback(dpy, 0, 0, 0, (XIMProc) xim_create_callback, 0); XSelectInput( dpy, QPaintDevice::x11AppRootWindow(), attr.your_event_mask ); } #else // !USE_X11R6_XIM else if ( XSetLocaleModifiers ("") == 0 )
QXIMInputContext::QXIMInputContext() { if (!qt_xim_preferred_style) // no configured input style, use the default qt_xim_preferred_style = xim_default_style; xim = 0; QByteArray ximServerName(qt_ximServer); if (qt_ximServer) ximServerName.prepend("@im="); else ximServerName = ""; if (!XSupportsLocale()) #ifndef QT_NO_DEBUG qWarning("Qt: Locale not supported on X server") #endif ; #ifdef USE_X11R6_XIM else if (XSetLocaleModifiers (ximServerName.constData()) == 0) qWarning("Qt: Cannot set locale modifiers: %s", ximServerName.constData()); else XRegisterIMInstantiateCallback(X11->display, 0, 0, 0, (XIMProc) xim_create_callback, reinterpret_cast<char *>(this)); #else // !USE_X11R6_XIM else if (XSetLocaleModifiers ("") == 0)
/* initialize info->im */ static void xim_info_try_im (GtkOXIMInfo *info) { GdkScreen *screen = info->screen; GdkDisplay *display = gdk_screen_get_display (screen); g_assert (info->im == NULL); if (info->reconnecting) return; if (XSupportsLocale ()) { if (!XSetLocaleModifiers ("@im=oxim")) g_warning ("Unable to set locale modifiers with XSetLocaleModifiers()"); info->im = XOpenIM (GDK_DISPLAY_XDISPLAY (display), NULL, NULL, NULL); if (!info->im) { XRegisterIMInstantiateCallback (GDK_DISPLAY_XDISPLAY(display), NULL, NULL, NULL, xim_instantiate_callback, (XPointer)info); info->reconnecting = TRUE; return; } setup_im (info); } }
static void InitI18N(Widget ctxw) { LoginWidget ctx = (LoginWidget)ctxw; XIM xim = (XIM) NULL; char *p; ctx->login.xic = (XIC) NULL; if ((p = XSetLocaleModifiers("@im=none")) != NULL && *p) xim = XOpenIM(XtDisplay(ctx), NULL, NULL, NULL); if (!xim) { LogError("Failed to open input method\n"); return; } ctx->login.xic = XCreateIC(xim, XNInputStyle, (XIMPreeditNothing|XIMStatusNothing), XNClientWindow, ctx->core.window, XNFocusWindow, ctx->core.window, NULL); if (!ctx->login.xic) { LogError("Failed to create input context\n"); XCloseIM(xim); } return; }
Blackbox::Blackbox(char **m_argv, const char *dpy_name, const std::string& rc, bool multi_head) : bt::Application(m_argv[0], dpy_name, multi_head), grab_count(0u), _resource(rc) { if (! XSupportsLocale()) fprintf(stderr, _("X server does not support locale\n")); if (XSetLocaleModifiers("") == NULL) fprintf(stderr, _("cannot set locale modifiers\n")); argv = m_argv; active_screen = 0; focused_window = (BlackboxWindow *) 0; _ewmh = (bt::EWMH*) 0; init_icccm(); if (! multi_head || display().screenCount() == 1) screen_list_count = 1; else screen_list_count = display().screenCount(); _resource.load(*this); screen_list = new BScreen*[screen_list_count]; unsigned int managed = 0; for (unsigned int i = 0; i < screen_list_count; ++i) { BScreen *screen = new BScreen(this, i); if (! screen->isScreenManaged()) { delete screen; continue; } screen_list[i] = screen; ++managed; } if (managed == 0) { fprintf(stderr, _("%s: no manageable screens found, exiting...\n"), applicationName().c_str()); ::exit(3); } screen_list_count = managed; // start with the first managed screen as the active screen setActiveScreen(screen_list[0]); XSynchronize(XDisplay(), false); XSync(XDisplay(), false); timer = new bt::Timer(this, this); timer->setTimeout(0l); }
/* * Class: sun_awt_X11_XlibWrapper * Method: XSetLocaleModifiers * Signature: (Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_sun_awt_X11_XlibWrapper_XSetLocaleModifiers (JNIEnv *env, jclass clazz, jstring jstr) { char * modifier_list = NULL; char * ret = NULL; if (!JNU_IsNull(env, jstr)) { modifier_list = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); } AWT_CHECK_HAVE_LOCK(); if (modifier_list) { ret = XSetLocaleModifiers(modifier_list); JNU_ReleaseStringPlatformChars(env, jstr, (const char *) modifier_list); } else { ret = XSetLocaleModifiers(""); } return (ret != NULL ? JNU_NewStringPlatform(env, ret): NULL); }
int _glfwPlatformInit(void) { // HACK: If the current locale is C, apply the environment's locale // This is done because the C locale breaks character input if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0) setlocale(LC_CTYPE, ""); XInitThreads(); _glfw.x11.display = XOpenDisplay(NULL); if (!_glfw.x11.display) { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to open X display"); return GL_FALSE; } _glfw.x11.screen = DefaultScreen(_glfw.x11.display); _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen); _glfw.x11.context = XUniqueContext(); if (!initExtensions()) return GL_FALSE; _glfw.x11.cursor = createNULLCursor(); if (XSupportsLocale()) { XSetLocaleModifiers(""); _glfw.x11.im = XOpenIM(_glfw.x11.display, 0, 0, 0); if (_glfw.x11.im) { if (!hasUsableInputMethodStyle()) { XCloseIM(_glfw.x11.im); _glfw.x11.im = NULL; } } } if (!_glfwInitContextAPI()) return GL_FALSE; if (!_glfwInitJoysticks()) return GL_FALSE; _glfwInitTimer(); return GL_TRUE; }
void Initialize_Locale (void) { char *locale; /* dverna - Nov. 98: #### DON'T DO THIS !!! The default XtLanguageProc routine calls setlocale(LC_ALL, lang) which f***s up our lower-level locale management, and especially the value of LC_NUMERIC. Anyway, since at this point, we don't know yet whether we're gonna need an X11 frame, we should really do it manually and not use Xlib's dumb default routine */ /*XtSetLanguageProc (NULL, (XtLanguageProc) NULL, NULL);*/ if ((locale = setlocale (LC_ALL, "")) == NULL) { stderr_out ("Can't set locale.\n"); stderr_out ("Using C locale instead.\n"); putenv ("LANG=C"); putenv ("LC_ALL=C"); if ((locale = setlocale (LC_ALL, "C")) == NULL) { stderr_out ("Can't even set locale to `C'!\n"); return; } } if (!XSupportsLocale ()) { stderr_out ("X Windows does not support locale `%s'\n", locale); stderr_out ("Using C Locale instead\n"); putenv ("LANG=C"); putenv ("LC_ALL=C"); if ((locale = setlocale (LC_ALL, "C")) == NULL) { stderr_out ("Can't even set locale to `C'!\n"); return; } if (!XSupportsLocale ()) { stderr_out ("X Windows does not even support locale `C'!\n"); return; } } setlocale(LC_NUMERIC, "C"); if (XSetLocaleModifiers ("") == NULL) { stderr_out ("XSetLocaleModifiers(\"\") failed\n"); stderr_out ("Check the value of the XMODIFIERS environment variable.\n"); } }
/*ARGSUSED*/ static String _XtDefaultLanguageProc( Display *dpy, /* unused */ String xnl, XtPointer closure) /* unused */ { if (! setlocale(LC_ALL, xnl)) XtWarning("locale not supported by C library, locale unchanged"); if (! XSupportsLocale()) { XtWarning("locale not supported by Xlib, locale set to C"); setlocale(LC_ALL, "C"); } if (! XSetLocaleModifiers("")) XtWarning("X locale modifiers not supported, using default"); return setlocale(LC_ALL, NULL); /* re-query in case overwritten */ }
void BrowserControl::init() { char* loc = setlocale(LC_ALL, ""); if (!loc) fprintf(stderr, "Could not use the the default environment locale\n"); if (!XSupportsLocale()) fprintf(stderr, "Default locale \"%s\" is no supported\n", loc ? loc : ""); // When changing the locale being used we must call XSetLocaleModifiers (refer to manpage). if (!XSetLocaleModifiers("")) fprintf(stderr, "Could not set locale modifiers for locale \"%s\"\n", loc ? loc : ""); m_display = XOpenDisplay(0); if (!m_display) fatalError("couldn't connect to X server\n"); m_context = XUniqueContext(); }
/*********************************************************************** * X11DRV_InitXIM * * Process-wide XIM initialization. */ BOOL X11DRV_InitXIM( const char *input_style ) { if (!strcasecmp(input_style, "offthespot")) ximStyleRequest = STYLE_OFFTHESPOT; else if (!strcasecmp(input_style, "overthespot")) ximStyleRequest = STYLE_OVERTHESPOT; else if (!strcasecmp(input_style, "root")) ximStyleRequest = STYLE_ROOT; if (!XSupportsLocale()) { WARN("X does not support locale.\n"); return FALSE; } if (XSetLocaleModifiers("") == NULL) { WARN("Could not set locale modifiers.\n"); return FALSE; } return TRUE; }
int main(int argc, char *argv[]) { setlocale(LC_CTYPE, ""); bindtextdomain(PROJECT_NAME, LOCALEDIR); textdomain(PROJECT_NAME); gtk_set_locale(); gtk_init(&argc, &argv); XSetLocaleModifiers(""); XSetErrorHandler((XErrorHandler) handle_error); fb_init(); do_argv(argc, argv); profile_file = g_build_filename(g_get_user_config_dir(), "fbpanel", profile, NULL); ensure_profile(); gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), IMGPREFIX); signal(SIGUSR1, sig_usr1); signal(SIGUSR2, sig_usr2); do { the_panel = p = g_new0(panel, 1); p->xc = xconf_new_from_file(profile_file, profile); if (!p->xc) exit(1); panel_start(p->xc); if (config) configure(p->xc); gtk_main(); panel_stop(p); //xconf_save_to_profile(cprofile, xc); xconf_del(p->xc, FALSE); g_free(p); DBG("force_quit=%d\n", force_quit); } while (force_quit == 0); g_free(profile_file); fb_free(); exit(0); }
bool X11Window::internalSetupWindowInput() { // create input context (to have better key input handling) if(!XSupportsLocale()) { g_logger.error("X11 doesn't support the current locale"); return false; } XSetLocaleModifiers(""); m_xim = XOpenIM(m_display, NULL, NULL, NULL); if(!m_xim) { g_logger.error("XOpenIM failed"); return false; } m_xic = XCreateIC(m_xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_window, NULL); if(!m_xic) { g_logger.error("Unable to create the input context"); return false; } return true; }
/*********************************************************************** * X11DRV_InitXIM * * Process-wide XIM initialization. */ BOOL X11DRV_InitXIM( const char *input_style ) { BOOL ret; if (!strcasecmp(input_style, "offthespot")) ximStyleRequest = STYLE_OFFTHESPOT; else if (!strcasecmp(input_style, "overthespot")) ximStyleRequest = STYLE_OVERTHESPOT; else if (!strcasecmp(input_style, "root")) ximStyleRequest = STYLE_ROOT; wine_tsx11_lock(); if (!(ret = XSupportsLocale())) { WARN("X does not support locale.\n"); } else if (XSetLocaleModifiers("") == NULL) { WARN("Could not set locale modifiers.\n"); ret = FALSE; } wine_tsx11_unlock(); return ret; }
int main(int argc, char **argv) { Display *display; int screen_num; Window win; //窗口ID unsigned int width, height; //窗口尺寸 unsigned int border_width = 4; //边界空白 unsigned int display_width, display_height;//屏幕尺寸 XEvent report; GC gc; unsigned long valuemask = 0; XGCValues values; char *display_name = NULL; Atom protocols; //edit int len = 127; unsigned char string[128], s_tab[ROW][127]; KeySym keysym; int row = 0, col = 0; int i, count = 0; Status status; //字体集 XFontSet fontset; char **missing_charsets; int num_missing_charsets; char *default_string; XFontSetExtents *fs_ext; int dec; //XIM XIM im; XIC ic; //overspot XRectangle spot, s_rect; XVaNestedList preedit_attr, status_attr; //设置locale if((setlocale(LC_ALL, "")) == NULL){ printf("cannot set locale\n"); exit(1); } //判断X是否支持locale if(!XSupportsLocale()){ printf("X does not support current locale\n"); exit(1); } //设置locale修饰 if(XSetLocaleModifiers(NULL)){ printf("Cannot set locale modifiers\n"); exit(1); } // 和X 服务器连接 if ( (display=XOpenDisplay(display_name)) == NULL ) { printf("Cannot connect to X server %s\n", XDisplayName(display_name)); exit(-1); } //获得缺省的 screen_num screen_num = DefaultScreen(display); //获得屏幕的宽度和高度 display_width = DisplayWidth(display, screen_num); display_height = DisplayHeight(display, screen_num); //建立字体集 fontset = XCreateFontSet(display, "8x16,-*-song-medium-r-normal--16-*-*-*-*-*-gb2312.1980-0", &missing_charsets, &num_missing_charsets, &default_string); if(num_missing_charsets > 0){ int i; printf("Following charsets are missing:\n"); for(i=0; i<num_missing_charsets; i++){ printf("Missing %d: %s\n", i, missing_charsets[i]); } printf("\nDefault string:%s\n", default_string); XFreeStringList(missing_charsets); } //字体的Extents fs_ext = XExtentsOfFontSet(fontset); dec = fs_ext->max_logical_extent.height + fs_ext->max_logical_extent.y; width = W_WIDTH; height = W_HEIGHT + dec; //建立窗口 win = XCreateSimpleWindow(display, //display RootWindow(display,screen_num), //父窗口 0, 0, width, height, //位置和大小 border_width, //边界宽度 BlackPixel(display,screen_num), //前景色 WhitePixel(display,screen_num));//背景色 //选择窗口感兴趣的事件掩码 XSelectInput(display, win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask); //建立GC gc = XCreateGC(display, win, valuemask, &values); protocols = XInternAtom(display, "WM_DELETE_WINDOW", True); XSetWMProtocols(display, win, &protocols, 1); //显示窗口 XMapWindow(display, win); //联接输入服务器 if((im = XOpenIM(display, NULL, NULL, NULL)) == NULL){ printf("Error : XOpenIM !\n"); exit(1); } //设置输入服务器的位置 spot.x = F_SIZE / 2 * col; spot.y = F_SIZE * (row + 1) - dec; preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, XNFontSet, fontset, NULL); s_rect.x = 0; s_rect.y = F_SIZE * ROW + dec + 2; s_rect.width = W_WIDTH; s_rect.height = F_SIZE; status_attr = XVaCreateNestedList(0, XNArea, &s_rect, XNFontSet, fontset, NULL); //建立IC if((ic = XCreateIC(im, XNInputStyle, XIMPreeditPosition | XIMStatusNothing, XNClientWindow, win, XNPreeditAttributes, preedit_attr, XNStatusAttributes, status_attr, NULL)) == NULL){ printf("Error : XCreateIC() ! \n"); XCloseIM(im); exit(0); } //释放内存 XFree(preedit_attr); XFree(status_attr); //写屏缓冲区初始化 for(i = 0; i < ROW; i++)s_tab[i][0] = 0; //进入事件循环 while (1) { //取得队列中的事件 XNextEvent(display, &report); //过滤事件 if(XFilterEvent(&report, None) == True) continue; switch (report.type) { //聚焦发声变化 case FocusIn: XSetICFocus(ic); break; case FocusOut: XUnsetICFocus(ic); break; //曝光事件, 窗口应重绘 case Expose: //取得最后一个曝光事件 if (report.xexpose.count != 0) break; for ( i=0; i < ROW; i++) XmbDrawString(display, win, fontset,gc, 0, F_SIZE * (i +1), s_tab[i], strlen(s_tab[i])); break; //窗口尺寸改变, 重新取得窗口的宽度和高度 case ConfigureNotify: width = report.xconfigure.width; height = report.xconfigure.height; break; //鼠标点击或有按键, 释放资源则退出 case KeyPress: count = XmbLookupString(ic, (XKeyPressedEvent *) &report, string, len, &keysym, &status); string[count] = 0; if (status == XLookupBoth&&keysym == XK_Return){ row = (++row) % ROW; col = 0; s_tab[row][0] = 0; XClearArea(display, win, 0, F_SIZE * row + dec, W_WIDTH, F_SIZE, False); } else if (status = XLookupChars || status == XLookupBoth){ XmbDrawString(display, win, fontset, gc, F_SIZE / 2 * col, F_SIZE * (row + 1), string, count); for (i = 0; i < count && col < len && string[i]; i++, col++) s_tab[row][col] = string[i]; s_tab[row][col] = 0; } //更新输入服务器位置 spot.x = F_SIZE / 2 * col; spot.y = F_SIZE * (row + 1); preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); XSetICValues(ic, XNPreeditAttributes, preedit_attr, NULL); XFree(preedit_attr); break; case ClientMessage: if (report.xclient.data.l[0] == protocols) { XDestroyIC(ic); XCloseIM(im); XDestroyWindow(display, win); XCloseDisplay(display); exit(0); } break; default: break; } } }
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"); }
/* Create auxiliary (toplevel) windows with the current visual */ static void create_aux_windows(_THIS) { int x = 0, y = 0; char classname[1024]; XSetWindowAttributes xattr; XWMHints *hints; unsigned long app_event_mask; int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen)); /* Look up some useful Atoms */ WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False); /* Don't create any extra windows if we are being managed */ if ( SDL_windowid ) { FSwindow = 0; WMwindow = SDL_strtol(SDL_windowid, NULL, 0); return; } if(FSwindow) XDestroyWindow(SDL_Display, FSwindow); #if SDL_VIDEO_DRIVER_X11_XINERAMA if ( use_xinerama ) { x = xinerama_info.x_org; y = xinerama_info.y_org; } #endif xattr.override_redirect = True; xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0; xattr.border_pixel = 0; xattr.colormap = SDL_XColorMap; FSwindow = XCreateWindow(SDL_Display, SDL_Root, x, y, 32, 32, 0, this->hidden->depth, InputOutput, SDL_Visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap, &xattr); XSelectInput(SDL_Display, FSwindow, StructureNotifyMask); /* Tell KDE to keep the fullscreen window on top */ { XEvent ev; long mask; SDL_memset(&ev, 0, sizeof(ev)); ev.xclient.type = ClientMessage; ev.xclient.window = SDL_Root; ev.xclient.message_type = XInternAtom(SDL_Display, "KWM_KEEP_ON_TOP", False); ev.xclient.format = 32; ev.xclient.data.l[0] = FSwindow; ev.xclient.data.l[1] = CurrentTime; mask = SubstructureRedirectMask; XSendEvent(SDL_Display, SDL_Root, False, mask, &ev); } hints = NULL; if(WMwindow) { /* All window attributes must survive the recreation */ hints = XGetWMHints(SDL_Display, WMwindow); XDestroyWindow(SDL_Display, WMwindow); } /* Create the window for windowed management */ /* (reusing the xattr structure above) */ WMwindow = XCreateWindow(SDL_Display, SDL_Root, x, y, 32, 32, 0, this->hidden->depth, InputOutput, SDL_Visual, CWBackPixel | CWBorderPixel | CWColormap, &xattr); /* Set the input hints so we get keyboard input */ if(!hints) { hints = XAllocWMHints(); hints->input = True; hints->flags = InputHint; } XSetWMHints(SDL_Display, WMwindow, hints); XFree(hints); X11_SetCaptionNoLock(this, this->wm_title, this->wm_icon); app_event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask | PropertyChangeMask | StructureNotifyMask | KeymapStateMask; XSelectInput(SDL_Display, WMwindow, app_event_mask); /* Set the class hints so we can get an icon (AfterStep) */ get_classname(classname, sizeof(classname)); { XClassHint *classhints; classhints = XAllocClassHint(); if(classhints != NULL) { classhints->res_name = classname; classhints->res_class = classname; XSetClassHint(SDL_Display, WMwindow, classhints); XFree(classhints); } } /* Setup the communication with the IM server */ /* create_aux_windows may be called several times against the same Display. We should reuse the SDL_IM if one has been opened for the Display, so we should not simply reset SDL_IM here. */ #ifdef X_HAVE_UTF8_STRING if (SDL_X11_HAVE_UTF8) { /* Discard obsolete resources if any. */ if (SDL_IM != NULL && SDL_Display != XDisplayOfIM(SDL_IM)) { /* Just a double check. I don't think this code is ever executed. */ SDL_SetError("display has changed while an IM is kept"); if (SDL_IC) { XUnsetICFocus(SDL_IC); XDestroyIC(SDL_IC); SDL_IC = NULL; } XCloseIM(SDL_IM); SDL_IM = NULL; } /* Open an input method. */ if (SDL_IM == NULL) { char *old_locale = NULL, *old_modifiers = NULL; const char *p; size_t n; /* I'm not comfortable to do locale setup here. However, we need C library locale (and xlib modifiers) to be set based on the user's preference to use XIM, and many existing game programs doesn't take care of users' locale preferences, so someone other than the game program should do it. Moreover, ones say that some game programs heavily rely on the C locale behaviour, e.g., strcol()'s, and we can't change the C library locale. Given the situation, I couldn't find better place to do the job... */ /* Save the current (application program's) locale settings. */ p = setlocale(LC_ALL, NULL); if ( p ) { n = SDL_strlen(p)+1; old_locale = SDL_stack_alloc(char, n); if ( old_locale ) { SDL_strlcpy(old_locale, p, n); } } p = XSetLocaleModifiers(NULL); if ( p ) { n = SDL_strlen(p)+1; old_modifiers = SDL_stack_alloc(char, n); if ( old_modifiers ) { SDL_strlcpy(old_modifiers, p, n); } } /* Fetch the user's preferences and open the input method with them. */ setlocale(LC_ALL, ""); XSetLocaleModifiers(""); SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname); /* Restore the application's locale settings so that we don't break the application's expected behaviour. */ if ( old_locale ) { /* We need to restore the C library locale first, since the interpretation of the X modifier may depend on it. */ setlocale(LC_ALL, old_locale); SDL_stack_free(old_locale); } if ( old_modifiers ) { XSetLocaleModifiers(old_modifiers); SDL_stack_free(old_modifiers); } } /* Create a new input context for the new window just created. */ if (SDL_IM == NULL) { SDL_SetError("no input method could be opened"); } else { if (SDL_IC != NULL) { /* Discard the old IC before creating new one. */ XUnsetICFocus(SDL_IC); XDestroyIC(SDL_IC); } /* Theoretically we should check the current IM supports PreeditNothing+StatusNothing style (i.e., root window method) before creating the IC. However, it is the bottom line method, and we supports any other options. If the IM didn't support root window method, the following call fails, and SDL falls back to pre-XIM keyboard handling. */ SDL_IC = pXCreateIC(SDL_IM, XNClientWindow, WMwindow, XNFocusWindow, WMwindow, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNResourceName, classname, XNResourceClass, classname, NULL); if (SDL_IC == NULL) { SDL_SetError("no input context could be created"); XCloseIM(SDL_IM); SDL_IM = NULL; } else { /* We need to receive X events that an IM wants and to pass them to the IM through XFilterEvent. The set of events may vary depending on the IM implementation and the options specified through various routes. Although unlikely, the xlib specification allows IM to change the event requirement with its own circumstances, it is safe to call SelectInput whenever we re-create an IC. */ unsigned long mask = 0; char *ret = pXGetICValues(SDL_IC, XNFilterEvents, &mask, NULL); if (ret != NULL) { XUnsetICFocus(SDL_IC); XDestroyIC(SDL_IC); SDL_IC = NULL; SDL_SetError("no input context could be created"); XCloseIM(SDL_IM); SDL_IM = NULL; } else { XSelectInput(SDL_Display, WMwindow, app_event_mask | mask); XSetICFocus(SDL_IC); } } } }
int _glfwPlatformInit(void) { #if !defined(X_HAVE_UTF8_STRING) // HACK: If the current locale is "C" and the Xlib UTF-8 functions are // unavailable, apply the environment's locale in the hope that it's // both available and not "C" // This is done because the "C" locale breaks wide character input, // which is what we fall back on when UTF-8 support is missing if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0) setlocale(LC_CTYPE, ""); #endif XInitThreads(); XrmInitialize(); _glfw.x11.display = XOpenDisplay(NULL); if (!_glfw.x11.display) { const char* display = getenv("DISPLAY"); if (display) { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to open display %s", display); } else { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: The DISPLAY environment variable is missing"); } return GLFW_FALSE; } _glfw.x11.screen = DefaultScreen(_glfw.x11.display); _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen); _glfw.x11.context = XUniqueContext(); getSystemContentScale(&_glfw.x11.contentScaleX, &_glfw.x11.contentScaleY); if (!initExtensions()) return GLFW_FALSE; _glfw.x11.helperWindowHandle = createHelperWindow(); _glfw.x11.hiddenCursorHandle = createHiddenCursor(); if (XSupportsLocale()) { XSetLocaleModifiers(""); _glfw.x11.im = XOpenIM(_glfw.x11.display, 0, NULL, NULL); if (_glfw.x11.im) { if (!hasUsableInputMethodStyle()) { XCloseIM(_glfw.x11.im); _glfw.x11.im = NULL; } } } #if defined(__linux__) if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; #endif _glfwInitTimerPOSIX(); _glfwPollMonitorsX11(); return GLFW_TRUE; }
int _glfwPlatformInit(void) { #if !defined(X_HAVE_UTF8_STRING) // HACK: If the current locale is C, apply the environment's locale // This is done because the C locale breaks wide character input if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0) setlocale(LC_CTYPE, ""); #endif XInitThreads(); _glfw.x11.display = XOpenDisplay(NULL); if (!_glfw.x11.display) { const char* display = getenv("DISPLAY"); if (display) { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to open display %s", display); } else { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: The DISPLAY environment variable is missing"); } return GLFW_FALSE; } _glfw.x11.screen = DefaultScreen(_glfw.x11.display); _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen); _glfw.x11.context = XUniqueContext(); if (!initExtensions()) return GLFW_FALSE; _glfw.x11.cursor = createNULLCursor(); if (XSupportsLocale()) { XSetLocaleModifiers(""); _glfw.x11.im = XOpenIM(_glfw.x11.display, 0, NULL, NULL); if (_glfw.x11.im) { if (!hasUsableInputMethodStyle()) { XCloseIM(_glfw.x11.im); _glfw.x11.im = NULL; } } } if (!_glfwInitContextAPI()) return GLFW_FALSE; if (!_glfwInitJoysticks()) return GLFW_FALSE; _glfwInitTimer(); return GLFW_TRUE; }
int main(int argc, char *argv[], char *env[]) { int i; void configure(); FILE *pfp; /* current profile FP */ GdkPixbuf* icon; ENTER; //printf("sizeof(gulong)=%d\n", sizeof(gulong)); setlocale(LC_CTYPE, ""); gtk_set_locale(); gtk_init(&argc, &argv); XSetLocaleModifiers(""); XSetErrorHandler((XErrorHandler) handle_error); icon = gdk_pixbuf_new_from_file(IMGPREFIX "star.png", NULL); if (icon) { gtk_window_set_default_icon(icon); g_object_unref(icon); } resolve_atoms(); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { usage(); exit(0); } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { printf("fbpanel %s\n", version); exit(0); } else if (!strcmp(argv[i], "--log")) { i++; if (i == argc) { ERR( "fbpanel: missing log level\n"); usage(); exit(1); } else { log_level = atoi(argv[i]); } } else if (!strcmp(argv[i], "--configure") || !strcmp(argv[i], "-C")) { config = 1; } else if (!strcmp(argv[i], "--profile") || !strcmp(argv[i], "-p")) { i++; if (i == argc) { ERR( "fbpanel: missing profile name\n"); usage(); exit(1); } else { cprofile = g_strdup(argv[i]); } } else { printf("fbpanel: unknown option - %s\n", argv[i]); usage(); exit(1); } } gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), IMGPREFIX); signal(SIGUSR1, sig_usr); do { if (!(pfp = open_profile(cprofile))) exit(1); p = g_new0(panel, 1); g_return_val_if_fail (p != NULL, 1); if (!panel_start(p, pfp)) { ERR( "fbpanel: can't start panel\n"); exit(1); } fclose(pfp); if (config) configure(); gtk_main(); panel_stop(p); g_free(p); } while (force_quit == 0); exit(0); }
int main(int argc, char **argv) { Display *dpy; WMScreen *scr; char *path; int i; char *display_name = ""; wsetabort(wAbort); memset(DeadHandlers, 0, sizeof(DeadHandlers)); WMInitializeApplication("WPrefs", &argc, argv); WMSetResourcePath(RESOURCE_PATH); path = WMPathForResourceOfType("WPrefs.tiff", NULL); if (!path) { /* maybe it is run directly from the source directory */ WMSetResourcePath("."); path = WMPathForResourceOfType("WPrefs.tiff", NULL); if (!path) { WMSetResourcePath(".."); } } if (path) { wfree(path); } if (argc > 1) { for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) { printf("WPrefs (Window Maker) %s\n", VERSION); exit(0); } else if (strcmp(argv[i], "-display") == 0) { i++; if (i >= argc) { wwarning(_("too few arguments for %s"), argv[i - 1]); exit(0); } display_name = argv[i]; } else { print_help(argv[0]); exit(0); } } } setlocale(LC_ALL, ""); #ifdef I18N if (getenv("NLSPATH")) bindtextdomain("WPrefs", getenv("NLSPATH")); else bindtextdomain("WPrefs", LOCALEDIR); bind_textdomain_codeset("WPrefs", "UTF-8"); textdomain("WPrefs"); if (!XSupportsLocale()) { wwarning(_("X server does not support locale")); } if (XSetLocaleModifiers("") == NULL) { wwarning(_("cannot set locale modifiers")); } #endif dpy = XOpenDisplay(display_name); if (!dpy) { wfatal(_("could not open display %s"), XDisplayName(display_name)); exit(0); } #if 0 XSynchronize(dpy, 1); #endif scr = WMCreateScreen(dpy, DefaultScreen(dpy)); if (!scr) { wfatal(_("could not initialize application")); exit(0); } xext_xkb_supported = XkbQueryExtension(dpy, NULL, NULL, NULL, NULL, NULL); WMPLSetCaseSensitive(False); Initialize(scr); while (1) { XEvent event; WMNextEvent(dpy, &event); while (DeadChildrenCount-- > 0) { int i; for (i = 0; i < MAX_DEATHS; i++) { if (DeadChildren[i] == DeadHandlers[i].pid) { (*DeadHandlers[i].handler) (DeadHandlers[i].data); DeadHandlers[i].pid = 0; } } } WMHandleEvent(&event); } }
static void create_aux_windows(_THIS) { int x = 0, y = 0; char classname[1024]; XSetWindowAttributes xattr; XWMHints *hints; unsigned long app_event_mask; int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen)); WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False); if ( SDL_windowid ) { FSwindow = 0; WMwindow = SDL_strtol(SDL_windowid, NULL, 0); return; } if(FSwindow) XDestroyWindow(SDL_Display, FSwindow); #if SDL_VIDEO_DRIVER_X11_XINERAMA if ( use_xinerama ) { x = xinerama_info.x_org; y = xinerama_info.y_org; } #endif xattr.override_redirect = True; xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0; xattr.border_pixel = 0; xattr.colormap = SDL_XColorMap; FSwindow = XCreateWindow(SDL_Display, SDL_Root, x + X11_wmXAdjust, y + X11_wmYAdjust, 32, 32, 0, this->hidden->depth, InputOutput, SDL_Visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap, &xattr); XSelectInput(SDL_Display, FSwindow, StructureNotifyMask); { XEvent ev; long mask; SDL_memset(&ev, 0, sizeof(ev)); ev.xclient.type = ClientMessage; ev.xclient.window = SDL_Root; ev.xclient.message_type = XInternAtom(SDL_Display, "KWM_KEEP_ON_TOP", False); ev.xclient.format = 32; ev.xclient.data.l[0] = FSwindow; ev.xclient.data.l[1] = CurrentTime; mask = SubstructureRedirectMask; XSendEvent(SDL_Display, SDL_Root, False, mask, &ev); } hints = NULL; if(WMwindow) { hints = XGetWMHints(SDL_Display, WMwindow); XDestroyWindow(SDL_Display, WMwindow); } WMwindow = XCreateWindow(SDL_Display, SDL_Root, x, y, 32, 32, 0, this->hidden->depth, InputOutput, SDL_Visual, CWBackPixel | CWBorderPixel | CWColormap, &xattr); if(!hints) { hints = XAllocWMHints(); hints->input = True; hints->flags = InputHint; } XSetWMHints(SDL_Display, WMwindow, hints); XFree(hints); X11_SetCaptionNoLock(this, this->wm_title, this->wm_icon); app_event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask | PropertyChangeMask | StructureNotifyMask | KeymapStateMask; XSelectInput(SDL_Display, WMwindow, app_event_mask); get_classname(classname, sizeof(classname)); { XClassHint *classhints; classhints = XAllocClassHint(); if(classhints != NULL) { classhints->res_name = classname; classhints->res_class = classname; XSetClassHint(SDL_Display, WMwindow, classhints); XFree(classhints); } } { pid_t pid = getpid(); char hostname[256]; if (pid > 0 && gethostname(hostname, sizeof(hostname)) > -1) { Atom _NET_WM_PID = XInternAtom(SDL_Display, "_NET_WM_PID", False); Atom WM_CLIENT_MACHINE = XInternAtom(SDL_Display, "WM_CLIENT_MACHINE", False); hostname[sizeof(hostname)-1] = '\0'; XChangeProperty(SDL_Display, WMwindow, _NET_WM_PID, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&pid, 1); XChangeProperty(SDL_Display, WMwindow, WM_CLIENT_MACHINE, XA_STRING, 8, PropModeReplace, (unsigned char *)hostname, SDL_strlen(hostname)); } } #ifdef X_HAVE_UTF8_STRING if (SDL_X11_HAVE_UTF8) { if (SDL_IM != NULL && SDL_Display != XDisplayOfIM(SDL_IM)) { SDL_SetError("display has changed while an IM is kept"); if (SDL_IC) { XUnsetICFocus(SDL_IC); XDestroyIC(SDL_IC); SDL_IC = NULL; } XCloseIM(SDL_IM); SDL_IM = NULL; } if (SDL_IM == NULL) { char *old_locale = NULL, *old_modifiers = NULL; const char *p; size_t n; p = setlocale(LC_ALL, NULL); if ( p ) { n = SDL_strlen(p)+1; old_locale = SDL_stack_alloc(char, n); if ( old_locale ) { SDL_strlcpy(old_locale, p, n); } } p = XSetLocaleModifiers(NULL); if ( p ) { n = SDL_strlen(p)+1; old_modifiers = SDL_stack_alloc(char, n); if ( old_modifiers ) { SDL_strlcpy(old_modifiers, p, n); } } setlocale(LC_ALL, ""); XSetLocaleModifiers(""); SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname); if ( old_locale ) { setlocale(LC_ALL, old_locale); SDL_stack_free(old_locale); } if ( old_modifiers ) { XSetLocaleModifiers(old_modifiers); SDL_stack_free(old_modifiers); } } if (SDL_IM == NULL) { SDL_SetError("no input method could be opened"); } else { if (SDL_IC != NULL) { XUnsetICFocus(SDL_IC); XDestroyIC(SDL_IC); } SDL_IC = pXCreateIC(SDL_IM, XNClientWindow, WMwindow, XNFocusWindow, WMwindow, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNResourceName, classname, XNResourceClass, classname, NULL); if (SDL_IC == NULL) { SDL_SetError("no input context could be created"); XCloseIM(SDL_IM); SDL_IM = NULL; } else { unsigned long mask = 0; char *ret = pXGetICValues(SDL_IC, XNFilterEvents, &mask, NULL); if (ret != NULL) { XUnsetICFocus(SDL_IC); XDestroyIC(SDL_IC); SDL_IC = NULL; SDL_SetError("no input context could be created"); XCloseIM(SDL_IM); SDL_IM = NULL; } else { XSelectInput(SDL_Display, WMwindow, app_event_mask | mask); XSetICFocus(SDL_IC); } } } }
int main(int argc, char *argv[], char *env[]) { int i; const char* desktop_name; char *file; setlocale(LC_CTYPE, ""); #if !GLIB_CHECK_VERSION(2, 32, 0) g_thread_init(NULL); #endif /* gdk_threads_init(); gdk_threads_enter(); */ gtk_init(&argc, &argv); #ifdef ENABLE_NLS bindtextdomain ( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR ); bind_textdomain_codeset ( GETTEXT_PACKAGE, "UTF-8" ); textdomain ( GETTEXT_PACKAGE ); #endif XSetLocaleModifiers(""); XSetErrorHandler((XErrorHandler) panel_handle_x_error); resolve_atoms(); desktop_name = g_getenv("XDG_CURRENT_DESKTOP"); is_in_lxde = desktop_name && (0 == strcmp(desktop_name, "LXDE")); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { usage(); exit(0); } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { printf("lxpanel %s\n", version); exit(0); } else if (!strcmp(argv[i], "--log")) { i++; if (i == argc) { g_critical( "lxpanel: missing log level"); usage(); exit(1); } else { /* deprecated */ } } else if (!strcmp(argv[i], "--configure") || !strcmp(argv[i], "-C")) { config = 1; } else if (!strcmp(argv[i], "--profile") || !strcmp(argv[i], "-p")) { i++; if (i == argc) { g_critical( "lxpanel: missing profile name"); usage(); exit(1); } else { cprofile = g_strdup(argv[i]); } } else { printf("lxpanel: unknown option - %s\n", argv[i]); usage(); exit(1); } } /* Add a gtkrc file to be parsed too. */ file = _user_config_file_name("gtkrc", NULL); gtk_rc_parse(file); g_free(file); /* Check for duplicated lxpanel instances */ if (!check_main_lock() && !config) { printf("There is already an instance of LXPanel. Now to exit\n"); exit(1); } _ensure_user_config_dirs(); /* Add our own icons to the search path of icon theme */ gtk_icon_theme_append_search_path( gtk_icon_theme_get_default(), PACKAGE_DATA_DIR "/images" ); fbev = fb_ev_new(); is_restarting = FALSE; /* init LibFM */ fm_gtk_init(NULL); /* prepare modules data */ lxpanel_prepare_modules(); init_static_plugins(); load_global_config(); /* NOTE: StructureNotifyMask is required by XRandR * See init_randr_support() in gdkscreen-x11.c of gtk+ for detail. */ gdk_window_set_events(gdk_get_default_root_window(), GDK_STRUCTURE_MASK | GDK_SUBSTRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK); gdk_window_add_filter(gdk_get_default_root_window (), (GdkFilterFunc)panel_event_filter, NULL); if( G_UNLIKELY( ! start_all_panels() ) ) g_warning( "Config files are not found.\n" ); /* * FIXME: configure?? if (config) configure(); */ gtk_main(); XSelectInput (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), GDK_ROOT_WINDOW(), NoEventMask); gdk_window_remove_filter(gdk_get_default_root_window (), (GdkFilterFunc)panel_event_filter, NULL); /* destroy all panels */ g_slist_foreach( all_panels, (GFunc) gtk_widget_destroy, NULL ); g_slist_free( all_panels ); all_panels = NULL; g_free( cfgfile ); free_global_config(); lxpanel_unload_modules(); fm_gtk_finalize(); /* gdk_threads_leave(); */ g_object_unref(fbev); if (!is_restarting) return 0; if (strchr(argv[0], G_DIR_SEPARATOR)) execve(argv[0], argv, env); else execve(g_find_program_in_path(argv[0]), argv, env); return 1; }
void DesktopWindowLinux::setup() { char* loc = setlocale(LC_ALL, ""); if (!loc) std::cerr << "Could not use the the default environment locale.\n"; if (!XSupportsLocale()) std::cerr << "Default locale \"" << (loc ? loc : "") << "\" is no supported.\n"; // When changing the locale being used we must call XSetLocaleModifiers (refer to manpage). if (!XSetLocaleModifiers("")) std::cerr << "Could not set locale modifiers for locale \"" << (loc ? loc : "") << "\".\n"; m_display = XOpenDisplay(0); if (!m_display) throw FatalError("Couldn't connect to X server"); int attributes[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_DOUBLEBUFFER, True, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 1, GLX_TRANSPARENT_TYPE, GLX_NONE, None }; int numReturned = 0; GLXFBConfig* fbConfigs(glXChooseFBConfig(m_display, DefaultScreen(m_display), attributes, &numReturned)); if (!fbConfigs) throw FatalError("No double buffered config available"); GLXFBConfig fbConfig = fbConfigs[0]; ScopedXFree x(fbConfigs); m_visualInfo = glXGetVisualFromFBConfig(m_display, fbConfig); if (!m_visualInfo) throw FatalError("No appropriate visual found."); XSetWindowAttributes setAttributes; setAttributes.colormap = XCreateColormap(m_display, DefaultRootWindow(m_display), m_visualInfo->visual, AllocNone); setAttributes.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | PointerMotionMask; m_window = XCreateWindow(m_display, DefaultRootWindow(m_display), 0, 0, m_size.width, m_size.height, 0, m_visualInfo->depth, InputOutput, m_visualInfo->visual, CWColormap | CWEventMask, &setAttributes); m_im = XOpenIM(m_display, 0, 0, 0); if (!m_im) throw FatalError("Could not open input method."); m_ic = XCreateIC(m_im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_window, NULL); if (!m_ic) throw FatalError("Could not open input context."); wmDeleteMessageAtom = XInternAtom(m_display, "WM_DELETE_WINDOW", False); XSetWMProtocols(m_display, m_window, &wmDeleteMessageAtom, 1); XMapWindow(m_display, m_window); XStoreName(m_display, m_window, "Drowser"); m_context = glXCreateNewContext(m_display, fbConfig, GLX_RGBA_TYPE, NULL, GL_TRUE); if (!m_context) throw FatalError("glXCreateContext() failed."); }
int main(int argc, char *argv[], char *env[]) { int i; ENTER; setlocale(LC_CTYPE, ""); gtk_init(&argc, &argv); XSetLocaleModifiers(""); XSetErrorHandler((XErrorHandler) handle_error); // resolve xatoms resolve_atoms(); p = g_new0(panel, 1); memset(p, 0, sizeof(panel)); p->allign = ALLIGN_CENTER; p->edge = EDGE_BOTTOM; p->widthtype = WIDTH_PERCENT; p->width = PANEL_WIDTH_DEFAULT; p->heighttype = HEIGHT_PIXEL; p->height = PANEL_HEIGHT_DEFAULT; p->setdocktype = 1; p->setstrut = 0; p->transparent = 0; p->icon_spacing = 0; p->alpha = 127; p->tintcolor = 0xFFFFFFFF; p->xtopbg = None; p->monitor = 0; p->margin = 0; p->on_primary = 0; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { usage(); exit(0); } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { printf("trayer %s\n", version); exit(0); } else if (!strcmp(argv[i], "-l")) { p->lower = 1; } else if (!strcmp(argv[i], "--edge")) { i++; if (i == argc) { ERR( "trayer: missing edge parameter value\n"); usage(); exit(1); } else { p->edge = str2num(edge_pair, argv[i], EDGE_NONE); } } else if (!strcmp(argv[i], "--align")) { i++; if (i == argc) { ERR( "trayer: missing align parameter value\n"); usage(); exit(1); } else { p->allign = str2num(allign_pair, argv[i], ALLIGN_NONE); } } else if (!strcmp(argv[i], "--margin")) { i++; if (i == argc) { ERR( "trayer: missing margin parameter value\n"); usage(); exit(1); } else { p->margin = atoi(argv[i]); } } else if (!strcmp(argv[i], "--widthtype")) { i++; if (i == argc) { ERR( "trayer: missing widthtype parameter value\n"); usage(); exit(1); } else { p->widthtype = str2num(width_pair, argv[i], WIDTH_NONE); } } else if (!strcmp(argv[i], "--width")) { i++; if (i == argc) { ERR( "trayer: missing width parameter value\n"); usage(); exit(1); } else { p->width = atoi(argv[i]); } } else if (!strcmp(argv[i], "--heighttype")) { i++; if (i == argc) { ERR( "trayer: missing heighttype parameter value\n"); usage(); exit(1); } else { p->heighttype = str2num(height_pair, argv[i], HEIGHT_NONE); } } else if (!strcmp(argv[i], "--height")) { i++; if (i == argc) { ERR( "trayer: missing height parameter value\n"); usage(); exit(1); } else { p->height = atoi(argv[i]); } } else if (!strcmp(argv[i], "--SetDockType")) { i++; if (i == argc) { ERR( "trayer: missing SetDockType parameter value\n"); usage(); exit(1); } else { p->setdocktype = str2num(bool_pair, argv[i], 0); } } else if (!strcmp(argv[i], "--SetPartialStrut")) { i++; if (i == argc) { ERR( "trayer: missing SetPartialStrut parameter value\n"); usage(); exit(1); } else { p->setstrut = str2num(bool_pair, argv[i], 0); } } else if (!strcmp(argv[i], "--transparent")) { i++; if (i == argc) { ERR( "trayer: missing transparent parameter value\n"); usage(); exit(1); } else { p->transparent = str2num(bool_pair, argv[i], 1); } } else if (!strcmp(argv[i], "--alpha")) { i++; if (i == argc) { ERR( "trayer: missing alpha parameter value\n"); usage(); exit(1); } else { p->alpha = atoi(argv[i]); } } else if (!strcmp(argv[i], "--tint")) { i++; if (i == argc) { ERR( "trayer: missing tint parameter value\n"); usage(); exit(1); } else { p->tintcolor = strtoul(argv[i], NULL, 0); } } else if (!strcmp(argv[i], "--distance")) { i++; if (i == argc) { ERR( "trayer: missing distance parameter value\n"); usage(); exit(1); } else { distance = atoi(argv[i]); } } else if (!strcmp(argv[i], "--distancefrom")) { i++; if (i == argc) { ERR( "trayer: missing distancefrom parameter value\n"); usage(); exit(1); } else { distancefrom = str2num(distancefrom_pair, argv[i], DISTANCEFROM_NONE); } } else if (!strcmp(argv[i], "--expand")) { i++; if (i == argc) { ERR( "trayer: missing expand parameter value\n"); usage(); exit(1); } else { expand = str2num(bool_pair, argv[i], 1); } } else if (!strcmp(argv[i], "--padding")) { i++; if (i == argc) { ERR( "trayer: missing padding parameter value\n"); usage(); exit(1); } else { padding = atoi(argv[i]); } } else if (!strcmp(argv[i], "--monitor")) { i++; if (i == argc) { ERR( "trayer: missing monitor parameter value\n"); usage(); exit(1); } else { if (g_ascii_isdigit(argv[i][0])) { p->monitor = atoi(argv[i]); } else if (!strcmp(argv[i], "primary")) { p->on_primary = 1; } } } else if (!strcmp(argv[i], "--iconspacing")) { i++; if (i == argc) { ERR( "trayer: missing icon padding parameter value\n"); usage(); exit(1); } else { p->icon_spacing = atoi(argv[i]); } } else { printf("trayer: unknown option - %s\n", argv[i]); usage(); exit(1); } } g_return_val_if_fail (p != NULL, 1); if (!panel_start(p)) { ERR( "trayer: can't start panel\n"); exit(1); } gtk_main(); panel_stop(p); g_free(p); exit(0); }
static void OpenIM( TkDisplay *dispPtr) /* Tk's structure for the display. */ { int i; XIMStyles *stylePtr; XIMStyle bestStyle = 0; if (XSetLocaleModifiers("") == NULL) { return; } dispPtr->inputMethod = XOpenIM(dispPtr->display, NULL, NULL, NULL); if (dispPtr->inputMethod == NULL) { return; } if ((XGetIMValues(dispPtr->inputMethod, XNQueryInputStyle, &stylePtr, NULL) != NULL) || (stylePtr == NULL)) { goto error; } /* * Select the best input style supported by both the IM and Tk. */ for (i = 0; i < stylePtr->count_styles; i++) { XIMStyle thisStyle = stylePtr->supported_styles[i]; if (thisStyle == (XIMPreeditPosition | XIMStatusNothing)) { bestStyle = thisStyle; break; } else if (thisStyle == (XIMPreeditNothing | XIMStatusNothing)) { bestStyle = thisStyle; } } XFree(stylePtr); if (bestStyle == 0) { goto error; } dispPtr->inputStyle = bestStyle; /* * Create an XFontSet for preedit area. */ if (dispPtr->inputStyle & XIMPreeditPosition) { char **missing_list; int missing_count; char *def_string; dispPtr->inputXfs = XCreateFontSet(dispPtr->display, "-*-*-*-R-Normal--14-130-75-75-*-*", &missing_list, &missing_count, &def_string); if (missing_count > 0) { XFreeStringList(missing_list); } } return; error: if (dispPtr->inputMethod) { XCloseIM(dispPtr->inputMethod); dispPtr->inputMethod = NULL; } }
static int glw_x11_init(glw_x11_t *gx11) { int attribs[10]; int na = 0; XInitThreads(); int use_locales = XSupportsLocale() && XSetLocaleModifiers("") != NULL; if((gx11->display = XOpenDisplay(gx11->displayname_real)) == NULL) { TRACE(TRACE_ERROR, "GLW", "Unable to open X display \"%s\"\n", gx11->displayname_real); return 1; } if(!glXQueryExtension(gx11->display, NULL, NULL)) { TRACE(TRACE_ERROR, "GLW", "OpenGL GLX extension not supported by display \"%s\"\n", gx11->displayname_real); return 1; } gx11->screen = DefaultScreen(gx11->display); gx11->screen_width = DisplayWidth(gx11->display, gx11->screen); gx11->screen_height = DisplayHeight(gx11->display, gx11->screen); gx11->root = RootWindow(gx11->display, gx11->screen); attribs[na++] = GLX_RGBA; attribs[na++] = GLX_RED_SIZE; attribs[na++] = 1; attribs[na++] = GLX_GREEN_SIZE; attribs[na++] = 1; attribs[na++] = GLX_BLUE_SIZE; attribs[na++] = 1; attribs[na++] = GLX_DOUBLEBUFFER; attribs[na++] = None; gx11->xvi = glXChooseVisual(gx11->display, gx11->screen, attribs); if(gx11->xvi == NULL) { TRACE(TRACE_ERROR, "GLW", "Unable to find an adequate Visual on \"%s\"\n", gx11->displayname_real); return 1; } if(GLXExtensionSupported(gx11->display, "GLX_SGI_swap_control")) { TRACE(TRACE_DEBUG, "GLW", "GLX_SGI_swap_control extension is present"); gx11->glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) glXGetProcAddress((const GLubyte*)"glXSwapIntervalSGI"); } build_blank_cursor(gx11); if(use_locales) gx11->im = XOpenIM(gx11->display, NULL, NULL, NULL); gx11->atom_deletewindow = XInternAtom(gx11->display, "WM_DELETE_WINDOW", 0); #if ENABLE_VDPAU if(GLXExtensionSupported(gx11->display, "GLX_EXT_texture_from_pixmap")) { gx11->gr.gr_be.gbr_bind_tex_image = (PFNGLXBINDTEXIMAGEEXTPROC) glXGetProcAddress((const GLubyte*)"glXBindTexImageEXT"); gx11->gr.gr_be.gbr_release_tex_image = (PFNGLXRELEASETEXIMAGEEXTPROC) glXGetProcAddress((const GLubyte*)"glXReleaseTexImageEXT"); gx11->gr.gr_be.gbr_vdpau_dev = vdpau_init_x11(gx11->display, gx11->screen, vdpau_preempted, gx11); } else { TRACE(TRACE_DEBUG, "VDPAU", "GLX_EXT_texture_from_pixmap extension not present, disabling VDPAU"); } #endif probe_wm(gx11); gx11->is_fullscreen = gx11->want_fullscreen; int fs = 0; if(gx11->wm_flags == 0) { fs = 1; // No window manager, open in fullscreen mode } else { /* If window manager cannot do fullscreen, ask window to open in fullscreen mode */ fs = gx11->want_fullscreen && !(gx11->wm_flags & GX11_WM_CAN_FULLSCREEN); } if(window_open(gx11, fs)) return -1; // Fullscreen via window manager if(gx11->want_fullscreen && !fs) wm_set_fullscreen(gx11, 1); return 0; }