Пример #1
0
int
GetWindowGeometry(unsigned int display_width, unsigned int display_height,
	int &window_width, int &window_height, int &window_x, int &window_y)
{
	// set default values
	window_x = display_width/8;
	window_y = display_height/8;
	window_width = display_width/3;
	window_height = display_height/3;

	// get geometry that user gave.
	if (*geometry != 0)
	{
		// user specified some geometry
		int user_x, user_y;	
		unsigned int user_width, user_height;
		int status = XParseGeometry(geometry, &user_x, &user_y, 
					&user_width, &user_height);
		if (status & XValue) window_x = user_x;
		if (status & YValue) window_y = user_y;
		if (status & WidthValue) window_width = user_width;
		if (status & HeightValue) window_height = user_height;
		if (status & XNegative)
			window_x = display_width - window_width + window_x;
		if (status & YNegative)
			window_y = display_height - window_height + window_y;
	}

	// all done
	return(OK);
}
Пример #2
0
static Bool
get_geometry (Display *dpy, Window window, XRectangle *ret)
{
  Atom type;
  int format;
  unsigned long nitems, bytesafter;
  unsigned char *name = 0;
  Atom atom = XInternAtom (dpy, XA_XSCREENSAVER_IMAGE_GEOMETRY, False);
  int x, y;
  unsigned int w, h;
  if (XGetWindowProperty (dpy, window, atom,
                          0, 1024, False, XA_STRING,
                          &type, &format, &nitems, &bytesafter,
                          &name)
      == Success
      && type != None)
    {
      int flags = XParseGeometry ((char *) name, &x, &y, &w, &h);
      free (name);
      /* Require all four, and don't allow negative positions. */
      if (flags == (XValue|YValue|WidthValue|HeightValue))
        {
          ret->x = x;
          ret->y = y;
          ret->width  = w;
          ret->height = h;
          return True;
        }
      else
        return False;
    }
  else
    return False;
}
Пример #3
0
bool
image_effects::set_blur (const char *geom)
{
  bool changed = false;
  unsigned int hr, vr;
  int junk;
  int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);

  if (!(geom_flags & WidthValue))
    hr = 1;
  if (!(geom_flags & HeightValue))
    vr = hr;

  min_it (hr, 128);
  min_it (vr, 128);

  if (h_blurRadius != hr)
    {
      changed = true;
      h_blurRadius = hr;
    }

  if (v_blurRadius != vr)
    {
      changed = true;
      v_blurRadius = vr;
    }

  return changed;
}
Пример #4
0
/* After parsing the command line and the resource database, use the
   information. */
static bool
use_options(void)
{
#ifdef HAVE_X11
    int x, y, w, h;
    int gflgs = XParseGeometry(geom_str, &x, &y, &w, &h);

    if(!(gflgs & WidthValue))
	w = -1;
    if(!(gflgs & HeightValue))
	h = -1;
    /* TODO: need to use -ve values properly */
    if(!(gflgs & XValue))
	x = -1;
    if(!(gflgs & YValue))
	y = -1;

    set_default_geometry (x, y, w, h);
#endif

#ifdef HAVE_X11
    if (opt_sync)
	XSynchronize (gdk_display, True);
#endif

    return true;
}
Пример #5
0
void CreateIconManagers()
{
    IconMgr *p;
    int mask;
    char str[100];
    char str1[100];
    Pixel background;
    char *icon_name;

    if (Scr->NoIconManagers)
	return;

    if (Scr->siconifyPm == None)
    {
	Scr->siconifyPm = XCreatePixmapFromBitmapData(dpy, Scr->Root,
	    (char *)siconify_bits, siconify_width, siconify_height, 1, 0, 1);
    }

    for (p = &Scr->iconmgr; p != NULL; p = p->next)
    {
	mask = XParseGeometry(p->geometry, &JunkX, &JunkY,
			      (unsigned int *) &p->width, (unsigned int *)&p->height);

	if (mask & XNegative)
	    JunkX = Scr->MyDisplayWidth - p->width - 
	      (2 * Scr->BorderWidth) + JunkX;

	if (mask & YNegative)
	    JunkY = Scr->MyDisplayHeight - p->height -
	      (2 * Scr->BorderWidth) + JunkY;

	background = Scr->IconManagerC.back;
	GetColorFromList(Scr->IconManagerBL, p->name, (XClassHint *)NULL,
			 &background);

	p->w = XCreateSimpleWindow(dpy, Scr->Root,
	    JunkX, JunkY, p->width, p->height, 1,
	    Scr->Black, background);

	sprintf(str, "%s Icon Manager", p->name);
	sprintf(str1, "%s Icons", p->name);
	if (p->icon_name)
	    icon_name = p->icon_name;
	else
	    icon_name = str1;

	XSetStandardProperties(dpy, p->w, str, icon_name, None, NULL, 0, NULL);

	p->twm_win = AddWindow(p->w, TRUE, p);
	SetMapStateProp (p->twm_win, WithdrawnState);
    }
    for (p = &Scr->iconmgr; p != NULL; p = p->next)
    {
	GrabButtons(p->twm_win);
	GrabKeys(p->twm_win);
    }
}
Пример #6
0
Rectangle parse_rectangle(char* string) {
    Rectangle rect;
    int x,y;
    unsigned int w, h;
    int flags = XParseGeometry(string, &x, &y, &w, &h);
    rect.x = (XValue & flags) ? (short int)x : 0;
    rect.y = (YValue & flags) ? (short int)y : 0;
    rect.width = (WidthValue & flags) ? (unsigned short int)w : 0;
    rect.height = (HeightValue & flags) ? (unsigned short int)h : 0;
    return rect;
}
Пример #7
0
/*
 * Perform initialization. This usually happens on the program startup
 * and restarting after glutMainLoop termination...
 */
void FGAPIENTRY glutInit( int* pargc, char** argv )
{
    char* displayName = NULL;
    char* geometry = NULL;
    if( fgState.Initialised )
        fgError( "illegal glutInit() reinitialization attempt" );

    if (pargc && *pargc && argv && *argv && **argv)
    {
        fgState.ProgramName = strdup (*argv);

        if( !fgState.ProgramName )
            fgError ("Could not allocate space for the program's name.");
    }

    fgCreateStructure( );

	fghParseCommandLineArguments ( pargc, argv, &displayName, &geometry );

    /*
     * Have the display created now. If there wasn't a "-display"
     * in the program arguments, we will use the DISPLAY environment
     * variable for opening the X display (see code above):
     */
    fgPlatformInitialize( displayName );

    /*
     * Geometry parsing deferred until here because we may need the screen
     * size.
     */

    if (geometry )
    {
        unsigned int parsedWidth, parsedHeight;
        int mask = XParseGeometry( geometry,
                                   &fgState.Position.X, &fgState.Position.Y,
                                   &parsedWidth, &parsedHeight );
        /* TODO: Check for overflow? */
        fgState.Size.X = parsedWidth;
        fgState.Size.Y = parsedHeight;

        if( (mask & (WidthValue|HeightValue)) == (WidthValue|HeightValue) )
            fgState.Size.Use = GL_TRUE;

        if( mask & XNegative )
            fgState.Position.X += fgDisplay.ScreenWidth - fgState.Size.X;

        if( mask & YNegative )
            fgState.Position.Y += fgDisplay.ScreenHeight - fgState.Size.Y;

        if( (mask & (XValue|YValue)) == (XValue|YValue) )
            fgState.Position.Use = GL_TRUE;
    }
}
Пример #8
0
void createWindowBoxes(void)
{
	WindowBox *winbox;
	char title [128];
	XWMHints      wmhints;
	XSizeHints    sizehints;

	for(winbox = Scr->FirstWindowBox; winbox; winbox = winbox->next) {
		int mask, x, y, gravity;
		unsigned int w, h;
		Window win;

		mask = XParseGeometry(winbox->geometry, &x, &y, &w, &h);
		if(mask & XNegative) {
			x += Scr->rootw  - w;
			gravity = (mask & YNegative) ? SouthEastGravity : NorthEastGravity;
		}
		else {
			gravity = (mask & YNegative) ? SouthWestGravity : NorthWestGravity;
		}
		if(mask & YNegative) {
			y += Scr->rooth - h;
		}

		win = XCreateSimpleWindow(dpy, Scr->Root, x, y, w, h, 0, Scr->Black,
		                          Scr->White);
		/*printf ("createWindowBoxes : name = %s, win = 0x%x, x = %d, y = %d, w = %d, h = %d\n",
		        winbox->name, win, x, y, w, h); */
		sprintf(title, "%s", winbox->name);
		XSetStandardProperties(dpy, win, title, title, None, NULL, 0, NULL);
		sizehints.flags  = USPosition | USSize | PWinGravity;
		sizehints.x      = x;
		sizehints.y      = y;
		sizehints.width  = w;
		sizehints.height = h;
		sizehints.win_gravity = gravity;
		XSetWMSizeHints(dpy, win, &sizehints, XA_WM_NORMAL_HINTS);

		wmhints.initial_state = NormalState;
		wmhints.input         = True;
		wmhints.flags         = InputHint | StateHint;
		XSetWMHints(dpy, win, &wmhints);

		winbox->window = win;
		winbox->twmwin = AddWindow(win, ADD_WINDOW_WINDOWBOX, NULL, Scr->currentvs);
		if(!winbox->twmwin) {
			fprintf(stderr, "cannot create %s window box, exiting...\n", winbox->name);
			exit(1);
		}
		winbox->twmwin->iswinbox = TRUE;
		XMapWindow(dpy, win);
	}
}
Пример #9
0
Файл: dock.c Проект: Cougar/pwm
void set_dock_params(const char *geom, const uint flags)
{
	uint dummy;
	int flag;
	
	flag=XParseGeometry(geom, &create_x, &create_y, &dummy, &dummy);
	
	create_flags=flags;
	
	if(flag&XNegative)
		create_flags|=DOCK_RIGHT;
	if(flag&YNegative)
		create_flags|=DOCK_BOTTOM;
}
Пример #10
0
static void
set_sizehints (XSizeHints *hintp, int min_width, int min_height,
               int defwidth, int defheight, int defx, int defy, char *geom)
{
    int geom_result;

    /* set the size hints, algorithm from xlib xbiff */

    hintp->width = hintp->min_width = min_width;
    hintp->height = hintp->min_height = min_height;
    hintp->flags = PMinSize;
    hintp->x = hintp->y = 0;
    geom_result = NoValue;
    if (geom != NULL) {
        geom_result = XParseGeometry (geom, &hintp->x, &hintp->y,
				      (unsigned int *)&hintp->width,
				      (unsigned int *)&hintp->height);
	if ((geom_result & WidthValue) && (geom_result & HeightValue)) {
#define max(a,b) ((a) > (b) ? (a) : (b))
	    hintp->width = max (hintp->width, hintp->min_width);
	    hintp->height = max (hintp->height, hintp->min_height);
	    hintp->flags |= USSize;
	}
	if ((geom_result & XValue) && (geom_result & YValue)) {
	    hintp->flags += USPosition;
	}
    }
    if (!(hintp->flags & USSize)) {
	hintp->width = defwidth;
	hintp->height = defheight;
	hintp->flags |= PSize;
    }
/*
    if (!(hintp->flags & USPosition)) {
	hintp->x = defx;
	hintp->y = defy;
	hintp->flags |= PPosition;
    }
 */
    if (geom_result & XNegative) {
	hintp->x = DisplayWidth (dpy, DefaultScreen (dpy)) + hintp->x -
		    hintp->width;
    }
    if (geom_result & YNegative) {
	hintp->y = DisplayHeight (dpy, DefaultScreen (dpy)) + hintp->y -
		    hintp->height;
    }
    return;
}
Пример #11
0
/*
  XBGetArgs - Get the X related arguments (geometry for now)

  Input Parameters:
. Argc - pointer to argument count
. argv - argument vector
. flag - 1 if the "found" arguments should be stripped from the argument list

  Output Parameters:
. px,py - position of window
. pw,ph - width and height of window

  Note:
  The output parameters are unchanged if they are not set.  The form of the
  argument is
$ -geometry width x height + xoffset + yoffset
$ with no spaces.  For example
$ -geometry 400x400
$ for a 400 x 400 window, and
$ -geometry +100+200
$ for a window located at (100,200).
  */
