Exemple #1
0
static void
SetLabelAndModeline(void)
{
    if (vidtune->monitor != NULL) {
	char string[32];

	XtVaSetValues(monitorb, XtNlabel,
		      vidtune->monitor->mon_identifier, NULL);
	XtSetSensitive(add, True);

	if (modeline.htotal && modeline.vtotal)
	    XmuSnprintf(string, sizeof(string), "%dx%d@%d",
			modeline.hdisplay, modeline.vdisplay,
			(int)((double)dot_clock / (double)modeline.htotal * 1000.0 /
			(double)modeline.vtotal));
	else
	    XmuSnprintf(string, sizeof(string), "%dx%d",
			modeline.hdisplay, modeline.vdisplay);
	XtVaSetValues(text, XtNstring, string, NULL);
    }
    else {
	XtVaSetValues(monitorb, XtNlabel, "", NULL);
	XtSetSensitive(add, False);
	XtVaSetValues(text, XtNstring, "", NULL);
    }
}
Exemple #2
0
static void
SwitchCallback(Widget w, XtPointer call_data, XtPointer client_data)
{
    int direction = (long)call_data;
    Arg args[1];
    Bool result;
    char label[32];

    XF86VidModeLockModeSwitch(XtDisplay(toplevel), vidtune->screen, False);
    result = XF86VidModeSwitchMode(XtDisplay(toplevel), vidtune->screen,
				   direction);
    XF86VidModeLockModeSwitch(XtDisplay(toplevel), vidtune->screen, True);
    if (!result)
	return;

    UpdateCallback(w, call_data, client_data);

    if (modeline.htotal && modeline.vtotal)
	XmuSnprintf(label, sizeof(label), "%dx%d @ %d Hz",
		    modeline.hdisplay, modeline.vdisplay,
		    (int)((double)dot_clock / (double)modeline.htotal * 1000.0 /
		    (double)modeline.vtotal));
    else
	XmuSnprintf(label, sizeof(label), "%dx%d",
		    modeline.hdisplay, modeline.vdisplay);
    XtSetArg(args[0], XtNlabel, label);
    XtSetValues(mode, args, 1);
}
Exemple #3
0
static char *
makeBackupName(String buf, String filename, unsigned len)
{
    if (app_resources.backupNamePrefix
	&& strlen(app_resources.backupNamePrefix)) {
	if (strchr(app_resources.backupNamePrefix, '/'))
	    XmuSnprintf(buf, len, "%s%s%s", app_resources.backupNamePrefix,
			filename, app_resources.backupNameSuffix);
	else {
	    char fname[BUFSIZ];
	    char *name, ch;

	    strncpy(fname, filename, sizeof(fname) - 1);
	    fname[sizeof(fname) - 1] = '\0';
	    if ((name = strrchr(fname, '/')) != NULL)
		++name;
	    else
		name = filename;
	    ch = *name;
	    *name = '\0';
	    ++name;
	    XmuSnprintf(buf, len, "%s%s%c%s%s",
			fname, app_resources.backupNamePrefix, ch, name,
			app_resources.backupNameSuffix);
	}
    }
    else
	XmuSnprintf(buf, len, "%s%s",
		    filename, app_resources.backupNameSuffix);

    return (strcmp(filename, buf) ? buf : NULL);
}
Exemple #4
0
void 
_XawTextSearch(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
    TextWidget ctx = (TextWidget)w;
    XawTextScanDirection dir;
    char *ptr, buf[BUFSIZ];
    XawTextEditType edit_mode;
    Arg args[1];
    wchar_t wcs[1];

    if (*num_params < 1 || *num_params > 2) {
	(void)XmuSnprintf(buf, sizeof(buf), "%s %s\n%s", SEARCH_HEADER, 
			  "This action must have only", 
			  "one or two parameters");
	XtAppWarning(XtWidgetToApplicationContext(w), buf);
	return;
    }

    if (*num_params == 2)
	ptr = params[1];
    else if (XawTextFormat(ctx, XawFmtWide)) {
	/* This just does the equivalent of
	   ptr = ""L, a waste because params[1] isnt W aligned */
	ptr = (char *)wcs;
	wcs[0] = 0;
    }
    else
	ptr = "";

    switch(params[0][0]) {
	case 'b': 		  /* Left */
	case 'B':
	    dir = XawsdLeft;
	    break;
	case 'f': 		  /* Right */
	case 'F':
	    dir = XawsdRight;
	    break;
	default:
	    (void)XmuSnprintf(buf, sizeof(buf), "%s %s\n%s", SEARCH_HEADER, 
			      "The first parameter must be",
			      "Either 'backward' or 'forward'");
	    XtAppWarning(XtWidgetToApplicationContext(w), buf);
	    return;
    }

    if (ctx->text.search== NULL) {
	ctx->text.search = XtNew(struct SearchAndReplace);
	ctx->text.search->search_popup = CreateDialog(w, ptr, "search",
						      AddSearchChildren);
	XtRealizeWidget(ctx->text.search->search_popup);
	SetWMProtocolTranslations(ctx->text.search->search_popup);
    }
Exemple #5
0
static void
GetModes(void)
{
    int i;
    char label[32];
    Arg args[1];
    static char menuName[16];
    static int menuN;

    XFree(vidtune->infos);
    XF86VidModeGetAllModeLines(XtDisplay(toplevel), vidtune->screen,
			       &vidtune->num_infos, &vidtune->infos);

    XmuSnprintf(menuName, sizeof(menuName), "menu%d", menuN);
    menuN = !menuN;
    if (menu)
	XtDestroyWidget(menu);
    menu = XtCreatePopupShell(menuName, simpleMenuWidgetClass, vtune, NULL, 0);
    XtVaSetValues(mode, XtNmenuName, menuName, NULL, 0);
    for (i = 0; i < vidtune->num_infos; i++) {
	Widget sme;

	if ((double)vidtune->infos[i]->htotal &&
	    (double)vidtune->infos[i]->vtotal)
	    XmuSnprintf(label, sizeof(label), "%dx%d @ %d Hz",
			vidtune->infos[i]->hdisplay,
			vidtune->infos[i]->vdisplay,
			(int)((double)vidtune->infos[i]->dotclock /
			(double)vidtune->infos[i]->htotal * 1000.0 /
			(double)vidtune->infos[i]->vtotal));
	else
	    XmuSnprintf(label, sizeof(label), "%dx%d",
			vidtune->infos[i]->hdisplay,
			vidtune->infos[i]->vdisplay);
	sme = XtCreateManagedWidget(label, smeBSBObjectClass, menu, NULL, 0);
	XtAddCallback(sme, XtNcallback, SelectCallback,
		      (XtPointer)vidtune->infos[i]);
    }

    if (modeline.htotal && modeline.vtotal)
	XmuSnprintf(label, sizeof(label), "%dx%d @ %d Hz",
		    modeline.hdisplay, modeline.vdisplay,
		    (int)((double)dot_clock / (double)modeline.htotal * 1000.0 /
		    (double)modeline.vtotal));
    else
	XmuSnprintf(label, sizeof(label), "%dx%d",
		    modeline.hdisplay, modeline.vdisplay);
    XtSetArg(args[0], XtNlabel, label);
    XtSetValues(mode, args, 1);
}
Exemple #6
0
/*ARGSUSED*/
static Boolean
_XawCvtPixelToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		     XrmValue *fromVal, XrmValue *toVal,
		     XtPointer *converter_data)
{
  static char buffer[19];
  Cardinal size;
  Colormap colormap;
  XColor color;

  if (*num_args != 1)
    {
      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		      XtNwrongParameters, "cvtPixelToString",
		      XtCToolkitError,
		      "Pixel to String conversion needs colormap argument",
		      NULL, NULL);
      return (False);
    }

  colormap = *(Colormap *)args[0].addr;
  color.pixel = *(Pixel *)fromVal->addr;

  /* Note:
   * If we know the visual type, we can calculate the xcolor
   * without asking Xlib.
   */
  XQueryColor(dpy, colormap, &color);
  XmuSnprintf(buffer, sizeof(buffer), "rgb:%04hx/%04hx/%04hx",
	      color.red, color.green, color.blue);
  size = strlen(buffer) + 1;

  string_done(buffer);
}
Exemple #7
0
/*ARGSUSED*/
Boolean
XmuCvtLongToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
                   XrmValuePtr fromVal, XrmValuePtr toVal, XtPointer *data)
{
    static char buffer[32];
    size_t size;

    if (*num_args != 0)
        XtWarning("Long to String conversion needs no extra arguments");

    XmuSnprintf(buffer, sizeof(buffer), "%ld", *(long *)fromVal->addr);

    size = strlen(buffer) + 1;
    if (toVal->addr != NULL)
    {
        if (toVal->size < size)
        {
            toVal->size = size;
            return (False);
        }
        strcpy((char *)toVal->addr, buffer);
    }
    else
        toVal->addr = (XPointer)buffer;
    toVal->size = sizeof(String);

    return (True);
}
Exemple #8
0
static void
EventLoop(Display *dpy, Window win, GC gc)
{
   XEvent ev;
   while (1) {
      XNextEvent( dpy, &ev );
      switch (ev.type) {
      case ReparentNotify:
         break;
      case MapNotify:
         break;
      case ConfigureNotify:
      case Expose:
         {         
            int numScreens, count, i;
            DMXWindowAttributes *winInfo;
            int x, y;
            const char *msg = "DMX window info:";

            DMXGetScreenCount(dpy, &numScreens);
            winInfo
                = (DMXWindowAttributes *)
                malloc(numScreens * sizeof(DMXWindowAttributes));
            assert(winInfo);
            if (!DMXGetWindowAttributes(dpy, win, &count,
                                        numScreens, winInfo)) {
               printf("Could not get window information for 0x%08lx\n",
                      (long unsigned)win);
            }
            x = y = 50;
            XClearWindow(dpy, win);
            XDrawString(dpy, win, gc, x, y, msg, strlen(msg));
            y += 20;
            for (i = 0; i < count; i++) {
               char str[500];
               XmuSnprintf(str, sizeof(str),
                       "screen %d:  pos: %dx%d+%d+%d  visible: %dx%d+%d+%d",
                       winInfo[i].screen,
                       winInfo[i].pos.width, winInfo[i].pos.height,
                       winInfo[i].pos.x, winInfo[i].pos.y,
                       winInfo[i].vis.width, winInfo[i].vis.height, 
                       winInfo[i].vis.x, winInfo[i].vis.y);
               XDrawString(dpy, win, gc, x, y, str, strlen(str));
               y += 20;
            }
            free(winInfo);
         }
         break;
      default:
         printf("Event type 0x%x\n", ev.type);
      }
   }
}
Exemple #9
0
/*ARGSUSED*/
static void 
DoInsert(Widget w, XtPointer closure, XtPointer call_data)
{
    TextWidget ctx = (TextWidget)closure;
    char buf[BUFSIZ], msg[BUFSIZ];
    Widget temp_widget;

    (void)XmuSnprintf(buf, sizeof(buf), "%s.%s", FORM_NAME, TEXT_NAME);
    if ((temp_widget = XtNameToWidget(ctx->text.file_insert, buf)) == NULL) {
	(void)strcpy(msg,
		     "Error: Could not get text widget from file insert popup");
    }
    else if (InsertFileNamed((Widget)ctx, GetString(temp_widget))) {
	PopdownFileInsert(w, closure, call_data);
	return;
    }
    else
	(void)XmuSnprintf(msg, sizeof(msg), "Error: %s", strerror(errno));

    (void)SetResourceByName(ctx->text.file_insert, 
			    LABEL_NAME, XtNlabel, (XtArgVal)msg);
    XBell(XtDisplay(w), 0);
}
Exemple #10
0
int
parser_range_to_string(char *str, parser_range *range, int nrange)
{
    int i, len;

    if (str == NULL || range == NULL || nrange <= 0)
	return (0);

    for (i = len = 0; i < nrange; i++) {
	if (i > 0)
	    len += XmuSnprintf(str + len, PARSER_RANGE_SIZE - len, "%s",
			       ", ");
	if (range[i].lo == range[i].hi)
	    len += XmuSnprintf(str + len, PARSER_RANGE_SIZE - len, "%g",
			       range[i].lo);
	else if (range[i].lo < range[i].hi)
	    len += XmuSnprintf(str + len, PARSER_RANGE_SIZE - len, "%g - %g",
			       range[i].lo, range[i].hi);
	else
	    return (0);
    }

    return (i);
}
Exemple #11
0
/*ARGSUSED*/
static Boolean
_XawCvtCardinalToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			XrmValue *fromVal, XrmValue *toVal,
			XtPointer *converter_data)
{
  static char buffer[11];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRCardinal);

  XmuSnprintf(buffer, sizeof(buffer), "%u", *(Cardinal *)fromVal->addr);
  size = strlen(buffer) + 1;

  string_done(buffer);
}
Exemple #12
0
void
XawTypeToStringWarning(Display *dpy, String type)
{
  char fname[64];
  String params[1];
  Cardinal num_params;

  XmuSnprintf(fname, sizeof(fname), "cvt%sToString", type);

  params[0] = type;
  num_params = 1;
  XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		  XtNconversionError, fname, XtCToolkitError,
		  "Cannot convert %s to String",
		  params, &num_params);
}
Exemple #13
0
static void
TypeToStringNoArgsWarning(Display *dpy, String type)
{
  char fname[64];
  String params[1];
  Cardinal num_params;

  XmuSnprintf(fname, sizeof(fname), "cvt%sToString", type);

  params[0] = type;
  num_params = 1;
  XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		  XtNconversionError, fname,
		  XtCToolkitError,
		  "%s to String conversion needs no extra arguments",
		  params, &num_params);
}
Exemple #14
0
/*ARGSUSED*/
static Boolean
_XawCvtBooleanToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		       XrmValue *fromVal, XrmValue *toVal,
		       XtPointer *converter_data)
{
  static char buffer[6];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRBoolean);

  XmuSnprintf(buffer, sizeof(buffer), "%s",
	      *(Boolean *)fromVal->addr ? XtEtrue : XtEfalse);
  size = strlen(buffer) + 1;

  string_done(buffer);
}
Exemple #15
0
static void
StartFormatPosition(void)
{
    char *fmt = app_resources.position_format;

    if (fmt)
	while (*fmt)
	    if (*fmt++ == '%') {
		int len = 0;

		if (*fmt == '-') {
		    ++fmt;
		    ++len;
		}
		while (*fmt >= '0' && *fmt <= '9') {
		    ++fmt;
		    if (++len >= MAX_FMT_LEN) {
			XtAppWarning(XtWidgetToApplicationContext(topwindow),
				     "Format too large to formatPosition");
			position_format_mask = 0;
			return;
		    }
		}
		switch (*fmt++) {
		    case 'l':	position_format_mask |= l_BIT;	break;
		    case 'c':	position_format_mask |= c_BIT;	break;
		    case 'p':	position_format_mask |= p_BIT;	break;
		    case 's':	position_format_mask |= s_BIT;	break;
		    case '%':	break;
		    default: {
			char msg[256];

			XmuSnprintf(msg, sizeof(msg),
				    "Unknown format \"%%%c\" in positionFormat",
				    fmt[-1]);
			XtAppWarning(XtWidgetToApplicationContext(topwindow),
				     msg);
			position_format_mask = 0;
			return;
		    }
		}
	    }
}
Exemple #16
0
static void
XawSimpleClassPartInitialize(WidgetClass cclass)
{
    SimpleWidgetClass c = (SimpleWidgetClass)cclass;
    SimpleWidgetClass super = (SimpleWidgetClass)c->core_class.superclass;

    if (c->simple_class.change_sensitive == NULL) {
	char buf[BUFSIZ];

	(void)XmuSnprintf(buf, sizeof(buf),
			  "%s Widget: The Simple Widget class method "
			  "'change_sensitive' is undefined.\nA function "
			  "must be defined or inherited.",
			  c->core_class.class_name);
	XtWarning(buf);
	c->simple_class.change_sensitive = ChangeSensitive;
    }

    if (c->simple_class.change_sensitive == XtInheritChangeSensitive)
	c->simple_class.change_sensitive = super->simple_class.change_sensitive;
}
Exemple #17
0
/*ARGSUSED*/
static Boolean
_XawCvtFontStructToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			  XrmValue *fromVal, XrmValue *toVal,
			  XtPointer *converter_data)
{
  static char buffer[128];
  Cardinal size;
  Atom atom;
  unsigned long value;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRFontStruct);

  if ((atom = XInternAtom(dpy, "FONT", True)) == None)
    return (False);

  size = 0;

  if (XGetFontProperty(*(XFontStruct **)fromVal->addr, atom, &value))
    {
      char *tmp = XGetAtomName(dpy, value);

      if (tmp)
	{
	  XmuSnprintf(buffer, sizeof(buffer), "%s", tmp);
	  size = strlen(tmp);
	  XFree(tmp);
	}
    }

  if (size)
    {
      ++size;
    string_done(buffer);
    }

  XawTypeToStringWarning(dpy, XtRFontStruct);

  return (False);
}
Exemple #18
0
char *
GetOptionDescription(char *module, char *option)
{
    char *type;
    XrmValue value;
    char query[256];
    unsigned char *ptr;

    InitializeOptionsDatabase();

    XmuSnprintf(query, sizeof(query), "%s.%s", module, option);
    ptr = (unsigned char*)strchr(query, '.') + 1;
    for (; *ptr; ptr++) {
	if (*ptr == '_' || *ptr == ' ' || *ptr == '\t')
	    memmove(ptr, ptr + 1, strlen((char*)ptr) + 1);
    }
    for (ptr = (unsigned char*)query; *ptr; ptr++)
	*ptr = tolower(*ptr);
    if (XrmGetResource(options_xrm, query, "Module.Option", &type, &value))
	return ((char*)value.addr);

    return (NULL);
}
Exemple #19
0
static void
SelectModuleOptionCallback(Widget w, XtPointer user_data, XtPointer call_data)
{
    xf86cfgModuleOptions *mod = module_options;
    XawListReturnStruct *info = (XawListReturnStruct *)call_data;
    char *description = NULL, *type = "undefined";
    char label[256];

    if (module_sel && info->string)
	description = GetOptionDescription(module_sel, info->string);
    if (description == NULL)
	description = "** NO DESCRIPTION AVAILABLE **";

    XtVaSetValues(desc, XtNstring, description, NULL);

    while (mod) {
	if (strcmp(module_sel, mod->name) == 0)
	    break;
	mod = mod->next;
    }
    if (mod) {
	OptionInfoPtr opts = mod->option;

	while (opts && opts->name) {
	    if (strcasecmp(opts->name, info->string) == 0)
		break;
	    ++opts;
	}
	if (opts && opts->name && opts->type >= OPTV_NONE &&
	    opts->type <= OPTV_FREQ)
	    type = types[opts->type];
    }

    XmuSnprintf(label, sizeof(label), "%s.%s (%s)", module_sel, info->string,
	        type);
    XtVaSetValues(labelType, XtNlabel, label, NULL);
}
Exemple #20
0
/*
 * Implementation
 */
