Пример #1
0
VdpStatus vdp_imp_device_create_x11(Display *display,
                                    int screen,
                                    VdpDevice *device,
                                    VdpGetProcAddress **get_proc_address)
{
	if (!display || !device || !get_proc_address)
		return VDP_STATUS_INVALID_POINTER;

	device_ctx_t *dev = handle_create(sizeof(*dev), device);
	if (!dev)
		return VDP_STATUS_RESOURCES;

	dev->display = XOpenDisplay(XDisplayString(display));
	dev->screen = screen;

	if (!ve_open())
	{
		handle_destroy(*device);
		return VDP_STATUS_ERROR;
	}

	char *env_vdpau_osd = getenv("VDPAU_OSD");
	if (env_vdpau_osd && strncmp(env_vdpau_osd, "1", 1) == 0)
	{
		dev->g2d_fd = open("/dev/g2d", O_RDWR);
		if (dev->g2d_fd != -1)
			dev->osd_enabled = 1;
		else
			VDPAU_DBG("Failed to open /dev/g2d! OSD disabled.");
	}

	*get_proc_address = vdp_get_proc_address;

	return VDP_STATUS_OK;
}
Пример #2
0
XtEnum XmPrintToFile(Display *pdpy, 
		     char *file_name,
		     XPFinishProc finish_proc, 
		     XPointer client_data)
{
    FileCallbackRec *callback;
    int pid;
    XPContext pcontext ;
    String application_name, application_class, display_name;
    FILE *file;
    int filedes[2];
    
    /* make sure we can open the file for writing */
    if ((file = fopen(file_name, "w")) == NULL) {
      return False;
    }

    if ((pipe(filedes)) == -1) {
      return False;
    }

    /* its important to flush before we fork, to make sure that the
       XpStartJob gets through first in the parent */
    XFlush(pdpy);

    XtGetApplicationNameAndClass(pdpy,
				 &application_name, &application_class);

    display_name = XDisplayString(pdpy) ;
    pcontext = XpGetContext(pdpy) ;
    pid = fork();

    if (pid == 0) {
      ChildPrintToFile(display_name, pcontext, file, file_name, filedes[1],
		       application_name, application_class);
    }
    else if (pid < 0) {
      return False;
    }

    /* we are in the parent */

    fclose(file);
    close(filedes[1]);

    /* allocate the space for a callback */
    callback = (FileCallbackRec *) XtMalloc(sizeof(FileCallbackRec));
    callback->display = pdpy;
    callback->pipe = filedes[0];
    callback->finish_proc = finish_proc;
    callback->client_data = client_data;

    /* notification that the child has completed */
    callback->input_id = 
        XtAppAddInput(XtDisplayToApplicationContext(pdpy), 
		      callback->pipe, (XtPointer)XtInputReadMask,
		      FilePipeCB, callback);

    return True;
}
Пример #3
0
static void
gst_vaapi_display_x11_constructed(GObject *object)
{
    GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
    GstVaapiDisplayX11Private * const priv = display->priv;
    GstVaapiDisplayCache * const cache = gst_vaapi_display_get_cache();
    const GstVaapiDisplayInfo *info;
    GObjectClass *parent_class;

    priv->create_display = priv->x11_display == NULL;

    /* Don't create X11 display if there is one in the cache already */
    if (priv->create_display) {
        info = gst_vaapi_display_cache_lookup_by_name(
            cache,
            priv->display_name,
            compare_display_name, NULL
        );
        if (info) {
            priv->x11_display    = info->native_display;
            priv->create_display = FALSE;
        }
    }

    /* Reset display-name if the user provided his own X11 display */
    if (!priv->create_display)
        set_display_name(display, XDisplayString(priv->x11_display));

    parent_class = G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class);
    if (parent_class->constructed)
        parent_class->constructed(object);
}
Пример #4
0
void CloneDisplay(Display *dpy)
{
  if(CurrentXDisplay || dpy == NULL)
    return;

  CurrentXDisplay = XOpenDisplay(XDisplayString(dpy));
}
Пример #5
0
int ftr_loop_run2(struct FTR *ff, struct FTR *gg)
{
	struct _FTR *f = (void*)ff;
	struct _FTR *g = (void*)gg;

	char *dn_f = XDisplayString(f->display);
	char *dn_g = XDisplayString(g->display);
	if (0 != strcmp(dn_f, dn_g))
		exit(fprintf(stderr, "FTR error: two displays bad bad bad (%p,%p)(\"%s\",\"%s\")\n", (void*)f->display, (void*)g->display, dn_f, dn_g));

	fprintf(stderr, "dn_f = %p \"%s\"\n", (void*)f->display, dn_f);
	fprintf(stderr, "dn_g = %p \"%s\"\n", (void*)g->display, dn_g);

	while (!f->stop_loop && !g->stop_loop)
	{
		int pending_f = XPending(f->display);
		int pending_g = XPending(g->display);

		fprintf(stderr, "pending fg = %d %d\n", pending_f, pending_g);

		// treat g
		if (!g->handle_idle || g->changed || pending_g > 0)
			process_next_event(gg);
		else if (g->handle_idle) {
			g->handle_idle(gg, 0, 0, 0, 0);
			XEvent ev;
			ev.type = Expose;
			XSendEvent(g->display, g->window, 0, NoEventMask, &ev);
			XFlush(g->display);
		}

		// treat f
		if (!f->handle_idle || f->changed || pending_f > 0)
			process_next_event(ff);
		else if (f->handle_idle) {
			f->handle_idle(ff, 0, 0, 0, 0);
			XEvent ev;
			ev.type = Expose;
			XSendEvent(f->display, f->window, 0, NoEventMask, &ev);
			XFlush(f->display);
		}
	}

	int r = f->stop_loop + g->stop_loop;
	f->stop_loop = g->stop_loop = 0;
	return r;
}
Пример #6
0
Файл: DragBS.c Проект: att/uwin
/*
 * 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);
    }
}
Пример #7
0
string _sh_command(string command, bool force_local, 
		   bool force_display_settings)
{
    // Fetch display settings
    string display;
    if (command_shell != 0)
	display = XDisplayString(XtDisplay(command_shell));
    else if (getenv("DISPLAY") != 0)
	display = getenv("DISPLAY");
    else
	display = "";

    // Make sure display contains host name
    if (display.contains("unix:", 0) || display.contains(":", 0))
    {
	display = string(hostname()) + display.from(":");
    }

    // Make sure display contains fully qualified host name
    if (display.contains(":") && !display.contains("::"))
    {
	string host = display.before(':');
	display = string(fullhostname(host.chars())) + display.from(":");
    }

    string settings = "";
    if (!display.empty())
    {
	settings += 
	    "DISPLAY=${DISPLAY-" + sh_quote(display) + "}; export DISPLAY; ";
    }
    settings += set_environment_command();

    if (force_local || !remote_gdb())
    {
	if (command.empty())
	    return "";
	if (force_display_settings)
	    command = settings + command;
	return "/bin/sh -c " + sh_quote(command);
    }

    string rsh = app_data.rsh_command;
    const string login = app_data.debugger_host_login;
    if (!login.empty())
	rsh += " -l " + login;

    rsh += " " + gdb_host;

    if (!command.empty())
	rsh += " /bin/sh -c " + sh_quote(sh_quote(settings + command));

    return rsh;
}
Пример #8
0
void
logoutUser(Display * display
#ifdef CLOSEDOWN_LOGOUT
  , int screens
#endif
)
{

#if ( HAVE_SYSLOG_H && defined( USE_SYSLOG ))
	syslog(SYSLOG_INFO, "%s: expired. closing down (uid %d) on %s\n",
	       ProgramName, getuid(), getenv("DISPLAY"));
	syslogStop(XDisplayString(display));
#endif
	if (logoutCmd && *logoutCmd) {
		int         cmd_pid;

		if ((cmd_pid = (int) FORK()) == -1) {
			(void) fprintf(stderr, "Failed to launch \"%s\"\n", logoutCmd);
			perror(ProgramName);
			cmd_pid = 0;
		} else if (!cmd_pid) {
			(void) system(logoutCmd);
			exit(0);
		}
	}
#ifdef CLOSEDOWN_LOGOUT
	(void) finish(display, False);
#else
	(void) finish(display, True);
#endif
#ifdef VMS
	(void) system("mcr decw$endsession -noprompt");
#else
#ifdef __sgi
	(void) system("/usr/bin/X11/tellwm end_session >/dev/null 2>&1");
	(void) sleep(10);	/* Give the above a chance to run */
