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"); } }
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 )
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; }
DC * initdc(void) { if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) { printf("no locale support\n"); } DC * dc = malloc(sizeof(DC)); if(! dc) { printf("cannot allocate memory"); } dc -> dpy = XOpenDisplay(NULL); if(! (dc -> dpy)) { printf("cannot open display\n"); } dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL); dc->font.xfont = NULL; dc->font.set = NULL; dc->font.xft_font = NULL; dc->canvas = None; dc->xftdraw = NULL; XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter); return dc; }
// --- Main Function ------------------------------------------------------ int main(int argc, char* argv[]) { if(argc == 2 && !strcmp("-v", argv[1])) die("INFO", "FusionWM-"VERSION); else if (argc != 1) die("INFO", "Usage: fusionwm [-v]"); if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) say("WARNING", "No locale support"); if(!(gDisplay = XOpenDisplay(NULL))) die("ERROR", "Cannot open display"); checkotherwm(); // Setup setup(); scan(); all_monitors_apply_layout(); // Main loop XEvent event; XSync(gDisplay, False); while (!gAboutToQuit && !XNextEvent(gDisplay, &event)) if(handler[event.type]) handler[event.type](&event); // call handler // Cleanup cleanup(); XCloseDisplay(gDisplay); return EXIT_SUCCESS; }
/* 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); } }
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)
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); }
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 win_init(win_t *win) { win_env_t *e; const char *bg, *fg, *f; memset(win, 0, sizeof(win_t)); e = &win->env; if ((e->dpy = XOpenDisplay(NULL)) == NULL) error(EXIT_FAILURE, 0, "Error opening X display"); e->scr = DefaultScreen(e->dpy); e->scrw = DisplayWidth(e->dpy, e->scr); e->scrh = DisplayHeight(e->dpy, e->scr); e->vis = DefaultVisual(e->dpy, e->scr); e->cmap = DefaultColormap(e->dpy, e->scr); e->depth = DefaultDepth(e->dpy, e->scr); if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) error(0, 0, "No locale support"); f = win_res(e->dpy, RES_CLASS ".font", "monospace-8"); win_init_font(e, f); bg = win_res(e->dpy, RES_CLASS ".background", "white"); fg = win_res(e->dpy, RES_CLASS ".foreground", "black"); win_alloc_color(e, bg, &win->bg); win_alloc_color(e, fg, &win->fg); win_alloc_color(e, "black", &win->black); win->light = win_luminance(&win->bg) > win_luminance(&win->fg); win->bar.l.size = BAR_L_LEN; win->bar.r.size = BAR_R_LEN; /* 3 padding bytes needed by utf8_decode */ win->bar.l.buf = emalloc(win->bar.l.size + 3); win->bar.l.buf[0] = '\0'; win->bar.r.buf = emalloc(win->bar.r.size + 3); win->bar.r.buf[0] = '\0'; win->bar.h = options->hide_bar ? 0 : barheight; INIT_ATOM_(WM_DELETE_WINDOW); INIT_ATOM_(_NET_WM_NAME); INIT_ATOM_(_NET_WM_ICON_NAME); INIT_ATOM_(_NET_WM_ICON); INIT_ATOM_(_NET_WM_STATE); INIT_ATOM_(_NET_WM_STATE_FULLSCREEN); INIT_ATOM_(_NET_SUPPORTED); win_check_wm_support(e->dpy, RootWindow(e->dpy, e->scr)); }
gchar* gdk_set_locale (void) { wchar_t result; gchar *current_locale; gdk_use_mb = FALSE; if (! strcmp (setlocale (LC_ALL, NULL), "C.UTF-8")) {return; } //musl fix if (!setlocale (LC_ALL,"")) g_warning ("locale not supported by C library"); if (!XSupportsLocale ()) { /*g_warning ("locale not supported by Xlib, locale set to C");*/ setlocale (LC_ALL, "C"); } /*if (!XSetLocaleModifiers ("")) g_warning ("can not set locale modifiers");*/ current_locale = setlocale (LC_ALL, NULL); if ((strcmp (current_locale, "C")) && (strcmp (current_locale, "POSIX"))) { gdk_use_mb = TRUE; #ifndef X_LOCALE /* Detect GNU libc, where mb == UTF8. Not useful unless it's * really a UTF8 locale. The below still probably will * screw up on Greek, Cyrillic, etc, encoded as UTF8. */ if ((MB_CUR_MAX == 2) && (mbstowcs (&result, "\xdd\xa5", 1) > 0) && result == 0x765) { if ((strlen (current_locale) < 4) || g_strcasecmp (current_locale + strlen(current_locale) - 4, "utf8")) gdk_use_mb = FALSE; } #endif /* X_LOCALE */ } GDK_NOTE (XIM, g_message ("%s multi-byte string functions.", gdk_use_mb ? "Using" : "Not using")); return current_locale; }
static void oxim_setlocale(void) { char loc_return[128], enc_return[128]; oxim_set_perr("oxim"); oxim_set_lc_ctype("", loc_return, 128, enc_return, 128, OXIMMSG_ERROR); oxim_core.lc_ctype = (char *)strdup(loc_return); oxim_set_lc_messages("", loc_return, 128); if (XSupportsLocale() != True) oxim_perr(OXIMMSG_ERROR, N_("X locale \"%s\" is not supported by your system.\n"), oxim_core.lc_ctype); }
DC * initdc(void) { DC *dc; if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("no locale support\n", stderr); if(!(dc = calloc(1, sizeof *dc))) eprintf("cannot malloc %u bytes:", sizeof *dc); if(!(dc->dpy = XOpenDisplay(NULL))) eprintf("cannot open display\n"); dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL); XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter); return dc; }
/*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 */ }
YsSystemFontCache::InternalData::InternalData() { const char *localeStr=setlocale(LC_CTYPE,""); if(NULL==localeStr || True!=XSupportsLocale()) { setlocale(LC_CTYPE,"en_US.UTF-8"); // Default to en_US } dsp=NULL; rootWin=NULL; fontSet=NULL; dsp=XOpenDisplay(NULL); if(NULL!=dsp) { rootWin=DefaultRootWindow(dsp); fontSet=MakeFontSet(16); } }
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(); }
void win_init(win_t *win) { win_env_t *e; if (win == NULL) return; memset(win, 0, sizeof(win_t)); e = &win->env; if ((e->dpy = XOpenDisplay(NULL)) == NULL) die("could not open display"); e->scr = DefaultScreen(e->dpy); e->scrw = DisplayWidth(e->dpy, e->scr); e->scrh = DisplayHeight(e->dpy, e->scr); e->vis = DefaultVisual(e->dpy, e->scr); e->cmap = DefaultColormap(e->dpy, e->scr); e->depth = DefaultDepth(e->dpy, e->scr); if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) warn("no locale support"); win_init_font(e->dpy, BAR_FONT); win->white = WhitePixel(e->dpy, e->scr); win->bgcol = win_alloc_color(win, WIN_BG_COLOR); win->fscol = win_alloc_color(win, WIN_FS_COLOR); win->selcol = win_alloc_color(win, SEL_COLOR); win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR); win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR); win->bar.h = options->hide_bar ? 0 : barheight; win->sizehints.flags = PWinGravity; win->sizehints.win_gravity = NorthWestGravity; if (options->fixed_win) /* actual min/max values set in win_update_sizehints() */ win->sizehints.flags |= PMinSize | PMaxSize; wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False); }
void win_init(win_t *win) { win_env_t *e; if (win == NULL) return; memset(win, 0, sizeof(win_t)); e = &win->env; if ((e->dpy = XOpenDisplay(NULL)) == NULL) die("could not open display"); e->scr = DefaultScreen(e->dpy); e->scrw = DisplayWidth(e->dpy, e->scr); e->scrh = DisplayHeight(e->dpy, e->scr); e->vis = DefaultVisual(e->dpy, e->scr); e->cmap = DefaultColormap(e->dpy, e->scr); e->depth = DefaultDepth(e->dpy, e->scr); if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) warn("no locale support"); win_init_font(e->dpy, BAR_FONT); win->bgcol = win_alloc_color(win, WIN_BG_COLOR); win->fscol = win_alloc_color(win, WIN_FS_COLOR); win->selcol = win_alloc_color(win, SEL_COLOR); win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR); win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR); win->bar.h = options->hide_bar ? 0 : barheight; INIT_ATOM_(WM_DELETE_WINDOW); INIT_ATOM_(_NET_WM_NAME); INIT_ATOM_(_NET_WM_ICON_NAME); INIT_ATOM_(_NET_WM_ICON); INIT_ATOM_(_NET_WM_STATE); INIT_ATOM_(_NET_WM_STATE_FULLSCREEN); INIT_ATOM_(_NET_SUPPORTED); }
/*********************************************************************** * 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; }
/* * internal functions */ Ecore_IMF_Context_Data * imf_context_data_new() { Ecore_IMF_Context_Data *imf_context_data = NULL; char *locale; locale = setlocale(LC_CTYPE, ""); if (!locale) return NULL; if (!XSupportsLocale()) return NULL; imf_context_data = calloc(1, sizeof(Ecore_IMF_Context_Data)); EINA_SAFETY_ON_NULL_RETURN_VAL(imf_context_data, NULL); imf_context_data->locale = strdup(locale); if (!imf_context_data->locale) goto error; return imf_context_data; error: imf_context_data_destroy(imf_context_data); return NULL; }
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; }
void creategui() { int x, y, w = width, h = height; XSetWindowAttributes wa; if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("no locale support\n", stderr); screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); initfont(font); cursor = XCreateFontCursor(dpy, XC_left_ptr); dc.norm[ColBG] = getcolor(normbgcolor); dc.norm[ColFG] = getcolor(normfgcolor); dc.sel[ColBG] = getcolor(selbgcolor); dc.sel[ColFG] = getcolor(selfgcolor); dc.drawable = XCreatePixmap(dpy, root, w, 2 * h, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, NULL); XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); if (!dc.font.set) XSetFont(dpy, dc.gc, dc.font.xfont->fid); wa.cursor = cursor; wa.background_pixel = dc.norm[ColBG]; XChangeWindowAttributes(dpy, root, CWBackPixel|CWCursor, &wa); x = (DisplayWidth(dpy, screen) - w) / 2; y = DisplayHeight(dpy, screen) / 2; createinput(userprompt, x, y - h, w, h, innerpx, False); createinput(passprompt, x, y, w, h, innerpx, True); im = XOpenIM(dpy, NULL, NULL, NULL); ic = XCreateIC(im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, inputs->win, XNFocusWindow, inputs->win, NULL); }
/*********************************************************************** * 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; }
void * winClipboardProc(void *pvNotUsed) { Atom atomClipboard, atomClipboardManager; int iReturn; HWND hwnd = NULL; int iConnectionNumber = 0; #ifdef HAS_DEVWINDOWS int fdMessageQueue = 0; #else struct timeval tvTimeout; #endif fd_set fdsRead; int iMaxDescriptor; Display *pDisplay = NULL; Window iWindow = None; int iRetries; Bool fUseUnicode; char szDisplay[512]; int iSelectError; winDebug("winClipboardProc - Hello\n"); ++clipboardRestarts; /* Do we use Unicode clipboard? */ fUseUnicode = g_fUnicodeClipboard; /* Save the Unicode support flag in a global */ g_fUseUnicode = fUseUnicode; /* Allow multiple threads to access Xlib */ if (XInitThreads() == 0) { ErrorF("winClipboardProc - XInitThreads failed.\n"); goto winClipboardProc_Exit; } /* See if X supports the current locale */ if (XSupportsLocale() == False) { ErrorF("winClipboardProc - Warning: Locale not supported by X.\n"); } /* Set error handler */ XSetErrorHandler(winClipboardErrorHandler); g_winClipboardProcThread = pthread_self(); g_winClipboardOldIOErrorHandler = XSetIOErrorHandler(winClipboardIOErrorHandler); /* Set jump point for Error exits */ iReturn = setjmp(g_jmpEntry); /* Check if we should continue operations */ if (iReturn != WIN_JMP_ERROR_IO && iReturn != WIN_JMP_OKAY) { /* setjmp returned an unknown value, exit */ ErrorF("winClipboardProc - setjmp returned: %d exiting\n", iReturn); goto winClipboardProc_Exit; } else if (iReturn == WIN_JMP_ERROR_IO) { /* TODO: Cleanup the Win32 window and free any allocated memory */ ErrorF("winClipboardProc - setjmp returned for IO Error Handler.\n"); pthread_exit(NULL); } /* Use our generated cookie for authentication */ winSetAuthorization(); /* Initialize retry count */ iRetries = 0; /* Setup the display connection string x */ /* * NOTE: Always connect to screen 0 since we require that screen * numbers start at 0 and increase without gaps. We only need * to connect to one screen on the display to get events * for all screens on the display. That is why there is only * one clipboard client thread. */ snprintf(szDisplay, 512, "127.0.0.1:%s.0", display); /* Print the display connection string */ ErrorF("winClipboardProc - DISPLAY=%s\n", szDisplay); /* Open the X display */ do { pDisplay = XOpenDisplay(szDisplay); if (pDisplay == NULL) { ErrorF("winClipboardProc - Could not open display, " "try: %d, sleeping: %d\n", iRetries + 1, WIN_CONNECT_DELAY); ++iRetries; sleep(WIN_CONNECT_DELAY); continue; } else break; } while (pDisplay == NULL && iRetries < WIN_CONNECT_RETRIES); /* Make sure that the display opened */ if (pDisplay == NULL) { ErrorF("winClipboardProc - Failed opening the display, giving up\n"); goto winClipboardProc_Done; } /* Save the display in the screen privates */ g_pClipboardDisplay = pDisplay; ErrorF("winClipboardProc - XOpenDisplay () returned and " "successfully opened the display.\n"); /* Get our connection number */ iConnectionNumber = ConnectionNumber(pDisplay); #ifdef HAS_DEVWINDOWS /* Open a file descriptor for the windows message queue */ fdMessageQueue = open(WIN_MSG_QUEUE_FNAME, O_RDONLY); if (fdMessageQueue == -1) { ErrorF("winClipboardProc - Failed opening %s\n", WIN_MSG_QUEUE_FNAME); goto winClipboardProc_Done; } /* Find max of our file descriptors */ iMaxDescriptor = max(fdMessageQueue, iConnectionNumber) + 1; #else iMaxDescriptor = iConnectionNumber + 1; #endif /* Create atoms */ atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False); atomClipboardManager = XInternAtom(pDisplay, "CLIPBOARD_MANAGER", False); /* Create a messaging window */ iWindow = XCreateSimpleWindow(pDisplay, DefaultRootWindow(pDisplay), 1, 1, 500, 500, 0, BlackPixel(pDisplay, 0), BlackPixel(pDisplay, 0)); if (iWindow == 0) { ErrorF("winClipboardProc - Could not create an X window.\n"); goto winClipboardProc_Done; } XStoreName(pDisplay, iWindow, "xwinclip"); /* Select event types to watch */ if (XSelectInput(pDisplay, iWindow, PropertyChangeMask) == BadWindow) ErrorF("winClipboardProc - XSelectInput generated BadWindow " "on messaging window\n"); /* Save the window in the screen privates */ g_iClipboardWindow = iWindow; /* Create Windows messaging window */ hwnd = winClipboardCreateMessagingWindow(); /* Save copy of HWND in screen privates */ g_hwndClipboard = hwnd; /* Assert ownership of selections if Win32 clipboard is owned */ if (NULL != GetClipboardOwner()) { /* PRIMARY */ iReturn = XSetSelectionOwner(pDisplay, XA_PRIMARY, iWindow, CurrentTime); if (iReturn == BadAtom || iReturn == BadWindow || XGetSelectionOwner(pDisplay, XA_PRIMARY) != iWindow) { ErrorF("winClipboardProc - Could not set PRIMARY owner\n"); goto winClipboardProc_Done; } /* CLIPBOARD */ iReturn = XSetSelectionOwner(pDisplay, atomClipboard, iWindow, CurrentTime); if (iReturn == BadAtom || iReturn == BadWindow || XGetSelectionOwner(pDisplay, atomClipboard) != iWindow) { ErrorF("winClipboardProc - Could not set CLIPBOARD owner\n"); goto winClipboardProc_Done; } } /* Pre-flush X events */ /* * NOTE: Apparently you'll freeze if you don't do this, * because there may be events in local data structures * already. */ winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode); /* Pre-flush Windows messages */ if (!winClipboardFlushWindowsMessageQueue(hwnd)) return 0; /* Signal that the clipboard client has started */ g_fClipboardStarted = TRUE; /* Loop for X events */ while (1) { /* Setup the file descriptor set */ /* * NOTE: You have to do this before every call to select * because select modifies the mask to indicate * which descriptors are ready. */ FD_ZERO(&fdsRead); FD_SET(iConnectionNumber, &fdsRead); #ifdef HAS_DEVWINDOWS FD_SET(fdMessageQueue, &fdsRead); #else tvTimeout.tv_sec = 0; tvTimeout.tv_usec = 100; #endif /* Wait for a Windows event or an X event */ iReturn = select(iMaxDescriptor, /* Highest fds number */ &fdsRead, /* Read mask */ NULL, /* No write mask */ NULL, /* No exception mask */ #ifdef HAS_DEVWINDOWS NULL /* No timeout */ #else &tvTimeout /* Set timeout */ #endif ); #ifndef HAS_WINSOCK iSelectError = errno; #else iSelectError = WSAGetLastError(); #endif if (iReturn < 0) { #ifndef HAS_WINSOCK if (iSelectError == EINTR) #else if (iSelectError == WSAEINTR) #endif continue; ErrorF("winClipboardProc - Call to select () failed: %d. " "Bailing.\n", iReturn); break; } /* Branch on which descriptor became active */ if (FD_ISSET(iConnectionNumber, &fdsRead)) { /* Process X events */ /* Exit when we see that server is shutting down */ iReturn = winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode); if (WIN_XEVENTS_SHUTDOWN == iReturn) { ErrorF("winClipboardProc - winClipboardFlushXEvents " "trapped shutdown event, exiting main loop.\n"); break; } } #ifdef HAS_DEVWINDOWS /* Check for Windows event ready */ if (FD_ISSET(fdMessageQueue, &fdsRead)) #else if (1) #endif { /* Process Windows messages */ if (!winClipboardFlushWindowsMessageQueue(hwnd)) { ErrorF("winClipboardProc - " "winClipboardFlushWindowsMessageQueue trapped " "WM_QUIT message, exiting main loop.\n"); break; } } } winClipboardProc_Exit: /* disable the clipboard, which means the thread will die */ g_fClipboard = FALSE; winClipboardProc_Done: /* Close our Windows window */ if (g_hwndClipboard) { /* Destroy the Window window (hwnd) */ winDebug("winClipboardProc - Destroy Windows window\n"); PostMessage(g_hwndClipboard, WM_DESTROY, 0, 0); winClipboardFlushWindowsMessageQueue(g_hwndClipboard); } /* Close our X window */ if (pDisplay && iWindow) { iReturn = XDestroyWindow(pDisplay, iWindow); if (iReturn == BadWindow) ErrorF("winClipboardProc - XDestroyWindow returned BadWindow.\n"); else ErrorF("winClipboardProc - XDestroyWindow succeeded.\n"); } #ifdef HAS_DEVWINDOWS /* Close our Win32 message handle */ if (fdMessageQueue) close(fdMessageQueue); #endif #if 0 /* * FIXME: XCloseDisplay hangs if we call it, as of 2004/03/26. The * XSync and XSelectInput calls did not help. */ /* Discard any remaining events */ XSync(pDisplay, TRUE); /* Select event types to watch */ XSelectInput(pDisplay, DefaultRootWindow(pDisplay), None); /* Close our X display */ if (pDisplay) { XCloseDisplay(pDisplay); } #endif /* global clipboard variable reset */ g_fClipboardLaunched = FALSE; g_fClipboardStarted = FALSE; g_iClipboardWindow = None; g_pClipboardDisplay = NULL; g_hwndClipboard = NULL; /* checking if we need to restart */ if (clipboardRestarts >= WIN_CLIPBOARD_RETRIES) { /* terminates clipboard thread but the main server still lives */ ErrorF ("winClipboardProc - the clipboard thread has restarted %d times and seems to be unstable, disabling clipboard integration\n", clipboardRestarts); g_fClipboard = FALSE; return; } if (g_fClipboard) { sleep(WIN_CLIPBOARD_DELAY); ErrorF("winClipboardProc - trying to restart clipboard thread \n"); /* Create the clipboard client thread */ if (!winInitClipboard()) { ErrorF("winClipboardProc - winClipboardInit failed.\n"); return; } winDebug("winClipboardProc - winInitClipboard returned.\n"); /* Flag that clipboard client has been launched */ g_fClipboardLaunched = TRUE; } else { ErrorF("winClipboardProc - Clipboard disabled - Exit from server \n"); /* clipboard thread has exited, stop server as well */ kill(getpid(), SIGTERM); } return NULL; }
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; }
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) { 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; } } }
int main(int argc, char *argv[]) { int i, use_ewmh_dock=0; char *action_string = NULL; char *endptr, *fnpre = NULL; /* default values */ dzen.title_win.name = "dzen title"; dzen.slave_win.name = "dzen slave"; dzen.cur_line = 0; dzen.ret_val = 0; dzen.title_win.x = dzen.slave_win.x = 0; dzen.title_win.y = 0; dzen.title_win.width = dzen.slave_win.width = 0; dzen.title_win.alignment = ALIGNCENTER; dzen.slave_win.alignment = ALIGNLEFT; dzen.fnt = FONT; dzen.bg = BGCOLOR; dzen.fg = FGCOLOR; dzen.slave_win.max_lines = 0; dzen.running = True; dzen.xinescreen = 0; dzen.tsupdate = 0; dzen.line_height = 0; dzen.title_win.expand = noexpand; /* Connect to X server */ x_connect(); x_read_resources(); /* cmdline args */ for(i = 1; i < argc; i++) if(!strncmp(argv[i], "-l", 3)){ if(++i < argc) { dzen.slave_win.max_lines = atoi(argv[i]); if(dzen.slave_win.max_lines) init_input_buffer(); } } else if(!strncmp(argv[i], "-geometry", 10)) { if(++i < argc) { int t; int tx, ty; unsigned int tw, th; t = XParseGeometry(argv[i], &tx, &ty, &tw, &th); if(t & XValue) dzen.title_win.x = tx; if(t & YValue) { dzen.title_win.y = ty; if(!ty && (t & YNegative)) /* -0 != +0 */ dzen.title_win.y = -1; } if(t & WidthValue) dzen.title_win.width = (signed int) tw; if(t & HeightValue) dzen.line_height = (signed int) th; } } else if(!strncmp(argv[i], "-u", 3)){ dzen.tsupdate = True; } else if(!strncmp(argv[i], "-expand", 8)){ if(++i < argc) { switch(argv[i][0]){ case 'l': dzen.title_win.expand = left; break; case 'c': dzen.title_win.expand = both; break; case 'r': dzen.title_win.expand = right; break; default: dzen.title_win.expand = noexpand; } } } else if(!strncmp(argv[i], "-p", 3)) { dzen.ispersistent = True; if (i+1 < argc) { dzen.timeout = strtoul(argv[i+1], &endptr, 10); if(*endptr) dzen.timeout = 0; else i++; } } else if(!strncmp(argv[i], "-ta", 4)) { if(++i < argc) dzen.title_win.alignment = alignment_from_char(argv[i][0]); } else if(!strncmp(argv[i], "-sa", 4)) { if(++i < argc) dzen.slave_win.alignment = alignment_from_char(argv[i][0]); } else if(!strncmp(argv[i], "-m", 3)) { dzen.slave_win.ismenu = True; if(i+1 < argc) { if( argv[i+1][0] == 'v') { ++i; break; } dzen.slave_win.ishmenu = (argv[i+1][0] == 'h') ? ++i, True : False; } } else if(!strncmp(argv[i], "-fn", 4)) { if(++i < argc) dzen.fnt = argv[i]; } else if(!strncmp(argv[i], "-e", 3)) { if(++i < argc) action_string = argv[i]; } else if(!strncmp(argv[i], "-title-name", 12)) { if(++i < argc) dzen.title_win.name = argv[i]; } else if(!strncmp(argv[i], "-slave-name", 12)) { if(++i < argc) dzen.slave_win.name = argv[i]; } else if(!strncmp(argv[i], "-bg", 4)) { if(++i < argc) dzen.bg = argv[i]; } else if(!strncmp(argv[i], "-fg", 4)) { if(++i < argc) dzen.fg = argv[i]; } else if(!strncmp(argv[i], "-x", 3)) { if(++i < argc) dzen.title_win.x = dzen.slave_win.x = atoi(argv[i]); } else if(!strncmp(argv[i], "-y", 3)) { if(++i < argc) dzen.title_win.y = atoi(argv[i]); } else if(!strncmp(argv[i], "-w", 3)) { if(++i < argc) dzen.slave_win.width = atoi(argv[i]); } else if(!strncmp(argv[i], "-h", 3)) { if(++i < argc) dzen.line_height= atoi(argv[i]); } else if(!strncmp(argv[i], "-tw", 4)) { if(++i < argc) dzen.title_win.width = atoi(argv[i]); } else if(!strncmp(argv[i], "-fn-preload", 12)) { if(++i < argc) { fnpre = estrdup(argv[i]); } } #ifdef DZEN_XINERAMA else if(!strncmp(argv[i], "-xs", 4)) { if(++i < argc) dzen.xinescreen = atoi(argv[i]); } #endif else if(!strncmp(argv[i], "-dock", 6)) use_ewmh_dock = 1; else if(!strncmp(argv[i], "-v", 3)) { printf("dzen-"VERSION", (C)opyright 2007-2009 Robert Manea\n"); printf( "Enabled optional features: " #ifdef DZEN_XMP " XPM " #endif #ifdef DZEN_XFT " XFT" #endif #ifdef DZEN_XINERAMA " XINERAMA " #endif "\n" ); return EXIT_SUCCESS; } else eprint("usage: dzen2 [-v] [-p [seconds]] [-m [v|h]] [-ta <l|c|r>] [-sa <l|c|r>]\n" " [-x <pixel>] [-y <pixel>] [-w <pixel>] [-h <pixel>] [-tw <pixel>] [-u]\n" " [-e <string>] [-l <lines>] [-fn <font>] [-bg <color>] [-fg <color>]\n" " [-geometry <geometry string>] [-expand <left|right>] [-dock]\n" " [-title-name <string>] [-slave-name <string>]\n" #ifdef DZEN_XINERAMA " [-xs <screen>]\n" #endif ); if(dzen.tsupdate && !dzen.slave_win.max_lines) dzen.tsupdate = False; if(!dzen.title_win.width) dzen.title_win.width = dzen.slave_win.width; if(!setlocale(LC_ALL, "") || !XSupportsLocale()) puts("dzen: locale not available, expect problems with fonts.\n"); if(action_string) fill_ev_table(action_string); else { if(!dzen.slave_win.max_lines) { char edef[] = "button3=exit:13"; fill_ev_table(edef); } else if(dzen.slave_win.ishmenu) { char edef[] = "enterslave=grabkeys;leaveslave=ungrabkeys;" "button4=scrollup;button5=scrolldown;" "key_Left=scrollup;key_Right=scrolldown;" "button1=menuexec;button3=exit:13;" "key_Escape=ungrabkeys,exit"; fill_ev_table(edef); } else { char edef[] = "entertitle=uncollapse,grabkeys;" "enterslave=grabkeys;leaveslave=collapse,ungrabkeys;" "button1=menuexec;button2=togglestick;button3=exit:13;" "button4=scrollup;button5=scrolldown;" "key_Up=scrollup;key_Down=scrolldown;" "key_Escape=ungrabkeys,exit"; fill_ev_table(edef); } } if((find_event(onexit) != -1) && (setup_signal(SIGTERM, catch_sigterm) == SIG_ERR)) fprintf(stderr, "dzen: error hooking SIGTERM\n"); if((find_event(sigusr1) != -1) && (setup_signal(SIGUSR1, catch_sigusr1) == SIG_ERR)) fprintf(stderr, "dzen: error hooking SIGUSR1\n"); if((find_event(sigusr2) != -1) && (setup_signal(SIGUSR2, catch_sigusr2) == SIG_ERR)) fprintf(stderr, "dzen: error hooking SIGUSR2\n"); if(setup_signal(SIGALRM, catch_alrm) == SIG_ERR) fprintf(stderr, "dzen: error hooking SIGALARM\n"); if(dzen.slave_win.ishmenu && !dzen.slave_win.max_lines) dzen.slave_win.max_lines = 1; x_create_windows(use_ewmh_dock); if(!dzen.slave_win.ishmenu) x_map_window(dzen.title_win.win); else { XMapRaised(dzen.dpy, dzen.slave_win.win); for(i=0; i < dzen.slave_win.max_lines; i++) XMapWindow(dzen.dpy, dzen.slave_win.line[i]); } /* Reposition the window back to where it should be */ XMoveWindow(dzen.dpy,dzen.title_win.win,dzen.title_win.x,dzen.title_win.y); if( fnpre != NULL ) font_preload(fnpre); do_action(onstart); /* main loop */ event_loop(); do_action(onexit); clean_up(); if(dzen.ret_val) return dzen.ret_val; return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { XGCValues xgcv; memset( &xgcv, 0, sizeof( xgcv ) ); xgcv.graphics_exposures = False; system( "killall -o 1s boxer" ); if( argc != 5 ) { fprintf( stderr, "Error: expects four parameters ./boxer [x] [y] [w] [h]\n" ); return -1; } x = atoi( argv[1] ); y = atoi( argv[2] ); w = atoi( argv[3] ); h = atoi( argv[4] ); int event_basep, error_basep, a, b; int xinerama_screen; XineramaScreenInfo *screeninfo = NULL; if (setlocale(LC_ALL, "") == NULL || !XSupportsLocale()) fprintf(stderr, "Locale not available, expect problems with fonts.\n"); char * dpy = getenv("DISPLAY"); Display * display = XOpenDisplay(dpy); if (!display) { fprintf( stderr, "Error: Cannot open display.\n" ); return -1; } int screen = XDefaultScreen(display); if (!XShapeQueryExtension(display, &event_basep, &error_basep)) { fprintf( stderr, "X-Server does not support shape extension" ); return -1; } Visual * visual = DefaultVisual(display, screen); depth = DefaultDepth(display, screen); if (XineramaQueryExtension(display, &a, &b ) && (screeninfo = XineramaQueryScreens(display, &screens)) && XineramaIsActive(display) && xinerama_screen >= 0 && xinerama_screen < screens ) { width = screeninfo[xinerama_screen].width; height = screeninfo[xinerama_screen].height; xpos = screeninfo[xinerama_screen].x_org; } else { width = XDisplayWidth(display, screen); height = XDisplayHeight(display, screen); xpos = 0; } if (screeninfo) XFree(screeninfo); XSetWindowAttributes setwinattr; setwinattr.override_redirect = 1; window = XCreateWindow(display, XRootWindow(display, screen), 0, 0, width, height, 0, depth, CopyFromParent, visual, CWOverrideRedirect, &setwinattr); XSelectInput(display, window, ExposureMask); //printf( "Window: %p (%d x %d @ %d)\n", window, width, height, depth ); XStoreName(display, window, "xzbar"); int mask_bitmap = XCreatePixmap(display, window, width, height, 1); int line_bitmap = XCreatePixmap(display, window, width, height, depth); gc = XCreateGC(display, window, GCGraphicsExposures, &xgcv); mask_gc = XCreateGC( display, mask_bitmap, GCGraphicsExposures, &xgcv); mask_gc_back = XCreateGC( display, mask_bitmap, GCGraphicsExposures, &xgcv); XSetBackground(display, gc, WhitePixel(display, screen)); XSetForeground(display, mask_gc_back, BlackPixel(display, screen)); XSetBackground(display, mask_gc_back, WhitePixel(display, screen)); XSetForeground(display, mask_gc, WhitePixel(display, screen)); XSetBackground(display, mask_gc, BlackPixel(display, screen)); stay_on_top( display, window ); XMapRaised(display, window); char **missing; int nmissing; char *defstr; _XOC * fontset = XCreateFontSet( display, default_font, &missing, &nmissing, &defstr); while(1) { XEvent e; int i; XSetForeground(display, gc, 0); XFillRectangle(display, mask_bitmap, mask_gc_back, 0, 0, width, height); XSetForeground(display, gc, 0xFF00FF); /* for (i = 0; i < 100; i++ ) { XRectangle t; t.x = rand()%1000; t.y = 100; t.width = 5; t.height = 20; XFillRectangles(display, mask_bitmap, mask_gc, &t, 1); XFillRectangles(display, line_bitmap, gc, &t, 1); } */ /* XRectangle t; t.x = x; t.y = y; t.width = w; t.height = h; */ int addx = x + w; int addy = y + h; int ox = x; int oy = y; if( ox > 0 ) XDrawLine( display, mask_bitmap, mask_gc, ox, addy, ox, oy ); else ox = 0; if( oy > 0 ) XDrawLine( display, mask_bitmap, mask_gc, ox, oy, addx, oy ); else oy = 0; XDrawLine( display, mask_bitmap, mask_gc, addx, oy, addx, addy ); XDrawLine( display, mask_bitmap, mask_gc, addx, addy, ox, addy ); if( ox > 0 ) XDrawLine( display, line_bitmap, gc, ox, addy, ox, oy ); else ox = 0; if( oy > 0 ) XDrawLine( display, line_bitmap, gc, ox, oy, addx, oy ); else oy = 0; XDrawLine( display, line_bitmap, gc, addx, oy, addx, addy ); XDrawLine( display, line_bitmap, gc, addx, addy, ox, addx ); // XDrawRectangles(display, mask_bitmap, mask_gc, &t, 1); // XDrawRectangles(display, line_bitmap, gc, &t, 1); //Combine the mask again. XShapeCombineMask(display, window, ShapeBounding, 0, 0, mask_bitmap, ShapeSet); // XNextEvent(display, &e); // if (e.type == Expose) { //printf( "Expose\n" ); XCopyArea(display, line_bitmap, window, gc, 0, 0, width, height, 0, 0); // } XFlush(display); usleep(100000); } }
int main (int argc, char *argv[]) { int i; char *pszDisplay = NULL; int fUnicodeClipboard = 1; /* Parse command-line parameters */ for (i = 1; i < argc; ++i) { /* Look for -display "display_name" or --display "display_name" */ if (i < argc - 1 && (!strcmp (argv[i], "-display") || !strcmp (argv[i], "--display"))) { /* Grab a pointer to the display parameter */ pszDisplay = argv[i + 1]; /* Skip the display argument */ i++; continue; } /* Look for -nounicodeclipboard */ if (!strcmp (argv[i], "-nounicodeclipboard")) { fUnicodeClipboard = 0; continue; } /* Look for -noprimary */ if (!strcmp (argv[i], "-noprimary")) { fPrimarySelection = False; continue; } /* Yack when we find a parameter that we don't know about */ printf ("Unknown parameter: %s\nExiting.\n", argv[i]); exit (1); } /* Do we have Unicode support? */ if (fUnicodeClipboard) { printf ("Unicode clipboard I/O\n"); } else { printf ("Non Unicode clipboard I/O\n"); } /* Apply locale specified in the LANG environment variable */ if (!setlocale (LC_ALL, "")) { printf ("setlocale() error\n"); exit (1); } /* See if X supports the current locale */ if (XSupportsLocale () == False) { printf ("Locale not supported by X, falling back to 'C' locale.\n"); setlocale(LC_ALL, "C"); } winClipboardProc(fUnicodeClipboard, pszDisplay); return 0; }