int main(int argc, char *argv[]) { KCmdLineArgs::init(argc, argv, "krootimage", "kdmgreet", ki18n("KRootImage"), QByteArray(), ki18n("Fancy desktop background for kdm")); KCmdLineOptions options; options.add("+config", ki18n("Name of the configuration file")); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (!args->count()) args->usage(); KComponentData inst(KCmdLineArgs::aboutData()); MyApplication app(args->arg(0).toLocal8Bit(), KCmdLineArgs::qtArgc(), KCmdLineArgs::qtArgv()); args->clear(); app.exec(); app.flush(); // Keep color resources after termination XSetCloseDownMode(QX11Info::display(), RetainTemporary); return 0; }
RazorDeskManager::RazorDeskManager(const QString & configId, RazorSettings * config) : DesktopPlugin(configId, config) { m_launchMode = DesktopPlugin::launchModeFromString(config->value("icon-launch-mode").toString()); config->beginGroup(configId); bool makeIcons = config->value("icons", false).toBool(); //now we got the desktop we need to determine if the user wants a defined picture there QString finalPixmap = config->value("wallpaper", "").toString(); config->endGroup(); if (finalPixmap.isEmpty() || !QFile::exists(finalPixmap)) { //now we want to use the system default - we still need to find that one out though finalPixmap = razorTheme.desktopBackground(); qDebug() << "trying to get system-defaults" << finalPixmap; } if (! finalPixmap.isEmpty()) { qDebug() << "Creating wallpaper"; int width,height; QDesktopWidget * dw = QApplication::desktop(); if (dw->screenCount() == 1) { width=dw->width(); height = dw->height(); } else { width=dw->screenGeometry(-1).width(); height=dw->screenGeometry(-1).height(); } QPixmap pixmap(finalPixmap); pixmap = pixmap.scaled(width,height); Pixmap p = pixmap.handle(); XGrabServer(QX11Info::display()); XChangeProperty(QX11Info::display(), QX11Info::appRootWindow(), XfitMan::atom("_XROOTPMAP_ID"), XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &p, 1); XChangeProperty(QX11Info::display(), QX11Info::appRootWindow(), XfitMan::atom("ESETROOT_PMAP_ID"), XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &p, 1); XSetCloseDownMode(QX11Info::display(), RetainPermanent); XSetWindowBackgroundPixmap(QX11Info::display(), QX11Info::appRootWindow(), p); XClearWindow(QX11Info::display(), QX11Info::appRootWindow()); XUngrabServer(QX11Info::display()); XFlush(QX11Info::display()); } if (makeIcons) { deskicons = new RazorSettings("deskicons", this); m_fsw = new QFileSystemWatcher(QStringList() << QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), this); connect(m_fsw, SIGNAL(directoryChanged(const QString&)), this, SLOT(updateIconList())); updateIconList(); } }
int main(int argc, char *argv[]) { RootImageApp app(argc, argv); XSetCloseDownMode(QX11Info::display(), RetainTemporary); app.exec(); app.flush(); return 0; }
/* * fetch and/or set the ATOM_PAIRS. This is triggered at least once * by the first call to XmInternAtom(). */ extern void _XmInitAtomPairs(Display *display) { Window win; char *dstr; Display *d; DEBUGOUT(_LtDebug0(__FILE__, NULL, "%s:_XmInitAtomPairs(%d)\n", __FILE__, __LINE__)); if ((win = read_drag_window(display)) == None) { dstr = XDisplayString(display); d = XOpenDisplay(dstr); if (d == NULL) { _XmWarning((Widget)XmGetXmDisplay(display), "Where's your display?"); return; } XGrabServer(d); if ((win = read_drag_window(d)) == None) { XSetCloseDownMode(d, RetainPermanent); win = create_drag_window(d); write_drag_window(d, &win); } XCloseDisplay(d); } set_drag_window(display, win); if (!read_atom_pairs(display)) { XGrabServer(display); if (!read_atom_pairs(display)) { write_atom_pairs(display); } XUngrabServer(display); XFlush(display); } }
void fgPlatformCloseDisplay ( void ) { /* * Make sure all X-client data we have created will be destroyed on * display closing */ XSetCloseDownMode( fgDisplay.pDisplay.Display, DestroyAll ); /* * Close the display connection, destroying all windows we have * created so far */ XCloseDisplay( fgDisplay.pDisplay.Display ); }
static cairo_surface_t * create_root_surface (GdkScreen *screen) { Atom prop_root, prop_esetroot; gint number, width, height; Display *display; Pixmap pixmap; cairo_surface_t *surface; number = gdk_screen_get_number (screen); width = gdk_screen_get_width (screen); height = gdk_screen_get_height (screen); /* Open a new connection so with Retain Permanent so the pixmap remains when the greeter quits */ gdk_flush (); display = XOpenDisplay (gdk_display_get_name (gdk_screen_get_display (screen))); if (!display) { g_warning ("Failed to create root pixmap"); return NULL; } XSetCloseDownMode (display, RetainPermanent); pixmap = XCreatePixmap (display, RootWindow (display, number), width, height, DefaultDepth (display, number)); XCloseDisplay (display); /* Convert into a Cairo surface */ surface = cairo_xlib_surface_create (GDK_SCREEN_XDISPLAY (screen), pixmap, GDK_VISUAL_XVISUAL (gdk_screen_get_system_visual (screen)), width, height); /* Use this pixmap for the background */ XSetWindowBackgroundPixmap (GDK_SCREEN_XDISPLAY (screen), RootWindow (GDK_SCREEN_XDISPLAY (screen), number), cairo_xlib_surface_get_drawable (surface)); /* Fix to make the code work when a compositor is running */ Pixmap xpm = cairo_xlib_surface_get_drawable (surface); prop_root = XInternAtom(GDK_SCREEN_XDISPLAY (screen), "_XROOTPMAP_ID", False); prop_esetroot = XInternAtom(GDK_SCREEN_XDISPLAY (screen), "ESETROOT_PMAP_ID", False); XChangeProperty(GDK_SCREEN_XDISPLAY (screen), RootWindow (GDK_SCREEN_XDISPLAY (screen), number), prop_root, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &xpm, 1); XChangeProperty(GDK_SCREEN_XDISPLAY (screen), RootWindow (GDK_SCREEN_XDISPLAY (screen), number), prop_esetroot, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &xpm, 1); return surface; }
int main(int argc, char **argv) { Atom prop, type; int format; unsigned long length, after; unsigned char *data; if(argc != 2) { fprintf(stderr,"Xpmroot Version %s\n",VERSION); fprintf(stderr,"Usage: xpmroot xpmfile\n"); fprintf(stderr,"Try Again\n"); exit(1); } dpy = XOpenDisplay(display_name); if (!dpy) { fprintf(stderr, "Xpmroot: unable to open display '%s'\n", XDisplayName (display_name)); exit (2); } screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); SetRootWindow(argv[1]); prop = XInternAtom(dpy, "_XSETROOT_ID", False); (void)XGetWindowProperty(dpy, root, prop, 0L, 1L, True, AnyPropertyType, &type, &format, &length, &after, &data); if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0)) XKillClient(dpy, *((Pixmap *)data)); XChangeProperty(dpy, root, prop, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &rootXpm, 1); XSetCloseDownMode(dpy, RetainPermanent); XCloseDisplay(dpy); return 0; }
int main( int argc, char *argv[] ) { KApplication::disableAutoDcopRegistration(); KLocale::setMainCatalogue( "kdesktop" ); KCmdLineArgs::init( argc, argv, "krootimage", I18N_NOOP( "KRootImage" ), description, version ); KCmdLineArgs::addCmdLineOptions( options ); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (!args->count()) args->usage(); MyApplication app( args->arg( 0 ) ); args->clear(); app.exec(); app.flushX(); // Keep color resources after termination XSetCloseDownMode( qt_xdisplay(), RetainTemporary ); return 0; }
JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_XSetCloseDownMode(JNIEnv *env, jclass clazz, jlong display, jint mode) { AWT_CHECK_HAVE_LOCK(); XSetCloseDownMode((Display*)display, (int)mode); }
void *WindowThreadFunc(void *userdata){ tWindow *p = (tWindow*)userdata; int screen, startx, starty; unsigned long win_mask; XSetWindowAttributes win_attrib; XSizeHints sizehints; Display* ptemp; /* should probably pass these from main.. */ char **argv=NULL; int argc=0; if(vb)printf("ThreadFunc\n"); if ((p->display = XOpenDisplay(NULL)) == NULL) { fprintf(stderr, "warning: can't XOpenDisplay %s\n",XDisplayName(NULL)); return NULL; } if (vb) printf("XDisplay:%p\n",(void*)p->display); screen = DefaultScreen(p->display); startx = 10; starty = 20; win_mask = CWBackPixel | CWBorderPixel; win_attrib.border_pixel =WhitePixel(p->display,screen); win_attrib.background_pixel =WhitePixel(p->display,screen); /* BlackPixel */ win_attrib.override_redirect = 0; if(vb)printf("creating XWindow..\n"); p->window = XCreateWindow( p->display, DefaultRootWindow(p->display), startx,starty, p->width, p->height, 0, /* borderwidth */ DefaultDepth(p->display,screen), InputOutput, CopyFromParent, win_mask, &win_attrib ); /* tell the window manager NOT to quit on delete window - we will handle it */ /* if this doesn't go here, but later, then valgrind doesn't like it */ p->atom_delwin_proto = XInternAtom (p->display, "WM_PROTOCOLS",False); p->atom_delwin = XInternAtom (p->display, "WM_DELETE_WINDOW", False); XSetWMProtocols (p->display, p->window, &p->atom_delwin_proto, 1); XSetWMProtocols (p->display, p->window, &p->atom_delwin, 1); if(vb)printf("created X window:%p\n",(void*)p->window); sizehints.flags = PSize | PMinSize; /* let windowmanager decide - PPosition */ /* sizehints.x=0;sizehints.y=0; */ sizehints.height = p->height; sizehints.width = p->width; sizehints.min_height = sizehints.height; sizehints.min_width = sizehints.width; if (vb) printf("setting properties..\n"); XSetStandardProperties( p->display, p->window, p->name, "", None, /* icon name and pixmap */ argv, argc, &sizehints); /* GC gc = XCreateGC(p->display,p->window,0,NULL); */ XMapRaised(p->display, p->window); /* visible and on top - else XMapWindow */ XSelectInput(p->display, p->window, ExposureMask | KeyPressMask | DestroyNotify | StructureNotifyMask | PointerMotionMask | /* PointerMotionHintMask | */ ButtonPressMask | ButtonReleaseMask ); /* ClientMessage always reported */ /* _init_display(p, p->width,p->height); */ p->valid=1; /* = True; */ /* lock and unlock pthread->init mutex - this ensures that calling thread is in pthread_wait before we send continue condition back */ /* ( because condition_wait unlocks it) */ mutex_lock(&p->thread_init_mutex); mutex_unlock(&p->thread_init_mutex); if(vb)printf("X11:init condition send:%p\n", (void*)&p->thread_init_cond); condition_send(&p->thread_init_cond); while (1) { if (XPending(p->display)>0) if(handle_events(p->display, p )==False) break; usleep(100); }; mutex_lock(&p->mutex); p->valid=0; /* global lock should be made when querying or change any windows valid state. */ XSetCloseDownMode(p->display, DestroyAll); ptemp = p->display; p->display=NULL; XCloseDisplay(ptemp); /* after X close */ if(vb)printf("X11:freeing cairo surface\n"); /* _clean_display(p); */ mutex_unlock(&p->mutex); if(vb)printf("X11:window thread quit\n"); return NULL; }
/* Must be called in the gl thread */ static void gst_gl_window_finalize (GObject * object) { GstGLWindow *window = GST_GL_WINDOW (object); GstGLWindowPrivate *priv = window->priv; XEvent event; Bool ret = TRUE; g_mutex_lock (priv->x_lock); priv->parent = 0; XUnmapWindow (priv->device, priv->internal_win_id); ret = eglMakeCurrent (priv->device, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (!ret) g_debug ("failed to release opengl context\n"); eglDestroyContext (priv->device, priv->gl_context); eglTerminate (priv->device); XFree (priv->visual_info); XReparentWindow (priv->device, priv->internal_win_id, priv->root, 0, 0); XDestroyWindow (priv->device, priv->internal_win_id); XSync (priv->device, FALSE); while (XPending (priv->device)) XNextEvent (priv->device, &event); XSetCloseDownMode (priv->device, DestroyAll); /*XAddToSaveSet (display, w) Display *display; Window w; */ //FIXME: it seems it causes destroy all created windows, even by other display connection: //This is case in: gst-launch-0.10 videotestsrc ! tee name=t t. ! queue ! glimagesink t. ! queue ! glimagesink //When the first window is closed and so its display is closed by the following line, then the other Window managed by the //other glimagesink, is not useable and so each opengl call causes a segmentation fault. //Maybe the solution is to use: XAddToSaveSet //The following line is commented to avoid the disagreement explained before. //XCloseDisplay (priv->device); g_debug ("display receiver closed\n"); XCloseDisplay (priv->disp_send); g_debug ("display sender closed\n"); if (priv->cond_send_message) { g_cond_free (priv->cond_send_message); priv->cond_send_message = NULL; } g_mutex_unlock (priv->x_lock); if (priv->x_lock) { g_mutex_free (priv->x_lock); priv->x_lock = NULL; } G_OBJECT_CLASS (gst_gl_window_parent_class)->finalize (object); }
static void test_error_trapping (GdkDisplay *gdk_display) { Display *d; int dummy; int error; d = GDK_DISPLAY_XDISPLAY (gdk_display); /* verify that we can catch errors */ gdk_error_trap_push (); XListProperties (d, 0, &dummy); /* round trip */ error = gdk_error_trap_pop (); g_assert (error == BadWindow); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); /* not a round trip */ XSetCloseDownMode (d, DestroyAll); error = gdk_error_trap_pop (); g_assert (error == BadValue); /* try the same without sync */ gdk_error_trap_push (); XListProperties (d, 0, &dummy); gdk_error_trap_pop_ignored (); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); XSetCloseDownMode (d, DestroyAll); gdk_error_trap_pop_ignored (); XSync (d, TRUE); /* verify that we can catch with nested traps; inner-most * active trap gets the error */ gdk_error_trap_push (); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); error = gdk_error_trap_pop (); g_assert (error == BadValue); error = gdk_error_trap_pop (); g_assert (error == Success); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_push (); error = gdk_error_trap_pop (); g_assert (error == Success); error = gdk_error_trap_pop (); g_assert (error == BadValue); /* try nested, without sync */ gdk_error_trap_push (); gdk_error_trap_push (); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_pop_ignored (); gdk_error_trap_pop_ignored (); gdk_error_trap_pop_ignored (); XSync (d, TRUE); /* try nested, without sync, with interleaved calls */ gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_pop_ignored (); XSetCloseDownMode (d, 12345); gdk_error_trap_pop_ignored (); XSetCloseDownMode (d, 12345); gdk_error_trap_pop_ignored (); XSync (d, TRUE); /* don't want to get errors that weren't in our push range */ gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_push (); XSync (d, TRUE); /* not an error */ error = gdk_error_trap_pop (); g_assert (error == Success); error = gdk_error_trap_pop (); g_assert (error == BadValue); /* non-roundtrip non-error request after error request, inside trap */ gdk_error_trap_push (); XSetCloseDownMode (d, 12345); XMapWindow (d, DefaultRootWindow (d)); error = gdk_error_trap_pop (); g_assert (error == BadValue); /* a non-roundtrip non-error request before error request, inside trap */ gdk_error_trap_push (); XMapWindow (d, DefaultRootWindow (d)); XSetCloseDownMode (d, 12345); error = gdk_error_trap_pop (); g_assert (error == BadValue); /* Not part of any test, just a double-check * that all errors have arrived */ XSync (d, TRUE); }
int main (int argc, char **argv) { Cursor cursor; Display *display; Window root; unsigned long pixel; char *cname; XColor color; Atom prop; Pixmap save_pixmap = (Pixmap)None; //============================================ // open display and check if we got a display //-------------------------------------------- display = XOpenDisplay(NULL); if (!display) { exit (1); } if ((argc == 2) && (strcmp (argv[1],"--fast") == 0)) { XCloseDisplay(display); exit (0); } #if 0 // disabled: for details see bug: #273147 //============================================ // check the resolution //-------------------------------------------- if (!validResolution(display)) { fprintf (stderr, "testX: invalid dimensions, must be >= %dx%d Pixels\n", MIN_X,MIN_Y ); exit (2); } #endif //============================================ // install color map for background pixels //-------------------------------------------- cname = argc == 2 ? argv[1] : "black"; screen = DefaultScreen(display); root = RootWindow(display, screen); pixel = BlackPixel(display, screen); if(XParseColor(display, DefaultColormap(display, screen), cname, &color)) { if(XAllocColor(display, DefaultColormap(display, screen), &color)) { pixel = color.pixel; } } XSetWindowBackground(display, root, pixel); XClearWindow (display, root); //============================================ // set watch cursor //-------------------------------------------- cursor = CreateCursorFromName(display,"top_left_arrow"); if (cursor) { XDefineCursor (display, root, cursor); XFreeCursor (display, cursor); } //============================================ // run the windowmanager (FVWM) //-------------------------------------------- RunWindowManager(); //============================================ // save background as pixmap //-------------------------------------------- save_pixmap = XCreatePixmap ( display, root, 1, 1, 1 ); prop = XInternAtom (display, "_XSETROOT_ID", False); XChangeProperty ( display, root, prop, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &save_pixmap, 1 ); XSetCloseDownMode ( display, RetainPermanent ); //============================================ // enable accessX modifiers //-------------------------------------------- // XAccess (display,NULL); //============================================ // close display and exit //-------------------------------------------- XCloseDisplay(display); exit (0); }
/* **************************************************************** * Modifica o fundo da janela * **************************************************************** */ int set_background (Display *dpy, Window win, XImage *ximage, const char *name) { Pixmap pic; int ret = 0; /* * Cria o Pixmap correspondente à imagem. */ pic = XCreatePixmap ( dpy, win, ximage->width, ximage->height, DefaultDepth (dpy, screen) ); if (pic == 0) { msg ("\"%s\": o servidor X não pode criar o Mapa de Pixels", name); return (-1); } /* * Envia para o servidor o conteúdo do Pixmap (a imagem). */ if (XPutImage (dpy, pic, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height)) { msg ("\"%s\": o servidor X rejeitou a imagem", name); XFreePixmap (dpy, pic); return (-1); } /* * O Pixmap torna-se o fundo da janela. */ XSetWindowBackgroundPixmap (dpy, win, pic); if (Rflag) { Atom prop, type; uchar *data; ulong length, after; int format; XClearWindow (dpy, win); XFlush (dpy); prop = XInternAtom (dpy, "_XSETROOT_ID", False); (void)XGetWindowProperty ( dpy, win, prop, 0, 1, True, AnyPropertyType, &type, &format, &length, &after, &data ); #if (0) /*******************************************************/ /* NÃO SEI BEM PARA QUE SERVIA... */ if ( type == XA_PIXMAP && format == 32 && length == 1 && after == 0 ) XKillClient (dpy, *((Pixmap *)data)); #endif /*******************************************************/ XChangeProperty ( dpy, win, prop, XA_PIXMAP, 32, PropModeReplace, (uchar *)&pic, 1 ); XSetCloseDownMode (dpy, RetainPermanent); XFlush (dpy); ret = -1; } XFreePixmap (dpy, pic); return (ret); } /* end set_background */
/* startup initialization */ void ProxyInit(Display *dpy, Window dsdm_win) { enum { XA_MOTIF_DRAG_WINDOW, XA_MOTIF_DRAG_PROXY_WINDOW, XA_MOTIF_DRAG_AND_DROP_MESSAGE, XA_MOTIF_DRAG_INITIATOR_INFO, XA_MOTIF_DRAG_RECEIVER_INFO, XAXmTRANSFER_SUCCESS, XAXmTRANSFER_FAILURE, XA_MOTIF_DRAG_TARGETS, XA_SUN_DRAGDROP_TRIGGER, XA_SUN_DRAGDROP_DONE, XA_SUN_SELECTION_END, XA_SUN_SELECTION_ERROR, XA_SUN_DRAGDROP_ACK, XATARGETS, XAMULTIPLE, NUM_ATOMS }; static char* atom_names[] = { "_MOTIF_DRAG_WINDOW", "_MOTIF_DRAG_PROXY_WINDOW", "_MOTIF_DRAG_AND_DROP_MESSAGE", "_MOTIF_DRAG_INITIATOR_INFO", "_MOTIF_DRAG_RECEIVER_INFO", "XmTRANSFER_SUCCESS", "XmTRANSFER_FAILURE", "_MOTIF_DRAG_TARGETS", "_SUN_DRAGDROP_TRIGGER", "_SUN_DRAGDROP_DONE", "_SUN_SELECTION_END", "_SUN_SELECTION_ERROR", "_SUN_DRAGDROP_ACK", "TARGETS", "MULTIPLE" }; int i; enum { ATOM_BUF_LEN = 25 }; char buf[ATOM_BUF_LEN * DROP_TABLE_MAX]; char *buf_names[DROP_TABLE_MAX]; Atom buf_atoms[DROP_TABLE_MAX]; XSetWindowAttributes attr; Atom atoms[NUM_ATOMS]; InitializeByteOrder(); /* make motif_drag_win and proxy_win persistant */ XSetCloseDownMode(dpy, RetainPermanent); XInternAtoms(dpy, atom_names, NUM_ATOMS, False, atoms); ATOM_MOTIF_DRAG_WIN = atoms[XA_MOTIF_DRAG_WINDOW]; ATOM_MOTIF_PROXY_WIN = atoms[XA_MOTIF_DRAG_PROXY_WINDOW]; ATOM_MOTIF_DND_MESS = atoms[XA_MOTIF_DRAG_AND_DROP_MESSAGE]; ATOM_MOTIF_INITIATOR_INFO = atoms[XA_MOTIF_DRAG_INITIATOR_INFO]; ATOM_MOTIF_RECEIVER_INFO = atoms[XA_MOTIF_DRAG_RECEIVER_INFO]; ATOM_MOTIF_SUCCESS = atoms[XAXmTRANSFER_SUCCESS]; ATOM_MOTIF_FAILURE = atoms[XAXmTRANSFER_FAILURE]; ATOM_MOTIF_TARGETS = atoms[XA_MOTIF_DRAG_TARGETS]; ATOM_SUN_DND_TRIGGER = atoms[XA_SUN_DRAGDROP_TRIGGER]; ATOM_SUN_DND_DONE = atoms[XA_SUN_DRAGDROP_DONE]; ATOM_SUN_SELECTION_ERROR = atoms[XA_SUN_SELECTION_ERROR]; ATOM_SUN_SELECTION_END = atoms[XA_SUN_SELECTION_END]; ATOM_SUN_DND_ACK = atoms[XA_SUN_DRAGDROP_ACK]; ATOM_TARGETS = atoms[XATARGETS]; ATOM_MULTIPLE = atoms[XAMULTIPLE]; for (i=0; i<DROP_TABLE_MAX; i++) { buf_names[i] = buf + (ATOM_BUF_LEN * i); sprintf(buf_names[i], "DND_PROXY_HANDLE_%d", i); } XInternAtoms(dpy, buf_names, DROP_TABLE_MAX, False, buf_atoms); for (i=0; i<DROP_TABLE_MAX; i++) { drop_table[i].proxy_handle = buf_atoms[i]; drop_table[i].proxy_sel_req_win = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, 1, 1, 0, 0, InputOnly, CopyFromParent, 0, &attr); } motif_drag_win = GetPropertyWindow(dpy, DefaultRootWindow(dpy), ATOM_MOTIF_DRAG_WIN); /* if motif_drag_win doesn't exist then define and declare it */ if (motif_drag_win == None) { motif_drag_win = dsdm_win; XChangeProperty (dpy, DefaultRootWindow(dpy), ATOM_MOTIF_DRAG_WIN, XA_WINDOW, 32, PropModeReplace, (unsigned char *) &motif_drag_win, 1); } /* define and declare the proxy_window */ proxy_win = dsdm_win; XChangeProperty(dpy, motif_drag_win, ATOM_MOTIF_PROXY_WIN, /* property */ XA_WINDOW, /* type */ 32, /* format */ PropModeReplace, /* mode */ (unsigned char *) &proxy_win, /* data */ 1 ); #ifdef DEBUG printf("drag_win=0x%lx, proxy_win=0x%lx\n", motif_drag_win, proxy_win); #endif /* Watch for mapping of top level windows */ XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureNotifyMask); /* Watch for someone taking away proxy_win ownership */ XSelectInput(dpy, proxy_win, PropertyChangeMask); for(i=0; i<DROP_TABLE_MAX; i++) XSetSelectionOwner(dpy, drop_table[i].proxy_handle, proxy_win, CurrentTime); }
/* * Perform the freeglut deinitialization... */ void fgDeinitialize( void ) { SFG_Timer *timer; if( !fgState.Initialised ) { return; } /* If we're in game mode, we want to leave game mode */ if( fgStructure.GameModeWindow ) { glutLeaveGameMode(); } /* If there was a menu created, destroy the rendering context */ if( fgStructure.MenuContext ) { #if TARGET_HOST_POSIX_X11 /* Note that the MVisualInfo is not owned by the MenuContext! */ glXDestroyContext( fgDisplay.Display, fgStructure.MenuContext->MContext ); #endif free( fgStructure.MenuContext ); fgStructure.MenuContext = NULL; } fgDestroyStructure( ); while( ( timer = fgState.Timers.First) ) { fgListRemove( &fgState.Timers, &timer->Node ); free( timer ); } while( ( timer = fgState.FreeTimers.First) ) { fgListRemove( &fgState.FreeTimers, &timer->Node ); free( timer ); } #if !defined(_WIN32_WCE) if ( fgState.JoysticksInitialised ) fgJoystickClose( ); if ( fgState.InputDevsInitialised ) fgInputDeviceClose( ); #endif /* !defined(_WIN32_WCE) */ fgState.JoysticksInitialised = GL_FALSE; fgState.InputDevsInitialised = GL_FALSE; fgState.MouseWheelTicks = 0; fgState.MajorVersion = 1; fgState.MinorVersion = 0; fgState.ContextFlags = 0; fgState.ContextProfile = 0; fgState.Initialised = GL_FALSE; fgState.Position.X = -1; fgState.Position.Y = -1; fgState.Position.Use = GL_FALSE; fgState.Size.X = 300; fgState.Size.Y = 300; fgState.Size.Use = GL_TRUE; fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; fgState.DirectContext = GLUT_TRY_DIRECT_CONTEXT; fgState.ForceIconic = GL_FALSE; fgState.UseCurrentContext = GL_FALSE; fgState.GLDebugSwitch = GL_FALSE; fgState.XSyncSwitch = GL_FALSE; fgState.ActionOnWindowClose = GLUT_ACTION_EXIT; fgState.ExecState = GLUT_EXEC_STATE_INIT; fgState.KeyRepeat = GLUT_KEY_REPEAT_ON; fgState.Modifiers = INVALID_MODIFIERS; fgState.GameModeSize.X = -1; fgState.GameModeSize.Y = -1; fgState.GameModeDepth = -1; fgState.GameModeRefresh = -1; fgListInit( &fgState.Timers ); fgListInit( &fgState.FreeTimers ); fgState.IdleCallback = NULL; fgState.MenuStateCallback = ( FGCBMenuState )NULL; fgState.MenuStatusCallback = ( FGCBMenuStatus )NULL; fgState.SwapCount = 0; fgState.SwapTime = 0; fgState.FPSInterval = 0; if( fgState.ProgramName ) { free( fgState.ProgramName ); fgState.ProgramName = NULL; } #if TARGET_HOST_POSIX_X11 /* * Make sure all X-client data we have created will be destroyed on * display closing */ XSetCloseDownMode( fgDisplay.Display, DestroyAll ); /* * Close the display connection, destroying all windows we have * created so far */ XCloseDisplay( fgDisplay.Display ); #elif TARGET_HOST_MS_WINDOWS if( fgDisplay.DisplayName ) { free( fgDisplay.DisplayName ); fgDisplay.DisplayName = NULL; } /* Reset the timer granularity */ timeEndPeriod ( 1 ); #endif fgState.Initialised = GL_FALSE; }
Status XmuLookupStandardColormap(Display *dpy, int screen, VisualID visualid, unsigned int depth, Atom property, Bool replace, Bool retain) /* * dpy - specifies X server connection * screen - specifies screen of display * visualid - specifies the visual type * depth - specifies the visual type * property - a standard colormap property * replace - specifies whether to replace * retain - specifies whether to retain */ { Display *odpy; /* original display connection */ XStandardColormap *colormap; XVisualInfo vinfo_template, *vinfo; /* visual */ long vinfo_mask; unsigned long r_max, g_max, b_max; /* allocation */ int count; Colormap cmap; /* colormap ID */ Status status = 0; /* Match the requested visual */ vinfo_template.visualid = visualid; vinfo_template.screen = screen; vinfo_template.depth = depth; vinfo_mask = VisualIDMask | VisualScreenMask | VisualDepthMask; if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &count)) == NULL) return 0; /* Monochrome visuals have no standard maps */ if (vinfo->colormap_size <= 2) { XFree((char *) vinfo); return 0; } /* If the requested property already exists on this screen, and, * if the replace flag has not been set to true, return success. * lookup() will remove a pre-existing map if replace is true. */ if (lookup(dpy, screen, visualid, property, (XStandardColormap *) NULL, replace) && !replace) { XFree((char *) vinfo); return 1; } /* Determine the best allocation for this property under the requested * visualid and depth, and determine whether or not to use the default * colormap of the screen. */ if (!XmuGetColormapAllocation(vinfo, property, &r_max, &g_max, &b_max)) { XFree((char *) vinfo); return 0; } cmap = (property == XA_RGB_DEFAULT_MAP && visualid == XVisualIDFromVisual(DefaultVisual(dpy, screen))) ? DefaultColormap(dpy, screen) : None; /* If retaining resources, open a new connection to the same server */ if (retain) { odpy = dpy; if ((dpy = XOpenDisplay(XDisplayString(odpy))) == NULL) { XFree((char *) vinfo); return 0; } } /* Create the standard colormap */ colormap = XmuStandardColormap(dpy, screen, visualid, depth, property, cmap, r_max, g_max, b_max); /* Set the standard colormap property */ if (colormap) { XGrabServer(dpy); if (lookup(dpy, screen, visualid, property, colormap, replace) && !replace) { /* Someone has defined the property since we last looked. * Since we will not replace it, release our own resources. * If this is the default map, our allocations will be freed * when this connection closes. */ if (colormap->killid == ReleaseByFreeingColormap) XFreeColormap(dpy, colormap->colormap); } else if (retain) { XSetCloseDownMode(dpy, RetainPermanent); } XUngrabServer(dpy); XFree((char *) colormap); status = 1; } if (retain) XCloseDisplay(dpy); XFree((char *) vinfo); return status; }
//========================================= // prepare when ready //----------------------------------------- void prepare (void) { int count; char disp[80] = ""; if (displayname != NULL) { sprintf(disp,"DISPLAY=%s",displayname); putenv (disp); } //========================================= // start windowmanager... //----------------------------------------- wmpid = fork(); switch(wmpid) { case -1: perror("fork"); exit(1); break; case 0: execl(FVWM,"fvwm2","-f",FVWMRC,NULL); break; default: waitpid ( wmpid, NULL, WNOHANG | WUNTRACED ); } //========================================= // enable accessX... //----------------------------------------- XAccess(dpy,displayname); //========================================= // set the fashion style for all displays // including Xinerama handling here... //------------------------------------------ CountScreens (dpy); for (count = 0;count < scr_count; count++) { int bannerpid; int current_screen = scr[count]; Window root = RootWindow(dpy, current_screen); int depth = DefaultDepth(dpy,current_screen); char* display = (char*)malloc(sizeof(char)*128); char* dspstr = (char*)malloc(sizeof(char)*128); char* color = (char*)malloc(sizeof(char)*128); char screenStr [255] = ""; char x [128] = ""; char y [128] = ""; int x1,y1,width,height; GC mgc = DefaultGC(dpy,current_screen); Cursor cursor; //========================================= // set the background to darkSlateBlue //----------------------------------------- sprintf(color,"MidnightBlue"); if (blank) { sprintf(color,"black"); } XSetWindowBackground( dpy, root, NameToPixel( color,BlackPixel(dpy,current_screen),dpy,current_screen ) ); XClearWindow(dpy,root); XSetCloseDownMode(dpy, RetainPermanent); usleep (1000); if (blank) { XFlush(dpy); } //========================================= // set the corner marks //----------------------------------------- if (! blank) { setCorner ("10x15-0-0",dpy,current_screen); setCorner ("10x15-0+0",dpy,current_screen); setCorner ("10x15+0-0",dpy,current_screen); setCorner ("10x15+0+0",dpy,current_screen); //========================================= // set the bounding rectangle //----------------------------------------- setBounding (dpy,current_screen); //========================================= // set the SuSE Linux banner //----------------------------------------- if (DisplayPlanes (dpy, current_screen) >= 8) { sprintf(dspstr,"%s",displayname); dspstr = strtok (dspstr,"."); sprintf(display,"%s.%d",dspstr,current_screen); sprintf(x,"%d",DisplayWidth (dpy,current_screen) - 150); sprintf(y,"%d",DisplayHeight (dpy,current_screen) - 80); bannerpid = fork(); switch(bannerpid) { case -1: perror("fork"); exit(1); break; case 0: execl ( XBanner,"xbanner", "-file",XBannerFile,"-display",display, "-px",x,"-py",y,NULL ); break; default: waitpid ( bannerpid, NULL, 0 ); } //=================================================== // create a xlook banner on all non primary screen // pointing out, that this screen is not the one // the configuration program is running on //--------------------------------------------------- if (current_screen > 0) { int HasRender; sprintf(screenStr,"%s %d. %s 1.", gettext("Display"),count+1, gettext("Configuration on display") ); HasRender = XTestRender (dpy); if (! HasRender) { break; } img = setText ( dpy,current_screen,screenStr,&imgx,&imgy ); } //========================================= // set save area of the root window to be // restored on demand //----------------------------------------- x1 = DisplayWidth (dpy,current_screen) - 380; y1 = DisplayHeight (dpy,current_screen) - 120; width = 380; height = 120; save[current_screen].width = width; save[current_screen].height = height; save[current_screen].x1 = x1; save[current_screen].y1 = y1; save[current_screen].bg = XCreatePixmap ( dpy,root,width,height,depth ); XCopyArea ( dpy,root,save[current_screen].bg,mgc,x1,y1,width,height,0,0 ); } //========================================= // set the cursor look and feel //----------------------------------------- cursor = CreateCursorFromName(dpy,current_screen,"top_left_arrow"); if (cursor) { XDefineCursor (dpy,root,cursor); XFreeCursor (dpy,cursor); } } } //========================================= // Enter main loop, restore and redraw //----------------------------------------- if (! blank) { looppid = fork(); switch (looppid) { case -1: perror("fork"); exit(1); break; case 0: while(1) { usleep (50000); RedrawWindow(); } break; } } }
int main(int argc, char *argv[]) { Display *dpy = XOpenDisplay(NULL); int screen = DefaultScreen(dpy); Window root = RootWindow(dpy, screen); Visual *vis = DefaultVisual(dpy, screen); int screenDepth = DefaultDepth(dpy, screen); int screenWidth = DisplayWidth(dpy, screen); int screenHeight = DisplayHeight(dpy, screen); unsigned int offsetX = 0; unsigned int offsetY = 0; unsigned int i; for(i = 1; i < argc; i++) { int c = argv[i][1]; switch(c) { case 'x': if(++i < argc) offsetX = -atoi(argv[i]); break; case 'y': if(++i < argc) offsetY = -atoi(argv[i]); break; } } Imlib_Image image = imlib_load_image(argv[argc - 1]); if(image) { Pixmap bg = XCreatePixmap(dpy, root, screenWidth, screenHeight, screenDepth); imlib_context_set_image(image); imlib_context_set_display(dpy); imlib_context_set_visual(vis); imlib_context_set_drawable(bg); imlib_render_image_on_drawable(offsetX, offsetY); // Ripped out of xsetroot. Atom atomRoot = XInternAtom(dpy, "_XROOTPMAP_ID", False); XChangeProperty( dpy, root, atomRoot, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &bg, 1 ); XKillClient(dpy, AllTemporary); XSetCloseDownMode(dpy, RetainPermanent); XSetWindowBackgroundPixmap(dpy, root, bg); XClearWindow(dpy, root); XFlush(dpy); XSync(dpy, False); imlib_free_image(); } return 0; }
int main(int argc, char *argv[]) { // Minimal options char fullscreen = 1; if(argc != 1) { if(strcmp(argv[1], "-h") == 0) { printf("lock. Use -n to not go to leave the desktop visible\n"); return 0; } if(strcmp(argv[1], "-n") == 0) { fullscreen = 0; } } // Open Display Display *display = XOpenDisplay(NULL); XSetCloseDownMode(display, DestroyAll); // Initialize PAM pam_handle_t *pamh; struct pam_conv conv; conv.conv = pam_nocomm; if(pam_start("xscreensaver", (getpwuid(getuid()))->pw_name, &conv, &pamh) != PAM_SUCCESS) { exit(1); } // Create and map window XSetWindowAttributes at; at.override_redirect = 1; at.event_mask = KeyPressMask; Window w = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 100, 100, 1, CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect | CWEventMask, &at); XWindowAttributes xwa; XGetWindowAttributes(display, DefaultRootWindow(display), &xwa); if(fullscreen == 1) { XMoveResizeWindow(display, w, 0, 0, xwa.width, xwa.height); } else { XMoveResizeWindow(display, w, 0, 0, 1, 1); } XMapWindow(display, w); XRaiseWindow(display, w); XSync(display, False); // Wait for the WM to settle.. sleep(1); // Grab Pointer & Keyboard for(int tries=0; XGrabPointer(display, w, False, ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, w, None, CurrentTime) != GrabSuccess; tries++) { if(tries > 3) { exit(1); } sleep(1); } for(int tries=0; XGrabKeyboard(display, w, False, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess; tries++) { if(tries > 3) { exit(1); } sleep(1); } XSetWindowBackground(display, w, 0); XClearWindow(display, w); XSync(display, False); // Disable screen if(fullscreen == 1) { DPMSForceLevel(display, DPMSModeOff); } // Read password from keyboard events, // verify, loop where required XEvent xev; char inputBuffer[4]; int passwordBufferLength = 0; while(True) { // Read password passwordBufferLength = 0; while(True) { XNextEvent(display, &xev); if(xev.type != 2 /* KeyPress */) { continue; } KeySym keysym = XLookupKeysym((XKeyEvent *)&xev, 0); if(keysym == XK_BackSpace && passwordBufferLength > 0) { passwordBufferLength--; } else if(keysym == XK_Return) { break; } else if(XLookupString((XKeyEvent *)&xev, inputBuffer, 4, NULL, NULL) == 1) { int len = strlen(inputBuffer); if(passwordBufferLength + len < sizeof(passwordBuffer)) { memcpy(passwordBuffer + passwordBufferLength, inputBuffer, len); passwordBufferLength += len; } } } passwordBuffer[passwordBufferLength] = 0; // Verify password pam_set_item(pamh, PAM_AUTHTOK, passwordBuffer); if(pam_authenticate(pamh, PAM_SILENT) == PAM_SUCCESS) { break; } } // Clean up pam_end(pamh, 0); XUnmapWindow(display, w); XUngrabServer(display); XFlush(display); return 0; }
main() { Window w2; Display *dpy = XOpenDisplay(NIL); assert(dpy); Screen *scr = DefaultScreenOfDisplay(dpy); // CreateWindow Window w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XDestroyWindow(dpy, w); // CreateWindow with arguments XSetWindowAttributes swa; swa.background_pixel = WhitePixelOfScreen(scr); swa.bit_gravity = NorthWestGravity; swa.border_pixel = BlackPixelOfScreen(scr); swa.colormap = DefaultColormapOfScreen(scr); swa.cursor = None; swa.win_gravity = NorthGravity; w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixel | CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWWinGravity, &swa); // CreateWindow with other arguments XDestroyWindow(dpy, w); Pixmap pixmap = XCreatePixmap(dpy, RootWindowOfScreen(scr), 45, 25, DefaultDepthOfScreen(scr)); assert(pixmap); swa.background_pixmap = pixmap; swa.border_pixmap = pixmap; w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixmap | CWBorderPixmap, &swa); // ChangeWindowAttributes swa.backing_planes = 0x1; swa.backing_pixel = WhitePixelOfScreen(scr); swa.save_under = True; swa.event_mask = KeyPressMask | KeyReleaseMask; swa.do_not_propagate_mask = ButtonPressMask | Button4MotionMask; swa.override_redirect = False; XChangeWindowAttributes(dpy, w, CWBackingPlanes | CWBackingPixel | CWSaveUnder | CWEventMask | CWDontPropagate | CWOverrideRedirect, &swa); // GetWindowAttributes XWindowAttributes wa; Status success = XGetWindowAttributes(dpy, w, &wa); // DestroyWindow (done) // DestroySubwindows w2 = XCreateWindow(dpy, w, 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XDestroySubwindows(dpy, w); // ChangeSaveSet // Display *dpy2 = XOpenDisplay(NIL); // assert(dpy2); // XAddToSaveSet(dpy2, w); // XCloseDisplay(dpy2); // ReparentWindow w2 = XCreateWindow(dpy, RootWindowOfScreen(scr), 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XReparentWindow(dpy, w2, w, 10, 5); // MapWindow XMapWindow(dpy, w); // MapSubwindows XMapSubwindows(dpy, w); // UnmapWindow XUnmapWindow(dpy, w); // UnmapSubwindows XMapWindow(dpy, w); XUnmapSubwindows(dpy, w2); XMapSubwindows(dpy, w); // ConfigureWindow Window w3 = XCreateWindow(dpy, w, 10, 50, 100, 10, 2, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XMapWindow(dpy, w3); XWindowChanges wc; wc.x = -5; wc.y = -10; wc.width = 50; wc.height = 40; wc.border_width = 7; wc.sibling = w2; wc.stack_mode = Opposite; XConfigureWindow(dpy, w3, CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWSibling | CWStackMode, &wc); // CirculateWindow XCirculateSubwindows(dpy, w, RaiseLowest); // GetGeometry Window root; int x, y; unsigned width, height, border_width, depth; XGetGeometry(dpy, w, &root, &x, &y, &width, &height, &border_width, &depth); // QueryTree Window parent; Window *children; unsigned nchildren; success = XQueryTree(dpy, w, &root, &parent, &children, &nchildren); XFree(children); // InternAtom Atom a = XInternAtom(dpy, "WM_PROTOCOLS", True); // GetAtomName char *string = XGetAtomName(dpy, XA_PRIMARY); XFree(string); // ChangeProperty XStoreName(dpy, w, "test window"); // DeleteProperty XDeleteProperty(dpy, w, XA_WM_NAME); // GetProperty // TODO // ListProperties int num_prop; Atom *list = XListProperties(dpy, w, &num_prop); XFree(list); // SetSelectionOwner XSetSelectionOwner(dpy, XA_PRIMARY, w, 12000); XSetSelectionOwner(dpy, XA_SECONDARY, w, CurrentTime); // GetSelectionOwner Window wx = XGetSelectionOwner(dpy, XA_PRIMARY); // ConvertSelection XConvertSelection(dpy, XA_SECONDARY, XA_CURSOR, XA_POINT, w, CurrentTime); // SendEvent // GrabPointer std::cerr << "Grabbing" << std::endl; int res = XGrabPointer(dpy, w, False, Button5MotionMask | PointerMotionHintMask, GrabModeSync, GrabModeAsync, w, None, CurrentTime); XSync(dpy, False); // sleep(5); // UngrabPointer std::cerr << "Ungrabbing" << std::endl; XUngrabPointer(dpy, CurrentTime); // GrabButton XGrabButton(dpy, 3, ShiftMask | ControlMask, w, False, PointerMotionHintMask | Button2MotionMask, GrabModeAsync, GrabModeSync, None, None); XGrabButton(dpy, 2, AnyModifier, w, False, PointerMotionHintMask | Button2MotionMask, GrabModeAsync, GrabModeSync, None, None); // UngrabButton XUngrabButton(dpy, 2, LockMask, w); // ChangeActivePointerGrab XChangeActivePointerGrab(dpy, ButtonPressMask, None, CurrentTime); // GrabKeyboard XGrabKeyboard(dpy, w, True, GrabModeSync, GrabModeSync, 12000); // UngrabKeyboard XUngrabKeyboard(dpy, 13000); // GrabKey XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Tab), ShiftMask | Mod3Mask, w, True, GrabModeSync, GrabModeSync); // UngrabKey XUngrabKey(dpy, AnyKey, AnyModifier, w); // AllowEvents XAllowEvents(dpy, AsyncPointer, 14000); // GrabServer XGrabServer(dpy); // UngrabServer XUngrabServer(dpy); // QueryPointer Window child; int root_x, root_y, win_x, win_y; unsigned mask; Bool bres = XQueryPointer(dpy, w, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); // GetMotionEvents int nevents; XGetMotionEvents(dpy, w, 15000, 16000, &nevents); // TranslateCoordinates int dest_x, dest_y; XTranslateCoordinates(dpy, w, w2, 10, 20, &dest_x, &dest_y, &child); // WarpPointer XWarpPointer(dpy, w, w2, 0, 0, 100, 100, 20, 30); // SetInputFocus XSetInputFocus(dpy,w, RevertToPointerRoot, 17000); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, 17000); // GetInputFocus Window focus; int revert_to; XGetInputFocus(dpy, &focus, &revert_to); // QueryKeymap char keys_return[32]; XQueryKeymap(dpy, keys_return); // OpenFont Font fid = XLoadFont(dpy, "cursor"); // CloseFont XUnloadFont(dpy, fid); // QueryFont XFontStruct *fs = XLoadQueryFont(dpy, "cursor"); assert(fs); // QueryTextExtents int direction, font_ascent, font_descent; XCharStruct overall; XQueryTextExtents(dpy, fs -> fid, "toto", 4, &direction, &font_ascent, &font_descent, &overall); XQueryTextExtents(dpy, fs -> fid, "odd__length", 11, &direction, &font_ascent, &font_descent, &overall); XChar2b c2bs; c2bs.byte1 = '$'; c2bs.byte2 = 'B'; XQueryTextExtents16(dpy, fs -> fid, &c2bs, 1, &direction, &font_ascent, &font_descent, &overall); XQueryTextExtents(dpy, fs -> fid, longString, strlen(longString), &direction, &font_ascent, &font_descent, &overall); // ListFonts int actual_count; char **fontList = XListFonts(dpy, "*", 100, &actual_count); XFree((char *)fontList); // ListFontsWithInfo int count; XFontStruct *info; char **names = XListFontsWithInfo(dpy, "*", 100, &count, &info); XFreeFontInfo(names, info, count); // SetFontPath // GetFontPath int npaths; char **charList = XGetFontPath(dpy, &npaths); char **charList2 = new char *[npaths + 1]; memcpy(charList2, charList, npaths * sizeof(char *)); charList2[npaths] = charList2[0]; XSetFontPath(dpy, charList2, npaths + 1); XSetFontPath(dpy, charList, npaths); // Reset to some reasonnable value XFreeFontPath(charList); delete [] charList2; // CreatePixmap Pixmap pix2 = XCreatePixmap(dpy, w, 100, 200, DefaultDepthOfScreen(scr)); // FreePixmap XFreePixmap(dpy, pix2); // CreateGC Pixmap bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr), "\000\000\001\000\000\001\000\000\001\377\377\377", 3, 4); XGCValues gcv; gcv.function = GXand; gcv.plane_mask = 0x1; gcv.foreground = WhitePixelOfScreen(scr); gcv.background = BlackPixelOfScreen(scr); gcv.line_width = 2; gcv.line_style = LineDoubleDash; gcv.cap_style = CapProjecting; gcv.join_style = JoinRound; gcv.fill_style = FillStippled; gcv.fill_rule = EvenOddRule; gcv.arc_mode = ArcPieSlice; gcv.tile = pixmap; gcv.stipple = bitmap; gcv.ts_x_origin = 3; gcv.ts_y_origin = 4; gcv.font = fs -> fid; gcv.subwindow_mode = ClipByChildren; gcv.graphics_exposures = True; gcv.clip_x_origin = 5; gcv.clip_y_origin = 6; gcv.clip_mask = bitmap; gcv.dash_offset = 1; gcv.dashes = 0xc2; GC gc = XCreateGC(dpy, w, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | GCTile | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont | GCSubwindowMode | GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCDashOffset | GCDashList | GCArcMode, &gcv); // ChangeGC gcv.function = GXandReverse; // Only a few of these should appear, since the values are cached on the client side by the Xlib. XChangeGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, &gcv); // CopyGC GC gc2 = XCreateGC(dpy, w, 0, NIL); XCopyGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, gc2); // SetDashes XSetDashes(dpy, gc, 3, "\001\377\001", 3); // SetClipRectangles XRectangle rectangles[] = { { 10, 20, 30, 40 }, { 100, 200, 5, 3 }, { -5, 1, 12, 24 } }; XSetClipRectangles(dpy, gc, 12, 9, rectangles, SIZEOF(rectangles), Unsorted); // FreeGC // done already // ClearArea XClearArea(dpy, w, 30, 10, 10, 100, False); // CopyArea XCopyArea(dpy, w, pixmap, gc, 0, 0, 100, 100, 10, 10); // CopyPlane // This won't work if the Screen doesn't have at least 3 planes XCopyPlane(dpy, pixmap, w, gc, 20, 10, 40, 30, 0, 0, 0x4); // PolyPoint XDrawPoint(dpy, w, gc, 1, 2); XPoint points[] = { { 3, 4 }, { 5, 6 } }; XDrawPoints(dpy, w, gc, points, SIZEOF(points), CoordModeOrigin); // PolyLine XDrawLines(dpy, w, gc, points, SIZEOF(points), CoordModePrevious); // PolySegment XSegment segments[] = { { 7, 8, 9, 10 }, { 11, 12, 13, 14 }, { 15, 16, 17, 18 } }; XDrawSegments(dpy, w, gc, segments, SIZEOF(segments)); // PolyRectangle XDrawRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles)); // PolyArc XArc arcs[] = { { 10, 20, 30, 40, 50, 60 }, { -70, 80, 90, 100, 110, 120 }, { 10, 20, 30, 40, 50, -30 } }; XDrawArcs(dpy, w, gc, arcs, SIZEOF(arcs)); // FillPoly XFillPolygon(dpy, w, gc, points, SIZEOF(points), Convex, CoordModePrevious); // PolyFillRectangle XFillRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles)); // PolyFillArc XFillArcs(dpy, w, gc, arcs, SIZEOF(arcs)); // PutImage // GetImage XImage *image = XGetImage(dpy, w, 10, 20, 40, 30, AllPlanes, ZPixmap); XPutImage(dpy, w, gc, image, 0, 0, 50, 60, 40, 30); XSync(dpy, False); // Make the next request starts at the beginning of a packet // PolyText8 XTextItem textItems[3]; textItems[0].chars = "toto"; textItems[0].nchars = strlen(textItems[0].chars); textItems[0].delta = -3; textItems[0].font = fs->fid; textItems[1].chars = "titi"; textItems[1].nchars = strlen(textItems[1].chars); textItems[1].delta = 3; textItems[1].font = None; textItems[2].chars = "tutu"; textItems[2].nchars = strlen(textItems[2].chars); textItems[2].delta = 0; textItems[2].font = fs->fid; XDrawText(dpy, w, gc, 10, 10, textItems, 3); XTextItem textItems2[3]; textItems2[0].chars = "totox"; textItems2[0].nchars = strlen(textItems2[0].chars); textItems2[0].delta = -3; textItems2[0].font = fs->fid; textItems2[1].chars = "titi"; textItems2[1].nchars = strlen(textItems2[1].chars); textItems2[1].delta = 3; textItems2[1].font = None; textItems2[2].chars = "tutu"; textItems2[2].nchars = strlen(textItems2[2].chars); textItems2[2].delta = 0; textItems2[2].font = fs->fid; XDrawText(dpy, w, gc, 10, 10, textItems2, 3); // PolyText16 XChar2b c2b2[] = { 0, 't', 0, 'x' }; XTextItem16 items16[] = { { &c2bs, 1, -5, None }, { NULL, 0, 0, None }, { c2b2, 2, 0, fs -> fid } }; XDrawText16(dpy, w, gc, 10, 0, items16, SIZEOF(items16)); // ImageText8 XDrawImageString(dpy, w, gc, 10, 10, "toto", 4); // ImageText16 XDrawImageString16(dpy, w, gc, 10, 10, &c2bs, 1); XDrawImageString16(dpy, w, gc, 10, 20, c2b2, 2); // CreateColormap // Don't forget to tell the kids how it was when we had only 8 bits per pixel. Colormap colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None); // FreeColormap XFreeColormap(dpy, colormap); colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None); // CopyColormapAndFree Colormap colormap2 = XCopyColormapAndFree(dpy, colormap); // InstallColormap XInstallColormap(dpy, colormap2); // UninstallColormap XUninstallColormap(dpy, colormap2); // ListInstalledColormaps int num; Colormap *colormapList = XListInstalledColormaps(dpy, w, &num); // AllocColor XColor screen; screen.red = 0; screen.green = 32767; screen.blue = 65535; screen.flags = DoRed | DoGreen | DoBlue; success = XAllocColor(dpy, colormap, &screen); // AllocNamedColor XColor screen2, exact; success = XAllocNamedColor(dpy, colormap, "Wheat", &screen2, &exact); // AllocColorCells unsigned long plane_masks, pixels; success = XAllocColorCells(dpy, colormap, False, &plane_masks, 1, &pixels, 1); // AllocColorPlanes unsigned long rmask, gmask, bmask; success = XAllocColorPlanes(dpy, colormap, False, &pixels, 1, 0, 0, 0, &rmask, &gmask, &bmask); // FreeColors unsigned long pixels2[2] = { screen.pixel, screen2.pixel }; XFreeColors(dpy, colormap, pixels2, 2, 0); // StoreColors success = XAllocColorCells(dpy, colormap, False, NIL, 0, pixels2, 2); // On many contemporary (that is, year 2000) video cards, you can't allocate read / write cells // I want my requests to be sent, however. if (!success) { XSetErrorHandler(errorHandler); } XColor colors[2]; colors[0] = screen; colors[0].pixel = pixels2[0]; colors[1] = screen2; colors[1].pixel = pixels2[1]; XStoreColors(dpy, colormap, colors, 2); // StoreNamedColor XStoreNamedColor(dpy, colormap, "Wheat", colors[0].pixel, DoBlue); XSync(dpy, False); XSetErrorHandler(NIL); // Restore the default handler // QueryColors screen2.pixel = WhitePixelOfScreen(scr); XQueryColor(dpy, colormap, &screen2); // LookupColor success = XLookupColor(dpy, colormap, "DarkCyan", &exact, &screen); // CreateCursor Cursor cursor = XCreatePixmapCursor(dpy, pixmap, None, &exact, colors, 10, 10); // CreateGlyphCursor Cursor cursor2 = XCreateGlyphCursor(dpy, fs -> fid, fs -> fid, 'X', 0, &exact, colors); // FreeCursor XFreeCursor(dpy, cursor2); // RecolorCursor XRecolorCursor(dpy, cursor, colors, &exact); // QueryBestSize success = XQueryBestSize(dpy, CursorShape, RootWindowOfScreen(scr), 100, 20, &width, &height); // QueryExtension int major_opcode, first_event, first_error; XQueryExtension(dpy, "toto", &major_opcode, &first_event, &first_error); // ListExtensions int nextensions; char **extensionList = XListExtensions(dpy, &nextensions); for(char **p = extensionList; nextensions; nextensions--, p++) std::cout << *p << std::endl; XFree(extensionList); // ChangeKeyboardMapping // GetKeyboardMapping int min_keycodes, max_keycodes; XDisplayKeycodes(dpy, &min_keycodes, &max_keycodes); int keysyms_per_keycode; KeySym *keysyms = XGetKeyboardMapping(dpy, min_keycodes, max_keycodes - min_keycodes + 1, &keysyms_per_keycode); XChangeKeyboardMapping(dpy, min_keycodes, keysyms_per_keycode, keysyms, max_keycodes - min_keycodes + 1); // ChangeKeyboardControl // GetKeyboardControl XKeyboardState keyboardState; XGetKeyboardControl(dpy, &keyboardState); XKeyboardControl keyboardValues; keyboardValues.key_click_percent = keyboardState.key_click_percent; keyboardValues.bell_percent = keyboardState.bell_percent; keyboardValues.bell_pitch = keyboardState.bell_pitch; keyboardValues.bell_duration = keyboardState.bell_duration; keyboardValues.led = 1; keyboardValues.led_mode = LedModeOn; keyboardValues.key = min_keycodes; keyboardValues.auto_repeat_mode = AutoRepeatModeDefault; XChangeKeyboardControl(dpy, KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration | KBLed | KBLedMode | KBKey | KBAutoRepeatMode, &keyboardValues); // Bell XBell(dpy, 90); // ChangePointerControl // GetPointerControl int accel_numerator, accel_denominator, threshold; XGetPointerControl(dpy, &accel_numerator, &accel_denominator, &threshold); XChangePointerControl(dpy, True, True, accel_numerator, accel_denominator, threshold); // SetScreenSaver // GetScreenSaver int timeout, interval, prefer_blanking, allow_exposures; XGetScreenSaver(dpy, &timeout, &interval, &prefer_blanking, &allow_exposures); XSetScreenSaver(dpy, timeout, interval, prefer_blanking, allow_exposures); // ChangeHosts // ListHosts int nhosts; Bool state; XHostAddress *hostList = XListHosts(dpy, &nhosts, &state); XHostAddress host; host.family = FamilyInternet; host.length = 4; host.address = "\001\002\003\004"; XAddHost(dpy, &host); // SetAccessControl XSetAccessControl(dpy, EnableAccess); // SetCloseDownMode XSetCloseDownMode(dpy, RetainTemporary); // KillClient XKillClient(dpy, AllTemporary); // RotateProperties Atom properties[] = { XInternAtom(dpy, "CUT_BUFFER0", False), XInternAtom(dpy, "CUT_BUFFER1", False), XInternAtom(dpy, "CUT_BUFFER2", False) }; XRotateWindowProperties(dpy, RootWindowOfScreen(scr), properties, SIZEOF(properties), -1); // ForceScreenSaver XForceScreenSaver(dpy, ScreenSaverReset); // SetPointerMapping // GetPointerMapping unsigned char map[64]; int map_length = XGetPointerMapping(dpy, map, 64); XSetPointerMapping(dpy, map, map_length); // SetModifierMapping // GetModifierMapping XModifierKeymap *modmap = XGetModifierMapping(dpy); XSetModifierMapping(dpy, modmap); // NoOperation XNoOp(dpy); for(;;) { XEvent e; XNextEvent(dpy, &e); std::cout << "Got an event of type " << e.type << std::endl; } }
int main(int argc, char** argv) { Cursor cursor; Display *display; Window root; unsigned long pixel; char* cname; XColor color; Atom prop; Pixmap save_pixmap = (Pixmap)None; //============================================ // open display and check if we got a display //-------------------------------------------- display = XOpenDisplay(NULL); if (!display) { exit (1); } if ((argc == 2) && (strcmp(argv[1], "--fast") == 0)) { XCloseDisplay(display); exit (0); } //============================================ // install color map for background pixels //-------------------------------------------- cname = argc == 2 ? argv[1] : "black"; screen = DefaultScreen(display); root = RootWindow(display, screen); pixel = BlackPixel(display, screen); if (XParseColor(display, DefaultColormap(display, screen), cname, &color)) { if (XAllocColor(display, DefaultColormap(display, screen), &color)) { pixel = color.pixel; } } XSetWindowBackground(display, root, pixel); XClearWindow(display, root); //============================================ // set watch cursor //-------------------------------------------- cursor = CreateCursorFromName(display, "top_left_arrow"); if (cursor) { XDefineCursor(display, root, cursor); XFreeCursor(display, cursor); } //============================================ // run the windowmanager (FVWM) //-------------------------------------------- RunWindowManager(); //============================================ // save background as pixmap //-------------------------------------------- save_pixmap = XCreatePixmap(display, root, 1, 1, 1); prop = XInternAtom(display, "_XSETROOT_ID", False); XChangeProperty(display, root, prop, XA_PIXMAP, 32, PropModeReplace, (unsigned char*) &save_pixmap, 1); XSetCloseDownMode(display, RetainPermanent); //============================================ // close display and exit //-------------------------------------------- XCloseDisplay(display); exit (0); }
int main(int argc, char **argv) { Atom prop = None; Atom e_prop = None; Atom m_prop = None; Atom type; int format; unsigned long length, after; unsigned char *data; int i = 1; Bool e_killed = False; Bool Dummy = False; Bool RetainPixmap = False; if (argc < 2) { usage(0); fprintf(stderr, "Nothing to do, try again.\n"); exit(1); } dpy = XOpenDisplay(display_name); if (!dpy) { fprintf( stderr, "fvwm-root: unable to open display '%s'\n", XDisplayName (display_name)); exit(2); } screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); for (i = 1; i < argc - 1; i++) { if ( strcasecmp(argv[i], "-r") == 0 || strcasecmp(argv[i], "--retain-pixmap") == 0) { RetainPixmap = True; } else if ( strcasecmp(argv[i], "--no-retain-pixmap") == 0) { RetainPixmap = False; } else if ( strcasecmp(argv[i], "-d") == 0 || strcasecmp(argv[i], "--dummy") == 0) { Dummy = True; } else if ( strcasecmp(argv[i], "--no-dummy") == 0) { Dummy = False; } else if ( strcasecmp(argv[i], "--dither") == 0) { Dither = True; } else if ( strcasecmp(argv[i], "--no-dither") == 0) { NoDither = True; } else if ( strcasecmp(argv[i], "--color-limit") == 0) { use_our_color_limit = True; if (i+1 < argc) { i++; opt_color_limit = atoi(argv[i]); } } else if ( strcasecmp(argv[i], "--no-color-limit") == 0) { NoColorLimit = True; } else if ( strcasecmp(argv[i], "-h") == 0 || strcasecmp(argv[i], "-?") == 0 || strcasecmp(argv[i], "--help") == 0) { usage(1); exit(0); } else if ( strcasecmp(argv[i], "-V") == 0 || strcasecmp(argv[i], "--version") == 0) { fprintf(stdout, "%s\n", VERSION); exit(0); } else { fprintf( stderr, "fvwm-root: unknown option '%s'\n", argv[i]); fprintf( stderr, "Run '%s --help' to get the usage.\n", argv[0]); exit(1); } } if ( Dummy || strcasecmp(argv[argc-1], "-d") == 0 || strcasecmp(argv[argc-1], "--dummy") == 0) { Dummy = True; } else if ( strcasecmp(argv[argc-1], "-h") == 0 || strcasecmp(argv[argc-1], "-?") == 0 || strcasecmp(argv[argc-1], "--help") == 0) { usage(1); exit(0); } else if ( strcasecmp(argv[argc-1], "-V") == 0 || strcasecmp(argv[argc-1], "--version") == 0) { fprintf(stdout, "%s\n", VERSION); exit(0); } else { int rc; rc = SetRootWindow(argv[argc-1]); if (rc == -1) { exit(1); } } prop = XInternAtom(dpy, "_XSETROOT_ID", False); (void)XGetWindowProperty( dpy, root, prop, 0L, 1L, True, AnyPropertyType, &type, &format, &length, &after, &data); if (type == XA_PIXMAP && format == 32 && length == 1 && after == 0 && data != NULL && (Pixmap)(*(long *)data) != None) { XKillClient(dpy, *((Pixmap *)data)); } if (data != NULL) XFree(data); e_prop = XInternAtom(dpy, "ESETROOT_PMAP_ID", False); (void)XGetWindowProperty( dpy, root, e_prop, 0L, 1L, True, AnyPropertyType, &type, &format, &length, &after, &data); if (type == XA_PIXMAP && format == 32 && length == 1 && after == 0 && data != NULL && (Pixmap)(*(long *)data) != None) { e_killed = True; XKillClient(dpy, *((Pixmap *)data)); } if (e_killed && !Dummy) { m_prop = XInternAtom(dpy, "_XROOTPMAP_ID", False); XDeleteProperty(dpy, root, m_prop); } if (RetainPixmap && !Dummy) { long prop; prop = rootImage; if (data != NULL) XFree(data); XSetCloseDownMode(dpy, RetainPermanent); if (e_prop == None) e_prop = XInternAtom(dpy, "ESETROOT_PMAP_ID", False); if (m_prop == None) m_prop = XInternAtom(dpy, "_XROOTPMAP_ID", False); XChangeProperty( dpy, root, e_prop, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &prop, 1); XChangeProperty( dpy, root, m_prop, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &prop, 1); } else { long dp = (long)None; if (prop == None) prop = XInternAtom(dpy, "_XSETROOT_ID", False); XChangeProperty( dpy, root, prop, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &dp, 1); } XCloseDisplay(dpy); return 0; }
int main (int argc, char **argv) { Cursor cursor; Display *display; Window root, blub, *blubs = NULL; unsigned clients; unsigned long pixel; char *cname; XColor color; int cnt; Atom prop; Pixmap save_pixmap = (Pixmap)None; display = XOpenDisplay(NULL); if(!display) return 1; cname = argc == 2 ? argv[1] : "black"; screen = DefaultScreen(display); root = RootWindow(display, screen); pixel = BlackPixel(display, screen); if(XParseColor(display, DefaultColormap(display, screen), cname, &color)) { if(XAllocColor(display, DefaultColormap(display, screen), &color)) { pixel = color.pixel; } } XSetWindowBackground(display, root, pixel); XClearWindow(display, root); cursor = CreateCursorFromName(display,"watch"); if (cursor) { XDefineCursor (display, root, cursor); XFreeCursor (display, cursor); } if (fork() == 0) { Window win; XEvent xev; close(0); close(1); close(2); chdir("/"); display = XOpenDisplay(NULL); // open a client... if (display) { win = XCreateSimpleWindow ( display, root, 0, 0, 1, 1, 0, 0, pixel ); XSync(display, False); } // wait within event loop... for(;;) XNextEvent(display, &xev); } // wait until the child has opened a client cnt = 100; do { if (!XQueryTree (display, root, &blub, &blub, &blubs, &clients)) { XCloseDisplay(display); return 0; } usleep(50000); } while(clients < 1 && cnt--); save_pixmap = XCreatePixmap (display, root, 1, 1, 1); prop = XInternAtom (display, "_XSETROOT_ID", False); XChangeProperty ( display, root, prop, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &save_pixmap, 1 ); XSetCloseDownMode (display, RetainPermanent); // enable accessX // XAccess (display,NULL); XCloseDisplay(display); RunWindowManager(); return 0; }
void SetDeskPageBackground(const Command *c) { Display *dpy2 = NULL; Window root2 = None; int screen2; Pixmap pix = None; current_colorset = -1; /* FvwmBacker bg preperation */ switch (c->type) { case 1: /* solid colors */ case 2: /* colorset */ dpy2 = XOpenDisplay(displayName); if (!dpy2) { fvwm_msg(ERR, "FvwmBacker", "Fail to create a forking dpy, Exit!"); exit(2); } screen2 = DefaultScreen(dpy2); root2 = RootWindow(dpy2, screen2); if (RetainPixmap) { XSetCloseDownMode(dpy2, RetainPermanent); } XGrabServer(dpy2); DeleteRootAtoms(dpy2, root2); switch (c->type) { case 2: current_colorset = c->colorset; /* Process a colorset */ if (CSET_IS_TRANSPARENT(c->colorset)) { fvwm_msg(ERR,"FvwmBacker", "You cannot " "use a transparent colorset as " "background!"); XUngrabServer(dpy2); XCloseDisplay(dpy2); return; } else if (Pdepth != DefaultDepth(dpy2, screen2)) { fvwm_msg(ERR,"FvwmBacker", "You cannot " "use a colorset background if\n" "the fvwm depth is not equal " "to the root depth!"); XUngrabServer(dpy2); XCloseDisplay(dpy2); return; } else if (RetainPixmap) { pix = CreateBackgroundPixmap( dpy2, root2, MyDisplayWidth, MyDisplayHeight, &Colorset[c->colorset], DefaultDepth(dpy2, screen2), DefaultGC(dpy2, screen2), False); if (pix != None) { XSetWindowBackgroundPixmap( dpy2, root2, pix); XClearWindow(dpy2, root2); } } else { SetWindowBackground( dpy2, root2, MyDisplayWidth, MyDisplayHeight, &Colorset[c->colorset], DefaultDepth(dpy2, screen2), DefaultGC(dpy2, screen2), True); } break; case 1: /* Process a solid color request */ if (RetainPixmap) { GC gc; XGCValues xgcv; xgcv.foreground = c->solidColor; gc = fvwmlib_XCreateGC( dpy2, root2, GCForeground, &xgcv); pix = XCreatePixmap( dpy2, root2, 1, 1, DefaultDepth(dpy2, screen2)); XFillRectangle( dpy2, pix, gc, 0, 0, 1, 1); XFreeGC(dpy2, gc); } XSetWindowBackground(dpy2, root2, c->solidColor); XClearWindow(dpy2, root2); break; } SetRootAtoms(dpy2, root2, pix); XUngrabServer(dpy2); XCloseDisplay(dpy2); /* this XSync, Ungrab, ...etc */ break; case -1: case 0: default: if(c->cmdStr != NULL) { SendFvwmPipe(fvwm_fd, c->cmdStr, (unsigned long)0); } break; } }
int main (int argc, char **argv) { Visual *vis; Colormap cm; Display *_display; Imlib_Context context; Imlib_Image image; Pixmap pixmap; Imlib_Color_Modifier modifier = NULL; _display = XOpenDisplay (NULL); int width, height, depth, i, alpha; char str1[40]; char str2[40]; char str3[40]; char str4[40]; char str5[40]; int ck0; int w, h; w = 0; h = 0; char strA1[30] = "hwe"; char strA2[30] = "hwer"; const char jpg[15] = "jpg"; //1 const char png[15] = "png"; //2 char *A1; char *A2; strcpy(strA1, argv[argc-1]); strcpy(strA2, strA1); A1 = strstr(strA1, jpg); A2 = strstr(strA2, png); //check to be sure image format is written right or abort checkForNull(A1, A2); for (screen = 0; screen < ScreenCount (_display); screen++) { display = XOpenDisplay (NULL); context = imlib_context_new (); imlib_context_push (context); imlib_context_set_display (display); vis = DefaultVisual (display, screen); cm = DefaultColormap (display, screen); width = DisplayWidth (display, screen); height = DisplayHeight (display, screen); depth = DefaultDepth (display, screen); pixmap = XCreatePixmap (display, RootWindow (display, screen), width, height, depth); imlib_context_set_visual (vis); imlib_context_set_colormap (cm); imlib_context_set_drawable (pixmap); imlib_context_set_color_range (imlib_create_color_range ()); image = imlib_create_image (width, height); imlib_context_set_image (image); printf("1\n"); imlib_context_set_color (0, 0, 0, 255); imlib_image_fill_rectangle (0, 0, width, height); imlib_context_set_dither (1); imlib_context_set_blend (1); printf("2\n"); alpha = 255; for (i = 1; i < argc; i++) { if (modifier != NULL) { imlib_apply_color_modifier (); imlib_free_color_modifier (); } modifier = imlib_create_color_modifier (); imlib_context_set_color_modifier (modifier); if (strcmp (argv[i], "-alpha") == 0) { if ((++i) >= argc) { fprintf (stderr, "Missing alpha\n"); continue; } if (sscanf (argv[i], "%i", &alpha) == 0) { fprintf (stderr, "Bad alpha (%s)\n", argv[i]); continue; } } else if (strcmp (argv[i], "-solid") == 0) { Color c; if ((++i) >= argc) { fprintf (stderr, "Missing color\n"); continue; } if (parse_color (argv[i], &c, alpha) == 1) { fprintf (stderr, "Bad color (%s)\n", argv[i]); continue; } imlib_context_set_color (c.r, c.g, c.b, c.a); imlib_image_fill_rectangle (0, 0, width, height); } else if (strcmp (argv[i], "-clear") == 0) { imlib_free_color_range (); imlib_context_set_color_range (imlib_create_color_range ()); } else if (strcmp (argv[i], "-add") == 0) { Color c; if ((++i) >= argc) { fprintf (stderr, "Missing color\n"); continue; } if (parse_color (argv[i], &c, alpha) == 1) { fprintf (stderr, "Bad color (%s)\n", argv[i - 1]); continue; } imlib_context_set_color (c.r, c.g, c.b, c.a); imlib_add_color_to_color_range (1); } else if (strcmp (argv[i], "-addd") == 0) { Color c; int distance; if ((++i) >= argc) { fprintf (stderr, "Missing color\n"); continue; } if ((++i) >= argc) { fprintf (stderr, "Missing distance\n"); continue; } if (parse_color (argv[i - 1], &c, alpha) == 1) { fprintf (stderr, "Bad color (%s)\n", argv[i - 1]); continue; } if (sscanf (argv[i], "%i", &distance) == 1) { fprintf (stderr, "Bad distance (%s)\n", argv[i]); continue; } imlib_context_set_color (c.r, c.g, c.b, c.a); imlib_add_color_to_color_range (distance); } else if (strcmp (argv[i], "-gradient") == 0) { int angle; if ((++i) >= argc) { fprintf (stderr, "Missing angle\n"); continue; } if (sscanf (argv[i], "%i", &angle) == 1) { fprintf (stderr, "Bad angle (%s)\n", argv[i]); continue; } imlib_image_fill_color_range_rectangle (0, 0, width, height, angle); } else if (strcmp (argv[i], "-fill") == 0) { if ((++i) >= argc) { fprintf (stderr, "Missing image\n"); continue; } if ( load_Mod_image(Fill, argv[i], width, height, alpha, image, ck0) == 1) { fprintf (stderr, "Bad image (%s)\n", argv[i]); continue; } } else if (strcmp (argv[i], "-dia") == 0) { if((++i) >= argc) { fprintf(stderr, "missing Dia, and Image\n"); continue; } strcpy (str1, argv[i]); strcpy (str2, str1); if ( findX(str1, &w, &h) == 1 ) { fprintf(stderr, " Bad Format\n"); continue; } else if (findX(str2, &w, &h) == 0 && ((++i) >= argc)) { fprintf(stderr, "Missing Image\n"); continue; } else { //if format is correct then assign a number for //load_Mod_Image to check ck0 = -2; w = w; h = h; } if( load_Mod_image(Dia, argv[i], w, h, alpha, image, ck0) == 1 ) { fprintf(stderr, "Bad Image or Bad Image Dimensions \n"); } } else if (strcmp (argv[i], "-tile") == 0) { if ((++i) >= argc) { fprintf(stderr, "format 0 missing \n"); continue; } strcpy (str1, argv[i]); strcpy (str2, str1); strcpy (str3, str2); strcpy (str4, str3); strcpy (str5, str4); if ( findX(str1, &w, &h) == 3 && ((++i) >= argc)) { fprintf(stderr, "missing Image\n"); continue; } //check to see if format is -tile 0 else if (findX(str2, &w, &h) == 3) { ck0 = 3; if( load_Mod_image(Tile, argv[i], width, height, alpha, image, ck0) == 1 ) { fprintf(stderr, "Bad Image or Bad Image Dimensions \n"); continue; } } if (findX(str3, &w, &h) == 1) { fprintf(stderr, "bad format\n"); continue; } if (findX(str4, &w, &h) == 0 && ((++i) >= argc)) { fprintf(stderr, "missing something again\n"); continue; } if (findX (str5, &w, &h) == 0 ) { ck0 = 2; w = w; h = h; } if( load_Mod_image(Tile, argv[i], w, h, alpha, image, ck0) == 1 ) { fprintf(stderr, "Bad Image or Bad Image Dimension\n"); } } else if (strcmp (argv[i], "-center") == 0) { if ((++i) >= argc) { fprintf (stderr, "Missing image\n"); continue; } if (load_Mod_image (Center, argv[i], width, height, alpha, image, ck0) == 1) { fprintf (stderr, "Bad image (%s)\n", argv[i]); continue; } } else if (strcmp (argv[i], "-tint") == 0) { Color c; DATA8 r[256], g[256], b[256], a[256]; int j; if ((++i) >= argc) { fprintf (stderr, "Missing color\n"); continue; } if (parse_color (argv[i], &c, 255) == 1) { fprintf (stderr, "Bad color\n"); continue; } imlib_get_color_modifier_tables (r, g, b, a); for (j = 0; j < 256; j++) { r[j] = (DATA8) (((double) r[j] / 255.0) * (double) c.r); g[j] = (DATA8) (((double) g[j] / 255.0) * (double) c.g); b[j] = (DATA8) (((double) b[j] / 255.0) * (double) c.b); } imlib_set_color_modifier_tables (r, g, b, a); } else if (strcmp (argv[i], "-blur") == 0) { int intval; if ((++i) >= argc) { fprintf (stderr, "Missing value\n"); continue; } if (sscanf (argv[i], "%i", &intval) == 1) { fprintf (stderr, "Bad value (%s)\n", argv[i]); continue; } imlib_image_blur (intval); } else if (strcmp (argv[i], "-sharpen") == 0) { int intval; if ((++i) >= argc) { fprintf (stderr, "Missing value\n"); continue; } if (sscanf (argv[i], "%i", &intval) == 1) { fprintf (stderr, "Bad value (%s)\n", argv[i]); continue; } imlib_image_sharpen (intval); } else if (strcmp (argv[i], "-contrast") == 0) { double dblval; if ((++i) >= argc) { fprintf (stderr, "Missing value\n"); continue; } if (sscanf (argv[i], "%lf", &dblval) == 1) { fprintf (stderr, "Bad value (%s)\n", argv[i]); continue; } imlib_modify_color_modifier_contrast (dblval); } else if (strcmp (argv[i], "-brightness") == 0) { double dblval; if ((++i) >= argc) { fprintf (stderr, "Missing value\n"); continue; } if (sscanf (argv[i], "%lf", &dblval) == 1) { fprintf (stderr, "Bad value (%s)\n", argv[i]); continue; } imlib_modify_color_modifier_brightness (dblval); } else if (strcmp (argv[i], "-gamma") == 0) { double dblval; if ((++i) >= argc) { fprintf (stderr, "Missing value\n"); continue; } if (sscanf (argv[i], "%lf", &dblval) == 1) { fprintf (stderr, "Bad value (%s)\n", argv[i]); continue; } imlib_modify_color_modifier_gamma (dblval); } else if (strcmp (argv[i], "-flipv") == 0) { imlib_image_flip_vertical (); } else if (strcmp (argv[i], "-fliph") == 0) { imlib_image_flip_horizontal (); } else if (strcmp (argv[i], "-flipd") == 0) { imlib_image_flip_diagonal (); } else if (strcmp (argv[i], "-write") == 0) { if ((++i) >= argc) { fprintf (stderr, "Missing filename\n"); continue; } imlib_save_image (argv[i]); } else { usage (argv[0]); imlib_free_image (); imlib_free_color_range (); if (modifier != NULL) { imlib_context_set_color_modifier (modifier); imlib_free_color_modifier (); modifier = NULL; } XFreePixmap (display, pixmap); exit (1); } // end else } // end loop off of argc if (modifier != NULL) { imlib_context_set_color_modifier (modifier); imlib_apply_color_modifier (); imlib_free_color_modifier (); modifier = NULL; } imlib_render_image_on_drawable (0, 0); imlib_free_image (); imlib_free_color_range (); if (setRootAtoms (pixmap) == 0) fprintf (stderr, "Couldn't create atoms...\n"); XKillClient (display, AllTemporary); XSetCloseDownMode (display, RetainTemporary); XSetWindowBackgroundPixmap (display, RootWindow (display, screen), pixmap); XClearWindow (display, RootWindow (display, screen)); XFlush (display); XSync (display, False); imlib_context_pop (); imlib_context_free (context); } // end for loop off screen // } // frist if statment at start of main return 0; }
void Xinitialize (int width, int height) { XVisualInfo vinfo_return; XSetWindowAttributes wa; Pixmap mask, cur; XColor black, white; black.red = black.green = black.blue = 0; /* buggered if I care, its just for an invisible cursor :] */ white.red = white.green = white.blue = 0; xWidth = width; xHeight = height; #ifdef __DEBUG__ printf ("xshm: connecting to X server\n"); #endif if ((dp = XOpenDisplay (0)) == 0) { printf ("xshm: could not open X display\n"); exit (0); } XSetCloseDownMode (dp, DestroyAll); screen = DefaultScreen (dp); if (XMatchVisualInfo (dp, DefaultScreen (dp), 8, PseudoColor, &vinfo_return) == False) { printf ("X: Screen doesn't support PseudoColor!\n"); exit(666); } /* Make sure all is destroyed if killed off */ /* Make sure we can do PsuedoColor colormap stuff */ if (!XShmQueryExtension (dp)) { /* Check to see if the extensions are supported */ fprintf (stderr, "X server doesn't support MITSHM extension.\n"); exit(666); } else if (!XShmPixmapFormat (dp)) { fprintf (stderr, "X server doesn't do shared memory pixmaps.\n"); exit(666); } #ifdef __DEBUG__ else printf ("xshm: MITSHM present\n"); #endif wi = XCreateSimpleWindow (dp, RootWindow (dp, screen), 50, 50, xWidth, xHeight, 0, 0, 0); colours = XCreateColormap (dp, wi, DefaultVisual (dp, XDefaultScreen (dp)), AllocAll); XSetWindowColormap (dp, wi, colours); cur = XCreatePixmapFromBitmapData (dp, wi, (char *) nocursorm_bits, nocursorm_width, nocursorm_height, (unsigned long) 1, (unsigned long) 0, (unsigned int) 1); mask = XCreatePixmapFromBitmapData (dp, wi, (char *) nocursorm_bits, nocursorm_width, nocursorm_height, (unsigned long) 1, (unsigned long) 0, (unsigned int) 1); cursor = XCreatePixmapCursor (dp, cur, mask, &black, &white, 0, 0); XFreePixmap (dp, cur); XFreePixmap (dp, mask); XDefineCursor (dp, wi, cursor); XMapWindow(dp, wi); GetShmPixmap(); XSetWindowBackgroundPixmap (dp, wi, pixmap); XSelectInput(dp, wi, KeyPressMask|KeyReleaseMask|ButtonPressMask| ButtonReleaseMask|PointerMotionMask|LeaveWindowMask|ExposureMask); atexit( Xuninitialize ); }
/* * Perform the OpenGLUT deinitialization... */ void ogDeinitialize( void ) { SOG_Timer *timer; if( !ogState.Initialised ) { ogWarning( "ogDeinitialize(): " "No valid initialization has been performed." ); return; } /* If there was a menu created, destroy the rendering context */ if( ogStructure.MenuContext ) { free( ogStructure.MenuContext ); ogStructure.MenuContext = NULL; } ogDestroyStructure( ); while( timer = ogState.Timers.First ) { ogListRemove( &ogState.Timers, &timer->Node ); free( timer ); } while( timer = ogState.FreeTimers.First ) { ogListRemove( &ogState.FreeTimers, &timer->Node ); free( timer ); } ogJoystickShutdown(); ogState.Initialised = GL_FALSE; ogState.Position.X = -1; ogState.Position.Y = -1; ogState.Position.Use = GL_FALSE; ogState.Size.X = 300; ogState.Size.Y = 300; ogState.Size.Use = GL_TRUE; ogState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; ogState.ForceDirectContext = GL_FALSE; ogState.TryDirectContext = GL_TRUE; ogState.ForceIconic = GL_FALSE; ogState.UseCurrentContext = GL_FALSE; ogState.GLDebugSwitch = GL_FALSE; ogState.XSyncSwitch = GL_FALSE; ogState.ActionOnWindowClose = GLUT_ACTION_EXIT; ogState.ExecState = GLUT_EXEC_STATE_INIT; ogState.KeyRepeat = GLUT_KEY_REPEAT_ON; ogState.Modifiers = 0xffffffff; ogState.GameModeSize.X = 640; ogState.GameModeSize.Y = 480; ogState.GameModeDepth = 16; ogState.GameModeRefresh = 72; ogState.Time.Set = GL_FALSE; ogListInit( &ogState.Timers ); ogListInit( &ogState.FreeTimers ); ogState.IdleCallback = NULL; ogState.MenuStateCallback = ( OGCBMenuState )NULL; ogState.MenuStatusCallback = ( OGCBMenuStatus )NULL; ogState.SwapCount = 0; ogState.SwapTime = 0; ogState.FPSInterval = 0; if( ogState.ProgramName ) { free( ogState.ProgramName ); ogState.ProgramName = NULL; } #if TARGET_HOST_UNIX_X11 /* Ask that X-client data we have created be destroyed on display close. */ XSetCloseDownMode( ogDisplay.Display, DestroyAll ); /* Close display connection; destroy all windows we have created so far. */ XCloseDisplay( ogDisplay.Display ); #endif }
/* * Perform the freeglut deinitialization... */ void fgDeinitialize( void ) { SFG_Timer *timer; if( !fgState.Initialised ) { fgWarning( "fgDeinitialize(): " "no valid initialization has been performed" ); return; } /* fgState.Initialised = GL_FALSE; */ /* * If there was a menu created, destroy the rendering context */ if( fgStructure.MenuContext ) { free( fgStructure.MenuContext ); fgStructure.MenuContext = NULL; } fgDestroyStructure( ); while( (timer = fgState.Timers.First) ) { fgListRemove( &fgState.Timers, &timer->Node ); free( timer ); } while( (timer = fgState.FreeTimers.First) ) { fgListRemove( &fgState.FreeTimers, &timer->Node ); free( timer ); } #ifndef _WIN32_WCE fgJoystickClose( ); #endif fgState.Initialised = GL_FALSE; fgState.Position.X = -1; fgState.Position.Y = -1; fgState.Position.Use = GL_FALSE; fgState.Size.X = 240; fgState.Size.Y = 320; fgState.Size.Use = GL_TRUE; fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; fgState.ForceDirectContext = GL_FALSE; fgState.TryDirectContext = GL_TRUE; fgState.ForceIconic = GL_FALSE; fgState.UseCurrentContext = GL_FALSE; fgState.GLDebugSwitch = GL_FALSE; fgState.XSyncSwitch = GL_FALSE; fgState.ActionOnWindowClose = GLUT_ACTION_EXIT; fgState.ExecState = GLUT_EXEC_STATE_INIT; fgState.IgnoreKeyRepeat = GL_TRUE; fgState.Modifiers = 0xffffffff; fgState.GameModeSize.X = 240; fgState.GameModeSize.Y = 320; fgState.GameModeDepth = 16; fgState.GameModeRefresh = 72; fgState.Time.Set = GL_FALSE; fgListInit( &fgState.Timers ); fgListInit( &fgState.FreeTimers ); fgState.IdleCallback = NULL; fgState.MenuStateCallback = ( FGCBMenuState )NULL; fgState.MenuStatusCallback = ( FGCBMenuStatus )NULL; fgState.SwapCount = 0; fgState.SwapTime = 0; fgState.FPSInterval = 0; if( fgState.ProgramName ) { free( fgState.ProgramName ); fgState.ProgramName = NULL; } __glDestroy(); #if TARGET_HOST_UNIX_X11 /* * Make sure all X-client data we have created will be destroyed on * display closing */ XSetCloseDownMode( fgDisplay.Display, DestroyAll ); /* * Close the display connection, destroying all windows we have * created so far */ XCloseDisplay( fgDisplay.Display ); #endif }
static void renderer_update_X11_background( Display *display, GdkPixbuf *image ) { Atom prop_root, prop_esetroot, type; Window root; Pixmap pmap_d1, pmap_d1_mask; int format; root = RootWindow( display, DefaultScreen( display ) ); // Create the Pixmap and the transparency map (we do not use) gdk_pixbuf_xlib_render_pixmap_and_mask( image, &pmap_d1, &pmap_d1_mask, 0 ); // Free the mask XFreePixmap( display, pmap_d1_mask ); // Not sure about this one, copied from FEH. prop_root = XInternAtom( display, "_XROOTPMAP_ID", True ); prop_esetroot = XInternAtom( display, "ESETROOT_PMAP_ID", True ); // If properties exist, kill the client that set this data. // and free it resources. if ( prop_root != None && prop_esetroot != None ) { unsigned long length,after; unsigned char *data_root, *data_esetroot; XGetWindowProperty( display, root, prop_root, 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, &data_root ); if ( type == XA_PIXMAP ) { XGetWindowProperty( display, root, prop_esetroot, 0L, 1L, False, AnyPropertyType, &type, &format, &length, &after, &data_esetroot ); if ( data_root && data_esetroot ) { if ( type == XA_PIXMAP && *( ( Pixmap * ) data_root ) == *( ( Pixmap * ) data_esetroot ) ) { XKillClient( display, *( ( Pixmap * ) data_root ) ); XSync( display, False ); } } if ( data_esetroot ) XFree( ( void * )data_esetroot ); } if ( data_root ) XFree( ( void * )data_root ); } /* This will locate the property, creating it if it doesn't exist */ prop_root = XInternAtom( display, "_XROOTPMAP_ID", False ); prop_esetroot = XInternAtom( display, "ESETROOT_PMAP_ID", False ); if ( prop_root == None || prop_esetroot == None ) { fprintf( stderr, "creation of pixmap property failed." ); return; } // Store the pmap_d1 in the X server. XChangeProperty( display, root, prop_root, XA_PIXMAP, 32, PropModeReplace, ( unsigned char * ) &pmap_d1, 1 ); XChangeProperty( display, root, prop_esetroot, XA_PIXMAP, 32, PropModeReplace, ( unsigned char * ) &pmap_d1, 1 ); // Set it XSetWindowBackgroundPixmap( display, root, pmap_d1 ); XClearWindow( display, root ); XSync( display, True ); // Make sure X keeps the data we set. XSetCloseDownMode( display, RetainPermanent ); }