#endif
#endif

#ifdef CLOSEDOWN_LOGOUT
	/* Do not want to kill other user's processes e.g. telnet session */
	closedownLogout(display, screens);
	return;
#endif
#ifdef SESSION_LOGOUT
	sessionLogout();
#endif
	uglyLogout();
	exit(-1);
}
Пример #9
0
void cleanDisplay                    ( Display           * display,
                                       int                 n )
{
  oyOptions_s * opts = 0,
              * result = 0;

  const char * display_name = strdup(XDisplayString(display));

  oyOptions_SetFromText( &opts, "////display_name",
                         display_name, OY_CREATE_NEW );
  oyOptions_Handle( "//" OY_TYPE_STD "/clean_profiles",
                                 opts,"clean_profiles",
                                 &result );
}
Пример #10
0
static int match_display_name(Display *x11_dpy, const char *display_name)
{
    Display *test_dpy;
    char *test_dpy_name, *x11_dpy_name;
    int test_dpy_namelen, x11_dpy_namelen;
    int m;

    test_dpy = XOpenDisplay(display_name);
    if (!test_dpy)
        return 0;

    test_dpy_name    = XDisplayString(test_dpy);
    test_dpy_namelen = get_display_name_length(test_dpy_name);
    x11_dpy_name     = XDisplayString(x11_dpy);
    x11_dpy_namelen  = get_display_name_length(x11_dpy_name);

    m = (test_dpy_namelen == x11_dpy_namelen &&
         (test_dpy_namelen == 0 ||
          (test_dpy_namelen > 0 &&
           strncmp(test_dpy_name, x11_dpy_name, test_dpy_namelen) == 0)));

    XCloseDisplay(test_dpy);
    return m;
}
Пример #11
0
static int xext_errhandler(Display *d, _Xconst char *ext, _Xconst char *reason)
{
#ifdef X11_DEBUG
	printf("Xext error inside SDL (may be harmless):\n");
	printf("  Extension \"%s\" %s on display \"%s\".\n",
	       ext, reason, XDisplayString(d));
#endif

	if (SDL_strcmp(reason, "missing") == 0) {
		return 0;
	}

	
	return Xext_handler(d, ext, reason);
}
XRecordKeyboardMonitor::XRecordKeyboardMonitor(Display *display)
    : m_connection(xcb_connect(XDisplayString(display), 0)),
      m_modifiersPressed(0), m_keysPressed(0)
{
    if (!m_connection) {
        return;
    }

    xcb_get_modifier_mapping_cookie_t modmapCookie =
        xcb_get_modifier_mapping(m_connection);

    m_context = xcb_generate_id(m_connection);
    xcb_record_range_t range;
    memset(&range, 0, sizeof(range));
    range.device_events.first = XCB_KEY_PRESS;
    range.device_events.last = XCB_KEY_RELEASE;
    xcb_record_client_spec_t cs = XCB_RECORD_CS_ALL_CLIENTS;
    xcb_record_create_context(m_connection, m_context, 0, 1, 1, &cs, &range);
    xcb_flush(m_connection);

    QScopedPointer<xcb_get_modifier_mapping_reply_t, QScopedPointerPodDeleter>
    modmap(xcb_get_modifier_mapping_reply(m_connection, modmapCookie, 0));
    if (!modmap) {
        return;
    }

    int nModifiers = xcb_get_modifier_mapping_keycodes_length(modmap.data());
    xcb_keycode_t *modifiers = xcb_get_modifier_mapping_keycodes(modmap.data());
    m_modifier.fill(false, std::numeric_limits<xcb_keycode_t>::max() + 1);
    for (xcb_keycode_t *i = modifiers; i < modifiers + nModifiers; i++) {
        m_modifier[*i] = true;
    }
    m_ignore.fill(false, std::numeric_limits<xcb_keycode_t>::max() + 1);
    for (xcb_keycode_t *i = modifiers;
            i < modifiers + modmap->keycodes_per_modifier; i++)
    {
        m_ignore[*i] = true;
    }
    m_pressed.fill(false, std::numeric_limits<xcb_keycode_t>::max() + 1);

    m_cookie = xcb_record_enable_context(m_connection, m_context);
    xcb_flush(m_connection);

    m_notifier = new QSocketNotifier(xcb_get_file_descriptor(m_connection),
                                     QSocketNotifier::Read, this);
    connect(m_notifier, SIGNAL(activated(int)), SLOT(processNextReply()));
    m_notifier->setEnabled(true);
}
Пример #13
0
QT_BEGIN_NAMESPACE