Bool
VideoModeInitialize(void)
{
    Widget form;
    char dispstr[128], *ptr, *tmp;

    static char *names[] = {
	NULL,
	NULL,
	"hsyncstart",
	"hsyncend",
	"htotal",
	"vsyncstart",
	"vsyncend",
	"vtotal",
	"flags",
	"clock",
	"hsync",
	"vsync",
    };
    static char *vnames[] = {
	NULL,
	NULL,
	"v-hsyncstart",
	"v-hsyncend",
	"v-htotal",
	"v-vsyncstart",
	"v-vsyncend",
	"v-vtotal",
	"v-flags",
	"v-clock",
	"v-hsync",
	"v-vsync",
    };
    Widget rep;
    int i;

    if (!XF86VidModeQueryVersion(XtDisplay(toplevel),
				 &MajorVersion, &MinorVersion)) {
	fprintf(stderr, "Unable to query video extension version\n");
	return (False);
    }
    else if (!XF86VidModeQueryExtension(XtDisplay(toplevel),
					&EventBase, &ErrorBase)) {
	fprintf(stderr, "Unable to query video extension information\n");
	return (False);
    }
    else if (MajorVersion < MINMAJOR ||
	(MajorVersion == MINMAJOR && MinorVersion < MINMINOR)) {
	fprintf(stderr,
		"Xserver is running an old XFree86-VidModeExtension version"
		" (%d.%d)\n", MajorVersion, MinorVersion);
	fprintf(stderr, "Minimum required version is %d.%d\n",
		MINMAJOR, MINMINOR);
	return (False);
    }
    else
	InitializeVidmodes();

    vtune = XtCreateWidget("vidtune", formWidgetClass,
			   work, NULL, 0);

    (void) XtVaCreateManagedWidget("vesaB", menuButtonWidgetClass, vtune,
				    XtNmenuName, "vesaP", NULL, 0);
    vesap = XtCreatePopupShell("vesaP", simpleMenuWidgetClass, vtune, NULL, 0);
    for (i = 0; i < sizeof(vesamodes) / sizeof(vesamodes[0]); i++) {
	rep = XtCreateManagedWidget(vesamodes[i].ident, smeBSBObjectClass,
				    vesap, NULL, 0);
	XtAddCallback(rep, XtNcallback, AddVesaModeCallback,
		      (XtPointer)&vesamodes[i]);
    }

    rep = XtCreateManagedWidget("prev", commandWidgetClass, vtune, NULL, 0);
    XtAddCallback(rep, XtNcallback, SwitchCallback, (XtPointer)-1);
    mode = XtCreateManagedWidget("mode", menuButtonWidgetClass, vtune, NULL, 0);
    rep = XtCreateManagedWidget("next", commandWidgetClass, vtune, NULL, 0);
    XtAddCallback(rep, XtNcallback, SwitchCallback, (XtPointer)1);

    screenp = XtCreatePopupShell("screenP", simpleMenuWidgetClass, vtune,
				 NULL, 0);

    XmuSnprintf(dispstr, sizeof(dispstr), "%s",
		DisplayString(XtDisplay(toplevel)));
    ptr = strrchr(dispstr, '.');
    tmp = strrchr(dispstr, ':');
    if (tmp != NULL && ptr != NULL && ptr > tmp)
	*ptr = '\0';

    for (i = 0; i < ScreenCount(XtDisplay(toplevel)); i++) {
	char name[128];

	XmuSnprintf(name, sizeof(name), "%s.%d", dispstr, i);
	rep = XtCreateManagedWidget(name, smeBSBObjectClass, screenp,
				    NULL, 0);
	XtAddCallback(rep, XtNcallback, ChangeScreenCallback,
	    (XtPointer)(long)i);
	if (i == 0) {
	    screenb = XtVaCreateManagedWidget("screenB", menuButtonWidgetClass,
					      vtune,
					      XtNmenuName, "screenP",
					      XtNlabel, name,
					      NULL, 0);
	}
    }
    XtRealizeWidget(screenp);

    rep = XtCreateManagedWidget("up", repeaterWidgetClass,
				vtune, NULL, 0);
    XtAddCallback(rep, XtNstartCallback, StartAdjustMonitorCallback, NULL);
    XtAddCallback(rep, XtNcallback,
		  AdjustMonitorCallback, (XtPointer)UP);
    XtAddCallback(rep, XtNstopCallback, EndAdjustMonitorCallback, NULL);
    rep = XtCreateManagedWidget("left", repeaterWidgetClass,
				vtune, NULL, 0);
    XtAddCallback(rep, XtNstartCallback, StartAdjustMonitorCallback, NULL);
    XtAddCallback(rep, XtNcallback,
		  AdjustMonitorCallback, (XtPointer)LEFT);
    XtAddCallback(rep, XtNstopCallback, EndAdjustMonitorCallback, NULL);
    XtCreateManagedWidget("monitor", simpleWidgetClass, vtune, NULL, 0);
    rep = XtCreateManagedWidget("right", repeaterWidgetClass,
				vtune, NULL, 0);
    XtAddCallback(rep, XtNstartCallback, StartAdjustMonitorCallback, NULL);
    XtAddCallback(rep, XtNcallback,
		  AdjustMonitorCallback, (XtPointer)RIGHT);
    XtAddCallback(rep, XtNstopCallback, EndAdjustMonitorCallback, NULL);
    rep = XtCreateManagedWidget("down", repeaterWidgetClass,
				vtune, NULL, 0);
    XtAddCallback(rep, XtNstartCallback, StartAdjustMonitorCallback, NULL);
    XtAddCallback(rep, XtNcallback,
		  AdjustMonitorCallback, (XtPointer)DOWN);
    XtAddCallback(rep, XtNstopCallback, EndAdjustMonitorCallback, NULL);
    rep = XtCreateManagedWidget("wider", repeaterWidgetClass,
				vtune, NULL, 0);
    XtAddCallback(rep, XtNstartCallback, StartAdjustMonitorCallback, NULL);
    XtAddCallback(rep, XtNcallback,
		  AdjustMonitorCallback, (XtPointer)WIDER);
    XtAddCallback(rep, XtNstopCallback, EndAdjustMonitorCallback, NULL);
    rep = XtCreateManagedWidget("narrower", repeaterWidgetClass,
				vtune, NULL, 0);
    XtAddCallback(rep, XtNstartCallback, StartAdjustMonitorCallback, NULL);
    XtAddCallback(rep, XtNcallback,
		  AdjustMonitorCallback, (XtPointer)NARROWER);
    XtAddCallback(rep, XtNstopCallback, EndAdjustMonitorCallback, NULL);
    rep = XtCreateManagedWidget("shorter", repeaterWidgetClass,
				vtune, NULL, 0);
    XtAddCallback(rep, XtNstartCallback, StartAdjustMonitorCallback, NULL);
    XtAddCallback(rep, XtNcallback,
		  AdjustMonitorCallback, (XtPointer)SHORTER);
    XtAddCallback(rep, XtNstopCallback, EndAdjustMonitorCallback, NULL);
    rep = XtCreateManagedWidget("taller", repeaterWidgetClass,
				vtune, NULL, 0);
    XtAddCallback(rep, XtNstartCallback, StartAdjustMonitorCallback, NULL);
    XtAddCallback(rep, XtNcallback,
		  AdjustMonitorCallback, (XtPointer)TALLER);
    XtAddCallback(rep, XtNstopCallback, EndAdjustMonitorCallback, NULL);

    automatic = XtCreateManagedWidget("auto", toggleWidgetClass, vtune, NULL, 0);
    XtAddCallback(automatic, XtNcallback, AutoCallback, NULL);
    apply = XtCreateManagedWidget("apply", commandWidgetClass, vtune, NULL, 0);
    XtAddCallback(apply, XtNcallback, ApplyCallback, NULL);
    restore = XtCreateManagedWidget("restore", commandWidgetClass, vtune, NULL, 0);
    XtAddCallback(restore, XtNcallback, RestoreCallback, NULL);
    rep = XtCreateManagedWidget("update", commandWidgetClass, vtune, NULL, 0);
    XtAddCallback(rep, XtNcallback, UpdateCallback, NULL);
    rep = XtCreateManagedWidget("test", commandWidgetClass, vtune, NULL, 0);
    XtAddCallback(rep, XtNcallback, TestCallback, NULL);

    form = XtCreateManagedWidget("form", formWidgetClass, vtune, NULL, 0);
    for (i = 2; i < VSYNC + 1; i++) {
	(void) XtCreateManagedWidget(names[i], labelWidgetClass,
					  form, NULL, 0);
	values[i] = XtCreateManagedWidget(vnames[i], labelWidgetClass,
					  form, NULL, 0);
    }

    add = XtCreateManagedWidget("add", commandWidgetClass, vtune, NULL, 0);
    XtAddCallback(add, XtNcallback, AddModeCallback, NULL);
    XtCreateManagedWidget("addto", labelWidgetClass, vtune, NULL, 0);
    monitorb = XtCreateManagedWidget("ident", menuButtonWidgetClass, vtune,
				     NULL, 0);
    XtCreateManagedWidget("as", labelWidgetClass, vtune, NULL, 0);
    text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, vtune,
				   XtNeditType, XawtextEdit, NULL, 0);

    XtRealizeWidget(vtune);

    return (True);
}
Exemple #21
0
static XawTextProperty *
_XawTextSinkAddProperty(XawTextPropertyList *list, XawTextProperty *property,
			Bool replace)
{
    XawTextProperty *result;
    XColor color;
    char identifier[1024];
    char foreground[16];
    char background[16];
    char *foundry, *family, *weight, *slant, *setwidth, *addstyle, *pixel_size,
	 *point_size, *res_x, *res_y, *spacing, *avgwidth, *registry, *encoding;
    char *xlfd;
    static char *asterisk = "*", *null = "";
    XrmQuark quark;

    if (list == NULL || property == NULL)
	return (NULL);

    if (property->mask & XAW_TPROP_FOREGROUND) {
	color.pixel = property->foreground;
	XQueryColor(DisplayOfScreen(list->screen), list->colormap, &color);
	XmuSnprintf(foreground, sizeof(foreground), "%04x%04x%04x",
		    color.red, color.green, color.blue);
    }
    else
	strcpy(foreground, asterisk);
    if (property->mask & XAW_TPROP_BACKGROUND) {
	color.pixel = property->background;
	XQueryColor(DisplayOfScreen(list->screen), list->colormap, &color);
	XmuSnprintf(background, sizeof(background), "%04x%04x%04x",
		    color.red, color.green, color.blue);
    }
    else
	strcpy(background, asterisk);

    if (property->xlfd_mask & XAW_TPROP_FOUNDRY)
	foundry = XrmQuarkToString(property->foundry);
    else
	foundry = asterisk;

    /* use default, or what was requested */
    if (property->family != NULLQUARK)
	family = XrmQuarkToString(property->family);
    else
	family = asterisk;
    if (property->weight != NULLQUARK)
	weight = XrmQuarkToString(property->weight);
    else
	weight = asterisk;
    if (property->slant != NULLQUARK) {
	slant = XrmQuarkToString(property->slant);
	if (toupper(*slant) != 'R')
	    slant = asterisk;	/* X defaults to italics, so, don't
				   care in resolving between `I' and `O' */
    }
    else
	slant = asterisk;

    if (property->xlfd_mask & XAW_TPROP_SETWIDTH)
	setwidth = XrmQuarkToString(property->setwidth);
    else
	setwidth = asterisk;
    if (property->xlfd_mask & XAW_TPROP_ADDSTYLE)
	addstyle = XrmQuarkToString(property->addstyle);
    else
	addstyle = null;

    /* use default, or what was requested */
    if (!(property->mask & XAW_TPROP_POINTSIZE) &&
	property->pixel_size != NULLQUARK)
	pixel_size = XrmQuarkToString(property->pixel_size);
    else
	pixel_size = asterisk;

    if (property->xlfd_mask & XAW_TPROP_POINTSIZE)
	point_size = XrmQuarkToString(property->point_size);
    else
	point_size = asterisk;
    if (property->xlfd_mask & XAW_TPROP_RESX)
	res_x = XrmQuarkToString(property->res_x);
    else
	res_x = asterisk;
    if (property->xlfd_mask & XAW_TPROP_RESY)
	res_y = XrmQuarkToString(property->res_y);
    else
	res_y = asterisk;
    if (property->xlfd_mask & XAW_TPROP_SPACING)
	spacing = XrmQuarkToString(property->spacing);
    else
	spacing = asterisk;
    if (property->xlfd_mask & XAW_TPROP_AVGWIDTH)
	avgwidth = XrmQuarkToString(property->avgwidth);
    else
	avgwidth = asterisk;

    /* use default, or what that was requested */
    if (property->registry != NULLQUARK)
	registry = XrmQuarkToString(property->registry);
    else
	registry = asterisk;
    if (property->encoding != NULLQUARK)
	encoding = XrmQuarkToString(property->encoding);
    else
	encoding = asterisk;

    if (replace) {
	result = XtNew(XawTextProperty);
	memcpy(result, property, sizeof(XawTextProperty));
    }
    else
	result = property;

    /* XXX should do the best to load a suitable font here */
    if (!(result->mask & XAW_TPROP_FONT)) {
	XmuSnprintf(identifier, sizeof(identifier),
		    "-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s",
		    foundry, family, weight, slant, setwidth, addstyle, pixel_size,
		    point_size, res_x, res_y, spacing, avgwidth, registry, encoding);
	if ((result->font = XLoadQueryFont(DisplayOfScreen(list->screen),
					   identifier)) != NULL) {
	    result->mask |= XAW_TPROP_FONT;
	    SetXlfdDefaults(DisplayOfScreen(list->screen), result);
	}
	else
	    result->mask &= ~XAW_TPROP_FONT;
    }

    if (result->font)
	xlfd = XrmQuarkToString(result->xlfd);
    else
	xlfd = null;

    XmuSnprintf(identifier, sizeof(identifier), "%08lx%08lx%s%s%d%d%d%d%s",
		property->mask, property->xlfd_mask,
		foreground, background,
		(result->mask & XAW_TPROP_UNDERLINE) != 0,
		(result->mask & XAW_TPROP_OVERSTRIKE) != 0,
		(result->mask & XAW_TPROP_SUBSCRIPT) != 0,
		(result->mask & XAW_TPROP_SUPERSCRIPT) != 0,
		xlfd);

    quark = XrmStringToQuark(identifier);
    if (result->identifier == NULLQUARK)
	result->identifier = quark;
    result->code = quark;

    if ((property = _XawTextSinkGetProperty(list, result->identifier)) != NULL) {
	if (result->font)
	    XFreeFont(DisplayOfScreen(list->screen), result->font);
	if (replace)
	    XtFree((XtPointer)result);

	return (property);
    }

    list->properties = (XawTextProperty**)
	XtRealloc((XtPointer)list->properties, sizeof(XawTextProperty*) *
		  (list->num_properties + 1));
    list->properties[list->num_properties++] = result;
    qsort((void*)list->properties, list->num_properties,
	      sizeof(XawTextProperty*), qcmp_qident);

    return (result);
}
Exemple #22
0
/*
 * version that reads pixmap data as well as bitmap data
 */
