Esempio n. 1
0
long xGetResLong(Display *display,
		 const char *name,
		 const char *res_string,
		 long hard_def)

{

  long paramvalue;
  char *paramstr, *end_pt;

  if (display == NULL) {
    paramvalue = uGetParamLong(name, res_string, hard_def);
  } else if ((paramstr = XGetDefault(display, name,
				     res_string)) == NULL) {
    paramvalue = uGetParamLong(name, res_string, hard_def);
  } else {
    errno = 0;
    paramvalue = strtol(paramstr, &end_pt, 10);
    if(errno != 0)
      paramvalue = uGetParamLong(name, res_string, hard_def);
  }

  return paramvalue;

}
Esempio n. 2
0
/**
 *  This function gets the dpi in the same way that mozilla gets the dpi, 
 *  this allows us to convert from pixels to points easily
 */
static gint
mozilla_get_dpi (void)
{
	GtkSettings* settings = gtk_settings_get_default ();
	gint dpi = 0;
	char *val;
	float screenWidthIn;

	/* Use the gtk-xft-dpi setting if it is set */
	if (g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (settings)),
					  "gtk-xft-dpi"))
	{
		g_object_get (G_OBJECT (settings), "gtk-xft-dpi", &dpi, NULL);
		if (dpi) return INT_ROUND (dpi / PANGO_SCALE);
	}

	/* Fall back to what xft thinks it is */
	val = XGetDefault (GDK_DISPLAY (), "Xft", "dpi");
	if (val)
	{
		char *e;
		double d = strtod(val, &e);
		if (e != val) return INT_ROUND (d);
	}
	
	/* Fall back to calculating manually from the gdk screen settings */
	screenWidthIn = ((float)gdk_screen_width_mm()) / 25.4f;
	return INT_ROUND (gdk_screen_width() / screenWidthIn);
}
Esempio n. 3
0
double xGetResDouble(Display *display,
		     const char *name,
		     const char *res_string,
		     double hard_def)

{

  double paramvalue;
  char *paramstr, *end_pt;

  
  if (display == NULL) {
    paramvalue = uGetParamDouble(name, res_string, hard_def);
  } else if ((paramstr = XGetDefault(display, name,
				     res_string)) == NULL) {
    paramvalue = uGetParamDouble(name, res_string, hard_def);
  } else {
    errno = 0;
    paramvalue = strtod(paramstr, &end_pt);
    if(errno != 0)
      paramvalue = uGetParamDouble(name, res_string, hard_def);
  }

  return paramvalue;

}
Esempio n. 4
0
int XCursorTheme::autodetectCursorSize() const
{
    /* This code is basically borrowed from display.c of the XCursor library
       We can't use "int XcursorGetDefaultSize(Display *dpy)" because if
       previously the cursor size was set to a custom value, it would return
       this custom value. */
    int size = 0;
    int dpi = 0;
    Display *dpy = QX11Info::display();
    // The string "v" is owned and will be destroyed by Xlib
    char *v = XGetDefault(dpy, "Xft", "dpi");
    if (v)
        dpi = atoi(v);
    if (dpi)
        size = dpi * 16 / 72;
    if (size == 0)
    {
        int dim;
        if (DisplayHeight(dpy, DefaultScreen(dpy)) <
            DisplayWidth(dpy, DefaultScreen(dpy)))
        {
            dim = DisplayHeight(dpy, DefaultScreen(dpy));
        } else {
            dim = DisplayWidth(dpy, DefaultScreen(dpy));
        };
        size = dim / 48;
    }
    return size;
}
Esempio n. 5
0
// choose a window
static int get_button1(void)
{
    char* button_name = XGetDefault(dpy, nameProg, "Button");
    int button = -1;                    // button number or negative for all

    if (!button_name)
        button = SelectButtonFirst;
    else if (!parse_button(button_name, &button))
        error_exit("invalid button specification \"%s\"", button_name);

    if (button >= 0 || button == SelectButtonFirst)
    {
        unsigned char pointer_map[256];         // 8 bits of pointer num
        int count, j;
        unsigned int ub = (unsigned int) button;

        count = XGetPointerMapping(dpy, pointer_map, 256);
        if (count <= 0)
            error_exit("no pointer mapping");

        if (button >= 0)                        // check button
        {
            for (j = 0; j < count; j++)
                if (ub == (unsigned int) pointer_map[j]) break;
            if (j == count)
                error_exit("button %u not mapped", ub);
        }
        else                                    // get first entry
            button = (int)((unsigned int)pointer_map[0]);
    }

    return button;
}
Esempio n. 6
0
static Bool
_XftDefaultInitBool (Display *dpy, XftPattern *pat, char *option)
{
    char    *v;
    int	    i;

    v = XGetDefault (dpy, "Xft", option);
    if (v && (i = XftDefaultParseBool (v)) >= 0)
	return XftPatternAddBool (pat, option, i != 0);
    return True;
}
Esempio n. 7
0
void
init_keyin(void)
{
    char *prop;
    unsigned int nlm;


    nlm = get_modifier_mask(XK_Num_Lock);
    UnsupportedModMask &= ~nlm;
    ModifiersMask &= ~nlm;

    /*
     * First set all the values for when the active cursor is in the window
     */

    in_cursor_height = 2;
    in_cursor_y = gInputFont->max_bounds.ascent +
        gInputFont->max_bounds.descent;
    in_cursor_width = gInputFont->max_bounds.width;

    /*
     * Now for when the cursor is empty
     */

    out_cursor_height = gInputFont->max_bounds.ascent +
        gInputFont->max_bounds.descent;
    out_cursor_y = 2;
    out_cursor_width = in_cursor_width;

    start_x = 5;

    start_y = gInputFont->max_bounds.ascent;

    /*
     * Find out How big I should make the simple boxes
     */

    simple_box_width = XTextWidth(gInputFont, "X", 1) + 5;

    prop = XGetDefault(gXDisplay, gArgv[0], "ProtectedQuit");

    if (prop == NULL) {
        protected_quit = (char *) halloc(strlen("ProtectedPage") + 1,
                                         "protected_quit");
        strcpy(protected_quit, "ProtectedPage");
    }
    else {
        protected_quit = (char *) halloc(strlen(prop) + 1, "protected_quit");
        strcpy(protected_quit, prop);
    }


}
Esempio n. 8
0
/***************************************************************************
 *
 * Get resources using the X library function "XGetDefault"
 *
 **************************************************************************/