XCompositeHandler::XCompositeHandler(QWaylandCompositor *compositor, Display *display)
    : QtWaylandServer::qt_xcomposite(compositor->display(), 1)
{
    mFakeRootWindow = new QWindow();
    mFakeRootWindow->setGeometry(QRect(-1,-1,1,1));
    mFakeRootWindow->create();
    mFakeRootWindow->show();

    int composite_event_base, composite_error_base;
    if (!XCompositeQueryExtension(display, &composite_event_base, &composite_error_base))
        qFatal("XComposite required");

    mDisplayString = QString::fromLocal8Bit(XDisplayString(display));
}
static void
gst_vaapi_display_x11_constructed(GObject *object)
{
    GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
    GObjectClass *parent_class;

    display->priv->create_display = display->priv->x11_display == NULL;

    /* Reset display-name if the user provided his own X11 display */
    if (!display->priv->create_display)
        set_display_name(display, XDisplayString(display->priv->x11_display));

    parent_class = G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class);
    if (parent_class->constructed)
        parent_class->constructed(object);
}
Пример #15
0
static gboolean
gst_vaapi_display_x11_bind_display (GstVaapiDisplay * base_display,
    gpointer native_display)
{
  GstVaapiDisplayX11 *const display = GST_VAAPI_DISPLAY_X11_CAST (base_display);
  GstVaapiDisplayX11Private *const priv = display->priv;

  priv->x11_display = native_display;
  priv->x11_screen = DefaultScreen (native_display);
  priv->use_foreign_display = TRUE;

  check_extensions (display);

  if (!set_display_name (display, XDisplayString (priv->x11_display)))
    return FALSE;
  return TRUE;
}
Пример #16
0
static
void *XpuPrintToFile( Display *pdpy, XPContext pcontext, const char *filename )
{
  MyPrintFileData *mpfd; /* warning: shared between threads !! */
         
  if( (mpfd = malloc(sizeof(MyPrintFileData))) == NULL )
    return(NULL);
  
  mpfd->parent_pdpy = pdpy;
  mpfd->displayname = XDisplayString(pdpy);
  mpfd->pdpy        = NULL;
  mpfd->pcontext    = pcontext;
  mpfd->file_name   = filename;
  mpfd->file        = NULL;      
  mpfd->status      = XPGetDocError;
  
  /* make sure we can open the file for writing */
  if( (mpfd->file = fopen(mpfd->file_name, "w")) == NULL ) 
  {
    /* fopen() error */
    free(mpfd);
    return(NULL);
  }
  
  /* its important to flush before we start the consumer thread, 
   * to make sure that the XpStartJob gets through first in the parent
   */
  XFlush(pdpy);
#ifdef XPU_USE_NSPR
  if( (mpfd->prthread = PR_CreateThread(PR_SYSTEM_THREAD, PrintToFile_Consumer, mpfd, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0)) == NULL )
#else    
  if( pthread_create(&(mpfd->tid), NULL, PrintToFile_Consumer, mpfd) != 0 ) 
#endif
  {
    /* pthread_create() error */
    fclose(mpfd->file);
    free(mpfd);
    return(NULL);
  }
  
  /* we're still in the parent */
  XPU_DEBUG_ONLY(printf("### parent started consumer thread.\n" ));
  return(mpfd);
}
Пример #17
0
void *
handle_xdpy_ref(void *dpy_orig)
{
    pthread_mutex_lock(&lock);
    Display *dpy = g_hash_table_lookup(xdpy_copies, dpy_orig);
    if (NULL == dpy) {
        dpy = XOpenDisplay(XDisplayString(dpy_orig));
        if (!dpy)
            goto quit;
        g_hash_table_replace(xdpy_copies, dpy_orig, dpy);
        g_hash_table_replace(xdpy_copies_refcount, dpy_orig, GINT_TO_POINTER(1));
    } else {
        int refcount = GPOINTER_TO_INT(g_hash_table_lookup(xdpy_copies_refcount, dpy_orig));
        g_hash_table_replace(xdpy_copies_refcount, dpy_orig, GINT_TO_POINTER(refcount+1));
    }
quit:
    pthread_mutex_unlock(&lock);
    return dpy;
}
Пример #18
0
static int vdpau_device_create(AVHWDeviceContext *ctx, const char *device,
                               AVDictionary *opts, int flags)
{
    AVVDPAUDeviceContext *hwctx = ctx->hwctx;

    VDPAUDevicePriv *priv;
    VdpStatus err;
    VdpGetInformationString *get_information_string;
    const char *display, *vendor;

    priv = av_mallocz(sizeof(*priv));
    if (!priv)
        return AVERROR(ENOMEM);

    ctx->user_opaque = priv;
    ctx->free        = vdpau_device_free;

    priv->dpy = XOpenDisplay(device);
    if (!priv->dpy) {
        av_log(ctx, AV_LOG_ERROR, "Cannot open the X11 display %s.\n",
               XDisplayName(device));
        return AVERROR_UNKNOWN;
    }
    display = XDisplayString(priv->dpy);

    err = vdp_device_create_x11(priv->dpy, XDefaultScreen(priv->dpy),
                                &hwctx->device, &hwctx->get_proc_address);
    if (err != VDP_STATUS_OK) {
        av_log(ctx, AV_LOG_ERROR, "VDPAU device creation on X11 display %s failed.\n",
               display);
        return AVERROR_UNKNOWN;
    }

    GET_CALLBACK(VDP_FUNC_ID_GET_INFORMATION_STRING, get_information_string);
    GET_CALLBACK(VDP_FUNC_ID_DEVICE_DESTROY,         priv->device_destroy);

    get_information_string(&vendor);
    av_log(ctx, AV_LOG_VERBOSE, "Successfully created a VDPAU device (%s) on "
           "X11 display %s\n", vendor, display);

    return 0;
}
Пример #19
0
static int xext_errhandler(Display *d, _Xconst char *ext, _Xconst char *reason)
{
#ifdef X11_DEBUG
	printf("Xext error inside SDL (may be harmless):\n");
	printf("  Extension \"%s\" %s on display \"%s\".\n",
	       ext, reason, XDisplayString(d));
#endif

	if (SDL_strcmp(reason, "missing") == 0) {
		/*
		 * Since the query itself, elsewhere, can handle a missing extension
		 *  and the default behaviour in Xlib is to write to stderr, which
		 *  generates unnecessary bug reports, we just ignore these.
		 */
		return 0;
	}

	/* Everything else goes to the default handler... */
	return Xext_handler(d, ext, reason);
}
Пример #20
0
static bool localDisplay(Display *dpy)
{
    QByteArray display(XDisplayString(dpy));
    QByteArray hostPart = display.left(display.indexOf(':'));

    if (hostPart.isEmpty())
        return true;

    if (hostPart == "localhost")
        return true;

    if (hostPart == "127.0.0.1")
        return true;

    char name[2048];
    gethostname(name, sizeof(name));

    if (hostPart == name)
       return true;

    return false;
}
Пример #21
0
static void
bus_test_client_class_init (BusTestClientClass *klass)
{
    IDEBUG ("%s", __FUNCTION__);

    IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass);

    ibus_object_class->destroy = bus_test_client_destroy;

    /* init display object */
    if (_xdisplay == NULL) {
        _xdisplay = XOpenDisplay (gdk_display_get_name (gdk_display_get_default ()));
    }

    /* init bus object */
    if (_bus == NULL) {
        ibus_set_display (XDisplayString (_xdisplay));
        _bus = ibus_bus_new();
    }

    g_signal_connect (_bus, "disconnected", G_CALLBACK (_bus_disconnected_cb), NULL);
}
Пример #22
0
int FcitxQtConnectionPrivate::displayNumber() {
    if (m_displayNumber >= 0)
        return m_displayNumber;
    Display * dpy = QX11Info::display();
    int displayNumber = 0;
    if (dpy) {
        char* display = XDisplayString(dpy);
        if (display) {
            char* strDisplayNumber = NULL;
            display = strdup(display);
            char* p = display;
            for (; *p != ':' && *p != '\0'; p++);

            if (*p == ':') {
                *p = '\0';
                p++;
                strDisplayNumber = p;
            }
            for (; *p != '.' && *p != '\0'; p++);

            if (*p == '.') {
                *p = '\0';
            }

            if (strDisplayNumber) {
                displayNumber = atoi(strDisplayNumber);
            }

            free(display);
        }
    }
    else
        displayNumber = fcitx_utils_get_display_number();

    m_displayNumber = displayNumber;

    return displayNumber;
}
Пример #23
0
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;
}
Пример #24
0
int
main(int argc, char * argv[])
{
  int           loop, num_extensions, num_devices;
  char          **extensions;
  XDeviceInfo   *devices;
  Display       *dpy;
  Window        root_win;
  unsigned long screen;
  int		list = 0;
  
  if (argc != 2) {
    fprintf(stderr, "usage : %s (-l | <device name>)\n", argv[0]);
    exit(1);
  }

  if (strcmp(argv[1], "-l") == 0) {
    list = 1;
  }
  
  dpy = XOpenDisplay(NULL);

  if (!dpy) {
    printf("unable to connect to X Server try to set the DISPLAY variable\n");
    exit(1);
  }

#ifdef DEBUG
  printf("connected to %s\n", XDisplayString(dpy));
#endif

  screen = DefaultScreen(dpy);
  root_win = RootWindow(dpy, screen);

  extensions = XListExtensions(dpy, &num_extensions);
  for (loop = 0; loop < num_extensions &&
         (strcmp(extensions[loop], "XInputExtension") != 0); loop++);
  XFreeExtensionList(extensions);
  if (loop != num_extensions)
    {
      devices = XListInputDevices(dpy, &num_devices);
      for(loop=0; loop<num_devices; loop++)
        {
	  if (list) {
	      printf("\"%s\"	[", devices[loop].name ? devices[loop].name : "<noname>");
	      switch(devices[loop].use) {
	      case IsXPointer:
		  printf("XPointer]\n");
		  break;
	      case IsXKeyboard:
		  printf("XKeyboard]\n");
		  break;
	      case IsXExtensionDevice:
		  printf("XExtensionDevice]\n");
		  break;
	      default:
		  printf("invalid value]\n");
		  break;
	      }
	  }
	  else {
          if ((argc == 2) && devices[loop].name &&
              (StrCaseCmp(devices[loop].name, argv[1]) == 0))
            if (devices[loop].use == IsXExtensionDevice)
              {
                XDevice *device;
              
#ifdef DEBUG
                fprintf(stderr, "opening device %s\n",
                        devices[loop].name ? devices[loop].name : "<noname>");
#endif
                device = XOpenDevice(dpy, devices[loop].id);
                if (device)
                  {
                    XChangePointerDevice(dpy, device, 0, 1);
                    exit(0);
                  }
                else
                  {
                    fprintf(stderr, "error opening device\n");
                    exit(1);
                  }
              }
	  }
        }
      XFreeDeviceList(devices);
    }
  else
    {
      fprintf(stderr, "No XInput extension available\n");
      exit(1);
    }
  
  if (list) {
    exit(0);
  }
  else {
    fprintf(stderr, "Extended device %s not found\n", argv[1]);
    exit(1);
  }
}
Пример #25
0
int
main(int argc, char * argv[])
{
  int           loop, num_extensions, num_devices;
  char          **extensions;
  XDeviceInfo   *devices;
  Display       *dpy;
  Window        root_win;
  unsigned long screen;
  int		list = 0;
  
  if (argc != 3) {
    fprintf(stderr, "usage : %s <device name> (ABSOLUTE|RELATIVE)\n", argv[0]);
    exit(1);
  }

  if (strcmp(argv[1], "-l") == 0) {
    list = 1;
  }
  
  dpy = XOpenDisplay(NULL);

  if (!dpy) {
    printf("unable to connect to X Server try to set the DISPLAY variable\n");
    exit(1);
  }

#ifdef DEBUG
  printf("connected to %s\n", XDisplayString(dpy));
#endif

  screen = DefaultScreen(dpy);
  root_win = RootWindow(dpy, screen);

  extensions = XListExtensions(dpy, &num_extensions);
  for (loop = 0; loop < num_extensions &&
         (strcmp(extensions[loop], "XInputExtension") != 0); loop++);
  XFreeExtensionList(extensions);
  if (loop != num_extensions)
    {
      devices = XListInputDevices(dpy, &num_devices);
      for(loop=0; loop<num_devices; loop++)
        {
          if (devices[loop].name &&
              (StrCaseCmp(devices[loop].name, argv[1]) == 0))
            if (devices[loop].use == IsXExtensionDevice)
              {
                XDevice *device;
              
#ifdef DEBUG
                fprintf(stderr, "opening device %s\n",
                        devices[loop].name ? devices[loop].name : "<noname>");
#endif
                device = XOpenDevice(dpy, devices[loop].id);
                if (device)
                  {
		    XSetDeviceMode(dpy, device, (strcmp("ABSOLUTE", argv[2]) == 0) ? Absolute
				   : Relative);
                    exit(0);
                  }
                else
                  {
                    fprintf(stderr, "error opening device\n");
                    exit(1);
                  }
              }
        }
      XFreeDeviceList(devices);
    }
  else
    {
      fprintf(stderr, "No XInput extension available\n");
      exit(1);
    }
  
  if (list) {
    exit(0);
  }
  else {
    fprintf(stderr, "Extended device %s not found\n", argv[1]);
    exit(1);
  }
}
Пример #26
0
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;
}
Пример #27
0
extern "C" KDE_EXPORT int kdemain(int argc, char **argv)
{
    {
        QCString multiHead = getenv("KDE_MULTIHEAD");
        if(multiHead.lower() == "true")
        {
            Display *dpy = XOpenDisplay(NULL);
            if(!dpy)
            {
                fprintf(stderr, "%s: FATAL ERROR: couldn't open display %s\n", argv[0], XDisplayName(NULL));
                exit(1);
            }

            int number_of_screens = ScreenCount(dpy);
            kicker_screen_number = DefaultScreen(dpy);
            int pos;
            QCString display_name = XDisplayString(dpy);
            XCloseDisplay(dpy);
            dpy = 0;

            if((pos = display_name.findRev('.')) != -1)
                display_name.remove(pos, 10);

            QCString env;
            if(number_of_screens != 1)
            {
                for(int i = 0; i < number_of_screens; i++)
                {
                    if(i != kicker_screen_number && fork() == 0)
                    {
                        kicker_screen_number = i;
                        // break here because we are the child process, we don't
                        // want to fork() anymore
                        break;
                    }
                }

                env.sprintf("DISPLAY=%s.%d", display_name.data(), kicker_screen_number);

                if(putenv(strdup(env.data())))
                {
                    fprintf(stderr, "%s: WARNING: unable to set DISPLAY environment variable\n", argv[0]);
                    perror("putenv()");
                }
            }
        }
    }

    KGlobal::locale()->setMainCatalogue("kicker");

    QCString appname;
    if(kicker_screen_number == 0)
        appname = "kicker";
    else
        appname.sprintf("kicker-screen-%d", kicker_screen_number);

    KAboutData aboutData(appname.data(), I18N_NOOP("KDE Panel"), version, description, KAboutData::License_BSD,
                         I18N_NOOP("(c) 1999-2004, The KDE Team"));

    aboutData.addAuthor("Aaron J. Seigo", I18N_NOOP("Current maintainer"), "*****@*****.**");
    aboutData.addAuthor("Matthias Elter", 0, "*****@*****.**");
    aboutData.addAuthor("Matthias Ettrich", 0, "*****@*****.**");
    aboutData.addAuthor("Wilco Greven", 0, "*****@*****.**");
    aboutData.addAuthor("Rik Hemsley", 0, "*****@*****.**");
    aboutData.addAuthor("Daniel M. Duley", 0, "*****@*****.**");
    aboutData.addAuthor("Preston Brown", 0, "*****@*****.**");
    aboutData.addAuthor("John Firebaugh", 0, "*****@*****.**");
    aboutData.addAuthor("Waldo Bastian", I18N_NOOP("Kiosk mode"), "*****@*****.**");

    aboutData.addCredit("Jessica Hall", /* I18N_NOOP("KConfigXT") */ 0, "*****@*****.**");
    aboutData.addCredit("Stefan Nikolaus", /* I18N_NOOP("Bug fixes") */ 0, "*****@*****.**");
    aboutData.addCredit("Benoît Minisini", /* I18N_NOOP("Bug fixes") */ 0, "*****@*****.**");
    KCmdLineArgs::init(argc, argv, &aboutData);

    if(!Kicker::start())
    {
        kdError() << "kicker is already running!" << endl;
        return 0;
    }

    if(signal(SIGTERM, sighandler) == SIG_IGN)
        signal(SIGTERM, SIG_IGN);
    if(signal(SIGINT, sighandler) == SIG_IGN)
        signal(SIGINT, SIG_IGN);
    if(signal(SIGHUP, sighandler) == SIG_IGN)
        signal(SIGHUP, SIG_IGN);

    // send it even before KApplication ctor, because ksmserver will launch another app as soon
    // as QApplication registers with it
    DCOPClient *cl = new DCOPClient;
    cl->attach();
    DCOPRef r("ksmserver", "ksmserver");
    r.setDCOPClient(cl);
    r.send("suspendStartup", QCString("kicker"));
    delete cl;
    Kicker *kicker = new Kicker;
    int rv = kicker->exec();
    delete kicker;
    return rv;
}
Пример #28
0
/********************************************************************
 *
 * Setup a child service record per the selection request.
 */