Pixmap
XmuLocatePixmapFile(Screen *screen, _Xconst char *name, 
			    unsigned long fore, unsigned long back, 
			    unsigned int depth, 
			    char *srcname, int srcnamelen,
			    int *widthp, int *heightp, int *xhotp, int *yhotp)
{

#ifndef BITMAPDIR
#define BITMAPDIR "/usr/include/X11/bitmaps"
#endif

    Display *dpy = DisplayOfScreen (screen);
    Window root = RootWindowOfScreen (screen);
    Bool try_plain_name = True;
    XmuCvtCache *cache = _XmuCCLookupDisplay (dpy);
    char **file_paths = (char **) NULL;
    char filename[PATH_MAX];
#if 0
    char* bitmapdir = BITMAPDIR;
#endif
    unsigned int width, height;
    int xhot, yhot;
    int i;

    /*
     * look in cache for bitmap path
     */
    if (cache) {
	if (!cache->string_to_bitmap.bitmapFilePath) {
	    XrmName xrm_name[2];
	    XrmClass xrm_class[2];
	    XrmRepresentation rep_type;
	    XrmValue value;

	    xrm_name[0] = XrmPermStringToQuark ("bitmapFilePath");
	    xrm_name[1] = NULLQUARK;
	    xrm_class[0] = XrmPermStringToQuark ("BitmapFilePath");
	    xrm_class[1] = NULLQUARK;
	    if (!XrmGetDatabase(dpy)) {
		/* what a hack; need to initialize it */
		(void) XGetDefault (dpy, "", "");
	    }
	    if (XrmQGetResource (XrmGetDatabase(dpy), xrm_name, xrm_class, 
				 &rep_type, &value) &&
		rep_type == XrmPermStringToQuark("String")) {
		cache->string_to_bitmap.bitmapFilePath = 
		  split_path_string (value.addr);
	    }
	}
	file_paths = cache->string_to_bitmap.bitmapFilePath;
    }

    /*
     * Search order:
     *    1.  name if it begins with / or ./
     *    2.  "each prefix in file_paths"/name
     *    3.  BITMAPDIR/name
     *    4.  name if didn't begin with / or .
     */

    for (i = 1; i <= 4; i++) {
	char *fn = filename;
	Pixmap pixmap;
	unsigned char *data;

	switch (i) {
	  case 1:
#ifndef __UNIXOS2__
	    if (!(name[0] == '/' || ((name[0] == '.') && name[1] == '/')))
#else
	    if (!(name[0] == '/' || (name[0] == '.' && name[1] == '/') ||
		  (isalpha(name[0]) && name[1] == ':')))
#endif
	      continue;
	    fn = (char *) name;
	    try_plain_name = False;
	    break;
	  case 2:
	    if (file_paths && *file_paths) {
		XmuSnprintf(filename, sizeof(filename),
			    "%s/%s", *file_paths, name);
		file_paths++;
		i--;
		break;
	    }
	    continue;
	  case 3:
	    XmuSnprintf(filename, sizeof(filename), "%s/%s", BITMAPDIR, name);
	    break;
	  case 4:
	    if (!try_plain_name) continue;
	    fn = (char *) name;
	    break;
	}

	data = NULL;
	pixmap = None;
#ifdef __UNIXOS2__
	fn = (char*)__XOS2RedirRoot(fn);
#endif
	if (XmuReadBitmapDataFromFile (fn, &width, &height, &data,
				       &xhot, &yhot) == BitmapSuccess) {
	    pixmap = XCreatePixmapFromBitmapData (dpy, root, (char *) data,
						  width, height,
						  fore, back, depth);
	    XFree ((char *)data);
	}

	if (pixmap) {
	    if (widthp) *widthp = (int)width;
	    if (heightp) *heightp = (int)height;
	    if (xhotp) *xhotp = xhot;
	    if (yhotp) *yhotp = yhot;
	    if (srcname && srcnamelen > 0) {
		strncpy (srcname, fn, srcnamelen - 1);
		srcname[srcnamelen - 1] = '\0';
	    }
	    return pixmap;
	}
    }

    return None;
}
Exemple #23
0
void
VideoModeConfigureStart(void)
{
    vidtune = computer.vidmodes[screenno];

    XtSetSensitive(vtune, vidtune != NULL);
    if (!XtIsManaged(vtune))
	XtManageChild(vtune);
    else
	XtMapWidget(vtune);
    if (vidtune != NULL) {
	Arg args[1];
	Boolean state;
	XF86ConfMonitorPtr mon;
	static char menuName[16];
	static int menuN;

	XtErrorFunc = XSetErrorHandler(VidmodeError);
	XF86VidModeLockModeSwitch(XtDisplay(toplevel), vidtune->screen, True);
	GetModeLine(True);
	GetModes();

	SetLabels();
	XtSetArg(args[0], XtNstate, &state);
	XtGetValues(automatic, args, 1);
	XtSetSensitive(apply, !state);
	autoflag = state;

	if (monitor)
	    XtDestroyWidget(monitor);
	XmuSnprintf(menuName, sizeof(menuName), "menuP%d", menuN);
	menuN = !menuN;
	monitor = XtCreatePopupShell(menuName, simpleMenuWidgetClass,
				     vtune, NULL, 0);
	XtVaSetValues(monitorb, XtNmenuName, menuName, NULL, 0);

	mon = XF86Config->conf_monitor_lst;
	while (mon != NULL) {
	    Widget sme = XtCreateManagedWidget(mon->mon_identifier,
					       smeBSBObjectClass,
					       monitor, NULL, 0);
	    XtAddCallback(sme, XtNcallback,
			  SelectMonitorCallback, (XtPointer)mon);

	    /* guess the monitor at a given screen and/or
	     * updates configuration if a monitor was removed from the
	     * configuration.
	     */
	    if (XF86Config->conf_layout_lst) {
		XF86ConfAdjacencyPtr adj = XF86Config->conf_layout_lst->
		    lay_adjacency_lst;

		while (adj != NULL) {
		    if (adj->adj_screen != NULL) {
			if (adj->adj_screen->scrn_monitor == mon &&
			    adj->adj_scrnum >= 0 &&
			    adj->adj_scrnum < ScreenCount(XtDisplay(toplevel))) {
			    if (computer.vidmodes[adj->adj_scrnum]->monitor ==
				NULL || computer.vidmodes[adj->adj_scrnum]->
				monitor == adj->adj_screen->scrn_monitor) {
				computer.vidmodes[adj->adj_scrnum]->monitor =
				    adj->adj_screen->scrn_monitor;
				break;
			    }
			    else
				computer.vidmodes[adj->adj_scrnum]->monitor =
				    NULL;
			}
		    }
		    adj = (XF86ConfAdjacencyPtr)(adj->list.next);
		}
	    }
	    mon = (XF86ConfMonitorPtr)(mon->list.next);
	}
	SetLabelAndModeline();
    }
}
Exemple #24
0
static void
SetLabel(int ident, int value)
{
    Arg args[1];
    char label[256];

    if (ident == FLAGS) {
	int len = 0;

	*label = '\0';
	if (value & V_PHSYNC)
	    len += XmuSnprintf(label, sizeof(label), "%s", "+hsync");
	if (modeline.flags & V_NHSYNC)
	    len += XmuSnprintf(label + len, sizeof(label), "%s%s",
			       len ? " " : "", "-hsync");
	if (value & V_PVSYNC)
	    len += XmuSnprintf(label + len, sizeof(label), "%s%s",
			       len ? " " : "", "+vsync");
	if (value & V_NVSYNC)
	    len += XmuSnprintf(label + len, sizeof(label), "%s%s",
			       len ? " " : "", "-vsync");
	if (value & V_INTERLACE)
	    len += XmuSnprintf(label + len, sizeof(label), "%s%s",
			       len ? " " : "", "interlace");
	if (value & V_CSYNC)
	    len += XmuSnprintf(label + len, sizeof(label), "%s%s",
			       len ? " " : "", "composite");
	if (value & V_PCSYNC)
	    len += XmuSnprintf(label + len, sizeof(label), "%s%s",
			       len ? " " : "", "+csync");
	if (value & V_NCSYNC)
	    len += XmuSnprintf(label + len, sizeof(label), "%s%s",
			       len ? " " : "", "-csync");
	if (value & V_DBLSCAN)
	    len += XmuSnprintf(label + len, sizeof(label), "%s%s",
			       len ? " " : "", "doublescan");

    }
    else if (ident == CLOCK || ident == HSYNC || ident == VSYNC)
	XmuSnprintf(label, sizeof(label), "%6.2f", (float)value / 1000.0);
    else
	XmuSnprintf(label, sizeof(label), "%d", value);

    XtSetArg(args[0], XtNlabel, label);
    XtSetValues(values[ident], args, 1);
}
Exemple #25
0
/*ARGSUSED*/
static void
PositionChanged(Widget w, XtPointer client_data, XtPointer call_data)
{
    int idx;
    XawTextPositionInfo *info = (XawTextPositionInfo*)call_data;

    for (idx = 0; idx < 3; idx++)
	if (w == texts[idx])
	    break;
    if (idx > 2)
	return;

    if (((position_format_mask & l_BIT)
	  && infos[idx].line_number != info->line_number)
	|| ((position_format_mask & c_BIT)
	    && infos[idx].column_number != info->column_number)
	|| ((position_format_mask & p_BIT)
	    && infos[idx].insert_position != info->insert_position)
	|| ((position_format_mask & s_BIT)
	    && infos[idx].last_position != info->last_position)
	|| infos[idx].overwrite_mode != info->overwrite_mode) {
	int len = 6;
	Arg args[1];
	char buffer[256], *str = app_resources.position_format;
	char fmt_buf[MAX_FMT_LEN + 2], *fmt;

	memcpy(&infos[idx], info, sizeof(XawTextPositionInfo));
	if (info->overwrite_mode)
	    strcpy(buffer, "Ovrwt ");
	else
	    strcpy(buffer, "      ");
	while (*str) {
	    switch (*str) {
		case '%':
		    fmt = fmt_buf;
		    *fmt++ = *str++;
		    if (*str == '-')
			*fmt++ = *str++;
		    /*CONSTCOND*/
		    while (*str >= '0' && *str <= '9') {
			/* StartPositionFormat() already checked the format
			 * length.
			 */
			*fmt++ = *str++;
		    }
		    *fmt++ = 'd';
		    *fmt = '\0';
		    switch (*str) {
			case 'l':
			    XmuSnprintf(&buffer[len], sizeof(buffer) - len,
					fmt_buf, info->line_number);
			    break;
			case 'c':
			    XmuSnprintf(&buffer[len], sizeof(buffer) - len,
					fmt_buf, info->column_number);
			    break;
			case 'p':
			    XmuSnprintf(&buffer[len], sizeof(buffer) - len,
					fmt_buf, info->insert_position);
			    break;
			case 's':
			    XmuSnprintf(&buffer[len], sizeof(buffer) - len,
					fmt_buf, info->last_position);
			    break;
			case '%':
			    strcpy(&buffer[len], "%");
			    break;
		    }
		    len += strlen(&buffer[len]);
		    break;
		default:
		    buffer[len++] = *str;
		    break;
	    }
	    if (len >= sizeof(buffer) - 1)
		break;
	    ++str;
	}
	buffer[len] = '\0';

	XtSetArg(args[0], XtNlabel, buffer);
	XtSetValues(positions[idx], args, 1);
    }
}
Exemple #26
0
/*
 * XmuPrintDefaultErrorMessage - print a nice error that looks like the usual
 * message.  Returns 1 if the caller should consider exitting else 0.
 */