void XBGetArgs( int *Argc, char **argv, int flag, int *px, int *py, int *pw, int *ph ){
	char         val[128];
	int          vallen;
	int          st, xx, yy;
	unsigned int ww, hh;

	vallen = 128;
	if (ArgGetString( Argc, argv, flag, "-geometry", val, vallen )) {
		/* value is of form wxh+x+y */
		st  = XParseGeometry( val, &xx, &yy, &ww, &hh );
		if (st & XValue)        *px = xx;
		if (st & YValue)        *py = yy;
		if (st & WidthValue)    *pw = (int)ww;
		if (st & HeightValue)   *ph = (int)hh;
    	}
}
Пример #12
0
void Widgets::handleXGeometry(QWidget * dlg)
{
#ifdef Q_WS_X11
	QString geometry;
	KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde");
	if (args && args->isSet("geometry"))
		geometry = args->getOption("geometry");
    if ( ! geometry.isEmpty()) {
	int x, y;
	int w, h;
	int m = XParseGeometry( geometry.toLatin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h);
	if ( (m & XNegative) )
	    x = KApplication::desktop()->width()  + x - w;
	if ( (m & YNegative) )
	    y = KApplication::desktop()->height() + y - h;
	dlg->setGeometry(x, y, w, h);
	// kDebug() << "x: " << x << "  y: " << y << "  w: " << w << "  h: " << h;
    }
#endif
}
Пример #13
0
void initscreen(char *geometry)
{
	d1 = XOpenDisplay(0);
	if (d1 == NULL) {
		printf("Can't open display.\n");
		exit(0);
	}

	if (geometry != NULL) {
		XParseGeometry(geometry, &w1_x, &w1_y, &w1_w, &w1_h);
	}

	/*Aufbau der XWindowsAttribStr */
	w0 = DefaultRootWindow(d1);
	winatt1.background_pixel = BlackPixel(d1, 0);
	winatt1.backing_store = WhenMapped;
	winatt1.event_mask = KeyPressMask | StructureNotifyMask | ExposureMask;
	w1 = XCreateWindow(d1, w0, w1_x, w1_y, w1_w, w1_h, w1_border, CopyFromParent, InputOutput, CopyFromParent,
			   CWBackPixel | CWBackingStore | CWEventMask, &winatt1);

	XStoreName(d1, w1, w1_wname);
	XSetIconName(d1, w1, w1_iname);
	XMapWindow(d1, w1);

	cm1 = DefaultColormap(d1, 0);
	if (!XAllocNamedColor(d1, cm1, "blue", &xc1, &xc2))
		printf("coudn't allocate blue color\n");
	f1_str = XLoadQueryFont(d1, font1_name);
	if (f1_str == NULL) {
		printf("could't load font\n");
		exit(EXIT_FAILURE);
	}

	gcval1.foreground = xc1.pixel;
	gcval1.font = f1_str->fid;
	gcval1.line_style = LineSolid;
	gc1 = XCreateGC(d1, w1, GCForeground | GCLineStyle, &gcval1);
	gcval1.foreground = WhitePixel(d1, 0);
	gc2 = XCreateGC(d1, w1, GCForeground | GCLineStyle | GCFont, &gcval1);
}
Пример #14
0
/*
 * FScreenParseGeometry
 *     Does the same as XParseGeometry, but handles additional "@scr".
 *     Since it isn't safe to define "ScreenValue" constant (actual values
 *     of other "XXXValue" are specified in Xutil.h, not by us, so there can
 *     be a clash), the screen value is always returned, even if it wasn't
 *     present in `parse_string' (set to default in that case).
 *
 */
int FScreenParseGeometryWithScreen(
	char *parsestring, int *x_return, int *y_return,
	unsigned int *width_return, unsigned int *height_return,
	int *screen_return)
{
	int   ret;
	char *copy, *scr_p;
	int   s_size;
	int   scr;

	/* Safety net */
	if (parsestring == NULL  ||  *parsestring == '\0')
	{
		return 0;
	}

	/* Make a local copy devoid of "@scr" */
	s_size = strlen(parsestring) + 1;
	copy = safemalloc(s_size);
	memcpy(copy, parsestring, s_size);
	scr_p = strchr(copy, '@');
	if (scr_p != NULL)
	{
		*scr_p++ = '\0';
	}

	/* Do the parsing */
	ret = XParseGeometry(
		copy, x_return, y_return, width_return, height_return);

	/* Parse the "@scr", if any */
	scr = FScreenParseScreenBit(scr_p, FSCREEN_SPEC_PRIMARY);
	*screen_return = scr;

	/* We don't need the string any more */
	free(copy);

	return ret;
}
EelGdkGeometryFlags
eel_gdk_parse_geometry (const char *string, int *x_return, int *y_return,
			     guint *width_return, guint *height_return)
{
	int x11_flags;
	EelGdkGeometryFlags gdk_flags;

	g_return_val_if_fail (string != NULL, EEL_GDK_NO_VALUE);
	g_return_val_if_fail (x_return != NULL, EEL_GDK_NO_VALUE);
	g_return_val_if_fail (y_return != NULL, EEL_GDK_NO_VALUE);
	g_return_val_if_fail (width_return != NULL, EEL_GDK_NO_VALUE);
	g_return_val_if_fail (height_return != NULL, EEL_GDK_NO_VALUE);

	x11_flags = XParseGeometry (string, x_return, y_return,
				    width_return, height_return);

	gdk_flags = EEL_GDK_NO_VALUE;
	if (x11_flags & XValue) {
		gdk_flags |= EEL_GDK_X_VALUE;
	}
	if (x11_flags & YValue) {
		gdk_flags |= EEL_GDK_Y_VALUE;
	}
	if (x11_flags & WidthValue) {
		gdk_flags |= EEL_GDK_WIDTH_VALUE;
	}
	if (x11_flags & HeightValue) {
		gdk_flags |= EEL_GDK_HEIGHT_VALUE;
	}
	if (x11_flags & XNegative) {
		gdk_flags |= EEL_GDK_X_NEGATIVE;
	}
	if (x11_flags & YNegative) {
		gdk_flags |= EEL_GDK_Y_NEGATIVE;
	}

	return gdk_flags;
}
Пример #16
0
void
cmd_set_geometry() {
    int ret=0, x=0, y=0;
    unsigned int w=0, h=0;
    if(uzbl.gui.geometry) {
        if(uzbl.gui.geometry[0] == 'm') { /* m/maximize/maximized */
            gtk_window_maximize((GtkWindow *)(uzbl.gui.main_window));
        } else {
            /* we used to use gtk_window_parse_geometry() but that didn't work how it was supposed to */
            ret = XParseGeometry(uzbl.gui.geometry, &x, &y, &w, &h);
            if(ret & XValue)
                gtk_window_move((GtkWindow *)uzbl.gui.main_window, x, y);
            if(ret & WidthValue)
                gtk_window_resize((GtkWindow *)uzbl.gui.main_window, w, h);
        }
    }

    /* update geometry var with the actual geometry
       this is necessary as some WMs don't seem to honour
       the above setting and we don't want to end up with
       wrong geometry information
    */
    retrieve_geometry();
}
Пример #17
0
static void 
SetGeometry (Widget w, String geometry, Position * x, Position * y)
			
{
   int x_return, y_return;
   unsigned int width_return, height_return;
   long flags;

   flags = XParseGeometry (geometry, &x_return, &y_return,
                           &width_return, &height_return);

   if (flags)
   {
      if (flags & XValue)
         *x = (Position) x_return;

      if (flags & XNegative)
         *x = (Position) (WidthOfScreen (XtScreen (w)) - XtWidth(w))
                         + x_return;

      if (flags & YValue)
         *y = (Position) y_return;

      if (flags & YNegative)
      {
         *y = (Position) (HeightOfScreen (XtScreen (w)) - XtHeight(w))
                         + y_return;
      }

      if (flags & XValue || flags & YValue || flags & XNegative ||
          flags & YNegative)
      {
         XtMoveWidget (w, *x, *y);
      }
   }
}
Пример #18
0
/*
 * Perform initialization. This usually happens on the program startup
 * and restarting after glutMainLoop termination...
 */