void mgr_initialize( XEvent *report, XpPdmServiceRec *rec )
{
    Display *testdpy;
    char    buf[1024];

    Display *selection_display;
    Window   requestor;
    Atom     prop_atom;
    unsigned long tafter;

    XTextProperty  text_prop;
    char           **list;
    int            list_cnt;

    /*
     * Grab the PDM_CLIENT_PROP from which all the juicy
     * information is retrieved.
     */
    selection_display = report->xselectionrequest.display;
    requestor = report->xselectionrequest.requestor;
    prop_atom = report->xselectionrequest.property;

    if ( XGetWindowProperty( selection_display, requestor, prop_atom,
			0, 100000, True, AnyPropertyType,
                        &text_prop.encoding,
			&text_prop.format,
			&text_prop.nitems,
			&tafter,
                        &text_prop.value ) != Success ) {
	/*
	 * Error
	 */
	rec->pdm_exec_errorcode = g.pdm_start_error;

	sprintf( buf, PDMD_MSG_5, g.prog_name );
	rec->pdm_exec_errormessage = xpstrdup( buf );

	return;
    }

    if ( text_prop.format != 8 ) {
	/*
	 * Error
	 */
	rec->pdm_exec_errorcode = g.pdm_start_error;

	sprintf( buf, PDMD_MSG_6, g.prog_name );
	rec->pdm_exec_errormessage = xpstrdup( buf );

	return;
    }

    if ( XmbTextPropertyToTextList( selection_display, &text_prop,
				     &list, &list_cnt ) < 0 ) {
	/*
	 * Error
	 */
	rec->pdm_exec_errorcode = g.pdm_start_error;

	sprintf( buf, PDMD_MSG_7, g.prog_name );
	rec->pdm_exec_errormessage = xpstrdup( buf );

	return;
    }

    /*
     * Fill in the PDM_MANAGER portion of the client record.
     */
    rec->video_display_str  = xpstrdup( list[0] );
    rec->video_window       = strtol(list[1], (char **)NULL, 16);
    rec->print_display_str  = xpstrdup( list[2] );
    rec->print_window       = strtol(list[3], (char **)NULL, 16);
#if 0 && defined(PRINTING_SUPPORTED)
    rec->print_context      = strtol(list[4], (char **)NULL, 16);
#endif /* PRINTING_SUPPORTED */
    rec->locale_hint        = xpstrdup( list[5] );
    XFreeStringList( list );

    rec->selection_display  = selection_display;
    rec->requestor          = requestor;
    rec->prop_atom          = prop_atom;
    rec->selection          = report->xselectionrequest.selection;
    rec->time               = report->xselectionrequest.time;

    rec->mgr_flag           = True;	/* mgr portion of rec now valid */

    /*
     * Optimization.  The only live display connection, for which we
     * need to trap XIO errors, is "selection display".  For the
     * "video" and "print" displays, we have the display strings and
     * can establish connections as we need them.  Since they are rarely
     * used, and opening them up here would create XIO liability problems
     * and a startup performance hit, we won't establish connections now.
     *
     * One optimization however is to see if the "print" display would
     * just happen to be the same at the "selection display" currently
     * open.
     */
    if ( !strcmp( XDisplayString(rec->selection_display),
		  rec->print_display_str ) ) {
	rec->seldpy_as_printdpy = True;
    }
    else {
	rec->seldpy_as_printdpy = False;

#ifdef OPTIONAL_PXAUTH_PRETEST
	/*
	 * Verify connectability to the Print Server.
	 *
	 * Note: once beyond the selection phase, all communication
	 *       will be by way of the Print Server.  If we cannot
	 *       connect later, then we will have no way to deliver
	 *       EXIT_PXAUTH, EXIT_VXAUTH, EXIT_ERROR, EXIT_OK or
         *       EXIT_CANCEL.  Real bad news!
	 *
	 * It is better to discover now that we don't have
	 * connection authorization for the print display since
	 * we can still let the user know of PXAUTH problems
	 * via the selection display currently open.
	 *
	 * Unfortunately, this pre-test is a performance hit in the
	 * startup phase.
	 */
	if ( ! (testdpy = XOpenDisplay(rec->print_display_str)) ) {
	    rec->pdm_exec_errorcode = g.pdm_start_pxauth;
	    return;
	}
	XCloseDisplay( testdpy );
#endif /* OPTIONAL_PXAUTH_PRETEST */
    }

#ifdef OPTIONAL_VXAUTH_PRETEST
    /*
     * Verify connectability to the Video Server.
     *
     * It is better to discover now that we don't have
     * connection authorization for the video display since
     * we can still let the user know of VXAUTH problems
     * via the selection display currently open.
     *
     * Unfortunately, this pre-test is a performance hit in the
     * startup phase.
     */
    if ( ! (testdpy = XOpenDisplay(rec->video_display_str)) ) {
	rec->pdm_exec_errorcode = g.pdm_start_vxauth;
	return;
    }
    XCloseDisplay( testdpy );
#endif /* OPTIONAL_VXAUTH_PRETEST */

}
Пример #29
0
static
void *XpuPrintToFile( Display *pdpy, XPContext pcontext, const char *filename )
{
  MyPrintFileData *mpfd;

  if( (mpfd = (MyPrintFileData *)malloc(sizeof(MyPrintFileData))) == NULL )
    return(NULL);

  /* create pipe */
  if( pipe(mpfd->pipe) == -1 ) 
  {
    /* this should never happen, but... */
    perror("XpuPrintToFile: cannot create pipe");
    free(mpfd);
    return(NULL);
  }
        
  mpfd->parent_pdpy = pdpy;
  mpfd->displayname = XDisplayString(pdpy);
  mpfd->pcontext    = pcontext;
  mpfd->file_name   = filename;
  mpfd->file        = NULL;
  mpfd->status      = XPGetDocError;
  
  /* make sure we can open the file for writing */
  if( (mpfd->file = fopen(mpfd->file_name, "w")) == NULL ) 
  {
    /* fopen() error */
    close(mpfd->pipe[1]);
    close(mpfd->pipe[0]);      
    free(mpfd);
    return(NULL);
  }
  
  /* its important to flush before we fork, to make sure that the
   * XpStartJob gets through first in the parent
   */
  XFlush(pdpy);     
  
  mpfd->pid = fork();

  if( mpfd->pid == 0 ) 
  {
    /* we're now in the fork()'ed child */
    PrintToFile_Consumer(mpfd);
  }
  else if( mpfd->pid < 0 ) 
  {
    /* fork() error */
    close(mpfd->pipe[1]);
    close(mpfd->pipe[0]);
    fclose(mpfd->file);
    free(mpfd);
    return(NULL);
  }
  
  /* we're still in the parent */
  XPU_DEBUG_ONLY(printf("### parent fork()'ed consumer child.\n"));
  
  /* child will write into file - we don't need it anymore here... :-) */
  fclose(mpfd->file);
  close(mpfd->pipe[1]);
  return(mpfd);      
}
Пример #30
0
extern struct gl_platform *gl_platform_create(gs_device_t *device,
		const struct gs_init_data *info)
{
	/* There's some trickery here... we're mixing libX11, xcb, and GLX
	   For an explanation see here: http://xcb.freedesktop.org/MixingCalls/
	   Essentially, GLX requires Xlib. Everything else we use xcb. */
	struct gl_windowinfo *wi = gl_windowinfo_create(info);
	struct gl_platform * plat = bmalloc(sizeof(struct gl_platform));
	Display * display;

	print_info_stuff(info);

	if (!wi) {
		blog(LOG_ERROR, "Failed to create window info!");
		goto fail_wi_create;
	}

	display = XOpenDisplay(XDisplayString(info->window.display));
	if (!display) {
		blog(LOG_ERROR, "Unable to open new X connection!");
		goto fail_display_open;
	}

	XSetEventQueueOwner(display, XCBOwnsEventQueue);
	XSetErrorHandler(x_error_handler);

	/* We assume later that cur_swap is already set. */
	device->cur_swap = &plat->swap;
	device->plat = plat;

	plat->display = display;
	plat->swap.device = device;
	plat->swap.info = *info;
	plat->swap.wi = wi;

	if (!gl_platform_init_swapchain(&plat->swap)) {
		blog(LOG_ERROR, "Failed to initialize swap chain!");
		goto fail_init_swapchain;
	}

	if (!gl_context_create(plat)) {
		blog(LOG_ERROR, "Failed to create context!");
		goto fail_context_create;
	}

	if (!glXMakeCurrent(plat->display, wi->window, plat->context)) {
		blog(LOG_ERROR, "Failed to make context current.");
		goto fail_make_current;
	}

	if (!gladLoadGL()) {
		blog(LOG_ERROR, "Failed to load OpenGL entry functions.");
		goto fail_load_gl;
	}

	blog(LOG_INFO, "OpenGL version: %s\n", glGetString(GL_VERSION));

	goto success;

fail_make_current:
	gl_context_destroy(plat);
fail_context_create:
fail_load_gl:
fail_init_swapchain:
	XCloseDisplay(display);
fail_display_open:
fail_wi_create:
	gl_windowinfo_destroy(wi);
	free(plat);
	plat = NULL;
success:
	return plat;
}