int
XmuPrintDefaultErrorMessage(Display *dpy, XErrorEvent *event, FILE *fp)
{
    char buffer[BUFSIZ];
    char mesg[BUFSIZ];
    char number[32];
    _Xconst char *mtype = "XlibMessage";
    register _XExtension *ext = (_XExtension *)NULL;
    _XExtension *bext = (_XExtension *)NULL;
    XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
    XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
    (void) fprintf(fp, "%s:  %s\n  ", mesg, buffer);
    XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
	mesg, BUFSIZ);
    (void) fprintf(fp, mesg, event->request_code);
    if (event->request_code < 128) {
	XmuSnprintf(number, sizeof(number), "%d", event->request_code);
	XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
    } else {
	/* XXX this is non-portable */
	for (ext = dpy->ext_procs;
	     ext && (ext->codes.major_opcode != event->request_code);
	     ext = ext->next)
	  ;
	if (ext)
	  XmuSnprintf(buffer, sizeof(buffer), "%s", ext->name);
	else
	    buffer[0] = '\0';
    }
    (void) fprintf(fp, " (%s)", buffer);
    fputs("\n  ", fp);
    if (event->request_code >= 128) {
	XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
			      mesg, BUFSIZ);
	(void) fprintf(fp, mesg, event->minor_code);
	if (ext) {
	    XmuSnprintf(mesg, sizeof(mesg),
			"%s.%d", ext->name, event->minor_code);
	    XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
	    (void) fprintf(fp, " (%s)", buffer);
	}
	fputs("\n  ", fp);
    }
    if (event->error_code >= 128) {
	/* kludge, try to find the extension that caused it */
	buffer[0] = '\0';
	for (ext = dpy->ext_procs; ext; ext = ext->next) {
	    if (ext->error_string)
		(*ext->error_string)(dpy, event->error_code, &ext->codes,
				     buffer, BUFSIZ);
	    if (buffer[0]) {
		bext = ext;
		break;
	    }
	    if (ext->codes.first_error &&
		ext->codes.first_error < event->error_code &&
		(!bext || ext->codes.first_error > bext->codes.first_error))
		bext = ext;
	}
	if (bext)
	    XmuSnprintf(buffer, sizeof(buffer), "%s.%d", bext->name,
			event->error_code - bext->codes.first_error);
	else
	    strcpy(buffer, "Value");
	XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ);
	if (mesg[0]) {
	    fputs("  ", fp);
	    (void) fprintf(fp, mesg, event->resourceid);
	    fputs("\n", fp);
	}
	/* let extensions try to print the values */
	for (ext = dpy->ext_procs; ext; ext = ext->next) {
	    if (ext->error_values)
		(*ext->error_values)(dpy, event, fp);
	}
    } else if ((event->error_code == BadWindow) ||
	       (event->error_code == BadPixmap) ||
	       (event->error_code == BadCursor) ||
	       (event->error_code == BadFont) ||
	       (event->error_code == BadDrawable) ||
	       (event->error_code == BadColor) ||
	       (event->error_code == BadGC) ||
	       (event->error_code == BadIDChoice) ||
	       (event->error_code == BadValue) ||
	       (event->error_code == BadAtom)) {
	if (event->error_code == BadValue)
	    XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
				  mesg, BUFSIZ);
	else if (event->error_code == BadAtom)
	    XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
				  mesg, BUFSIZ);
	else
	    XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
				  mesg, BUFSIZ);
	(void) fprintf(fp, mesg, event->resourceid);
	fputs("\n  ", fp);
    }
    XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
	mesg, BUFSIZ);
    (void) fprintf(fp, mesg, event->serial);
    fputs("\n  ", fp);
    XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
	mesg, BUFSIZ);
    (void) fprintf(fp, mesg, NextRequest(dpy)-1);
    fputs("\n", fp);
    if (event->error_code == BadImplementation) return 0;
    return 1;
}
Exemple #27
0
void
ReadCardsDatabase(void)
{
#ifdef USE_MODULES
    if (!nomodules) {
	int i, j, ivendor, idevice;
	char name[256];
	_Xconst char *vendor, *device;
	CardsEntry *entry = NULL, *tmp;
	xf86cfgModuleOptions *opts = module_options;
	const pciDeviceInfo **pDev;

	/* Only list cards that have a driver installed */
	while (opts) {
	    if (opts->chipsets) {
		SymTabPtr chips = opts->chipsets;

		while (chips->name) {
		    vendor = opts->name;
		    device = chips->name;
		    ivendor = (chips->token & 0xffff0000) >> 16;
		    idevice = chips->token & 0xffff0;
		    if (ivendor == 0)
			ivendor = opts->vendor;

		    if (xf86PCIVendorInfo) {
			for (i = 0; xf86PCIVendorInfo[i].VendorName; i++)
			    if (ivendor == xf86PCIVendorInfo[i].VendorID) {
				vendor = xf86PCIVendorInfo[i].VendorName;
				break;
			    }
			if (xf86PCIVendorInfo[i].VendorName) {
			    if ((pDev = xf86PCIVendorInfo[i].Device)) {
				for (j = 0; pDev[j]; j++)
				    if (idevice == pDev[j]->DeviceID) {
					device = pDev[j]->DeviceName;
					break;
				    }
			    }
			}
		    }

		    /* Since frequently there is more than one driver for a
		     * single vendor, it is required to avoid duplicates.
		     */
		    XmuSnprintf(name, sizeof(name), "%s %s", vendor, device);
		    tmp = LookupCard(name);

		    if (tmp == NULL || strcmp(tmp->chipset, chips->name) ||
			strcmp(tmp->driver, opts->name)) {
			entry = (CardsEntry*)XtCalloc(1, sizeof(CardsEntry));
			if (NumCardsEntry % 16 == 0) {
			    CardsDB = (CardsEntry**)XtRealloc((XtPointer)CardsDB,
				    sizeof(CardsEntry*) * (NumCardsEntry + 16));
			}
			CardsDB[NumCardsEntry++] = entry;
			entry->name = XtNewString(name);

			/* XXX no private copy of strings */
			entry->chipset = (char*)chips->name;
			entry->driver = opts->name;

			/* better than linear searchs to find duplicates */
			qsort(CardsDB, NumCardsEntry, sizeof(CardsEntry*),
			      CompareCards);
		    }
		    ++chips;
		}
	    }
	    opts = opts->next;
	}
Exemple #28
0
/*
 * Implementation
 */
XtPointer
MonitorConfig(XtPointer conf)
{
    XF86ConfMonitorPtr monitor = (XF86ConfMonitorPtr)conf;
    char monitor_name[48];
    Arg args[1];

    current_monitor = monitor;

    xf86info.cur_list = MONITOR;
    XtSetSensitive(back, xf86info.lists[MONITOR].cur_function > 0);
    XtSetSensitive(next, xf86info.lists[MONITOR].cur_function <
			 xf86info.lists[MONITOR].num_functions - 1);
    (xf86info.lists[MONITOR].functions[xf86info.lists[MONITOR].cur_function])
	(&xf86info);

    XawListUnhighlight(hlist);
    XawListUnhighlight(vlist);

    if (monitor != NULL) {
	XF86ConfScreenPtr screen = XF86Config->conf_screen_lst;
	char str[PARSER_RANGE_SIZE];

	XtSetArg(args[0], XtNstring, monitor->mon_identifier);
	XtSetValues(ident_widget, args, 1);

	while (screen != NULL) {
	    if (screen->scrn_monitor == monitor)
		break;

	    screen = (XF86ConfScreenPtr)(screen->list.next);
	}
	if (screen != NULL) {
	    oldcard = card = screen->scrn_device;
	    XtSetArg(args[0], XtNlabel, card->dev_identifier);
	}
	else {
	    oldcard = card = NULL;
	    XtSetArg(args[0], XtNlabel, "");
	}
	XtSetValues(cmenu, args, 1);

	mon_n_hsync = monitor->mon_n_hsync;
	memcpy(mon_hsync, monitor->mon_hsync,
	       sizeof(parser_range) * mon_n_hsync);
	*str = '\0';
	parser_range_to_string(str, mon_hsync, mon_n_hsync);
	XtSetArg(args[0], XtNstring, str);
	XtSetValues(hsync, args, 1);

	mon_n_vrefresh = monitor->mon_n_vrefresh;
	memcpy(mon_vrefresh, monitor->mon_vrefresh,
	       sizeof(parser_range) * mon_n_vrefresh);
	*str = '\0';
	parser_range_to_string(str, mon_vrefresh, mon_n_vrefresh);
	XtSetArg(args[0], XtNstring, str);
	XtSetValues(vsync, args, 1);
    }
    else {
	XF86ConfMonitorPtr monitor = XF86Config->conf_monitor_lst;
	int nmonitors = 0;

	oldcard = card = NULL;
	while (monitor != NULL) {
		++nmonitors;
	    monitor = (XF86ConfMonitorPtr)(monitor->list.next);
	}
	do {
	    XmuSnprintf(monitor_name, sizeof(monitor_name),
			"Monitor%d", nmonitors);
	    ++nmonitors;
	} while (xf86findMonitor(monitor_name,
		 XF86Config->conf_monitor_lst));

	XtSetArg(args[0], XtNstring, monitor_name);
	XtSetValues(ident_widget, args, 1);

	XtSetArg(args[0], XtNstring, "");
	XtSetValues(hsync, args, 1);
	XtSetValues(vsync, args, 1);

	XtSetArg(args[0], XtNlabel, "");
	XtSetValues(cmenu, args, 1);
    }

    if (ConfigLoop(MonitorConfigCheck) == True) {
	if (monitor == NULL) {
	    monitor = (XF86ConfMonitorPtr)
		XtCalloc(1, sizeof(XF86ConfMonitorRec));
	    monitor->mon_identifier = XtNewString(ident_string);
	}

	memcpy(monitor->mon_hsync, mon_hsync, sizeof(parser_range) *
	       (monitor->mon_n_hsync = mon_n_hsync));
	memcpy(monitor->mon_vrefresh, mon_vrefresh, sizeof(parser_range) *
	       (monitor->mon_n_vrefresh = mon_n_vrefresh));

	if (strcasecmp(monitor->mon_identifier, ident_string))
	    xf86renameMonitor(XF86Config, monitor, ident_string);

	if (oldcard != card) {
	    int i;

	    for (i = 0; i < computer.num_devices; i++)
		if (computer.devices[i]->widget == config)
		    break;
	    if (computer.devices[i]->config == NULL)
		XF86Config->conf_monitor_lst =
				xf86addMonitor(XF86Config->conf_monitor_lst,
					       monitor);
	    computer.devices[i]->config = (XtPointer)monitor;
	    ChangeScreen(monitor, monitor, card, oldcard);
	    DrawCables();
	}

	return (monitor);
    }

    return (NULL);
}
Exemple #29
0
/*ARGUSED*/
static Bool
EnumDatabase(XrmDatabase *db, XrmBindingList bindings, XrmQuarkList quarks,
	     XrmRepresentation *type, XrmValue *value, XPointer closure)
{
    char *module = XrmQuarkToString(quarks[0]),
	 *option = XrmQuarkToString(quarks[1]);

    /* handle *.Option: value */
    if (module && option == NULL) {
	option = module;
	module = "*";
    }

    /*
     * NOTE: If the Options file is changed to support any other format than
     *
     *		Module.Option: description text
     *
     * this code will also need to be updated.
     */

    if (module) {
	XrmValue xrm;
	char *type, *value, query[256];

	XmuSnprintf(query, sizeof(query), "%s.%s", module, option);
	if (XrmGetResource(options_xrm, query, "Module.Option", &type, &xrm))
	    value = (char*)xrm.addr;
	else
	    value = NULL;

	if (value) {
	    char *norm;
	    unsigned char *ptr;
	    int position;
	    int length = strlen(module) + strlen(option) + strlen(value) + 4;

	    rebuild_xrm.string = XtRealloc(rebuild_xrm.string,
					   rebuild_xrm.offset + length);
	    position = rebuild_xrm.offset +
		       sprintf(rebuild_xrm.string + rebuild_xrm.offset, "%s.%s:",
			       module, option);

	    /* removes underlines and spaces */
	    norm = strchr(rebuild_xrm.string + rebuild_xrm.offset, '.') + 1;
	    for (; *norm; norm++) {
		if (*norm == '_' || *norm == ' ' || *norm == '\t') {
		    memmove(norm, norm + 1, strlen(norm) + 1);
		    --position;
		    --length;
		}
	    }

	    for (ptr = (unsigned char*)rebuild_xrm.string + rebuild_xrm.offset;
		 *ptr; ptr++)
		*ptr = tolower(*ptr);
	    sprintf(rebuild_xrm.string + position, "%s\n", value);
	    rebuild_xrm.offset += length - 1;
	}
    }

    return (False);
}
Exemple #30
0
void
OptionsPopup(XF86OptionPtr *opts)
#endif
{
    static int first = 1;
#ifdef USE_MODULES
    static Widget button, menu;
    static char label[256], menuName[16];
    Widget sme;
    char buf[256];
    int i = 0;
    Arg args[1];
    static int menuN;
#endif

    option_str = NULL;
    options = opts;
    if (first) {
	Widget pane, form, viewport, bottom, popdown;

	first = 0;

	if (optionsShell == NULL)
	    CreateOptionsShell();
	pane = XtCreateManagedWidget("pane", panedWidgetClass,
				     optionsShell, NULL, 0);

	form = XtCreateManagedWidget("commands", formWidgetClass,
				     pane, NULL, 0);
	add = XtCreateManagedWidget("add", commandWidgetClass,
				    form, NULL, 0);
	XtAddCallback(add, XtNcallback, AddOption, NULL);
	remov = XtCreateManagedWidget("remove", commandWidgetClass,
				      form, NULL, 0);
	XtAddCallback(remov, XtNcallback, RemoveOption, NULL);
	update = XtCreateManagedWidget("update", commandWidgetClass,
				       form, NULL, 0);
	XtAddCallback(update, XtNcallback, UpdateOption, NULL);
#ifdef USE_MODULES
	if (!nomodules) {
	    Widget command;

	    command = XtCreateManagedWidget("help", commandWidgetClass,
					    form, NULL, 0);
	    XtAddCallback(command, XtNcallback, ModuleOptionsPopup, NULL);
	}
#endif
	form = XtCreateManagedWidget("form", formWidgetClass,
				     pane, NULL, 0);
	XtVaCreateManagedWidget("label1", labelWidgetClass, form,
				XtNlabel, " Option \"",
				NULL);
	name = XtVaCreateManagedWidget("name", asciiTextWidgetClass, form,
				       XtNeditType, XawtextEdit,
				       NULL);
	XtVaCreateManagedWidget("label2", labelWidgetClass,
				form,
				XtNlabel, "\" \"",
				NULL);
	value = XtVaCreateManagedWidget("value", asciiTextWidgetClass, form,
					XtNeditType, XawtextEdit,
					NULL);
	XtVaCreateManagedWidget("label3", labelWidgetClass, form,
				XtNlabel, "\" ",
				NULL);
	viewport = XtCreateManagedWidget("viewport", viewportWidgetClass,
					 form, NULL, 0);
	list = XtCreateManagedWidget("list", listWidgetClass,
				     viewport, NULL, 0);
	XtAddCallback(list, XtNcallback, SelectOptionCallback, NULL);
	bottom = XtCreateManagedWidget("bottom", formWidgetClass,
				       pane, NULL, 0);
#ifdef USE_MODULES
	if (!nomodules)
	    button = XtCreateManagedWidget("driverOpts", menuButtonWidgetClass,
					    bottom, NULL, 0);
#endif
	popdown = XtVaCreateManagedWidget("popdown", commandWidgetClass,
					bottom, NULL);
#ifdef USE_MODULES
	if (!nomodules)
	    XtVaSetValues(popdown, XtNfromHoriz, button, NULL);
#endif

	XtAddCallback(popdown, XtNcallback, PopdownCallback, NULL);
	XtRealizeWidget(optionsShell);
	XSetWMProtocols(DPY, XtWindow(optionsShell), &wm_delete_window, 1);

#ifdef USE_MODULES
	if (!nomodules) {
	    char *str;

	    XtSetArg(args[0], XtNlabel, &str);
	    XtGetValues(button, args, 1);
	    XmuSnprintf(label, sizeof(label), "%s", str);
	}
#endif
    }

#ifdef USE_MODULES
    if (!nomodules) {
	if (menu)
	    XtDestroyWidget(menu);
	XmuSnprintf(menuName, sizeof(menuName), "optionM%d", menuN);
	menuN = !menuN;
	menu = XtCreatePopupShell(menuName, simpleMenuWidgetClass, button,
				  NULL, 0);
	XtVaSetValues(button, XtNmenuName, menuName, NULL);
	if (drv_opts) {
	    int len, longest = 0;
	    char fmt[32];

	    for (i = 0; drv_opts[i].name != NULL; i++) {
		len = strlen(drv_opts[i].name);
		if (len > longest)
		    longest = len;
	    }
	    XmuSnprintf(fmt, sizeof(fmt), "%c-%ds  %%s", '%', longest);
	    for (; drv_opts->name != NULL; drv_opts++) {
		char *type;

		if (drv_opts->type >= OPTV_NONE && drv_opts->type <= OPTV_FREQ)
		    type = types[drv_opts->type];
		else
		    type = "UNKNOWN";

		XmuSnprintf(buf, sizeof(buf), fmt, drv_opts->name, type);
		sme = XtVaCreateManagedWidget(drv_opts->name, smeBSBObjectClass,
					      menu, XtNlabel, buf, NULL);
		XtAddCallback(sme, XtNcallback, AddDriverOption, (XtPointer)drv_opts);
	    }
	}
	if (i) {
	    xf86cfgModuleOptions *mod = module_options;

	    while (mod) {
		if (strcmp(mod->name, driver) == 0) {
		    /* don't assign to driver, as it may be a temp string */
		    module_sel = mod->name;
		    break;
		}
		mod = mod->next;
	    }
	    XmuSnprintf(buf, sizeof(buf), "%s%s", label, driver);
	    XtSetArg(args[0], XtNlabel, buf);
	    XtSetValues(button, args, 1);
	    XtMapWidget(button);
	}
	else
	    XtUnmapWidget(button);
    }
#endif

    UpdateOptionList();
    popped = True;
    XtPopup(optionsShell, XtGrabExclusive);

    while (popped)
	XtAppProcessEvent(XtWidgetToApplicationContext(optionsShell), XtIMAll);
}