void FGAPIENTRY glutInit( int* pargc, char** argv )
{
    char* displayName = NULL;
    char* geometry = NULL;
    int i, j, argc = *pargc;

    if( fgState.Initialised )
        fgError( "illegal glutInit() reinitialization attempt" );

    if (pargc && *pargc && argv && *argv && **argv)
    {
        fgState.ProgramName = strdup (*argv);

        if( !fgState.ProgramName )
            fgError ("Could not allocate space for the program's name.");
    }

    fgCreateStructure( );

    fgElapsedTime( );

#ifndef _WIN32_WCE
    /* check if GLUT_FPS env var is set */
    {
        const char *fps = getenv( "GLUT_FPS" );
        if( fps )
        {
            sscanf( fps, "%d", &fgState.FPSInterval );
            if( fgState.FPSInterval <= 0 )
                fgState.FPSInterval = 5000;  /* 5000 milliseconds */
        }
    }

    displayName = getenv( "DISPLAY");

    for( i = 1; i < argc; i++ )
    {
        if( strcmp( argv[ i ], "-display" ) == 0 )
        {
            if( ++i >= argc )
                fgError( "-display parameter must be followed by display name" );

            displayName = argv[ i ];

            argv[ i - 1 ] = NULL;
            argv[ i     ] = NULL;
            ( *pargc ) -= 2;
        }
        else if( strcmp( argv[ i ], "-geometry" ) == 0 )
        {
            if( ++i >= argc )
                fgError( "-geometry parameter must be followed by window "
                         "geometry settings" );

            geometry = argv[ i ];

            argv[ i - 1 ] = NULL;
            argv[ i     ] = NULL;
            ( *pargc ) -= 2;
        }
        else if( strcmp( argv[ i ], "-direct" ) == 0)
        {
            if( ! fgState.TryDirectContext )
                fgError( "parameters ambiguity, -direct and -indirect "
                    "cannot be both specified" );

            fgState.ForceDirectContext = GL_TRUE;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
        else if( strcmp( argv[ i ], "-indirect" ) == 0 )
        {
            if( fgState.ForceDirectContext )
                fgError( "parameters ambiguity, -direct and -indirect "
                    "cannot be both specified" );

            fgState.TryDirectContext = GL_FALSE;
            argv[ i ] = NULL;
            (*pargc)--;
        }
        else if( strcmp( argv[ i ], "-iconic" ) == 0 )
        {
            fgState.ForceIconic = GL_TRUE;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
        else if( strcmp( argv[ i ], "-gldebug" ) == 0 )
        {
            fgState.GLDebugSwitch = GL_TRUE;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
        else if( strcmp( argv[ i ], "-sync" ) == 0 )
        {
            fgState.XSyncSwitch = GL_TRUE;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
    }
#endif
    /*
     * Compact {argv}.
     */
    j = 2;
    for( i = 1; i < *pargc; i++, j++ )
    {
        if( argv[ i ] == NULL )
        {
            /* Guaranteed to end because there are "*pargc" arguments left */
            while ( argv[ j ] == NULL )
                j++;
            argv[ i ] = argv[ j ];
        }
    }

    /*
     * Have the display created now. As I am too lazy to implement
     * the program arguments parsing, we will have the DISPLAY
     * environment variable used for opening the X display:
     *
     * XXX The above comment is rather unclear.  We have just
     * XXX completed parsing of the program arguments for GLUT
     * XXX parameters.  We obviously canNOT parse the application-
     * XXX specific parameters.  Can someone re-write the above
     * XXX more clearly?
     */
    fgInitialize( displayName );

    /*
     * Geometry parsing deffered until here because we may need the screen
     * size.
     */

    if (geometry )
    {
        int mask = XParseGeometry( geometry,
                                   &fgState.Position.X, &fgState.Position.Y,
                                   &fgState.Size.X, &fgState.Size.Y );

        if( (mask & (WidthValue|HeightValue)) == (WidthValue|HeightValue) )
            fgState.Size.Use = GL_TRUE;

        if( mask & XNegative )
            fgState.Position.X += fgDisplay.ScreenWidth - fgState.Size.X;

        if( mask & YNegative )
            fgState.Position.Y += fgDisplay.ScreenHeight - fgState.Size.Y;

        if( (mask & (XValue|YValue)) == (XValue|YValue) )
            fgState.Position.Use = GL_TRUE;
    }
}
Пример #19
0
int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch,
               struct gui_data *inst, Conf *conf)
{
    int err = 0;
    char *val;

    /*
     * Macros to make argument handling easier. Note that because
     * they need to call `continue', they cannot be contained in
     * the usual do {...} while (0) wrapper to make them
     * syntactically single statements; hence it is not legal to
     * use one of these macros as an unbraced statement between
     * `if' and `else'.
     */
#define EXPECTS_ARG { \
    if (--argc <= 0) { \
	err = 1; \
	fprintf(stderr, "%s: %s expects an argument\n", appname, p); \
        continue; \
    } else \
	val = *++argv; \
}
#define SECOND_PASS_ONLY { if (!do_everything) continue; }

    while (--argc > 0) {
	char *p = *++argv;
        int ret;

	/*
	 * Shameless cheating. Debian requires all X terminal
	 * emulators to support `-T title'; but
	 * cmdline_process_param will eat -T (it means no-pty) and
	 * complain that pterm doesn't support it. So, in pterm
	 * only, we convert -T into -title.
	 */
	if ((cmdline_tooltype & TOOLTYPE_NONNETWORK) &&
	    !strcmp(p, "-T"))
	    p = (char*)"-title";

        ret = cmdline_process_param(p, (argc > 1 ? argv[1] : NULL),
                                    do_everything ? 1 : -1, conf);

	if (ret == -2) {
	    cmdline_error("option \"%s\" requires an argument",p);
	} else if (ret == 2) {
	    --argc, ++argv;            /* skip next argument */
            continue;
	} else if (ret == 1) {
            continue;
        }

	if (!strcmp(p, "-fn") || !strcmp(p, "-font")) {
        FontSpec *fs;
	    EXPECTS_ARG;
        SECOND_PASS_ONLY;
        fs = fontspec_new(val);
        conf_set_fontspec(conf, CONF_font, fs);
        fontspec_free(fs);
	} else if (!strcmp(p, "-fb")) {
        FontSpec *fs;
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
        fs = fontspec_new(val);
        conf_set_fontspec(conf, CONF_boldfont, fs);
        fontspec_free(fs);
	} else if (!strcmp(p, "-fw")) {
        FontSpec *fs;
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
        fs = fontspec_new(val);
        conf_set_fontspec(conf, CONF_widefont, fs);
        fontspec_free(fs);
	} else if (!strcmp(p, "-fwb")) {
        FontSpec *fs;
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
        fs = fontspec_new(val);
        conf_set_fontspec(conf, CONF_wideboldfont, fs);
        fontspec_free(fs);
	} else if (!strcmp(p, "-cs")) {
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
        conf_set_str(conf, CONF_line_codepage, val);

	} else if (!strcmp(p, "-geometry")) {
#ifdef Q_OS_UNIX
	    int flags, x, y;
	    unsigned int w, h;
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;

	    flags = XParseGeometry(val, &x, &y, &w, &h);
	    if (flags & WidthValue)
            conf_set_int(conf, CONF_width, w);
        if (flags & HeightValue)
            conf_set_int(conf, CONF_height, h);

            if (flags & (XValue | YValue)) {
                inst->xpos = x;
                inst->ypos = y;
                inst->gotpos = TRUE;
                inst->gravity = ((flags & XNegative ? 1 : 0) |
                                 (flags & YNegative ? 2 : 0));
            }
#endif
	} else if (!strcmp(p, "-sl")) {
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
        conf_set_int(conf, CONF_savelines, atoi(val));

	} /*else if (!strcmp(p, "-fg") || !strcmp(p, "-bg") ||
		   !strcmp(p, "-bfg") || !strcmp(p, "-bbg") ||
		   !strcmp(p, "-cfg") || !strcmp(p, "-cbg")) {
	    GdkColor col;

	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
	    if (!gdk_color_parse(val, &col)) {
		err = 1;
		fprintf(stderr, "%s: unable to parse colour \"%s\"\n",
                        appname, val);
	    } else {
		int index;
		index = (!strcmp(p, "-fg") ? 0 :
			 !strcmp(p, "-bg") ? 2 :
			 !strcmp(p, "-bfg") ? 1 :
			 !strcmp(p, "-bbg") ? 3 :
			 !strcmp(p, "-cfg") ? 4 :
			 !strcmp(p, "-cbg") ? 5 : -1);
		assert(index != -1);
		cfg->colours[index][0] = col.red / 256;
		cfg->colours[index][1] = col.green / 256;
		cfg->colours[index][2] = col.blue / 256;
	    }

	} */else if (use_pty_argv && !strcmp(p, "-e")) {
	    /* This option swallows all further arguments. */
	    if (!do_everything)
		break;

	    if (--argc > 0) {
		int i;
		pty_argv = snewn(argc+1, char *);
		++argv;
		for (i = 0; i < argc; i++)
		    pty_argv[i] = argv[i];
		pty_argv[argc] = NULL;
		break;		       /* finished command-line processing */
	    } else
		err = 1, fprintf(stderr, "%s: -e expects an argument\n",
                                 appname);

	} else if (!strcmp(p, "-title")) {
void BC_DisplayInfo::parse_geometry(char *geom, int *x, int *y, int *width, int *height)
{
	XParseGeometry(geom, x, y, (unsigned int*)width, (unsigned int*)height);
}
Пример #21
0
/*
 * Perform initialization. This usually happens on the program startup
 * and restarting after glutMainLoop termination...
 */
void FGAPIENTRY glutInit( int* pargc, char** argv )
{
    char* displayName = NULL;
    char* geometry = NULL;
    int i, j, argc = *pargc;

    if( fgState.Initialised )
        fgError( "illegal glutInit() reinitialization attempt" );

    if (pargc && *pargc && argv && *argv && **argv)
    {
        fgState.ProgramName = strdup (*argv);

        if( !fgState.ProgramName )
            fgError ("Could not allocate space for the program's name.");
    }

    fgCreateStructure( );

    /* Get start time */
    fgState.Time = fgSystemTime();

    /* check if GLUT_FPS env var is set */
#ifndef _WIN32_WCE
    {
        const char *fps = getenv( "GLUT_FPS" );

        if( fps )
        {
            int interval;
            sscanf( fps, "%d", &interval );

            if( interval <= 0 )
                fgState.FPSInterval = 5000;  /* 5000 millisecond default */
            else
                fgState.FPSInterval = interval;
        }
    }

    displayName = getenv( "DISPLAY" );

    for( i = 1; i < argc; i++ )
    {
        if( strcmp( argv[ i ], "-display" ) == 0 )
        {
            if( ++i >= argc )
                fgError( "-display parameter must be followed by display name" );

            displayName = argv[ i ];

            argv[ i - 1 ] = NULL;
            argv[ i     ] = NULL;
            ( *pargc ) -= 2;
        }
        else if( strcmp( argv[ i ], "-geometry" ) == 0 )
        {
            if( ++i >= argc )
                fgError( "-geometry parameter must be followed by window "
                         "geometry settings" );

            geometry = argv[ i ];

            argv[ i - 1 ] = NULL;
            argv[ i     ] = NULL;
            ( *pargc ) -= 2;
        }
        else if( strcmp( argv[ i ], "-direct" ) == 0)
        {
            if( fgState.DirectContext == GLUT_FORCE_INDIRECT_CONTEXT )
                fgError( "parameters ambiguity, -direct and -indirect "
                    "cannot be both specified" );

            fgState.DirectContext = GLUT_FORCE_DIRECT_CONTEXT;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
        else if( strcmp( argv[ i ], "-indirect" ) == 0 )
        {
            if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
                fgError( "parameters ambiguity, -direct and -indirect "
                    "cannot be both specified" );

            fgState.DirectContext = GLUT_FORCE_INDIRECT_CONTEXT;
            argv[ i ] = NULL;
            (*pargc)--;
        }
        else if( strcmp( argv[ i ], "-iconic" ) == 0 )
        {
            fgState.ForceIconic = GL_TRUE;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
        else if( strcmp( argv[ i ], "-gldebug" ) == 0 )
        {
            fgState.GLDebugSwitch = GL_TRUE;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
        else if( strcmp( argv[ i ], "-sync" ) == 0 )
        {
            fgState.XSyncSwitch = GL_TRUE;
            argv[ i ] = NULL;
            ( *pargc )--;
        }
    }

    /* Compact {argv}. */
    for( i = j = 1; i < *pargc; i++, j++ )
    {
        /* Guaranteed to end because there are "*pargc" arguments left */
        while ( argv[ j ] == NULL )
            j++;
        if ( i != j )
            argv[ i ] = argv[ j ];
    }

#endif /* _WIN32_WCE */

    /*
     * Have the display created now. If there wasn't a "-display"
     * in the program arguments, we will use the DISPLAY environment
     * variable for opening the X display (see code above):
     */
    fghInitialize( displayName );

    /*
     * Geometry parsing deffered until here because we may need the screen
     * size.
     */

    if (geometry )
    {
        unsigned int parsedWidth, parsedHeight;
        int mask = XParseGeometry( geometry,
                                   &fgState.Position.X, &fgState.Position.Y,
                                   &parsedWidth, &parsedHeight );
        /* TODO: Check for overflow? */
        fgState.Size.X = parsedWidth;
        fgState.Size.Y = parsedHeight;

        if( (mask & (WidthValue|HeightValue)) == (WidthValue|HeightValue) )
            fgState.Size.Use = GL_TRUE;

        if( mask & XNegative )
            fgState.Position.X += fgDisplay.ScreenWidth - fgState.Size.X;

        if( mask & YNegative )
            fgState.Position.Y += fgDisplay.ScreenHeight - fgState.Size.Y;

        if( (mask & (XValue|YValue)) == (XValue|YValue) )
            fgState.Position.Use = GL_TRUE;
    }
}
Пример #22
0
/*
 * The following function initializes a toplevel window.
 * It returns 0 if the initialization was successful,
 * or -1 if it couldn't initialize the double buffering routine.
 */
int Init_top(void)
{
    int					top_x, top_y;
    int					i;
    int					x, y;
    unsigned				w, h;
    unsigned long			values;
    int					top_flags;
    XGCValues				xgc;
    XSetWindowAttributes		sattr;
    unsigned long			mask;

    if (topWindow)
	fatal("Init_top called twice");

    if (Colors_init() == -1)
	return -1;

    radarDrawRectanglePtr = XFillRectangle;

    /*
     * Get toplevel geometry.
     */
    top_flags = 0;
    if (geometry != NULL && geometry[0] != '\0')
	mask = XParseGeometry(geometry, &x, &y, &w, &h);
    else
	mask = 0;

    if ((mask & WidthValue) != 0) {
	top_width = w;
	top_flags |= USSize;
    } else {
	top_width = DEF_TOP_WIDTH;
	top_flags |= PSize;
    }
    LIMIT(top_width, MIN_TOP_WIDTH, MAX_TOP_WIDTH);
    if ((mask & HeightValue) != 0) {
	top_height = h;
	top_flags |= USSize;
    } else {
	top_height = DEF_TOP_HEIGHT;
	top_flags |= PSize;
    }
    LIMIT(top_height, MIN_TOP_HEIGHT, MAX_TOP_HEIGHT);
    if ((mask & XValue) != 0) {
	if ((mask & XNegative) != 0)
	    top_x = DisplayWidth(dpy, DefaultScreen(dpy)) - top_width + x;
	else
	    top_x = x;
	top_flags |= USPosition;
    } else {
	top_x = (DisplayWidth(dpy, DefaultScreen(dpy)) - top_width) /2;
	top_flags |= PPosition;
    }
    if ((mask & YValue) != 0) {
	if ((mask & YNegative) != 0)
	    top_y = DisplayHeight(dpy, DefaultScreen(dpy)) - top_height + y;
	else
	    top_y = y;
	top_flags |= USPosition;
    } else {
	top_y = (DisplayHeight(dpy, DefaultScreen(dpy)) - top_height) /2;
	top_flags |= PPosition;
    }
    if (geometry != NULL) {
	free(geometry);
	geometry = NULL;
    }

    /*
     * Create toplevel window (we need this first so that we can create GCs)
     */
    mask = 0;
    /*old debug: sattr.background_pixel = colors[WHITE].pixel;*/
    sattr.background_pixel = colors[BLACK].pixel;
    mask |= CWBackPixel;
    sattr.border_pixel = colors[WHITE].pixel;
    mask |= CWBorderPixel;
    if (colormap != 0) {
	sattr.colormap = colormap;
	mask |= CWColormap;
    }
    if (ignoreWindowManager) {
	sattr.override_redirect = True;
	mask |= CWOverrideRedirect;
    }
    topWindow = XCreateWindow(dpy,
			      DefaultRootWindow(dpy),
			      top_x, top_y,
			      top_width, top_height,
			      0, (int)dispDepth,
			      InputOutput, visual,
			      mask, &sattr);
    XSelectInput(dpy, topWindow,
		 KeyPressMask | KeyReleaseMask
		 | FocusChangeMask | StructureNotifyMask);
    Init_disp_prop(dpy, topWindow, top_width, top_height,
		   top_x, top_y, top_flags);
    if (kdpy) {
	int scr = DefaultScreen(kdpy);
	keyboardWindow = XCreateSimpleWindow(kdpy,
					     DefaultRootWindow(kdpy),
					     top_x, top_y,
					     top_width, top_height,
					     0, 0, BlackPixel(dpy, scr));
	XSelectInput(kdpy, keyboardWindow,
		     KeyPressMask | KeyReleaseMask | FocusChangeMask);
	Init_disp_prop(kdpy, keyboardWindow, top_width, top_height,
		       top_x, top_y, top_flags);
    }

    /*
     * Create item bitmaps
     */
    for (i = 0; i < NUM_ITEMS; i++)
	itemBitmaps[i]
	    = XCreateBitmapFromData(dpy, topWindow,
				    (char *)itemBitmapData[i].data,
				    ITEM_SIZE, ITEM_SIZE);

    /*
     * Creates and initializes the graphic contexts.
     */
    xgc.line_width = 0;
    xgc.line_style = LineSolid;
    xgc.cap_style = CapButt;
    xgc.join_style = JoinMiter;		/* I think this is fastest, is it? */
    xgc.graphics_exposures = False;
    values
	= GCLineWidth|GCLineStyle|GCCapStyle|GCJoinStyle|GCGraphicsExposures;

    messageGC	= XCreateGC(dpy, topWindow, values, &xgc);
    radarGC	= XCreateGC(dpy, topWindow, values, &xgc);
    buttonGC	= XCreateGC(dpy, topWindow, values, &xgc);
    scoreListGC	= XCreateGC(dpy, topWindow, values, &xgc);
    textGC	= XCreateGC(dpy, topWindow, values, &xgc);
    talkGC	= XCreateGC(dpy, topWindow, values, &xgc);
    motdGC	= XCreateGC(dpy, topWindow, values, &xgc);
    gameGC	= XCreateGC(dpy, topWindow, values, &xgc);
    XSetBackground(dpy, gameGC, colors[BLACK].pixel);

    /*
     * Set fonts
     */
    gameFont
	= Set_font(dpy, gameGC, gameFontName, "gameFont");
    messageFont
	= Set_font(dpy, messageGC, messageFontName, "messageFont");
    scoreListFont
	= Set_font(dpy, scoreListGC, scoreListFontName, "scoreListFont");
    buttonFont
	= Set_font(dpy, buttonGC, buttonFontName, "buttonFont");
    textFont
	= Set_font(dpy, textGC, textFontName, "textFont");
    talkFont
	= Set_font(dpy, talkGC, talkFontName, "talkFont");
    motdFont
	= Set_font(dpy, motdGC, motdFontName, "motdFont");

    XSetState(dpy, gameGC,
	      WhitePixel(dpy, DefaultScreen(dpy)),
	      BlackPixel(dpy, DefaultScreen(dpy)),
	      GXcopy, AllPlanes);
    XSetState(dpy, radarGC,
	      WhitePixel(dpy, DefaultScreen(dpy)),
	      BlackPixel(dpy, DefaultScreen(dpy)),
	      GXcopy, AllPlanes);
    XSetState(dpy, messageGC,
	      WhitePixel(dpy, DefaultScreen(dpy)),
	      BlackPixel(dpy, DefaultScreen(dpy)),
	      GXcopy, AllPlanes);
    XSetState(dpy, buttonGC,
	      WhitePixel(dpy, DefaultScreen(dpy)),
	      BlackPixel(dpy, DefaultScreen(dpy)),
	      GXcopy, AllPlanes);
    XSetState(dpy, scoreListGC,
	      WhitePixel(dpy, DefaultScreen(dpy)),
	      BlackPixel(dpy, DefaultScreen(dpy)),
	      GXcopy, AllPlanes);

    if (dbuf_state->type == COLOR_SWITCH)
	XSetPlaneMask(dpy, gameGC, dbuf_state->drawing_planes);

    return 0;
}
Пример #23
0
int
main(int argc, char *argv[]) {
	int i, use_ewmh_dock=0;
	char *action_string = NULL;
	char *endptr, *fnpre = NULL;

	/* default values */
	dzen.title_win.name = "dzen title";
	dzen.slave_win.name = "dzen slave";
	dzen.cur_line  = 0;
	dzen.ret_val   = 0;
	dzen.title_win.x = dzen.slave_win.x = 0;
	dzen.title_win.y = 0;
	dzen.title_win.width = dzen.slave_win.width = 0;
	dzen.title_win.alignment = ALIGNCENTER;
	dzen.slave_win.alignment = ALIGNLEFT;
	dzen.fnt = FONT;
	dzen.bg  = BGCOLOR;
	dzen.fg  = FGCOLOR;
	dzen.slave_win.max_lines  = 0;
	dzen.running = True;
	dzen.xinescreen = 0;
	dzen.tsupdate = 0;
	dzen.line_height = 0;
	dzen.title_win.expand = noexpand;

	/* Connect to X server */
	x_connect();
	x_read_resources();

	/* cmdline args */
	for(i = 1; i < argc; i++)
		if(!strncmp(argv[i], "-l", 3)){
			if(++i < argc) {
				dzen.slave_win.max_lines = atoi(argv[i]);
				if(dzen.slave_win.max_lines)
					init_input_buffer();
			}
		}
		else if(!strncmp(argv[i], "-geometry", 10)) {
			if(++i < argc) {
				int t;
				int tx, ty;
				unsigned int tw, th;

				t = XParseGeometry(argv[i], &tx, &ty, &tw, &th);

				if(t & XValue)
					dzen.title_win.x = tx;
				if(t & YValue) {
					dzen.title_win.y = ty;
					if(!ty && (t & YNegative))
						/* -0 != +0 */
						dzen.title_win.y = -1;
				}
				if(t & WidthValue)
					dzen.title_win.width = (signed int) tw;
				if(t & HeightValue)
					dzen.line_height = (signed int) th;
			}
		}
		else if(!strncmp(argv[i], "-u", 3)){
			dzen.tsupdate = True;
		}
		else if(!strncmp(argv[i], "-expand", 8)){
			if(++i < argc) {
				switch(argv[i][0]){
					case 'l':
						dzen.title_win.expand = left;
						break;
					case 'c':
						dzen.title_win.expand = both;
						break;
					case 'r':
						dzen.title_win.expand = right;
						break;
					default:
						dzen.title_win.expand = noexpand;
				}
			}
		}
		else if(!strncmp(argv[i], "-p", 3)) {
			dzen.ispersistent = True;
			if (i+1 < argc) {
				dzen.timeout = strtoul(argv[i+1], &endptr, 10);
				if(*endptr)
					dzen.timeout = 0;
				else
					i++;
			}
		}
		else if(!strncmp(argv[i], "-ta", 4)) {
			if(++i < argc) dzen.title_win.alignment = alignment_from_char(argv[i][0]);
		}
		else if(!strncmp(argv[i], "-sa", 4)) {
			if(++i < argc) dzen.slave_win.alignment = alignment_from_char(argv[i][0]);
		}
		else if(!strncmp(argv[i], "-m", 3)) {
			dzen.slave_win.ismenu = True;
			if(i+1 < argc) {
				if( argv[i+1][0] == 'v') {
					++i;
					break;
				}
				dzen.slave_win.ishmenu = (argv[i+1][0] == 'h') ? ++i, True : False;
			}
		}
		else if(!strncmp(argv[i], "-fn", 4)) {
			if(++i < argc) dzen.fnt = argv[i];
		}
		else if(!strncmp(argv[i], "-e", 3)) {
			if(++i < argc) action_string = argv[i];
		}
		else if(!strncmp(argv[i], "-title-name", 12)) {
			if(++i < argc) dzen.title_win.name = argv[i];
		}
		else if(!strncmp(argv[i], "-slave-name", 12)) {
			if(++i < argc) dzen.slave_win.name = argv[i];
		}
		else if(!strncmp(argv[i], "-bg", 4)) {
			if(++i < argc) dzen.bg = argv[i];
		}
		else if(!strncmp(argv[i], "-fg", 4)) {
			if(++i < argc) dzen.fg = argv[i];
		}
		else if(!strncmp(argv[i], "-x", 3)) {
			if(++i < argc) dzen.title_win.x = dzen.slave_win.x = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-y", 3)) {
			if(++i < argc) dzen.title_win.y = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-w", 3)) {
			if(++i < argc) dzen.slave_win.width = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-h", 3)) {
			if(++i < argc) dzen.line_height= atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-tw", 4)) {
			if(++i < argc) dzen.title_win.width = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-fn-preload", 12)) {
			if(++i < argc) {
				fnpre = estrdup(argv[i]);
			}
		}
#ifdef DZEN_XINERAMA
		else if(!strncmp(argv[i], "-xs", 4)) {
			if(++i < argc) dzen.xinescreen = atoi(argv[i]);
		}
#endif
		else if(!strncmp(argv[i], "-dock", 6))
			use_ewmh_dock = 1;
		else if(!strncmp(argv[i], "-v", 3)) {
			printf("dzen-"VERSION", (C)opyright 2007-2009 Robert Manea\n");
			printf(
			"Enabled optional features: "
#ifdef DZEN_XMP
			" XPM "
#endif
#ifdef DZEN_XFT
			" XFT"
#endif
#ifdef DZEN_XINERAMA
			" XINERAMA "
#endif
			"\n"
			);
			return EXIT_SUCCESS;
		}
		else
			eprint("usage: dzen2 [-v] [-p [seconds]] [-m [v|h]] [-ta <l|c|r>] [-sa <l|c|r>]\n"
                   "             [-x <pixel>] [-y <pixel>] [-w <pixel>] [-h <pixel>] [-tw <pixel>] [-u]\n"
				   "             [-e <string>] [-l <lines>]  [-fn <font>] [-bg <color>] [-fg <color>]\n"
				   "             [-geometry <geometry string>] [-expand <left|right>] [-dock]\n"
				   "             [-title-name <string>] [-slave-name <string>]\n"
#ifdef DZEN_XINERAMA
				   "             [-xs <screen>]\n"
#endif
				  );

	if(dzen.tsupdate && !dzen.slave_win.max_lines)
		dzen.tsupdate = False;

	if(!dzen.title_win.width)
		dzen.title_win.width = dzen.slave_win.width;

	if(!setlocale(LC_ALL, "") || !XSupportsLocale())
		puts("dzen: locale not available, expect problems with fonts.\n");

	if(action_string)
		fill_ev_table(action_string);
	else {
		if(!dzen.slave_win.max_lines) {
			char edef[] = "button3=exit:13";
			fill_ev_table(edef);
		}
		else if(dzen.slave_win.ishmenu) {
			char edef[] = "enterslave=grabkeys;leaveslave=ungrabkeys;"
				"button4=scrollup;button5=scrolldown;"
				"key_Left=scrollup;key_Right=scrolldown;"
				"button1=menuexec;button3=exit:13;"
				"key_Escape=ungrabkeys,exit";
			fill_ev_table(edef);
		}
		else {
			char edef[]  = "entertitle=uncollapse,grabkeys;"
				"enterslave=grabkeys;leaveslave=collapse,ungrabkeys;"
				"button1=menuexec;button2=togglestick;button3=exit:13;"
				"button4=scrollup;button5=scrolldown;"
				"key_Up=scrollup;key_Down=scrolldown;"
				"key_Escape=ungrabkeys,exit";
			fill_ev_table(edef);
		}
	}

	if((find_event(onexit) != -1)
			&& (setup_signal(SIGTERM, catch_sigterm) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGTERM\n");

	if((find_event(sigusr1) != -1)
			&& (setup_signal(SIGUSR1, catch_sigusr1) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGUSR1\n");

	if((find_event(sigusr2) != -1)
		&& (setup_signal(SIGUSR2, catch_sigusr2) == SIG_ERR))
		fprintf(stderr, "dzen: error hooking SIGUSR2\n");

	if(setup_signal(SIGALRM, catch_alrm) == SIG_ERR)
		fprintf(stderr, "dzen: error hooking SIGALARM\n");

	if(dzen.slave_win.ishmenu &&
			!dzen.slave_win.max_lines)
		dzen.slave_win.max_lines = 1;


	x_create_windows(use_ewmh_dock);

	if(!dzen.slave_win.ishmenu)
		x_map_window(dzen.title_win.win);
	else {
		XMapRaised(dzen.dpy, dzen.slave_win.win);
		for(i=0; i < dzen.slave_win.max_lines; i++)
			XMapWindow(dzen.dpy, dzen.slave_win.line[i]);
	}

	/* Reposition the window back to where it should be */
	XMoveWindow(dzen.dpy,dzen.title_win.win,dzen.title_win.x,dzen.title_win.y);

	if( fnpre != NULL )
		font_preload(fnpre);

	do_action(onstart);

	/* main loop */
	event_loop();

	do_action(onexit);
	clean_up();

	if(dzen.ret_val)
		return dzen.ret_val;

	return EXIT_SUCCESS;
}
Пример #24
0
void win_open(win_t *win)
{
	win_env_t *e;
	XClassHint classhint;
	XColor col;
	char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
	Pixmap none;
	int gmask;

	if (win == NULL)
		return;

	e = &win->env;

	/* determine window offsets, width & height */
	if (options->geometry == NULL)
		gmask = 0;
	else
		gmask = XParseGeometry(options->geometry, &win->x, &win->y,
		                       &win->w, &win->h);
	if ((gmask & WidthValue) != 0)
		win->sizehints.flags |= USSize;
	else
		win->w = WIN_WIDTH;
	if ((gmask & HeightValue) != 0)
		win->sizehints.flags |= USSize;
	else
		win->h = WIN_HEIGHT;
	if ((gmask & XValue) != 0) {
		if ((gmask & XNegative) != 0) {
			win->x += e->scrw - win->w;
			win->sizehints.win_gravity = NorthEastGravity;
		}
		win->sizehints.flags |= USPosition;
	} else {
		win->x = (e->scrw - win->w) / 2;
	}
	if ((gmask & YValue) != 0) {
		if ((gmask & YNegative) != 0) {
			win->y += e->scrh - win->h;
			if (win->sizehints.win_gravity == NorthEastGravity)
				win->sizehints.win_gravity = SouthEastGravity;
			else
				win->sizehints.win_gravity = SouthWestGravity;
		}
		win->sizehints.flags |= USPosition;
	} else {
		win->y = (e->scrh - win->h) / 2;
	}

	win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
	                          win->x, win->y, win->w, win->h, 0,
	                          e->depth, InputOutput, e->vis, 0, None);
	if (win->xwin == None)
		die("could not create window");
	
	XSelectInput(e->dpy, win->xwin,
	             ExposureMask | ButtonReleaseMask | ButtonPressMask |
	             KeyPressMask | PointerMotionMask | StructureNotifyMask);

	carrow = XCreateFontCursor(e->dpy, XC_left_ptr);
	chand = XCreateFontCursor(e->dpy, XC_fleur);
	cwatch = XCreateFontCursor(e->dpy, XC_watch);

	if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black",
	                     &col, &col) == 0)
	{
		die("could not allocate color: black");
	}
	none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8);
	cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0);

	gc = XCreateGC(e->dpy, win->xwin, 0, None);

	win_set_title(win, "sxiv");

	classhint.res_class = "Sxiv";
	classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv";
	XSetClassHint(e->dpy, win->xwin, &classhint);

	XSetWMProtocols(e->dpy, win->xwin, &wm_delete_win, 1);

	win->h -= win->bar.h;
	win_update_sizehints(win);

	XMapWindow(e->dpy, win->xwin);
	XFlush(e->dpy);

	if (options->fullscreen)
		win_toggle_fullscreen(win);
}
Пример #25
0
Memimage*
_xattach(char *label, char *winsize)
{
	char *argv[2], *disp;
	int i, havemin, height, mask, n, width, x, xrootid, y;
	Rectangle r;
	XClassHint classhint;
	XDrawable pmid;
	XPixmapFormatValues *pfmt;
	XScreen *xscreen;
	XSetWindowAttributes attr;
	XSizeHints normalhint;
	XTextProperty name;
	XVisualInfo xvi;
	XWindow xrootwin;
	XWindowAttributes wattr;
	XWMHints hint;
	Atom atoms[2];

	/*
	if(XInitThreads() == 0){
		fprint(2, "XInitThreads failed\n");
		abort();
	}
	*/

	/*
	 * Connect to X server.
	 */
	_x.display = XOpenDisplay(NULL);
	if(_x.display == nil){
		disp = getenv("DISPLAY");
		werrstr("XOpenDisplay %s: %r", disp ? disp : ":0");
		free(disp);
		return nil;
	}
	_x.fd = ConnectionNumber(_x.display);
	XSetErrorHandler(xerror);
	XSetIOErrorHandler(xioerror);
	xrootid = DefaultScreen(_x.display);
	xrootwin = DefaultRootWindow(_x.display);

	/* 
	 * Figure out underlying screen format.
	 */
	if(XMatchVisualInfo(_x.display, xrootid, 24, TrueColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 24, DirectColor, &xvi)){
		_x.vis = xvi.visual;
		_x.depth = 24;
	}
	else
	if(XMatchVisualInfo(_x.display, xrootid, 16, TrueColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 16, DirectColor, &xvi)){
		_x.vis = xvi.visual;
		_x.depth = 16;
	}
	else
	if(XMatchVisualInfo(_x.display, xrootid, 15, TrueColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 15, DirectColor, &xvi)){
		_x.vis = xvi.visual;
		_x.depth = 15;
	}
	else
	if(XMatchVisualInfo(_x.display, xrootid, 8, PseudoColor, &xvi)
	|| XMatchVisualInfo(_x.display, xrootid, 8, StaticColor, &xvi)){
		if(_x.depth > 8){
			werrstr("can't deal with colormapped depth %d screens",
				_x.depth);
			goto err0;
		}
		_x.vis = xvi.visual;
		_x.depth = 8;
	}
	else{
		_x.depth = DefaultDepth(_x.display, xrootid);
		if(_x.depth != 8){
			werrstr("can't understand depth %d screen", _x.depth);
			goto err0;
		}
		_x.vis = DefaultVisual(_x.display, xrootid);
	}

	if(DefaultDepth(_x.display, xrootid) == _x.depth)
		_x.usetable = 1;

	/*
	 * _x.depth is only the number of significant pixel bits,
	 * not the total number of pixel bits.  We need to walk the
	 * display list to find how many actual bits are used
	 * per pixel.
	 */
	_x.chan = 0;
	pfmt = XListPixmapFormats(_x.display, &n);
	for(i=0; i<n; i++){
		if(pfmt[i].depth == _x.depth){
			switch(pfmt[i].bits_per_pixel){
			case 1:	/* untested */
				_x.chan = GREY1;
				break;
			case 2:	/* untested */
				_x.chan = GREY2;
				break;
			case 4:	/* untested */
				_x.chan = GREY4;
				break;
			case 8:
				_x.chan = CMAP8;
				break;
			case 15:
				_x.chan = RGB15;
				break;
			case 16: /* how to tell RGB15? */
				_x.chan = RGB16;
				break;
			case 24: /* untested (impossible?) */
				_x.chan = RGB24;
				break;
			case 32:
				_x.chan = XRGB32;
				break;
			}
		}
	}
	if(_x.chan == 0){
		werrstr("could not determine screen pixel format");
		goto err0;
	}

	/*
	 * Set up color map if necessary.
	 */
	xscreen = DefaultScreenOfDisplay(_x.display);
	_x.cmap = DefaultColormapOfScreen(xscreen);
	if(_x.vis->class != StaticColor){
		plan9cmap();
		setupcmap(xrootwin);
	}

	/*
	 * We get to choose the initial rectangle size.
	 * This is arbitrary.  In theory we should read the
	 * command line and allow the traditional X options.
	 */
	mask = 0;
	x = 0;
	y = 0;
	if(winsize && winsize[0]){
		if(parsewinsize(winsize, &r, &havemin) < 0)
			sysfatal("%r");
	}else{
		/*
		 * Parse the various X resources.  Thanks to Peter Canning.
		 */
		char *screen_resources, *display_resources, *geom, 
			*geomrestype, *home, *file;
		XrmDatabase database;
		XrmValue geomres;

		database = XrmGetDatabase(_x.display);
		screen_resources = XScreenResourceString(xscreen);
		if(screen_resources != nil){
			XrmCombineDatabase(XrmGetStringDatabase(screen_resources), &database, False);
			XFree(screen_resources);
		}

		display_resources = XResourceManagerString(_x.display);
		if(display_resources == nil){
			home = getenv("HOME");
			if(home!=nil && (file=smprint("%s/.Xdefaults", home)) != nil){
				XrmCombineFileDatabase(file, &database, False);
				free(file);
			}
			free(home);
		}else
			XrmCombineDatabase(XrmGetStringDatabase(display_resources), &database, False);

		geom = smprint("%s.geometry", label);
		if(geom && XrmGetResource(database, geom, nil, &geomrestype, &geomres))
			mask = XParseGeometry(geomres.addr, &x, &y, (uint*)&width, (uint*)&height);
		free(geom);

		if((mask & WidthValue) && (mask & HeightValue)){
			r = Rect(0, 0, width, height);
		}else{
			r = Rect(0, 0, WidthOfScreen(xscreen)*3/4,
					HeightOfScreen(xscreen)*3/4);
			if(Dx(r) > Dy(r)*3/2)
				r.max.x = r.min.x + Dy(r)*3/2;
			if(Dy(r) > Dx(r)*3/2)
				r.max.y = r.min.y + Dx(r)*3/2;
		}
		if(mask & XNegative){
			x += WidthOfScreen(xscreen);
		}
		if(mask & YNegative){
			y += HeightOfScreen(xscreen);
		}
		havemin = 0;
	}
	screenrect = Rect(0, 0, WidthOfScreen(xscreen), HeightOfScreen(xscreen));
	windowrect = r;

	memset(&attr, 0, sizeof attr);
	attr.colormap = _x.cmap;
	attr.background_pixel = ~0;
	attr.border_pixel = 0;
	_x.drawable = XCreateWindow(
		_x.display,	/* display */
		xrootwin,	/* parent */
		x,		/* x */
		y,		/* y */
		Dx(r),		/* width */
	 	Dy(r),		/* height */
		0,		/* border width */
		_x.depth,	/* depth */
		InputOutput,	/* class */
		_x.vis,		/* visual */
				/* valuemask */
		CWBackPixel|CWBorderPixel|CWColormap,
		&attr		/* attributes (the above aren't?!) */
	);

	/*
	 * Label and other properties required by ICCCCM.
	 */
	memset(&name, 0, sizeof name);
	if(label == nil)
		label = "pjw-face-here";
	name.value = (uchar*)label;
	name.encoding = XA_STRING;
	name.format = 8;
	name.nitems = strlen((char*)name.value);

	memset(&normalhint, 0, sizeof normalhint);
	normalhint.flags = PSize|PMaxSize;
	if(winsize && winsize[0]){
		normalhint.flags &= ~PSize;
		normalhint.flags |= USSize;
		normalhint.width = Dx(r);
		normalhint.height = Dy(r);
	}else{
		if((mask & WidthValue) && (mask & HeightValue)){
			normalhint.flags &= ~PSize;
			normalhint.flags |= USSize;
			normalhint.width = width;
			normalhint.height = height;
		}
		if((mask & WidthValue) && (mask & HeightValue)){
			normalhint.flags |= USPosition;
			normalhint.x = x;
			normalhint.y = y;
		}
	}

	normalhint.max_width = WidthOfScreen(xscreen);
	normalhint.max_height = HeightOfScreen(xscreen);

	memset(&hint, 0, sizeof hint);
	hint.flags = InputHint|StateHint;
	hint.input = 1;
	hint.initial_state = NormalState;

	memset(&classhint, 0, sizeof classhint);
	classhint.res_name = label;
	classhint.res_class = label;

	argv[0] = label;
	argv[1] = nil;

	XSetWMProperties(
		_x.display,	/* display */
		_x.drawable,	/* window */
		&name,		/* XA_WM_NAME property */
		&name,		/* XA_WM_ICON_NAME property */
		argv,		/* XA_WM_COMMAND */
		1,		/* argc */
		&normalhint,	/* XA_WM_NORMAL_HINTS */
		&hint,		/* XA_WM_HINTS */
		&classhint	/* XA_WM_CLASSHINTS */
	);
	XFlush(_x.display);

	if(havemin){
		XWindowChanges ch;

		memset(&ch, 0, sizeof ch);
		ch.x = r.min.x;
		ch.y = r.min.y;
		XConfigureWindow(_x.display, _x.drawable, CWX|CWY, &ch);
		/*
		 * Must pretend origin is 0,0 for X.
		 */
		r = Rect(0,0,Dx(r),Dy(r));
	}
	/*
	 * Look up clipboard atom.
	 */
	_x.clipboard = XInternAtom(_x.display, "CLIPBOARD", False);
	_x.utf8string = XInternAtom(_x.display, "UTF8_STRING", False);
	_x.targets = XInternAtom(_x.display, "TARGETS", False);
	_x.text = XInternAtom(_x.display, "TEXT", False);
	_x.compoundtext = XInternAtom(_x.display, "COMPOUND_TEXT", False);
	_x.takefocus = XInternAtom(_x.display, "WM_TAKE_FOCUS", False);
	_x.losefocus = XInternAtom(_x.display, "_9WM_LOSE_FOCUS", False);
	_x.wmprotos = XInternAtom(_x.display, "WM_PROTOCOLS", False);

	atoms[0] = _x.takefocus;
	atoms[1] = _x.losefocus;
	XChangeProperty(_x.display, _x.drawable, _x.wmprotos, XA_ATOM, 32,
		PropModeReplace, (uchar*)atoms, 2);

	/*
	 * Put the window on the screen, check to see what size we actually got.
	 */
	XMapWindow(_x.display, _x.drawable);
	XSync(_x.display, False);

	if(!XGetWindowAttributes(_x.display, _x.drawable, &wattr))
		fprint(2, "XGetWindowAttributes failed\n");
	else if(wattr.width && wattr.height){
		if(wattr.width != Dx(r) || wattr.height != Dy(r)){
			r.max.x = wattr.width;
			r.max.y = wattr.height;
		}
	}else
		fprint(2, "XGetWindowAttributes: bad attrs\n");

	/*
	 * Allocate our local backing store.
	 */
	_x.screenr = r;
	_x.screenpm = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth);
	_x.nextscreenpm = _x.screenpm;
	_x.screenimage = _xallocmemimage(r, _x.chan, _x.screenpm);

	/*
	 * Allocate some useful graphics contexts for the future.
	 */
	_x.gcfill	= xgc(_x.screenpm, FillSolid, -1);
	_x.gccopy	= xgc(_x.screenpm, -1, -1);
	_x.gcsimplesrc 	= xgc(_x.screenpm, FillStippled, -1);
	_x.gczero	= xgc(_x.screenpm, -1, -1);
	_x.gcreplsrc	= xgc(_x.screenpm, FillTiled, -1);

	pmid = XCreatePixmap(_x.display, _x.drawable, 1, 1, 1);
	_x.gcfill0	= xgc(pmid, FillSolid, 0);
	_x.gccopy0	= xgc(pmid, -1, -1);
	_x.gcsimplesrc0	= xgc(pmid, FillStippled, -1);
	_x.gczero0	= xgc(pmid, -1, -1);
	_x.gcreplsrc0	= xgc(pmid, FillTiled, -1);
	XFreePixmap(_x.display, pmid);

	return _x.screenimage;

err0:
	/*
	 * Should do a better job of cleaning up here.
	 */
	XCloseDisplay(_x.display);
	return nil;
}
void GLUTAPIENTRY
glutInit(int *argcp, char **argv)
{
  char *display = NULL;
  char *str, *geometry = NULL;
#ifdef OLD_VMS
   struct timeval6 unused;
#else
   struct timeval unused;
#endif
  int i;

  if (__glutDisplay) {
    __glutWarning("glutInit being called a second time.");
    return;
  }
  /* Determine temporary program name. */
  str = strrchr(argv[0], '/');
  if (str == NULL) {
    __glutProgramName = argv[0];
  } else {
    __glutProgramName = str + 1;
  }

  /* Make private copy of command line arguments. */
  __glutArgc = *argcp;
  __glutArgv = (char **) malloc(__glutArgc * sizeof(char *));
  if (!__glutArgv)
    __glutFatalError("out of memory.");
  for (i = 0; i < __glutArgc; i++) {
    __glutArgv[i] = __glutStrdup(argv[i]);
    if (!__glutArgv[i])
      __glutFatalError("out of memory.");
  }

  /* determine permanent program name */
  str = strrchr(__glutArgv[0], '/');
  if (str == NULL) {
    __glutProgramName = __glutArgv[0];
  } else {
    __glutProgramName = str + 1;
  }

  /* parse arguments for standard options */
  for (i = 1; i < __glutArgc; i++) {
    if (!strcmp(__glutArgv[i], "-display")) {
#if defined(_WIN32)
      __glutWarning("-display option not supported by Win32 GLUT.");
#endif
      if (++i >= __glutArgc) {
        __glutFatalError(
          "follow -display option with X display name.");
      }
      display = __glutArgv[i];
      removeArgs(argcp, &argv[1], 2);
    } else if (!strcmp(__glutArgv[i], "-geometry")) {
      if (++i >= __glutArgc) {
        __glutFatalError(
          "follow -geometry option with geometry parameter.");
      }
      geometry = __glutArgv[i];
      removeArgs(argcp, &argv[1], 2);
    } else if (!strcmp(__glutArgv[i], "-direct")) {
#if defined(_WIN32)
      __glutWarning("-direct option not supported by Win32 GLUT.");
#endif
      if (!__glutTryDirect)
        __glutFatalError(
          "cannot force both direct and indirect rendering.");
      __glutForceDirect = GL_TRUE;
      removeArgs(argcp, &argv[1], 1);
    } else if (!strcmp(__glutArgv[i], "-indirect")) {
#if defined(_WIN32)
      __glutWarning("-indirect option not supported by Win32 GLUT.");
#endif
      if (__glutForceDirect)
        __glutFatalError(
          "cannot force both direct and indirect rendering.");
      __glutTryDirect = GL_FALSE;
      removeArgs(argcp, &argv[1], 1);
    } else if (!strcmp(__glutArgv[i], "-iconic")) {
      __glutIconic = GL_TRUE;
      removeArgs(argcp, &argv[1], 1);
    } else if (!strcmp(__glutArgv[i], "-gldebug")) {
      __glutDebug = GL_TRUE;
      removeArgs(argcp, &argv[1], 1);
    } else if (!strcmp(__glutArgv[i], "-sync")) {
#if defined(_WIN32)
      __glutWarning("-sync option not supported by Win32 GLUT.");
#endif
      synchronize = GL_TRUE;
      removeArgs(argcp, &argv[1], 1);
    } else {
      /* Once unknown option encountered, stop command line
         processing. */
      break;
    }
  }
#if defined(__OS2__)
  __glutOpenOS2Connection(display);
#elif defined(_WIN32)
  __glutOpenWin32Connection(display);
#else
  __glutOpenXConnection(display);
#endif
  if (geometry) {
    int flags, x, y, width, height;

    /* Fix bogus "{width|height} may be used before set"
       warning */
    width = 0;
    height = 0;

    flags = XParseGeometry(geometry, &x, &y,
      (unsigned int *) &width, (unsigned int *) &height);
    if (WidthValue & flags) {
      /* Careful because X does not allow zero or negative
         width windows */
      if (width > 0)
        __glutInitWidth = width;
    }
    if (HeightValue & flags) {
      /* Careful because X does not allow zero or negative
         height windows */
      if (height > 0)
        __glutInitHeight = height;
    }
    glutInitWindowSize(__glutInitWidth, __glutInitHeight);
    if (XValue & flags) {
      if (XNegative & flags)
        x = DisplayWidth(__glutDisplay, __glutScreen) +
          x - __glutSizeHints.width;
      /* Play safe: reject negative X locations */
      if (x >= 0)
        __glutInitX = x;
    }
    if (YValue & flags) {
      if (YNegative & flags)
        y = DisplayHeight(__glutDisplay, __glutScreen) +
          y - __glutSizeHints.height;
      /* Play safe: reject negative Y locations */
      if (y >= 0)
        __glutInitY = y;
    }
    glutInitWindowPosition(__glutInitX, __glutInitY);
  }
  __glutInitTime(&unused);

  /* check if GLUT_FPS env var is set */
  {
     const char *fps = getenv("GLUT_FPS");
     if (fps) {
        sscanf(fps, "%d", &__glutFPS);
        if (__glutFPS <= 0)
           __glutFPS = 5000;  /* 5000 milliseconds */
     }
  }
}
Пример #27
0
void
parse_xargs (int argc, char **argv, char **geometry)
{
    int option;
    extern char *optarg;

#ifdef ALLOW_PIX_DOUBLING
    char* option_string = "vbrndg:wR:G:B:";
#else
    char* option_string = "vbrng:wR:G:B:";
#endif
    while ((option = getopt (argc, argv, option_string)) != EOF) {
	switch (option)
	{
	case 'v':
	    verbose = TRUE;
	    break;
	case 'g':
	    *geometry = optarg;
	    break;
#ifdef ALLOW_PIX_DOUBLING
	case 'd':
	    pix_double = 1;
	    /* Fall through.  We are not allowed a border with pix doubling */
#endif
	case 'b':
	    borderx = 0;
	    bordery = 0;
	    break;
	case 'r':
	    borderx = BORDERX;
	    bordery = BORDERY;
	    break;
	case 'n':
	    no_init_help = TRUE;
	    break;
	case 'w':
	    gamma_correct_red = GAMMA_CORRECT_RED;
	    gamma_correct_green = GAMMA_CORRECT_GREEN;
	    gamma_correct_blue = GAMMA_CORRECT_BLUE;
	    break;
	case 'R':
	    sscanf (optarg, "%f", &gamma_correct_red);
	    break;
	case 'G':
	    sscanf (optarg, "%f", &gamma_correct_green);
	    break;
	case 'B':
	    sscanf (optarg, "%f", &gamma_correct_blue);
	    break;


	}
    }
    if (verbose)
	printf (_("Version %s\n"), VERSION);
    if (!(display.dpy = XOpenDisplay (display.dname)))
    {
	printf (" Can't open the dispay!\n");
	HandleError ("Cannot open display.\n", FATAL);
	exit (-1);
    }
    /* Record the screen number and root window. */
    display.screen = DefaultScreen (display.dpy);
    display.root = RootWindow (display.dpy, display.screen);

    display.winW = WINWIDTH + borderx * 2 + pix_double * WINWIDTH;
    display.winH = WINHEIGHT + bordery * 2 + pix_double * WINHEIGHT;
    winX = (DisplayWidth (display.dpy, display.screen) - display.winW) / 2;
    winY = (DisplayHeight (display.dpy, display.screen) - display.winH) / 2;
    if (*geometry != NULL)
	XParseGeometry (*geometry, &winX, &winY, &display.winW, &display.winH);
}
Пример #28
0
int main(int argc, char* argv[])
{
	Display *dpy = NULL;
	ASVisual *asv ;
	int screen = 0, depth = 0;
	int dummy, geom_flags = 0;
	unsigned int to_width, to_height ;
	ASGradient grad ;
	ASGradient default_grad = { 1, 11, &(default_colors[0]), 
									   &(default_offsets[0])} ;
	ASImage *grad_im = NULL;

	/* see ASView.1 : */
	set_application_name( argv[0] );
#if (HAVE_AFTERBASE_FLAG==1)
	set_output_threshold(OUTPUT_LEVEL_DEBUG);
#endif

	if( argc > 1 )
	{
	    if( strcmp( argv[1], "-h") == 0 )
	    {
			usage();
			return 0;
		}
	    /* see ASScale.1 : */
	    geom_flags = XParseGeometry( argv[1], &dummy, &dummy,
		                             &to_width, &to_height );
	}else
		usage();
	memset( &grad, 0x00, sizeof(ASGradient));

#ifndef X_DISPLAY_MISSING
    dpy = XOpenDisplay(NULL);
	_XA_WM_DELETE_WINDOW = XInternAtom( dpy, "WM_DELETE_WINDOW", False);
	screen = DefaultScreen(dpy);
	depth = DefaultDepth( dpy, screen );
#endif

	if( argc >= 5 )
	{
		int i = 2;
		/* see ASGrad.1 : */
		grad.type = atoi( argv[2] );
		grad.npoints = 0 ;
		grad.color = safemalloc( ((argc-2)/2)*sizeof(ARGB32));
		grad.offset = safemalloc( ((argc-2)/2)*sizeof(double));
		while( ++i < argc )
		{
			if( grad.npoints > 0 )
			{
				if( i == argc-1 )
					grad.offset[grad.npoints] = 1.0;
				else
					grad.offset[grad.npoints] = atof( argv[i] );
				++i ;
			}

			/* see ASTile.1 : */
			if( parse_argb_color( argv[i], &(grad.color[grad.npoints])) 
				!= argv[i] )
				if( grad.offset[grad.npoints] >= 0. && 
					grad.offset[grad.npoints]<= 1.0 )
					grad.npoints++ ;
		}
	}else
	{
		grad = default_grad ;
		if( argc >= 3 )
			grad.type = atoi( argv[2] );
	}

	if( grad.npoints <= 0 )
	{
		show_error( " not enough gradient points specified.");
		return 1;
	}

	/* Making sure tiling geometry is sane : */
#ifndef X_DISPLAY_MISSING
	if( !get_flags(geom_flags, WidthValue ) )
		to_width  = DisplayWidth(dpy, screen)*2/3 ;
	if( !get_flags(geom_flags, HeightValue ) )
		to_height = DisplayHeight(dpy, screen)*2/3 ;
#else
	if( !get_flags(geom_flags, WidthValue ) )
		to_width  = 500 ;
	if( !get_flags(geom_flags, HeightValue ) )
		to_height = 500 ;
#endif
	printf( "%s: rendering gradient of type %d to %dx%d\n",
			get_application_name(), grad.type&GRADIENT_TYPE_MASK, 
			to_width, to_height );

	/* see ASView.3 : */
	asv = create_asvisual( dpy, screen, depth, NULL );
	/* see ASGrad.2 : */
	grad_im = make_gradient( asv, &grad, to_width, to_height,
	        	             SCL_DO_ALL,
#ifndef X_DISPLAY_MISSING
							 ASA_XImage,
#else
							 ASA_ASImage,
#endif
							 0, ASIMAGE_QUALITY_DEFAULT );
	if( grad_im )
	{
#ifndef X_DISPLAY_MISSING
		/* see ASView.4 : */
		Window w = create_top_level_window( asv,
		                                    DefaultRootWindow(dpy), 32, 32,
		                        			to_width, to_height, 1, 0, NULL,
											"ASGradient", NULL );
		if( w != None )
		{
			Pixmap p ;

		  	XMapRaised   (dpy, w);
			/* see ASView.5 : */
			p = asimage2pixmap( asv, DefaultRootWindow(dpy), grad_im,
					            NULL, True );
			destroy_asimage( &grad_im );
			/* see common.c: set_window_background_and_free() : */
			p = set_window_background_and_free( w, p );
			/* see common.c: wait_closedown() : */
		}
		wait_closedown(w);
		dpy = NULL;
#else
		ASImage2file( grad_im, NULL, "asgrad.jpg", ASIT_Jpeg, NULL );
		destroy_asimage( &grad_im );
#endif
	}
    return 0 ;
}
Пример #29
0
Widget 
make_queryform(Widget parent,	    /* into whom widget should be placed */
	       const char* msgstr,  /* message string */
	       const char* button,  /* button title */
	       const char* title)   /* form title */
{
    Widget form, text, prev;
    Arg args[10];
    Cardinal n;
    char *shell_geom;
    int x, y, geom_flags;
    unsigned int shell_w, shell_h;
    Dimension max_width, max_height;

    form = XtVaCreateManagedWidget ("form", formWidgetClass, parent, 
				    XtNtitle, button,
				    NULL);

    text = XtVaCreateManagedWidget
	("message", asciiTextWidgetClass, form,
	 XtNleft, XtChainLeft,
	 XtNright, XtChainRight,
	 XtNtop, XtChainTop,
	 XtNbottom, XtChainBottom,
	 XtNdisplayCaret, False,
	 XtNlength, strlen (msgstr),
	 XtNstring, msgstr,
	 NULL);
    /*
     * Did the user specify our geometry?
     * If so, don't bother computing it ourselves, since we will be overridden.
     */
    XtVaGetValues(parent, XtNgeometry, &shell_geom, NULL);
    geom_flags = XParseGeometry(shell_geom, &x, &y, &shell_w, &shell_h);
    if (!(geom_flags & WidthValue && geom_flags & HeightValue))
    {
	Dimension width, height, height_addons = 0;
	Dimension scroll_size, border_width;
	Widget label, scroll;
	Position left, right, top, bottom;
	const char *tmp;
	/*
	 * A Text widget is used for the automatic scroll bars.
	 * But Text widget doesn't automatically compute its size.
	 * The Label widget does that nicely, so we create one and examine it.
	 * This widget is never visible.
	 */
	XtVaGetValues(text, XtNtopMargin, &top, XtNbottomMargin, &bottom,
		      XtNleftMargin, &left, XtNrightMargin, &right, (void*)0);
	label = XtVaCreateWidget("message", labelWidgetClass, form,
				 XtNlabel, msgstr,
				 XtNinternalWidth, (left+right+1)/2,
				 XtNinternalHeight, (top+bottom+1)/2,
				 NULL);
	XtVaGetValues(label, XtNwidth, &width, XtNheight, &height, NULL);
	XtDestroyWidget(label);
	max_width = .7 * WidthOfScreen(XtScreen(text));
	max_height = .7 * HeightOfScreen(XtScreen(text));
	if (width > max_width)
	{
	    width = max_width;
	    /* add in the height of any horizontal scroll bar */
	    scroll = XtVaCreateWidget("hScrollbar", scrollbarWidgetClass, text,
				      XtNorientation, XtorientHorizontal,
				      NULL);
	    XtVaGetValues(scroll, XtNheight, &scroll_size,
			  XtNborderWidth, &border_width, NULL);
	    XtDestroyWidget(scroll);
	    height_addons = scroll_size + border_width;
	}

	/* This fixes the xmessage assumption that the label widget and the
	 * text widget have the same size. In Xaw 7, the text widget has
	 * one extra pixel between lines.
	 * Xmessage is not internationalized, so the code bellow is harmless.
	 */
	tmp = msgstr;
	while (tmp != 0 && *tmp)
	{
	    ++tmp;
	    ++height;
	    tmp = strchr(tmp, '\n');
	}

	if (height > max_height)
	{
	    height = max_height;
	    /* add in the width of any vertical scroll bar */
	    scroll = XtVaCreateWidget("vScrollbar", scrollbarWidgetClass, text,
				      XtNorientation, XtorientVertical, NULL);
	    XtVaGetValues(scroll, XtNwidth, &scroll_size,
			  XtNborderWidth, &border_width, NULL);
	    XtDestroyWidget(scroll);
	    width += scroll_size + border_width;
	}
	height += height_addons;
	XtVaSetValues(text, XtNwidth, width, XtNheight, height, NULL);
    }
    /*
     * Create the buttons
     */
    n = 0;
    XtSetArg (args[n], XtNleft, XtChainLeft); n++;
    XtSetArg (args[n], XtNright, XtChainLeft); n++;
    XtSetArg (args[n], XtNtop, XtChainBottom); n++;
    XtSetArg (args[n], XtNbottom, XtChainBottom); n++;
    XtSetArg (args[n], XtNfromVert, text); n++;
    XtSetArg (args[n], XtNvertDistance, 5); n++;

    prev = 0;
    XtSetArg (args[n], XtNfromHoriz, prev); 
    prev = XtCreateManagedWidget (button, commandWidgetClass,
				      form, args, n);
    XtAddCallback (prev, XtNcallback, handle_button, 0);
    Dimension border;

    XtVaGetValues(prev, XtNborderWidth, &border, NULL);
    border *= 2;
    XtVaSetValues(prev, XtNborderWidth, border, NULL);
    return form;
}
Пример #30
0
static void
set_size_hints(Window w)
{
    int x, y;
    unsigned int width, height;
    char userdefaults[50];
    char progdefaults[50];
    char *str_type[50];
    unsigned int fwidth = 0, fheight = 0;
    unsigned int xadder = 0, yadder = 0;
    int geo = 0;                /* return flag from XGetGeometry */
    unsigned int depth, bw=0;
    Window root;
    XSizeHints size_hints;
    XPoint xp;
    XrmValue value;

    size_hints.flags = 0;

    strcpy(progdefaults, "=600x450+0+0");

    if (w) {
        /*
         * The window should be queried for it's size and position. Then the
         * new window should be given almost the same locations
         */

        if (XGetGeometry(gXDisplay, w, &root, &x, &y, &width, &height, &bw, &depth))
        {
            xp = getWindowPositionXY(gXDisplay, w);
            x = xp.x + 40;
            y = xp.y + 40;
            if (x < 0)
                x = 0;
            if (y < 0)
                y = 0;
            size_hints.flags |= (USSize | USPosition);
        }
        else {
            fprintf(stderr, "(HyperDoc) Error Querying window configuration: %ld.\n", w);
            x = y = 0;
            width = 600;
            height = 450;
            size_hints.flags |= (PSize | PPosition);
        }
    }
    else {
        /* this is the first window, so lets try to find a nice spot for it */

        if (XrmGetResource(rDB, "FriCAS.hyperdoc.Geometry",
                           "FriCAS.hyperdoc.Geometry", str_type,
                           &value) == True) {
            strncpy(userdefaults, value.addr, (int) value.size);
            geo = XParseGeometry(userdefaults, &x, &y, &width, &height);
        } else {
            strcpy(userdefaults, progdefaults);
        }

        size_hints.flags |= (geo & (WidthValue | HeightValue)) ? USSize : PSize;
        size_hints.flags |= (geo & (XValue | YValue)) ? USPosition : PPosition;

        geo = XGeometry(gXDisplay, gXScreenNumber, userdefaults, progdefaults,
                        bw, fwidth, fheight, xadder, yadder,
                        &x, &y, (int *)&width, (int *)&height);
    }

    size_hints.x = x;
    size_hints.y = y;
    size_hints.width = width;
    size_hints.height = height;

    getTitleBarMinimumSize(&(size_hints.min_width), &(size_hints.min_height));
#if 0
    size_hints.min_width  = MIN_WINDOW_SIZE;
    size_hints.min_height = MIN_WINDOW_SIZE;
#endif
    size_hints.flags |= PMinSize;

    XSetNormalHints(gXDisplay, gWindow->fMainWindow, &size_hints);
    /* just in case a hint isn't enough ... */
    XFlush(gXDisplay);
/*  XMoveResizeWindow(gXDisplay, gWindow->fMainWindow, x, y, width, height); */
}