void GetThoseResourceStrings(void)
{
  char *tmp;
  int i=0;
  
  while(string_resource_list[i].keyword != NULL)
    {
      if((tmp = XGetDefault(display,xvt_name,
			    string_resource_list[i].keyword)) != (char *)0)
	*string_resource_list[i].dataptr = tmp;
      i++;
    }
}
Esempio n. 9
0
static Bool
_XftDefaultInitDouble (Display *dpy, XftPattern *pat, char *option)
{
    char    *v, *e;
    double  d;

    v = XGetDefault (dpy, "Xft", option);
    if (v)
    {
	d = strtod (v, &e);
	if (e != v)
	    return XftPatternAddDouble (pat, option, d);
    }
    return True;
}
Esempio n. 10
0
long int GetMultiClickTime() {
	long int value = 200;
	int clicktime;
	bool successful = false;

	// Try and acquire the multi-click time from the user defined X defaults.
	char *xprop = XGetDefault(disp, "*", "multiClickTime");
	if (xprop != NULL && sscanf(xprop, "%4i", &clicktime) != EOF) {
		successful = true;
	}

	xprop = XGetDefault(disp, "OpenWindows", "MultiClickTimeout");
	if (xprop != NULL && sscanf(xprop, "%4i", &clicktime) != EOF) {
		successful = true;
	}

	#ifdef XT
	int argc = 0;
	char ** argv = {NULL};

	// Fall back to the X Toolkit extension if available and other efforts failed.
    XtDisplayInitialize(app_context, disp, "JNativeHook", "JNativeHook", NULL, 0, &argc, argv);
	if (!successful) {
		clicktime = XtGetMultiClickTime(disp);
		if (clicktime >= 0) {
			successful = true;
		}
	}
	#endif

	if (successful) {
		value = clicktime;
	}

	return value;
}
Esempio n. 11
0
  Q_DECL_EXPORT void kcminit_mouse()
  {
      KConfig *config = new KConfig("kcminputrc", KConfig::NoGlobals );
    MouseSettings settings;
    settings.load(config);
    settings.apply(true); // force

#ifdef HAVE_XCURSOR
    KConfigGroup group = config->group("Mouse");
    QString theme = group.readEntry("cursorTheme", QString());
    QString size = group.readEntry("cursorSize", QString());

    // Note: If you update this code, update kapplymousetheme as well.

    // use a default value for theme only if it's not configured at all, not even in X resources
    if( theme.isEmpty()
        && QByteArray( XGetDefault( QX11Info::display(), "Xcursor", "theme" )).isEmpty()
        && QByteArray( XcursorGetTheme( QX11Info::display())).isEmpty())
    {
        theme = "default";
    }

     // Apply the KDE cursor theme to ourselves
    if( !theme.isEmpty())
        XcursorSetTheme(QX11Info::display(), QFile::encodeName(theme));

    if (!size.isEmpty())
    	XcursorSetDefaultSize(QX11Info::display(), size.toUInt());

    // Load the default cursor from the theme and apply it to the root window.
    Cursor handle = XcursorLibraryLoadCursor(QX11Info::display(), "left_ptr");
    XDefineCursor(QX11Info::display(), QX11Info::appRootWindow(), handle);
    XFreeCursor(QX11Info::display(), handle); // Don't leak the cursor

    // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment
    // variables when launching applications.
    OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"),
                                       QStringLiteral("/KLauncher"),
                                       QDBusConnection::sessionBus());
    if(!theme.isEmpty())
        klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), theme);
    if( !size.isEmpty())
        klauncher.setLaunchEnv(QStringLiteral("XCURSOR_SIZE"), size);

