static void terminate_x_connection() { int fd = XConnectionNumber(XimServer::gDpy); remove_current_fd_watch(fd); }
/****************************************************************************** StartMeUp - Do X initialization things ******************************************************************************/ void StartMeUp() { if (!(dpy = XOpenDisplay(""))) { fprintf(stderr,"%s: can't open display %s", Module, XDisplayName("")); exit (1); } x_fd = XConnectionNumber(dpy); screen= DefaultScreen(dpy); Root = RootWindow(dpy, screen); d_depth = DefaultDepth(dpy, screen); ScreenHeight = DisplayHeight(dpy,screen); ScreenWidth = DisplayWidth(dpy,screen); if ((ButtonFont=XLoadQueryFont(dpy,font_string))==NULL) { if ((ButtonFont=XLoadQueryFont(dpy,"fixed"))==NULL) exit(1); } fontheight = ButtonFont->ascent+ButtonFont->descent; win_width=XTextWidth(ButtonFont,"XXXXXXXXXXXXXXX",10); }
/* Initialise the command connection. This should be called after the X * server connection is established. */ void init_command(unsigned char *command,unsigned char **argv) { #ifdef GREEK_KBD greek_init(GreekMode); /*atexit(greek_end); not necessary */ #endif /* Enable the delete window protocol. */ wm_del_win = XInternAtom(display,"WM_DELETE_WINDOW",False); XSetWMProtocols(display,main_win,&wm_del_win,1); if ((comm_fd = run_command(command,argv)) < 0) { error("Quitting"); clean_exit(1); } x_fd = XConnectionNumber(display); #if defined(_HPUX_SOURCE) || defined(__Lynx__) fd_width = sysconf(_SC_OPEN_MAX); #else fd_width = getdtablesize(); #endif com_buf_next = com_buf_top = com_buf; }
// Wait for an event (either XEvent, or an internal Message) bool sleepUntilEvent (const int timeoutMs) { if (! isEmpty()) return true; if (display != 0) { ScopedXLock xlock; if (XPending (display)) return true; } struct timeval tv; tv.tv_sec = 0; tv.tv_usec = timeoutMs * 1000; int fd0 = getWaitHandle(); int fdmax = fd0; fd_set readset; FD_ZERO (&readset); FD_SET (fd0, &readset); if (display != 0) { ScopedXLock xlock; int fd1 = XConnectionNumber (display); FD_SET (fd1, &readset); fdmax = jmax (fd0, fd1); } const int ret = select (fdmax + 1, &readset, 0, 0, &tv); return (ret > 0); // ret <= 0 if error or timeout }
static PyObject *PyFFFont_removeGtkWindowToMainEventLoop(PyFF_Font *self, PyObject *args) { PyObject *result = NULL; PyObject *temp; int v = 0; if ( !PyArg_ParseTuple( args, "i", &v )) return( NULL ); gpointer gdkwindow = gdk_xid_table_lookup( v ); if( gdkwindow ) { Display* d = GDK_WINDOW_XDISPLAY(gdkwindow); int fd = XConnectionNumber(d); if( fd ) { gpointer udata = 0; GDrawRemoveReadFD( 0, fd, udata ); } } /* Boilerplate to return "None" */ Py_INCREF(Py_None); result = Py_None; return result; }
static PyObject *PyFFFont_getGtkWindowMainEventLoopFD(PyFF_Font *self, PyObject *args) { PyObject *result = NULL; PyObject *temp; int v = 0; if ( !PyArg_ParseTuple( args, "i", &v )) return( NULL ); gpointer gdkwindow = gdk_xid_table_lookup( v ); if( gdkwindow ) { Display* d = GDK_WINDOW_XDISPLAY(gdkwindow); int fd = XConnectionNumber(d); if( fd ) { return( Py_BuildValue("i", fd )); } } /* Boilerplate to return "None" */ Py_INCREF(Py_None); result = Py_None; return result; }
static int pretrans_setup() { int fd = XConnectionNumber(XimServer::gDpy); add_fd_watch(fd, READ_OK, xEventRead); return fd; }
static xrandrt_t *xrandrt_init(const char *display_name) { xrandrt_t *xr; int fd; Display *disp; disp = XOpenDisplay(display_name); if ((xr = malloc(sizeof(*xr))) == NULL) { if (disp != NULL) XCloseDisplay(disp); } else { fd = XConnectionNumber(disp); memset(xr, 0, sizeof(*xr)); xr->disp = disp; xr->chan = g_io_channel_unix_new(fd); xr->evsrc = g_io_add_watch(xr->chan, G_IO_IN|G_IO_HUP|G_IO_ERR, xevent_cb,xr); printf("videoep: xrandr initialized\n"); { Window root; Visual *vis; int sno; unsigned long wp; unsigned long bp; Window win; int depth; XSetWindowAttributes attr; unsigned long mask; root = XDefaultRootWindow(disp); sno = XDefaultScreen(disp); vis = XDefaultVisual(disp, sno); depth = XDefaultDepth(disp, sno); bp = XBlackPixel(disp, sno); wp = XWhitePixel(disp, sno); mask = CWBackPixel | CWBorderPixel | CWEventMask; attr.background_pixel = wp; attr.border_pixel = bp; attr.event_mask = ButtonPressMask | FocusChangeMask; win = XCreateWindow(disp, root, 50,50, 400,300, 1, depth, InputOutput, vis, mask, &attr); XMapWindow(disp,win); XFlush(disp); } } return xr; }
static int init() { XWindowAttributes wa; XSetWindowAttributes swa; XGCValues gcv; Window root; XConfigureEvent ce; d = XOpenDisplay(0); if (!d) die("cannot open display"); root = DefaultRootWindow(d); XGetWindowAttributes(d, root, &wa); visual = wa.visual; cmap = wa.colormap; screen = DefaultScreen(d); depth = DefaultDepth(d, screen); /* create the main window */ win = XCreateSimpleWindow(d, root, 0, 0, Width, Height, 0, 0, WhitePixel(d, screen)); swa.backing_store = WhenMapped; swa.bit_gravity = NorthWestGravity; XChangeWindowAttributes(d, win, CWBackingStore|CWBitGravity, &swa); XStoreName(d, win, "ED"); XSelectInput(d, win, StructureNotifyMask|ButtonPressMask|ButtonReleaseMask|Button1MotionMask|KeyPressMask|ExposureMask); /* simulate an initial resize and map the window */ ce.type = ConfigureNotify; ce.width = Width; ce.height = Height; XSendEvent(d, win, False, StructureNotifyMask, (XEvent *)&ce); XMapWindow(d, win); /* allocate font */ font = XftFontOpenName(d, screen, FONTNAME); if (!font) die("cannot open default font"); /* initialize gc */ gcv.foreground = WhitePixel(d, screen); gcv.graphics_exposures = False; gc = XCreateGC(d, win, GCForeground|GCGraphicsExposures, &gcv); /* initialize back buffer and Xft drawing context */ pbuf = XCreatePixmap(d, win, Width, Height, depth); xft = XftDrawCreate(d, pbuf, visual, cmap); /* set the action rectangle */ gui_x11.actionr.w = HMargin - 3; gui_x11.actionr.h = VMargin + font->height; return XConnectionNumber(d); }
void ParadynTkGUI::CloseTkConnection( void ) { #if !defined(i386_unknown_nt4_0) Display* disp = Tk_Display( Tk_MainWindow(interp) ); int fd = XConnectionNumber( disp ); close( fd ); #else // we don't need to worry about closing the Tk connection // under Windows, because the process created by CreateProcess() // doesn't interfere with our use of Tk #endif // defined(i386_unknown_nt4_0) }
void QEventLoop::init() { // initialize the common parts of the event loop pipe( d->thread_pipe ); fcntl(d->thread_pipe[0], F_SETFD, FD_CLOEXEC); fcntl(d->thread_pipe[1], F_SETFD, FD_CLOEXEC); d->sn_highest = -1; // intitialize the X11 parts of the event loop d->xfd = -1; if ( qt_is_gui_used ) d->xfd = XConnectionNumber( QPaintDevice::x11AppDisplay() ); }
void xt_client_xloop_create(void) { /* If this is the first running widget, hook this display into the mainloop */ if (0 == num_widgets) { int cnumber; GSource* gs; /* Set up xtdisplay in case we're missing one */ if (!xtdisplay) { (void)xt_client_get_display(); } /* * hook Xt event loop into the glib event loop. */ /* the assumption is that gtk_init has already been called */ gs = g_source_new(&xt_event_funcs, sizeof(GSource)); if (!gs) { return; } g_source_set_priority(gs, GDK_PRIORITY_EVENTS); g_source_set_can_recurse(gs, TRUE); tag = g_source_attach(gs, (GMainContext*)NULL); g_source_unref(gs); #ifdef VMS cnumber = XConnectionNumber(xtdisplay); #else cnumber = ConnectionNumber(xtdisplay); #endif xt_event_poll_fd.fd = cnumber; xt_event_poll_fd.events = G_IO_IN; xt_event_poll_fd.revents = 0; /* hmm... is this correct? */ g_main_context_add_poll ((GMainContext*)NULL, &xt_event_poll_fd, G_PRIORITY_LOW); /* add a timer so that we can poll and process Xt timers */ xt_polling_timer_id = g_timeout_add(25, (GtkFunction)xt_event_polling_timer_callback, xtdisplay); } /* Bump up our usage count */ num_widgets++; }
/* Initialise the command connection. This should be called after the X * server connection is established. */ void init_command(char* command, char** argv) { /* Enable the delete window protocol. */ wm_del_win = XInternAtom(display,"WM_DELETE_WINDOW",False); XSetWMProtocols(display,main_win,&wm_del_win,1); if ((comm_fd = run_command(command,argv)) < 0) { error("Quitting"); quit(1); } x_fd = XConnectionNumber(display); com_buf_next = com_buf_top = com_buf; com_stack_top = com_stack; }
/* this should be called first */ int APP_CC xcommon_init(void) { if (g_display != 0) { LOG(10, ("xcommon_init: xcommon_init already called")); return 0; } g_display = XOpenDisplay(0); if (g_display == 0) { LOGM((LOG_LEVEL_ERROR, "xcommon_init: error, XOpenDisplay failed")); return 1; } LOG(0, ("xcommon_init: connected to display ok")); /* setting the error handlers can cause problem when shutting down chansrv on some xlibs */ XSetErrorHandler(xcommon_error_handler); //XSetIOErrorHandler(xcommon_fatal_handler); g_x_socket = XConnectionNumber(g_display); if (g_x_socket == 0) { LOGM((LOG_LEVEL_ERROR, "xcommon_init: XConnectionNumber failed")); return 1; } g_x_wait_obj = g_create_wait_obj_from_socket(g_x_socket, 0); g_screen_num = DefaultScreen(g_display); g_screen = ScreenOfDisplay(g_display, g_screen_num); g_root_window = RootWindowOfScreen(g_screen); g_wm_delete_window_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", 0); g_wm_protocols_atom = XInternAtom(g_display, "WM_PROTOCOLS", 0); g_utf8_string = XInternAtom(g_display, "UTF8_STRING", 0); g_net_wm_name = XInternAtom(g_display, "_NET_WM_NAME", 0); g_wm_state = XInternAtom(g_display, "WM_STATE", 0); return 0; }
/* * actually start the display up, after all the user interaction has * been done. */ void StartWindow(int ratWidth, int ratHeight) { XSelectInput(dpy, mwWindow, KeyPressMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask | FocusChangeMask); HourGlassCursor(); initMaze(); SwapBitmaps(); displayFD = XConnectionNumber(dpy); XMapWindow(dpy, mwWindow); /* Map window to screen */ initRats(ratWidth, ratHeight); }
/* Procedure d'initialisation du serveur X et des variables globales*/ void Xinit(int IsFather) { char *name; Atom myatom; int i=16; /* Connextion au serveur X */ #ifdef DEBUG __bounds_debug_no_checking=True; #endif x11base->display=XOpenDisplay(NULL); if (x11base->display==NULL) { fprintf(stderr,"Enable to open display.\n"); exit(1); } #ifdef DEBUG __bounds_debug_no_checking=False; #endif if (IsFather) { name=(char*)calloc(sizeof(char),strlen("FvwmScript")+5); do { sprintf(name,"%c%xFvwmScript",161,i); i++; myatom=XInternAtom(x11base->display,name,False); } while (XGetSelectionOwner(x11base->display,myatom)!=None); x11base->TabScriptId[1]=name; x11base->TabScriptId[0]=NULL; } x11base->NbChild=0; x11base->screen=DefaultScreen(x11base->display); x11base->WhitePix=WhitePixel(x11base->display,x11base->screen); x11base->BlackPix=BlackPixel(x11base->display,x11base->screen); x11base->depth=XDefaultDepth(x11base->display,x11base->screen); x11base->colormap = DefaultColormap(x11base->display,x11base->screen); x11base->root = RootWindow(x11base->display,x11base->screen); x_fd = XConnectionNumber(x11base->display); }
int initXconnection() { x11Display = XOpenDisplay(NULL); if (x11Display != 0L) { XSetIOErrorHandler(xio_errhandler); XCreateSimpleWindow(x11Display, DefaultRootWindow(x11Display), 0, 0, 1, 1, 0, BlackPixelOfScreen(DefaultScreenOfDisplay(x11Display)), BlackPixelOfScreen(DefaultScreenOfDisplay(x11Display))); return XConnectionNumber(x11Display); } else { kdWarning(1205) << "Can't connect to the X Server.\n"; kdWarning(1205) << "Might not terminate at end of session.\n"; return -1; } }
XlibEventSource::XlibEventSource(Display* display, Client* client) : m_display(display) , m_client(client) , m_source(0) { assert(display); assert(client); m_pollFD.fd = XConnectionNumber(display); m_pollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR; m_pollFD.revents = 0; m_source = reinterpret_cast<WrappedGSource*>(g_source_new(&eventSourceFuncs, sizeof(WrappedGSource))); m_source->xlibEventSource = this; g_source_attach(&m_source->source, 0); g_source_add_poll(&m_source->source, &m_pollFD); }
/* XNextEvent() with timeout */ static Bool XNextEventTimeout( Display *display, XEvent *event_return, struct timeval *timeout ) { int res; fd_set readfds; int display_fd = XConnectionNumber(display); /* small shortcut... */ if( timeout == NULL ) { XNextEvent(display, event_return); return(True); } FD_ZERO(&readfds); FD_SET(display_fd, &readfds); /* Note/bug: In the case of internal X events (like used to trigger callbacks * registered by XpGetDocumentData()&co.) select() will return with "new info" * - but XNextEvent() below processes these _internal_ events silently - and * will block if there are no other non-internal events. * The workaround here is to check with XEventsQueued() if there are non-internal * events queued - if not select() will be called again - unfortunately we use * the old timeout here instead of the "remaining" time... (this only would hurt * if the timeout would be really long - but for current use with values below * 1/2 secs it does not hurt... =:-) */ while( XEventsQueued(display, QueuedAfterFlush) == 0 ) { res = select(display_fd+1, &readfds, NULL, NULL, timeout); switch(res) { case -1: /* select() error - should not happen */ perror("XNextEventTimeout: select() failure"); return(False); case 0: /* timeout */ return(False); } } XNextEvent(display, event_return); return(True); }
void InitInput(int argc, char *argv[]) { int rc; rc = AllocDevicePair(serverClient, "Xnest", &xnestPointerDevice, &xnestKeyboardDevice, xnestPointerProc, xnestKeyboardProc, FALSE); if (rc != Success) FatalError("Failed to init Xnest default devices.\n"); mieqInit(); AddEnabledDevice(XConnectionNumber(xnestDisplay)); RegisterBlockAndWakeupHandlers(xnestBlockHandler, xnestWakeupHandler, NULL); }
QXlibScreen::QXlibScreen() : mFormat(QImage::Format_RGB32) #if !defined(QT_NO_OPENGL) && defined(QT_OPENGL_ES_2) , mEGLDisplay(0) #endif { char *display_name = getenv("DISPLAY"); Display *display = XOpenDisplay(display_name); mDisplay = new QXlibDisplay(display); #ifndef DONT_USE_MIT_SHM int MIT_SHM_extension_supported = XShmQueryExtension (mDisplay->nativeDisplay()); Q_ASSERT(MIT_SHM_extension_supported == True); #endif original_x_errhandler = XSetErrorHandler(qt_x_errhandler); if (qgetenv("DO_X_SYNCHRONIZE").toInt()) XSynchronize(mDisplay->nativeDisplay(), true); mScreen = DefaultScreen(mDisplay->nativeDisplay()); XSelectInput(mDisplay->nativeDisplay(),rootWindow(), KeymapStateMask | EnterWindowMask | LeaveWindowMask | PropertyChangeMask); int width = DisplayWidth(mDisplay->nativeDisplay(), mScreen); int height = DisplayHeight(mDisplay->nativeDisplay(), mScreen); mGeometry = QRect(0,0,width,height); int physicalWidth = DisplayWidthMM(mDisplay->nativeDisplay(), mScreen); int physicalHeight = DisplayHeightMM(mDisplay->nativeDisplay(), mScreen); mPhysicalSize = QSize(physicalWidth,physicalHeight); int xSocketNumber = XConnectionNumber(mDisplay->nativeDisplay()); mDepth = DefaultDepth(mDisplay->nativeDisplay(),mScreen); #ifdef MYX11_DEBUG qDebug() << "X socket:"<< xSocketNumber; #endif QSocketNotifier *sock = new QSocketNotifier(xSocketNumber, QSocketNotifier::Read, this); connect(sock, SIGNAL(activated(int)), this, SLOT(eventDispatcher())); mCursor = new QXlibCursor(this); mKeyboard = new QXlibKeyboard(this); }
void InitInput(int argc, char *argv[]) { xnestPointerDevice = AddInputDevice(xnestPointerProc, TRUE); xnestKeyboardDevice = AddInputDevice(xnestKeyboardProc, TRUE); if (!xnestEvents) xnestEvents = (xEvent *) xcalloc(sizeof(xEvent), GetMaximumEventsNum()); if (!xnestEvents) FatalError("couldn't allocate room for events\n"); RegisterPointerDevice(xnestPointerDevice); RegisterKeyboardDevice(xnestKeyboardDevice); mieqInit(); AddEnabledDevice(XConnectionNumber(xnestDisplay)); RegisterBlockAndWakeupHandlers(xnestBlockHandler, xnestWakeupHandler, NULL); }
//Main. int main (int argc, char *argv[]) { //Initialize sensors and structures... if (argc>2) { fprintf(stderr, "Usage: %s {raw, cooked}\n", argv[0]); exit(EXIT_FAILURE); } else { sensor_init((argc==2 && strcmp(argv[1], "raw")==0) ? raw : cooked); } //Create X connection. display_init(); int x_fd=XConnectionNumber(_D); //To be perfectly formal, I have to check POSIX compatibility. fprintf(log_stream, "X Connection descriptor opened on fd %3d.\n", x_fd); /**/ while (service_select_request(x_fd)!=loop_end) ; /**/ sleep(2); //Terminate X connection. display_destr(); //Close files and structures... sensor_destr(); return 0; }
Bool aftershow_connect_x_gui(AfterShowContext *ctx) { if (!ctx->gui.x.valid) { int i; AfterShowXScreen *scr; ctx->gui.x.dpy = XOpenDisplay(ctx->display); if (ctx->gui.x.dpy != NULL) { ctx->gui.x.fd = XConnectionNumber (ctx->gui.x.dpy); ctx->gui.x.screens_num = get_flags(ctx->flags, AfterShow_SingleScreen)?1:ScreenCount (ctx->gui.x.dpy); ctx->gui.x.screens = scr = safecalloc(ctx->gui.x.screens_num, sizeof(AfterShowXScreen)); for (i = 0; i < ctx->gui.x.screens_num; ++i) { scr->screen = i; scr->root.magic = MAGIC_AFTERSHOW_X_WINDOW; scr->root.screen = scr; aftershow_setup_root_x_window (ctx, &(scr->root)); scr->windows = create_ashash( 0, NULL, NULL, NULL ); ++scr; } ctx->gui.x.first_screen = 0; ctx->gui.x.valid = True; show_progress( "X display \"%s\" connected. Servicing %d screens.", ctx->display?ctx->display:"", ctx->gui.x.screens_num); }else { if (ctx->display) show_error("failed to initialize X Window session for display \"%s\"", ctx->display); else show_error("failed to initialize X Window session for default display"); } } return ctx->gui.x.valid; }
int drawinit(int w, int h) { atexit(shmfree); if((display = XOpenDisplay(NULL)) == NULL){ fprintf(stderr, "cannot open display!\n"); return -1; } width = w > 0 ? w : 640; height = h > 0 ? h : 360; visual = DefaultVisual(display, 0); window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, width, height, 1, 0, 0); if(visual->class != TrueColor){ fprintf(stderr, "Cannot handle non true color visual ...\n"); return -1; } shminit(); XSelectInput( display, window, EnterWindowMask| LeaveWindowMask| PointerMotionMask| KeyPressMask| KeyReleaseMask| ButtonPressMask| ButtonReleaseMask| ExposureMask| StructureNotifyMask| 0 ); XMapWindow(display, window); return XConnectionNumber(display); }
int EZX_block_and_wait(struct timeval *timeout) { int stat, xfd; fd_set readMask; xfd = XConnectionNumber(theDisplay); FD_ZERO(&readMask); FD_SET(xfd,&readMask); do { stat = select(FD_SETSIZE, &readMask, NULL, NULL, timeout); } while (stat < 0 && errno == EINTR); if (stat > 0) { if (FD_ISSET(xfd,&readMask)) return 1; else return 2; } else return 0; }
void QEventDispatcherX11::startingUp() { Q_D(QEventDispatcherX11); d->xfd = XConnectionNumber(X11->display); }
int main(int argc, char **argv) { unsigned long valuemask; /* mask for create windows */ XSetWindowAttributes attributes; /* attributes for create windows */ void InternUsefulAtoms(void); void InitVariables(void); int i, len; extern int x_fd; char *display_string; char message[255]; Bool single = False; Bool option_error = FALSE; MenuRoot *mr; g_argv = argv; g_argc = argc; OpenConsole(); DBUG("main", "Entered, about to parse args"); for (i = 1; i < argc; i++) { if (strncasecmp(argv[i], "-debug", 6) == 0) { debugging = True; } else if (strncasecmp(argv[i], "-s", 2) == 0) { single = True; } else if (strncasecmp(argv[i], "-d", 2) == 0) { if (++i >= argc) usage(); display_name = argv[i]; } else if (strncasecmp(argv[i], "-f", 2) == 0) { if (++i >= argc) usage(); config_command = (char *) malloc(6 + strlen(argv[i])); strcpy(config_command, "Read "); strcat(config_command, argv[i]); free_config_command = True; } else if (strncasecmp(argv[i], "-cmd", 4) == 0) { if (++i >= argc) usage(); config_command = argv[i]; } else if (strncasecmp(argv[i], "-file", 5) == 0) { if (++i >= argc) usage(); output_file = argv[i]; } else if (strncasecmp(argv[i], "-h", 2) == 0) { usage(); exit(0); } else if (strncasecmp(argv[i], "-blackout", 9) == 0) { Blackout = True; } else if (strncasecmp(argv[i], "-version", 8) == 0) { fvwm_msg(INFO, "main", "Fvwm95 Version %s compiled on %s at %s\n", VERSION, __DATE__, __TIME__); } else { fvwm_msg(ERR, "main", "Unknown option: `%s'\n", argv[i]); option_error = TRUE; } } DBUG("main", "Done parsing args"); if (option_error) { usage(); } DBUG("main", "Installing signal handlers"); newhandler(SIGINT); newhandler(SIGHUP); newhandler(SIGQUIT); newhandler(SIGTERM); signal(SIGUSR1, Restart); signal(SIGPIPE, DeadPipe); ReapChildren(); if (!(dpy = XOpenDisplay(display_name))) { fvwm_msg(ERR, "main", "can't open display %s", XDisplayName(display_name)); exit(1); } Scr.screen = DefaultScreen(dpy); Scr.NumberOfScreens = ScreenCount(dpy); master_pid = getpid(); if (!single) { int myscreen = 0; char *cp; strcpy(message, XDisplayString(dpy)); XCloseDisplay(dpy); for (i = 1; i < Scr.NumberOfScreens; i++) { if (fork() == 0) { myscreen = i; break; } } /* * Truncate the string 'whatever:n.n' to 'whatever:n', * and then append the screen number. */ cp = strchr(message, ':'); if (cp != NULL) { cp = strchr(cp, '.'); if (cp != NULL) *cp = '\0'; /* truncate at display part */ } sprintf(message + strlen(message), ".%d", myscreen); dpy = XOpenDisplay(message); Scr.screen = myscreen; Scr.NumberOfScreens = ScreenCount(dpy); } x_fd = XConnectionNumber(dpy); fd_width = GetFdWidth(); if (fcntl(x_fd, F_SETFD, 1) == -1) { fvwm_msg(ERR, "main", "close-on-exec failed"); exit(1); } /* Add a DISPLAY entry to the environment, in case we were started * with fvwm -display term:0.0 */ len = strlen(XDisplayString(dpy)); display_string = safemalloc(len + 10); sprintf(display_string, "DISPLAY=%s", XDisplayString(dpy)); putenv(display_string); /* Add a HOSTDISPLAY environment variable, which is the same as * DISPLAY, unless display = :0.0 or unix:0.0, in which case the full * host name will be used for ease in networking . */ /* Note: Can't free the rdisplay_string after putenv, because it * becomes part of the environment! */ if (strncmp(display_string, "DISPLAY=:", 9) == 0) { char client[MAXHOSTNAME], *rdisplay_string; mygethostname(client, MAXHOSTNAME); rdisplay_string = safemalloc(len + 14 + strlen(client)); sprintf(rdisplay_string, "HOSTDISPLAY=%s:%s", client, &display_string[9]); putenv(rdisplay_string); } else if (strncmp(display_string, "DISPLAY=unix:", 13) == 0) { char client[MAXHOSTNAME], *rdisplay_string; mygethostname(client, MAXHOSTNAME); rdisplay_string = safemalloc(len + 14 + strlen(client)); sprintf(rdisplay_string, "HOSTDISPLAY=%s:%s", client, &display_string[13]); putenv(rdisplay_string); } else { char *rdisplay_string; rdisplay_string = safemalloc(len + 14); sprintf(rdisplay_string, "HOSTDISPLAY=%s", XDisplayString(dpy)); putenv(rdisplay_string); } Scr.Root = RootWindow(dpy, Scr.screen); if (Scr.Root == None) { fvwm_msg(ERR, "main", "Screen %d is not a valid screen", (char *) Scr.screen); exit(1); } #ifdef SHAPE ShapesSupported = XShapeQueryExtension(dpy, &ShapeEventBase, &ShapeErrorBase); #endif /* SHAPE */ InternUsefulAtoms(); /* Make sure property priority colors is empty */ XChangeProperty(dpy, Scr.Root, _XA_MIT_PRIORITY_COLORS, XA_CARDINAL, 32, PropModeReplace, NULL, 0); XSetErrorHandler((XErrorHandler) CatchRedirectError); XSetIOErrorHandler((XIOErrorHandler) CatchFatal); XSelectInput(dpy, Scr.Root, LeaveWindowMask | EnterWindowMask | PropertyChangeMask | SubstructureRedirectMask | KeyPressMask | SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask); XSync(dpy, 0); XSetErrorHandler((XErrorHandler) FvwmErrorHandler); BlackoutScreen(); CreateCursors(); InitVariables(); InitEventHandlerJumpTable(); initModules(); InitPictureCMap(dpy, Scr.Root); /* for the pixmap cache... */ Scr.gray_bitmap = XCreateBitmapFromData(dpy, Scr.Root, g_bits, g_width, g_height); DBUG("main", "Setting up rc file defaults..."); SetRCDefaults(); DBUG("main", "Running config_command..."); ExecuteFunction(config_command, NULL, &Event, C_ROOT, -1); DBUG("main", "Done running config_command"); /* CaptureAllWindows(); MakeMenus(); */ #if 0 /* this seems to cause problems for FvwmCpp/M4 startup actually */ /* if not a direct 'Read', we'll capture all windows here, in case cmd fails we'll still have defaults */ if (strncasecmp(config_command, "Read", 4) != 0 && strncasecmp(config_command, "PipeRead", 8) != 0) { /* so if cmd (FvwmM4/Cpp most likely) fails, we can still have borders & stuff... */ StartupStuff(); } #endif /* 0 */ if (free_config_command) { free(config_command); } if (Scr.d_depth < 2) { Scr.gray_pixmap = XCreatePixmapFromBitmapData(dpy, Scr.Root, g_bits, g_width, g_height, Scr.WinColors.fore, Scr.WinColors.back, Scr.d_depth); Scr.light_gray_pixmap = XCreatePixmapFromBitmapData(dpy, Scr.Root, l_g_bits, l_g_width, l_g_height, Scr.WinColors.fore, Scr.WinColors.back, Scr.d_depth); } /* create a window which will accept the keyboard focus when no other windows have it */ attributes.event_mask = KeyPressMask | FocusChangeMask; attributes.override_redirect = True; Scr.NoFocusWin = XCreateWindow(dpy, Scr.Root, -10, -10, 10, 10, 0, 0, InputOnly, CopyFromParent, CWEventMask | CWOverrideRedirect, &attributes); XMapWindow(dpy, Scr.NoFocusWin); SetMWM_INFO(Scr.NoFocusWin); XSetInputFocus(dpy, Scr.NoFocusWin, RevertToParent, CurrentTime); XSync(dpy, 0); if (debugging) XSynchronize(dpy, 1); Scr.SizeStringWidth = XTextWidth(Scr.StdFont.font, " +8888 x +8888 ", 15); attributes.border_pixel = Scr.WinColors.fore; attributes.background_pixel = Scr.WinColors.back; attributes.bit_gravity = NorthWestGravity; attributes.save_under = True; valuemask = (CWBorderPixel | CWBackPixel | CWBitGravity | CWSaveUnder); /* create the window for coordinates */ Scr.SizeWindow = XCreateWindow(dpy, Scr.Root, Scr.MyDisplayWidth / 2 - (Scr.SizeStringWidth + SIZE_HINDENT * 2) / 2, Scr.MyDisplayHeight / 2 - (Scr.StdFont.height + SIZE_VINDENT * 2) / 2, (unsigned int) (Scr.SizeStringWidth + SIZE_HINDENT * 2), (unsigned int) (Scr.StdFont.height + SIZE_VINDENT * 2), (unsigned int) 0, 0, (unsigned int) CopyFromParent, (Visual *) CopyFromParent, valuemask, &attributes); #ifndef NON_VIRTUAL initPanFrames(); #endif XGrabServer(dpy); #ifndef NON_VIRTUAL checkPanFrames(); #endif XUngrabServer(dpy); UnBlackoutScreen(); DBUG("main", "Entering HandleEvents loop..."); HandleEvents(); DBUG("main", "Back from HandleEvents loop? Exiting..."); return 0; }
GtkWidget* gtk_xtbin_new (GdkWindow *parent_window, String * f) { GtkXtBin *xtbin; gpointer user_data; assert(parent_window != NULL); xtbin = gtk_type_new (GTK_TYPE_XTBIN); if (!xtbin) return (GtkWidget*)NULL; if (f) fallback = f; /* Initialize the Xt toolkit */ xtbin->parent_window = parent_window; xt_client_init(&(xtbin->xtclient), GDK_VISUAL_XVISUAL(gdk_window_get_visual(parent_window )), GDK_COLORMAP_XCOLORMAP(gdk_window_get_colormap(parent_window)), gdk_window_get_visual(parent_window )->depth); if (!xtbin->xtclient.xtdisplay) { /* If XtOpenDisplay failed, we can't go any further. * Bail out. */ #ifdef DEBUG_XTBIN printf("gtk_xtbin_init: XtOpenDisplay() returned NULL.\n"); #endif g_free (xtbin); return (GtkWidget *)NULL; } /* If this is the first running widget, hook this display into the mainloop */ if (0 == num_widgets) { int cnumber; /* * hook Xt event loop into the glib event loop. */ /* the assumption is that gtk_init has already been called */ GSource* gs = g_source_new(&xt_event_funcs, sizeof(GSource)); if (!gs) { return NULL; } g_source_set_priority(gs, GDK_PRIORITY_EVENTS); g_source_set_can_recurse(gs, TRUE); tag = g_source_attach(gs, (GMainContext*)NULL); #ifdef VMS cnumber = XConnectionNumber(xtdisplay); #else cnumber = ConnectionNumber(xtdisplay); #endif xt_event_poll_fd.fd = cnumber; xt_event_poll_fd.events = G_IO_IN; xt_event_poll_fd.revents = 0; /* hmm... is this correct? */ g_main_context_add_poll ((GMainContext*)NULL, &xt_event_poll_fd, G_PRIORITY_LOW); /* add a timer so that we can poll and process Xt timers */ xt_polling_timer_id = gtk_timeout_add(25, (GtkFunction)xt_event_polling_timer_callback, xtdisplay); } /* Bump up our usage count */ num_widgets++; /* Build the hierachy */ xtbin->xtdisplay = xtbin->xtclient.xtdisplay; gtk_widget_set_parent_window(GTK_WIDGET(xtbin), parent_window); gdk_window_get_user_data(xtbin->parent_window, &user_data); if (user_data) gtk_container_add(GTK_CONTAINER(user_data), GTK_WIDGET(xtbin)); return GTK_WIDGET (xtbin); }
/*******************************************************************************\ |* openXwindow *| \*******************************************************************************/ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) { unsigned int borderwidth = 1; XClassHint classHint; char *display_name = NULL; char *wname = argv[0]; XTextProperty name; XGCValues gcv; unsigned long gcm; char *geometry = NULL; int dummy=0; int i; for (i=1; argv[i]; i++) { if (!strcmp(argv[i], "-display")) display_name = argv[++i]; else if (!strcmp(argv[i], "-geometry")) geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { fprintf(stderr, "%s: can't open display %s\n", wname, XDisplayName(display_name)); exit(1); } screen = DefaultScreen(display); Root = RootWindow(display, screen); d_depth = DefaultDepth(display, screen); x_fd = XConnectionNumber(display); /* Convert XPM to XImage */ GetXPM(&wmgen, pixmap_bytes); /* Create a window to hold the stuff */ mysizehints.flags = USSize | USPosition; mysizehints.x = 0; mysizehints.y = 0; back_pix = GetColor("white"); fore_pix = GetColor("black"); XWMGeometry(display, screen, geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); mysizehints.width = 64; mysizehints.height = 64; win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); /* Activate hints */ XSetWMNormalHints(display, win, &mysizehints); classHint.res_name = wname; classHint.res_class = wname; XSetClassHint(display, win, &classHint); XSelectInput(display, win, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask); XSelectInput(display, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask); if (XStringListToTextProperty(&wname, 1, &name) == 0) { fprintf(stderr, "%s: can't allocate window name\n", wname); exit(1); } XSetWMName(display, win, &name); /* Create GC for drawing */ gcm = GCForeground | GCBackground | GCGraphicsExposures; gcv.foreground = fore_pix; gcv.background = back_pix; gcv.graphics_exposures = 0; NormalGC = XCreateGC(display, Root, gcm, &gcv); /* ONLYSHAPE ON */ pixmask = XCreateBitmapFromData(display, win, pixmask_bits, pixmask_width, pixmask_height); XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet); XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet); /* ONLYSHAPE OFF */ mywmhints.initial_state = WithdrawnState; mywmhints.icon_window = iconwin; mywmhints.icon_x = mysizehints.x; mywmhints.icon_y = mysizehints.y; mywmhints.window_group = win; mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint; XSetWMHints(display, win, &mywmhints); XSetCommand(display, win, argv, argc); XMapWindow(display, win); }