#endif

    delete config;
  }
Esempio n. 12
0
static Bool
_XftDefaultInitInteger (Display *dpy, XftPattern *pat, char *option)
{
    char    *v, *e;
    int	    i;

    v = XGetDefault (dpy, "Xft", option);
    if (v)
    {
	if (XftNameConstant (v, &i))
	    return XftPatternAddInteger (pat, option, i);
	i = strtol (v, &e, 0);
	if (e != v)
	    return XftPatternAddInteger (pat, option, i);
    }
    return True;
}
Esempio n. 13
0
char* iupdrvGetSystemFont(void)
{
  static char systemfont[200] = "";
  ImotFont* motfont = NULL;
  char* font = XGetDefault(iupmot_display, "Iup", "fontList");
  if (font)
    motfont = motFindFont(NULL, font);

  if (!motfont)
  {
    font = "Fixed, 11";
    motfont = motFindFont("misc", font);
  }

  strcpy(systemfont, font);
  return systemfont;
}
Esempio n. 14
0
int main( int argc, char* argv[] )
    {
    if( argc != 3 )
        return 1;
    dpy = XOpenDisplay( NULL );
    if( dpy == NULL )
        return 2;
    int ret = 0;
#ifdef HAVE_XCURSOR
    const char* theme = argv[ 1 ];
    const char* size = argv[ 2 ];

    // Note: If you update this code, update kapplymousetheme as well.

    // use a default value for theme only if it's not configured at all, not even in X resources
    if( isEmpty( theme )
        && isEmpty( XGetDefault( trinity_qt_xdisplay(), "Xcursor", "theme" ))
        && isEmpty( XcursorGetTheme( trinity_qt_xdisplay())))
    {
        theme = "default";
        ret = 10; // means to switch to default
    }

     // Apply the KDE cursor theme to ourselves
    if( !isEmpty( theme ))
        XcursorSetTheme(trinity_qt_xdisplay(), theme );

    if (!isEmpty( size ))
    	XcursorSetDefaultSize(trinity_qt_xdisplay(), atoi( size ));

    // Load the default cursor from the theme and apply it to the root window.
    Cursor handle = XcursorLibraryLoadCursor(trinity_qt_xdisplay(), "left_ptr");
    XDefineCursor(trinity_qt_xdisplay(), trinity_qt_xrootwin(), handle);
    XFreeCursor(trinity_qt_xdisplay(), handle); // Don't leak the cursor

#else
    ( void ) trinity_qt_xdisplay();
    ( void ) trinity_qt_xrootwin();
    ( void ) argv;
#endif
    XCloseDisplay( dpy );
    return ret;
    }
Esempio n. 15
0
char *xGetResString(Display *display,
		    const char *name,
		    const char *res_string,
		    const char *hard_def)

{

  char *paramstr;

  if (display == NULL) {
    paramstr = uGetParamString(name, res_string, hard_def);
  } else if ((paramstr = XGetDefault(display, name,
				     res_string)) == NULL) {
    paramstr = uGetParamString(name, res_string, hard_def);
  }

  return paramstr;

}
Esempio n. 16
0
static cairo_bool_t
get_boolean_default (Display       *dpy,
		     const char    *option,
		     cairo_bool_t  *value)
{
    char *v;
    int i;

    v = XGetDefault (dpy, "Xft", option);
    if (v) {
	i = parse_boolean (v);
	if (i >= 0) {
	    *value = i;
	    return TRUE;
	}
    }

    return FALSE;
}
Esempio n. 17
0
static void
GetResourcePixmapPath(Display *display)
{
    XrmName xrm_name[2];
    XrmClass xrm_class[2];
    XrmRepresentation rep_type;
    XrmValue value;
    static char *default_path =
	"%H/%T/%N:%P/include/X11/%T/%N:/usr/X11R6/include/X11/%T/%N:/usr/include/X11/%T/%N:%N";

    xrm_name[0] = XrmPermStringToQuark("pixmapFilePath");
    xrm_name[1] = NULLQUARK;
    xrm_class[0] = XrmPermStringToQuark("PixmapFilePath");
    xrm_class[1] = NULLQUARK;
    if (!XrmGetDatabase(display))
	(void) XGetDefault(display, "", "");
    if (XrmQGetResource(XrmGetDatabase(display), xrm_name, xrm_class,
			&rep_type, &value) &&
			rep_type == XrmPermStringToQuark("String")) {
	int length = 0;
	char *tok, *buffer = XtNewString(value.addr);

	for (tok = strtok(buffer, ":"); tok; tok = strtok(NULL, ":")) {
	    int toklen = strlen(tok);

	    if (toklen) {
		pixmap_path = XtRealloc(pixmap_path, length + toklen + 5);
		strcpy(pixmap_path + length, tok);
		if (length)
		    pixmap_path[length++] = ':';
		sprintf(pixmap_path + length, "%s/%%N", tok);
		length += strlen(tok) + 3;
	    }
	}
	pixmap_path = XtRealloc(pixmap_path, length + strlen(default_path) + 2);
	if (length)
	    pixmap_path[length++] = ':';
	strcpy(pixmap_path + length, default_path);
    }
    else
	pixmap_path = default_path;
}
Esempio n. 18
0
static gboolean
get_integer_default (Display *dpy,
		     gchar   *option,
		     gint    *value)
{
  gchar *v, *e;
  
  v = XGetDefault (dpy, "Xft", option);
  if (v)
    {
      if (FcNameConstant ((FcChar8 *) v, value))
	return TRUE;
      
      *value = strtol (v, &e, 0);
      if (e != v)
	return TRUE;
    }
  
  return FALSE;
}
Esempio n. 19
0
static cairo_bool_t
get_integer_default (Display    *dpy,
		     const char *option,
		     int        *value)
{
    char *v, *e;

    v = XGetDefault (dpy, "Xft", option);
    if (v) {
#if CAIRO_HAS_FT_FONT
	if (FcNameConstant ((FcChar8 *) v, value))
	    return TRUE;
#endif

	*value = strtol (v, &e, 0);
	if (e != v)
	    return TRUE;
    }

    return FALSE;
}
Esempio n. 20
0
static gboolean
get_boolean_default (Display *dpy,
		     gchar   *option,
		     gboolean *value)
{
  gchar *v;
  gint i;
  
  v = XGetDefault (dpy, "Xft", option);
  if (v)
    {
      i = parse_boolean (v);
      if (i >= 0)
	{
	  *value = i;
	  return TRUE;
	}
    }
  
  return FALSE;
}
Esempio n. 21
0
static gboolean
get_double_default (Display *dpy,
		    gchar   *option,
		    gdouble *value)
{
  gchar    *v, *e;
  
  v = XGetDefault (dpy, "Xft", option);
  if (v)
    {
      /* Xft uses strtod, though localization probably wasn't
       * desired. For compatibility, we use the conservative
       * g_strtod() that accepts either localized or non-localized
       * decimal separator.
       */
      *value = g_strtod (v, &e);
      if (e != v)
	return TRUE;
    }
  
  return FALSE;
}
Esempio n. 22
0
static
char const *
lnch_opts_find(
    struct lnch_ctxt const * const p_ctxt,
    int const argc,
    char const * const * const argv,
    struct lnch_opts_descriptor const * const p_desc)
{
    char const * p_value = NULL;

    int argi = 1u;

    while (!p_value && (argi < argc))
    {
        if (0 == strcmp(argv[argi++], p_desc->p_switch))
        {
            if (argi < argc)
            {
                p_value = argv[argi];
                argi ++;
            }
        }
    }

    if (!p_value)
    {
        struct lnch_display const * const p_display = p_ctxt->p_display;

        p_value = XGetDefault(p_display->dpy, LNCH_OPTS_APP_NAME, p_desc->p_resource);

        if (!p_value)
        {
            p_value = p_desc->p_default;
        }
    }

    return p_value;

} /* lnch_opts_find() */
Esempio n. 23
0
bool
grTkLoadFont()
{
    Tk_Window tkwind;
    int i;
    char *s;
    char *unable = "Unable to load font";

    static char *fontnames[4] = {
      TK_FONT_SMALL,
      TK_FONT_MEDIUM,
      TK_FONT_LARGE,
      TK_FONT_XLARGE };
    static char *optionnames[4] = {
      "small",
      "medium",
      "large",
      "xlarge"};

    tkwind = Tk_MainWindow(magicinterp);
    for (i = 0; i < 4; i++)
    {
    	s = XGetDefault(grXdpy, "magic", optionnames[i]);
	if (s) fontnames[i] = s;
        if ((grTkFonts[i] = Tk_GetFont(magicinterp,
			tkwind, fontnames[i])) == NULL) 
        {
	    TxError("%s %s\n", unable, fontnames[i]);
            if ((grTkFonts[i] = Tk_GetFont(magicinterp,
			tkwind, TK_DEFAULT_FONT)) == NULL) 
	    {
	        TxError("%s %s\n", unable, TK_DEFAULT_FONT);
		return FALSE;
	    }
        }
    }
    return TRUE;
}
Esempio n. 24
0
float
gdip_get_display_dpi ()
{
	static float dpis = 0;

	if (dpis == 0) {
#if __APPLE__
		float h_dpi, v_dpi;
		gdip_get_display_dpi_carbon (&h_dpi, &v_dpi);

		dpis = h_dpi;
		return dpis;
#elif HAS_X11 && CAIRO_HAS_XLIB_SURFACE
		char *val;

		Display* display;
		display = XOpenDisplay (0);
		/* If the display is openable lets try to read dpi from it; otherwise use a default of 96.0f */
		if (display) {
			val = XGetDefault (display, "Xft", "dpi");
			if (val) {
				dpis = atof (val);
			} else {
				dpis = 96.0f;
			}
			XCloseDisplay (display);
		} else {
			dpis = 96.0f;
		}
#else
		dpis = 96.0f;
#endif
	}

	return dpis;
}
Esempio n. 25
0
/*
 *  Main program
 */
int
main(int argc, char* argv[])
{
  Arg		args[10];
  int 		n = 0;
  Pixel		fg, bg;
  Display	*display;
  int		time;
  char		*str;
  int 		i;

  XtSetArg(args[n], XmNallowShellResize, True);  n++;
  toplevel = XtVaAppInitialize(&app_context, APP_CLASS, NULL, 0, &argc, argv,
			       fallback_resources, NULL);

  app_class_quark = XrmStringToQuark(APP_CLASS);
  app_quark = XrmStringToQuark(argv[0]);

  mainW = CreateInterface("main", toplevel);

  /* First try the resource database,  then use the fallbacks below */
  str = XGetDefault(XtDisplay(toplevel), APP_CLASS, "updateTime");
  if (str == NULL)
    str = XGetDefault(XtDisplay(toplevel), argv[0], "updateTime");
  if (str == NULL)
    updateTime = 2000;
  else
    updateTime = atoi(str);

  str = XGetDefault(XtDisplay(toplevel), APP_CLASS, "deleteCommand");
  if (str == NULL)
    str = XGetDefault(XtDisplay(toplevel), argv[0], "deleteCommand");
  if (str == NULL)
    deleteCommand = "rm %s";
  else
    deleteCommand = str;

  /* Find the widgets in the hierarchy */
  dirOM = XtNameToWidget(mainW, "*dirOM");

  dirLabel = (Widget *) XtMalloc(sizeof(Widget) * ndirLabel);
  for (i = 0; i < ndirLabel; i++) {
    char buf[16];
    sprintf(buf, "*l%d", i);
    dirLabel[i] = XtNameToWidget(mainW, buf);
    paths[i] = NULL;
  }

  fileviewer = XtNameToWidget(mainW, "*container");
  gotoDialog = XtNameToWidget(mainW, "*gotoDialog");
  
  displayLabel = XtNameToWidget(mainW, "*Where");

  XtVaGetValues(fileviewer, XmNforeground, &bg,	
		XmNbackground, &fg, NULL, NULL);

  XtManageChild(mainW);

  /* Install our special error handler */
  XSetErrorHandler((XErrorHandler) ErrorHandler);

  /* Add the UTM callbacks on the container area */
  XtAddCallback(fileviewer, XmNdestinationCallback, 
		(XtCallbackProc) targetDestinationCallback, NULL);
  XtAddCallback(fileviewer, XmNconvertCallback, 
		(XtCallbackProc) targetConvertCallback, NULL);
  XtAddCallback(XtParent(fileviewer), XmNresizeCallback,
		fixViewerSize, NULL);

  readdirCB(fileviewer, ".", NULL);

  XtRealizeWidget(toplevel);

  XmContainerRelayout(fileviewer);

  XtAppAddTimeOut(app_context, updateTime,
		  UpdateDir, (XtPointer) 0);

  XtAppMainLoop(app_context);

  return 0;    /* make compiler happy */
}
Esempio n. 26
0
void
get_defaults()
{
	char *opt;
	XModifierKeymap *modmap;
	unsigned int numlockmask = 0;
	int i, j;
	char def_key[] = "ControlAlt+y";
	char def_key_bigger[] = "Control+KP_Add";
	char def_key_smaller[] = "Control+KP_Subtract";
	char def_key_full[] = "Alt+F11";

	/* modifier stuff taken from evilwm */
	modmap = XGetModifierMapping(dpy);
	for (i = 0; i < 8; i++) {
		for (j = 0; j < modmap->max_keypermod; j++) {
			if (modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock)) {
				numlockmask = (1 << i);
			}
		}
	}
	XFreeModifiermap(modmap);
	opt = XGetDefault(dpy, progname, "screenWidth");
	opt_width = opt ? atoi(opt) : DisplayWidth(dpy, screen);
	opt = XGetDefault(dpy, progname, "xrandrSupport");
	opt_xrandr = opt ? atoi(opt) : 0;
	opt = XGetDefault(dpy, progname, "handleColor");
	opt_color = opt ? opt : "grey70";
	opt = XGetDefault(dpy, progname, "handleWidth");
	opt_bw = opt ? atoi(opt) : 3;
	opt = XGetDefault(dpy, progname, "consoleHeight");
	opt_height = opt ? atoi(opt) : 10;
	opt = XGetDefault(dpy, progname, "xOffset");
	opt_x = opt_x_orig = opt ? atoi(opt) : 0;
	opt = XGetDefault(dpy, progname, "yOffset");
	opt_y = opt_y_orig = opt ? atoi(opt) : 0;
	opt = XGetDefault(dpy, progname, "aniDelay");
	opt_delay = opt ? atoi(opt) : 40;
	opt = XGetDefault(dpy, progname, "stepSize");
	opt_step = opt_xrandr ? 0 : opt ? atoi(opt) : 1;
	opt = XGetDefault(dpy, progname, "restart");
	opt_restart = opt ? atoi(opt) : 0;
	opt = XGetDefault(dpy, progname, "restartHidden");
	opt_restart_hidden = opt ? atoi(opt) : 0;
	opt = XGetDefault(dpy, progname, "term");
	opt_term = opt ? opt : "xterm";
	opt = XGetDefault(dpy, progname, "toggleKey");
	opt_key = opt ? grab_that_key(opt, numlockmask) : grab_that_key(def_key, numlockmask);
	opt = XGetDefault(dpy, progname, "keySmaller");
	opt_key_smaller = opt ? grab_that_key(opt, numlockmask) : grab_that_key(def_key_smaller, numlockmask);
	opt = XGetDefault(dpy, progname, "keyBigger");
	opt_key_bigger = opt ? grab_that_key(opt, numlockmask) : grab_that_key(def_key_bigger, numlockmask);
	opt = XGetDefault(dpy, progname, "keyFull");
	opt_key_full = opt ? grab_that_key(opt, numlockmask) : grab_that_key(def_key_full, numlockmask);
}
Esempio n. 27
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;
}
Esempio n. 28
0
void
dev_open(
	char  *id
)
{
	extern char	*getenv();
	static RGBPRIMS	myprims = STDPRIMS;
	static int	atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8,
				GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8,
				GLX_DEPTH_SIZE,15, None};
	char	*ev;
	double	gamval = GAMMA;
	RGBPRIMP	dpri = stdprims;
	XSetWindowAttributes	ourwinattr;
	XWMHints	ourxwmhints;
	XSizeHints	oursizhints;
					/* set quadtree globals */
	qtMinNodesiz = 3;
	qtDepthEps = 0.07;
					/* open display server */
	ourdisplay = XOpenDisplay(NULL);
	if (ourdisplay == NULL)
		error(USER, "cannot open X-windows; DISPLAY variable set?\n");
					/* find a usable visual */
	ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
	if (ourvinf == NULL)
		error(USER, "no suitable visuals available");
					/* get a context */
	gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
					/* set gamma and tone mapping */
	if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL
			|| (ev = getenv("DISPLAY_GAMMA")) != NULL)
		gamval = atof(ev);
	if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL &&
			sscanf(ev, "%f %f %f %f %f %f %f %f",
				&myprims[RED][CIEX],&myprims[RED][CIEY],
				&myprims[GRN][CIEX],&myprims[GRN][CIEY],
				&myprims[BLU][CIEX],&myprims[BLU][CIEY],
				&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
		dpri = myprims;
	tmGlobal = tmInit(mytmflags(), dpri, gamval);
	if (tmGlobal == NULL)
		error(SYSTEM, "not enough memory in dev_open");
					/* open window */
	ourwinattr.background_pixel = ourblack;
	ourwinattr.border_pixel = ourblack;
	ourwinattr.event_mask = ourmask;
					/* this is stupid */
	ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
				ourvinf->visual, AllocNone);
	gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
		DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
		DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
		BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual,
		CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
	if (gwind == 0)
		error(SYSTEM, "cannot create window\n");
   	XStoreName(ourdisplay, gwind, id);
					/* set window manager hints */
	ourxwmhints.flags = InputHint|IconPixmapHint;
	ourxwmhints.input = True;
	ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
			gwind, x11icon_bits, x11icon_width, x11icon_height);
	XSetWMHints(ourdisplay, gwind, &ourxwmhints);
	oursizhints.min_width = MINWIDTH;
	oursizhints.min_height = MINHEIGHT;
	oursizhints.flags = PMinSize;
	XSetNormalHints(ourdisplay, gwind, &oursizhints);
					/* set GLX context */
	glXMakeCurrent(ourdisplay, gwind, gctx);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glShadeModel(GL_FLAT);
	glDisable(GL_DITHER);
	glDisable(GL_CULL_FACE);
	glMatrixMode(GL_PROJECTION);
	glOrtho(0., 1., 0., 1., -.01, 1.01);
	glTranslated(0., 0., -1.01);
					/* figure out sensible view */
	pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
			DisplayWidth(ourdisplay, ourscreen);
	pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
			DisplayHeight(ourdisplay, ourscreen);
	odev.v = stdview;
	odev.v.type = VT_PER;
					/* map the window */
	XMapWindow(ourdisplay, gwind);
	dev_input();			/* sets size and view angles */
					/* allocate our leaf pile */
	if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) *
			DisplayHeight(ourdisplay,ourscreen) * 3 /
			(qtMinNodesiz*qtMinNodesiz*2)))
		error(SYSTEM, "insufficient memory for value storage");
	odev.name = id;
	odev.ifd = ConnectionNumber(ourdisplay);
					/* initialize cone array */
	initcones();
}
Esempio n. 29
0
int
main(int argc, char *argv[])
{
    int i;				/* iterator, temp variable */
    char *displayname = NULL;		/* name of server to contact */
    int screenno;			/* screen number of dpy */
    XID id = None;			/* resource to kill */
    char *button_name = NULL;		/* name of button for window select */
    int button;				/* button number or negative for all */
    Bool kill_all = False;
    Bool top = False;

    ProgramName = argv[0];
    button = SelectButtonFirst;

    for (i = 1; i < argc; i++) {
	char *arg = argv[i];

	if (arg[0] == '-') {
	    switch (arg[1]) {
	      case 'd':			/* -display displayname */
		if (++i >= argc) usage ();
		displayname = argv[i];
		continue;
	      case 'i':			/* -id resourceid */
		if (++i >= argc) usage ();
		id = parse_id (argv[i]);
		continue;
	      case 'b':			/* -button number */
		if (++i >= argc) usage ();
		button_name = argv[i];
		continue;
	      case 'f':			/* -frame */
		top = True;
		continue;
	      case 'a':			/* -all */
		kill_all = True;
		continue;
	      default:
		usage ();
	    }
	} else {
	    usage ();
	}
    }					/* end for */

    dpy = XOpenDisplay (displayname);
    if (!dpy) {
	fprintf (stderr, "%s:  unable to open display \"%s\"\n",
		 ProgramName, XDisplayName (displayname));
	Exit (1);
    }
    screenno = DefaultScreen (dpy);

    if (kill_all) {
	if (verify_okay_to_kill (dpy, screenno)) 
	  kill_all_windows (dpy, screenno, top);
	Exit (0);
    }

    /*
     * if no id was given, we need to choose a window
     */

    if (id == None) {
	if (!button_name)
	    button_name = XGetDefault (dpy, ProgramName, "Button");

	if (button_name && !parse_button (button_name, &button)) {
	    fprintf (stderr, "%s:  invalid button specification \"%s\"\n",
		     ProgramName, button_name);
	    Exit (1);
	}

	if (button >= 0 || button == SelectButtonFirst) {
	    unsigned char pointer_map[256];	 /* 8 bits of pointer num */
	    int count, j;
	    unsigned int ub = (unsigned int) button;


	    count = XGetPointerMapping (dpy, pointer_map, 256);
	    if (count <= 0) {
		fprintf (stderr, 
			 "%s:  no pointer mapping, can't select window\n",
			 ProgramName);
		Exit (1);
	    }

	    if (button >= 0) {			/* check button */
		for (j = 0; j < count; j++) {
		    if (ub == (unsigned int) pointer_map[j]) break;
		}
		if (j == count) {
		    fprintf (stderr,
	 "%s:  no button number %u in pointer map, can't select window\n",
			     ProgramName, ub);
		    Exit (1);
	        }
	    } else {				/* get first entry */
		button = (int) ((unsigned int) pointer_map[0]);
	    }
	}
	if ((id = get_window_id (dpy, screenno, button,
				"the window whose client you wish to kill"))) {
	    if (id == RootWindow(dpy,screenno)) id = None;
	    else if (!top) {
		XID indicated = id;
		if ((id = XmuClientWindow(dpy, indicated)) == indicated) {
		    
		    /* Try not to kill the window manager when the user
		     * indicates an icon to xkill.
		     */

		    if (! wm_state_set(dpy, id) && wm_running(dpy, screenno))
			id = None;

		} 
	    }
	}
    }

    if (id != None) {
	printf ("%s:  killing creator of resource 0x%lx\n", ProgramName, id);
	XSync (dpy, 0);			/* give xterm a chance */
	XKillClient (dpy, id);
	XSync (dpy, 0);
    }

    Exit (0);
    /*NOTREACHED*/
    return 0;
}
Esempio n. 30
0
int
main(int argc, char *argv[])
{
    Visual visual;
    XSetWindowAttributes xswa;
    int i;
    char *displayname = NULL;
    Display *dpy;
    Colormap cmap;
    enum e_action action = doDefault;
    unsigned long mask;
    int screen;
    int x, y, width, height;
    char *geom = NULL;
    int geom_result;
    int display_width, display_height;
    char *solidcolor = NULL;
    XColor cdef;

    ProgramName = argv[0];

    for (i = 1; i < argc; i++) {
        char *arg = argv[i];

        if (arg[0] == '-') {
            if (isabbreviation ("-display", arg, 2)) {
                if (++i >= argc) Syntax ();
                displayname = argv[i];
                continue;
            } else if (isabbreviation ("-geometry", arg, 2)) {
                if (++i >= argc) Syntax ();
                geom = argv[i];
                continue;
            } else if (isabbreviation ("-black", arg, 2)) {
                action = doBlack;
                continue;
            } else if (isabbreviation ("-white", arg, 2)) {
                action = doWhite;
                continue;
            } else if (isabbreviation ("-solid", arg, 2)) {
                if (++i >= argc) Syntax ();
                solidcolor = argv[i];
                action = doSolid;
                continue;
            } else if (isabbreviation ("-none", arg, 2)) {
                action = doNone;
                continue;
            } else if (isabbreviation ("-root", arg, 2)) {
                action = doRoot;
                continue;
            } else
                Syntax ();
        } else if (arg[0] == '=')			/* obsolete */
            geom = arg;
        else
            Syntax ();
    }

    if ((dpy = XOpenDisplay(displayname)) == NULL) {
        fprintf (stderr, "%s:  unable to open display '%s'\n",
                 ProgramName, XDisplayName (displayname));
        exit (1);
    }

    if (action == doDefault) {
        char *def;

        if ((def = XGetDefault (dpy, ProgramName, "Solid")) != NULL) {
            solidcolor = strdup (def);
            if (solidcolor == NULL) {
                fprintf (stderr,
                         "%s:  unable to allocate memory for string.\n",
                         ProgramName);
                exit (1);
            }
            action = doSolid;
        } else {
            struct s_pair *pp;

            for (pp = pair_table; pp->resource_name != NULL; pp++) {
                def = XGetDefault (dpy, ProgramName, pp->resource_name);
                if (def && parse_boolean_option (def) == 1) {
                    action = pp->action;
                }
            }
        }
    }

    if (geom == NULL) geom = XGetDefault (dpy, ProgramName, "Geometry");

    screen = DefaultScreen (dpy);
    display_width = DisplayWidth (dpy, screen);
    display_height = DisplayHeight (dpy, screen);
    x = y = 0;
    width = display_width;
    height = display_height;

    if (DisplayCells (dpy, screen) <= 2 && action == doSolid) {
        if (strcmp (solidcolor, "black") == 0)
            action = doBlack;
        else if (strcmp (solidcolor, "white") == 0)
            action = doWhite;
        else {
            fprintf (stderr,
                     "%s:  can't use colors on a monochrome display.\n",
                     ProgramName);
            action = doNone;
        }
    }

    if (geom)
        geom_result = XParseGeometry (geom, &x, &y,
                                      (unsigned int *)&width,
                                      (unsigned int *)&height);
    else
        geom_result = NoValue;

    /*
     * For parsing geometry, we want to have the following
     *
     *     =                (0,0) for (display_width,display_height)
     *     =WxH+X+Y         (X,Y) for (W,H)
     *     =WxH-X-Y         (display_width-W-X,display_height-H-Y) for (W,H)
     *     =+X+Y            (X,Y) for (display_width-X,display_height-Y)
     *     =WxH             (0,0) for (W,H)
     *     =-X-Y            (0,0) for (display_width-X,display_height-Y)
     *
     * If we let any missing values be taken from (0,0) for
     * (display_width,display_height) we just have to deal with the
     * negative offsets.
     */

    if (geom_result & XNegative) {
        if (geom_result & WidthValue) {
            x = display_width - width + x;
        } else {
            width = display_width + x;
            x = 0;
        }
    }
    if (geom_result & YNegative) {
        if (geom_result & HeightValue) {
            y = display_height - height + y;
        } else {
            height = display_height + y;
            y = 0;
        }
    }

    mask = 0;
    switch (action) {
    case doBlack:
        xswa.background_pixel = BlackPixel (dpy, screen);
        mask |= CWBackPixel;
        break;
    case doWhite:
        xswa.background_pixel = WhitePixel (dpy, screen);
        mask |= CWBackPixel;
        break;
    case doSolid:
        cmap = DefaultColormap (dpy, screen);
        if (XParseColor (dpy, cmap, solidcolor, &cdef) &&
                XAllocColor (dpy, cmap, &cdef)) {
            xswa.background_pixel = cdef.pixel;
            mask |= CWBackPixel;
        } else {
            fprintf (stderr,"%s:  unable to allocate color '%s'.\n",
                     ProgramName, solidcolor);
            action = doNone;
        }
        break;
    case doDefault:
    case doNone:
        xswa.background_pixmap = None;
        mask |= CWBackPixmap;
        break;
    case doRoot:
        xswa.background_pixmap = ParentRelative;
        mask |= CWBackPixmap;
        break;
    }
    xswa.override_redirect = True;
    xswa.backing_store = NotUseful;
    xswa.save_under = False;
    mask |= (CWOverrideRedirect | CWBackingStore | CWSaveUnder);
    visual.visualid = CopyFromParent;
    win = XCreateWindow(dpy, DefaultRootWindow(dpy), x, y, width, height,
                        0, DefaultDepth(dpy, screen), InputOutput, &visual, mask, &xswa);

    /*
     * at some point, we really ought to go walk the tree and turn off
     * backing store;  or do a ClearArea generating exposures on all windows
     */
    XMapWindow (dpy, win);
    /* the following will free the color that we might have allocateded */
    XCloseDisplay (dpy);
    exit (0);
}